diff --git a/makefile b/makefile index 0379753f1b..734c03a2c8 100755 --- a/makefile +++ b/makefile @@ -443,6 +443,7 @@ asm-format = S as = $(cc) ld = $(cc) build-ld = $(build-cc) +build-ld-cpp = $(build-cxx) default-remote-test-host = localhost default-remote-test-port = 22 @@ -1984,7 +1985,7 @@ endif $(generator): $(generator-objects) $(generator-lzma-objects) @echo "linking $(@)" - $(build-ld) $(^) $(build-lflags) -o $(@) + $(build-ld-cpp) $(^) $(build-lflags) -o $(@) $(openjdk-objects): $(build)/openjdk/%-openjdk.o: $(openjdk-src)/%.c \ $(openjdk-headers-dep) diff --git a/src/avian/classpath-common.h b/src/avian/classpath-common.h index 3bddc5f06d..e3f28605f1 100644 --- a/src/avian/classpath-common.h +++ b/src/avian/classpath-common.h @@ -31,9 +31,9 @@ getTrace(Thread* t, unsigned skipCount) if (skipCount == 0) { GcMethod* method = walker->method(); if (isAssignableFrom - (t, type(t, GcThrowable::Type), cast(t, method->class_())) + (t, type(t, GcThrowable::Type), method->class_()) and vm::strcmp(reinterpret_cast(""), - &byteArrayBody(t, method->name(), 0)) + method->name()->body().begin()) == 0) { return true; @@ -266,7 +266,7 @@ clone(Thread* t, object o) reinterpret_cast(o) + 1, size - BytesPerWord); } else { - object classNameSlash = objectClass(t, o)->name(); + object classNameSlash = reinterpret_cast(objectClass(t, o)->name()); THREAD_RUNTIME_ARRAY(t, char, classNameDot, byteArrayLength(t, classNameSlash)); replace('/', '.', RUNTIME_ARRAY_BODY(classNameDot), reinterpret_cast(&byteArrayBody(t, classNameSlash, 0))); @@ -285,7 +285,7 @@ makeStackTraceElement(Thread* t, object e) GcMethod* method = cast(t, traceElementMethod(t, e)); PROTECT(t, method); - object class_name = className(t, method->class_()); + object class_name = reinterpret_cast(method->class_()->name()); PROTECT(t, class_name); THREAD_RUNTIME_ARRAY(t, char, s, byteArrayLength(t, class_name)); @@ -293,7 +293,7 @@ makeStackTraceElement(Thread* t, object e) reinterpret_cast(&byteArrayBody(t, class_name, 0))); class_name = makeString(t, "%s", RUNTIME_ARRAY_BODY(s)); - object method_name = method->name(); + object method_name = reinterpret_cast(method->name()); PROTECT(t, method_name); method_name = t->m->classpath->makeString @@ -302,11 +302,11 @@ makeStackTraceElement(Thread* t, object e) unsigned line = t->m->processor->lineNumber (t, method, traceElementIp(t, e)); - object file = classSourceFile(t, method->class_()); + object file = reinterpret_cast(method->class_()->sourceFile()); file = file ? t->m->classpath->makeString (t, file, 0, byteArrayLength(t, file) - 1) : 0; - return reinterpret_cast(makeStackTraceElement(t, class_name, method_name, file, line)); + return reinterpret_cast(makeStackTraceElement(t, cast(t, class_name), cast(t, method_name), cast(t, file), line)); } object @@ -366,7 +366,7 @@ resolveClassBySpec(Thread* t, object loader, const char* spec, } } -object +GcJclass* resolveJType(Thread* t, object loader, const char* spec, unsigned specLength) { return getJClass(t, resolveClassBySpec(t, loader, spec, specLength)); @@ -452,7 +452,7 @@ resolveParameterJTypes(Thread* t, object loader, object spec, PROTECT(t, array); for (int i = *parameterCount - 1; i >= 0; --i) { - object c = getJClass(t, cast(t, pairFirst(t, list))); + object c = reinterpret_cast(getJClass(t, cast(t, pairFirst(t, list)))); set(t, array, ArrayBody + (i * BytesPerWord), c); list = pairSecond(t, list); } @@ -490,7 +490,7 @@ resolveExceptionJTypes(Thread* t, object loader, object addendum) o); } - o = getJClass(t, cast(t, o)); + o = reinterpret_cast(getJClass(t, cast(t, o))); set(t, array, ArrayBody + (i * BytesPerWord), o); } @@ -516,10 +516,10 @@ invoke(Thread* t, GcMethod* method, object instance, object args) } if (method->parameterCount()) { - unsigned specLength = byteArrayLength(t, method->spec()); + unsigned specLength = method->spec()->length(); THREAD_RUNTIME_ARRAY(t, char, spec, specLength); memcpy(RUNTIME_ARRAY_BODY(spec), - &byteArrayBody(t, method->spec(), 0), specLength); + method->spec()->body().begin(), specLength); unsigned i = 0; for (MethodSpecIterator it(t, RUNTIME_ARRAY_BODY(spec)); it.hasNext();) { GcClass* type; @@ -549,7 +549,7 @@ invoke(Thread* t, GcMethod* method, object instance, object args) memcpy(RUNTIME_ARRAY_BODY(name), p, nameLength - 1); RUNTIME_ARRAY_BODY(name)[nameLength - 1] = 0; type = resolveClass - (t, classLoader(t, method->class_()), + (t, reinterpret_cast(method->class_()->loader()), RUNTIME_ARRAY_BODY(name)); } break; @@ -568,7 +568,7 @@ invoke(Thread* t, GcMethod* method, object instance, object args) } } - initClass(t, cast(t, method->class_())); + initClass(t, method->class_()); unsigned returnCode = method->returnCode(); @@ -706,12 +706,12 @@ getDeclaredClasses(Thread* t, object c, bool publicOnly) and ((not publicOnly) or (innerClassReferenceFlags(t, reference) & ACC_PUBLIC))) { - object inner = getJClass( + object inner = reinterpret_cast(getJClass( t, resolveClass( t, classLoader(t, c), - innerClassReferenceInner(t, arrayBody(t, table, i)))); + innerClassReferenceInner(t, arrayBody(t, table, i))))); -- count; set(t, result, ArrayBody + (count * BytesPerWord), inner); @@ -725,7 +725,7 @@ getDeclaredClasses(Thread* t, object c, bool publicOnly) return makeObjectArray(t, type(t, GcJclass::Type), 0); } -object +GcJclass* getDeclaringClass(Thread* t, object c) { object addendum = classAddendum(t, c); diff --git a/src/avian/machine.h b/src/avian/machine.h index 7fc31e7be9..814354bf10 100644 --- a/src/avian/machine.h +++ b/src/avian/machine.h @@ -1207,6 +1207,7 @@ class GcObject { }; class GcFinalizer; +class GcClassLoader; class Machine { public: @@ -1447,7 +1448,7 @@ class Thread { class LibraryLoadStack: public AutoResource { public: - LibraryLoadStack(Thread* t, object classLoader) + LibraryLoadStack(Thread* t, GcClassLoader* classLoader) : AutoResource(t), next(t->libraryLoadStack), classLoader(classLoader), @@ -1465,7 +1466,7 @@ class Thread { } LibraryLoadStack* next; - object classLoader; + GcClassLoader* classLoader; SingleProtector protector; }; @@ -1634,7 +1635,7 @@ class Classpath { canTailCall(Thread* t, GcMethod* caller, object calleeClassName, object calleeMethodName, object calleeMethodSpec) = 0; - virtual object libraryClassLoader(Thread* t, GcMethod* caller) = 0; + virtual GcClassLoader* libraryClassLoader(Thread* t, GcMethod* caller) = 0; virtual void shutDown(Thread* t) = 0; @@ -1985,6 +1986,12 @@ T* cast(Thread* t UNUSED, object o) #include "type-declarations.cpp" +inline object& +arrayBodyUnsafe(Thread*, object a, unsigned index) +{ + return reinterpret_cast(a)->body()[index]; +} + inline uint64_t runRaw(Thread* t, uint64_t (*function)(Thread*, uintptr_t*), uintptr_t* arguments) @@ -2433,7 +2440,7 @@ inline uint32_t stringHash(Thread* t, object s) { if (stringHashCode(t, s) == 0 and stringLength(t, s)) { - object data = stringData(t, s); + object data = reinterpret_cast(stringData(t, s)); if (objectClass(t, data) == type(t, GcByteArray::Type)) { stringHashCode(t, s) = hash (&byteArrayBody(t, data, stringOffset(t, s)), stringLength(t, s)); @@ -2448,7 +2455,7 @@ stringHash(Thread* t, object s) inline uint16_t stringCharAt(Thread* t, object s, int i) { - object data = stringData(t, s); + object data = reinterpret_cast(stringData(t, s)); if (objectClass(t, data) == type(t, GcByteArray::Type)) { return byteArrayBody(t, data, stringOffset(t, s) + i); } else { @@ -2477,8 +2484,8 @@ inline uint32_t methodHash(Thread* t, object mo) { GcMethod* method = cast(t, mo); - return byteArrayHash(t, method->name()) - ^ byteArrayHash(t, method->spec()); + return byteArrayHash(t, reinterpret_cast(method->name())) + ^ byteArrayHash(t, reinterpret_cast(method->spec())); } inline bool @@ -2487,8 +2494,8 @@ methodEqual(Thread* t, object ao, object bo) GcMethod* a = cast(t, ao); GcMethod* b = cast(t, bo); return a == b or - (byteArrayEqual(t, a->name(), b->name()) and - byteArrayEqual(t, a->spec(), b->spec())); + (byteArrayEqual(t, reinterpret_cast(a->name()), reinterpret_cast(b->name())) and + byteArrayEqual(t, reinterpret_cast(a->spec()), reinterpret_cast(b->spec()))); } class MethodSpecIterator { @@ -2865,7 +2872,7 @@ findInHierarchy(Thread* t, GcClass* class_, object name, object spec, throwNew(t, errorType, "%s %s not found in %s", &byteArrayBody(t, name, 0), &byteArrayBody(t, spec, 0), - &byteArrayBody(t, class_->name(), 0)); + class_->name()->body().begin()); } return o; @@ -2899,10 +2906,10 @@ findInterfaceMethod(Thread* t, GcMethod* method, GcClass* class_) { assertT(t, (class_->vmFlags() & BootstrapFlag) == 0); - object interface = method->class_(); + GcClass* interface = method->class_(); object itable = class_->interfaceTable(); for (unsigned i = 0; i < arrayLength(t, itable); i += 2) { - if (arrayBody(t, itable, i) == interface) { + if (arrayBody(t, itable, i) == reinterpret_cast(interface)) { return cast(t, arrayBody (t, arrayBody(t, itable, i + 1), method->offset())); } @@ -2923,7 +2930,7 @@ objectArrayBody(Thread* t UNUSED, object array, unsigned index) { assertT(t, objectClass(t, array)->fixedSize() == BytesPerWord * 2); assertT(t, objectClass(t, array)->arrayElementSize() == BytesPerWord); - assertT(t, objectClass(t, array)->objectMask() + assertT(t, reinterpret_cast(objectClass(t, array)->objectMask()) == classObjectMask(t, arrayBody (t, t->m->types, GcArray::Type))); return fieldAtOffset(array, ArrayBody + (index * BytesPerWord)); @@ -3462,10 +3469,10 @@ disposeLocalReference(Thread* t, jobject r) } inline bool -methodVirtual(Thread* t, GcMethod* method) +methodVirtual(Thread* t UNUSED, GcMethod* method) { return (method->flags() & (ACC_STATIC | ACC_PRIVATE)) == 0 - and byteArrayBody(t, method->name(), 0) != '<'; + and method->name()->body()[0] != '<'; } inline unsigned @@ -3644,7 +3651,7 @@ inline GcClass* resolveClassInPool(Thread* t, GcMethod* method, unsigned index, bool throw_ = true) { - return resolveClassInPool(t, classLoader(t, method->class_()), + return resolveClassInPool(t, reinterpret_cast(method->class_()->loader()), method, index, throw_); } @@ -3696,7 +3703,7 @@ inline object resolveField(Thread* t, GcMethod* method, unsigned index, bool throw_ = true) { return resolveField - (t, classLoader(t, method->class_()), method, index, throw_); + (t, reinterpret_cast(method->class_()->loader()), method, index, throw_); } inline void @@ -3798,7 +3805,7 @@ inline GcMethod* resolveMethod(Thread* t, GcMethod* method, unsigned index, bool throw_ = true) { return resolveMethod - (t, classLoader(t, method->class_()), method, index, throw_); + (t, reinterpret_cast(method->class_()->loader()), method, index, throw_); } object @@ -3867,25 +3874,25 @@ getMethodRuntimeData(Thread* t, GcMethod* method) method->runtimeDataIndex() - 1); } -inline object +inline GcJclass* getJClass(Thread* t, GcClass* c) { PROTECT(t, c); - object jclass = classRuntimeDataJclass(t, getClassRuntimeData(t, c)); + GcJclass* jclass = cast(t, classRuntimeDataJclass(t, getClassRuntimeData(t, c))); loadMemoryBarrier(); if (jclass == 0) { ACQUIRE(t, t->m->classLock); - jclass = classRuntimeDataJclass(t, getClassRuntimeData(t, c)); + jclass = cast(t, classRuntimeDataJclass(t, getClassRuntimeData(t, c))); if (jclass == 0) { - jclass = t->m->classpath->makeJclass(t, c); + jclass = cast(t, t->m->classpath->makeJclass(t, c)); storeStoreMemoryBarrier(); - set(t, getClassRuntimeData(t, c), ClassRuntimeDataJclass, jclass); + set(t, getClassRuntimeData(t, c), ClassRuntimeDataJclass, reinterpret_cast(jclass)); } } diff --git a/src/avian/process.h b/src/avian/process.h index fd9a005ebc..8fa14dad18 100644 --- a/src/avian/process.h +++ b/src/avian/process.h @@ -37,9 +37,9 @@ codeReadInt32(Thread* t, object code, unsigned& ip) } inline bool -isSuperclass(Thread* t, GcClass* class_, GcClass* base) +isSuperclass(Thread* t UNUSED, GcClass* class_, GcClass* base) { - for (GcClass* oc = cast(t, base->super()); oc; oc = cast(t, oc->super())) { + for (GcClass* oc = base->super(); oc; oc = oc->super()) { if (oc == class_) { return true; } @@ -52,8 +52,8 @@ isSpecialMethod(Thread* t, GcMethod* method, GcClass* class_) { return (class_->flags() & ACC_SUPER) and strcmp(reinterpret_cast(""), - &byteArrayBody(t, method->name(), 0)) != 0 - and isSuperclass(t, cast(t, method->class_()), class_); + method->name()->body().begin()) != 0 + and isSuperclass(t, method->class_(), class_); } void diff --git a/src/builtin.cpp b/src/builtin.cpp index 40ca116b73..72f26ecb67 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -51,7 +51,7 @@ resolveSystemClassThrow(Thread* t, object loader, object spec) object fieldForOffsetInClass(Thread* t, GcClass* c, unsigned offset) { - GcClass* super = cast(t, c->super()); + GcClass* super = c->super(); if (super) { object field = fieldForOffsetInClass(t, super, offset); if (field) { diff --git a/src/classpath-android.cpp b/src/classpath-android.cpp index ee1f6ab4da..667e289da7 100644 --- a/src/classpath-android.cpp +++ b/src/classpath-android.cpp @@ -55,7 +55,8 @@ loadLibrary(Thread* t, object, uintptr_t* arguments) { object name = reinterpret_cast(arguments[1]); - Thread::LibraryLoadStack stack(t, reinterpret_cast(arguments[2])); + Thread::LibraryLoadStack stack( + t, cast(t, reinterpret_cast(arguments[2]))); unsigned length = stringLength(t, name); THREAD_RUNTIME_ARRAY(t, char, n, length + 1); @@ -106,12 +107,12 @@ void JNICALL closeMemoryMappedFile(Thread*, GcMethod*, uintptr_t*); object -makeMethodOrConstructor(Thread* t, object c, unsigned index) +makeMethodOrConstructor(Thread* t, GcJclass* c, unsigned index) { PROTECT(t, c); object method = arrayBody - (t, classMethodTable(t, jclassVmClass(t, c)), index); + (t, classMethodTable(t, c->vmClass()), index); PROTECT(t, method); unsigned parameterCount; @@ -121,7 +122,7 @@ makeMethodOrConstructor(Thread* t, object c, unsigned index) ¶meterCount, &returnTypeSpec); PROTECT(t, parameterTypes); - object returnType = resolveJType + GcJclass* returnType = resolveJType (t, classLoader(t, methodClass(t, method)), reinterpret_cast (&byteArrayBody(t, methodSpec(t, method), returnTypeSpec)), byteArrayLength(t, methodSpec(t, method)) - 1 - returnTypeSpec); @@ -136,9 +137,9 @@ makeMethodOrConstructor(Thread* t, object c, unsigned index) } else { PROTECT(t, exceptionTypes); - object name = t->m->classpath->makeString + GcString* name = cast(t, t->m->classpath->makeString (t, methodName(t, method), 0, - byteArrayLength(t, methodName(t, method)) - 1); + byteArrayLength(t, methodName(t, method)) - 1)); return reinterpret_cast(makeJmethod (t, 0, index, c, name, parameterTypes, exceptionTypes, returnType, 0, 0, @@ -147,16 +148,16 @@ makeMethodOrConstructor(Thread* t, object c, unsigned index) } object -makeField(Thread* t, object c, unsigned index) +makeField(Thread* t, GcJclass* c, unsigned index) { PROTECT(t, c); object field = arrayBody - (t, classFieldTable(t, jclassVmClass(t, c)), index); + (t, classFieldTable(t, c->vmClass()), index); PROTECT(t, field); - object type = getJClass + GcJclass* type = getJClass (t, resolveClassBySpec (t, classLoader(t, fieldClass(t, field)), reinterpret_cast @@ -164,9 +165,9 @@ makeField(Thread* t, object c, unsigned index) byteArrayLength(t, fieldSpec(t, field)) - 1)); PROTECT(t, type); - object name = t->m->classpath->makeString + GcString* name = cast(t, t->m->classpath->makeString (t, fieldName(t, field), 0, - byteArrayLength(t, fieldName(t, field)) - 1); + byteArrayLength(t, fieldName(t, field)) - 1)); return reinterpret_cast(makeJfield(t, 0, c, type, 0, 0, name, index)); } @@ -279,7 +280,7 @@ class MyClasspath : public Classpath { } else { resolveSystemClass (t, root(t, Machine::BootLoader), - type(t, GcThreadGroup::Type)->name(), false); + reinterpret_cast(type(t, GcThreadGroup::Type)->name()), false); group = makeNew(t, type(t, GcThreadGroup::Type)); @@ -291,7 +292,7 @@ class MyClasspath : public Classpath { resolveSystemClass (t, root(t, Machine::BootLoader), - type(t, GcThread::Type)->name(), false); + reinterpret_cast(type(t, GcThread::Type)->name()), false); object thread = makeNew(t, type(t, GcThread::Type)); PROTECT(t, thread); @@ -313,11 +314,11 @@ class MyClasspath : public Classpath { virtual object makeJMethod(Thread* t, GcMethod* vmMethod) { - object table = classMethodTable(t, vmMethod->class_()); + object table = vmMethod->class_()->methodTable(); for (unsigned i = 0; i < arrayLength(t, table); ++i) { if (reinterpret_cast(vmMethod) == arrayBody(t, table, i)) { return makeMethodOrConstructor - (t, getJClass(t, cast(t, vmMethod->class_())), i); + (t, getJClass(t, vmMethod->class_()), i); } } abort(t); @@ -570,15 +571,15 @@ class MyClasspath : public Classpath { return true; } - virtual object libraryClassLoader(Thread* t, GcMethod* caller) + virtual GcClassLoader* libraryClassLoader(Thread* t, GcMethod* caller) { return strcmp( "java/lang/Runtime", reinterpret_cast( - &byteArrayBody(t, className(t, caller->class_()), 0))) + caller->class_()->name()->body().begin())) == 0 ? t->libraryLoadStack->classLoader - : classLoader(t, caller->class_()); + : caller->class_()->loader(); } virtual void @@ -1088,9 +1089,9 @@ extern "C" AVIAN_EXPORT int64_t JNICALL Avian_java_lang_Class_getInterfaces (Thread* t, object, uintptr_t* arguments) { - object c = reinterpret_cast(arguments[0]); + GcJclass* c = cast(t, reinterpret_cast(arguments[0])); - object addendum = classAddendum(t, jclassVmClass(t, c)); + object addendum = classAddendum(t, c->vmClass()); if (addendum) { object table = classAddendumInterfaceTable(t, addendum); if (table) { @@ -1100,8 +1101,8 @@ Avian_java_lang_Class_getInterfaces PROTECT(t, array); for (unsigned i = 0; i < arrayLength(t, table); ++i) { - object c = getJClass(t, cast(t, arrayBody(t, table, i))); - set(t, array, ArrayBody + (i * BytesPerWord), c); + GcJclass* c = getJClass(t, cast(t, arrayBody(t, table, i))); + set(t, array, ArrayBody + (i * BytesPerWord), reinterpret_cast(c)); } return reinterpret_cast(array); @@ -1144,8 +1145,8 @@ Avian_java_lang_Class_getEnclosingMethod if (enclosingClass) { PROTECT(t, enclosingClass); - enclosingClass = getJClass - (t, resolveClass(t, classLoader(t, c), enclosingClass)); + // enclosingClass = getJClass + // (t, resolveClass(t, classLoader(t, c), enclosingClass)); object enclosingMethod = classAddendumEnclosingMethod(t, addendum); if (enclosingMethod) { @@ -1196,16 +1197,16 @@ extern "C" AVIAN_EXPORT int64_t JNICALL Avian_java_lang_Class_getComponentType (Thread* t, object, uintptr_t* arguments) { - object c = reinterpret_cast(arguments[0]); + GcJclass* c = cast(t, reinterpret_cast(arguments[0])); - if (classArrayDimensions(t, jclassVmClass(t, c))) { - uint8_t n = byteArrayBody(t, className(t, jclassVmClass(t, c)), 1); + if (classArrayDimensions(t, c->vmClass())) { + uint8_t n = byteArrayBody(t, className(t, c->vmClass()), 1); if (n != 'L' and n != '[') { return reinterpret_cast (getJClass(t, primitiveClass(t, n))); } else { return reinterpret_cast - (getJClass(t, cast(t, classStaticTable(t, jclassVmClass(t, c))))); + (getJClass(t, cast(t, classStaticTable(t, c->vmClass())))); } } else { return 0; @@ -1235,7 +1236,7 @@ extern "C" AVIAN_EXPORT int64_t JNICALL Avian_java_lang_Class_getDeclaredField (Thread* t, object, uintptr_t* arguments) { - object c = reinterpret_cast(arguments[0]); + GcJclass* c = cast(t, reinterpret_cast(arguments[0])); PROTECT(t, c); object name = reinterpret_cast(arguments[1]); @@ -1247,7 +1248,7 @@ Avian_java_lang_Class_getDeclaredField int index = intValue (t, t->m->processor->invoke - (t, method, 0, jclassVmClass(t, c), name)); + (t, method, 0, c->vmClass(), name)); if (index >= 0) { return reinterpret_cast(local::makeField(t, c, index)); @@ -1260,7 +1261,7 @@ extern "C" AVIAN_EXPORT int64_t JNICALL Avian_java_lang_Class_getDeclaredConstructorOrMethod (Thread* t, object, uintptr_t* arguments) { - object c = reinterpret_cast(arguments[0]); + GcJclass* c = cast(t, reinterpret_cast(arguments[0])); PROTECT(t, c); object name = reinterpret_cast(arguments[1]); @@ -1275,7 +1276,7 @@ Avian_java_lang_Class_getDeclaredConstructorOrMethod int index = intValue (t, t->m->processor->invoke - (t, method, 0, jclassVmClass(t, c), name, parameterTypes)); + (t, method, 0, c->vmClass(), name, parameterTypes)); if (index >= 0) { return reinterpret_cast @@ -1520,13 +1521,13 @@ Avian_dalvik_system_VMStack_getCallingClassLoader if (counter--) { return true; } else { - this->loader = classLoader(t, walker->method()->class_()); + this->loader = walker->method()->class_()->loader(); return false; } } Thread* t; - object loader; + GcClassLoader* loader; unsigned counter; } v(t); @@ -1554,11 +1555,11 @@ Avian_dalvik_system_VMStack_getClasses (t, type(t, GcJclass::Type), walker->count()); } - object c = getJClass(t, cast(t, walker->method()->class_())); + GcJclass* c = getJClass(t, walker->method()->class_()); assertT(t, counter - 2 < objectArrayLength(t, array)); - set(t, array, ArrayBody + ((counter - 2) * BytesPerWord), c); + set(t, array, ArrayBody + ((counter - 2) * BytesPerWord), reinterpret_cast(c)); return true; } @@ -1828,7 +1829,7 @@ extern "C" AVIAN_EXPORT int64_t JNICALL Avian_java_lang_Class_getDeclaredMethods (Thread* t, object, uintptr_t* arguments) { - object c = reinterpret_cast(arguments[0]); + GcJclass* c = cast(t, reinterpret_cast(arguments[0])); PROTECT(t, c); bool publicOnly = arguments[1]; @@ -1838,14 +1839,14 @@ Avian_java_lang_Class_getDeclaredMethods "(Lavian/VMClass;Z)[Ljava/lang/reflect/Method;"); return reinterpret_cast - (t->m->processor->invoke(t, get, 0, jclassVmClass(t, c), publicOnly)); + (t->m->processor->invoke(t, get, 0, c->vmClass(), publicOnly)); } extern "C" AVIAN_EXPORT int64_t JNICALL Avian_java_lang_Class_getDeclaredFields (Thread* t, object, uintptr_t* arguments) { - object c = reinterpret_cast(arguments[0]); + GcJclass* c = cast(t, reinterpret_cast(arguments[0])); PROTECT(t, c); bool publicOnly = arguments[1]; @@ -1855,7 +1856,7 @@ Avian_java_lang_Class_getDeclaredFields "(Lavian/VMClass;Z)[Ljava/lang/reflect/Field;"); return reinterpret_cast - (t->m->processor->invoke(t, get, 0, jclassVmClass(t, c), publicOnly)); + (t->m->processor->invoke(t, get, 0, c->vmClass(), publicOnly)); } extern "C" AVIAN_EXPORT int64_t JNICALL @@ -2282,7 +2283,7 @@ Avian_avian_Classes_makeMethod { return reinterpret_cast (local::makeMethodOrConstructor - (t, reinterpret_cast(arguments[0]), arguments[1])); + (t, cast(t, reinterpret_cast(arguments[0])), arguments[1])); } extern "C" AVIAN_EXPORT int64_t JNICALL @@ -2291,7 +2292,7 @@ Avian_avian_Classes_makeField { return reinterpret_cast (local::makeField - (t, reinterpret_cast(arguments[0]), arguments[1])); + (t, cast(t, reinterpret_cast(arguments[0])), arguments[1])); } extern "C" AVIAN_EXPORT int64_t JNICALL diff --git a/src/classpath-avian.cpp b/src/classpath-avian.cpp index 434a9aa9de..aab301a791 100644 --- a/src/classpath-avian.cpp +++ b/src/classpath-avian.cpp @@ -29,7 +29,7 @@ class MyClasspath : public Classpath { virtual object makeJclass(Thread* t, GcClass* class_) { - return reinterpret_cast(vm::makeJclass(t, reinterpret_cast(class_))); + return reinterpret_cast(vm::makeJclass(t, class_)); } virtual object @@ -53,7 +53,7 @@ class MyClasspath : public Classpath { return reinterpret_cast(vm::makeThread (t, 0, 0, 0, 0, 0, NewState, NormalPriority, 0, 0, 0, - root(t, Machine::AppLoader), 0, 0, group, 0)); + cast(t, root(t, Machine::AppLoader)), 0, 0, cast(t, group), 0)); } virtual object @@ -61,10 +61,10 @@ class MyClasspath : public Classpath { { PROTECT(t, vmMethod); - object jmethod = reinterpret_cast(makeJmethod(t, reinterpret_cast(vmMethod), false)); + object jmethod = reinterpret_cast(makeJmethod(t, vmMethod, false)); - return byteArrayBody(t, vmMethod->name(), 0) == '<' - ? reinterpret_cast(makeJconstructor(t, jmethod)) : jmethod; + return vmMethod->name()->body()[0] == '<' + ? reinterpret_cast(makeJconstructor(t, cast(t, jmethod))) : jmethod; } virtual object @@ -78,7 +78,7 @@ class MyClasspath : public Classpath { virtual object makeJField(Thread* t, object vmField) { - return reinterpret_cast(makeJfield(t, vmField, false)); + return reinterpret_cast(makeJfield(t, cast(t, vmField), false)); } virtual object @@ -204,12 +204,12 @@ class MyClasspath : public Classpath { &byteArrayBody(t, calleeClassName, 0))))); } - virtual object libraryClassLoader(Thread* t, GcMethod* caller) + virtual GcClassLoader* libraryClassLoader(Thread* t, GcMethod* caller) { - return (caller->class_() == reinterpret_cast(type(t, Gc::ClassLoaderType)) + return (caller->class_() == type(t, Gc::ClassLoaderType) and t->libraryLoadStack) ? t->libraryLoadStack->classLoader - : classLoader(t, caller->class_()); + : caller->class_()->loader(); } virtual void @@ -265,7 +265,7 @@ Avian_java_lang_Object_toString unsigned hash = objectHash(t, this_); object s = makeString (t, "%s@0x%x", - &byteArrayBody(t, objectClass(t, this_)->name(), 0), + objectClass(t, this_)->name()->body().begin(), hash); return reinterpret_cast(s); @@ -581,7 +581,7 @@ extern "C" AVIAN_EXPORT int64_t JNICALL Avian_java_lang_ClassLoader_getCaller(Thread* t, object, uintptr_t*) { return reinterpret_cast( - getJClass(t, cast(t, getCaller(t, 2)->class_()))); + getJClass(t, getCaller(t, 2)->class_())); } extern "C" AVIAN_EXPORT void JNICALL @@ -591,7 +591,7 @@ extern "C" AVIAN_EXPORT void JNICALL Thread::LibraryLoadStack stack( t, - classLoader(t, jclassVmClass(t, reinterpret_cast(arguments[1])))); + cast(t, reinterpret_cast(arguments[1]))->vmClass()->loader()); bool mapName = arguments[2]; diff --git a/src/classpath-openjdk.cpp b/src/classpath-openjdk.cpp index ae3af3c4bd..e1284cc8f6 100644 --- a/src/classpath-openjdk.cpp +++ b/src/classpath-openjdk.cpp @@ -331,7 +331,7 @@ getClassName(Thread* t, GcClass* c) } } - return c->name(); + return reinterpret_cast(c->name()); } object @@ -579,7 +579,7 @@ class MyClasspath : public Classpath { { PROTECT(t, vmMethod); - return byteArrayBody(t, vmMethod->name(), 0) == '<' + return vmMethod->name()->body()[0] == '<' ? reinterpret_cast(makeJconstructor(t, reinterpret_cast(vmMethod))) : reinterpret_cast(makeJmethod(t, reinterpret_cast(vmMethod))); } @@ -653,11 +653,11 @@ class MyClasspath : public Classpath { resolveNative(Thread* t, GcMethod* method) { if (strcmp(reinterpret_cast("sun/font/SunFontManager"), - &byteArrayBody(t, className(t, method->class_()), 0)) == 0 + method->class_()->name()->body().begin()) == 0 and strcmp(reinterpret_cast("initIDs"), - &byteArrayBody(t, method->name(), 0)) == 0 + method->name()->body().begin()) == 0 and strcmp(reinterpret_cast("()V"), - &byteArrayBody(t, method->spec(), 0)) == 0) + method->spec()->body().begin()) == 0) { PROTECT(t, method); @@ -692,7 +692,7 @@ class MyClasspath : public Classpath { globalMachine = t->m; resolveSystemClass(t, root(t, Machine::BootLoader), - type(t, GcClassLoader::Type)->name()); + reinterpret_cast(type(t, GcClassLoader::Type)->name())); setRoot(t, Machine::ThreadTerminated, reinterpret_cast(resolveMethod (t, root(t, Machine::BootLoader), "java/lang/ThreadGroup", @@ -844,30 +844,28 @@ class MyClasspath : public Classpath { (&byteArrayBody(t, calleeClassName, 0)))); } - virtual object libraryClassLoader(Thread* t, GcMethod* caller) + virtual GcClassLoader* libraryClassLoader(Thread* t, GcMethod* caller) { #ifdef AVIAN_OPENJDK_SRC - return (caller->class_() == type(t, Machine::ClassLoaderType) - and t->libraryLoadStack) + return (caller->class_() + == type(t, Machine::ClassLoaderType) and t->libraryLoadStack) ? t->libraryLoadStack->classLoader #else - return strcmp( - "java/lang/ClassLoader$NativeLibrary", - reinterpret_cast( - &byteArrayBody(t, className(t, caller->class_()), 0))) - == 0 - ? classLoader( + return strcmp("java/lang/ClassLoader$NativeLibrary", + reinterpret_cast + (caller->class_()->name()->body().begin())) == 0 + ? cast( t, - jclassVmClass(t, - t->m->processor->invoke( - t, - resolveMethod(t, - cast(t, caller->class_()), - "getFromClass", - "()Ljava/lang/Class;"), - 0))) + cast(t, + t->m->processor->invoke( + t, + resolveMethod(t, + caller->class_(), + "getFromClass", + "()Ljava/lang/Class;"), + 0))->vmClass())->loader() #endif - : classLoader(t, caller->class_()); + : caller->class_()->loader(); } virtual void @@ -2236,7 +2234,7 @@ makeJmethod(Thread* t, object vmMethod, int index) ¶meterCount, &returnTypeSpec); PROTECT(t, parameterTypes); - object returnType = resolveJType + GcJclass* returnType = resolveJType (t, classLoader(t, methodClass(t, vmMethod)), reinterpret_cast (&byteArrayBody(t, methodSpec(t, vmMethod), returnTypeSpec)), byteArrayLength(t, methodSpec(t, vmMethod)) - 1 - returnTypeSpec); @@ -2298,12 +2296,12 @@ makeJmethod(Thread* t, object vmMethod, int index) expect(t, index != -1); - object jclass = getJClass(t, cast(t, methodClass(t, vmMethod))); + GcJclass* jclass = getJClass(t, cast(t, methodClass(t, vmMethod))); return reinterpret_cast(makeJmethod - (t, true, 0, jclass, index, name, returnType, parameterTypes, - exceptionTypes, methodFlags(t, vmMethod), signature, 0, annotationTable, - parameterAnnotationTable, annotationDefault, 0, 0, 0)); + (t, true, 0, jclass, index, cast(t, name), returnType, parameterTypes, + exceptionTypes, methodFlags(t, vmMethod), cast(t, signature), 0, cast(t, annotationTable), + cast(t, parameterAnnotationTable), cast(t, annotationDefault), 0, 0, 0)); } object @@ -2368,11 +2366,11 @@ makeJconstructor(Thread* t, object vmMethod, int index) expect(t, index != -1); - object jclass = getJClass(t, cast(t, methodClass(t, vmMethod))); + GcJclass* jclass = getJClass(t, cast(t, methodClass(t, vmMethod))); return reinterpret_cast(makeJconstructor (t, true, 0, jclass, index, parameterTypes, exceptionTypes, methodFlags - (t, vmMethod), signature, 0, annotationTable, parameterAnnotationTable, + (t, vmMethod), cast(t, signature), 0, cast(t, annotationTable), cast(t, parameterAnnotationTable), 0, 0, 0)); } @@ -2394,7 +2392,7 @@ makeJfield(Thread* t, object vmField, int index) byteArrayLength(t, fieldSpec(t, vmField)) - 1); PROTECT(t, type); - object jtype = getJClass(t, type); + GcJclass* jtype = getJClass(t, type); object signature; object annotationTable; @@ -2436,11 +2434,11 @@ makeJfield(Thread* t, object vmField, int index) expect(t, index != -1); - object jclass = getJClass(t, cast(t, fieldClass(t, vmField))); + GcJclass* jclass = getJClass(t, cast(t, fieldClass(t, vmField))); return reinterpret_cast(makeJfield - (t, true, 0, jclass, index, name, jtype, fieldFlags - (t, vmField), signature, 0, annotationTable, 0, 0, 0, 0)); + (t, true, 0, jclass, index, cast(t, name), jtype, fieldFlags + (t, vmField), cast(t, signature), 0, cast(t, annotationTable), 0, 0, 0, 0)); } void @@ -3414,7 +3412,7 @@ jvmDumpThreads(Thread* t, uintptr_t* arguments) unsigned threadsLength = objectArrayLength(t, *threads); GcClass* arrayClass = resolveObjectArrayClass - (t, type(t, GcStackTraceElement::Type)->loader(), + (t, reinterpret_cast(type(t, GcStackTraceElement::Type)->loader()), reinterpret_cast(type(t, GcStackTraceElement::Type))); object result = makeObjectArray(t, arrayClass, threadsLength); PROTECT(t, result); @@ -3478,12 +3476,12 @@ jvmGetClassContext(Thread* t, uintptr_t*) PROTECT(t, context); for (unsigned i = 0; i < objectArrayLength(t, trace); ++i) { - object c = getJClass( + object c = reinterpret_cast(getJClass( t, cast( t, methodClass(t, - traceElementMethod(t, objectArrayBody(t, trace, i))))); + traceElementMethod(t, objectArrayBody(t, trace, i)))))); set(t, context, ArrayBody + (i * BytesPerWord), c); } @@ -3574,11 +3572,11 @@ EXPORT(JVM_LatestUserDefinedLoader)(Thread* t) { } virtual bool visit(Processor::StackWalker* walker) { - object loader = classLoader(t, walker->method()->class_()); + object loader = reinterpret_cast(walker->method()->class_()->loader()); if (loader and loader != root(t, Machine::BootLoader) and strcmp - (&byteArrayBody(t, objectClass(t, loader)->name(), 0), + (objectClass(t, loader)->name()->body().begin(), reinterpret_cast ("sun/reflect/DelegatingClassLoader"))) { @@ -3616,7 +3614,7 @@ jvmGetArrayElement(Thread* t, uintptr_t* arguments) jobject array = reinterpret_cast(arguments[0]); jint index = arguments[1]; - switch (byteArrayBody(t, objectClass(t, *array)->name(), 1)) { + switch (objectClass(t, *array)->name()->body()[1]) { case 'Z': return reinterpret_cast (makeLocalReference @@ -3677,7 +3675,7 @@ EXPORT(JVM_SetArrayElement)(Thread* t, jobject array, jint index, { ENTER(t, Thread::ActiveState); - switch (byteArrayBody(t, objectClass(t, *array)->name(), 1)) { + switch (objectClass(t, *array)->name()->body()[1]) { case 'Z': fieldAtOffset(*array, ArrayBody + index) = booleanValue(t, *value); break; @@ -3806,7 +3804,7 @@ EXPORT(JVM_GetCallerClass)(Thread* t, int target) GcMethod* method = getCaller(t, target, true); return method ? makeLocalReference - (t, getJClass(t, cast(t, method->class_()))) : 0; + (t, reinterpret_cast(getJClass(t, method->class_()))) : 0; } extern "C" AVIAN_EXPORT jclass JNICALL @@ -3818,32 +3816,32 @@ EXPORT(JVM_FindPrimitiveClass)(Thread* t, const char* name) case 'b': if (name[1] == 'o') { return makeLocalReference - (t, getJClass(t, type(t, GcJboolean::Type))); + (t, reinterpret_cast(getJClass(t, type(t, GcJboolean::Type)))); } else { return makeLocalReference - (t, getJClass(t, type(t, GcJbyte::Type))); + (t, reinterpret_cast(getJClass(t, type(t, GcJbyte::Type)))); } case 'c': return makeLocalReference - (t, getJClass(t, type(t, GcJchar::Type))); + (t, reinterpret_cast(getJClass(t, type(t, GcJchar::Type)))); case 'd': return makeLocalReference - (t, getJClass(t, type(t, GcJdouble::Type))); + (t, reinterpret_cast(getJClass(t, type(t, GcJdouble::Type)))); case 'f': return makeLocalReference - (t, getJClass(t, type(t, GcJfloat::Type))); + (t, reinterpret_cast(getJClass(t, type(t, GcJfloat::Type)))); case 'i': return makeLocalReference - (t, getJClass(t, type(t, GcJint::Type))); + (t, reinterpret_cast(getJClass(t, type(t, GcJint::Type)))); case 'l': return makeLocalReference - (t, getJClass(t, type(t, GcJlong::Type))); + (t, reinterpret_cast(getJClass(t, type(t, GcJlong::Type)))); case 's': return makeLocalReference - (t, getJClass(t, type(t, GcJshort::Type))); + (t, reinterpret_cast(getJClass(t, type(t, GcJshort::Type)))); case 'v': return makeLocalReference - (t, getJClass(t, type(t, GcJvoid::Type))); + (t, reinterpret_cast(getJClass(t, type(t, GcJvoid::Type)))); default: throwNew(t, GcIllegalArgumentException::Type); } @@ -3890,7 +3888,7 @@ jvmFindClassFromClassLoader(Thread* t, uintptr_t* arguments) initClass(t, c); } - return reinterpret_cast(makeLocalReference(t, getJClass(t, c))); + return reinterpret_cast(makeLocalReference(t, reinterpret_cast(getJClass(t, c)))); } extern "C" AVIAN_EXPORT jclass JNICALL @@ -3933,7 +3931,7 @@ jvmFindLoadedClass(Thread* t, uintptr_t* arguments) GcClass* c = findLoadedClass(t, *loader, spec); return reinterpret_cast - (c ? makeLocalReference(t, getJClass(t, c)) : 0); + (c ? makeLocalReference(t, reinterpret_cast(getJClass(t, c))) : 0); } extern "C" AVIAN_EXPORT jclass JNICALL @@ -3954,7 +3952,7 @@ jvmDefineClass(Thread* t, uintptr_t* arguments) return reinterpret_cast (makeLocalReference - (t, getJClass(t, cast(t, defineClass(t, *loader, data, length))))); + (t, reinterpret_cast(getJClass(t, cast(t, defineClass(t, *loader, data, length)))))); } extern "C" AVIAN_EXPORT jclass JNICALL @@ -4008,7 +4006,7 @@ jvmGetClassInterfaces(Thread* t, uintptr_t* arguments) PROTECT(t, array); for (unsigned i = 0; i < arrayLength(t, table); ++i) { - object c = getJClass(t, cast(t, arrayBody(t, table, i))); + object c = reinterpret_cast(getJClass(t, cast(t, arrayBody(t, table, i)))); set(t, array, ArrayBody + (i * BytesPerWord), c); } @@ -4043,7 +4041,7 @@ EXPORT(JVM_GetClassLoader)(Thread* t, jclass c) GcMethod* caller = getCaller(t, 2); if (caller and strcmp (reinterpret_cast - (&byteArrayBody(t, className(t, caller->class_()), 0)), + (caller->class_()->name()->body().begin()), "sun/misc/Unsafe") == 0) { return 0; @@ -4152,11 +4150,11 @@ jvmGetComponentType(Thread* t, uintptr_t* arguments) uint8_t n = byteArrayBody(t, className(t, jclassVmClass(t, *c)), 1); if (n != 'L' and n != '[') { return reinterpret_cast - (makeLocalReference(t, getJClass(t, primitiveClass(t, n)))); + (makeLocalReference(t, reinterpret_cast(getJClass(t, primitiveClass(t, n))))); } else { return reinterpret_cast (makeLocalReference - (t, getJClass(t, cast(t, classStaticTable(t, jclassVmClass(t, *c)))))); + (t, reinterpret_cast(getJClass(t, cast(t, classStaticTable(t, jclassVmClass(t, *c))))))); } } else { return 0; @@ -4208,8 +4206,8 @@ jvmGetDeclaringClass(Thread* t, uintptr_t* arguments) { return reinterpret_cast (makeLocalReference - (t, getDeclaringClass - (t, jclassVmClass(t, *reinterpret_cast(arguments[0]))))); + (t, reinterpret_cast(getDeclaringClass + (t, jclassVmClass(t, *reinterpret_cast(arguments[0])))))); } extern "C" AVIAN_EXPORT jclass JNICALL @@ -4429,7 +4427,7 @@ jvmInvokeMethod(Thread* t, uintptr_t* arguments) instance = 0; } - if (instance and not instanceOf(t, cast(t, vmMethod->class_()), *instance)) { + if (instance and not instanceOf(t, vmMethod->class_(), *instance)) { throwNew(t, GcIllegalArgumentException::Type); } @@ -5260,8 +5258,8 @@ getEnclosingMethodInfo(Thread* t, uintptr_t* arguments) object array = makeObjectArray(t, type(t, GcJobject::Type), 3); PROTECT(t, array); - enclosingClass = getJClass - (t, resolveClass(t, classLoader(t, class_), enclosingClass)); + enclosingClass = reinterpret_cast(getJClass + (t, resolveClass(t, classLoader(t, class_), enclosingClass))); set(t, array, ArrayBody, enclosingClass); diff --git a/src/compile.cpp b/src/compile.cpp index afdf3c5946..e5559c5925 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -318,7 +318,7 @@ GcMethod* findMethod(Thread* t, GcMethod* method, object instance) { if ((method->flags() & ACC_STATIC) == 0) { - if (classFlags(t, method->class_()) & ACC_INTERFACE) { + if (method->class_()->flags() & ACC_INTERFACE) { return findInterfaceMethod(t, method, objectClass(t, instance)); } else if (methodVirtual(t, method)) { return findVirtualMethod(t, method, objectClass(t, instance)); @@ -336,10 +336,10 @@ resolveTarget(MyThread* t, void* stack, GcMethod* method) PROTECT(t, method); PROTECT(t, class_); - resolveSystemClass(t, root(t, Machine::BootLoader), class_->name()); + resolveSystemClass(t, root(t, Machine::BootLoader), reinterpret_cast(class_->name())); } - if (classFlags(t, method->class_()) & ACC_INTERFACE) { + if (method->class_()->flags() & ACC_INTERFACE) { return findInterfaceMethod(t, method, class_); } else { return findVirtualMethod(t, method, class_); @@ -352,7 +352,7 @@ resolveTarget(MyThread* t, GcClass* class_, unsigned index) if (class_->vmFlags() & BootstrapFlag) { PROTECT(t, class_); - resolveSystemClass(t, root(t, Machine::BootLoader), class_->name()); + resolveSystemClass(t, root(t, Machine::BootLoader), reinterpret_cast(class_->name())); } return cast(t, arrayBody(t, class_->virtualTable(), index)); @@ -456,11 +456,11 @@ nextFrame(MyThread* t, void** ip, void** sp, GcMethod* method, GcMethod* target, } // fprintf(stderr, "nextFrame %s.%s%s target %s.%s%s ip %p sp %p\n", - // &byteArrayBody(t, className(t, method->class_()), 0), - // &byteArrayBody(t, method->name(), 0), - // &byteArrayBody(t, method->spec(), 0), + // method->class_()->name()->body().begin(), + // method->name()->body().begin(), + // method->spec()->body().begin(), // target - // ? &byteArrayBody(t, className(t, target->class_()), 0) + // ? &byteArrayBody(t, target->class_()->name(), 0) // : 0, // target // ? &byteArrayBody(t, methodName(t, target), 0) @@ -2006,7 +2006,7 @@ releaseLock(MyThread* t, GcMethod* method, void* stack) if (t->methodLockIsClean) { object lock; if (method->flags() & ACC_STATIC) { - lock = method->class_(); + lock = reinterpret_cast(method->class_()); } else { lock = *localObject (t, stackForFrame(t, stack, method), method, @@ -2301,9 +2301,9 @@ prepareMethodForCall(MyThread* t, GcMethod* target) { if (methodAbstract(t, target)) { throwNew(t, GcAbstractMethodError::Type, "%s.%s%s", - &byteArrayBody(t, className(t, target->class_()), 0), - &byteArrayBody(t, target->name(), 0), - &byteArrayBody(t, target->spec(), 0)); + target->class_()->name()->body().begin(), + target->name()->body().begin(), + target->spec()->body().begin()); } else { if (unresolved(t, methodAddress(t, target))) { PROTECT(t, target); @@ -2347,9 +2347,9 @@ checkMethod(Thread* t, GcMethod* method, bool shouldBeStatic) if (((method->flags() & ACC_STATIC) == 0) == shouldBeStatic) { throwNew(t, GcIncompatibleClassChangeError::Type, "expected %s.%s%s to be %s", - &byteArrayBody(t, className(t, method->class_()), 0), - &byteArrayBody(t, method->name(), 0), - &byteArrayBody(t, method->spec(), 0), + method->class_()->name()->body().begin(), + method->name()->body().begin(), + method->spec()->body().begin(), shouldBeStatic ? "static" : "non-static"); } } @@ -2375,7 +2375,7 @@ findSpecialMethodFromReference(MyThread* t, object pair) GcClass* class_ = cast(t, methodClass(t, pairFirst(t, pair))); if (isSpecialMethod(t, target, class_)) { - target = findVirtualMethod(t, target, cast(t, class_->super())); + target = findVirtualMethod(t, target, class_->super()); } checkMethod(t, target, false); @@ -2440,8 +2440,8 @@ traceSize(Thread* t) t->m->processor->walkStack(t, &counter); - return GcArray::FixedSize + (counter.count * ArrayElementSizeOfArray) - + (counter.count * GcTraceElement::FixedSize); + return pad(GcArray::FixedSize) + (counter.count * pad(ArrayElementSizeOfArray)) + + (counter.count * pad(GcTraceElement::FixedSize)); } void NO_RETURN @@ -2690,8 +2690,8 @@ void checkCast(MyThread* t, GcClass* class_, object o) { if (UNLIKELY(o and not isAssignableFrom(t, class_, objectClass(t, o)))) { - object classNameFrom = objectClass(t, o)->name(); - object classNameTo = class_->name(); + object classNameFrom = reinterpret_cast(objectClass(t, o)->name()); + object classNameTo = reinterpret_cast(class_->name()); THREAD_RUNTIME_ARRAY(t, char, classFrom, byteArrayLength(t, classNameFrom)); THREAD_RUNTIME_ARRAY(t, char, classTo, byteArrayLength(t, classNameTo)); replace('/', '.', RUNTIME_ARRAY_BODY(classFrom), @@ -3121,7 +3121,7 @@ compileDirectInvoke(MyThread* t, Frame* frame, GcMethod* target, bool tailCall) // don't bother calling an empty method unless calling it might // cause the class to be initialized, which may have side effects if (emptyMethod(t, target) - and (not classNeedsInit(t, cast(t, target->class_())))) + and (not classNeedsInit(t, target->class_()))) { frame->popFootprint(target->parameterFootprint()); tailCall = false; @@ -3129,7 +3129,7 @@ compileDirectInvoke(MyThread* t, Frame* frame, GcMethod* target, bool tailCall) BootContext* bc = frame->context->bootContext; if (bc) { if ((target->class_() == frame->context->method->class_() - or (not classNeedsInit(t, cast(t, target->class_())))) + or (not classNeedsInit(t, target->class_()))) and (not (avian::codegen::TailCalls and tailCall and (target->flags() & ACC_NATIVE)))) { @@ -3144,7 +3144,7 @@ compileDirectInvoke(MyThread* t, Frame* frame, GcMethod* target, bool tailCall) compileDirectInvoke(t, frame, target, tailCall, true, 0); } } else if (unresolved(t, methodAddress(t, target)) - or classNeedsInit(t, cast(t, target->class_()))) + or classNeedsInit(t, target->class_())) { compileDirectInvoke(t, frame, target, tailCall, true, 0); } else { @@ -3230,7 +3230,7 @@ handleMonitorEvent(MyThread* t, Frame* frame, intptr_t function) if (method->flags() & ACC_STATIC) { PROTECT(t, method); - lock = frame->append(method->class_()); + lock = frame->append(reinterpret_cast(method->class_())); } else { lock = loadLocal( frame->context, 1, ir::Type::object(), savedTargetIndex(t, method)); @@ -3294,10 +3294,10 @@ inTryBlock(MyThread* t, object code, unsigned ip) } bool -needsReturnBarrier(MyThread* t, GcMethod* method) +needsReturnBarrier(MyThread* t UNUSED, GcMethod* method) { return (method->flags() & ConstructorFlag) - and (classVmFlags(t, method->class_()) & HasFinalMemberFlag); + and (method->class_()->vmFlags() & HasFinalMemberFlag); } bool @@ -3354,8 +3354,8 @@ isTailCall(MyThread* t, object code, unsigned ip, GcMethod* caller, GcMethod* ca { return isTailCall (t, code, ip, caller, callee->returnCode(), - className(t, callee->class_()), callee->name(), - callee->spec()); + reinterpret_cast(callee->class_()->name()), reinterpret_cast(callee->name()), + reinterpret_cast(callee->spec())); } bool @@ -3531,14 +3531,14 @@ ir::Value* popLongAddress(Frame* frame) } bool -intrinsic(MyThread* t, Frame* frame, GcMethod* target) +intrinsic(MyThread* t UNUSED, Frame* frame, GcMethod* target) { #define MATCH(name, constant) \ - (byteArrayLength(t, name) \ + (name->length() \ == sizeof(constant) and::strcmp( \ - reinterpret_cast(&byteArrayBody(t, name, 0)), constant) == 0) + reinterpret_cast(name->body().begin()), constant) == 0) - object className = vm::className(t, target->class_()); + GcByteArray* className = target->class_()->name(); if (UNLIKELY(MATCH(className, "java/lang/Math"))) { avian::codegen::Compiler* c = frame->c; if (MATCH(target->name(), "sqrt") and MATCH(target->spec(), "(D)D")) { @@ -4970,9 +4970,9 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, GcMethod* target = resolveMethod(t, context->method, index - 1, false); if (LIKELY(target)) { - GcClass* class_ = cast(t, context->method->class_()); + GcClass* class_ = context->method->class_(); if (isSpecialMethod(t, target, class_)) { - target = findVirtualMethod(t, target, cast(t, class_->super())); + target = findVirtualMethod(t, target, class_->super()); } checkMethod(t, target, false); @@ -6751,22 +6751,22 @@ finish(MyThread* t, FixedAllocator* allocator, Context* context) logCompile (t, 0, 0, reinterpret_cast - (&byteArrayBody(t, className(t, context->method->class_()), 0)), + (context->method->class_()->name()->body().begin()), reinterpret_cast - (&byteArrayBody(t, context->method->name(), 0)), + (context->method->name()->body().begin()), reinterpret_cast - (&byteArrayBody(t, context->method->spec(), 0))); + (context->method->spec()->body().begin())); } // for debugging: if (false and ::strcmp (reinterpret_cast - (&byteArrayBody(t, className(t, context->method->class_()), 0)), + (context->method->class_()->name()->body().begin()), "java/lang/System") == 0 and ::strcmp (reinterpret_cast - (&byteArrayBody(t, context->method->name(), 0)), + (context->method->name()->body().begin()), "") == 0) { trap(); @@ -6804,7 +6804,7 @@ finish(MyThread* t, FixedAllocator* allocator, Context* context) context->executableSize = (allocator->memory.begin() + allocator->offset) - static_cast(context->executableStart); - initArray(t, pool, context->objectPoolCount + 1); + initArray(t, reinterpret_cast(pool), context->objectPoolCount + 1); mark(t, pool, 0); set(t, pool, ArrayBody, root(t, ObjectPools)); @@ -6883,21 +6883,21 @@ finish(MyThread* t, FixedAllocator* allocator, Context* context) logCompile (t, start, codeSize, reinterpret_cast - (&byteArrayBody(t, className(t, context->method->class_()), 0)), + (context->method->class_()->name()->body().begin()), reinterpret_cast - (&byteArrayBody(t, context->method->name(), 0)), + (context->method->name()->body().begin()), reinterpret_cast - (&byteArrayBody(t, context->method->spec(), 0))); + (context->method->spec()->body().begin())); // for debugging: if (false and ::strcmp (reinterpret_cast - (&byteArrayBody(t, className(t, context->method->class_()), 0)), + (context->method->class_()->name()->body().begin()), "java/lang/System") == 0 and ::strcmp (reinterpret_cast - (&byteArrayBody(t, context->method->name(), 0)), + (context->method->name()->body().begin()), "") == 0) { trap(); @@ -6913,9 +6913,9 @@ compile(MyThread* t, Context* context) avian::codegen::Compiler* c = context->compiler; // fprintf(stderr, "compiling %s.%s%s\n", -// &byteArrayBody(t, className(t, context->method->class_()), 0), -// &byteArrayBody(t, context->method->name(), 0), -// &byteArrayBody(t, context->method->spec(), 0)); +// context->method->class_()->name()->body().begin(), +// context->method->name()->body().begin(), +// context->method->spec()->body().begin()); unsigned footprint = context->method->parameterFootprint(); unsigned locals = localSize(t, context->method); @@ -6934,7 +6934,7 @@ compile(MyThread* t, Context* context) for (MethodSpecIterator it (t, reinterpret_cast - (&byteArrayBody(t, context->method->spec(), 0))); + (context->method->spec()->body().begin())); it.hasNext();) { switch (*it.next()) { @@ -7148,11 +7148,11 @@ invokeNativeSlow(MyThread* t, GcMethod* method, void* function) + t->arch->frameFooterSize() + t->arch->frameReturnAddressSize(); - object jclass = 0; + GcJclass* jclass = 0; PROTECT(t, jclass); if (method->flags() & ACC_STATIC) { - jclass = getJClass(t, cast(t, method->class_())); + jclass = getJClass(t, method->class_()); RUNTIME_ARRAY_BODY(args)[argOffset++] = reinterpret_cast(&jclass); } else { @@ -7163,7 +7163,7 @@ invokeNativeSlow(MyThread* t, GcMethod* method, void* function) MethodSpecIterator it (t, reinterpret_cast - (&byteArrayBody(t, method->spec(), 0))); + (method->spec()->body().begin())); while (it.hasNext()) { unsigned type = RUNTIME_ARRAY_BODY(types)[typeOffset++] @@ -7204,13 +7204,13 @@ invokeNativeSlow(MyThread* t, GcMethod* method, void* function) if (DebugNatives) { fprintf(stderr, "invoke native method %s.%s\n", - &byteArrayBody(t, className(t, method->class_()), 0), - &byteArrayBody(t, method->name(), 0)); + method->class_()->name()->body().begin(), + method->name()->body().begin()); } if (method->flags() & ACC_SYNCHRONIZED) { if (method->flags() & ACC_STATIC) { - acquire(t, method->class_()); + acquire(t, reinterpret_cast(method->class_())); } else { acquire(t, *reinterpret_cast(RUNTIME_ARRAY_BODY(args)[1])); } @@ -7234,7 +7234,7 @@ invokeNativeSlow(MyThread* t, GcMethod* method, void* function) if (method->flags() & ACC_SYNCHRONIZED) { if (method->flags() & ACC_STATIC) { - release(t, method->class_()); + release(t, reinterpret_cast(method->class_())); } else { release(t, *reinterpret_cast(RUNTIME_ARRAY_BODY(args)[1])); } @@ -7242,8 +7242,8 @@ invokeNativeSlow(MyThread* t, GcMethod* method, void* function) if (DebugNatives) { fprintf(stderr, "return from native method %s.%s\n", - &byteArrayBody(t, className(t, method->class_()), 0), - &byteArrayBody(t, method->name(), 0)); + method->class_()->name()->body().begin(), + method->name()->body().begin()); } if (UNLIKELY(t->exception)) { @@ -7498,7 +7498,7 @@ visitArguments(MyThread* t, Heap::Visitor* v, void* stack, GcMethod* method) for (MethodSpecIterator it (t, reinterpret_cast - (&byteArrayBody(t, method->spec(), 0))); + (method->spec()->body().begin())); it.hasNext();) { switch (*it.next()) { @@ -7633,7 +7633,7 @@ callContinuation(MyThread* t, object continuation, object result, int8_t* returnSpec(MyThread* t, GcMethod* method) { - int8_t* s = &byteArrayBody(t, method->spec(), 0); + int8_t* s = method->spec()->body().begin(); while (*s and *s != ')') ++ s; expect(t, *s == ')'); return s + 1; @@ -7657,7 +7657,7 @@ returnClass(MyThread* t, GcMethod* method) memcpy(&byteArrayBody(t, name, 0), spec + 1, length - 2); } - return resolveClass(t, classLoader(t, method->class_()), name); + return resolveClass(t, reinterpret_cast(method->class_()->loader()), name); } bool @@ -7769,7 +7769,7 @@ callContinuation(MyThread* t, object continuation, object result, and continuationContextContinuation(t, unwindContext)) { nextContinuation = continuationContextContinuation(t, unwindContext); - result = reinterpret_cast(makeUnwindResult(t, continuation, result, exception)); + result = reinterpret_cast(makeUnwindResult(t, continuation, result, cast(t, exception))); action = Unwind; } else if (rewindContext and continuationContextContinuation(t, rewindContext)) @@ -8186,7 +8186,7 @@ class SignalHandler: public SignalRegistrar::Handler { static_cast(*stack) - t->arch->frameReturnAddressSize(), t->continuation, t->trace); - if (ensure(t, fixedSize + traceSize(t))) { + if (ensure(t, pad(fixedSize) + traceSize(t))) { atomicOr(&(t->flags), Thread::TracingFlag); t->exception = makeThrowable(t, type); atomicAnd(&(t->flags), ~Thread::TracingFlag); @@ -8454,10 +8454,10 @@ class MyProcessor: public Processor { offset, 0, 0, - reinterpret_cast(name), - reinterpret_cast(spec), - addendum, - reinterpret_cast(class_), + name, + spec, + cast(t, addendum), + class_, reinterpret_cast(code)); } @@ -8488,17 +8488,17 @@ class MyProcessor: public Processor { arrayElementSize, arrayDimensions, 0, - objectMask, - name, - sourceFile, - super, + cast(t, objectMask), + cast(t, name), + cast(t, sourceFile), + cast(t, super), interfaceTable, virtualTable, fieldTable, methodTable, - staticTable, + reinterpret_cast(staticTable), // DANGER DANGER DANGER!!!!!!!!! addendum, - loader, + cast(t, loader), 0, vtableLength); } @@ -8626,7 +8626,7 @@ class MyProcessor: public Processor { method = findMethod(t, method, this_); const char* spec = reinterpret_cast - (&byteArrayBody(t, method->spec(), 0)); + (method->spec()->body().begin()); unsigned size = method->parameterFootprint(); THREAD_RUNTIME_ARRAY(t, uintptr_t, array, size); @@ -8656,7 +8656,7 @@ class MyProcessor: public Processor { method = findMethod(t, method, this_); const char* spec = reinterpret_cast - (&byteArrayBody(t, method->spec(), 0)); + (method->spec()->body().begin()); unsigned size = method->parameterFootprint(); THREAD_RUNTIME_ARRAY(t, uintptr_t, array, size); @@ -8687,7 +8687,7 @@ class MyProcessor: public Processor { method = findMethod(t, method, this_); const char* spec = reinterpret_cast - (&byteArrayBody(t, method->spec(), 0)); + (method->spec()->body().begin()); unsigned size = method->parameterFootprint(); THREAD_RUNTIME_ARRAY(t, uintptr_t, array, size); @@ -9484,11 +9484,11 @@ fixupMethods(Thread* t, GcHashMap* map, BootImage* image UNUSED, uint8_t* code) reinterpret_cast(methodCompiled(t, method)), methodCompiledSize(t, method), reinterpret_cast - (&byteArrayBody(t, className(t, method->class_()), 0)), + (method->class_()->name()->body().begin()), reinterpret_cast - (&byteArrayBody(t, method->name(), 0)), + (method->name()->body().begin()), reinterpret_cast - (&byteArrayBody(t, method->spec(), 0))); + (method->spec()->body().begin())); } } } @@ -10007,7 +10007,7 @@ compile(MyThread* t, FixedAllocator* allocator, BootContext* bootContext, PROTECT(t, method); if (bootContext == 0 and method->flags() & ACC_STATIC) { - initClass(t, cast(t, method->class_())); + initClass(t, method->class_()); } if (methodAddress(t, method) != defaultThunk(t)) { @@ -10091,7 +10091,7 @@ compile(MyThread* t, FixedAllocator* allocator, BootContext* bootContext, set(t, reinterpret_cast(method), MethodCode, clone->code()); if (methodVirtual(t, method)) { - classVtable(t, method->class_(), method->offset()) + classVtable(t, reinterpret_cast(method->class_()), method->offset()) = reinterpret_cast(methodCompiled(t, clone)); } diff --git a/src/interpret.cpp b/src/interpret.cpp index f236848149..2b5c539bef 100644 --- a/src/interpret.cpp +++ b/src/interpret.cpp @@ -318,7 +318,7 @@ pushFrame(Thread* t, GcMethod* method) // to release a monitor we never successfully acquired when we try // to pop the frame back off. if (method->flags() & ACC_STATIC) { - acquire(t, method->class_()); + acquire(t, reinterpret_cast(method->class_())); } else { acquire(t, peekObject(t, base)); } @@ -356,7 +356,7 @@ popFrame(Thread* t) if (method->flags() & ACC_SYNCHRONIZED) { if (method->flags() & ACC_STATIC) { - release(t, method->class_()); + release(t, reinterpret_cast(method->class_())); } else { release(t, peekObject(t, frameBase(t, t->frame))); } @@ -494,7 +494,7 @@ marshalArguments(Thread* t, uintptr_t* args, uint8_t* types, unsigned sp, { MethodSpecIterator it (t, reinterpret_cast - (&byteArrayBody(t, method->spec(), 0))); + (method->spec()->body().begin())); unsigned argOffset = 0; unsigned typeOffset = 0; @@ -565,7 +565,7 @@ invokeNativeSlow(Thread* t, GcMethod* method, void* function) unsigned sp; if (method->flags() & ACC_STATIC) { sp = frameBase(t, t->frame); - jclass = getJClass(t, cast(t, method->class_())); + jclass = getJClass(t, method->class_()); RUNTIME_ARRAY_BODY(args)[argOffset++] = reinterpret_cast(&jclass); } else { @@ -588,8 +588,8 @@ invokeNativeSlow(Thread* t, GcMethod* method, void* function) if (DebugRun) { fprintf(stderr, "invoke native method %s.%s\n", - &byteArrayBody(t, className(t, method->class_()), 0), - &byteArrayBody(t, method->name(), 0)); + method->class_()->name()->body().begin(), + method->name()->body().begin()); } { ENTER(t, Thread::IdleState); @@ -608,10 +608,8 @@ invokeNativeSlow(Thread* t, GcMethod* method, void* function) if (DebugRun) { fprintf(stderr, "return from native method %s.%s\n", - &byteArrayBody - (t, className(t, frameMethod(t, t->frame)->class_()), 0), - &byteArrayBody - (t, frameMethod(t, t->frame)->name(), 0)); + frameMethod(t, t->frame)->class_()->name()->body().begin(), + frameMethod(t, t->frame)->name()->body().begin()); } popFrame(t); @@ -797,10 +795,8 @@ interpret3(Thread* t, const int base) fprintf(stderr, "ip: %d; instruction: 0x%x in %s.%s ", ip - 1, instruction, - &byteArrayBody - (t, className(t, frameMethod(t, frame)->class_()), 0), - &byteArrayBody - (t, frameMethod(t, frame)->name(), 0)); + frameMethod(t, frame)->class_()->name()->body().begin(), + frameMethod(t, frame)->name()->body().begin()); int line = findLineNumber(t, frameMethod(t, frame), ip); switch (line) { @@ -1076,9 +1072,8 @@ interpret3(Thread* t, const int base) if (not instanceOf(t, class_, peekObject(t, sp - 1))) { exception = makeThrowable (t, GcClassCastException::Type, "%s as %s", - &byteArrayBody - (t, objectClass(t, peekObject(t, sp - 1))->name(), 0), - &byteArrayBody(t, class_->name(), 0)); + objectClass(t, peekObject(t, sp - 1))->name()->body().begin(), + class_->name()->body().begin()); goto throw_; } } @@ -1862,9 +1857,9 @@ interpret3(Thread* t, const int base) unsigned parameterFootprint = method->parameterFootprint(); if (LIKELY(peekObject(t, sp - parameterFootprint))) { - GcClass* class_ = cast(t, frameMethod(t, frame)->class_()); + GcClass* class_ = frameMethod(t, frame)->class_(); if (isSpecialMethod(t, method, class_)) { - class_ = cast(t, class_->super()); + class_ = class_->super(); PROTECT(t, method); PROTECT(t, class_); @@ -1888,7 +1883,7 @@ interpret3(Thread* t, const int base) GcMethod* method = resolveMethod(t, frameMethod(t, frame), index - 1); PROTECT(t, method); - initClass(t, cast(t, method->class_())); + initClass(t, method->class_()); code = reinterpret_cast(method); } goto invoke; @@ -2563,7 +2558,7 @@ interpret3(Thread* t, const int base) case return_: { GcMethod* method = frameMethod(t, frame); if ((method->flags() & ConstructorFlag) - and (classVmFlags(t, method->class_()) & HasFinalMemberFlag)) + and (method->class_()->vmFlags() & HasFinalMemberFlag)) { storeStoreMemoryBarrier(); } @@ -2670,8 +2665,8 @@ interpret3(Thread* t, const int base) GcClass* class_ = objectClass(t, peekObject(t, sp - parameterFootprint)); assertT(t, class_->vmFlags() & BootstrapFlag); - resolveClass(t, classLoader(t, frameMethod(t, frame)->class_()), - class_->name()); + resolveClass(t, reinterpret_cast(frameMethod(t, frame)->class_()->loader()), + reinterpret_cast(class_->name())); ip -= 3; } goto loop; @@ -2896,16 +2891,16 @@ invoke(Thread* t, GcMethod* method) class_ = objectClass(t, peekObject(t, t->sp - parameterFootprint)); if (class_->vmFlags() & BootstrapFlag) { - resolveClass(t, root(t, Machine::BootLoader), class_->name()); + resolveClass(t, root(t, Machine::BootLoader), reinterpret_cast(class_->name())); } - if (classFlags(t, method->class_()) & ACC_INTERFACE) { + if (method->class_()->flags() & ACC_INTERFACE) { method = findInterfaceMethod(t, method, class_); } else { method = findVirtualMethod(t, method, class_); } } else { - class_ = cast(t, method->class_()); + class_ = method->class_(); } if (method->flags() & ACC_STATIC) { @@ -3001,10 +2996,10 @@ class MyProcessor: public Processor { offset, 0, 0, - reinterpret_cast(name), - reinterpret_cast(spec), - addendum, - reinterpret_cast(class_), + name, + spec, + cast(t, addendum), + class_, reinterpret_cast(code)); } @@ -3028,10 +3023,26 @@ class MyProcessor: public Processor { object loader, unsigned vtableLength UNUSED) { - return vm::makeClass - (t, flags, vmFlags, fixedSize, arrayElementSize, arrayDimensions, 0, - objectMask, name, sourceFile, super, interfaceTable, virtualTable, - fieldTable, methodTable, addendum, staticTable, loader, 0, 0); + return vm::makeClass(t, + flags, + vmFlags, + fixedSize, + arrayElementSize, + arrayDimensions, + 0, + cast(t, objectMask), + cast(t, name), + cast(t, sourceFile), + cast(t, super), + interfaceTable, + virtualTable, + fieldTable, + methodTable, + cast(t, addendum), + staticTable, + cast(t, loader), + 0, + 0); } virtual void @@ -3133,7 +3144,7 @@ class MyProcessor: public Processor { } const char* spec = reinterpret_cast - (&byteArrayBody(t, method->spec(), 0)); + (method->spec()->body().begin()); pushArguments(t, this_, spec, arguments); return local::invoke(t, method); @@ -3157,7 +3168,7 @@ class MyProcessor: public Processor { } const char* spec = reinterpret_cast - (&byteArrayBody(t, method->spec(), 0)); + (method->spec()->body().begin()); pushArguments(t, this_, spec, arguments); return local::invoke(t, method); @@ -3181,7 +3192,7 @@ class MyProcessor: public Processor { } const char* spec = reinterpret_cast - (&byteArrayBody(t, method->spec(), 0)); + (method->spec()->body().begin()); pushArguments(t, this_, spec, indirectObjects, arguments); return local::invoke(t, method); diff --git a/src/jnienv.cpp b/src/jnienv.cpp index 0c48b5bd21..aa709dc287 100644 --- a/src/jnienv.cpp +++ b/src/jnienv.cpp @@ -323,11 +323,11 @@ defineClass(Thread* t, uintptr_t* arguments) return reinterpret_cast(makeLocalReference( t, - getJClass(t, + reinterpret_cast(getJClass(t, cast(t, defineClass(t, loader ? *loader : root(t, Machine::BootLoader), buffer, - length))))); + length)))))); } jclass JNICALL @@ -351,10 +351,12 @@ findClass(Thread* t, uintptr_t* arguments) GcMethod* caller = getCaller(t, 0); - GcClass* c = resolveClass(t, - caller ? t->m->classpath->libraryClassLoader(t, caller) - : root(t, Machine::AppLoader), - n); + GcClass* c = resolveClass( + t, + caller ? reinterpret_cast + (t->m->classpath->libraryClassLoader(t, caller)) + : root(t, Machine::AppLoader), + n); if (t->m->classpath->mayInitClasses()) { PROTECT(t, c); @@ -362,7 +364,7 @@ findClass(Thread* t, uintptr_t* arguments) initClass(t, c); } - return reinterpret_cast(makeLocalReference(t, getJClass(t, c))); + return reinterpret_cast(makeLocalReference(t, reinterpret_cast(getJClass(t, c)))); } jclass JNICALL @@ -451,7 +453,7 @@ getObjectClass(Thread* t, uintptr_t* arguments) jobject o = reinterpret_cast(arguments[0]); return reinterpret_cast(makeLocalReference( - t, getJClass(t, objectClass(t, *o)))); + t, reinterpret_cast(getJClass(t, objectClass(t, *o))))); } jclass JNICALL @@ -471,7 +473,7 @@ getSuperclass(Thread* t, uintptr_t* arguments) } else { object super = classSuper(t, class_); return super ? reinterpret_cast - (makeLocalReference(t, getJClass(t, cast(t, super)))) : 0; + (makeLocalReference(t, reinterpret_cast(getJClass(t, cast(t, super))))) : 0; } } diff --git a/src/machine.cpp b/src/machine.cpp index eb92ed8132..28a8b696c4 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -738,7 +738,7 @@ invoke(Thread* t, uintptr_t* arguments) void finalizeObject(Thread* t, object o, const char* name) { - for (GcClass* c = objectClass(t, o); c; c = cast(t, c->super())) { + for (GcClass* c = objectClass(t, o); c; c = c->super()) { for (unsigned i = 0; i < arrayLength(t, c->methodTable()); ++i) { object m = arrayBody(t, c->methodTable(), i); @@ -1070,7 +1070,7 @@ parsePoolEntry(Thread* t, Stream& s, uint32_t* index, GcSingleton* pool, unsigne GcMethod* template_ = makeMethod (t, 0, returnCode, parameterCount, parameterFootprint, 0, 0, 0, 0, - pairFirst(t, nameAndType), pairSecond(t, nameAndType), 0, 0, 0); + cast(t, pairFirst(t, nameAndType)), cast(t, pairSecond(t, nameAndType)), 0, 0, 0); object value = reinterpret_cast (makeInvocation(t, @@ -1195,8 +1195,12 @@ addInterfaces(Thread* t, GcClass* class_, GcHashMap* map) for (unsigned i = 0; i < arrayLength(t, table); i += increment) { GcClass* interface = cast(t, arrayBody(t, table, i)); - object name = interface->name(); - hashMapInsertMaybe(t, map, name, reinterpret_cast(interface), byteArrayHash, + GcByteArray* name = interface->name(); + hashMapInsertMaybe(t, + map, + reinterpret_cast(name), + reinterpret_cast(interface), + byteArrayHash, byteArrayEqual); } } @@ -1205,7 +1209,7 @@ addInterfaces(Thread* t, GcClass* class_, GcHashMap* map) GcClassAddendum* getClassAddendum(Thread* t, GcClass* class_, GcSingleton* pool) { - GcClassAddendum* addendum = cast(t, class_->addendum()); + GcClassAddendum* addendum = class_->addendum(); if (addendum == 0) { PROTECT(t, class_); @@ -1229,7 +1233,7 @@ parseInterfaceTable(Thread* t, Stream& s, GcClass* class_, GcSingleton* pool, PROTECT(t, map); if (class_->super()) { - addInterfaces(t, cast(t, class_->super()), map); + addInterfaces(t, class_->super(), map); } unsigned count = s.read2(); @@ -1249,7 +1253,7 @@ parseInterfaceTable(Thread* t, Stream& s, GcClass* class_, GcSingleton* pool, PROTECT(t, name); GcClass* interface = resolveClass - (t, class_->loader(), name, true, throwType); + (t, reinterpret_cast(class_->loader()), name, true, throwType); PROTECT(t, interface); @@ -1301,7 +1305,7 @@ parseFieldTable(Thread* t, Stream& s, GcClass* class_, GcSingleton* pool) unsigned memberOffset = BytesPerWord; if (class_->super()) { - memberOffset = classFixedSize(t, class_->super()); + memberOffset = class_->super()->fixedSize(); } unsigned count = s.read2(); @@ -1377,10 +1381,10 @@ parseFieldTable(Thread* t, Stream& s, GcClass* class_, GcSingleton* pool) flags, 0, // offset 0, // native ID - singletonObject(t, pool, name - 1), - singletonObject(t, pool, spec - 1), - addendum, - reinterpret_cast(class_)); + cast(t, singletonObject(t, pool, name - 1)), + cast(t, singletonObject(t, pool, spec - 1)), + cast(t, addendum), + class_); unsigned size = fieldSize(t, code); if (flags & ACC_STATIC) { @@ -1474,13 +1478,13 @@ parseFieldTable(Thread* t, Stream& s, GcClass* class_, GcSingleton* pool) } } - class_->fixedSize() = pad(memberOffset); + class_->fixedSize() = memberOffset; if (class_->super() - and memberOffset == classFixedSize(t, class_->super())) + and memberOffset == class_->super()->fixedSize()) { set(t, reinterpret_cast(class_), ClassObjectMask, - classObjectMask(t, class_->super())); + reinterpret_cast(class_->super()->objectMask())); } else { object mask = reinterpret_cast(makeIntArray (t, ceilingDivide(class_->fixedSize(), 32 * BytesPerWord))); @@ -1488,11 +1492,11 @@ parseFieldTable(Thread* t, Stream& s, GcClass* class_, GcSingleton* pool) object superMask = 0; if (class_->super()) { - superMask = classObjectMask(t, class_->super()); + superMask = reinterpret_cast(class_->super()->objectMask()); if (superMask) { memcpy(&intArrayBody(t, mask, 0), &intArrayBody(t, superMask, 0), - ceilingDivide(classFixedSize(t, class_->super()), + ceilingDivide(class_->super()->fixedSize(), 32 * BytesPerWord) * 4); } @@ -1999,7 +2003,7 @@ addInterfaceMethods(Thread* t, GcClass* class_, GcHashMap* virtualMap, method->name(), method->spec(), 0, - reinterpret_cast(class_), + class_, 0); hashMapInsert(t, @@ -2042,7 +2046,7 @@ parseMethodTable(Thread* t, Stream& s, GcClass* class_, GcSingleton* pool) if ((class_->flags() & ACC_INTERFACE) == 0) { if (class_->super()) { - superVirtualTable = classVirtualTable(t, class_->super()); + superVirtualTable = class_->super()->virtualTable(); } if (superVirtualTable) { @@ -2207,10 +2211,10 @@ parseMethodTable(Thread* t, Stream& s, GcClass* class_, GcSingleton* pool) if (UNLIKELY((class_->flags() & ACC_INTERFACE) == 0 and vm::strcmp (reinterpret_cast("finalize"), - &byteArrayBody(t, method->name(), 0)) == 0 + method->name()->body().begin()) == 0 and vm::strcmp (reinterpret_cast("()V"), - &byteArrayBody(t, method->spec(), 0)) == 0 + method->spec()->body().begin()) == 0 and (not emptyMethod(t, method)))) { class_->vmFlags() |= HasFinalizerFlag; @@ -2219,13 +2223,13 @@ parseMethodTable(Thread* t, Stream& s, GcClass* class_, GcSingleton* pool) method->offset() = i; if (vm::strcmp(reinterpret_cast(""), - &byteArrayBody(t, method->name(), 0)) == 0) + method->name()->body().begin()) == 0) { method->vmFlags() |= ClassInitFlag; class_->vmFlags() |= NeedInitFlag; } else if (vm::strcmp (reinterpret_cast(""), - &byteArrayBody(t, method->name(), 0)) == 0) + method->name()->body().begin()) == 0) { method->vmFlags() |= ConstructorFlag; } @@ -2253,14 +2257,14 @@ parseMethodTable(Thread* t, Stream& s, GcClass* class_, GcSingleton* pool) // inherit virtual table from superclass set(t, reinterpret_cast(class_), ClassVirtualTable, superVirtualTable); - if (classInterfaceTable(t, class_->super()) + if (class_->super()->interfaceTable() and arrayLength(t, class_->interfaceTable()) == arrayLength - (t, classInterfaceTable(t, class_->super()))) + (t, class_->super()->interfaceTable())) { // inherit interface table from superclass set(t, reinterpret_cast(class_), ClassInterfaceTable, - classInterfaceTable(t, class_->super())); + class_->super()->interfaceTable()); } else { populateInterfaceVtables = true; } @@ -2411,9 +2415,9 @@ parseAttributeTable(Thread* t, Stream& s, GcClass* class_, GcSingleton* pool) object reference = reinterpret_cast(makeInnerClassReference (t, - inner ? referenceName(t, singletonObject(t, pool, inner - 1)) : 0, - outer ? referenceName(t, singletonObject(t, pool, outer - 1)) : 0, - name ? singletonObject(t, pool, name - 1) : 0, + cast(t, inner ? referenceName(t, singletonObject(t, pool, inner - 1)) : 0), + cast(t, outer ? referenceName(t, singletonObject(t, pool, outer - 1)) : 0), + cast(t, name ? singletonObject(t, pool, name - 1) : 0), flags)); set(t, table, ArrayBody + (i * BytesPerWord), reference); @@ -2506,13 +2510,13 @@ updateBootstrapClass(Thread* t, GcClass* bootstrapClass, GcClass* class_) bootstrapClass->vmFlags() |= class_->vmFlags(); bootstrapClass->flags() |= class_->flags(); - set(t, reinterpret_cast(bootstrapClass), ClassSuper, class_->super()); - set(t, reinterpret_cast(bootstrapClass), ClassInterfaceTable, class_->interfaceTable()); - set(t, reinterpret_cast(bootstrapClass), ClassVirtualTable, class_->virtualTable()); - set(t, reinterpret_cast(bootstrapClass), ClassFieldTable, class_->fieldTable()); - set(t, reinterpret_cast(bootstrapClass), ClassMethodTable, class_->methodTable()); - set(t, reinterpret_cast(bootstrapClass), ClassStaticTable, class_->staticTable()); - set(t, reinterpret_cast(bootstrapClass), ClassAddendum, class_->addendum()); + set(t, reinterpret_cast(bootstrapClass), ClassSuper, reinterpret_cast(class_->super())); + set(t, reinterpret_cast(bootstrapClass), ClassInterfaceTable, reinterpret_cast(class_->interfaceTable())); + set(t, reinterpret_cast(bootstrapClass), ClassVirtualTable, reinterpret_cast(class_->virtualTable())); + set(t, reinterpret_cast(bootstrapClass), ClassFieldTable, reinterpret_cast(class_->fieldTable())); + set(t, reinterpret_cast(bootstrapClass), ClassMethodTable, reinterpret_cast(class_->methodTable())); + set(t, reinterpret_cast(bootstrapClass), ClassStaticTable, reinterpret_cast(class_->staticTable())); + set(t, reinterpret_cast(bootstrapClass), ClassAddendum, reinterpret_cast(class_->addendum())); updateClassTables(t, bootstrapClass, class_); } @@ -2532,7 +2536,7 @@ makeArrayClass(Thread* t, object loader, unsigned dimensions, object spec, // make a stack trace for a ClassNotFoundException. resolveSystemClass (t, root(t, Machine::BootLoader), - type(t, GcJobject::Type)->name(), false); + reinterpret_cast(type(t, GcJobject::Type)->name()), false); } object vtable = type(t, GcJobject::Type)->virtualTable(); @@ -2544,7 +2548,7 @@ makeArrayClass(Thread* t, object loader, unsigned dimensions, object spec, 2 * BytesPerWord, BytesPerWord, dimensions, - type(t, GcArray::Type)->objectMask(), + reinterpret_cast(type(t, GcArray::Type)->objectMask()), spec, 0, reinterpret_cast(type(t, GcJobject::Type)), @@ -2579,7 +2583,7 @@ saveLoadedClass(Thread* t, object loader, GcClass* c) hashMapInsert(t, cast(t, classLoaderMap(t, loader)), - c->name(), + reinterpret_cast(c->name()), reinterpret_cast(c), byteArrayHash); } @@ -2643,17 +2647,17 @@ makeArrayClass(Thread* t, object loader, object spec, bool throw_, ACQUIRE(t, t->m->classLock); - GcClass* class_ = findLoadedClass(t, elementClass->loader(), spec); + GcClass* class_ = findLoadedClass(t, reinterpret_cast(elementClass->loader()), spec); if (class_) { return class_; } class_ = makeArrayClass - (t, elementClass->loader(), dimensions, spec, reinterpret_cast(elementClass)); + (t, reinterpret_cast(elementClass->loader()), dimensions, spec, reinterpret_cast(elementClass)); PROTECT(t, class_); - saveLoadedClass(t, elementClass->loader(), class_); + saveLoadedClass(t, reinterpret_cast(elementClass->loader()), class_); return class_; } @@ -2721,10 +2725,10 @@ bootClass(Thread* t, Gc::Type type, int superType, uint32_t objectMask, if (objectMask) { if (super and super->objectMask() - and intArrayBody(t, super->objectMask(), 0) + and super->objectMask()->body()[0] == static_cast(objectMask)) { - mask = vm::type(t, static_cast(superType))->objectMask(); + mask = reinterpret_cast(vm::type(t, static_cast(superType))->objectMask()); } else { mask = reinterpret_cast(makeIntArray(t, 1)); intArrayBody(t, mask, 0) = objectMask; @@ -3156,7 +3160,7 @@ updatePackageMap(Thread* t, GcClass* class_) setRoot(t, Machine::PackageMap, reinterpret_cast(makeHashMap(t, 0, 0))); } - object className = class_->name(); + object className = reinterpret_cast(class_->name()); if ('[' != byteArrayBody(t, className, 0)) { THREAD_RUNTIME_ARRAY (t, char, packageName, byteArrayLength(t, className)); @@ -3179,7 +3183,7 @@ updatePackageMap(Thread* t, GcClass* class_) (t, cast(t, root(t, Machine::PackageMap)), key, byteArrayHash, byteArrayEqual); - object source = class_->source(); + object source = reinterpret_cast(class_->source()); if (source) { // note that we strip the "file:" prefix, since OpenJDK's // Package.defineSystemPackage expects an unadorned filename: @@ -4115,7 +4119,7 @@ isAssignableFrom(Thread* t, GcClass* a, GcClass* b) } else if ((a->vmFlags() & PrimitiveFlag) == (b->vmFlags() & PrimitiveFlag)) { - for (; b; b = cast(t, b->super())) { + for (; b; b = b->super()) { if (b == a) { return true; } @@ -4131,7 +4135,7 @@ instanceOf(Thread* t, GcClass* class_, object o) if (o == 0) { return false; } else { - return isAssignableFrom(t, class_, reinterpret_cast(objectClass(t, o))); + return isAssignableFrom(t, class_, objectClass(t, o)); } } @@ -4273,8 +4277,7 @@ parseClass(Thread* t, object loader, const uint8_t* data, unsigned size, 0, // array dimensions 0, // runtime data index 0, // object mask - referenceName - (t, singletonObject(t, pool, name - 1)), + cast(t, referenceName(t, singletonObject(t, pool, name - 1))), 0, // source file 0, // super 0, // interfaces @@ -4283,7 +4286,7 @@ parseClass(Thread* t, object loader, const uint8_t* data, unsigned size, 0, // methods 0, // addendum 0, // static table - loader, + cast(t, loader), 0, // source 0);// vtable length PROTECT(t, class_); @@ -4324,17 +4327,17 @@ parseClass(Thread* t, object loader, const uint8_t* data, unsigned size, class_->fixedSize(), class_->arrayElementSize(), class_->arrayDimensions(), - class_->objectMask(), - class_->name(), - class_->sourceFile(), - class_->super(), - class_->interfaceTable(), - class_->virtualTable(), - class_->fieldTable(), - class_->methodTable(), - class_->addendum(), - class_->staticTable(), - class_->loader(), + reinterpret_cast(class_->objectMask()), + reinterpret_cast(class_->name()), + reinterpret_cast(class_->sourceFile()), + reinterpret_cast(class_->super()), + reinterpret_cast(class_->interfaceTable()), + reinterpret_cast(class_->virtualTable()), + reinterpret_cast(class_->fieldTable()), + reinterpret_cast(class_->methodTable()), + reinterpret_cast(class_->addendum()), + reinterpret_cast(class_->staticTable()), + reinterpret_cast(class_->loader()), vtableLength); PROTECT(t, real); @@ -4345,7 +4348,7 @@ parseClass(Thread* t, object loader, const uint8_t* data, unsigned size, if (root(t, Machine::PoolMap)) { object bootstrapClass = hashMapFind - (t, cast(t, root(t, Machine::BootstrapClassMap)), class_->name(), + (t, cast(t, root(t, Machine::BootstrapClassMap)), reinterpret_cast(class_->name()), byteArrayHash, byteArrayEqual); hashMapInsert( @@ -4523,7 +4526,7 @@ resolveClass(Thread* t, object loader, object spec, bool throw_, if (classLoaderClass->vmFlags() & BootstrapFlag) { resolveSystemClass (t, root(t, Machine::BootLoader), - classLoaderClass->name()); + reinterpret_cast(classLoaderClass->name())); } } } @@ -4589,8 +4592,7 @@ resolveMethod(Thread* t, GcClass* class_, const char* methodName, if (method == 0) { throwNew(t, GcNoSuchMethodError::Type, "%s %s not found in %s", - methodName, methodSpec, &byteArrayBody - (t, class_->name(), 0)); + methodName, methodSpec, class_->name()->body().begin()); } else { return method; } @@ -4613,13 +4615,13 @@ resolveField(Thread* t, GcClass* class_, const char* fieldName, GcClass* c = class_; PROTECT(t, c); - for (; c != 0 and field == 0; c = cast(t, c->super())) { + for (; c != 0 and field == 0; c = c->super()) { field = findFieldInClass(t, c, name, spec); } if (field == 0) { throwNew(t, GcNoSuchFieldError::Type, "%s %s not found in %s", - fieldName, fieldSpec, &byteArrayBody(t, class_->name(), 0)); + fieldName, fieldSpec, class_->name()->body().begin()); } else { return field; } @@ -4673,7 +4675,7 @@ preInitClass(Thread* t, GcClass* c) } } else if (c->vmFlags() & InitErrorFlag) { throwNew(t, GcNoClassDefFoundError::Type, "%s", - &byteArrayBody(t, c->name(), 0)); + c->name()->body().begin()); } else { c->vmFlags() |= InitFlag; return true; @@ -4715,7 +4717,7 @@ initClass(Thread* t, GcClass* c) { PROTECT(t, c); - object super = c->super(); + object super = reinterpret_cast(c->super()); if (super) { initClass(t, cast(t, super)); } @@ -4779,7 +4781,7 @@ object makeObjectArray(Thread* t, GcClass* elementClass, unsigned count) { GcClass* arrayClass = resolveObjectArrayClass - (t, elementClass->loader(), reinterpret_cast(elementClass)); + (t, reinterpret_cast(elementClass->loader()), reinterpret_cast(elementClass)); PROTECT(t, arrayClass); @@ -4818,7 +4820,7 @@ findInHierarchyOrNull(Thread* t, GcClass* class_, object name, object spec, } if (o == 0) { - for (; o == 0 and class_; class_ = cast(t, class_->super())) { + for (; o == 0 and class_; class_ = class_->super()) { o = find(t, class_, name, spec); } @@ -5050,8 +5052,7 @@ printTrace(Thread* t, object exception) logTrace(errorLog(t), "caused by: "); } - logTrace(errorLog(t), "%s", &byteArrayBody - (t, objectClass(t, e)->name(), 0)); + logTrace(errorLog(t), "%s", objectClass(t, e)->name()->body().begin()); if (throwableMessage(t, e)) { object m = throwableMessage(t, e); @@ -5281,9 +5282,9 @@ getCaller(Thread* t, unsigned target, bool skipMethodInvoke) virtual bool visit(Processor::StackWalker* walker) { if (skipMethodInvoke - and cast(t, walker->method()->class_()) + and walker->method()->class_() == type(t, GcJmethod::Type) - and strcmp(&byteArrayBody(t, walker->method()->name(), 0), + and strcmp(walker->method()->name()->body().begin(), reinterpret_cast("invoke")) == 0) { return true; } @@ -5348,7 +5349,7 @@ populateMultiArray(Thread* t, object array, int32_t* counts, PROTECT(t, array); - object spec = objectClass(t, array)->name(); + object spec = reinterpret_cast(objectClass(t, array)->name()); PROTECT(t, spec); object elementSpec = reinterpret_cast(makeByteArray(t, byteArrayLength(t, spec) - 1)); @@ -5357,7 +5358,7 @@ populateMultiArray(Thread* t, object array, int32_t* counts, byteArrayLength(t, spec) - 1); GcClass* class_ = resolveClass - (t, objectClass(t, array)->loader(), elementSpec); + (t, reinterpret_cast(objectClass(t, array)->loader()), elementSpec); PROTECT(t, class_); for (int32_t i = 0; i < counts[index]; ++i) { @@ -5449,10 +5450,8 @@ vmfPrintTrace(Thread* t, FILE* out) Visitor(Thread* t, FILE* out): t(t), out(out) { } virtual bool visit(Processor::StackWalker* walker) { - const int8_t* class_ = &byteArrayBody - (t, className(t, walker->method()->class_()), 0); - const int8_t* method = &byteArrayBody - (t, walker->method()->name(), 0); + const int8_t* class_ = walker->method()->class_()->name()->body().begin(); + const int8_t* method = walker->method()->name()->body().begin(); int line = t->m->processor->lineNumber (t, walker->method(), walker->ip()); diff --git a/src/process.cpp b/src/process.cpp index 48cc3aaa13..feb629e4f7 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -71,14 +71,14 @@ jniNameLength(Thread* t, GcMethod* method, bool decorate) { unsigned size = 0; - object className = ::className(t, method->class_()); + object className = reinterpret_cast(method->class_()->name()); for (unsigned i = 0; i < byteArrayLength(t, className) - 1; ++i) { size += mangledSize(byteArrayBody(t, className, i)); } ++ size; - object methodName = method->name(); + object methodName = reinterpret_cast(method->name()); for (unsigned i = 0; i < byteArrayLength(t, methodName) - 1; ++i) { size += mangledSize(byteArrayBody(t, methodName, i)); } @@ -86,7 +86,7 @@ jniNameLength(Thread* t, GcMethod* method, bool decorate) if (decorate) { size += 2; - object methodSpec = method->spec(); + object methodSpec = reinterpret_cast(method->spec()); for (unsigned i = 1; i < byteArrayLength(t, methodSpec) - 1 and byteArrayBody(t, methodSpec, i) != ')'; ++i) { @@ -104,14 +104,14 @@ makeJNIName(Thread* t, const char* prefix, unsigned prefixLength, char* name, memcpy(name, prefix, prefixLength); name += prefixLength; - object className = ::className(t, method->class_()); + object className = reinterpret_cast(method->class_()->name()); for (unsigned i = 0; i < byteArrayLength(t, className) - 1; ++i) { name += mangle(byteArrayBody(t, className, i), name); } *(name++) = '_'; - object methodName = method->name(); + object methodName = reinterpret_cast(method->name()); for (unsigned i = 0; i < byteArrayLength(t, methodName) - 1; ++i) { name += mangle(byteArrayBody(t, methodName, i), name); } @@ -120,7 +120,7 @@ makeJNIName(Thread* t, const char* prefix, unsigned prefixLength, char* name, *(name++) = '_'; *(name++) = '_'; - object methodSpec = method->spec(); + object methodSpec = reinterpret_cast(method->spec()); for (unsigned i = 1; i < byteArrayLength(t, methodSpec) - 1 and byteArrayBody(t, methodSpec, i) != ')'; ++i) { @@ -232,15 +232,15 @@ resolveNative(Thread* t, GcMethod* method) assertT(t, method->flags() & ACC_NATIVE); - initClass(t, cast(t, method->class_())); + initClass(t, method->class_()); if (methodRuntimeDataNative(t, getMethodRuntimeData(t, method)) == 0) { object native = resolveNativeMethod(t, method); if (UNLIKELY(native == 0)) { throwNew(t, GcUnsatisfiedLinkError::Type, "%s.%s%s", - &byteArrayBody(t, className(t, method->class_()), 0), - &byteArrayBody(t, method->name(), 0), - &byteArrayBody(t, method->spec(), 0)); + method->class_()->name()->body().begin(), + method->name()->body().begin(), + method->spec()->body().begin()); } PROTECT(t, native); diff --git a/src/tools/bootimage-generator/main.cpp b/src/tools/bootimage-generator/main.cpp index b6fc181c90..767104451e 100644 --- a/src/tools/bootimage-generator/main.cpp +++ b/src/tools/bootimage-generator/main.cpp @@ -618,13 +618,11 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, if (((methodName == 0 or ::strcmp (reinterpret_cast - (&byteArrayBody - (t, method->name(), 0)), methodName) == 0) + (method->name()->body().begin()), methodName) == 0) and (methodSpec == 0 or ::strcmp (reinterpret_cast - (&byteArrayBody - (t, method->spec(), 0)), methodSpec) + (method->spec()->body().begin()), methodSpec) == 0))) { if (method->code() @@ -640,26 +638,26 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, } } - object addendum = method->addendum(); - if (addendum and methodAddendumExceptionTable(t, addendum)) { + GcMethodAddendum* addendum = method->addendum(); + if (addendum and addendum->exceptionTable()) { PROTECT(t, addendum); // resolve exception types now to avoid trying to update // immutable references at runtime for (unsigned i = 0; i < shortArrayLength - (t, methodAddendumExceptionTable(t, addendum)); ++i) + (t, addendum->exceptionTable()); ++i) { uint16_t index = shortArrayBody - (t, methodAddendumExceptionTable(t, addendum), i) - 1; + (t, addendum->exceptionTable(), i) - 1; object o = singletonObject - (t, cast(t, addendumPool(t, addendum)), index); + (t, cast(t, addendum->pool()), index); if (objectClass(t, o) == type(t, GcReference::Type)) { o = reinterpret_cast(resolveClass (t, root(t, Machine::BootLoader), referenceName(t, o))); - set(t, addendumPool(t, addendum), + set(t, addendum->pool(), SingletonBody + (index * BytesPerWord), o); } } diff --git a/src/tools/type-generator/io.h b/src/tools/type-generator/io.h index 83810eba2f..f209c7963a 100644 --- a/src/tools/type-generator/io.h +++ b/src/tools/type-generator/io.h @@ -7,7 +7,9 @@ There is NO WARRANTY for this software. See license.txt for details. */ - + +#include + #include "assert.h" #ifndef AVIAN_TOOLS_TYPE_GENERATOR_IO_H @@ -101,7 +103,7 @@ class Output { virtual void dispose() = 0; - virtual void write(const char* s) = 0; + virtual void write(const std::string& s) = 0; void write(int i) { static const int Size = 32; @@ -133,8 +135,8 @@ class FileOutput : public Output { } } - virtual void write(const char* s) { - fputs(s, stream); + virtual void write(const std::string& s) { + fputs(s.c_str(), stream); } const char* filename() { diff --git a/src/tools/type-generator/main.cpp b/src/tools/type-generator/main.cpp index 6cf8957ac5..a0db3a5bfc 100644 --- a/src/tools/type-generator/main.cpp +++ b/src/tools/type-generator/main.cpp @@ -14,6 +14,12 @@ #include "string.h" #include "errno.h" +#include +#include +#include +#include +#include + #include "avian/constants.h" #include "avian/finder.h" @@ -31,13 +37,149 @@ using namespace avian::util; #define UNUSED __attribute__((unused)) -void operator delete(void*) { abort(); } - -extern "C" void __cxa_pure_virtual(void) { abort(); } - using namespace vm; using namespace avian::tools::typegenerator; +namespace avian { +namespace tools { +namespace typegenerator { + +class Class; + +class Field { + public: + std::string name; + size_t elementSize; + size_t offset; + uintptr_t ownerId; + bool noassert; + bool nogc; + + std::string javaSpec; + std::string typeName; + + Field(Class* ownerId, + const std::string& typeName, + const std::string& javaSpec, + const std::string& name, + size_t elementSize) + : name(name), + elementSize(elementSize), + offset(0), + ownerId(reinterpret_cast(ownerId)), + noassert(false), + nogc(false), + javaSpec(javaSpec), + typeName(typeName) + { + } + + std::string dump() const { + std::ostringstream ss; + ss << "field " << name << ":" << typeName << ":" << javaSpec << ", size=" << elementSize << ", offset=" << offset; + if(noassert) { + ss << " noassert"; + } + if(nogc) { + ss << " nogc"; + } + return ss.str(); + } +}; + +class Method { + public: + std::string javaName; + std::string javaSpec; + + Method(const std::string& javaName, const std::string& javaSpec) + : javaName(javaName), javaSpec(javaSpec) + { + } + + bool operator == (const Method& o) const { + return javaName == o.javaName && javaSpec == o.javaSpec; + } + + bool operator < (const Method& o) const { + return javaName < o.javaName || (javaName == o.javaName && javaSpec < o.javaSpec); + } + std::string dump() const { + return "method " + javaName + javaSpec; + } +}; + +class Class { + public: + // "simple" name, used for generated code, defined in types.def + std::string name; + + // Name of the backing Java class, empty if there isn't one + std::string javaName; + + Class* super; + + std::vector fields; + std::set methods; + + Field* arrayField; + + bool overridesMethods; + + int fixedSize; + + Class(const std::string& name) : name(name), super(0), arrayField(0), overridesMethods(false), fixedSize(-1) + { + } + + std::string dump() const { + std::ostringstream ss; + ss << "class " << name; + if(javaName.size() > 0) { + ss << "(" << javaName << ")"; + } + if(super) { + ss << " : " << super->name << "(" << super->javaName << ")"; + } + ss << " {\n"; + + for(std::vector::const_iterator it = fields.begin(); it != fields.end(); it++) { + ss << " " << (*it)->dump() << "\n"; + } + + for(std::set::const_iterator it = methods.begin(); it != methods.end(); ++it) { + ss << " " << it->dump() << "\n"; + } + ss << "}"; + return ss.str(); + } + + void dumpToStdout() const AVIAN_EXPORT { + printf("%s\n", dump().c_str()); + } +}; + +class Module { + public: + // Map from java-level name to Class + std::map javaClasses; + + std::map classes; + + void add(Class* cl) { + assert(classes.find(cl->name) == classes.end()); + classes[cl->name] = cl; + if(cl->javaName != "") { + assert(javaClasses.find(cl->javaName) == javaClasses.end()); + javaClasses[cl->javaName] = cl; + } + } +}; + +} +} +} + namespace { namespace local { @@ -48,21 +190,6 @@ namespace local { const unsigned BytesPerWord = POINTER_SIZE; -inline unsigned -pad(unsigned size, unsigned alignment) -{ - unsigned n = alignment; - while (size and n % size) ++ n; - return n - alignment; -} - -inline unsigned -pad(unsigned n) -{ - unsigned extra = n % BytesPerWord; - return (extra ? n + BytesPerWord - extra : n); -} - inline bool equal(const char* a, const char* b) { @@ -70,378 +197,22 @@ equal(const char* a, const char* b) } inline bool -endsWith(const char* a, const char* b) +endsWith(const std::string& b, const std::string& a) { - unsigned al = strlen(a); - unsigned bl = strlen(b); - return (bl >= al) and strncmp(a, b + (bl - al), al) == 0; + if (b.size() > a.size()) { + return false; + } + return std::equal(a.begin() + a.size() - b.size(), a.end(), b.begin()); } -inline const char* -take(unsigned n, const char* c) -{ - char* r = static_cast(malloc(n + 1)); - assert(r); - memcpy(r, c, n); - r[n] = 0; - return r; -} - -class Scalar : public Object { - public: - Object* owner; - const char* typeName; - const char* name; - unsigned elementSize; - bool noassert; - bool nogc; - - static Scalar* make(Object* owner, const char* typeName, const char* name, - unsigned size) - { - Scalar* o = allocate(); - o->type = Object::Scalar; - o->owner = owner; - o->typeName = typeName; - o->name = name; - o->elementSize = size; - o->noassert = false; - o->nogc = false; - return o; - } -}; - -class Array : public Scalar { - public: - static Array* make(Object* owner, const char* typeName, const char* name, - unsigned elementSize) - { - Array* o = allocate(); - o->type = Object::Array; - o->owner = owner; - o->typeName = typeName; - o->name = name; - o->elementSize = elementSize; - o->noassert = false; - o->nogc = false; - return o; - } -}; - -unsigned -arrayElementSize(Object* o) -{ - switch (o->type) { - case Object::Array: - return static_cast(o)->elementSize; - - default: - UNREACHABLE; - } -} - -Object* -memberOwner(Object* o) -{ - switch (o->type) { - case Object::Scalar: - case Object::Array: - return static_cast(o)->owner; - - default: - UNREACHABLE; - } -} - -const char* -memberTypeName(Object* o) -{ - switch (o->type) { - case Object::Scalar: - case Object::Array: - return static_cast(o)->typeName; - - default: - UNREACHABLE; - } -} - -const char* -memberTypeEnumName(Object* o) -{ - const char* n = memberTypeName(o); - if (strcmp("void*", n) == 0) { +std::string enumName(std::string& type) { + if (type == "void*") { return "word"; } else { - return n; + return type; } } -const char*& -memberName(Object* o) -{ - switch (o->type) { - case Object::Scalar: - case Object::Array: - return static_cast(o)->name; - - default: - UNREACHABLE; - } -} - -unsigned -memberSize(Object* o) -{ - switch (o->type) { - case Object::Scalar: - return static_cast(o)->elementSize; - - default: - UNREACHABLE; - } -} - -unsigned -memberElementSize(Object* o) -{ - switch (o->type) { - case Object::Scalar: - case Object::Array: - return static_cast(o)->elementSize; - - default: - UNREACHABLE; - } -} - -bool& -memberNoAssert(Object* o) -{ - switch (o->type) { - case Object::Scalar: - case Object::Array: - return static_cast(o)->noassert; - - default: - UNREACHABLE; - } -} - -bool& -memberNoGC(Object* o) -{ - switch (o->type) { - case Object::Scalar: - case Object::Array: - return static_cast(o)->nogc; - - default: - UNREACHABLE; - } -} - -bool -memberGC(Object* o) -{ - return not memberNoGC(o) and equal(memberTypeName(o), "object"); -} - -class Method : public Object { - public: - Object* owner; - const char* name; - const char* spec; - - static Method* make(Object* owner, const char* name, const char* spec) - { - Method* o = allocate(); - o->type = Object::Method; - o->owner = owner; - o->name = name; - o->spec = spec; - return o; - } -}; - -const char* -methodName(Object* o) -{ - switch (o->type) { - case Object::Method: - return static_cast(o)->name; - - default: - UNREACHABLE; - } -} - -const char* -methodSpec(Object* o) -{ - switch (o->type) { - case Object::Method: - return static_cast(o)->spec; - - default: - UNREACHABLE; - } -} - -class Type : public Object { - public: - const char* name; - const char* javaName; - Object* super; - List members; - List methods; - bool overridesMethods; - - static Type* make(Object::ObjectType type, const char* name, - const char* javaName) - { - Type* o = allocate(); - o->type = type; - o->name = name; - o->javaName = javaName; - o->super = 0; - o->members.first = o->members.last = 0; - o->methods.first = o->methods.last = 0; - o->overridesMethods = false; - return o; - } -}; - -const char* -typeName(Object* o) -{ - switch (o->type) { - case Object::Type: - return static_cast(o)->name; - - default: - UNREACHABLE; - } -} - -const char* -typeJavaName(Object* o) -{ - switch (o->type) { - case Object::Type: - return static_cast(o)->javaName; - - default: - UNREACHABLE; - } -} - -Object* -typeMembers(Object* o) -{ - switch (o->type) { - case Object::Type: - return static_cast(o)->members.first; - - default: - UNREACHABLE; - } -} - -Object* -typeMethods(Object* o) -{ - switch (o->type) { - case Object::Type: - return static_cast(o)->methods.first; - - default: - UNREACHABLE; - } -} - -bool& -typeOverridesMethods(Object* o) -{ - switch (o->type) { - case Object::Type: - return static_cast(o)->overridesMethods; - - default: - UNREACHABLE; - } -} - -void -addMember(Object* o, Object* member) -{ - switch (o->type) { - case Object::Type: - if (member->type == Object::Array) { - static_cast(o)->members.append - (Scalar::make(o, "uintptr_t", "length", BytesPerWord)); - } - static_cast(o)->members.append(member); - break; - - default: - UNREACHABLE; - } -} - -void -addMethod(Object* o, Object* method) -{ - switch (o->type) { - case Object::Type: - for (Object* p = typeMethods(o); p; p = cdr(p)) { - Object* m = car(p); - if (equal(methodName(m), methodName(method)) - and equal(methodSpec(m), methodSpec(method))) - { - setCar(p, method); - return; - } - } - static_cast(o)->methods.append(method); - break; - - default: - UNREACHABLE; - } -} - -Object*& -typeSuper(Object* o) -{ - switch (o->type) { - case Object::Type: - return static_cast(o)->super; - - default: - UNREACHABLE; - } -} - -class Number : public Object { - public: - unsigned value; - - static Number* make(unsigned value) { - Number* o = allocate(); - o->type = Object::Number; - o->value = value; - return o; - } -}; - -unsigned -number(Object* o) -{ - assert(o->type == Object::Number); - return static_cast(o)->value; -} - class Character : public Object { public: char value; @@ -501,29 +272,13 @@ class Singleton : public Object { } }; -bool -endsWith(char c, const char* s) +std::string +capitalize(const std::string& s) { - assert(s); - if (*s == 0) return false; - - while (*s) ++ s; - return (*(s - 1) == c); -} - -const char* -capitalize(const char* s) -{ - assert(s); - unsigned length = strlen(s); - assert(length); - char* r = static_cast(malloc(length + 1)); - assert(r); - - memcpy(r, s, length + 1); - if (r[0] >= 'a' and r[0] <= 'z') r[0] = (r[0] - 'a') + 'A'; - - return r; + if(s[0] >= 'a' && s[0] <= 'z') { + return (char)(s[0] + 'A' - 'a') + s.substr(1, s.size() - 1); + } + return s; } Object* @@ -587,284 +342,180 @@ read(Input* in, Object* eos, int level) } } -Object* -declaration(const char* name, Object* declarations) -{ - for (Object* p = declarations; p; p = cdr(p)) { - Object* o = car(p); - switch (o->type) { - case Object::Type: - if (equal(name, typeName(o))) return o; - break; - - default: UNREACHABLE; - } - } - return 0; -} - -Object* -javaDeclaration(const char* name, Object* declarations) -{ - for (Object* p = declarations; p; p = cdr(p)) { - Object* o = car(p); - switch (o->type) { - case Object::Type: - if (typeJavaName(o) and equal(name, typeJavaName(o))) return o; - break; - - default: UNREACHABLE; - } - } - return 0; -} - -Object* -derivationChain(Object* o) -{ - Object* chain = 0; - for (Object* p = o; p; p = typeSuper(p)) { - chain = cons(p, chain); - } - return chain; -} - -class MemberIterator { - public: - Object* types; - Object* type; - Object* members; - Object* member; - int index_; - unsigned offset_; - unsigned size_; - unsigned padding_; - unsigned alignment_; - unsigned sawSuperclassBoundary; - - MemberIterator(Object* type, bool skipSupers = false): - types(derivationChain(type)), - type(car(types)), - members(0), - member(0), - index_(-1), - offset_(BytesPerWord), - size_(0), - padding_(0), - alignment_(BytesPerWord), - sawSuperclassBoundary(true) - { - while (skipSupers and hasMore() and this->type != type) next(); - padding_ = 0; - alignment_ = BytesPerWord; - } - - bool hasMore() { - if (members) { - return true; - } else { - while (types) { - if (member) { - assert(member->type == Object::Scalar); - offset_ = ((offset_ + size_) + (BytesPerWord - 1)) - & ~(BytesPerWord - 1); - alignment_ = BytesPerWord; - sawSuperclassBoundary = true; - member = 0; - } else { - sawSuperclassBoundary = false; - } - - type = car(types); - members = typeMembers(type); - types = cdr(types); - if (members) return true; - } - return false; - } - } - - Object* next() { - assert(hasMore()); - - if (member) { - assert(member->type == Object::Scalar); - offset_ += size_; - } - - member = car(members); - members = cdr(members); - - ++ index_; - - switch (member->type) { - case Object::Scalar: { - size_ = memberSize(member); - padding_ = pad(size_, alignment_); - alignment_ = (alignment_ + size_ + padding_) % 8; - } break; - - case Object::Array: { - size_ = 0x7FFFFFFF; - padding_ = pad(memberElementSize(member), alignment_); - alignment_ = 0; - } break; - - default: UNREACHABLE; - } - - offset_ += padding_; - - // fprintf(stderr, - // "type: %s; member: %s; size: %d; padding: %d; alignment: %d;" - // " offset: %d;\n", - // typeName(type), memberName(member), size_, padding_, alignment_, - // offset_); - - return member; - } - - unsigned offset() { - return offset_; - } - - unsigned size() { - return size_; - } - - unsigned padding() { - return padding_; - } - - unsigned space() { - return size_ + padding_; - } - - unsigned index() { - return index_; - } - - unsigned alignment() { - return alignment_; - } -}; - bool -namesPointer(const char* s) +namesPointer(const std::string& s) { - return equal(s, "Collector") - or equal(s, "Disposer") - or endsWith('*', s); + return s == "Collector" + or s == "Disposer" + or endsWith("*", s); } unsigned -sizeOf(const char* type) +sizeOf(Module& module, const std::string& type) { - if (equal(type, "object") - or equal(type, "intptr_t") or equal(type, "uintptr_t")) + if (type == "object" + or type == "intptr_t" or type == "uintptr_t") { return BytesPerWord; - } else if (equal(type, "unsigned") or equal(type, "int")) { + } else if (type == "unsigned" or type == "int") { return sizeof(int); - } else if (equal(type, "bool")) { + } else if (type == "bool") { return sizeof(bool); - } else if (equal(type, "int8_t") or equal(type, "uint8_t")) { + } else if (type == "int8_t" or type == "uint8_t") { return sizeof(uint8_t); - } else if (equal(type, "int16_t") or equal(type, "uint16_t")) { + } else if (type == "int16_t" or type == "uint16_t") { return sizeof(uint16_t); - } else if (equal(type, "int32_t") or equal(type, "uint32_t")) { + } else if (type == "int32_t" or type == "uint32_t") { return sizeof(uint32_t); - } else if (equal(type, "int64_t") or equal(type, "uint64_t")) { + } else if (type == "int64_t" or type == "uint64_t") { return sizeof(uint64_t); - } else if (equal(type, "char")) { + } else if (type == "char") { return sizeof(char); } else if (endsWith("[0]", type)) { return 0; } else if (namesPointer(type)) { return BytesPerWord; } else { - fprintf(stderr, "unexpected type: %s\n", type); - abort(); + std::map::iterator it = module.classes.find(type); + if(it != module.classes.end()) { + return BytesPerWord; + } else { + fprintf(stderr, "unexpected type: %s\n", type.c_str()); + abort(); + } } } -Object* -parseArray(Object* t, Object* p) +struct FieldSpec { + bool isArray; + std::string aliasName; + bool require; + Field* field; + + FieldSpec(){} + + FieldSpec(bool isArray, Field* field) :isArray(isArray), require(false), field(field) {} +}; + +class ClassParser { + public: + Class* cl; + std::map fields; + + ClassParser(Class* cl) : cl(cl) + { + } + + void add(FieldSpec f) { + if(f.aliasName.size() > 0) { + if(fields.find(f.aliasName) == fields.end()) { + if(fields.find(f.field->name) != fields.end()) { + // printf("alias %s.%s -> %s.%s\n", cl->name.c_str(), f.field->name.c_str(), cl->name.c_str(), f.aliasName.c_str()); + std::map::iterator it = fields.find(f.field->name); + assert(it != fields.end()); + Field* renamed = it->second; + fields.erase(it); + fields[f.aliasName] = renamed; + + renamed->name = f.aliasName; + + // TODO: this currently works around how avian uses an object (either a char[] or byte[]) for String.data + renamed->typeName = f.field->typeName; + renamed->javaSpec = f.field->javaSpec; + } else { + // printf("ignoring absent alias %s.%s -> %s.%s\n", cl->name.c_str(), f.field->name.c_str(), cl->name.c_str(), f. aliasName.c_str()); + } + } else { + // printf("ignoring already defined alias %s.%s -> %s.%s\n", cl->name.c_str(), f.field->name.c_str(), cl->name.c_str(), f. aliasName.c_str()); + } + } else { + if(fields.find(f.field->name) == fields.end()) { + // printf("add %s.%s\n", cl->name.c_str(), f.field->name.c_str()); + fields[f.field->name] = f.field; + if(f.isArray) { + add(FieldSpec(false, new Field(cl, "uintptr_t", "", "length", BytesPerWord))); + assert(!cl->arrayField); + cl->arrayField = f.field; + } else { + cl->fields.push_back(f.field); + } + } else { + // printf("required check %s.%s\n", cl->name.c_str(), f.field->name.c_str()); + assert(f.aliasName.size() > 0 || f.require); + fields[f.field->name]->nogc |= f.field->nogc; + fields[f.field->name]->noassert |= f.field->noassert; + } + } + } + + void setSuper(Class* super) { + assert(!cl->super); + cl->super = super; + assert(!super->arrayField); + assert(fields.size() == 0); + for(std::vector::iterator it = super->fields.begin(); it != super->fields.end(); it++) { + add(FieldSpec(false, *it)); + } + } +}; + +FieldSpec parseArray(Module& module, ClassParser& clparser, Object* p) { const char* typeName = string(car(p)); p = cdr(p); const char* name = string(car(p)); - return Array::make(t, typeName, name, sizeOf(typeName)); + assert(!clparser.cl->arrayField); + return FieldSpec(true, new Field(clparser.cl, typeName, "", name, sizeOf(module, typeName))); } -Object* -parseMember(Object* t, Object* p); - -Object* -parseMember(Object* t, Object* p, bool* isNew) -{ - Object* member = parseMember(t, p); - for (MemberIterator it(t); it.hasMore();) { - Object* m = it.next(); - if (equal(memberName(m), memberName(member))) { - if (not equal(memberTypeName(m), memberTypeName(member))) { - abort(); - } - *isNew = false; - return m; - } - } - *isNew = true; - return member; -} - -Object* -parseMember(Object* t, Object* p) -{ +FieldSpec parseVerbatimField(Module& module, ClassParser& clparser, Object* p) { const char* spec = string(car(p)); - if (equal(spec, "array")) { - return parseArray(t, cdr(p)); + const char* name = string(car(cdr(p))); + return FieldSpec( + false, + new Field(clparser.cl, spec, "", name, sizeOf(module, spec))); +} + +FieldSpec parseField(Module& module, ClassParser& clparser, Object* p) +{ + FieldSpec f; + const char* spec = string(car(p)); + if (equal(spec, "field")) { + return parseVerbatimField(module, clparser, cdr(p)); + } else if (equal(spec, "array")) { + return parseArray(module, clparser, cdr(p)); } else if (equal(spec, "noassert")) { - bool isNew; - Object* member = parseMember(t, cdr(p), &isNew); - memberNoAssert(member) = true; - return isNew ? member : 0; + f = parseField(module, clparser, cdr(p)); + f.field->noassert = true; + f.require = true; } else if (equal(spec, "nogc")) { - bool isNew; - Object* member = parseMember(t, cdr(p), &isNew); - memberNoGC(member) = true; - return isNew ? member : 0; + f = parseField(module, clparser, cdr(p)); + f.field->nogc = true; + f.require = true; } else if (equal(spec, "require")) { - bool isNew; - Object* member = parseMember(t, cdr(p), &isNew); - return isNew ? member : 0; + f = parseField(module, clparser, cdr(p)); + f.require = true; } else if (equal(spec, "alias")) { - bool isNew; - Object* member = parseMember(t, cdr(cdr(p)), &isNew); - memberName(member) = string(car(cdr(p))); - return 0; + const char* name = string(car(cdr(p))); + f = parseField(module, clparser, cdr(cdr(p))); + f.aliasName = name; } else { - return Scalar::make(t, spec, string(car(cdr(p))), sizeOf(spec)); + return parseVerbatimField(module, clparser, p); } + return f; } void -parseSubdeclaration(Object* t, Object* p, Object* declarations) +parseSubdeclaration(Module& module, ClassParser& clparser, Object* p) { const char* front = string(car(p)); if (equal(front, "extends")) { - assert(t->type == Object::Type); - assert(typeSuper(t) == 0); - typeSuper(t) = declaration(string(car(cdr(p))), declarations); - assert(typeSuper(t)); - assert(typeSuper(t)->type == Object::Type); + Class* super = module.classes[string(car(cdr(p)))]; + clparser.setSuper(super); } else { - Object* member = parseMember(t, p); - if (member) { - addMember(t, member); - } + clparser.add(parseField(module, clparser, p)); } } @@ -914,7 +565,7 @@ fieldType(const char* spec) } void -parseJavaClass(Object* type, Stream* s, Object* declarations) +parseJavaClass(Module& module, ClassParser& clparser, Stream* s) { uint32_t magic = s->read4(); assert(magic == 0xCAFEBABE); @@ -972,8 +623,8 @@ parseJavaClass(Object* type, Stream* s, Object* declarations) if (superIndex) { const char* name = reinterpret_cast (pool[pool[superIndex - 1] - 1]); - typeSuper(type) = javaDeclaration(name, declarations); - assert(typeSuper(type)); + Class* super = module.javaClasses[name]; + clparser.setSuper(super); } unsigned interfaceCount = s->read2(); @@ -1005,17 +656,12 @@ parseJavaClass(Object* type, Stream* s, Object* declarations) const char* spec = reinterpret_cast(pool[specIndex - 1]); const char* memberType = fieldType(spec); - Object* member = Scalar::make - (type, memberType, name, sizeOf(memberType)); - - addMember(type, member); + clparser.add(FieldSpec(false, new Field(clparser.cl, memberType, spec, name, sizeOf(module, memberType)))); } } - if (typeSuper(type)) { - for (Object* p = typeMethods(typeSuper(type)); p; p = cdr(p)) { - addMethod(type, car(p)); - } + if (clparser.cl->super) { + clparser.cl->methods.insert(clparser.cl->super->methods.begin(), clparser.cl->super->methods.end()); } unsigned methodCount = s->read2(); @@ -1034,27 +680,27 @@ parseJavaClass(Object* type, Stream* s, Object* declarations) const char* spec = reinterpret_cast(pool[specIndex - 1]); if ((flags & (ACC_STATIC | ACC_PRIVATE)) == 0 and *name != '<') { - Object* method = Method::make(type, name, spec); - addMethod(type, method); - typeOverridesMethods(type) = true; + clparser.cl->methods.insert(Method(name, spec)); + clparser.cl->overridesMethods = true; } } } -Object* -parseType(Finder* finder, Object::ObjectType type, Object* p, - Object* declarations) +void parseType(Finder* finder, Module& module, Object* p) { const char* name = string(car(p)); + Class* cl = new Class(name); + + ClassParser clparser(cl); + const char* javaName = 0; if (cdr(p) and car(cdr(p))->type == Object::String) { p = cdr(p); javaName = string(car(p)); + cl->javaName = javaName; } - Type* t = Type::make(type, name, javaName); - bool isJavaType = javaName and *javaName != '['; if (isJavaType) { @@ -1065,640 +711,517 @@ parseType(Finder* finder, Object::ObjectType type, Object* p, } } client; System::Region* region = finder->find(append(javaName, ".class")); - if (region == 0) return 0; + if (region == 0) { + return; + } Stream s(&client, region->start(), region->length()); - parseJavaClass(t, &s, declarations); + parseJavaClass(module, clparser, &s); region->dispose(); } + module.add(cl); + for (p = cdr(p); p; p = cdr(p)) { - if (type == Object::Type) { - parseSubdeclaration(t, car(p), declarations); - } else { - Object* member = parseMember(t, car(p)); - if (member) { - assert(member->type == Object::Scalar); - addMember(t, member); - } - } + parseSubdeclaration(module, clparser, car(p)); } if (not isJavaType) { - if (type == Object::Type and typeSuper(t)) { - for (Object* p = typeMethods(typeSuper(t)); p; p = cdr(p)) { - addMethod(t, car(p)); - } + if (cl->super) { + cl->methods.insert(cl->super->methods.begin(), cl->super->methods.end()); } } - - return t; } -Object* -parseDeclaration(Finder* finder, Object* p, Object* declarations) +void parseDeclaration(Finder* finder, Module& module, Object* p) { const char* spec = string(car(p)); if (equal(spec, "type")) { - return parseType(finder, Object::Type, cdr(p), declarations); + parseType(finder, module, cdr(p)); } else { fprintf(stderr, "unexpected declaration spec: %s\n", spec); abort(); } } -Object* -parse(Finder* finder, Input* in) +void parse(Finder* finder, Input* in, Module& module) { Object* eos = Singleton::make(Object::Eos); List declarations; Object* o; while ((o = read(in, eos, 0)) != eos) { - Object* declaration = parseDeclaration(finder, o, declarations.first); - if (declaration) { - declarations.append(declaration); - } + parseDeclaration(finder, module, o); } - - return declarations.first; } -void -writeAccessorName(Output* out, Object* member, bool unsafe = false) +void layoutClass(Class* cl) { + if(cl->fixedSize >= 0) { + return; + } + + unsigned offset = BytesPerWord; + + unsigned size = 0; + unsigned alignment = BytesPerWord; + + alignment = BytesPerWord; + + for(std::vector::iterator it = cl->fields.begin(); it != cl->fields.end(); it++) { + Field& f = **it; + + alignment = f.elementSize; + offset = (offset + alignment - 1) & ~(alignment - 1); + f.offset = offset; + + size = f.elementSize; + + offset += size; + } + if(cl->arrayField) { + Field& f = *cl->arrayField; + + alignment = f.elementSize; + offset = (offset + alignment - 1) & ~(alignment - 1); + f.offset = offset; + } + // offset = (offset + BytesPerWord - 1) & ~(BytesPerWord - 1); + cl->fixedSize = offset; +} + +void layoutClasses(Module& module) { - const char* owner = typeName(memberOwner(member)); - out->write(owner); - out->write(capitalize(memberName(member))); - if (unsafe) { - out->write("Unsafe"); + for(std::map::iterator it = module.classes.begin(); it != module.classes.end(); ++it) { + Class* cl = it->second; + layoutClass(cl); } } void -writeOffset(Output* out, Object* offset, bool allocationStyle = false) +writeOffset(Output* out, size_t offset) { - if (offset) { - bool wrote = false; - unsigned padLevel = 0; - for (Object* p = offset; p; p = cdr(p)) { - Object* o = car(p); - if (wrote) { - out->write(" + "); - } - switch (o->type) { - case Object::Number: { - if (number(o)) { - out->write(number(o)); - wrote = true; - } - } break; + out->write(offset); +} - case Object::Array: { - out->write("pad(("); - if (allocationStyle) { - out->write("length"); +void +writeOffset(Output* out, Class* cl) +{ + out->write(cl->fixedSize); + if(cl->arrayField) { + out->write(" + pad(length * "); + out->write(cl->arrayField->elementSize); + out->write(")"); + } +} + +void +writeAccessorName(Output* out, Class* cl, Field& field) +{ + out->write(cl->name); + out->write(capitalize(field.name)); +} + +void writeFieldType(Output* out, Module& module, Field& f) { + if(f.javaSpec.size() != 0) { + if(f.javaSpec[0] == 'L') { + std::string className = f.javaSpec.substr(1, f.javaSpec.size() - 2); + std::map::iterator it = module.javaClasses.find(className); + if(it != module.javaClasses.end()) { + if(it->second->name == "jobject") { + // TEMPORARY HACK! + out->write("object"); } else { - out->write(typeName(memberOwner(o))); - out->write("Length"); - out->write("(o)"); + out->write("Gc"); + out->write(capitalize(it->second->name)); + out->write("*"); } - out->write(" * "); - out->write(arrayElementSize(o)); - out->write(")"); - ++ padLevel; - wrote = true; - } break; - - default: UNREACHABLE; + return; + } + } else if(f.javaSpec[0] == '[') { + std::map::iterator it = module.javaClasses.find(f.javaSpec); + if(it != module.javaClasses.end()) { + out->write("Gc"); + out->write(capitalize(it->second->name)); + out->write("*"); + return; } } - - for (unsigned i = 0; i < padLevel; ++i) out->write(")"); + } + std::map::iterator it = module.classes.find(f.typeName); + assert(f.typeName.size() > 0); + if(it != module.classes.end()) { + out->write("Gc"); + out->write(capitalize(it->second->name)); + out->write("*"); } else { - out->write("0"); + out->write(f.typeName); + } +} + +void writeSimpleFieldType(Output* out, Module& module, Field& f) { + if(f.javaSpec.size() != 0 && (f.javaSpec[0] == 'L' || f.javaSpec[0] == '[')) { + out->write("object"); + } else { + writeFieldType(out, module, f); } } void -writeAccessor(Output* out, Object* member, Object* offset, bool unsafe = false) +writeAccessor(Output* out, Module& module, Class* cl, Field& field, bool isArray) { - const char* typeName = memberTypeName(member); + std::string typeName = field.typeName; - if (not unsafe) { - out->write("const unsigned "); - out->write(capitalize(local::typeName(memberOwner(member)))); - out->write(capitalize(memberName(member))); - out->write(" = "); - writeOffset(out, offset); - out->write(";\n\n"); + out->write("const unsigned "); + out->write(capitalize(cl->name)); + out->write(capitalize(field.name)); + out->write(" = "); + writeOffset(out, field.offset); + out->write(";\n\n"); - out->write("#define HAVE_"); - out->write(capitalize(local::typeName(memberOwner(member)))); - out->write(capitalize(memberName(member))); - out->write(" 1\n\n"); - } + out->write("#define HAVE_"); + out->write(capitalize(cl->name)); + out->write(capitalize(field.name)); + out->write(" 1\n\n"); out->write("inline "); - if (endsWith("[0]", typeName)) { - out->write(take(strlen(typeName) - 3, typeName)); - out->write("*"); - } else { - out->write(typeName); + // if (endsWith("[0]", typeName)) { + // out->write(take(strlen(typeName) - 3, typeName)); + // out->write("*"); + // } else { + writeSimpleFieldType(out, module, field); out->write("&"); - } + // } out->write("\n"); - writeAccessorName(out, member, unsafe); + writeAccessorName(out, cl, field); out->write("(Thread* t UNUSED, object"); out->write(" o"); - if (member->type != Object::Scalar) { + if (isArray) { out->write(", unsigned i"); } out->write(") {\n"); - if (memberOwner(member)->type == Object::Type) { - if (not unsafe) { - out->write(" assertT(t, t->m->unsafe or "); - out->write("instanceOf(t, reinterpret_cast(arrayBodyUnsafe"); - out->write("(t, t->m->types, Gc::"); - out->write(capitalize(local::typeName(memberOwner(member)))); - out->write("Type))"); - out->write(", o));\n"); + out->write(" assertT(t, t->m->unsafe or "); + out->write("instanceOf(t, reinterpret_cast(arrayBodyUnsafe"); + out->write("(t, t->m->types, Gc::"); + out->write(capitalize(cl->name)); + out->write("Type))"); + out->write(", o));\n"); - if (member->type != Object::Scalar) { - out->write(" assertT(t, i < "); - out->write(local::typeName(memberOwner(member))); - out->write("Length(t, o));\n"); - } - } + if (isArray) { + out->write(" assertT(t, i < "); + out->write(cl->name); + out->write("Length(t, o));\n"); } - out->write(" return reinterpret_cast<"); + out->write(" return *reinterpret_cast<"); - if (endsWith("[0]", typeName)) { - out->write(take(strlen(typeName) - 3, typeName)); + // if (endsWith("[0]", typeName)) { + // out->write(take(strlen(typeName) - 3, typeName)); + // out->write("*"); + // } else { + writeSimpleFieldType(out, module, field); out->write("*"); - } else { - out->write(typeName); - out->write("&"); - } + // } - out->write(">(reinterpret_cast(o)"); - out->write("["); + out->write(">(reinterpret_cast(o) + "); - out->write(capitalize(local::typeName(memberOwner(member)))); - out->write(capitalize(memberName(member))); + out->write(capitalize(cl->name)); + out->write(capitalize(field.name)); - if (member->type != Object::Scalar) { + if (isArray) { out->write(" + (i * "); - unsigned elementSize = sizeOf(memberTypeName(member)); + unsigned elementSize = sizeOf(module, field.typeName); out->write(elementSize); out->write(")"); } - out->write("]);\n}\n\n"); -} - -Object* -typeBodyOffset(Object* type, Object* offset) -{ - MemberIterator it(type, true); - while (it.hasMore()) { - Object* m = it.next(); - switch (m->type) { - case Object::Scalar: { - offset = cons(Number::make(it.space()), offset); - } break; - - case Object::Array: { - if (it.padding()) offset = cons(Number::make(it.padding()), offset); - offset = cons(m, offset); - } break; - - default: UNREACHABLE; - } - } - unsigned padding = pad(BytesPerWord, it.alignment()); - if (padding) offset = cons(Number::make(padding), offset); - return offset; -} - -Object* -typeOffset(Object* type, Object* super) -{ - if (super) { - return typeBodyOffset(super, typeOffset(super, typeSuper(super))); - } else { - return (type->type == Object::Type ? - cons(Number::make(BytesPerWord), 0) : 0); - } -} - -Object* -typeOffset(Object* type) -{ - return typeOffset(0, type); + out->write(");\n}\n\n"); } void -writeAccessors(Output* out, Object* declarations) +writeAccessors(Output* out, Module& module) { - for (Object* p = declarations; p; p = cdr(p)) { - Object* o = car(p); - switch (o->type) { - case Object::Type: { - Object* offset = typeOffset - (o, o->type == Object::Type ? typeSuper(o) : 0); - for (MemberIterator it(o, true); it.hasMore();) { - Object* m = it.next(); - switch (m->type) { - case Object::Scalar: { - if (it.padding()) offset = cons(Number::make(it.padding()), offset); - writeAccessor(out, m, offset); - if (memberNoAssert(m)) { - writeAccessor(out, m, offset, true); - } - offset = cons(Number::make(it.size()), offset); - } break; + for(std::map::iterator it = module.classes.begin(); it != module.classes.end(); ++it) { + Class* cl = it->second; + for(std::vector::iterator it = cl->fields.begin(); it != cl->fields.end(); ++it) { + Field& f = **it; - case Object::Array: { - if (it.padding()) offset = cons(Number::make(it.padding()), offset); - writeAccessor(out, m, offset); - if (memberNoAssert(m)) { - writeAccessor(out, m, offset, true); - } - offset = cons(m, offset); - } break; - - default: UNREACHABLE; - } - } - } break; - - default: break; + writeAccessor(out, module, cl, f, false); + } + if(cl->arrayField) { + writeAccessor(out, module, cl, *cl->arrayField, true); } } } -unsigned -typeFixedSize(Object* type) -{ - unsigned length = BytesPerWord; - for (MemberIterator it(type); it.hasMore();) { - Object* m = it.next(); - switch (m->type) { - case Object::Scalar: { - length = pad(it.offset() + it.size()); - } break; - - case Object::Array: break; - - default: UNREACHABLE; - } - } - return length; -} - -unsigned -typeArrayElementSize(Object* type) -{ - for (MemberIterator it(type); it.hasMore();) { - Object* m = it.next(); - switch (m->type) { - case Object::Scalar: break; - - case Object::Array: { - return memberElementSize(m); - } break; - - default: UNREACHABLE; - } - } - return 0; -} - void -writeSizes(Output* out, Object* declarations) +writeSizes(Output* out, Module& module) { - for (Object* p = declarations; p; p = cdr(p)) { - Object* o = car(p); - switch (o->type) { - case Object::Type: { - out->write("const unsigned FixedSizeOf"); - out->write(capitalize(typeName(o))); + for(std::map::iterator it = module.classes.begin(); it != module.classes.end(); ++it) { + Class* cl = it->second; + + out->write("const unsigned FixedSizeOf"); + out->write(capitalize(cl->name)); + out->write(" = "); + out->write(cl->fixedSize); + out->write(";\n\n"); + + if (cl->arrayField) { + out->write("const unsigned ArrayElementSizeOf"); + out->write(capitalize(cl->name)); out->write(" = "); - out->write(typeFixedSize(o)); + out->write(cl->arrayField->elementSize); out->write(";\n\n"); - - int aes = typeArrayElementSize(o); - if (aes) { - out->write("const unsigned ArrayElementSizeOf"); - out->write(capitalize(typeName(o))); - out->write(" = "); - out->write(aes); - out->write(";\n\n"); - } - } break; - - default: break; } } } -const char* -obfuscate(const char* s) +std::string +obfuscate(const std::string& s) { - if (equal(s, "default")) { - return "default_"; - } else if (equal(s, "template")) { - return "template_"; - } else if (equal(s, "class")) { - return "class_"; - } else if (equal(s, "register")) { - return "register_"; - } else if (equal(s, "this")) { - return "this_"; + if (s == "default" || s == "template" || s == "class" || s == "register" + || s == "this") { + return s + "_"; } else { return s; } } void -writeConstructorParameters(Output* out, Object* t) +writeConstructorParameters(Output* out, Module& module, Class* cl) { - for (MemberIterator it(t); it.hasMore();) { - Object* m = it.next(); - switch (m->type) { - case Object::Scalar: { - out->write(", "); - out->write(memberTypeName(m)); - out->write(" "); - out->write(obfuscate(memberName(m))); - } break; - - default: break; - } + for(std::vector::iterator it = cl->fields.begin(); it != cl->fields.end(); ++it) { + Field& f = **it; + out->write(", "); + writeFieldType(out, module, f); + out->write(" "); + out->write(obfuscate(f.name)); } } void -writeConstructorArguments(Output* out, Object* t) +writeConstructorArguments(Output* out, Class* cl) { - for (MemberIterator it(t); it.hasMore();) { - Object* m = it.next(); - switch (m->type) { - case Object::Scalar: { - out->write(", "); - out->write(obfuscate(memberName(m))); - } break; - - default: break; - } + for(std::vector::iterator it = cl->fields.begin(); it != cl->fields.end(); ++it) { + Field& f = **it; + out->write(", "); + out->write(obfuscate(f.name)); } } void -writeConstructorInitializations(Output* out, Object* t) +writeConstructorInitializations(Output* out, Class* cl) { - for (MemberIterator it(t); it.hasMore();) { - Object* m = it.next(); - switch (m->type) { - case Object::Scalar: { - out->write(" "); - writeAccessorName(out, m); - out->write("(t, o) = "); - out->write(obfuscate(memberName(m))); - out->write(";\n"); - } break; - - default: break; - } + for(std::vector::iterator it = cl->fields.begin(); it != cl->fields.end(); ++it) { + Field& f = **it; + out->write(" o->"); + out->write(obfuscate(f.name)); + out->write("() = "); + out->write(obfuscate(f.name)); + out->write(";\n"); } } -void writeClassAccessors(Output* out, Object* t) -{ - for (MemberIterator it(t); it.hasMore();) { - Object* m = it.next(); - switch (m->type) { - case Object::Scalar: { - out->write(" "); - out->write(memberTypeName(m)); - out->write("& "); - out->write(obfuscate(memberName(m))); - out->write("() { return field_at<"); - out->write(memberTypeName(m)); - out->write(">("); - out->write(capitalize(local::typeName(memberOwner(m)))); - out->write(capitalize(memberName(m))); - out->write("); }\n"); - } break; - case Object::Array: { - out->write(" avian::util::Slice<"); - out->write(memberTypeName(m)); - out->write("> "); - out->write(obfuscate(memberName(m))); - out->write("() { return avian::util::Slice<"); - out->write(memberTypeName(m)); - out->write("> (&field_at<"); - out->write(memberTypeName(m)); - out->write(">("); - out->write(capitalize(local::typeName(memberOwner(m)))); - out->write(capitalize(memberName(m))); - out->write("), field_at("); - out->write(capitalize(local::typeName(memberOwner(m)))); - out->write("Length)); }\n"); - } break; - default: - break; - } +void writeClassDeclarations(Output* out, Module& module) +{ + for(std::map::iterator it = module.classes.begin(); it != module.classes.end(); it++) { + Class* cl = it->second; + + out->write("class Gc"); + out->write(capitalize(cl->name)); + out->write(";\n"); + } + out->write("\n"); +} + +void writeClassAccessors(Output* out, Module& module, Class* cl) +{ + for(std::vector::iterator it = cl->fields.begin(); it != cl->fields.end(); ++it) { + Field& f = **it; + out->write(" "); + writeFieldType(out, module, f); + out->write("& "); + out->write(obfuscate(f.name)); + out->write("() { return field_at<"); + writeFieldType(out, module, f); + out->write(">("); + out->write(capitalize(cl->name)); + out->write(capitalize(f.name)); + out->write("); }\n"); + } + if(cl->arrayField) { + Field& f = *cl->arrayField; + out->write(" avian::util::Slice<"); + out->write(f.typeName); + out->write("> "); + out->write(obfuscate(f.name)); + out->write("() { return avian::util::Slice<"); + out->write(f.typeName); + out->write("> (&field_at<"); + out->write(f.typeName); + out->write(">("); + out->write(capitalize(cl->name)); + out->write(capitalize(f.name)); + out->write("), field_at("); + out->write(capitalize(cl->name)); + out->write("Length)); }\n"); } } -void writeClassDeclarations(Output* out, Object* declarations) +void writeClasses(Output* out, Module& module) { - for (Object* p = declarations; p; p = cdr(p)) { - Object* o = car(p); - switch (o->type) { - case Object::Type: { - out->write("class Gc"); - out->write(capitalize(typeName(o))); - out->write(": public GcObject {\n"); - out->write(" public:\n"); - out->write(" static const Gc::Type Type = Gc::"); - out->write(capitalize(typeName(o))); - out->write("Type;\n"); - out->write(" static const size_t FixedSize = FixedSizeOf"); - out->write(capitalize(typeName(o))); - out->write(";\n\n"); + for(std::map::iterator it = module.classes.begin(); it != module.classes.end(); it++) { + Class* cl = it->second; - writeClassAccessors(out, o); + out->write("class Gc"); + out->write(capitalize(cl->name)); + out->write(": public GcObject {\n"); + out->write(" public:\n"); + out->write(" static const Gc::Type Type = Gc::"); + out->write(capitalize(cl->name)); + out->write("Type;\n"); + out->write(" static const size_t FixedSize = FixedSizeOf"); + out->write(capitalize(cl->name)); + out->write(";\n\n"); - out->write("};\n\n"); - } break; + writeClassAccessors(out, module, cl); - default: - break; - } + out->write("};\n\n"); } } void -writeInitializerDeclarations(Output* out, Object* declarations) +writeInitializerDeclarations(Output* out, Module& module) { - for (Object* p = declarations; p; p = cdr(p)) { - Object* o = car(p); - switch (o->type) { - case Object::Type: { - out->write("void init"); - out->write(capitalize(typeName(o))); - out->write("(Thread* t, object o"); + for(std::map::iterator it = module.classes.begin(); it != module.classes.end(); ++it) { + Class* cl = it->second; + out->write("void init"); + out->write(capitalize(cl->name)); + out->write("(Thread* t, Gc"); + out->write(capitalize(cl->name)); + out->write("* o"); - writeConstructorParameters(out, o); + writeConstructorParameters(out, module, cl); - out->write(");\n\n"); - } break; - - default: break; - } + out->write(");\n\n"); } } void -writeConstructorDeclarations(Output* out, Object* declarations) +writeConstructorDeclarations(Output* out, Module& module) { - for (Object* p = declarations; p; p = cdr(p)) { - Object* o = car(p); - switch (o->type) { - case Object::Type: { - out->write("Gc"); - out->write(capitalize(typeName(o))); - out->write("* make"); - out->write(capitalize(typeName(o))); - out->write("(Thread* t"); + for(std::map::iterator it = module.classes.begin(); it != module.classes.end(); ++it) { + Class* cl = it->second; + out->write("Gc"); + out->write(capitalize(cl->name)); + out->write("* make"); + out->write(capitalize(cl->name)); + out->write("(Thread* t"); - writeConstructorParameters(out, o); + writeConstructorParameters(out, module, cl); - out->write(");\n\n"); - } break; - - default: break; - } + out->write(");\n\n"); } } void -writeInitializers(Output* out, Object* declarations) +writeInitializers(Output* out, Module& module) { - for (Object* p = declarations; p; p = cdr(p)) { - Object* o = car(p); - switch (o->type) { - case Object::Type: { - out->write("void\ninit"); - out->write(capitalize(typeName(o))); - out->write("(Thread* t, object o"); + for(std::map::iterator it = module.classes.begin(); it != module.classes.end(); ++it) { + Class* cl = it->second; + out->write("void init"); + out->write(capitalize(cl->name)); + out->write("(Thread* t, Gc"); + out->write(capitalize(cl->name)); + out->write("* o"); - writeConstructorParameters(out, o); + writeConstructorParameters(out, module, cl); - out->write(")\n{\n"); + out->write(")\n{\n"); - out->write(" setObjectClass(t, o, "); - out->write("reinterpret_cast(arrayBody(t, t->m->types, Gc::"); - out->write(capitalize(typeName(o))); - out->write("Type)));\n"); + out->write(" setObjectClass(t, reinterpret_cast(o), "); + out->write("reinterpret_cast(reinterpret_cast(t->m->types)->body()[Gc::"); + out->write(capitalize(cl->name)); + out->write("Type]));\n"); - writeConstructorInitializations(out, o); + writeConstructorInitializations(out, cl); - out->write("}\n\n"); - } break; - - default: break; - } + out->write("}\n\n"); } } void -writeConstructors(Output* out, Object* declarations) +writeConstructors(Output* out, Module& module) { - for (Object* p = declarations; p; p = cdr(p)) { - Object* o = car(p); - switch (o->type) { - case Object::Type: { - out->write("Gc"); - out->write(capitalize(typeName(o))); - out->write("* make"); - out->write(capitalize(typeName(o))); - out->write("(Thread* t"); + for(std::map::iterator it = module.classes.begin(); it != module.classes.end(); ++it) { + Class* cl = it->second; + out->write("Gc"); + out->write(capitalize(cl->name)); + out->write("* make"); + out->write(capitalize(cl->name)); + out->write("(Thread* t"); - writeConstructorParameters(out, o); + writeConstructorParameters(out, module, cl); - out->write(")\n{\n"); + out->write(")\n{\n"); - bool hasObjectMask = strcmp(typeName(o), "singleton") == 0; - for (MemberIterator it(o); it.hasMore();) { - Object* m = it.next(); - if (m->type == Object::Scalar - and equal(memberTypeName(m), "object") - and not memberNoGC(m)) - { - out->write(" PROTECT(t, "); - out->write(obfuscate(memberName(m))); - out->write(");\n"); + bool hasObjectMask = cl->name == "singleton"; + for(std::vector::iterator it = cl->fields.begin(); it != cl->fields.end(); it++) { + Field& f = **it; + if (f.typeName == "object" + and not f.nogc) + { + out->write(" PROTECT(t, "); + out->write(obfuscate(f.name)); + out->write(");\n"); - hasObjectMask = true; - } else if (m->type == Object::Array - and equal(memberTypeName(m), "object") - and not memberNoGC(m)) - { - hasObjectMask = true; - } + hasObjectMask = true; } - - out->write(" object o = allocate(t, "); - writeOffset(out, typeOffset(o), true); - if (hasObjectMask) { - out->write(", true"); - } else { - out->write(", false"); - } - out->write(");\n"); - - out->write(" init"); - out->write(capitalize(typeName(o))); - out->write("(t, o"); - writeConstructorArguments(out, o); - out->write(");\n"); - - out->write(" return reinterpret_castwrite(capitalize(typeName(o))); - out->write("*>(o);\n}\n\n"); - } break; - - default: break; } + if(cl->arrayField) { + Field& f = *cl->arrayField; + if (f.typeName == "object" and not f.nogc) { + hasObjectMask = true; + } + } + + out->write(" Gc"); + out->write(capitalize(cl->name)); + out->write("* o = reinterpret_castwrite(capitalize(cl->name)); + out->write("*>(allocate(t, "); + writeOffset(out, cl); + if (hasObjectMask) { + out->write(", true"); + } else { + out->write(", false"); + } + out->write("));\n"); + + out->write(" init"); + out->write(capitalize(cl->name)); + out->write("(t, o"); + writeConstructorArguments(out, cl); + out->write(");\n"); + + out->write(" return o;\n}\n\n"); } } void -writeEnums(Output* out, Object* declarations) +writeEnums(Output* out, Module& module) { bool wrote = false; - for (Object* p = declarations; p; p = cdr(p)) { - Object* o = car(p); - switch (o->type) { - case Object::Type: { - if (wrote) { - out->write(",\n"); - } else { - wrote = true; - } - out->write(capitalize(typeName(o))); - out->write("Type"); - } break; - - default: break; + for(std::map::iterator it = module.classes.begin(); it != module.classes.end(); ++it) { + Class* cl = it->second; + if (wrote) { + out->write(",\n"); + } else { + wrote = true; } + out->write(capitalize(cl->name)); + out->write("Type"); } if (wrote) { @@ -1706,14 +1229,6 @@ writeEnums(Output* out, Object* declarations) } } -unsigned -methodCount(Object* o) -{ - unsigned c = 0; - for (Object* p = typeMethods(o); p; p = cdr(p)) ++c; - return c; -} - void set(uint32_t* mask, unsigned index) { @@ -1725,31 +1240,26 @@ set(uint32_t* mask, unsigned index) } uint32_t -typeObjectMask(Object* type) +typeObjectMask(Class* cl) { - assert(typeFixedSize(type) + typeArrayElementSize(type) + assert(cl->fixedSize + (cl->arrayField ? cl->arrayField->elementSize : 0) < 32 * BytesPerWord); uint32_t mask = 1; - for (MemberIterator it(type); it.hasMore();) { - Object* m = it.next(); - unsigned offset = it.offset() / BytesPerWord; + for(std::vector::iterator it = cl->fields.begin(); it != cl->fields.end(); it++) { + Field& f = **it; + unsigned offset = f.offset / BytesPerWord; + if(f.typeName == "object" && !f.nogc) { + set(&mask, offset); + } + } - switch (m->type) { - case Object::Scalar: { - if (memberGC(m)) { - set(&mask, offset); - } - } break; - - case Object::Array: { - if (memberGC(m)) { - set(&mask, offset); - } - } break; - - default: UNREACHABLE; + if(cl->arrayField) { + Field& f = *cl->arrayField; + unsigned offset = f.offset / BytesPerWord; + if(f.typeName == "object" && !f.nogc) { + set(&mask, offset); } } @@ -1757,110 +1267,82 @@ typeObjectMask(Object* type) } void -writeInitialization(Output* out, Object* type) +writeInitialization(Output* out, std::set& alreadyInited, Class* cl) { + if(alreadyInited.find(cl) != alreadyInited.end()) { + return; + } + alreadyInited.insert(cl); + if(cl->super && cl->name != "intArray" && cl->name != "class") { + writeInitialization(out, alreadyInited, cl->super); + } out->write("bootClass(t, Gc::"); - out->write(capitalize(typeName(type))); + out->write(capitalize(cl->name)); out->write("Type, "); - if (typeSuper(type)) { + if (cl->super) { out->write("Gc::"); - out->write(capitalize(typeName(typeSuper(type)))); + out->write(capitalize(cl->super->name)); out->write("Type"); } else { out->write("-1"); } out->write(", "); - if (typeObjectMask(type) != 1) { - out->write(typeObjectMask(type)); + if (typeObjectMask(cl) != 1) { + out->write(typeObjectMask(cl)); } else { out->write("0"); } out->write(", "); - out->write(typeFixedSize(type)); + out->write(cl->fixedSize); out->write(", "); - out->write(typeArrayElementSize(type)); + out->write(cl->arrayField ? cl->arrayField->elementSize : 0); out->write(", "); - out->write(methodCount(type)); + out->write(cl->methods.size()); out->write(");\n"); } -unsigned -typeCount(Object* declarations) -{ - unsigned count = 0; - for (Object* p = declarations; p; p = cdr(p)) { - Object* o = car(p); - switch (o->type) { - case Object::Type: { - ++ count; - } break; - - default: break; - } - } - 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) +writeInitializations(Output* out, Module& module) { - declarations = reorder(declarations); + std::set alreadyInited; - for (Object* p = declarations; p; p = cdr(p)) { - Object* o = car(p); - if (o->type == Object::Type) { - writeInitialization(out, o); + writeInitialization(out, alreadyInited, module.classes["intArray"]); + writeInitialization(out, alreadyInited, module.classes["class"]); + + for(std::map::iterator it = module.classes.begin(); it != module.classes.end(); ++it) { + Class* cl = it->second; + if(cl->name != "intArray" && cl->name != "class") { + writeInitialization(out, alreadyInited, cl); } } } void -writeJavaInitialization(Output* out, Object* type) +writeJavaInitialization(Output* out, Class* cl) { out->write("bootJavaClass(t, Gc::"); - out->write(capitalize(typeName(type))); + out->write(capitalize(cl->name)); out->write("Type, "); - if (typeSuper(type)) { + if (cl->super) { out->write("Gc::"); - out->write(capitalize(typeName(typeSuper(type)))); + out->write(capitalize(cl->super->name)); out->write("Type"); } else { out->write("-1"); } out->write(", \""); - out->write(typeJavaName(type)); + out->write(cl->javaName); out->write("\", "); - if (typeOverridesMethods(type)) { - out->write(methodCount(type)); + if (cl->overridesMethods) { + out->write(cl->methods.size()); } else { out->write("-1"); } @@ -1868,115 +1350,109 @@ writeJavaInitialization(Output* out, Object* type) } void -writeJavaInitializations(Output* out, Object* declarations) +writeJavaInitializations(Output* out, Module& module) { - for (Object* p = declarations; p; p = cdr(p)) { - Object* o = car(p); - if (o->type == Object::Type and typeJavaName(o)) { - writeJavaInitialization(out, o); + for(std::map::iterator it = module.classes.begin(); it != module.classes.end(); ++it) { + Class* cl = it->second; + if (cl->javaName.size()) { + writeJavaInitialization(out, cl); } } } void -writeNameInitialization(Output* out, Object* type) +writeNameInitialization(Output* out, Class* cl) { out->write("nameClass(t, Gc::"); - out->write(capitalize(typeName(type))); + out->write(capitalize(cl->name)); out->write("Type, \""); - if (equal(typeName(type), "jbyte") - or equal(typeName(type), "jboolean") - or equal(typeName(type), "jshort") - or equal(typeName(type), "jchar") - or equal(typeName(type), "jint") - or equal(typeName(type), "jlong") - or equal(typeName(type), "jfloat") - or equal(typeName(type), "jdouble") - or equal(typeName(type), "jvoid")) + if (cl->name == "jbyte" + or cl->name == "jboolean" + or cl->name == "jshort" + or cl->name == "jchar" + or cl->name == "jint" + or cl->name == "jlong" + or cl->name == "jfloat" + or cl->name == "jdouble" + or cl->name == "jvoid") { - out->write(typeName(type) + 1); + out->write(cl->name.substr(1, cl->name.size() - 1)); } else { out->write("vm::"); - out->write(typeName(type)); + out->write(cl->name); } out->write("\");\n"); } void -writeNameInitializations(Output* out, Object* declarations) +writeNameInitializations(Output* out, Module& module) { - for (Object* p = declarations; p; p = cdr(p)) { - Object* o = car(p); - if (o->type == Object::Type and typeJavaName(o) == 0) { - writeNameInitialization(out, o); + for(std::map::iterator it = module.classes.begin(); it != module.classes.end(); ++it) { + Class* cl = it->second; + if (!cl->javaName.size()) { + writeNameInitialization(out, cl); } } } void -writeMap(Output* out, Object* type) +writeMap(Output* out, Class* cl) { - for (MemberIterator it(type); it.hasMore();) { - Object* m = it.next(); + std::ostringstream ss; + uintptr_t ownerId = 0; + for(std::vector::iterator it = cl->fields.begin(); it != cl->fields.end(); it++) { + Field& f = **it; - if (it.sawSuperclassBoundary) { - it.sawSuperclassBoundary = false; - out->write("Type_pad, "); + if(ownerId && ownerId != f.ownerId) { + ss << "Type_pad, "; + } + ownerId = f.ownerId; + + ss << "Type_"; + ss << enumName(f.typeName); + if (f.nogc) { + ss << "_nogc"; } - switch (m->type) { - case Object::Scalar: { - out->write("Type_"); - out->write(memberTypeEnumName(m)); - if (memberNoGC(m)) { - out->write("_nogc"); - } - } break; - - case Object::Array: { - out->write("Type_array, "); - out->write("Type_"); - out->write(memberTypeEnumName(m)); - } break; - - default: UNREACHABLE; - } - - out->write(", "); + ss << ", "; } - out->write("Type_none"); + if(cl->arrayField) { + Field& f = *cl->arrayField; + if(ownerId && ownerId != f.ownerId) { + ss << "Type_pad, "; + } + ss << "Type_array, "; + ss << "Type_"; + ss << enumName(f.typeName); + ss << ", "; + } + + ss << "Type_none"; + + out->write(ss.str()); } void -writeMaps(Output* out, Object* declarations) +writeMaps(Output* out, Module& module) { - unsigned count = 0; - for (Object* p = declarations; p; p = cdr(p)) { - if (car(p)->type == Object::Type) { - ++ count; - } - } - out->write("Type types[]["); - out->write(count); + out->write(module.classes.size()); out->write("] = {\n"); bool wrote = false; - for (Object* p = declarations; p; p = cdr(p)) { - Object* o = car(p); - if (o->type == Object::Type) { - if (wrote) { - out->write(",\n"); - } else { - wrote = true; - } - - out->write("// "); - out->write(typeName(o)); - out->write("\n{ "); - writeMap(out, o); - out->write(" }"); + for(std::map::iterator it = module.classes.begin(); it != module.classes.end(); ++it) { + Class* cl = it->second; + if (wrote) { + out->write(",\n"); + } else { + wrote = true; } + + out->write("// "); + out->write(cl->name); + out->write("\n{ "); + writeMap(out, cl); + out->write(" }"); } out->write("\n};"); } @@ -2065,7 +1541,9 @@ int main(int ac, char** av) FileInput in(0, inStream, false); - Object* declarations = local::parse(finder, &in); + Module module; + local::parse(finder, &in, module); + local::layoutClasses(module); finder->dispose(); system->dispose(); @@ -2078,28 +1556,29 @@ int main(int ac, char** av) FileOutput out(0, outStream, false); if (local::equal(outputType.value, "enums")) { - local::writeEnums(&out, declarations); + local::writeEnums(&out, module); } else if (local::equal(outputType.value, "declarations")) { out.write("const unsigned TypeCount = "); - out.Output::write(local::typeCount(declarations)); + out.Output::write(module.classes.size()); out.write(";\n\n"); - local::writeAccessors(&out, declarations); - local::writeSizes(&out, declarations); - local::writeClassDeclarations(&out, declarations); - local::writeInitializerDeclarations(&out, declarations); - local::writeConstructorDeclarations(&out, declarations); + local::writeClassDeclarations(&out, module); + local::writeAccessors(&out, module); + local::writeSizes(&out, module); + local::writeClasses(&out, module); + local::writeInitializerDeclarations(&out, module); + local::writeConstructorDeclarations(&out, module); } else if (local::equal(outputType.value, "constructors")) { - local::writeInitializers(&out, declarations); - local::writeConstructors(&out, declarations); + local::writeInitializers(&out, module); + local::writeConstructors(&out, module); } else if (local::equal(outputType.value, "initializations")) { - local::writeInitializations(&out, declarations); + local::writeInitializations(&out, module); } else if (local::equal(outputType.value, "java-initializations")) { - local::writeJavaInitializations(&out, declarations); + local::writeJavaInitializations(&out, module); } else if (local::equal(outputType.value, "name-initializations")) { - local::writeNameInitializations(&out, declarations); + local::writeNameInitializations(&out, module); } else if (local::equal(outputType.value, "maps")) { - local::writeMaps(&out, declarations); + local::writeMaps(&out, module); } out.write("\n"); diff --git a/src/tools/type-generator/sexpr.h b/src/tools/type-generator/sexpr.h index 07eb6e0d72..dc208c94ec 100644 --- a/src/tools/type-generator/sexpr.h +++ b/src/tools/type-generator/sexpr.h @@ -30,7 +30,6 @@ class Object { Method, Type, Pair, - Number, Character, String, Eos