make builtin class type a bootstrap version of java/lang/Class

This commit is contained in:
Joel Dice 2007-07-12 17:46:08 -06:00
parent 69eed6ba5a
commit 0099aa396b
7 changed files with 72 additions and 18 deletions

View File

@ -1,9 +1,23 @@
package java.lang;
public final class Class <T> {
private Object body;
private short flags;
private short vmFlags;
private short fixedSize;
private short arrayElementSize;
private int[] objectMask;
private byte[] name;
private Class super_;
private Object interfaceTable;
private Object virtualTable;
private Object fieldTable;
private Object methodTable;
private Object staticTable;
private Object initializer;
private Class() { }
public native String getName();
public String getName() {
return new String(name, 0, name.length, false);
}
}

View File

@ -20,6 +20,20 @@ public final class String {
}
}
public String(byte[] data, int offset, int length, boolean copy) {
if (copy) {
byte[] c = new byte[length];
System.arraycopy(data, offset, c, 0, length);
this.data = c;
this.length = length;
} else {
this.data = data;
this.offset = offset;
this.length = length;
}
}
public int length() {
return length;
}

View File

@ -16,6 +16,12 @@ toString(Thread* t, jobject this_)
return pushReference(t, s);
}
jclass
getClass(Thread* t, jobject this_)
{
return pushReference(t, objectClass(t, *this_));
}
void
wait(Thread* t, jobject this_, jlong milliseconds)
{
@ -189,6 +195,8 @@ populate(Thread* t, object map)
} builtins[] = {
{ "Java_java_lang_Object_toString",
reinterpret_cast<void*>(toString) },
{ "Java_java_lang_Object_getClass",
reinterpret_cast<void*>(getClass) },
{ "Java_java_lang_Object_wait",
reinterpret_cast<void*>(wait) },
{ "Java_java_lang_Object_notify",

View File

@ -537,13 +537,15 @@ Thread::Thread(Machine* m, Allocator* allocator, object javaThread,
object arrayClass = arrayBody(t, t->vm->types, Machine::ArrayType);
set(t, cast<object>(t->vm->types, 0), arrayClass);
object objectClass = arrayBody(t, m->types, Machine::JobjectType);
object classClass = arrayBody(t, m->types, Machine::ClassType);
set(t, cast<object>(classClass, 0), classClass);
set(t, classSuper(t, classClass), objectClass);
object intArrayClass = arrayBody(t, m->types, Machine::IntArrayType);
set(t, cast<object>(intArrayClass, 0), classClass);
set(t, classSuper(t, intArrayClass),
arrayBody(t, m->types, Machine::JobjectType));
set(t, classSuper(t, intArrayClass), objectClass);
m->unsafe = false;

View File

@ -568,7 +568,7 @@ parseFieldTable(Thread* t, Stream& s, object class_, object pool)
classFixedSize(t, class_) = pad(memberOffset);
object mask = makeIntArray
(t, divide(classFixedSize(t, class_), BitsPerWord), true);
(t, divide(classFixedSize(t, class_), BitsPerWord * BytesPerWord), true);
intArrayBody(t, mask, 0) = 1;
bool sawReferenceField = false;

View File

@ -71,14 +71,14 @@ cons(Object* car, Object* cdr)
return Pair::make(car, cdr);
}
Object*
Object*&
car(Object* o)
{
assert(o->type == Object::Pair);
return static_cast<Pair*>(o)->car;
}
Object*
Object*&
cdr(Object* o)
{
assert(o->type == Object::Pair);
@ -1514,6 +1514,27 @@ typeCount(Object* declarations)
return count;
}
Object*
reorder(Object* declarations)
{
Object* intArrayType = 0;
Object* classType = 0;
for (Object** p = &declarations; *p;) {
Object* o = car(*p);
if (o->type == Object::Type and equal(typeName(o), "intArray")) {
intArrayType = o;
*p = cdr(*p);
} else if (o->type == Object::Type and equal(typeName(o), "class")) {
classType = o;
*p = cdr(*p);
} else {
p = &cdr(*p);
}
}
return cons(intArrayType, cons(classType, declarations));
}
void
writeInitializations(Output* out, Object* declarations)
{
@ -1530,16 +1551,11 @@ writeInitializations(Output* out, Object* declarations)
out->write(count);
out->write(" * sizeof(void*));\n\n");
for (Object* p = declarations; p; p = cdr(p)) {
Object* o = car(p);
if (o->type == Object::Type and equal(typeName(o), "intArray")) {
writeInitialization(out, o);
}
}
declarations = reorder(declarations);
for (Object* p = declarations; p; p = cdr(p)) {
Object* o = car(p);
if (o->type == Object::Type and not equal(typeName(o), "intArray")) {
if (o->type == Object::Type) {
writeInitialization(out, o);
}
}

View File

@ -1,4 +1,7 @@
(type class
(type jobject java/lang/Object)
(type class java/lang/Class
(extends jobject)
(uint16_t flags)
(uint16_t vmFlags)
(uint16_t fixedSize)
@ -105,9 +108,6 @@
(type array
(noassert array object body))
(type jobject java/lang/Object)
(type string java/lang/String
(extends jobject)
(object data)