From b5699cc9dc6a8559c000be81fc8e758bffaeeed8 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Wed, 28 May 2014 22:17:25 -0600 Subject: [PATCH] move Machine::*Type to GcObject::*Type --- include/avian/codegen/promise.h | 2 +- include/avian/codegen/registers.h | 2 +- include/avian/util/arg-parser.h | 2 +- src/avian/classpath-common.h | 200 ++-- src/avian/machine.h | 567 +++++----- src/avian/process.h | 16 +- src/avian/processor.h | 33 +- src/avian/util.h | 22 +- src/builtin.cpp | 110 +- src/classpath-android.cpp | 248 +++-- src/classpath-avian.cpp | 82 +- src/classpath-openjdk.cpp | 420 +++---- src/codegen/compiler/resource.cpp | 2 +- src/compile.cpp | 1423 ++++++++++++------------ src/heapdump.cpp | 2 +- src/interpret.cpp | 595 +++++----- src/jnienv.cpp | 257 ++--- src/machine.cpp | 1238 +++++++++++---------- src/process.cpp | 46 +- src/tools/bootimage-generator/main.cpp | 182 +-- src/tools/type-generator/main.cpp | 129 ++- src/util.cpp | 70 +- 22 files changed, 2916 insertions(+), 2732 deletions(-) diff --git a/include/avian/codegen/promise.h b/include/avian/codegen/promise.h index c1afc6a447..09ef8ba835 100644 --- a/include/avian/codegen/promise.h +++ b/include/avian/codegen/promise.h @@ -160,4 +160,4 @@ class DelayedPromise: public ListenPromise { } // namespace codegen } // namespace avian -#endif // AVIAN_CODEGEN_PROMISE_H \ No newline at end of file +#endif // AVIAN_CODEGEN_PROMISE_H diff --git a/include/avian/codegen/registers.h b/include/avian/codegen/registers.h index 4819d60043..0b87e2f4d8 100644 --- a/include/avian/codegen/registers.h +++ b/include/avian/codegen/registers.h @@ -70,4 +70,4 @@ public: } // namespace codegen } // namespace avian -#endif // AVIAN_CODEGEN_REGISTERS_H \ No newline at end of file +#endif // AVIAN_CODEGEN_REGISTERS_H diff --git a/include/avian/util/arg-parser.h b/include/avian/util/arg-parser.h index 3a94dc93e9..6b6d29d8ea 100644 --- a/include/avian/util/arg-parser.h +++ b/include/avian/util/arg-parser.h @@ -46,4 +46,4 @@ public: } // namespace avian } // namespace util -#endif // AVIAN_UTIL_ARG_PARSER_H \ No newline at end of file +#endif // AVIAN_UTIL_ARG_PARSER_H diff --git a/src/avian/classpath-common.h b/src/avian/classpath-common.h index 12de97659b..e51058ae5e 100644 --- a/src/avian/classpath-common.h +++ b/src/avian/classpath-common.h @@ -29,16 +29,16 @@ getTrace(Thread* t, unsigned skipCount) virtual bool visit(Processor::StackWalker* walker) { if (skipCount == 0) { - object method = walker->method(); + GcMethod* method = walker->method(); if (isAssignableFrom - (t, type(t, Machine::ThrowableType), methodClass(t, method)) + (t, type(t, GcThrowable::Type), cast(t, method->class_())) and vm::strcmp(reinterpret_cast(""), - &byteArrayBody(t, methodName(t, method), 0)) + &byteArrayBody(t, method->name(), 0)) == 0) { return true; } else { - trace = makeTrace(t, walker); + trace = reinterpret_cast(makeTrace(t, walker)); return false; } } else { @@ -75,9 +75,9 @@ arrayCopy(Thread* t, object src, int32_t srcOffset, object dst, { if (LIKELY(src and dst)) { if (LIKELY(compatibleArrayTypes - (t, objectClass(t, src), objectClass(t, dst)))) + (t, reinterpret_cast(objectClass(t, src)), reinterpret_cast(objectClass(t, dst))))) { - unsigned elementSize = classArrayElementSize(t, objectClass(t, src)); + unsigned elementSize = objectClass(t, src)->arrayElementSize(); if (LIKELY(elementSize)) { intptr_t sl = fieldAtOffset(src, BytesPerWord); @@ -98,13 +98,13 @@ arrayCopy(Thread* t, object src, int32_t srcOffset, object dst, length * elementSize); } - if (classObjectMask(t, objectClass(t, dst))) { + if (objectClass(t, dst)->objectMask()) { mark(t, dst, ArrayBody + (dstOffset * BytesPerWord), length); } return; } else { - throwNew(t, Machine::IndexOutOfBoundsExceptionType); + throwNew(t, GcIndexOutOfBoundsException::Type); } } else { return; @@ -112,11 +112,11 @@ arrayCopy(Thread* t, object src, int32_t srcOffset, object dst, } } } else { - throwNew(t, Machine::NullPointerExceptionType); + throwNew(t, GcNullPointerException::Type); return; } - throwNew(t, Machine::ArrayStoreExceptionType); + throwNew(t, GcArrayStoreException::Type); } void @@ -239,7 +239,7 @@ loadLibrary(Thread* t, const char* path, const char* name, bool mapName, runOnLoadIfFound(t, lib); } } else if (throw_) { - throwNew(t, Machine::UnsatisfiedLinkErrorType, + throwNew(t, GcUnsatisfiedLinkError::Type, "library not found in %s: %s", path, name); } @@ -251,26 +251,26 @@ clone(Thread* t, object o) { PROTECT(t, o); - object class_ = objectClass(t, o); + GcClass* class_ = objectClass(t, o); unsigned size = baseSize(t, o, class_) * BytesPerWord; object clone; - if (classArrayElementSize(t, class_)) { - clone = static_cast(allocate(t, size, classObjectMask(t, class_))); + if (class_->arrayElementSize()) { + clone = static_cast(allocate(t, size, class_->objectMask())); memcpy(clone, o, size); // clear any object header flags: setObjectClass(t, o, objectClass(t, o)); - } else if (instanceOf(t, type(t, Machine::CloneableType), o)) { + } else if (instanceOf(t, type(t, GcCloneable::Type), o)) { clone = make(t, class_); memcpy(reinterpret_cast(clone) + 1, reinterpret_cast(o) + 1, size - BytesPerWord); } else { - object classNameSlash = className(t, objectClass(t, o)); + object classNameSlash = objectClass(t, o)->name(); THREAD_RUNTIME_ARRAY(t, char, classNameDot, byteArrayLength(t, classNameSlash)); replace('/', '.', RUNTIME_ARRAY_BODY(classNameDot), reinterpret_cast(&byteArrayBody(t, classNameSlash, 0))); - throwNew(t, Machine::CloneNotSupportedExceptionType, "%s", + throwNew(t, GcCloneNotSupportedException::Type, "%s", RUNTIME_ARRAY_BODY(classNameDot)); } @@ -282,13 +282,13 @@ makeStackTraceElement(Thread* t, object e) { PROTECT(t, e); - object class_ = className(t, methodClass(t, traceElementMethod(t, e))); - PROTECT(t, class_); + object class_name = className(t, methodClass(t, traceElementMethod(t, e))); + PROTECT(t, class_name); - THREAD_RUNTIME_ARRAY(t, char, s, byteArrayLength(t, class_)); + THREAD_RUNTIME_ARRAY(t, char, s, byteArrayLength(t, class_name)); replace('/', '.', RUNTIME_ARRAY_BODY(s), - reinterpret_cast(&byteArrayBody(t, class_, 0))); - class_ = makeString(t, "%s", RUNTIME_ARRAY_BODY(s)); + reinterpret_cast(&byteArrayBody(t, class_name, 0))); + class_name = makeString(t, "%s", RUNTIME_ARRAY_BODY(s)); object method = methodName(t, traceElementMethod(t, e)); PROTECT(t, method); @@ -297,13 +297,13 @@ makeStackTraceElement(Thread* t, object e) (t, method, 0, byteArrayLength(t, method) - 1); unsigned line = t->m->processor->lineNumber - (t, traceElementMethod(t, e), traceElementIp(t, e)); + (t, cast(t, traceElementMethod(t, e)), traceElementIp(t, e)); object file = classSourceFile(t, methodClass(t, traceElementMethod(t, e))); file = file ? t->m->classpath->makeString (t, file, 0, byteArrayLength(t, file) - 1) : 0; - return makeStackTraceElement(t, class_, method, file, line); + return reinterpret_cast(makeStackTraceElement(t, class_name, method, file, line)); } object @@ -311,19 +311,19 @@ translateInvokeResult(Thread* t, unsigned returnCode, object o) { switch (returnCode) { case ByteField: - return makeByte(t, intValue(t, o)); + return reinterpret_cast(makeByte(t, intValue(t, o))); case BooleanField: - return makeBoolean(t, intValue(t, o) != 0); + return reinterpret_cast(makeBoolean(t, intValue(t, o) != 0)); case CharField: - return makeChar(t, intValue(t, o)); + return reinterpret_cast(makeChar(t, intValue(t, o))); case ShortField: - return makeShort(t, intValue(t, o)); + return reinterpret_cast(makeShort(t, intValue(t, o))); case FloatField: - return makeFloat(t, intValue(t, o)); + return reinterpret_cast(makeFloat(t, intValue(t, o))); case IntField: case LongField: @@ -332,14 +332,14 @@ translateInvokeResult(Thread* t, unsigned returnCode, object o) return o; case DoubleField: - return makeDouble(t, longValue(t, o)); + return reinterpret_cast(makeDouble(t, longValue(t, o))); default: abort(t); } } -object +GcClass* resolveClassBySpec(Thread* t, object loader, const char* spec, unsigned specLength) { @@ -350,7 +350,7 @@ resolveClassBySpec(Thread* t, object loader, const char* spec, RUNTIME_ARRAY_BODY(s)[specLength - 2] = 0; return resolveClass(t, loader, RUNTIME_ARRAY_BODY(s)); } - + case '[': { THREAD_RUNTIME_ARRAY(t, char, s, specLength + 1); memcpy(RUNTIME_ARRAY_BODY(s), spec, specLength); @@ -389,15 +389,15 @@ resolveParameterTypes(Thread* t, object loader, object spec, while (byteArrayBody(t, spec, offset) != ';') ++ offset; ++ offset; - object type = resolveClassBySpec + GcClass* type = resolveClassBySpec (t, loader, reinterpret_cast(&byteArrayBody(t, spec, start)), offset - start); - - list = makePair(t, type, list); + + list = reinterpret_cast(makePair(t, reinterpret_cast(type), list)); ++ count; } break; - + case '[': { unsigned start = offset; while (byteArrayBody(t, spec, offset) == '[') ++ offset; @@ -412,18 +412,18 @@ resolveParameterTypes(Thread* t, object loader, object spec, ++ offset; break; } - - object type = resolveClassBySpec + + GcClass* type = resolveClassBySpec (t, loader, reinterpret_cast(&byteArrayBody(t, spec, start)), offset - start); - - list = makePair(t, type, list); + + list = reinterpret_cast(makePair(t, reinterpret_cast(type), list)); ++ count; } break; default: - list = makePair - (t, primitiveClass(t, byteArrayBody(t, spec, offset)), list); + list = reinterpret_cast(makePair + (t, reinterpret_cast(primitiveClass(t, byteArrayBody(t, spec, offset))), list)); ++ offset; ++ count; break; @@ -443,13 +443,13 @@ resolveParameterJTypes(Thread* t, object loader, object spec, (t, loader, spec, parameterCount, returnTypeSpec); PROTECT(t, list); - + object array = makeObjectArray - (t, type(t, Machine::JclassType), *parameterCount); + (t, type(t, GcJclass::Type), *parameterCount); PROTECT(t, array); for (int i = *parameterCount - 1; i >= 0; --i) { - object c = getJClass(t, pairFirst(t, list)); + object c = getJClass(t, cast(t, pairFirst(t, list))); set(t, array, ArrayBody + (i * BytesPerWord), c); list = pairSecond(t, list); } @@ -461,14 +461,14 @@ object resolveExceptionJTypes(Thread* t, object loader, object addendum) { if (addendum == 0 or methodAddendumExceptionTable(t, addendum) == 0) { - return makeObjectArray(t, type(t, Machine::JclassType), 0); + return makeObjectArray(t, type(t, GcJclass::Type), 0); } PROTECT(t, loader); PROTECT(t, addendum); object array = makeObjectArray - (t, type(t, Machine::JclassType), + (t, type(t, GcJclass::Type), shortArrayLength(t, methodAddendumExceptionTable(t, addendum))); PROTECT(t, array); @@ -478,16 +478,16 @@ resolveExceptionJTypes(Thread* t, object loader, object addendum) uint16_t index = shortArrayBody (t, methodAddendumExceptionTable(t, addendum), i) - 1; - object o = singletonObject(t, addendumPool(t, addendum), index); + object o = singletonObject(t, cast(t, addendumPool(t, addendum)), index); + + if (objectClass(t, o) == type(t, GcReference::Type)) { + o = reinterpret_cast(resolveClass(t, loader, referenceName(t, o))); - if (objectClass(t, o) == type(t, Machine::ReferenceType)) { - o = resolveClass(t, loader, referenceName(t, o)); - set(t, addendumPool(t, addendum), SingletonBody + (index * BytesPerWord), o); } - o = getJClass(t, o); + o = getJClass(t, cast(t, o)); set(t, array, ArrayBody + (i * BytesPerWord), o); } @@ -496,41 +496,41 @@ resolveExceptionJTypes(Thread* t, object loader, object addendum) } object -invoke(Thread* t, object method, object instance, object args) +invoke(Thread* t, GcMethod* method, object instance, object args) { PROTECT(t, method); PROTECT(t, instance); PROTECT(t, args); - if (methodFlags(t, method) & ACC_STATIC) { + if (method->flags() & ACC_STATIC) { instance = 0; } if ((args == 0 ? 0 : objectArrayLength(t, args)) - != methodParameterCount(t, method)) + != method->parameterCount()) { - throwNew(t, Machine::IllegalArgumentExceptionType); + throwNew(t, GcIllegalArgumentException::Type); } - if (methodParameterCount(t, method)) { - unsigned specLength = byteArrayLength(t, methodSpec(t, method)); + if (method->parameterCount()) { + unsigned specLength = byteArrayLength(t, method->spec()); THREAD_RUNTIME_ARRAY(t, char, spec, specLength); memcpy(RUNTIME_ARRAY_BODY(spec), - &byteArrayBody(t, methodSpec(t, method), 0), specLength); + &byteArrayBody(t, method->spec(), 0), specLength); unsigned i = 0; for (MethodSpecIterator it(t, RUNTIME_ARRAY_BODY(spec)); it.hasNext();) { - object type; + GcClass* type; bool objectType = false; const char* p = it.next(); switch (*p) { - case 'Z': type = vm::type(t, Machine::BooleanType); break; - case 'B': type = vm::type(t, Machine::ByteType); break; - case 'S': type = vm::type(t, Machine::ShortType); break; - case 'C': type = vm::type(t, Machine::CharType); break; - case 'I': type = vm::type(t, Machine::IntType); break; - case 'F': type = vm::type(t, Machine::FloatType); break; - case 'J': type = vm::type(t, Machine::LongType); break; - case 'D': type = vm::type(t, Machine::DoubleType); break; + case 'Z': type = vm::type(t, GcBoolean::Type); break; + case 'B': type = vm::type(t, GcByte::Type); break; + case 'S': type = vm::type(t, GcShort::Type); break; + case 'C': type = vm::type(t, GcChar::Type); break; + case 'I': type = vm::type(t, GcInt::Type); break; + case 'F': type = vm::type(t, GcFloat::Type); break; + case 'J': type = vm::type(t, GcLong::Type); break; + case 'D': type = vm::type(t, GcDouble::Type); break; case 'L': case '[': { @@ -546,7 +546,7 @@ invoke(Thread* t, object 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, methodClass(t, method)), + (t, classLoader(t, method->class_()), RUNTIME_ARRAY_BODY(name)); } break; @@ -560,20 +560,20 @@ invoke(Thread* t, object method, object instance, object args) { // fprintf(stderr, "%s is not a %s\n", arg ? &byteArrayBody(t, className(t, objectClass(t, arg)), 0) : reinterpret_cast(""), &byteArrayBody(t, className(t, type), 0)); - throwNew(t, Machine::IllegalArgumentExceptionType); + throwNew(t, GcIllegalArgumentException::Type); } } } - initClass(t, methodClass(t, method)); + initClass(t, cast(t, method->class_())); - unsigned returnCode = methodReturnCode(t, method); + unsigned returnCode = method->returnCode(); THREAD_RESOURCE0(t, { if (t->exception) { t->exception = makeThrowable - (t, Machine::InvocationTargetExceptionType, 0, 0, t->exception); - + (t, GcInvocationTargetException::Type, 0, 0, t->exception); + set(t, t->exception, InvocationTargetExceptionTarget, throwableCause(t, t->exception)); } @@ -592,29 +592,29 @@ invoke(Thread* t, object method, object instance, object args) // only safe to call during bootstrap when there's only one thread // running: void -intercept(Thread* t, object c, const char* name, const char* spec, +intercept(Thread* t, GcClass* c, const char* name, const char* spec, void* function, bool updateRuntimeData) { - object m = findMethodOrNull(t, c, name, spec); + GcMethod* m = findMethodOrNull(t, c, name, spec); if (m) { PROTECT(t, m); - methodFlags(t, m) |= ACC_NATIVE; + m->flags() |= ACC_NATIVE; if (updateRuntimeData) { - object clone = methodClone(t, m); + GcMethod* clone = methodClone(t, m); // make clone private to prevent vtable updates at compilation // time. Otherwise, our interception might be bypassed by calls // through the vtable. - methodFlags(t, clone) |= ACC_PRIVATE; + clone->flags() |= ACC_PRIVATE; + + object native = reinterpret_cast(makeNativeIntercept(t, function, true, reinterpret_cast(clone))); - object native = makeNativeIntercept(t, function, true, clone); - PROTECT(t, native); - + object runtimeData = getMethodRuntimeData(t, m); - + set(t, runtimeData, MethodRuntimeDataNative, native); } } else { @@ -633,7 +633,7 @@ Finder* getFinder(Thread* t, const char* name, unsigned nameLength) { ACQUIRE(t, t->m->referenceLock); - + for (object p = root(t, Machine::VirtualFileFinders); p; p = finderNext(t, p)) { @@ -646,7 +646,7 @@ getFinder(Thread* t, const char* name, unsigned nameLength) } } - object n = makeByteArray(t, nameLength + 1); + object n = reinterpret_cast(makeByteArray(t, nameLength + 1)); memcpy(&byteArrayBody(t, n, 0), name, nameLength); void* p = t->m->libraries->resolve @@ -660,8 +660,8 @@ getFinder(Thread* t, const char* name, unsigned nameLength) uint8_t* data = function(&size); if (data) { Finder* f = makeFinder(t->m->system, t->m->heap, data, size); - object finder = makeFinder - (t, f, n, root(t, Machine::VirtualFileFinders)); + object finder = reinterpret_cast(makeFinder + (t, f, n, root(t, Machine::VirtualFileFinders))); setRoot(t, Machine::VirtualFileFinders, finder); @@ -693,7 +693,7 @@ getDeclaredClasses(Thread* t, object c, bool publicOnly) } } - object result = makeObjectArray(t, type(t, Machine::JclassType), count); + object result = makeObjectArray(t, type(t, GcJclass::Type), count); PROTECT(t, result); for (unsigned i = 0; i < arrayLength(t, table); ++i) { @@ -703,11 +703,13 @@ getDeclaredClasses(Thread* t, object c, bool publicOnly) and ((not publicOnly) or (innerClassReferenceFlags(t, reference) & ACC_PUBLIC))) { - object inner = getJClass - (t, resolveClass - (t, classLoader(t, c), - innerClassReferenceInner(t, arrayBody(t, table, i)))); - + object inner = getJClass( + t, + resolveClass( + t, + classLoader(t, c), + innerClassReferenceInner(t, arrayBody(t, table, i)))); + -- count; set(t, result, ArrayBody + (count * BytesPerWord), inner); } @@ -717,7 +719,7 @@ getDeclaredClasses(Thread* t, object c, bool publicOnly) } } - return makeObjectArray(t, type(t, Machine::JclassType), 0); + return makeObjectArray(t, type(t, GcJclass::Type), 0); } object @@ -733,9 +735,11 @@ getDeclaringClass(Thread* t, object c) (&byteArrayBody(t, innerClassReferenceInner(t, reference), 0), &byteArrayBody(t, className(t, c), 0)) == 0) { - return getJClass - (t, resolveClass - (t, classLoader(t, c), innerClassReferenceOuter(t, reference))); + return getJClass( + t, + resolveClass(t, + classLoader(t, c), + innerClassReferenceOuter(t, reference))); } } } @@ -758,7 +762,7 @@ classModifiers(Thread* t, object c) &byteArrayBody(t, innerClassReferenceInner(t, reference), 0))) { return innerClassReferenceFlags(t, reference); - } + } } } } diff --git a/src/avian/machine.h b/src/avian/machine.h index f0cc3c3252..55cf100486 100644 --- a/src/avian/machine.h +++ b/src/avian/machine.h @@ -68,7 +68,7 @@ using namespace avian::util; private: \ object name; \ Thread::SingleProtector protector; \ - } MAKE_NAME(resource_)(t, name); + } MAKE_NAME(resource_)(t, reinterpret_cast(name)); #define THREAD_RESOURCE(t, type, name, releaseBody) \ class MAKE_NAME(Resource_): public Thread::AutoResource { \ @@ -1181,11 +1181,34 @@ class Reference { class Classpath; -class Machine { +class Gc { public: enum Type { #include "type-enums.cpp" }; +}; + +class GcObject { + public: + + template + T* as(Thread* t); + + template + bool isa(Thread* t); + + protected: + template + T& field_at(size_t offset) + { + return *reinterpret_cast(reinterpret_cast(this) + offset); + } +}; + +class GcFinalizer; + +class Machine { + public: enum AllocationType { MovableAllocation, @@ -1230,7 +1253,7 @@ class Machine { unsigned propertyCount, const char** arguments, unsigned argumentCount, unsigned stackSizeInBytes); - ~Machine() { + ~Machine() { dispose(); } @@ -1269,8 +1292,8 @@ class Machine { BootImage* bootimage; object types; object roots; - object finalizers; - object tenuredFinalizers; + GcFinalizer* finalizers; + GcFinalizer* tenuredFinalizers; object finalizeQueue; object weakReferences; object tenuredWeakReferences; @@ -1364,13 +1387,13 @@ class Thread { class SingleProtector: public Protector { public: - SingleProtector(Thread* t, object* p): Protector(t), p(p) { } + SingleProtector(Thread* t, void* p): Protector(t), p(p) { } virtual void visit(Heap::Visitor* v) { v->visit(p); } - object* p; + void* p; }; class Resource { @@ -1399,7 +1422,7 @@ class Thread { class ClassInitStack: public AutoResource { public: - ClassInitStack(Thread* t, object class_): + ClassInitStack(Thread* t, GcClass* class_): AutoResource(t), next(t->classInitStack), class_(class_), @@ -1417,7 +1440,7 @@ class Thread { } ClassInitStack* next; - object class_; + GcClass* class_; SingleProtector protector; }; @@ -1554,7 +1577,7 @@ class Thread { class Classpath { public: virtual object - makeJclass(Thread* t, object class_) = 0; + makeJclass(Thread* t, GcClass* class_) = 0; virtual object makeString(Thread* t, object array, int32_t offset, int32_t length) = 0; @@ -1563,7 +1586,7 @@ class Classpath { makeThread(Thread* t, Thread* parent) = 0; virtual object - makeJMethod(Thread* t, object vmMethod) = 0; + makeJMethod(Thread* t, GcMethod* vmMethod) = 0; virtual object getVMMethod(Thread* t, object jmethod) = 0; @@ -1581,7 +1604,7 @@ class Classpath { runThread(Thread* t) = 0; virtual void - resolveNative(Thread* t, object method) = 0; + resolveNative(Thread* t, GcMethod* method) = 0; virtual void interceptMethods(Thread* t) = 0; @@ -1607,10 +1630,10 @@ class Classpath { getDirectBufferCapacity(Thread* t, object buffer) = 0; virtual bool - canTailCall(Thread* t, object caller, object calleeClassName, + canTailCall(Thread* t, GcMethod* caller, object calleeClassName, object calleeMethodName, object calleeMethodSpec) = 0; - virtual object libraryClassLoader(Thread* t, object caller) = 0; + virtual object libraryClassLoader(Thread* t, GcMethod* caller) = 0; virtual void shutDown(Thread* t) = 0; @@ -1656,12 +1679,17 @@ Classpath* makeClasspath(System* system, Allocator* allocator, const char* javaHome, const char* embedPrefix); -typedef uint64_t (JNICALL *FastNativeFunction)(Thread*, object, uintptr_t*); +typedef uint64_t (JNICALL *FastNativeFunction)(Thread*, GcMethod*, uintptr_t*); -inline object +inline GcClass* objectClass(Thread*, object o) { - return maskAlignedPointer(fieldAtOffset(o, 0)); + return reinterpret_cast(maskAlignedPointer(fieldAtOffset(o, 0))); +} +inline GcClass* +objectClass(Thread*, GcObject* o) +{ + return reinterpret_cast(maskAlignedPointer(fieldAtOffset(o, 0))); } inline unsigned @@ -1887,11 +1915,11 @@ set(Thread* t, object target, unsigned offset, object value) } inline void -setObjectClass(Thread*, object o, object value) +setObjectClass(Thread*, object o, GcClass* c) { fieldAtOffset(o, 0) = reinterpret_cast - (reinterpret_cast(value) + (reinterpret_cast(c) | (reinterpret_cast (fieldAtOffset(o, 0)) & (~PointerMask))); } @@ -1923,7 +1951,36 @@ object& arrayBodyUnsafe(Thread*, object, unsigned); bool -instanceOf(Thread* t, object class_, object o); +instanceOf(Thread* t, GcClass* class_, object o); + +template +T* GcObject::as(Thread* t UNUSED) +{ + assert(t, + t->m->unsafe + || instanceOf(t, reinterpret_cast(arrayBodyUnsafe(t, t->m->types, T::Type)), reinterpret_cast(this))); + return static_cast(this); +} + +template +bool GcObject::isa(Thread* t) +{ + return instanceOf(t, reinterpret_cast(arrayBodyUnsafe(t, t->m->types, T::Type)), reinterpret_cast(this)); +} + +template +T* cast(Thread* t UNUSED, object o) +{ + if(o == 0) { + return 0; + } + assert(t, + t->m->unsafe || instanceOf(t, + reinterpret_cast(arrayBodyUnsafe( + t, t->m->types, T::Type)), + o)); + return reinterpret_cast(o); +} #include "type-declarations.cpp" @@ -2019,11 +2076,11 @@ inline Thread* startThread(Thread* t, object javaThread) { { PROTECT(t, javaThread); - + stress(t); ACQUIRE_RAW(t, t->m->stateLock); - + if (t->m->threadCount > t->m->liveCount + ZombieCollectionThreshold) { collect(t, Heap::MinorCollection); } @@ -2049,7 +2106,7 @@ registerDaemon(Thread* t) atomicOr(&(t->flags), Thread::DaemonFlag); ++ t->m->daemonCount; - + t->m->stateLock->notifyAll(t->systemThread); } @@ -2114,16 +2171,16 @@ setRoot(Thread* t, Machine::Root root, object value) set(t, t->m->roots, ArrayBody + (root * BytesPerWord), value); } -inline object -type(Thread* t, Machine::Type type) +inline GcClass* +type(Thread* t, Gc::Type type) { - return arrayBody(t, t->m->types, type); + return cast(t, arrayBody(t, t->m->types, type)); } inline void -setType(Thread* t, Machine::Type type, object value) +setType(Thread* t, Gc::Type type, GcClass* value) { - set(t, t->m->types, ArrayBody + (type * BytesPerWord), value); + set(t, t->m->types, ArrayBody + (type * BytesPerWord), reinterpret_cast(value)); } inline bool @@ -2145,13 +2202,13 @@ hashTaken(Thread*, object o) } inline unsigned -baseSize(Thread* t, object o, object class_) +baseSize(Thread* t UNUSED, object o, GcClass* class_) { - assert(t, classFixedSize(t, class_) >= BytesPerWord); + assert(t, class_->fixedSize() >= BytesPerWord); - return ceilingDivide(classFixedSize(t, class_), BytesPerWord) - + ceilingDivide(classArrayElementSize(t, class_) - * fieldAtOffset(o, classFixedSize(t, class_) - BytesPerWord), + return ceilingDivide(class_->fixedSize(), BytesPerWord) + + ceilingDivide(class_->arrayElementSize() + * fieldAtOffset(o, class_->fixedSize() - BytesPerWord), BytesPerWord); } @@ -2168,26 +2225,26 @@ makeTrace(Thread* t) } inline object -makeNew(Thread* t, object class_) +makeNew(Thread* t, GcClass* class_) { assert(t, t->state == Thread::NoState or t->state == Thread::ActiveState); PROTECT(t, class_); - unsigned sizeInBytes = pad(classFixedSize(t, class_)); + unsigned sizeInBytes = pad(class_->fixedSize()); assert(t, sizeInBytes); - object instance = allocate(t, sizeInBytes, classObjectMask(t, class_)); + object instance = allocate(t, sizeInBytes, class_->objectMask()); setObjectClass(t, instance, class_); return instance; } object -makeNewGeneral(Thread* t, object class_); +makeNewGeneral(Thread* t, GcClass* class_); inline object -make(Thread* t, object class_) +make(Thread* t, GcClass* class_) { - if (UNLIKELY(classVmFlags(t, class_) + if (UNLIKELY(class_->vmFlags() & (WeakReferenceFlag | HasFinalizerFlag))) { return makeNewGeneral(t, class_); @@ -2233,16 +2290,16 @@ inline object makeString(Thread* t, object data, unsigned offset, unsigned length, unsigned) { if (offset == 0 and length == charArrayLength(t, data)) { - return makeString(t, data, 0, 0); + return reinterpret_cast(makeString(t, data, 0, 0)); } else { PROTECT(t, data); - object array = makeCharArray(t, length); + object array = reinterpret_cast(makeCharArray(t, length)); memcpy(&charArrayBody(t, array, 0), &charArrayBody(t, data, offset), length * 2); - return makeString(t, array, 0, 0); + return reinterpret_cast(makeString(t, array, 0, 0)); } } @@ -2284,14 +2341,14 @@ stringUTFChars(Thread* t, object string, unsigned start, unsigned length, inline void stringUTFChars(Thread* t, object string, char* chars, unsigned charsLength) { - stringUTFChars(t, string, 0, stringLength(t, string), chars, charsLength); + stringUTFChars(t, string, 0, stringLength(t, string), chars, charsLength); } bool -isAssignableFrom(Thread* t, object a, object b); +isAssignableFrom(Thread* t, GcClass* a, GcClass* b); object -classInitializer(Thread* t, object class_); +classInitializer(Thread* t, GcClass* class_); object frameMethod(Thread* t, int frame); @@ -2376,7 +2433,7 @@ stringHash(Thread* t, object s) { if (stringHashCode(t, s) == 0 and stringLength(t, s)) { object data = stringData(t, s); - if (objectClass(t, data) == type(t, Machine::ByteArrayType)) { + if (objectClass(t, data) == type(t, GcByteArray::Type)) { stringHashCode(t, s) = hash (&byteArrayBody(t, data, stringOffset(t, s)), stringLength(t, s)); } else { @@ -2391,7 +2448,7 @@ inline uint16_t stringCharAt(Thread* t, object s, int i) { object data = stringData(t, s); - if (objectClass(t, data) == type(t, Machine::ByteArrayType)) { + if (objectClass(t, data) == type(t, GcByteArray::Type)) { return byteArrayBody(t, data, stringOffset(t, s) + i); } else { return charArrayBody(t, data, stringOffset(t, s) + i); @@ -2416,18 +2473,21 @@ stringEqual(Thread* t, object a, object b) } inline uint32_t -methodHash(Thread* t, object method) +methodHash(Thread* t, object mo) { - return byteArrayHash(t, methodName(t, method)) - ^ byteArrayHash(t, methodSpec(t, method)); + GcMethod* method = cast(t, mo); + return byteArrayHash(t, method->name()) + ^ byteArrayHash(t, method->spec()); } inline bool -methodEqual(Thread* t, object a, object b) +methodEqual(Thread* t, object ao, object bo) { + GcMethod* a = cast(t, ao); + GcMethod* b = cast(t, bo); return a == b or - (byteArrayEqual(t, methodName(t, a), methodName(t, b)) and - byteArrayEqual(t, methodSpec(t, a), methodSpec(t, b))); + (byteArrayEqual(t, a->name(), b->name()) and + byteArrayEqual(t, a->spec(), b->spec())); } class MethodSpecIterator { @@ -2460,12 +2520,12 @@ class MethodSpecIterator { break; } break; - + default: ++ s; break; } - + return p; } @@ -2525,7 +2585,7 @@ scanMethodSpec(Thread* t, const char* s, bool static_, default: ++ footprint; - break; + break; } } @@ -2538,15 +2598,15 @@ scanMethodSpec(Thread* t, const char* s, bool static_, *returnCode = fieldCode(t, *it.returnSpec()); } -object +GcClass* findLoadedClass(Thread* t, object loader, object spec); inline bool -emptyMethod(Thread* t, object method) +emptyMethod(Thread* t, GcMethod* method) { - return ((methodFlags(t, method) & ACC_NATIVE) == 0) - and (codeLength(t, methodCode(t, method)) == 1) - and (codeBody(t, methodCode(t, method), 0) == return_); + return ((method->flags() & ACC_NATIVE) == 0) + and (codeLength(t, method->code()) == 1) + and (codeBody(t, method->code(), 0) == return_); } object @@ -2555,42 +2615,42 @@ parseUtf8(Thread* t, const char* data, unsigned length); object parseUtf8(Thread* t, object array); -object +GcClass* parseClass(Thread* t, object loader, const uint8_t* data, unsigned length, - Machine::Type throwType = Machine::NoClassDefFoundErrorType); + Gc::Type throwType = GcNoClassDefFoundError::Type); -object +GcClass* resolveClass(Thread* t, object loader, object name, bool throw_ = true, - Machine::Type throwType = Machine::NoClassDefFoundErrorType); + Gc::Type throwType = GcNoClassDefFoundError::Type); -inline object +inline GcClass* resolveClass(Thread* t, object loader, const char* name, bool throw_ = true, - Machine::Type throwType = Machine::NoClassDefFoundErrorType) + Gc::Type throwType = GcNoClassDefFoundError::Type) { PROTECT(t, loader); object n = makeByteArray(t, "%s", name); return resolveClass(t, loader, n, throw_, throwType); } -object +GcClass* resolveSystemClass (Thread* t, object loader, object name, bool throw_ = true, - Machine::Type throwType = Machine::NoClassDefFoundErrorType); + Gc::Type throwType = GcNoClassDefFoundError::Type); -inline object +inline GcClass* resolveSystemClass(Thread* t, object loader, const char* name) { return resolveSystemClass(t, loader, makeByteArray(t, "%s", name)); } void -linkClass(Thread* t, object loader, object class_); +linkClass(Thread* t, object loader, GcClass* class_); -object -resolveMethod(Thread* t, object class_, const char* methodName, +GcMethod* +resolveMethod(Thread* t, GcClass* class_, const char* methodName, const char* methodSpec); -inline object +inline GcMethod* resolveMethod(Thread* t, object loader, const char* className, const char* methodName, const char* methodSpec) { @@ -2599,7 +2659,7 @@ resolveMethod(Thread* t, object loader, const char* className, } object -resolveField(Thread* t, object class_, const char* fieldName, +resolveField(Thread* t, GcClass* class_, const char* fieldName, const char* fieldSpec); inline object @@ -2611,34 +2671,34 @@ resolveField(Thread* t, object loader, const char* className, } bool -classNeedsInit(Thread* t, object c); +classNeedsInit(Thread* t, GcClass* c); bool -preInitClass(Thread* t, object c); +preInitClass(Thread* t, GcClass* c); void -postInitClass(Thread* t, object c); +postInitClass(Thread* t, GcClass* c); void -initClass(Thread* t, object c); +initClass(Thread* t, GcClass* c); -object +GcClass* resolveObjectArrayClass(Thread* t, object loader, object elementClass); object -makeObjectArray(Thread* t, object elementClass, unsigned count); +makeObjectArray(Thread* t, GcClass* elementClass, unsigned count); inline object makeObjectArray(Thread* t, unsigned count) { - return makeObjectArray(t, type(t, Machine::JobjectType), count); + return makeObjectArray(t, type(t, GcJobject::Type), count); } object -findFieldInClass(Thread* t, object class_, object name, object spec); +findFieldInClass(Thread* t, GcClass* class_, object name, object spec); inline object -findFieldInClass2(Thread* t, object class_, const char* name, const char* spec) +findFieldInClass2(Thread* t, GcClass* class_, const char* name, const char* spec) { PROTECT(t, class_); object n = makeByteArray(t, "%s", name); @@ -2648,23 +2708,23 @@ findFieldInClass2(Thread* t, object class_, const char* name, const char* spec) } object -findMethodInClass(Thread* t, object class_, object name, object spec); +findMethodInClass(Thread* t, GcClass* class_, object name, object spec); inline object makeThrowable -(Thread* t, Machine::Type type, object message = 0, object trace = 0, +(Thread* t, Gc::Type type, object message = 0, object trace = 0, object cause = 0) { PROTECT(t, message); PROTECT(t, trace); PROTECT(t, cause); - + if (trace == 0) { trace = makeTrace(t); } object result = make(t, vm::type(t, type)); - + set(t, result, ThrowableMessage, message); set(t, result, ThrowableTrace, trace); set(t, result, ThrowableCause, cause); @@ -2673,7 +2733,7 @@ makeThrowable } inline object -makeThrowableV(Thread* t, Machine::Type type, const char* format, va_list a, +makeThrowableV(Thread* t, Gc::Type type, const char* format, va_list a, int size) { object s = makeByteArrayV(t, format, a, size); @@ -2689,7 +2749,7 @@ makeThrowableV(Thread* t, Machine::Type type, const char* format, va_list a, } inline object -makeThrowable(Thread* t, Machine::Type type, const char* format, ...) +makeThrowable(Thread* t, Gc::Type type, const char* format, ...) { int size = 256; while (true) { @@ -2732,7 +2792,7 @@ throw_(Thread* t, object e) t->exception = e; - if (objectClass(t, e) == type(t, Machine::OutOfMemoryErrorType)) { + if (objectClass(t, e) == type(t, GcOutOfMemoryError::Type)) { #ifdef AVIAN_HEAPDUMP if (not t->m->dumpedHeapOnOOM) { t->m->dumpedHeapOnOOM = true; @@ -2765,14 +2825,14 @@ throw_(Thread* t, object e) inline void NO_RETURN throwNew -(Thread* t, Machine::Type type, object message = 0, object trace = 0, +(Thread* t, Gc::Type type, object message = 0, object trace = 0, object cause = 0) { throw_(t, makeThrowable(t, type, message, trace, cause)); } inline void NO_RETURN -throwNew(Thread* t, Machine::Type type, const char* format, ...) +throwNew(Thread* t, Gc::Type type, const char* format, ...) { int size = 256; while (true) { @@ -2790,13 +2850,13 @@ throwNew(Thread* t, Machine::Type type, const char* format, ...) } object -findInHierarchyOrNull(Thread* t, object class_, object name, object spec, - object (*find)(Thread*, object, object, object)); +findInHierarchyOrNull(Thread* t, GcClass* class_, object name, object spec, + object (*find)(Thread*, GcClass*, object, object)); inline object -findInHierarchy(Thread* t, object class_, object name, object spec, - object (*find)(Thread*, object, object, object), - Machine::Type errorType, bool throw_ = true) +findInHierarchy(Thread* t, GcClass* class_, object name, object spec, + object (*find)(Thread*, GcClass*, object, object), + Gc::Type errorType, bool throw_ = true) { object o = findInHierarchyOrNull(t, class_, name, spec, find); @@ -2804,46 +2864,46 @@ findInHierarchy(Thread* t, object class_, object name, object spec, throwNew(t, errorType, "%s %s not found in %s", &byteArrayBody(t, name, 0), &byteArrayBody(t, spec, 0), - &byteArrayBody(t, className(t, class_), 0)); + &byteArrayBody(t, class_->name(), 0)); } return o; } -inline object -findMethod(Thread* t, object class_, object name, object spec) +inline GcMethod* +findMethod(Thread* t, GcClass* class_, object name, object spec) { - return findInHierarchy - (t, class_, name, spec, findMethodInClass, Machine::NoSuchMethodErrorType); + return cast(t, findInHierarchy + (t, class_, name, spec, findMethodInClass, GcNoSuchMethodError::Type)); } -inline object -findMethodOrNull(Thread* t, object class_, const char* name, const char* spec) +inline GcMethod* +findMethodOrNull(Thread* t, GcClass* class_, const char* name, const char* spec) { PROTECT(t, class_); object n = makeByteArray(t, "%s", name); PROTECT(t, n); object s = makeByteArray(t, "%s", spec); - return findInHierarchyOrNull(t, class_, n, s, findMethodInClass); + return cast(t, findInHierarchyOrNull(t, class_, n, s, findMethodInClass)); } -inline object -findVirtualMethod(Thread* t, object method, object class_) +inline GcMethod* +findVirtualMethod(Thread* t, GcMethod* method, GcClass* class_) { - return arrayBody(t, classVirtualTable(t, class_), methodOffset(t, method)); + return cast(t, arrayBody(t, class_->virtualTable(), method->offset())); } -inline object -findInterfaceMethod(Thread* t, object method, object class_) +inline GcMethod* +findInterfaceMethod(Thread* t, GcMethod* method, GcClass* class_) { - assert(t, (classVmFlags(t, class_) & BootstrapFlag) == 0); + assert(t, (class_->vmFlags() & BootstrapFlag) == 0); - object interface = methodClass(t, method); - object itable = classInterfaceTable(t, class_); + object interface = method->class_(); + object itable = class_->interfaceTable(); for (unsigned i = 0; i < arrayLength(t, itable); i += 2) { if (arrayBody(t, itable, i) == interface) { - return arrayBody - (t, arrayBody(t, itable, i + 1), methodOffset(t, method)); + return cast(t, arrayBody + (t, arrayBody(t, itable, i + 1), method->offset())); } } abort(t); @@ -2852,19 +2912,19 @@ findInterfaceMethod(Thread* t, object method, object class_) inline unsigned objectArrayLength(Thread* t UNUSED, object array) { - assert(t, classFixedSize(t, objectClass(t, array)) == BytesPerWord * 2); - assert(t, classArrayElementSize(t, objectClass(t, array)) == BytesPerWord); + assert(t, objectClass(t, array)->fixedSize() == BytesPerWord * 2); + assert(t, objectClass(t, array)->arrayElementSize() == BytesPerWord); return fieldAtOffset(array, BytesPerWord); } inline object& objectArrayBody(Thread* t UNUSED, object array, unsigned index) { - assert(t, classFixedSize(t, objectClass(t, array)) == BytesPerWord * 2); - assert(t, classArrayElementSize(t, objectClass(t, array)) == BytesPerWord); - assert(t, classObjectMask(t, objectClass(t, array)) + assert(t, objectClass(t, array)->fixedSize() == BytesPerWord * 2); + assert(t, objectClass(t, array)->arrayElementSize() == BytesPerWord); + assert(t, objectClass(t, array)->objectMask() == classObjectMask(t, arrayBody - (t, t->m->types, Machine::ArrayType))); + (t, t->m->types, GcArray::Type))); return fieldAtOffset(array, ArrayBody + (index * BytesPerWord)); } @@ -2922,12 +2982,12 @@ monitorAtomicAppendAcquire(Thread* t, object monitor, object node) if (node == 0) { PROTECT(t, monitor); - node = makeMonitorNode(t, t, 0); + node = reinterpret_cast(makeMonitorNode(t, t, 0)); } while (true) { object tail = monitorAcquireTail(t, monitor); - + loadMemoryBarrier(); object next = monitorNodeNext(t, tail); @@ -3012,7 +3072,7 @@ monitorAcquire(Thread* t, object monitor, object node = 0) ACQUIRE(t, t->lock); monitorAtomicAppendAcquire(t, monitor, node); - + // note that we don't try to acquire the lock until we're first in // line, both because it's fair and because we don't support // removing elements from arbitrary positions in the queue @@ -3023,12 +3083,12 @@ monitorAcquire(Thread* t, object monitor, object node = 0) reinterpret_cast(t)))) { ENTER(t, Thread::IdleState); - + t->lock->wait(t->systemThread, 0); } expect(t, t == monitorAtomicPollAcquire(t, monitor, true)); - + ++ monitorDepth(t, monitor); } @@ -3044,12 +3104,12 @@ monitorRelease(Thread* t, object monitor) monitorOwner(t, monitor) = 0; storeLoadMemoryBarrier(); - + Thread* next = monitorAtomicPollAcquire(t, monitor, false); if (next and acquireSystem(t, next)) { ACQUIRE(t, next->lock); - + next->lock->notify(t->systemThread); releaseSystem(t, next); @@ -3137,7 +3197,7 @@ monitorWait(Thread* t, object monitor, int64_t time) // pre-allocate monitor node so we don't get an OutOfMemoryError // when we try to re-acquire the monitor below - object monitorNode = makeMonitorNode(t, t, 0); + object monitorNode = reinterpret_cast(makeMonitorNode(t, t, 0)); PROTECT(t, monitorNode); { ACQUIRE(t, t->lock); @@ -3194,7 +3254,7 @@ inline bool monitorNotify(Thread* t, object monitor) { expect(t, monitorOwner(t, monitor) == t); - + Thread* next = monitorPollWait(t, monitor); if (next) { @@ -3291,13 +3351,13 @@ wait(Thread* t, object o, int64_t milliseconds) if (interrupted) { if (t->m->alive or (t->flags & Thread::DaemonFlag) == 0) { t->m->classpath->clearInterrupted(t); - throwNew(t, Machine::InterruptedExceptionType); + throwNew(t, GcInterruptedException::Type); } else { throw_(t, root(t, Machine::Shutdown)); } } } else { - throwNew(t, Machine::IllegalMonitorStateExceptionType); + throwNew(t, GcIllegalMonitorStateException::Type); } if (DebugMonitors) { @@ -3326,7 +3386,7 @@ notify(Thread* t, object o) if (m and monitorOwner(t, m) == t) { monitorNotify(t, m); } else { - throwNew(t, Machine::IllegalMonitorStateExceptionType); + throwNew(t, GcIllegalMonitorStateException::Type); } } @@ -3343,7 +3403,7 @@ notifyAll(Thread* t, object o) if (m and monitorOwner(t, m) == t) { monitorNotifyAll(t, m); } else { - throwNew(t, Machine::IllegalMonitorStateExceptionType); + throwNew(t, GcIllegalMonitorStateException::Type); } } @@ -3369,7 +3429,7 @@ getAndClearInterrupted(Thread* t, Thread* target) } inline bool -exceptionMatch(Thread* t, object type, object exception) +exceptionMatch(Thread* t, GcClass* type, object exception) { return type == 0 or (exception != root(t, Machine::Shutdown) @@ -3401,10 +3461,10 @@ disposeLocalReference(Thread* t, jobject r) } inline bool -methodVirtual(Thread* t, object method) +methodVirtual(Thread* t, GcMethod* method) { - return (methodFlags(t, method) & (ACC_STATIC | ACC_PRIVATE)) == 0 - and byteArrayBody(t, methodName(t, method), 0) != '<'; + return (method->flags() & (ACC_STATIC | ACC_PRIVATE)) == 0 + and byteArrayBody(t, method->name(), 0) != '<'; } inline unsigned @@ -3423,9 +3483,9 @@ singletonMaskSize(unsigned count) } inline unsigned -singletonMaskSize(Thread* t, object singleton) +singletonMaskSize(Thread* t UNUSED, GcSingleton* singleton) { - unsigned length = singletonLength(t, singleton); + unsigned length = singleton->length(); if (length) { return ceilingDivide(length + 2, BitsPerWord + 1); } @@ -3433,17 +3493,17 @@ singletonMaskSize(Thread* t, object singleton) } inline unsigned -singletonCount(Thread* t, object singleton) +singletonCount(Thread* t, GcSingleton* singleton) { - return singletonLength(t, singleton) - singletonMaskSize(t, singleton); + return singleton->length() - singletonMaskSize(t, singleton); } inline uint32_t* -singletonMask(Thread* t, object singleton) +singletonMask(Thread* t, GcSingleton* singleton) { - assert(t, singletonLength(t, singleton)); + assert(t, singleton->length()); return reinterpret_cast - (&singletonBody(t, singleton, singletonCount(t, singleton))); + (&singletonBody(t, reinterpret_cast(singleton), singletonCount(t, singleton))); } inline void @@ -3454,13 +3514,13 @@ singletonMarkObject(uint32_t* mask, unsigned index) } inline void -singletonMarkObject(Thread* t, object singleton, unsigned index) +singletonMarkObject(Thread* t, GcSingleton* singleton, unsigned index) { singletonMarkObject(singletonMask(t, singleton), index); } inline bool -singletonIsObject(Thread* t, object singleton, unsigned index) +singletonIsObject(Thread* t, GcSingleton* singleton, unsigned index) { assert(t, index < singletonCount(t, singleton)); @@ -3469,24 +3529,24 @@ singletonIsObject(Thread* t, object singleton, unsigned index) } inline object& -singletonObject(Thread* t, object singleton, unsigned index) +singletonObject(Thread* t, GcSingleton* singleton, unsigned index) { assert(t, singletonIsObject(t, singleton, index)); - return reinterpret_cast(singletonBody(t, singleton, index)); + return reinterpret_cast(singletonBody(t, reinterpret_cast(singleton), index)); } inline uintptr_t& -singletonValue(Thread* t, object singleton, unsigned index) +singletonValue(Thread* t, GcSingleton* singleton, unsigned index) { assert(t, not singletonIsObject(t, singleton, index)); - return singletonBody(t, singleton, index); + return singletonBody(t, reinterpret_cast(singleton), index); } -inline object +inline GcSingleton* makeSingletonOfSize(Thread* t, unsigned count) { - object o = makeSingleton(t, count + singletonMaskSize(count)); - assert(t, singletonLength(t, o) == count + singletonMaskSize(t, o)); + GcSingleton* o = makeSingleton(t, count + singletonMaskSize(count)); + assert(t, o->length() == count + singletonMaskSize(t, o)); if (count) { singletonMask(t, o)[0] = 1; } @@ -3494,14 +3554,14 @@ makeSingletonOfSize(Thread* t, unsigned count) } inline void -singletonSetBit(Thread* t, object singleton, unsigned start, unsigned index) +singletonSetBit(Thread* t, GcSingleton* singleton, unsigned start, unsigned index) { singletonValue(t, singleton, start + (index / BitsPerWord)) |= static_cast(1) << (index % BitsPerWord); } inline bool -singletonBit(Thread* t, object singleton, unsigned start, unsigned index) +singletonBit(Thread* t, GcSingleton* singleton, unsigned start, unsigned index) { return (singletonValue(t, singleton, start + (index / BitsPerWord)) & (static_cast(1) << (index % BitsPerWord))) != 0; @@ -3520,96 +3580,99 @@ poolMaskSize(unsigned count) } inline unsigned -poolMaskSize(Thread* t, object pool) +poolMaskSize(Thread* t, GcSingleton* pool) { return ceilingDivide(singletonCount(t, pool), BitsPerWord + 1); } inline unsigned -poolSize(Thread* t, object pool) +poolSize(Thread* t, GcSingleton* pool) { return singletonCount(t, pool) - poolMaskSize(t, pool); } -inline object +inline GcClass* resolveClassInObject(Thread* t, object loader, object container, unsigned classOffset, bool throw_ = true) { object o = fieldAtOffset(container, classOffset); - loadMemoryBarrier(); + loadMemoryBarrier(); - if (objectClass(t, o) == type(t, Machine::ByteArrayType)) { + if (objectClass(t, o) == type(t, GcByteArray::Type)) { PROTECT(t, container); - o = resolveClass(t, loader, o, throw_); - - if (o) { + GcClass* c = resolveClass(t, loader, o, throw_); + + if (c) { storeStoreMemoryBarrier(); - set(t, container, classOffset, o); + set(t, container, classOffset, reinterpret_cast(c)); } + + return c; } - return o; + return cast(t, o); } -inline object -resolveClassInPool(Thread* t, object loader, object method, unsigned index, +inline GcClass* +resolveClassInPool(Thread* t, object loader, GcMethod* method, unsigned index, bool throw_ = true) { - object o = singletonObject(t, codePool(t, methodCode(t, method)), index); + object o = singletonObject(t, cast(t, codePool(t, method->code())), index); loadMemoryBarrier(); - if (objectClass(t, o) == type(t, Machine::ReferenceType)) { + if (objectClass(t, o) == type(t, GcReference::Type)) { PROTECT(t, method); - o = resolveClass(t, loader, referenceName(t, o), throw_); - - if (o) { + GcClass* c = resolveClass(t, loader, referenceName(t, o), throw_); + + if (c) { storeStoreMemoryBarrier(); - set(t, codePool(t, methodCode(t, method)), - SingletonBody + (index * BytesPerWord), o); + set(t, codePool(t, method->code()), + SingletonBody + (index * BytesPerWord), reinterpret_cast(c)); } + return c; } - return o; + return cast(t, o); } -inline object -resolveClassInPool(Thread* t, object method, unsigned index, +inline GcClass* +resolveClassInPool(Thread* t, GcMethod* method, unsigned index, bool throw_ = true) { - return resolveClassInPool(t, classLoader(t, methodClass(t, method)), + return resolveClassInPool(t, classLoader(t, method->class_()), method, index, throw_); } inline object -resolve(Thread* t, object loader, object method, unsigned index, - object (*find)(vm::Thread*, object, object, object), - Machine::Type errorType, bool throw_ = true) +resolve(Thread* t, object loader, GcMethod* method, unsigned index, + object (*find)(vm::Thread*, GcClass*, object, object), + Gc::Type errorType, bool throw_ = true) { - object o = singletonObject(t, codePool(t, methodCode(t, method)), index); + object o = singletonObject(t, cast(t, codePool(t, method->code())), index); - loadMemoryBarrier(); + loadMemoryBarrier(); - if (objectClass(t, o) == type(t, Machine::ReferenceType)) { + if (objectClass(t, o) == type(t, GcReference::Type)) { PROTECT(t, method); object reference = o; PROTECT(t, reference); - object class_ = resolveClassInObject(t, loader, o, ReferenceClass, throw_); - + GcClass* class_ = resolveClassInObject(t, loader, o, ReferenceClass, throw_); + if (class_) { o = findInHierarchy (t, class_, referenceName(t, reference), referenceSpec(t, reference), find, errorType, throw_); - + if (o) { storeStoreMemoryBarrier(); - set(t, codePool(t, methodCode(t, method)), + set(t, codePool(t, method->code()), SingletonBody + (index * BytesPerWord), o); } } else { @@ -3621,18 +3684,18 @@ resolve(Thread* t, object loader, object method, unsigned index, } inline object -resolveField(Thread* t, object loader, object method, unsigned index, +resolveField(Thread* t, object loader, GcMethod* method, unsigned index, bool throw_ = true) { return resolve(t, loader, method, index, findFieldInClass, - Machine::NoSuchFieldErrorType, throw_); + GcNoSuchFieldError::Type, throw_); } inline object -resolveField(Thread* t, object method, unsigned index, bool throw_ = true) +resolveField(Thread* t, GcMethod* method, unsigned index, bool throw_ = true) { return resolveField - (t, classLoader(t, methodClass(t, method)), method, index, throw_); + (t, classLoader(t, method->class_()), method, index, throw_); } inline void @@ -3643,7 +3706,7 @@ acquireFieldForRead(Thread* t, object field) and (fieldCode(t, field) == DoubleField or fieldCode(t, field) == LongField))) { - acquire(t, field); + acquire(t, field); } } @@ -3655,7 +3718,7 @@ releaseFieldForRead(Thread* t, object field) and (fieldCode(t, field) == DoubleField or fieldCode(t, field) == LongField)) { - release(t, field); + release(t, field); } else { loadMemoryBarrier(); } @@ -3685,7 +3748,7 @@ acquireFieldForWrite(Thread* t, object field) and (fieldCode(t, field) == DoubleField or fieldCode(t, field) == LongField)) { - acquire(t, field); + acquire(t, field); } else { storeStoreMemoryBarrier(); } @@ -3700,7 +3763,7 @@ releaseFieldForWrite(Thread* t, object field) and (fieldCode(t, field) == DoubleField or fieldCode(t, field) == LongField)) { - release(t, field); + release(t, field); } else { storeLoadMemoryBarrier(); } @@ -3722,19 +3785,19 @@ class FieldWriteResource { Thread::SingleProtector protector; }; -inline object -resolveMethod(Thread* t, object loader, object method, unsigned index, +inline GcMethod* +resolveMethod(Thread* t, object loader, GcMethod* method, unsigned index, bool throw_ = true) { - return resolve(t, loader, method, index, findMethodInClass, - Machine::NoSuchMethodErrorType, throw_); + return cast(t, resolve(t, loader, method, index, findMethodInClass, + GcNoSuchMethodError::Type, throw_)); } -inline object -resolveMethod(Thread* t, object method, unsigned index, bool throw_ = true) +inline GcMethod* +resolveMethod(Thread* t, GcMethod* method, unsigned index, bool throw_ = true) { return resolveMethod - (t, classLoader(t, methodClass(t, method)), method, index, throw_); + (t, classLoader(t, method->class_()), method, index, throw_); } object @@ -3752,32 +3815,32 @@ getClassRuntimeDataIfExists(Thread* t, object c) } inline object -getClassRuntimeData(Thread* t, object c) +getClassRuntimeData(Thread* t, GcClass* c) { - if (classRuntimeDataIndex(t, c) == 0) { + if (c->runtimeDataIndex() == 0) { PROTECT(t, c); ACQUIRE(t, t->m->classLock); - if (classRuntimeDataIndex(t, c) == 0) { - object runtimeData = makeClassRuntimeData(t, 0, 0, 0, 0); + if (c->runtimeDataIndex() == 0) { + object runtimeData = reinterpret_cast(makeClassRuntimeData(t, 0, 0, 0, 0)); setRoot(t, Machine::ClassRuntimeDataTable, vectorAppend (t, root(t, Machine::ClassRuntimeDataTable), runtimeData)); - classRuntimeDataIndex(t, c) = vectorSize + c->runtimeDataIndex() = vectorSize (t, root(t, Machine::ClassRuntimeDataTable)); } } return vectorBody(t, root(t, Machine::ClassRuntimeDataTable), - classRuntimeDataIndex(t, c) - 1); + c->runtimeDataIndex() - 1); } inline object -getMethodRuntimeData(Thread* t, object method) +getMethodRuntimeData(Thread* t, GcMethod* method) { - int index = methodRuntimeDataIndex(t, method); + int index = method->runtimeDataIndex(); loadMemoryBarrier(); @@ -3786,25 +3849,25 @@ getMethodRuntimeData(Thread* t, object method) ACQUIRE(t, t->m->classLock); - if (methodRuntimeDataIndex(t, method) == 0) { - object runtimeData = makeMethodRuntimeData(t, 0); + if (method->runtimeDataIndex() == 0) { + object runtimeData = reinterpret_cast(makeMethodRuntimeData(t, 0)); setRoot(t, Machine::MethodRuntimeDataTable, vectorAppend (t, root(t, Machine::MethodRuntimeDataTable), runtimeData)); storeStoreMemoryBarrier(); - methodRuntimeDataIndex(t, method) = vectorSize + method->runtimeDataIndex() = vectorSize (t, root(t, Machine::MethodRuntimeDataTable)); } } return vectorBody(t, root(t, Machine::MethodRuntimeDataTable), - methodRuntimeDataIndex(t, method) - 1); + method->runtimeDataIndex() - 1); } inline object -getJClass(Thread* t, object c) +getJClass(Thread* t, GcClass* c) { PROTECT(t, c); @@ -3820,7 +3883,7 @@ getJClass(Thread* t, object c) jclass = t->m->classpath->makeJclass(t, c); storeStoreMemoryBarrier(); - + set(t, getClassRuntimeData(t, c), ClassRuntimeDataJclass, jclass); } } @@ -3828,31 +3891,31 @@ getJClass(Thread* t, object c) return jclass; } -inline object +inline GcClass* primitiveClass(Thread* t, char name) { switch (name) { - case 'B': return type(t, Machine::JbyteType); - case 'C': return type(t, Machine::JcharType); - case 'D': return type(t, Machine::JdoubleType); - case 'F': return type(t, Machine::JfloatType); - case 'I': return type(t, Machine::JintType); - case 'J': return type(t, Machine::JlongType); - case 'S': return type(t, Machine::JshortType); - case 'V': return type(t, Machine::JvoidType); - case 'Z': return type(t, Machine::JbooleanType); - default: throwNew(t, Machine::IllegalArgumentExceptionType); + case 'B': return type(t, GcJbyte::Type); + case 'C': return type(t, GcJchar::Type); + case 'D': return type(t, GcJdouble::Type); + case 'F': return type(t, GcJfloat::Type); + case 'I': return type(t, GcJint::Type); + case 'J': return type(t, GcJlong::Type); + case 'S': return type(t, GcJshort::Type); + case 'V': return type(t, GcJvoid::Type); + case 'Z': return type(t, GcJboolean::Type); + default: throwNew(t, GcIllegalArgumentException::Type); } } - + inline void -registerNative(Thread* t, object method, void* function) +registerNative(Thread* t, GcMethod* method, void* function) { PROTECT(t, method); - expect(t, methodFlags(t, method) & ACC_NATIVE); + expect(t, method->flags() & ACC_NATIVE); - object native = makeNative(t, function, false); + object native = reinterpret_cast(makeNative(t, function, false)); PROTECT(t, native); object runtimeData = getMethodRuntimeData(t, method); @@ -3869,8 +3932,8 @@ unregisterNatives(Thread* t, object c) { if (classMethodTable(t, c)) { for (unsigned i = 0; i < arrayLength(t, classMethodTable(t, c)); ++i) { - object method = arrayBody(t, classMethodTable(t, c), i); - if (methodFlags(t, method) & ACC_NATIVE) { + GcMethod* method = cast(t, arrayBody(t, classMethodTable(t, c), i)); + if (method->flags() & ACC_NATIVE) { set(t, getMethodRuntimeData(t, method), MethodRuntimeDataNative, 0); } } @@ -3881,29 +3944,29 @@ void populateMultiArray(Thread* t, object array, int32_t* counts, unsigned index, unsigned dimensions); -object +GcMethod* getCaller(Thread* t, unsigned target, bool skipMethodInvoke = false); object defineClass(Thread* t, object loader, const uint8_t* buffer, unsigned length); -inline object -methodClone(Thread* t, object method) +inline GcMethod* +methodClone(Thread* t, GcMethod* method) { return makeMethod - (t, methodVmFlags(t, method), - methodReturnCode(t, method), - methodParameterCount(t, method), - methodParameterFootprint(t, method), - methodFlags(t, method), - methodOffset(t, method), - methodNativeID(t, method), - methodRuntimeDataIndex(t, method), - methodName(t, method), - methodSpec(t, method), - methodAddendum(t, method), - methodClass(t, method), - methodCode(t, method)); + (t, method->vmFlags(), + method->returnCode(), + method->parameterCount(), + method->parameterFootprint(), + method->flags(), + method->offset(), + method->nativeID(), + method->runtimeDataIndex(), + method->name(), + method->spec(), + method->addendum(), + method->class_(), + method->code()); } inline uint64_t diff --git a/src/avian/process.h b/src/avian/process.h index d532e162be..fd9a005ebc 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, object class_, object base) +isSuperclass(Thread* t, GcClass* class_, GcClass* base) { - for (object oc = classSuper(t, base); oc; oc = classSuper(t, oc)) { + for (GcClass* oc = cast(t, base->super()); oc; oc = cast(t, oc->super())) { if (oc == class_) { return true; } @@ -48,19 +48,19 @@ isSuperclass(Thread* t, object class_, object base) } inline bool -isSpecialMethod(Thread* t, object method, object class_) +isSpecialMethod(Thread* t, GcMethod* method, GcClass* class_) { - return (classFlags(t, class_) & ACC_SUPER) + return (class_->flags() & ACC_SUPER) and strcmp(reinterpret_cast(""), - &byteArrayBody(t, methodName(t, method), 0)) != 0 - and isSuperclass(t, methodClass(t, method), class_); + &byteArrayBody(t, method->name(), 0)) != 0 + and isSuperclass(t, cast(t, method->class_()), class_); } void -resolveNative(Thread* t, object method); +resolveNative(Thread* t, GcMethod* method); int -findLineNumber(Thread* t, object method, unsigned ip); +findLineNumber(Thread* t, GcMethod* method, unsigned ip); } // namespace vm diff --git a/src/avian/processor.h b/src/avian/processor.h index 3f92096891..effbafd5fc 100644 --- a/src/avian/processor.h +++ b/src/avian/processor.h @@ -32,6 +32,11 @@ class Slice; namespace vm { +class GcByteArray; +class GcCode; +class GcClass; +class GcMethod; + class Processor { public: class StackWalker; @@ -45,7 +50,7 @@ class Processor { public: virtual void walk(StackVisitor* v) = 0; - virtual object method() = 0; + virtual GcMethod* method() = 0; virtual int ip() = 0; @@ -62,7 +67,7 @@ class Processor { virtual Thread* makeThread(Machine* m, object javaThread, Thread* parent) = 0; - virtual object + virtual GcMethod* makeMethod(Thread* t, uint8_t vmFlags, uint8_t returnCode, @@ -70,13 +75,13 @@ class Processor { uint8_t parameterFootprint, uint16_t flags, uint16_t offset, - object name, - object spec, + GcByteArray* name, + GcByteArray* spec, object addendum, - object class_, - object code) = 0; + GcClass* class_, + GcCode* code) = 0; - virtual object + virtual GcClass* makeClass(Thread* t, uint16_t flags, uint16_t vmFlags, @@ -97,7 +102,7 @@ class Processor { unsigned vtableLength) = 0; virtual void - initVtable(Thread* t, object c) = 0; + initVtable(Thread* t, GcClass* c) = 0; virtual void visitObjects(Thread* t, Heap::Visitor* v) = 0; @@ -106,7 +111,7 @@ class Processor { walkStack(Thread* t, StackVisitor* v) = 0; virtual int - lineNumber(Thread* t, object method, int ip) = 0; + lineNumber(Thread* t, GcMethod* method, int ip) = 0; virtual object* makeLocalReference(Thread* t, object o) = 0; @@ -121,14 +126,14 @@ class Processor { popLocalFrame(Thread* t) = 0; virtual object - invokeArray(Thread* t, object method, object this_, object arguments) = 0; + invokeArray(Thread* t, GcMethod* method, object this_, object arguments) = 0; virtual object - invokeArray(Thread* t, object method, object this_, const jvalue* arguments) + invokeArray(Thread* t, GcMethod* method, object this_, const jvalue* arguments) = 0; virtual object - invokeList(Thread* t, object method, object this_, bool indirectObjects, + invokeList(Thread* t, GcMethod* method, object this_, bool indirectObjects, va_list arguments) = 0; virtual object @@ -153,7 +158,7 @@ class Processor { virtual void compileMethod(Thread* t, Zone* zone, object* constants, object* calls, - avian::codegen::DelayedPromise** addresses, object method, + avian::codegen::DelayedPromise** addresses, GcMethod* method, OffsetResolver* resolver) = 0; virtual void @@ -186,7 +191,7 @@ class Processor { = 0; object - invoke(Thread* t, object method, object this_, ...) + invoke(Thread* t, GcMethod* method, object this_, ...) { va_list a; va_start(a, this_); diff --git a/src/avian/util.h b/src/avian/util.h index 993abf1829..a43c1380fc 100644 --- a/src/avian/util.h +++ b/src/avian/util.h @@ -17,12 +17,12 @@ namespace vm { object -hashMapFindNode(Thread* t, object map, object key, +hashMapFindNode(Thread* t, GcHashMap* map, object key, uint32_t (*hash)(Thread*, object), bool (*equal)(Thread*, object, object)); inline object -hashMapFind(Thread* t, object map, object key, +hashMapFind(Thread* t, GcHashMap* map, object key, uint32_t (*hash)(Thread*, object), bool (*equal)(Thread*, object, object)) { @@ -31,15 +31,15 @@ hashMapFind(Thread* t, object map, object key, } void -hashMapResize(Thread* t, object map, uint32_t (*hash)(Thread*, object), +hashMapResize(Thread* t, GcHashMap* map, uint32_t (*hash)(Thread*, object), unsigned size); void -hashMapInsert(Thread* t, object map, object key, object value, +hashMapInsert(Thread* t, GcHashMap* map, object key, object value, uint32_t (*hash)(Thread*, object)); inline bool -hashMapInsertOrReplace(Thread* t, object map, object key, object value, +hashMapInsertOrReplace(Thread* t, GcHashMap* map, object key, object value, uint32_t (*hash)(Thread*, object), bool (*equal)(Thread*, object, object)) { @@ -54,7 +54,7 @@ hashMapInsertOrReplace(Thread* t, object map, object key, object value, } inline bool -hashMapInsertMaybe(Thread* t, object map, object key, object value, +hashMapInsertMaybe(Thread* t, GcHashMap* map, object key, object value, uint32_t (*hash)(Thread*, object), bool (*equal)(Thread*, object, object)) { @@ -68,12 +68,12 @@ hashMapInsertMaybe(Thread* t, object map, object key, object value, } object -hashMapRemove(Thread* t, object map, object key, +hashMapRemove(Thread* t, GcHashMap* map, object key, uint32_t (*hash)(Thread*, object), bool (*equal)(Thread*, object, object)); object -hashMapIterator(Thread* t, object map); +hashMapIterator(Thread* t, GcHashMap* map); object hashMapIteratorNext(Thread* t, object it); @@ -102,14 +102,14 @@ treeUpdate(Thread* t, object tree, intptr_t key, object value, object sentinal, class HashMapIterator: public Thread::Protector { public: - HashMapIterator(Thread* t, object map): + HashMapIterator(Thread* t, GcHashMap* map): Protector(t), map(map), node(0), index(0) { find(); } void find() { - object array = hashMapArray(t, map); + object array = map->array(); if (array) { for (unsigned i = index; i < arrayLength(t, array); ++i) { if (arrayBody(t, array, i)) { @@ -145,7 +145,7 @@ class HashMapIterator: public Thread::Protector { v->visit(&node); } - object map; + GcHashMap* map; object node; unsigned index; }; diff --git a/src/builtin.cpp b/src/builtin.cpp index 356d02e6ce..60e896130e 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -21,37 +21,37 @@ namespace { int64_t search(Thread* t, object loader, object name, - object (*op)(Thread*, object, object), bool replaceDots) + GcClass* (*op)(Thread*, object, object), bool replaceDots) { if (LIKELY(name)) { PROTECT(t, loader); PROTECT(t, name); - object n = makeByteArray(t, stringLength(t, name) + 1); + object n = reinterpret_cast(makeByteArray(t, stringLength(t, name) + 1)); char* s = reinterpret_cast(&byteArrayBody(t, n, 0)); stringChars(t, name, s); - + if (replaceDots) { replace('.', '/', s); } return reinterpret_cast(op(t, loader, n)); } else { - throwNew(t, Machine::NullPointerExceptionType); + throwNew(t, GcNullPointerException::Type); } } -object +GcClass* resolveSystemClassThrow(Thread* t, object loader, object spec) { return resolveSystemClass - (t, loader, spec, true, Machine::ClassNotFoundExceptionType); + (t, loader, spec, true, GcClassNotFoundException::Type); } object -fieldForOffsetInClass(Thread* t, object c, unsigned offset) +fieldForOffsetInClass(Thread* t, GcClass* c, unsigned offset) { - object super = classSuper(t, c); + GcClass* super = cast(t, c->super()); if (super) { object field = fieldForOffsetInClass(t, super, offset); if (field) { @@ -59,7 +59,7 @@ fieldForOffsetInClass(Thread* t, object c, unsigned offset) } } - object table = classFieldTable(t, c); + object table = c->fieldTable(); if (table) { for (unsigned i = 0; i < objectArrayLength(t, table); ++i) { object field = objectArrayBody(t, table, i); @@ -75,12 +75,12 @@ fieldForOffsetInClass(Thread* t, object c, unsigned offset) } object -fieldForOffset(Thread* t, object o, unsigned offset) +fieldForOffset(Thread* t, GcSingleton* o, unsigned offset) { - object c = objectClass(t, o); - if (classVmFlags(t, c) & SingletonFlag) { - c = singletonObject(t, o, 0); - object table = classFieldTable(t, c); + GcClass* c = objectClass(t, o); + if (c->vmFlags() & SingletonFlag) { + c = cast(t, singletonObject(t, o, 0)); + object table = c->fieldTable(); if (table) { for (unsigned i = 0; i < objectArrayLength(t, table); ++i) { object field = objectArrayBody(t, table, i); @@ -108,7 +108,7 @@ extern "C" AVIAN_EXPORT void JNICALL Avian_avian_Classes_initialize (Thread* t, object, uintptr_t* arguments) { - object this_ = reinterpret_cast(arguments[0]); + GcClass* this_ = cast(t, reinterpret_cast(arguments[0])); initClass(t, this_); } @@ -135,7 +135,7 @@ Avian_avian_Classes_resolveVMClass object spec = reinterpret_cast(arguments[1]); return reinterpret_cast - (resolveClass(t, loader, spec, true, Machine::ClassNotFoundExceptionType)); + (resolveClass(t, loader, spec, true, GcClassNotFoundException::Type)); } extern "C" AVIAN_EXPORT int64_t JNICALL @@ -149,7 +149,7 @@ Avian_avian_Classes_defineVMClass uint8_t* buffer = static_cast (t->m->heap->allocate(length)); - + THREAD_RESOURCE2(t, uint8_t*, buffer, int, length, t->m->heap->free(buffer, length)); @@ -202,7 +202,7 @@ Avian_avian_SystemClassLoader_resourceURLPrefix return name ? reinterpret_cast(makeString(t, "%s", name)) : 0; } else { - throwNew(t, Machine::NullPointerExceptionType); + throwNew(t, GcNullPointerException::Type); } } @@ -226,7 +226,7 @@ Avian_avian_SystemClassLoader_00024ResourceEnumeration_nextResourceURLPrefix return name ? reinterpret_cast(makeString(t, "%s", name)) : 0; } else { - throwNew(t, Machine::NullPointerExceptionType); + throwNew(t, GcNullPointerException::Type); } } @@ -235,7 +235,7 @@ Avian_avian_SystemClassLoader_getClass (Thread* t, object, uintptr_t* arguments) { return reinterpret_cast - (getJClass(t, reinterpret_cast(arguments[0]))); + (getJClass(t, cast(t, reinterpret_cast(arguments[0])))); } extern "C" AVIAN_EXPORT int64_t JNICALL @@ -256,7 +256,7 @@ Avian_avian_SystemClassLoader_getPackageSource object key = makeByteArray(t, RUNTIME_ARRAY_BODY(chars)); object array = hashMapFind - (t, root(t, Machine::PackageMap), key, byteArrayHash, byteArrayEqual); + (t, cast(t, root(t, Machine::PackageMap)), key, byteArrayHash, byteArrayEqual); if (array) { return reinterpret_cast @@ -286,7 +286,7 @@ Avian_avian_Machine_dumpHeap } fclose(out); } else { - throwNew(t, Machine::RuntimeExceptionType, "file not found: %s", + throwNew(t, GcRuntimeException::Type, "file not found: %s", RUNTIME_ARRAY_BODY(n)); } } @@ -357,7 +357,7 @@ Avian_avian_avianvmresource_Handler_00024ResourceInputStream_open return reinterpret_cast(r); } else { - throwNew(t, Machine::NullPointerExceptionType); + throwNew(t, GcNullPointerException::Type); } } @@ -398,7 +398,7 @@ Avian_avian_avianvmresource_Handler_00024ResourceInputStream_read__JI_3BII int32_t length = arguments[5]; if (length == 0) return 0; - + System::Region* region = reinterpret_cast(peer); if (length > static_cast(region->length()) - position) { length = static_cast(region->length()) - position; @@ -469,7 +469,7 @@ Avian_avian_Singleton_getObject (Thread* t, object, uintptr_t* arguments) { return reinterpret_cast - (singletonObject(t, reinterpret_cast(arguments[0]), arguments[1])); + (singletonObject(t, cast(t, reinterpret_cast(arguments[0])), arguments[1])); } extern "C" AVIAN_EXPORT int64_t JNICALL @@ -477,7 +477,7 @@ Avian_avian_Singleton_getInt (Thread* t, object, uintptr_t* arguments) { return singletonValue - (t, reinterpret_cast(arguments[0]), arguments[1]); + (t, cast(t, reinterpret_cast(arguments[0])), arguments[1]); } extern "C" AVIAN_EXPORT int64_t JNICALL @@ -486,7 +486,7 @@ Avian_avian_Singleton_getLong { int64_t v; memcpy(&v, &singletonValue - (t, reinterpret_cast(arguments[0]), arguments[1]), 8); + (t, cast(t, reinterpret_cast(arguments[0])), arguments[1]), 8); return v; } @@ -499,7 +499,7 @@ Avian_sun_misc_Unsafe_allocateMemory if (p) { return reinterpret_cast(p); } else { - throwNew(t, Machine::OutOfMemoryErrorType); + throwNew(t, GcOutOfMemoryError::Type); } } @@ -711,19 +711,19 @@ extern "C" AVIAN_EXPORT int64_t JNICALL Avian_sun_misc_Unsafe_arrayIndexScale (Thread* t, object, uintptr_t* arguments) { - object c = jclassVmClass(t, reinterpret_cast(arguments[1])); + GcClass* c = cast(t, jclassVmClass(t, reinterpret_cast(arguments[1]))); - if (c == type(t, Machine::BooleanArrayType) - || c == type(t, Machine::ByteArrayType)) + if (c == type(t, GcBooleanArray::Type) + || c == type(t, GcByteArray::Type)) return 1; - else if (c == type(t, Machine::ShortArrayType) - || c == type(t, Machine::CharArrayType)) + else if (c == type(t, GcShortArray::Type) + || c == type(t, GcCharArray::Type)) return 2; - else if (c == type(t, Machine::IntArrayType) - || c == type(t, Machine::FloatArrayType)) + else if (c == type(t, GcIntArray::Type) + || c == type(t, GcFloatArray::Type)) return 4; - else if (c == type(t, Machine::LongArrayType) - || c == type(t, Machine::DoubleArrayType)) + else if (c == type(t, GcLongArray::Type) + || c == type(t, GcDoubleArray::Type)) return 8; else return BytesPerWord; @@ -740,7 +740,7 @@ Avian_java_nio_FixedArrayByteBuffer_allocateFixed object array = allocate3 (t, t->m->heap, Machine::FixedAllocation, ArrayBody + capacity, false); - setObjectClass(t, array, type(t, Machine::ByteArrayType)); + setObjectClass(t, array, type(t, GcByteArray::Type)); byteArrayLength(t, array) = capacity; longArrayBody(t, address, 0) = reinterpret_cast(array) + ArrayBody; @@ -776,7 +776,7 @@ Avian_sun_misc_Unsafe_putObjectVolatile object o = reinterpret_cast(arguments[1]); int64_t offset; memcpy(&offset, arguments + 2, 8); object value = reinterpret_cast(arguments[4]); - + storeStoreMemoryBarrier(); set(t, o, offset, reinterpret_cast(value)); storeLoadMemoryBarrier(); @@ -795,7 +795,7 @@ Avian_sun_misc_Unsafe_getObjectVolatile { object o = reinterpret_cast(arguments[1]); int64_t offset; memcpy(&offset, arguments + 2, 8); - + uintptr_t value = fieldAtOffset(o, offset); loadMemoryBarrier(); return value; @@ -866,21 +866,21 @@ Avian_sun_misc_Unsafe_getLongVolatile object lock; if (BytesPerWord < 8) { - if (classArrayDimensions(t, objectClass(t, o))) { - lock = objectClass(t, o); + if (objectClass(t, o)->arrayDimensions()) { + lock = reinterpret_cast(objectClass(t, o)); } else { - lock = fieldForOffset(t, o, offset); + lock = fieldForOffset(t, cast(t, o), offset); } PROTECT(t, o); PROTECT(t, lock); - acquire(t, lock); + acquire(t, lock); } int64_t result = fieldAtOffset(o, offset); if (BytesPerWord < 8) { - release(t, lock); + release(t, lock); } else { loadMemoryBarrier(); } @@ -898,15 +898,15 @@ Avian_sun_misc_Unsafe_putLongVolatile object lock; if (BytesPerWord < 8) { - if (classArrayDimensions(t, objectClass(t, o))) { - lock = objectClass(t, o); + if (objectClass(t, o)->arrayDimensions()) { + lock = reinterpret_cast(objectClass(t, o)); } else { - lock = fieldForOffset(t, o, offset); + lock = fieldForOffset(t, cast(t, o), offset); } PROTECT(t, o); PROTECT(t, lock); - acquire(t, lock); + acquire(t, lock); } else { storeStoreMemoryBarrier(); } @@ -934,7 +934,7 @@ Avian_sun_misc_Unsafe_unpark (Thread* t, object, uintptr_t* arguments) { object thread = reinterpret_cast(arguments[1]); - + monitorAcquire(t, interruptLock(t, thread)); threadUnparked(t, thread) = true; monitorNotify(t, interruptLock(t, thread)); @@ -947,7 +947,7 @@ Avian_sun_misc_Unsafe_park { bool absolute = arguments[1]; int64_t time; memcpy(&time, arguments + 2, 8); - + int64_t then = t->m->system->now(); if (absolute) { @@ -973,7 +973,7 @@ Avian_sun_misc_Unsafe_park int64_t now = t->m->system->now(); time -= now - then; then = now; - + if (time == 0) { break; } @@ -992,7 +992,7 @@ Avian_sun_misc_Unsafe_putIntVolatile object o = reinterpret_cast(arguments[1]); int64_t offset; memcpy(&offset, arguments + 2, 8); int32_t value = arguments[4]; - + storeStoreMemoryBarrier(); fieldAtOffset(o, offset) = value; storeLoadMemoryBarrier(); @@ -1024,7 +1024,7 @@ Avian_sun_misc_Unsafe_putByteVolatile object o = reinterpret_cast(arguments[1]); int64_t offset; memcpy(&offset, arguments + 2, 8); int8_t value = arguments[4]; - + storeStoreMemoryBarrier(); fieldAtOffset(o, offset) = value; storeLoadMemoryBarrier(); @@ -1063,7 +1063,7 @@ Avian_sun_misc_Unsafe_putShortVolatile object o = reinterpret_cast(arguments[1]); int64_t offset; memcpy(&offset, arguments + 2, 8); int16_t value = arguments[4]; - + storeStoreMemoryBarrier(); fieldAtOffset(o, offset) = value; storeLoadMemoryBarrier(); diff --git a/src/classpath-android.cpp b/src/classpath-android.cpp index 7d9e6d3dc3..f3db02c6bb 100644 --- a/src/classpath-android.cpp +++ b/src/classpath-android.cpp @@ -25,7 +25,7 @@ extern "C" int JNI_OnLoad(JavaVM*, void*); #include "avian/util.h" #ifdef PLATFORM_WINDOWS -const char* getErrnoDescription(int err); // This function is defined in mingw-extensions.cpp +const char* getErrnoDescription(int err); // This function is defined in mingw-extensions.cpp #endif using namespace vm; @@ -93,7 +93,7 @@ defineClass(Thread* t, object method, uintptr_t* arguments) if (v) { return reinterpret_cast - (getJClass(t, reinterpret_cast(v))); + (getJClass(t, cast(t, reinterpret_cast(v)))); } else { return 0; } @@ -103,7 +103,7 @@ int64_t JNICALL mapData(Thread*, object, uintptr_t*); void JNICALL -closeMemoryMappedFile(Thread*, object, uintptr_t*); +closeMemoryMappedFile(Thread*, GcMethod*, uintptr_t*); object makeMethodOrConstructor(Thread* t, object c, unsigned index) @@ -131,8 +131,8 @@ makeMethodOrConstructor(Thread* t, object c, unsigned index) (t, classLoader(t, methodClass(t, method)), methodAddendum(t, method)); if (byteArrayBody(t, methodName(t, method), 0) == '<') { - return makeJconstructor - (t, 0, c, parameterTypes, exceptionTypes, 0, 0, 0, 0, index); + return reinterpret_cast(makeJconstructor + (t, 0, c, parameterTypes, exceptionTypes, 0, 0, 0, 0, index)); } else { PROTECT(t, exceptionTypes); @@ -140,9 +140,9 @@ makeMethodOrConstructor(Thread* t, object c, unsigned index) (t, methodName(t, method), 0, byteArrayLength(t, methodName(t, method)) - 1); - return makeJmethod + return reinterpret_cast(makeJmethod (t, 0, index, c, name, parameterTypes, exceptionTypes, returnType, 0, 0, - 0, 0, 0); + 0, 0, 0)); } } @@ -168,7 +168,7 @@ makeField(Thread* t, object c, unsigned index) (t, fieldName(t, field), 0, byteArrayLength(t, fieldName(t, field)) - 1); - return makeJfield(t, 0, c, type, 0, 0, name, index); + return reinterpret_cast(makeJfield(t, 0, c, type, 0, 0, name, index)); } void initVmThread(Thread* t, object thread, unsigned offset) @@ -176,14 +176,14 @@ void initVmThread(Thread* t, object thread, unsigned offset) PROTECT(t, thread); if (fieldAtOffset(thread, offset) == 0) { - object c = resolveClass + GcClass* c = resolveClass (t, root(t, Machine::BootLoader), "java/lang/VMThread"); PROTECT(t, c); object instance = makeNew(t, c); PROTECT(t, instance); - object constructor = resolveMethod + GcMethod* constructor = resolveMethod (t, c, "", "(Ljava/lang/Thread;)V"); t->m->processor->invoke(t, constructor, instance, thread); @@ -235,13 +235,13 @@ class MyClasspath : public Classpath { { } virtual object - makeJclass(Thread* t, object class_) + makeJclass(Thread* t, GcClass* class_) { PROTECT(t, class_); - object c = allocate(t, FixedSizeOfJclass, true); - setObjectClass(t, c, type(t, Machine::JclassType)); - set(t, c, JclassVmClass, class_); + object c = allocate(t, GcJclass::FixedSize, true); + setObjectClass(t, c, type(t, GcJclass::Type)); + set(t, c, JclassVmClass, reinterpret_cast(class_)); return c; } @@ -249,10 +249,10 @@ class MyClasspath : public Classpath { virtual object makeString(Thread* t, object array, int32_t offset, int32_t length) { - if (objectClass(t, array) == type(t, Machine::ByteArrayType)) { + if (objectClass(t, array) == type(t, GcByteArray::Type)) { PROTECT(t, array); - object charArray = makeCharArray(t, length); + object charArray = reinterpret_cast(makeCharArray(t, length)); for (int i = 0; i < length; ++i) { expect(t, (byteArrayBody(t, array, offset + i) & 0x80) == 0); @@ -261,10 +261,10 @@ class MyClasspath : public Classpath { array = charArray; } else { - expect(t, objectClass(t, array) == type(t, Machine::CharArrayType)); + expect(t, objectClass(t, array) == type(t, GcCharArray::Type)); } - return vm::makeString(t, array, offset, length, 0); + return reinterpret_cast(vm::makeString(t, array, offset, length, 0)); } virtual object @@ -279,25 +279,25 @@ class MyClasspath : public Classpath { } else { resolveSystemClass (t, root(t, Machine::BootLoader), - className(t, type(t, Machine::ThreadGroupType)), false); + type(t, GcThreadGroup::Type)->name(), false); - group = makeNew(t, type(t, Machine::ThreadGroupType)); + group = makeNew(t, type(t, GcThreadGroup::Type)); - object constructor = resolveMethod - (t, type(t, Machine::ThreadGroupType), "", "()V"); + GcMethod* constructor = resolveMethod + (t, type(t, GcThreadGroup::Type), "", "()V"); t->m->processor->invoke(t, constructor, group); } resolveSystemClass (t, root(t, Machine::BootLoader), - className(t, type(t, Machine::ThreadType)), false); + type(t, GcThread::Type)->name(), false); - object thread = makeNew(t, type(t, Machine::ThreadType)); + object thread = makeNew(t, type(t, GcThread::Type)); PROTECT(t, thread); - object constructor = resolveMethod - (t, type(t, Machine::ThreadType), "", + GcMethod* constructor = resolveMethod + (t, type(t, GcThread::Type), "", "(Ljava/lang/ThreadGroup;Ljava/lang/String;IZ)V"); t->m->processor->invoke @@ -311,13 +311,13 @@ class MyClasspath : public Classpath { } virtual object - makeJMethod(Thread* t, object vmMethod) + makeJMethod(Thread* t, GcMethod* vmMethod) { - object table = classMethodTable(t, methodClass(t, vmMethod)); + object table = classMethodTable(t, vmMethod->class_()); for (unsigned i = 0; i < arrayLength(t, table); ++i) { - if (vmMethod == arrayBody(t, table, i)) { + if (reinterpret_cast(vmMethod) == arrayBody(t, table, i)) { return makeMethodOrConstructor - (t, getJClass(t, methodClass(t, vmMethod)), i); + (t, getJClass(t, cast(t, vmMethod->class_())), i); } } abort(t); @@ -326,7 +326,7 @@ class MyClasspath : public Classpath { virtual object getVMMethod(Thread* t, object jmethod) { - return objectClass(t, jmethod) == type(t, Machine::JmethodType) + return objectClass(t, jmethod) == type(t, GcJmethod::Type) ? arrayBody (t, classMethodTable (t, jclassVmClass(t, jmethodDeclaringClass(t, jmethod))), @@ -343,7 +343,7 @@ class MyClasspath : public Classpath { object table = classFieldTable(t, fieldClass(t, vmField)); for (unsigned i = 0; i < arrayLength(t, table); ++i) { if (vmField == arrayBody(t, table, i)) { - return makeField(t, getJClass(t, fieldClass(t, vmField)), i); + return makeField(t, getJClass(t, cast(t, fieldClass(t, vmField))), i); } } abort(t); @@ -394,14 +394,14 @@ class MyClasspath : public Classpath { initVmThread(t, t->javaThread, offset); - object method = resolveMethod + GcMethod* method = resolveMethod (t, root(t, Machine::BootLoader), "java/lang/Thread", "run", "()V"); t->m->processor->invoke(t, method, t->javaThread); } virtual void - resolveNative(Thread* t, object method) + resolveNative(Thread* t, GcMethod* method) { vm::resolveNative(t, method); } @@ -409,7 +409,7 @@ class MyClasspath : public Classpath { void interceptMethods(Thread* t, bool updateRuntimeData) { - { object c = resolveClass + { GcClass* c = resolveClass (t, root(t, Machine::BootLoader), "java/lang/Runtime", false); if (c) { @@ -421,7 +421,7 @@ class MyClasspath : public Classpath { } } - { object c = resolveClass + { GcClass* c = resolveClass (t, root(t, Machine::BootLoader), "java/lang/ref/FinalizerReference", false); @@ -433,7 +433,7 @@ class MyClasspath : public Classpath { } } - { object c = resolveClass + { GcClass* c = resolveClass (t, root(t, Machine::BootLoader), "java/lang/ClassLoader", false); if (c) { @@ -448,7 +448,7 @@ class MyClasspath : public Classpath { } } - { object c = resolveClass + { GcClass* c = resolveClass (t, root(t, Machine::BootLoader), "libcore/util/ZoneInfoDB", false); if (c) { @@ -459,7 +459,7 @@ class MyClasspath : public Classpath { } } - { object c = resolveClass + { GcClass* c = resolveClass (t, root(t, Machine::BootLoader), "libcore/io/MemoryMappedFile", false); @@ -506,11 +506,11 @@ class MyClasspath : public Classpath { virtual void boot(Thread* t) { - object c = resolveClass + GcClass* c = resolveClass (t, root(t, Machine::BootLoader), "java/lang/ClassLoader"); PROTECT(t, c); - object constructor = resolveMethod + GcMethod* constructor = resolveMethod (t, c, "", "(Ljava/lang/ClassLoader;Z)V"); PROTECT(t, constructor); @@ -531,14 +531,14 @@ class MyClasspath : public Classpath { virtual object makeDirectByteBuffer(Thread* t, void* p, jlong capacity) { - object c = resolveClass + GcClass* c = resolveClass (t, root(t, Machine::BootLoader), "java/nio/DirectByteBuffer"); PROTECT(t, c); object instance = makeNew(t, c); PROTECT(t, instance); - object constructor = resolveMethod(t, c, "", "(JI)V"); + GcMethod* constructor = resolveMethod(t, c, "", "(JI)V"); t->m->processor->invoke (t, constructor, instance, reinterpret_cast(p), @@ -565,20 +565,20 @@ class MyClasspath : public Classpath { } virtual bool - canTailCall(Thread*, object, object, object, object) + canTailCall(Thread*, GcMethod*, object, object, object) { return true; } - virtual object libraryClassLoader(Thread* t, object caller) + virtual object libraryClassLoader(Thread* t, GcMethod* caller) { return strcmp( "java/lang/Runtime", reinterpret_cast( - &byteArrayBody(t, className(t, methodClass(t, caller)), 0))) + &byteArrayBody(t, className(t, caller->class_()), 0))) == 0 ? t->libraryLoadStack->classLoader - : classLoader(t, methodClass(t, caller)); + : classLoader(t, caller->class_()); } virtual void @@ -604,14 +604,14 @@ class MyClasspath : public Classpath { int64_t JNICALL mapData(Thread* t, object, uintptr_t*) { - object c = resolveClass + GcClass* c = resolveClass (t, root(t, Machine::BootLoader), "libcore/io/MemoryMappedFile"); PROTECT(t, c); object instance = makeNew(t, c); PROTECT(t, instance); - object constructor = resolveMethod(t, c, "", "(JJ)V"); + GcMethod* constructor = resolveMethod(t, c, "", "(JJ)V"); const char* jar = "javahomeJar"; Finder* finder = getFinder(t, jar, strlen(jar)); @@ -632,11 +632,11 @@ mapData(Thread* t, object, uintptr_t*) } } - throwNew(t, Machine::RuntimeExceptionType); + throwNew(t, GcRuntimeException::Type); } void JNICALL -closeMemoryMappedFile(Thread* t, object method, uintptr_t* arguments) +closeMemoryMappedFile(Thread* t, GcMethod* method, uintptr_t* arguments) { object file = reinterpret_cast(arguments[0]); PROTECT(t, file); @@ -658,8 +658,8 @@ closeMemoryMappedFile(Thread* t, object method, uintptr_t* arguments) } t->m->processor->invoke - (t, nativeInterceptOriginal - (t, methodRuntimeDataNative(t, getMethodRuntimeData(t, method))), + (t, cast(t, nativeInterceptOriginal + (t, methodRuntimeDataNative(t, getMethodRuntimeData(t, method)))), file); } @@ -668,28 +668,28 @@ matchType(Thread* t, object field, object o) { switch (fieldCode(t, field)) { case ByteField: - return objectClass(t, o) == type(t, Machine::ByteType); + return objectClass(t, o) == type(t, GcByte::Type); case BooleanField: - return objectClass(t, o) == type(t, Machine::BooleanType); + return objectClass(t, o) == type(t, GcBoolean::Type); case CharField: - return objectClass(t, o) == type(t, Machine::CharType); + return objectClass(t, o) == type(t, GcChar::Type); case ShortField: - return objectClass(t, o) == type(t, Machine::ShortType); + return objectClass(t, o) == type(t, GcShort::Type); case IntField: - return objectClass(t, o) == type(t, Machine::IntType); + return objectClass(t, o) == type(t, GcInt::Type); case LongField: - return objectClass(t, o) == type(t, Machine::LongType); + return objectClass(t, o) == type(t, GcLong::Type); case FloatField: - return objectClass(t, o) == type(t, Machine::FloatType); + return objectClass(t, o) == type(t, GcFloat::Type); case DoubleField: - return objectClass(t, o) == type(t, Machine::DoubleType); + return objectClass(t, o) == type(t, GcDouble::Type); case ObjectField: if (o == 0) { @@ -701,7 +701,7 @@ matchType(Thread* t, object field, object o) if (byteArrayBody(t, fieldSpec(t, field), 0) == '[') { spec = fieldSpec(t, field);; } else { - spec = makeByteArray(t, byteArrayLength(t, fieldSpec(t, field)) - 2); + spec = reinterpret_cast(makeByteArray(t, byteArrayLength(t, fieldSpec(t, field)) - 2)); memcpy(&byteArrayBody(t, spec, 0), &byteArrayBody(t, fieldSpec(t, field), 1), @@ -725,42 +725,42 @@ getField(Thread* t, object field, object instance) PROTECT(t, field); PROTECT(t, instance); - initClass(t, fieldClass(t, field)); + initClass(t, cast(t, fieldClass(t, field))); object target; if (fieldFlags(t, field) & ACC_STATIC) { target = classStaticTable(t, fieldClass(t, field)); - } else if (instanceOf(t, fieldClass(t, field), instance)){ + } else if (instanceOf(t, cast(t, fieldClass(t, field)), instance)){ target = instance; } else { - throwNew(t, Machine::IllegalArgumentExceptionType); + throwNew(t, GcIllegalArgumentException::Type); } unsigned offset = fieldOffset(t, field); switch (fieldCode(t, field)) { case ByteField: - return makeByte(t, fieldAtOffset(target, offset)); + return reinterpret_cast(makeByte(t, fieldAtOffset(target, offset))); case BooleanField: - return makeBoolean(t, fieldAtOffset(target, offset)); + return reinterpret_cast(makeBoolean(t, fieldAtOffset(target, offset))); case CharField: - return makeChar(t, fieldAtOffset(target, offset)); + return reinterpret_cast(makeChar(t, fieldAtOffset(target, offset))); case ShortField: - return makeShort(t, fieldAtOffset(target, offset)); + return reinterpret_cast(makeShort(t, fieldAtOffset(target, offset))); case IntField: - return makeInt(t, fieldAtOffset(target, offset)); + return reinterpret_cast(makeInt(t, fieldAtOffset(target, offset))); case LongField: - return makeLong(t, fieldAtOffset(target, offset)); + return reinterpret_cast(makeLong(t, fieldAtOffset(target, offset))); case FloatField: - return makeFloat(t, fieldAtOffset(target, offset)); + return reinterpret_cast(makeFloat(t, fieldAtOffset(target, offset))); case DoubleField: - return makeDouble(t, fieldAtOffset(target, offset)); + return reinterpret_cast(makeDouble(t, fieldAtOffset(target, offset))); case ObjectField: return fieldAtOffset(target, offset); @@ -777,20 +777,20 @@ setField(Thread* t, object field, object instance, object value) PROTECT(t, value); if (not matchType(t, field, value)) { - throwNew(t, Machine::IllegalArgumentExceptionType); + throwNew(t, GcIllegalArgumentException::Type); } object target; if ((fieldFlags(t, field) & ACC_STATIC) != 0) { target = classStaticTable(t, fieldClass(t, field)); - } else if (instanceOf(t, fieldClass(t, field), instance)){ + } else if (instanceOf(t, cast(t, fieldClass(t, field)), instance)){ target = instance; } else { - throwNew(t, Machine::IllegalArgumentExceptionType); + throwNew(t, GcIllegalArgumentException::Type); } PROTECT(t, target); - initClass(t, fieldClass(t, field)); + initClass(t, cast(t, fieldClass(t, field))); unsigned offset = fieldOffset(t, field); switch (fieldCode(t, field)) { @@ -1100,7 +1100,7 @@ Avian_java_lang_Class_getInterfaces PROTECT(t, array); for (unsigned i = 0; i < arrayLength(t, table); ++i) { - object c = getJClass(t, arrayBody(t, table, i)); + object c = getJClass(t, cast(t, arrayBody(t, table, i))); set(t, array, ArrayBody + (i * BytesPerWord), c); } @@ -1109,7 +1109,7 @@ Avian_java_lang_Class_getInterfaces } return reinterpret_cast - (makeObjectArray(t, type(t, Machine::JclassType), 0)); + (makeObjectArray(t, type(t, GcJclass::Type), 0)); } extern "C" AVIAN_EXPORT int64_t JNICALL @@ -1151,11 +1151,17 @@ Avian_java_lang_Class_getEnclosingMethod if (enclosingMethod) { PROTECT(t, enclosingMethod); - return reinterpret_cast - (t->m->classpath->makeJMethod - (t, findMethodInClass - (t, enclosingClass, pairFirst(t, enclosingMethod), - pairSecond(t, enclosingMethod)))); + abort(t); + // TODO: the following violates type safety; enclosingClass at this + // point is a GcJclass (having come from "getJClass()") - but the method + // expects a GcClass. + // Figure it out. + + // return reinterpret_cast + // (t->m->classpath->makeJMethod + // (t, findMethodInClass + // (t, cast(t, enclosingClass), pairFirst(t, enclosingMethod), + // pairSecond(t, enclosingMethod)))); } } } @@ -1173,9 +1179,9 @@ extern "C" AVIAN_EXPORT int64_t JNICALL Avian_java_lang_Class_newInstanceImpl (Thread* t, object, uintptr_t* arguments) { - object c = jclassVmClass(t, reinterpret_cast(arguments[0])); + GcClass* c = cast(t, jclassVmClass(t, reinterpret_cast(arguments[0]))); - object method = resolveMethod(t, c, "", "()V"); + GcMethod* method = resolveMethod(t, c, "", "()V"); PROTECT(t, method); object instance = makeNew(t, c); @@ -1199,7 +1205,7 @@ Avian_java_lang_Class_getComponentType (getJClass(t, primitiveClass(t, n))); } else { return reinterpret_cast - (getJClass(t, classStaticTable(t, jclassVmClass(t, c)))); + (getJClass(t, cast(t, classStaticTable(t, jclassVmClass(t, c))))); } } else { return 0; @@ -1216,7 +1222,7 @@ Avian_java_lang_Class_classForName object loader = reinterpret_cast(arguments[2]); PROTECT(t, loader); - object method = resolveMethod + GcMethod* method = resolveMethod (t, root(t, Machine::BootLoader), "avian/Classes", "forName", "(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;"); @@ -1235,7 +1241,7 @@ Avian_java_lang_Class_getDeclaredField object name = reinterpret_cast(arguments[1]); PROTECT(t, name); - object method = resolveMethod + GcMethod* method = resolveMethod (t, root(t, Machine::BootLoader), "avian/Classes", "findField", "(Lavian/VMClass;Ljava/lang/String;)I"); @@ -1263,7 +1269,7 @@ Avian_java_lang_Class_getDeclaredConstructorOrMethod object parameterTypes = reinterpret_cast(arguments[2]); PROTECT(t, parameterTypes); - object method = resolveMethod + GcMethod* method = resolveMethod (t, root(t, Machine::BootLoader), "avian/Classes", "findMethod", "(Lavian/VMClass;Ljava/lang/String;[Ljava/lang/Class;)I"); @@ -1292,7 +1298,7 @@ Avian_java_lang_VMClassLoader_findLoadedClass if (v) { return reinterpret_cast - (getJClass(t, reinterpret_cast(v))); + (getJClass(t, cast(t, reinterpret_cast(v)))); } else { return 0; } @@ -1309,7 +1315,7 @@ Avian_java_lang_VMClassLoader_defineClass__Ljava_lang_ClassLoader_2Ljava_lang_St if (v) { return reinterpret_cast - (getJClass(t, reinterpret_cast(v))); + (getJClass(t, cast(t, reinterpret_cast(v)))); } else { return 0; } @@ -1341,7 +1347,7 @@ Avian_dalvik_system_VMRuntime_properties (Thread* t, object, uintptr_t*) { object array = makeObjectArray( - t, type(t, Machine::StringType), t->m->propertyCount + 1); + t, type(t, GcString::Type), t->m->propertyCount + 1); PROTECT(t, array); unsigned i; @@ -1477,7 +1483,7 @@ Avian_java_lang_VMThread_sleep if (milliseconds <= 0) milliseconds = 1; if (threadSleepLock(t, t->javaThread) == 0) { - object lock = makeJobject(t); + object lock = reinterpret_cast(makeJobject(t)); set(t, t->javaThread, ThreadSleepLock, lock); } @@ -1514,7 +1520,7 @@ Avian_dalvik_system_VMStack_getCallingClassLoader if (counter--) { return true; } else { - this->loader = classLoader(t, methodClass(t, walker->method())); + this->loader = classLoader(t, walker->method()->class_()); return false; } } @@ -1545,10 +1551,10 @@ Avian_dalvik_system_VMStack_getClasses } else { if (array == 0) { array = makeObjectArray - (t, type(t, Machine::JclassType), walker->count()); + (t, type(t, GcJclass::Type), walker->count()); } - object c = getJClass(t, methodClass(t, walker->method())); + object c = getJClass(t, cast(t, walker->method()->class_())); assert(t, counter - 2 < objectArrayLength(t, array)); @@ -1570,7 +1576,7 @@ Avian_dalvik_system_VMStack_getClasses t->m->processor->walkStack(t, &v); return reinterpret_cast - (v.array ? v.array : makeObjectArray(t, type(t, Machine::JclassType), 0)); + (v.array ? v.array : makeObjectArray(t, type(t, GcJclass::Type), 0)); } extern "C" AVIAN_EXPORT int64_t JNICALL @@ -1718,7 +1724,7 @@ Avian_java_lang_Class_getSuperclass if (classFlags(t, c) & ACC_INTERFACE) { return 0; } else { - object s = classSuper(t, c); + GcClass* s = cast(t, classSuper(t, c)); return s ? reinterpret_cast(getJClass(t, s)) : 0; } } @@ -1798,9 +1804,9 @@ Avian_java_lang_Class_isAssignableFrom if (LIKELY(that)) { return isAssignableFrom - (t, jclassVmClass(t, this_), jclassVmClass(t, that)); + (t, cast(t, jclassVmClass(t, this_)), cast(t, jclassVmClass(t, that))); } else { - throwNew(t, Machine::NullPointerExceptionType); + throwNew(t, GcNullPointerException::Type); } } @@ -1812,7 +1818,7 @@ Avian_java_lang_Class_isInstance object o = reinterpret_cast(arguments[1]); if (o) { - return instanceOf(t, jclassVmClass(t, this_), o); + return instanceOf(t, cast(t, jclassVmClass(t, this_)), o); } else { return 0; } @@ -1827,7 +1833,7 @@ Avian_java_lang_Class_getDeclaredMethods bool publicOnly = arguments[1]; - object get = resolveMethod + GcMethod* get = resolveMethod (t, root(t, Machine::BootLoader), "avian/Classes", "getMethods", "(Lavian/VMClass;Z)[Ljava/lang/reflect/Method;"); @@ -1844,7 +1850,7 @@ Avian_java_lang_Class_getDeclaredFields bool publicOnly = arguments[1]; - object get = resolveMethod + GcMethod* get = resolveMethod (t, root(t, Machine::BootLoader), "avian/Classes", "getFields", "(Lavian/VMClass;Z)[Ljava/lang/reflect/Field;"); @@ -1858,10 +1864,10 @@ Avian_java_lang_reflect_Method_invokeNative { object instance = reinterpret_cast(arguments[1]); object args = reinterpret_cast(arguments[2]); - object method = arrayBody + GcMethod* method = cast(t, arrayBody (t, classMethodTable (t, jclassVmClass(t, reinterpret_cast(arguments[3]))), - arguments[6]); + arguments[6])); return reinterpret_cast(invoke(t, method, instance, args)); } @@ -1923,7 +1929,7 @@ Avian_java_lang_reflect_Method_getAnnotation PROTECT(t, method); PROTECT(t, table); - object get = resolveMethod + GcMethod* get = resolveMethod (t, root(t, Machine::BootLoader), "avian/Classes", "getAnnotation", "(Ljava/lang/ClassLoader;[Ljava/lang/Object;)" "Ljava/lang/annotation/Annotation;"); @@ -1962,7 +1968,7 @@ Avian_java_lang_reflect_Method_getDeclaredAnnotations objectArrayLength(t, table)); PROTECT(t, array); - object get = resolveMethod + GcMethod* get = resolveMethod (t, root(t, Machine::BootLoader), "avian/Classes", "getAnnotation", "(Ljava/lang/ClassLoader;[Ljava/lang/Object;)" "Ljava/lang/annotation/Annotation;"); @@ -2013,7 +2019,7 @@ extern "C" AVIAN_EXPORT int64_t JNICALL objectArrayLength(t, table)); PROTECT(t, array); - object get = resolveMethod(t, + GcMethod* get = resolveMethod(t, root(t, Machine::BootLoader), "avian/Classes", "getAnnotation", @@ -2054,7 +2060,7 @@ Avian_java_lang_reflect_Method_getDefaultValue object addendum = methodAddendum(t, method); if (addendum) { - object get = resolveMethod + GcMethod* get = resolveMethod (t, root(t, Machine::BootLoader), "avian/Classes", "getAnnotationDefaultValue", "(Ljava/lang/ClassLoader;Lavian/MethodAddendum;)" @@ -2075,12 +2081,12 @@ Avian_java_lang_reflect_Constructor_constructNative object args = reinterpret_cast(arguments[1]); PROTECT(t, args); - object c = jclassVmClass(t, reinterpret_cast(arguments[2])); + GcClass* c = cast(t, jclassVmClass(t, reinterpret_cast(arguments[2]))); PROTECT(t, c); initClass(t, c); - object method = arrayBody(t, classMethodTable(t, c), arguments[4]); + GcMethod* method = cast(t, arrayBody(t, c->methodTable(), arguments[4])); PROTECT(t, method); object instance = makeNew(t, c); @@ -2174,7 +2180,7 @@ Avian_java_lang_reflect_Field_setIField object instance = reinterpret_cast(arguments[1]); PROTECT(t, instance); - object value = makeInt(t, arguments[7]); + object value = reinterpret_cast(makeInt(t, arguments[7])); local::setField(t, field, instance, value); } @@ -2210,7 +2216,7 @@ Avian_java_lang_reflect_Field_getAnnotation PROTECT(t, field); PROTECT(t, table); - object get = resolveMethod + GcMethod* get = resolveMethod (t, root(t, Machine::BootLoader), "avian/Classes", "getAnnotation", "(Ljava/lang/ClassLoader;[Ljava/lang/Object;)" "Ljava/lang/annotation/Annotation;"); @@ -2294,7 +2300,7 @@ Avian_java_lang_reflect_Array_createObjectArray { return reinterpret_cast (makeObjectArray - (t, jclassVmClass(t, reinterpret_cast(arguments[0])), + (t, cast(t, jclassVmClass(t, reinterpret_cast(arguments[0]))), arguments[1])); } @@ -2309,14 +2315,14 @@ extern "C" AVIAN_EXPORT int64_t JNICALL Avian_dalvik_system_VMRuntime_newNonMovableArray (Thread* t, object, uintptr_t* arguments) { - if (jclassVmClass(t, reinterpret_cast(arguments[1])) - == type(t, Machine::JbyteType)) + if (cast(t, jclassVmClass(t, reinterpret_cast(arguments[1]))) + == type(t, GcJbyte::Type)) { object array = allocate3 (t, t->m->heap, Machine::FixedAllocation, ArrayBody + arguments[2], false); - setObjectClass(t, array, type(t, Machine::ByteArrayType)); + setObjectClass(t, array, type(t, GcByteArray::Type)); byteArrayLength(t, array) = arguments[2]; return reinterpret_cast(array); @@ -2492,7 +2498,7 @@ Avian_libcore_io_Posix_getenv(Thread* t, object, uintptr_t* arguments) extern "C" AVIAN_EXPORT int64_t JNICALL Avian_libcore_io_Posix_uname(Thread* t, object, uintptr_t*) { - object c = resolveClass + GcClass* c = resolveClass (t, root(t, Machine::BootLoader), "libcore/io/StructUtsname"); PROTECT(t, c); @@ -2540,7 +2546,7 @@ Avian_libcore_io_Posix_writeBytes(Thread* t, object, uintptr_t* arguments) int d = jniGetFDFromFileDescriptor(t, &fd); int r; - if (objectClass(t, buffer) == type(t, Machine::ByteArrayType)) { + if (objectClass(t, buffer) == type(t, GcByteArray::Type)) { void* tmp = t->m->heap->allocate(count); memcpy(tmp, &byteArrayBody(t, buffer, offset), count); { ENTER(t, Thread::IdleState); @@ -2556,7 +2562,7 @@ Avian_libcore_io_Posix_writeBytes(Thread* t, object, uintptr_t* arguments) if (r < 0) { THREAD_RUNTIME_ARRAY(t, char, message, 256); - throwNew(t, Machine::RuntimeExceptionType, "writeBytes %d: %s", d, + throwNew(t, GcRuntimeException::Type, "writeBytes %d: %s", d, jniStrError(errno, RUNTIME_ARRAY_BODY(message), 0)); } else { return r; diff --git a/src/classpath-avian.cpp b/src/classpath-avian.cpp index 7bed10ce32..434a9aa9de 100644 --- a/src/classpath-avian.cpp +++ b/src/classpath-avian.cpp @@ -27,15 +27,15 @@ class MyClasspath : public Classpath { { } virtual object - makeJclass(Thread* t, object class_) + makeJclass(Thread* t, GcClass* class_) { - return vm::makeJclass(t, class_); + return reinterpret_cast(vm::makeJclass(t, reinterpret_cast(class_))); } virtual object makeString(Thread* t, object array, int32_t offset, int32_t length) { - return vm::makeString(t, array, offset, length, 0); + return reinterpret_cast(vm::makeString(t, array, offset, length, 0)); } virtual object @@ -45,32 +45,32 @@ class MyClasspath : public Classpath { if (parent) { group = threadGroup(t, parent->javaThread); } else { - group = makeThreadGroup(t, 0, 0, 0); + group = reinterpret_cast(makeThreadGroup(t, 0, 0, 0)); } const unsigned NewState = 0; const unsigned NormalPriority = 5; - return vm::makeThread + return reinterpret_cast(vm::makeThread (t, 0, 0, 0, 0, 0, NewState, NormalPriority, 0, 0, 0, - root(t, Machine::AppLoader), 0, 0, group, 0); + root(t, Machine::AppLoader), 0, 0, group, 0)); } virtual object - makeJMethod(Thread* t, object vmMethod) + makeJMethod(Thread* t, GcMethod* vmMethod) { PROTECT(t, vmMethod); - object jmethod = makeJmethod(t, vmMethod, false); + object jmethod = reinterpret_cast(makeJmethod(t, reinterpret_cast(vmMethod), false)); - return byteArrayBody(t, methodName(t, vmMethod), 0) == '<' - ? makeJconstructor(t, jmethod) : jmethod; + return byteArrayBody(t, vmMethod->name(), 0) == '<' + ? reinterpret_cast(makeJconstructor(t, jmethod)) : jmethod; } virtual object getVMMethod(Thread* t, object jmethod) { - return objectClass(t, jmethod) == type(t, Machine::JmethodType) + return objectClass(t, jmethod) == type(t, GcJmethod::Type) ? jmethodVmMethod(t, jmethod) : jmethodVmMethod(t, jconstructorMethod(t, jmethod)); } @@ -78,7 +78,7 @@ class MyClasspath : public Classpath { virtual object makeJField(Thread* t, object vmField) { - return makeJfield(t, vmField, false); + return reinterpret_cast(makeJfield(t, vmField, false)); } virtual object @@ -96,7 +96,7 @@ class MyClasspath : public Classpath { virtual void runThread(Thread* t) { - object method = resolveMethod + GcMethod* method = resolveMethod (t, root(t, Machine::BootLoader), "java/lang/Thread", "run", "(Ljava/lang/Thread;)V"); @@ -104,7 +104,7 @@ class MyClasspath : public Classpath { } virtual void - resolveNative(Thread* t, object method) + resolveNative(Thread* t, GcMethod* method) { vm::resolveNative(t, method); } @@ -141,14 +141,14 @@ class MyClasspath : public Classpath { virtual object makeDirectByteBuffer(Thread* t, void* p, jlong capacity) { - object c = resolveClass + GcClass* c = resolveClass (t, root(t, Machine::BootLoader), "java/nio/DirectByteBuffer"); PROTECT(t, c); object instance = makeNew(t, c); PROTECT(t, instance); - object constructor = resolveMethod(t, c, "", "(JI)V"); + GcMethod* constructor = resolveMethod(t, c, "", "(JI)V"); t->m->processor->invoke (t, constructor, instance, reinterpret_cast(p), @@ -180,7 +180,7 @@ class MyClasspath : public Classpath { } virtual bool canTailCall(Thread* t, - object, + GcMethod*, object calleeClassName, object calleeMethodName, object) @@ -204,12 +204,12 @@ class MyClasspath : public Classpath { &byteArrayBody(t, calleeClassName, 0))))); } - virtual object libraryClassLoader(Thread* t, object caller) + virtual object libraryClassLoader(Thread* t, GcMethod* caller) { - return (methodClass(t, caller) == type(t, Machine::ClassLoaderType) + return (caller->class_() == reinterpret_cast(type(t, Gc::ClassLoaderType)) and t->libraryLoadStack) ? t->libraryLoadStack->classLoader - : classLoader(t, methodClass(t, caller)); + : classLoader(t, caller->class_()); } 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, className(t, objectClass(t, this_)), 0), + &byteArrayBody(t, objectClass(t, this_)->name(), 0), hash); return reinterpret_cast(s); @@ -328,7 +328,7 @@ extern "C" AVIAN_EXPORT int64_t JNICALL Avian_java_io_ObjectInputStream_makeInstance (Thread* t, object, uintptr_t* arguments) { - object c = reinterpret_cast(arguments[0]); + GcClass* c = cast(t, reinterpret_cast(arguments[0])); return reinterpret_cast(make(t, c)); } @@ -434,7 +434,7 @@ extern "C" AVIAN_EXPORT int64_t JNICALL Avian_java_lang_reflect_Constructor_make (Thread* t, object, uintptr_t* arguments) { - object c = reinterpret_cast(arguments[0]); + GcClass* c = cast(t, reinterpret_cast(arguments[0])); return reinterpret_cast(make(t, c)); } @@ -450,7 +450,7 @@ extern "C" AVIAN_EXPORT int64_t JNICALL Avian_java_lang_reflect_Method_invoke (Thread* t, object, uintptr_t* arguments) { - object method = reinterpret_cast(arguments[0]); + GcMethod* method = cast(t, reinterpret_cast(arguments[0])); object instance = reinterpret_cast(arguments[1]); object args = reinterpret_cast(arguments[2]); @@ -458,11 +458,11 @@ Avian_java_lang_reflect_Method_invoke if (t->exception) { object exception = t->exception; t->exception = makeThrowable - (t, Machine::InvocationTargetExceptionType, 0, 0, exception); + (t, GcInvocationTargetException::Type, 0, 0, exception); } }); - unsigned returnCode = methodReturnCode(t, method); + unsigned returnCode = method->returnCode(); return reinterpret_cast (translateInvokeResult @@ -476,15 +476,15 @@ Avian_java_lang_reflect_Array_getLength object array = reinterpret_cast(arguments[0]); if (LIKELY(array)) { - unsigned elementSize = classArrayElementSize(t, objectClass(t, array)); + unsigned elementSize = objectClass(t, array)->arrayElementSize(); if (LIKELY(elementSize)) { return fieldAtOffset(array, BytesPerWord); } else { - throwNew(t, Machine::IllegalArgumentExceptionType); + throwNew(t, GcIllegalArgumentException::Type); } } else { - throwNew(t, Machine::NullPointerExceptionType); + throwNew(t, GcNullPointerException::Type); } } @@ -496,7 +496,7 @@ Avian_java_lang_reflect_Array_makeObjectArray int length = arguments[1]; return reinterpret_cast - (makeObjectArray(t, jclassVmClass(t, elementType), length)); + (makeObjectArray(t, cast(t, jclassVmClass(t, elementType)), length)); } extern "C" AVIAN_EXPORT int64_t JNICALL @@ -542,7 +542,7 @@ extern "C" AVIAN_EXPORT int64_t JNICALL Avian_java_lang_System_getVMProperties(Thread* t, object, uintptr_t*) { object array - = makeObjectArray(t, type(t, Machine::StringType), t->m->propertyCount); + = makeObjectArray(t, type(t, GcString::Type), t->m->propertyCount); PROTECT(t, array); for (unsigned i = 0; i < t->m->propertyCount; ++i) { @@ -573,7 +573,7 @@ Avian_java_lang_System_identityHashCode if (LIKELY(o)) { return objectHash(t, o); } else { - throwNew(t, Machine::NullPointerExceptionType); + throwNew(t, GcNullPointerException::Type); } } @@ -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, methodClass(t, getCaller(t, 2)))); + getJClass(t, cast(t, getCaller(t, 2)->class_()))); } extern "C" AVIAN_EXPORT void JNICALL @@ -619,7 +619,7 @@ Avian_java_lang_Runtime_addShutdownHook ACQUIRE(t, t->m->shutdownLock); setRoot(t, Machine::ShutdownHooks, - makePair(t, hook, root(t, Machine::ShutdownHooks))); + reinterpret_cast(makePair(t, hook, root(t, Machine::ShutdownHooks)))); } extern "C" AVIAN_EXPORT int64_t JNICALL @@ -637,7 +637,7 @@ Avian_java_lang_Throwable_resolveTrace PROTECT(t, trace); unsigned length = objectArrayLength(t, trace); - object elementType = type(t, Machine::StackTraceElementType); + GcClass* elementType = type(t, GcStackTraceElement::Type); object array = makeObjectArray(t, elementType, length); PROTECT(t, array); @@ -764,13 +764,13 @@ extern "C" AVIAN_EXPORT int64_t JNICALL Avian_avian_Classes_isAssignableFrom (Thread* t, object, uintptr_t* arguments) { - object this_ = reinterpret_cast(arguments[0]); - object that = reinterpret_cast(arguments[1]); + GcClass* this_ = cast(t, reinterpret_cast(arguments[0])); + GcClass* that = cast(t, reinterpret_cast(arguments[1])); if (LIKELY(that)) { return vm::isAssignableFrom(t, this_, that); } else { - throwNew(t, Machine::NullPointerExceptionType); + throwNew(t, GcNullPointerException::Type); } } @@ -792,14 +792,14 @@ Avian_avian_Classes_makeMethod arguments[1]); PROTECT(t, method); - object c = resolveClass + GcClass* c = resolveClass (t, root(t, Machine::BootLoader), "java/lang/reflect/Method"); PROTECT(t, c); object instance = makeNew(t, c); PROTECT(t, instance); - object constructor = resolveMethod(t, c, "", "(Lavian/VMMethod;)V"); + GcMethod* constructor = resolveMethod(t, c, "", "(Lavian/VMMethod;)V"); t->m->processor->invoke(t, constructor, instance, method); @@ -811,7 +811,7 @@ Avian_avian_Classes_makeMethod object instance = makeNew(t, c); - object constructor = resolveMethod + GcMethod* constructor = resolveMethod (t, c, "", "(Ljava/lang/Method;)V"); t->m->processor->invoke(t, constructor, instance, method); diff --git a/src/classpath-openjdk.cpp b/src/classpath-openjdk.cpp index 6e63aa454f..f79885309b 100644 --- a/src/classpath-openjdk.cpp +++ b/src/classpath-openjdk.cpp @@ -291,7 +291,7 @@ const int VirtualFileBase = 1000000000; Machine* globalMachine; const char* -primitiveName(Thread* t, object c) +primitiveName(Thread* t, GcClass* c) { if (c == primitiveClass(t, 'V')) { return "void"; @@ -317,21 +317,21 @@ primitiveName(Thread* t, object c) } object -getClassName(Thread* t, object c) +getClassName(Thread* t, GcClass* c) { - if (className(t, c) == 0) { - if (classVmFlags(t, c) & PrimitiveFlag) { + if (c->name() == 0) { + if (c->vmFlags() & PrimitiveFlag) { PROTECT(t, c); object name = makeByteArray(t, primitiveName(t, c)); - set(t, c, ClassName, name); + set(t, reinterpret_cast(c), ClassName, name); } else { abort(t); } } - return className(t, c); + return c->name(); } object @@ -482,17 +482,17 @@ class MyClasspath : public Classpath { } virtual object - makeJclass(Thread* t, object class_) + makeJclass(Thread* t, GcClass* class_) { PROTECT(t, class_); object name = makeClassNameString(t, getClassName(t, class_)); PROTECT(t, name); - object c = allocate(t, FixedSizeOfJclass, true); - setObjectClass(t, c, type(t, Machine::JclassType)); + object c = allocate(t, GcJclass::FixedSize, true); + setObjectClass(t, c, type(t, GcJclass::Type)); set(t, c, JclassName, name); - set(t, c, JclassVmClass, class_); + set(t, c, JclassVmClass, reinterpret_cast(class_)); return c; } @@ -500,21 +500,21 @@ class MyClasspath : public Classpath { virtual object makeString(Thread* t, object array, int32_t offset, int32_t length) { - if (objectClass(t, array) == type(t, Machine::ByteArrayType)) { + if (objectClass(t, array) == type(t, GcByteArray::Type)) { PROTECT(t, array); - object charArray = makeCharArray(t, length); + GcCharArray* charArray = makeCharArray(t, length); for (int i = 0; i < length; ++i) { if (byteArrayBody(t, array, offset + i) & 0x80) { - object constructor = resolveMethod - (t, type(t, Machine::StringType), "", + GcMethod* constructor = resolveMethod + (t, type(t, GcString::Type), "", "([BIILjava/lang/String;)V"); PROTECT(t, constructor); object utf8 = vm::makeString(t, "UTF8"); PROTECT(t, utf8); - object s = makeNew(t, type(t, Machine::StringType)); + object s = makeNew(t, type(t, GcString::Type)); PROTECT(t, s); t->m->processor->invoke @@ -523,12 +523,12 @@ class MyClasspath : public Classpath { return s; } - charArrayBody(t, charArray, i) = byteArrayBody(t, array, offset + i); + charArrayBody(t, reinterpret_cast(charArray), i) = byteArrayBody(t, array, offset + i); } - array = charArray; + array = reinterpret_cast(charArray); } else { - expect(t, objectClass(t, array) == type(t, Machine::CharArrayType)); + expect(t, objectClass(t, array) == type(t, GcCharArray::Type)); } return vm::makeString(t, array, offset, length, 0); @@ -544,28 +544,28 @@ class MyClasspath : public Classpath { if (parent) { group = threadGroup(t, parent->javaThread); } else { - group = allocate(t, FixedSizeOfThreadGroup, true); - setObjectClass(t, group, type(t, Machine::ThreadGroupType)); + group = allocate(t, GcThreadGroup::FixedSize, true); + setObjectClass(t, group, type(t, GcThreadGroup::Type)); threadGroupMaxPriority(t, group) = MaxPriority; } PROTECT(t, group); - object thread = allocate(t, FixedSizeOfThread, true); - setObjectClass(t, thread, type(t, Machine::ThreadType)); + object thread = allocate(t, GcThread::FixedSize, true); + setObjectClass(t, thread, type(t, GcThread::Type)); threadPriority(t, thread) = NormalPriority; threadGroup(t, thread) = group; threadContextClassLoader(t, thread) = root(t, Machine::AppLoader); PROTECT(t, thread); - object blockerLock = makeJobject(t); + object blockerLock = reinterpret_cast(makeJobject(t)); set(t, thread, ThreadBlockerLock, blockerLock); const unsigned BufferSize = 256; char buffer[BufferSize]; unsigned length = vm::snprintf(buffer, BufferSize, "Thread-%p", thread); - object name = makeCharArray(t, length); + object name = reinterpret_cast(makeCharArray(t, length)); for (unsigned i = 0; i < length; ++i) { charArrayBody(t, name, i) = buffer[i]; } @@ -575,19 +575,19 @@ class MyClasspath : public Classpath { } virtual object - makeJMethod(Thread* t, object vmMethod) + makeJMethod(Thread* t, GcMethod* vmMethod) { PROTECT(t, vmMethod); - return byteArrayBody(t, methodName(t, vmMethod), 0) == '<' - ? makeJconstructor(t, vmMethod) - : makeJmethod(t, vmMethod); + return byteArrayBody(t, vmMethod->name(), 0) == '<' + ? reinterpret_cast(makeJconstructor(t, reinterpret_cast(vmMethod))) + : reinterpret_cast(makeJmethod(t, reinterpret_cast(vmMethod))); } virtual object getVMMethod(Thread* t, object jmethod) { - return objectClass(t, jmethod) == type(t, Machine::JmethodType) + return objectClass(t, jmethod) == type(t, GcJmethod::Type) ? arrayBody (t, classMethodTable (t, jclassVmClass(t, jmethodClazz(t, jmethod))), @@ -637,27 +637,27 @@ class MyClasspath : public Classpath { t->exception = 0; t->m->processor->invoke - (t, root(t, Machine::ThreadTerminated), + (t, cast(t, root(t, Machine::ThreadTerminated)), threadGroup(t, t->javaThread), t->javaThread); t->exception = e; }); - object method = resolveMethod + GcMethod* method = resolveMethod (t, root(t, Machine::BootLoader), "java/lang/Thread", "run", "()V"); t->m->processor->invoke(t, method, t->javaThread); } virtual void - resolveNative(Thread* t, object method) + resolveNative(Thread* t, GcMethod* method) { if (strcmp(reinterpret_cast("sun/font/SunFontManager"), - &byteArrayBody(t, className(t, methodClass(t, method)), 0)) == 0 + &byteArrayBody(t, className(t, method->class_()), 0)) == 0 and strcmp(reinterpret_cast("initIDs"), - &byteArrayBody(t, methodName(t, method), 0)) == 0 + &byteArrayBody(t, method->name(), 0)) == 0 and strcmp(reinterpret_cast("()V"), - &byteArrayBody(t, methodSpec(t, method), 0)) == 0) + &byteArrayBody(t, method->spec(), 0)) == 0) { PROTECT(t, method); @@ -692,11 +692,11 @@ class MyClasspath : public Classpath { globalMachine = t->m; resolveSystemClass(t, root(t, Machine::BootLoader), - className(t, type(t, Machine::ClassLoaderType))); + type(t, GcClassLoader::Type)->name()); - setRoot(t, Machine::ThreadTerminated, resolveMethod + setRoot(t, Machine::ThreadTerminated, reinterpret_cast(resolveMethod (t, root(t, Machine::BootLoader), "java/lang/ThreadGroup", - "threadTerminated", "(Ljava/lang/Thread;)V")); + "threadTerminated", "(Ljava/lang/Thread;)V"))); #ifdef AVIAN_OPENJDK_SRC interceptFileOperations(t, true); @@ -706,16 +706,16 @@ class MyClasspath : public Classpath { #endif // not AVIAN_OPENJDK_SRC { object assertionLock = resolveField - (t, type(t, Machine::ClassLoaderType), "assertionLock", + (t, type(t, GcClassLoader::Type), "assertionLock", "Ljava/lang/Object;"); set(t, root(t, Machine::BootLoader), fieldOffset(t, assertionLock), root(t, Machine::BootLoader)); } - { object class_ = resolveClass + { GcClass* class_ = resolveClass (t, root(t, Machine::BootLoader), "java/util/Properties", true, - Machine::NoClassDefFoundErrorType); + GcNoClassDefFoundError::Type); PROTECT(t, class_); @@ -723,7 +723,7 @@ class MyClasspath : public Classpath { PROTECT(t, instance); - object constructor = resolveMethod(t, class_, "", "()V"); + GcMethod* constructor = resolveMethod(t, class_, "", "()V"); t->m->processor->invoke(t, constructor, instance); @@ -732,8 +732,8 @@ class MyClasspath : public Classpath { "setProperties", "(Ljava/util/Properties;)V", 0, instance); } - { object constructor = resolveMethod - (t, type(t, Machine::ClassLoaderType), "", + { GcMethod* constructor = resolveMethod + (t, type(t, GcClassLoader::Type), "", "(Ljava/lang/ClassLoader;)V"); PROTECT(t, constructor); @@ -746,18 +746,18 @@ class MyClasspath : public Classpath { } { object scl = resolveField - (t, type(t, Machine::ClassLoaderType), "scl", + (t, type(t, GcClassLoader::Type), "scl", "Ljava/lang/ClassLoader;"); PROTECT(t, scl); object sclSet = resolveField - (t, type(t, Machine::ClassLoaderType), "sclSet", "Z"); + (t, type(t, GcClassLoader::Type), "sclSet", "Z"); - set(t, classStaticTable(t, type(t, Machine::ClassLoaderType)), + set(t, type(t, GcClassLoader::Type)->staticTable(), fieldOffset(t, scl), root(t, Machine::AppLoader)); - fieldAtOffset(classStaticTable(t, type(t, Machine::ClassLoaderType)), + fieldAtOffset(type(t, GcClassLoader::Type)->staticTable(), fieldOffset(t, sclSet)) = true; } @@ -782,14 +782,14 @@ class MyClasspath : public Classpath { virtual object makeDirectByteBuffer(Thread* t, void* p, jlong capacity) { - object c = resolveClass + GcClass* c = resolveClass (t, root(t, Machine::BootLoader), "java/nio/DirectByteBuffer"); PROTECT(t, c); object instance = makeNew(t, c); PROTECT(t, instance); - object constructor = resolveMethod(t, c, "", "(JI)V"); + GcMethod* constructor = resolveMethod(t, c, "", "(JI)V"); t->m->processor->invoke (t, constructor, instance, reinterpret_cast(p), @@ -821,7 +821,7 @@ class MyClasspath : public Classpath { } virtual bool - canTailCall(Thread* t, object, object calleeClassName, + canTailCall(Thread* t, GcMethod*, object calleeClassName, object calleeMethodName, object) { // we can't tail call System.loadLibrary or Runtime.loadLibrary @@ -844,17 +844,17 @@ class MyClasspath : public Classpath { (&byteArrayBody(t, calleeClassName, 0)))); } - virtual object libraryClassLoader(Thread* t, object caller) + virtual object libraryClassLoader(Thread* t, GcMethod* caller) { #ifdef AVIAN_OPENJDK_SRC - return (methodClass(t, caller) == type(t, Machine::ClassLoaderType) + 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, methodClass(t, caller)), 0))) + &byteArrayBody(t, className(t, caller->class_()), 0))) == 0 ? classLoader( t, @@ -862,22 +862,22 @@ class MyClasspath : public Classpath { t->m->processor->invoke( t, resolveMethod(t, - methodClass(t, caller), + cast(t, caller->class_()), "getFromClass", "()Ljava/lang/Class;"), 0))) #endif - : classLoader(t, methodClass(t, caller)); + : classLoader(t, caller->class_()); } virtual void shutDown(Thread* t) { - object c = resolveClass + GcClass* c = resolveClass (t, root(t, Machine::BootLoader), "java/lang/Shutdown", false); if (c) { - object m = findMethodOrNull(t, c, "shutdown", "()V"); + GcMethod* m = findMethodOrNull(t, c, "shutdown", "()V"); if (m) { t->m->processor->invoke(t, m, 0); @@ -1140,17 +1140,17 @@ openFile(Thread* t, object method, uintptr_t* arguments) EmbeddedFile ef(cp, RUNTIME_ARRAY_BODY(p), stringLength(t, path)); if (ef.jar) { if (ef.jarLength == 0 or ef.pathLength == 0) { - throwNew(t, Machine::FileNotFoundExceptionType); + throwNew(t, GcFileNotFoundException::Type); } Finder* finder = getFinder(t, ef.jar, ef.jarLength); if (finder == 0) { - throwNew(t, Machine::FileNotFoundExceptionType); + throwNew(t, GcFileNotFoundException::Type); } System::Region* r = finder->find(ef.path); if (r == 0) { - throwNew(t, Machine::FileNotFoundExceptionType); + throwNew(t, GcFileNotFoundException::Type); } PROTECT(t, this_); @@ -1217,7 +1217,7 @@ readByteFromFile(Thread* t, object method, uintptr_t* arguments) return -1; } } else { - throwNew(t, Machine::IoExceptionType); + throwNew(t, GcIoException::Type); } } else { return intValue @@ -1271,7 +1271,7 @@ readBytesFromFile(Thread* t, object method, uintptr_t* arguments) return length; } else { - throwNew(t, Machine::IoExceptionType); + throwNew(t, GcIoException::Type); } } else { return intValue @@ -1313,7 +1313,7 @@ skipBytesInFile(Thread* t, object method, uintptr_t* arguments) return count; } else { - throwNew(t, Machine::IoExceptionType); + throwNew(t, GcIoException::Type); } } else { return longValue @@ -1345,7 +1345,7 @@ availableBytesInFile(Thread* t, object method, uintptr_t* arguments) return static_cast(regionRegion(t, region))->length() - regionPosition(t, region); } else { - throwNew(t, Machine::IoExceptionType); + throwNew(t, GcIoException::Type); } } else { object r = t->m->processor->invoke @@ -1449,17 +1449,17 @@ openZipFile(Thread* t, object method, uintptr_t* arguments) EmbeddedFile ef(cp, RUNTIME_ARRAY_BODY(p), stringLength(t, path)); if (ef.jar) { if (ef.jarLength == 0 or ef.pathLength == 0) { - throwNew(t, Machine::FileNotFoundExceptionType); + throwNew(t, GcFileNotFoundException::Type); } Finder* finder = getFinder(t, ef.jar, ef.jarLength); if (finder == 0) { - throwNew(t, Machine::FileNotFoundExceptionType); + throwNew(t, GcFileNotFoundException::Type); } System::Region* r = finder->find(ef.path); if (r == 0) { - throwNew(t, Machine::FileNotFoundExceptionType); + throwNew(t, GcFileNotFoundException::Type); } const uint8_t* start = r->start(); @@ -1479,7 +1479,7 @@ openZipFile(Thread* t, object method, uintptr_t* arguments) } } } else { - -- p; + -- p; } } @@ -1832,8 +1832,8 @@ getBootstrapResource(Thread* t, object, uintptr_t* arguments) object name = reinterpret_cast(arguments[0]); PROTECT(t, name); - object m = findMethodOrNull - (t, type(t, Machine::SystemClassLoaderType), + GcMethod* m = findMethodOrNull + (t, type(t, GcSystemClassLoader::Type), "findResource", "(Ljava/lang/String;)Ljava/net/URL;"); if (m) { @@ -1850,8 +1850,8 @@ getBootstrapResources(Thread* t, object, uintptr_t* arguments) object name = reinterpret_cast(arguments[0]); PROTECT(t, name); - object m = findMethodOrNull - (t, type(t, Machine::SystemClassLoaderType), + GcMethod* m = findMethodOrNull + (t, type(t, GcSystemClassLoader::Type), "findResources", "(Ljava/lang/String;)Ljava/util/Enumeration;"); if (m) { @@ -2086,15 +2086,15 @@ interceptFileOperations(Thread* t, bool updateRuntimeData) } } - intercept(t, type(t, Machine::ClassLoaderType), "loadLibrary", + intercept(t, type(t, GcClassLoader::Type), "loadLibrary", "(Ljava/lang/Class;Ljava/lang/String;Z)V", voidPointer(loadLibrary), updateRuntimeData); - intercept(t, type(t, Machine::ClassLoaderType), "getBootstrapResource", + intercept(t, type(t, GcClassLoader::Type), "getBootstrapResource", "(Ljava/lang/String;)Ljava/net/URL;", voidPointer(getBootstrapResource), updateRuntimeData); - intercept(t, type(t, Machine::ClassLoaderType), "getBootstrapResources", + intercept(t, type(t, GcClassLoader::Type), "getBootstrapResources", "(Ljava/lang/String;)Ljava/util/Enumeration;", voidPointer(getBootstrapResources), updateRuntimeData); } @@ -2280,7 +2280,7 @@ makeJmethod(Thread* t, object vmMethod, int index) PROTECT(t, annotationDefault); if (annotationTable or parameterAnnotationTable or annotationDefault) { - object runtimeData = getClassRuntimeData(t, methodClass(t, vmMethod)); + object runtimeData = getClassRuntimeData(t, cast(t, methodClass(t, vmMethod))); set(t, runtimeData, ClassRuntimeDataPool, addendumPool(t, methodAddendum(t, vmMethod))); @@ -2298,12 +2298,12 @@ makeJmethod(Thread* t, object vmMethod, int index) expect(t, index != -1); - object jclass = getJClass(t, methodClass(t, vmMethod)); + object jclass = getJClass(t, cast(t, methodClass(t, vmMethod))); - return makeJmethod + return reinterpret_cast(makeJmethod (t, true, 0, jclass, index, name, returnType, parameterTypes, exceptionTypes, methodFlags(t, vmMethod), signature, 0, annotationTable, - parameterAnnotationTable, annotationDefault, 0, 0, 0); + parameterAnnotationTable, annotationDefault, 0, 0, 0)); } object @@ -2350,7 +2350,7 @@ makeJconstructor(Thread* t, object vmMethod, int index) PROTECT(t, parameterAnnotationTable); if (annotationTable or parameterAnnotationTable) { - object runtimeData = getClassRuntimeData(t, methodClass(t, vmMethod)); + object runtimeData = getClassRuntimeData(t, cast(t, methodClass(t, vmMethod))); set(t, runtimeData, ClassRuntimeDataPool, addendumPool(t, methodAddendum(t, vmMethod))); @@ -2368,12 +2368,12 @@ makeJconstructor(Thread* t, object vmMethod, int index) expect(t, index != -1); - object jclass = getJClass(t, methodClass(t, vmMethod)); + object jclass = getJClass(t, cast(t, methodClass(t, vmMethod))); - return makeJconstructor + return reinterpret_cast(makeJconstructor (t, true, 0, jclass, index, parameterTypes, exceptionTypes, methodFlags (t, vmMethod), signature, 0, annotationTable, parameterAnnotationTable, - 0, 0, 0); + 0, 0, 0)); } object @@ -2387,14 +2387,14 @@ makeJfield(Thread* t, object vmField, int index) (t, fieldName(t, vmField)) - 1)); PROTECT(t, name); - object type = resolveClassBySpec + GcClass* type = resolveClassBySpec (t, classLoader(t, fieldClass(t, vmField)), reinterpret_cast (&byteArrayBody(t, fieldSpec(t, vmField), 0)), byteArrayLength(t, fieldSpec(t, vmField)) - 1); PROTECT(t, type); - type = getJClass(t, type); + object jtype = getJClass(t, type); object signature; object annotationTable; @@ -2418,7 +2418,7 @@ makeJfield(Thread* t, object vmField, int index) PROTECT(t, annotationTable); if (annotationTable) { - object runtimeData = getClassRuntimeData(t, fieldClass(t, vmField)); + object runtimeData = getClassRuntimeData(t, cast(t, fieldClass(t, vmField))); set(t, runtimeData, ClassRuntimeDataPool, addendumPool(t, fieldAddendum(t, vmField))); @@ -2436,15 +2436,15 @@ makeJfield(Thread* t, object vmField, int index) expect(t, index != -1); - object jclass = getJClass(t, fieldClass(t, vmField)); + object jclass = getJClass(t, cast(t, fieldClass(t, vmField))); - return makeJfield - (t, true, 0, jclass, index, name, type, fieldFlags - (t, vmField), signature, 0, annotationTable, 0, 0, 0, 0); + return reinterpret_cast(makeJfield + (t, true, 0, jclass, index, name, jtype, fieldFlags + (t, vmField), signature, 0, annotationTable, 0, 0, 0, 0)); } void -setProperty(Thread* t, object method, object properties, +setProperty(Thread* t, GcMethod* method, object properties, const char* name, const void* value, const char* format = "%s") { PROTECT(t, method); @@ -2508,7 +2508,7 @@ Avian_java_lang_Class_getSuperclass return 0; } else { object super = classSuper(t, class_); - return super ? reinterpret_cast(getJClass(t, super)) : 0; + return super ? reinterpret_cast(getJClass(t, cast(t, super))) : 0; } } @@ -2563,14 +2563,14 @@ Avian_sun_misc_Unsafe_defineClass__Ljava_lang_String_2_3BIILjava_lang_ClassLoade memcpy(buffer, &byteArrayBody(t, data, offset), length); return reinterpret_cast - (getJClass(t, defineClass(t, loader, buffer, length))); + (getJClass(t, cast(t, defineClass(t, loader, buffer, length)))); } extern "C" AVIAN_EXPORT int64_t Avian_sun_misc_Unsafe_allocateInstance (Thread* t, object, uintptr_t* arguments) { - object c = jclassVmClass(t, reinterpret_cast(arguments[1])); + GcClass* c = cast(t, jclassVmClass(t, reinterpret_cast(arguments[1]))); PROTECT(t, c); initClass(t, c); @@ -2774,7 +2774,7 @@ extern "C" AVIAN_EXPORT void JNICALL Avian_sun_misc_Unsafe_ensureClassInitialized (Thread* t, object, uintptr_t* arguments) { - initClass(t, jclassVmClass(t, reinterpret_cast(arguments[1]))); + initClass(t, cast(t, jclassVmClass(t, reinterpret_cast(arguments[1])))); } extern "C" AVIAN_EXPORT void JNICALL @@ -2942,7 +2942,7 @@ jvmInitProperties(Thread* t, uintptr_t* arguments) { jobject properties = reinterpret_cast(arguments[0]); - object method = resolveMethod + GcMethod* method = resolveMethod (t, root(t, Machine::BootLoader), "java/util/Properties", "setProperty", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;"); @@ -3321,7 +3321,7 @@ jvmSleep(Thread* t, uintptr_t* arguments) } if (threadSleepLock(t, t->javaThread) == 0) { - object lock = makeJobject(t); + object lock = reinterpret_cast(makeJobject(t)); set(t, t->javaThread, ThreadSleepLock, lock); } @@ -3413,9 +3413,9 @@ jvmDumpThreads(Thread* t, uintptr_t* arguments) jobjectArray threads = reinterpret_cast(arguments[0]); unsigned threadsLength = objectArrayLength(t, *threads); - object arrayClass = resolveObjectArrayClass - (t, classLoader(t, type(t, Machine::StackTraceElementType)), - type(t, Machine::StackTraceElementType)); + GcClass* arrayClass = resolveObjectArrayClass + (t, type(t, GcStackTraceElement::Type)->loader(), + reinterpret_cast(type(t, GcStackTraceElement::Type))); object result = makeObjectArray(t, arrayClass, threadsLength); PROTECT(t, result); @@ -3431,7 +3431,7 @@ jvmDumpThreads(Thread* t, uintptr_t* arguments) unsigned traceLength = objectArrayLength(t, trace); object array = makeObjectArray - (t, type(t, Machine::StackTraceElementType), traceLength); + (t, type(t, GcStackTraceElement::Type), traceLength); PROTECT(t, array); for (unsigned traceIndex = 0; traceIndex < traceLength; ++ traceIndex) { @@ -3474,12 +3474,16 @@ jvmGetClassContext(Thread* t, uintptr_t*) PROTECT(t, trace); object context = makeObjectArray - (t, type(t, Machine::JclassType), objectArrayLength(t, trace)); + (t, type(t, GcJclass::Type), objectArrayLength(t, trace)); PROTECT(t, context); for (unsigned i = 0; i < objectArrayLength(t, trace); ++i) { - object c = getJClass - (t, methodClass(t, traceElementMethod(t, objectArrayBody(t, trace, i)))); + object c = getJClass( + t, + cast( + t, + methodClass(t, + traceElementMethod(t, objectArrayBody(t, trace, i))))); set(t, context, ArrayBody + (i * BytesPerWord), c); } @@ -3509,10 +3513,10 @@ jvmGetSystemPackage(Thread* t, uintptr_t* arguments) THREAD_RUNTIME_ARRAY(t, char, chars, stringLength(t, *s) + 1); stringChars(t, *s, RUNTIME_ARRAY_BODY(chars)); - object key = makeByteArray(t, RUNTIME_ARRAY_BODY(chars)); + object key = reinterpret_cast(makeByteArray(t, RUNTIME_ARRAY_BODY(chars))); object array = hashMapFind - (t, root(t, Machine::PackageMap), key, byteArrayHash, byteArrayEqual); + (t, cast(t, root(t, Machine::PackageMap)), key, byteArrayHash, byteArrayEqual); if (array) { return reinterpret_cast @@ -3535,11 +3539,13 @@ EXPORT(JVM_GetSystemPackage)(Thread* t, jstring s) uint64_t jvmGetSystemPackages(Thread* t, uintptr_t*) { - return reinterpret_cast - (makeLocalReference - (t, makeObjectArray - (t, resolveClass - (t, root(t, Machine::BootLoader), "java/lang/Package"), 0))); + return reinterpret_cast(makeLocalReference( + t, + makeObjectArray( + t, + resolveClass( + t, root(t, Machine::BootLoader), "java/lang/Package"), + 0))); } extern "C" AVIAN_EXPORT jobjectArray JNICALL @@ -3568,11 +3574,11 @@ EXPORT(JVM_LatestUserDefinedLoader)(Thread* t) { } virtual bool visit(Processor::StackWalker* walker) { - object loader = classLoader(t, methodClass(t, walker->method())); + object loader = classLoader(t, walker->method()->class_()); if (loader and loader != root(t, Machine::BootLoader) and strcmp - (&byteArrayBody(t, className(t, objectClass(t, loader)), 0), + (&byteArrayBody(t, objectClass(t, loader)->name(), 0), reinterpret_cast ("sun/reflect/DelegatingClassLoader"))) { @@ -3610,39 +3616,39 @@ jvmGetArrayElement(Thread* t, uintptr_t* arguments) jobject array = reinterpret_cast(arguments[0]); jint index = arguments[1]; - switch (byteArrayBody(t, className(t, objectClass(t, *array)), 1)) { + switch (byteArrayBody(t, objectClass(t, *array)->name(), 1)) { case 'Z': return reinterpret_cast (makeLocalReference - (t, makeBoolean(t, fieldAtOffset(*array, ArrayBody + index)))); + (t, reinterpret_cast(makeBoolean(t, fieldAtOffset(*array, ArrayBody + index))))); case 'B': return reinterpret_cast (makeLocalReference - (t, makeByte(t, fieldAtOffset(*array, ArrayBody + index)))); + (t, reinterpret_cast(makeByte(t, fieldAtOffset(*array, ArrayBody + index))))); case 'C': return reinterpret_cast (makeLocalReference - (t, makeChar(t, fieldAtOffset(*array, ArrayBody + (index * 2))))); + (t, reinterpret_cast(makeChar(t, fieldAtOffset(*array, ArrayBody + (index * 2)))))); case 'S': return reinterpret_cast (makeLocalReference - (t, makeShort(t, fieldAtOffset(*array, ArrayBody + (index * 2))))); + (t, reinterpret_cast(makeShort(t, fieldAtOffset(*array, ArrayBody + (index * 2)))))); case 'I': return reinterpret_cast (makeLocalReference - (t, makeInt(t, fieldAtOffset(*array, ArrayBody + (index * 4))))); + (t, reinterpret_cast(makeInt(t, fieldAtOffset(*array, ArrayBody + (index * 4)))))); case 'F': return reinterpret_cast (makeLocalReference - (t, makeFloat(t, fieldAtOffset(*array, ArrayBody + (index * 4))))); + (t, reinterpret_cast(makeFloat(t, fieldAtOffset(*array, ArrayBody + (index * 4)))))); case 'J': return reinterpret_cast (makeLocalReference - (t, makeLong(t, fieldAtOffset(*array, ArrayBody + (index * 8))))); + (t, reinterpret_cast(makeLong(t, fieldAtOffset(*array, ArrayBody + (index * 8)))))); case 'D': return reinterpret_cast (makeLocalReference - (t, makeDouble(t, fieldAtOffset(*array, ArrayBody + (index * 8))))); + (t, reinterpret_cast(makeDouble(t, fieldAtOffset(*array, ArrayBody + (index * 8)))))); case 'L': case '[': return reinterpret_cast @@ -3671,7 +3677,7 @@ EXPORT(JVM_SetArrayElement)(Thread* t, jobject array, jint index, { ENTER(t, Thread::ActiveState); - switch (byteArrayBody(t, className(t, objectClass(t, *array)), 1)) { + switch (byteArrayBody(t, objectClass(t, *array)->name(), 1)) { case 'Z': fieldAtOffset(*array, ArrayBody + index) = booleanValue(t, *value); break; @@ -3714,25 +3720,25 @@ makeNewArray(Thread* t, object c, unsigned length) { if (classVmFlags(t, c) & PrimitiveFlag) { const char* name = reinterpret_cast - (&byteArrayBody(t, local::getClassName(t, c), 0)); + (&byteArrayBody(t, local::getClassName(t, cast(t, c)), 0)); switch (*name) { case 'b': if (name[1] == 'o') { - return makeBooleanArray(t, length); + return reinterpret_cast(makeBooleanArray(t, length)); } else { - return makeByteArray(t, length); + return reinterpret_cast(makeByteArray(t, length)); } - case 'c': return makeCharArray(t, length); - case 'd': return makeDoubleArray(t, length); - case 'f': return makeFloatArray(t, length); - case 'i': return makeIntArray(t, length); - case 'l': return makeLongArray(t, length); - case 's': return makeShortArray(t, length); + case 'c': return reinterpret_cast(makeCharArray(t, length)); + case 'd': return reinterpret_cast(makeDoubleArray(t, length)); + case 'f': return reinterpret_cast(makeFloatArray(t, length)); + case 'i': return reinterpret_cast(makeIntArray(t, length)); + case 'l': return reinterpret_cast(makeLongArray(t, length)); + case 's': return reinterpret_cast(makeShortArray(t, length)); default: abort(t); } } else { - return makeObjectArray(t, c, length); + return reinterpret_cast(makeObjectArray(t, cast(t, c), length)); } } @@ -3766,7 +3772,7 @@ jvmNewMultiArray(Thread* t, uintptr_t* arguments) for (int i = intArrayLength(t, *dimensions) - 1; i >= 0; --i) { RUNTIME_ARRAY_BODY(counts)[i] = intArrayBody(t, *dimensions, i); if (UNLIKELY(RUNTIME_ARRAY_BODY(counts)[i] < 0)) { - throwNew(t, Machine::NegativeArraySizeExceptionType, "%d", + throwNew(t, GcNegativeArraySizeException::Type, "%d", RUNTIME_ARRAY_BODY(counts)[i]); return 0; } @@ -3797,10 +3803,10 @@ EXPORT(JVM_GetCallerClass)(Thread* t, int target) { ENTER(t, Thread::ActiveState); - object method = getCaller(t, target, true); + GcMethod* method = getCaller(t, target, true); return method ? makeLocalReference - (t, getJClass(t, methodClass(t, method))) : 0; + (t, getJClass(t, cast(t, method->class_()))) : 0; } extern "C" AVIAN_EXPORT jclass JNICALL @@ -3812,34 +3818,34 @@ EXPORT(JVM_FindPrimitiveClass)(Thread* t, const char* name) case 'b': if (name[1] == 'o') { return makeLocalReference - (t, getJClass(t, type(t, Machine::JbooleanType))); + (t, getJClass(t, type(t, GcJboolean::Type))); } else { return makeLocalReference - (t, getJClass(t, type(t, Machine::JbyteType))); + (t, getJClass(t, type(t, GcJbyte::Type))); } case 'c': return makeLocalReference - (t, getJClass(t, type(t, Machine::JcharType))); + (t, getJClass(t, type(t, GcJchar::Type))); case 'd': return makeLocalReference - (t, getJClass(t, type(t, Machine::JdoubleType))); + (t, getJClass(t, type(t, GcJdouble::Type))); case 'f': return makeLocalReference - (t, getJClass(t, type(t, Machine::JfloatType))); + (t, getJClass(t, type(t, GcJfloat::Type))); case 'i': return makeLocalReference - (t, getJClass(t, type(t, Machine::JintType))); + (t, getJClass(t, type(t, GcJint::Type))); case 'l': return makeLocalReference - (t, getJClass(t, type(t, Machine::JlongType))); + (t, getJClass(t, type(t, GcJlong::Type))); case 's': return makeLocalReference - (t, getJClass(t, type(t, Machine::JshortType))); + (t, getJClass(t, type(t, GcJshort::Type))); case 'v': return makeLocalReference - (t, getJClass(t, type(t, Machine::JvoidType))); + (t, getJClass(t, type(t, GcJvoid::Type))); default: - throwNew(t, Machine::IllegalArgumentExceptionType); + throwNew(t, GcIllegalArgumentException::Type); } } @@ -3848,7 +3854,7 @@ jvmResolveClass(Thread* t, uintptr_t* arguments) { jclass c = reinterpret_cast(arguments[0]); - object method = resolveMethod + GcMethod* method = resolveMethod (t, root(t, Machine::BootLoader), "avian/Classes", "link", "(Lavian/VMClass;)V"); @@ -3873,10 +3879,10 @@ jvmFindClassFromClassLoader(Thread* t, uintptr_t* arguments) jobject loader = reinterpret_cast(arguments[2]); jboolean throwError = arguments[3]; - object c = resolveClass + GcClass* c = resolveClass (t, loader ? *loader : root(t, Machine::BootLoader), name, true, - throwError ? Machine::NoClassDefFoundErrorType - : Machine::ClassNotFoundExceptionType); + throwError ? static_cast(GcNoClassDefFoundError::Type) + : static_cast(GcClassNotFoundException::Type)); if (init) { PROTECT(t, c); @@ -3917,14 +3923,14 @@ jvmFindLoadedClass(Thread* t, uintptr_t* arguments) jobject loader = reinterpret_cast(arguments[0]); jstring name = reinterpret_cast(arguments[1]); - object spec = makeByteArray(t, stringLength(t, *name) + 1); + object spec = reinterpret_cast(makeByteArray(t, stringLength(t, *name) + 1)); { char* s = reinterpret_cast(&byteArrayBody(t, spec, 0)); stringChars(t, *name, s); replace('.', '/', s); } - object c = findLoadedClass(t, *loader, spec); + GcClass* c = findLoadedClass(t, *loader, spec); return reinterpret_cast (c ? makeLocalReference(t, getJClass(t, c)) : 0); @@ -3948,7 +3954,7 @@ jvmDefineClass(Thread* t, uintptr_t* arguments) return reinterpret_cast (makeLocalReference - (t, getJClass(t, defineClass(t, *loader, data, length)))); + (t, getJClass(t, cast(t, defineClass(t, *loader, data, length))))); } extern "C" AVIAN_EXPORT jclass JNICALL @@ -3998,11 +4004,11 @@ jvmGetClassInterfaces(Thread* t, uintptr_t* arguments) PROTECT(t, table); object array = makeObjectArray - (t, type(t, Machine::JclassType), arrayLength(t, table)); + (t, type(t, GcJclass::Type), arrayLength(t, table)); PROTECT(t, array); for (unsigned i = 0; i < arrayLength(t, table); ++i) { - object c = getJClass(t, arrayBody(t, table, i)); + object c = getJClass(t, cast(t, arrayBody(t, table, i))); set(t, array, ArrayBody + (i * BytesPerWord), c); } @@ -4012,7 +4018,7 @@ jvmGetClassInterfaces(Thread* t, uintptr_t* arguments) return reinterpret_cast (makeLocalReference - (t, makeObjectArray(t, type(t, Machine::JclassType), 0))); + (t, makeObjectArray(t, type(t, GcJclass::Type), 0))); } extern "C" AVIAN_EXPORT jobjectArray JNICALL @@ -4034,10 +4040,10 @@ EXPORT(JVM_GetClassLoader)(Thread* t, jclass c) // sun.misc.Unsafe.getUnsafe expects a null result if the class // loader is the boot classloader and will throw a // SecurityException otherwise. - object caller = getCaller(t, 2); + GcMethod* caller = getCaller(t, 2); if (caller and strcmp (reinterpret_cast - (&byteArrayBody(t, className(t, methodClass(t, caller)), 0)), + (&byteArrayBody(t, className(t, caller->class_()), 0)), "sun/misc/Unsafe") == 0) { return 0; @@ -4091,7 +4097,7 @@ EXPORT(JVM_SetClassSigners)(Thread* t, jclass c, jobjectArray signers) { ENTER(t, Thread::ActiveState); - object runtimeData = getClassRuntimeData(t, jclassVmClass(t, *c)); + object runtimeData = getClassRuntimeData(t, cast(t, jclassVmClass(t, *c))); set(t, runtimeData, ClassRuntimeDataSigners, *signers); } @@ -4101,7 +4107,7 @@ jvmGetProtectionDomain(Thread* t, uintptr_t* arguments) { jclass c = reinterpret_cast(arguments[0]); - object method = resolveMethod + GcMethod* method = resolveMethod (t, root(t, Machine::BootLoader), "avian/Classes", "getProtectionDomain", "(Lavian/VMClass;)Ljava/security/ProtectionDomain;"); @@ -4150,7 +4156,7 @@ jvmGetComponentType(Thread* t, uintptr_t* arguments) } else { return reinterpret_cast (makeLocalReference - (t, getJClass(t, classStaticTable(t, jclassVmClass(t, *c))))); + (t, getJClass(t, cast(t, classStaticTable(t, jclassVmClass(t, *c)))))); } } else { return 0; @@ -4261,7 +4267,7 @@ jvmGetClassDeclaredMethods(Thread* t, uintptr_t* arguments) PROTECT(t, table); object array = makeObjectArray - (t, type(t, Machine::JmethodType), + (t, type(t, GcJmethod::Type), local::countMethods(t, jclassVmClass(t, *c), publicOnly)); PROTECT(t, array); @@ -4287,7 +4293,7 @@ jvmGetClassDeclaredMethods(Thread* t, uintptr_t* arguments) } else { return reinterpret_cast (makeLocalReference - (t, makeObjectArray(t, type(t, Machine::JmethodType), 0))); + (t, makeObjectArray(t, type(t, GcJmethod::Type), 0))); } } @@ -4310,7 +4316,7 @@ jvmGetClassDeclaredFields(Thread* t, uintptr_t* arguments) PROTECT(t, table); object array = makeObjectArray - (t, type(t, Machine::JfieldType), + (t, type(t, GcJfield::Type), local::countFields(t, jclassVmClass(t, *c), publicOnly)); PROTECT(t, array); @@ -4333,7 +4339,7 @@ jvmGetClassDeclaredFields(Thread* t, uintptr_t* arguments) } else { return reinterpret_cast (makeLocalReference - (t, makeObjectArray(t, type(t, Machine::JfieldType), 0))); + (t, makeObjectArray(t, type(t, GcJfield::Type), 0))); } } @@ -4357,7 +4363,7 @@ jvmGetClassDeclaredConstructors(Thread* t, uintptr_t* arguments) PROTECT(t, table); object array = makeObjectArray - (t, type(t, Machine::JconstructorType), + (t, type(t, GcJconstructor::Type), local::countConstructors(t, jclassVmClass(t, *c), publicOnly)); PROTECT(t, array); @@ -4385,7 +4391,7 @@ jvmGetClassDeclaredConstructors(Thread* t, uintptr_t* arguments) } else { return reinterpret_cast (makeLocalReference - (t, makeObjectArray(t, type(t, Machine::JconstructorType), 0))); + (t, makeObjectArray(t, type(t, GcJconstructor::Type), 0))); } } @@ -4414,17 +4420,17 @@ jvmInvokeMethod(Thread* t, uintptr_t* arguments) jobject instance = reinterpret_cast(arguments[1]); jobjectArray args = reinterpret_cast(arguments[2]); - object vmMethod = arrayBody + GcMethod* vmMethod = cast(t, arrayBody (t, classMethodTable (t, jclassVmClass(t, jmethodClazz(t, *method))), - jmethodSlot(t, *method)); + jmethodSlot(t, *method))); - if (methodFlags(t, vmMethod) & ACC_STATIC) { + if (vmMethod->flags() & ACC_STATIC) { instance = 0; } - if (instance and not instanceOf(t, methodClass(t, vmMethod), *instance)) { - throwNew(t, Machine::IllegalArgumentExceptionType); + if (instance and not instanceOf(t, cast(t, vmMethod->class_()), *instance)) { + throwNew(t, GcIllegalArgumentException::Type); } return reinterpret_cast @@ -4451,13 +4457,13 @@ jvmNewInstanceFromConstructor(Thread* t, uintptr_t* arguments) jobjectArray args = reinterpret_cast(arguments[1]); object instance = make - (t, jclassVmClass(t, jconstructorClazz(t, *constructor))); + (t, cast(t, jclassVmClass(t, jconstructorClazz(t, *constructor)))); PROTECT(t, instance); - object method = arrayBody + GcMethod* method = cast(t, arrayBody (t, classMethodTable (t, jclassVmClass(t, jconstructorClazz(t, *constructor))), - jconstructorSlot(t, *constructor)); + jconstructorSlot(t, *constructor))); invoke(t, method, instance, args ? *args : 0); @@ -4490,10 +4496,10 @@ EXPORT(JVM_GetClassConstantPool)(Thread* t, jclass c) } if (pool == 0) { - pool = classRuntimeDataPool(t, getClassRuntimeData(t, vmClass)); + pool = classRuntimeDataPool(t, getClassRuntimeData(t, cast(t, vmClass))); } - return makeLocalReference(t, makeConstantPool(t, pool)); + return makeLocalReference(t, reinterpret_cast(makeConstantPool(t, pool))); } extern "C" AVIAN_EXPORT jint JNICALL @@ -4503,7 +4509,7 @@ EXPORT(JVM_ConstantPoolGetSize)(Thread* t, jobject, jobject pool) ENTER(t, Thread::ActiveState); - return singletonCount(t, *pool); + return singletonCount(t, cast(t, *pool)); } extern "C" AVIAN_EXPORT jclass JNICALL @@ -4539,7 +4545,7 @@ EXPORT(JVM_ConstantPoolGetIntAt)(Thread* t, jobject, jobject pool, jint index) { ENTER(t, Thread::ActiveState); - return singletonValue(t, *pool, index - 1); + return singletonValue(t, cast(t, *pool), index - 1); } extern "C" AVIAN_EXPORT jlong JNICALL @@ -4548,7 +4554,7 @@ EXPORT(JVM_ConstantPoolGetLongAt)(Thread* t, jobject, jobject pool, jint index) ENTER(t, Thread::ActiveState); uint64_t v; - memcpy(&v, &singletonValue(t, *pool, index - 1), 8); + memcpy(&v, &singletonValue(t, cast(t, *pool), index - 1), 8); return v; } @@ -4559,7 +4565,7 @@ EXPORT(JVM_ConstantPoolGetFloatAt)(Thread* t, jobject, jobject pool, { ENTER(t, Thread::ActiveState); - return bitsToFloat(singletonValue(t, *pool, index - 1)); + return bitsToFloat(singletonValue(t, cast(t, *pool), index - 1)); } extern "C" AVIAN_EXPORT jdouble JNICALL @@ -4569,7 +4575,7 @@ EXPORT(JVM_ConstantPoolGetDoubleAt)(Thread* t, jobject, jobject pool, ENTER(t, Thread::ActiveState); double v; - memcpy(&v, &singletonValue(t, *pool, index - 1), 8); + memcpy(&v, &singletonValue(t, cast(t, *pool), index - 1), 8); return v; } @@ -4584,7 +4590,7 @@ jvmConstantPoolGetUTF8At(Thread* t, uintptr_t* arguments) jobject pool = reinterpret_cast(arguments[0]); jint index = arguments[1]; - object array = parseUtf8(t, singletonObject(t, *pool, index - 1)); + object array = parseUtf8(t, singletonObject(t, cast(t, *pool), index - 1)); return reinterpret_cast (makeLocalReference @@ -4607,21 +4613,21 @@ maybeWrap(Thread* t, bool wrapException) { if (t->exception and wrapException - and not (instanceOf(t, type(t, Machine::ErrorType), t->exception) + and not (instanceOf(t, type(t, GcError::Type), t->exception) or instanceOf - (t, type(t, Machine::RuntimeExceptionType), t->exception))) + (t, type(t, GcRuntimeException::Type), t->exception))) { object exception = t->exception; t->exception = 0; PROTECT(t, exception); - object paeClass = resolveClass + GcClass* paeClass = resolveClass (t, root(t, Machine::BootLoader), "java/security/PrivilegedActionException"); PROTECT(t, paeClass); - object paeConstructor = resolveMethod + GcMethod* paeConstructor = resolveMethod (t, paeClass, "", "(Ljava/lang/Exception;)V"); PROTECT(t, paeConstructor); @@ -4643,15 +4649,15 @@ jvmDoPrivileged(Thread* t, uintptr_t* arguments) // todo: cache these class and method lookups in the t->m->classpath // object: - object privilegedAction = resolveClass + GcClass* privilegedAction = resolveClass (t, root(t, Machine::BootLoader), "java/security/PrivilegedAction"); - object method; + GcMethod* method; if (instanceOf(t, privilegedAction, *action)) { method = resolveMethod (t, privilegedAction, "run", "()Ljava/lang/Object;"); } else { - object privilegedExceptionAction = resolveClass + GcClass* privilegedExceptionAction = resolveClass (t, root(t, Machine::BootLoader), "java/security/PrivilegedExceptionAction"); @@ -5121,7 +5127,7 @@ uint64_t getInputArgumentArray(Thread* t, uintptr_t*) { object array = makeObjectArray - (t, type(t, Machine::StringType), t->m->argumentCount); + (t, type(t, GcString::Type), t->m->argumentCount); PROTECT(t, array); for (unsigned i = 0; i < t->m->argumentCount; ++i) { @@ -5178,12 +5184,13 @@ GetBoolAttribute(Thread* t, jmmBoolAttribute attribute) uint64_t getMemoryManagers(Thread* t, uintptr_t*) { - return reinterpret_cast - (makeLocalReference - (t, makeObjectArray - (t, resolveClass - (t, root(t, Machine::BootLoader), - "java/lang/management/MemoryManagerMXBean"), 0))); + return reinterpret_cast(makeLocalReference( + t, + makeObjectArray(t, + resolveClass(t, + root(t, Machine::BootLoader), + "java/lang/management/MemoryManagerMXBean"), + 0))); } jobjectArray JNICALL @@ -5195,12 +5202,13 @@ GetMemoryManagers(Thread* t, jobject) uint64_t getMemoryPools(Thread* t, uintptr_t*) { - return reinterpret_cast - (makeLocalReference - (t, makeObjectArray - (t, resolveClass - (t, root(t, Machine::BootLoader), - "java/lang/management/MemoryPoolMXBean"), 0))); + return reinterpret_cast(makeLocalReference( + t, + makeObjectArray(t, + resolveClass(t, + root(t, Machine::BootLoader), + "java/lang/management/MemoryPoolMXBean"), + 0))); } jobjectArray JNICALL @@ -5249,12 +5257,12 @@ getEnclosingMethodInfo(Thread* t, uintptr_t* arguments) if (enclosingClass) { PROTECT(t, enclosingClass); - object array = makeObjectArray(t, type(t, Machine::JobjectType), 3); + object array = makeObjectArray(t, type(t, GcJobject::Type), 3); PROTECT(t, array); enclosingClass = getJClass (t, resolveClass(t, classLoader(t, class_), enclosingClass)); - + set(t, array, ArrayBody, enclosingClass); object enclosingMethod = classAddendumEnclosingMethod(t, addendum); diff --git a/src/codegen/compiler/resource.cpp b/src/codegen/compiler/resource.cpp index d47ad1ff11..674db90333 100644 --- a/src/codegen/compiler/resource.cpp +++ b/src/codegen/compiler/resource.cpp @@ -223,4 +223,4 @@ void release(Context* c, Resource* resource, Value* value UNUSED, Site* site UNU } // namespace compiler } // namespace codegen -} // namespace avian \ No newline at end of file +} // namespace avian diff --git a/src/compile.cpp b/src/compile.cpp index e81323a2b0..578af74148 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -120,13 +120,13 @@ class MyThread: public Thread { public: class CallTrace { public: - CallTrace(MyThread* t, object method): + CallTrace(MyThread* t, GcMethod* method): t(t), ip(getIp(t)), stack(t->stack), scratch(t->scratch), continuation(t->continuation), - nativeMethod((methodFlags(t, method) & ACC_NATIVE) ? method : 0), + nativeMethod((method->flags() & ACC_NATIVE) ? method : 0), targetMethod(0), originalMethod(method), next(t->trace) @@ -147,9 +147,9 @@ class MyThread: public Thread { void* stack; void* scratch; object continuation; - object nativeMethod; - object targetMethod; - object originalMethod; + GcMethod* nativeMethod; + GcMethod* targetMethod; + GcMethod* originalMethod; CallTrace* next; }; @@ -314,48 +314,48 @@ resolveThisPointer(MyThread* t, void* stack) [t->arch->frameFooterSize() + t->arch->frameReturnAddressSize()]; } -object -findMethod(Thread* t, object method, object instance) +GcMethod* +findMethod(Thread* t, GcMethod* method, object instance) { - if ((methodFlags(t, method) & ACC_STATIC) == 0) { - if (classFlags(t, methodClass(t, method)) & ACC_INTERFACE) { + if ((method->flags() & ACC_STATIC) == 0) { + if (classFlags(t, method->class_()) & ACC_INTERFACE) { return findInterfaceMethod(t, method, objectClass(t, instance)); } else if (methodVirtual(t, method)) { - return findVirtualMethod(t, method, objectClass(t, instance)); + return findVirtualMethod(t, method, objectClass(t, instance)); } } return method; } -object -resolveTarget(MyThread* t, void* stack, object method) +GcMethod* +resolveTarget(MyThread* t, void* stack, GcMethod* method) { - object class_ = objectClass(t, resolveThisPointer(t, stack)); + GcClass* class_ = objectClass(t, resolveThisPointer(t, stack)); - if (classVmFlags(t, class_) & BootstrapFlag) { + if (class_->vmFlags() & BootstrapFlag) { PROTECT(t, method); PROTECT(t, class_); - resolveSystemClass(t, root(t, Machine::BootLoader), className(t, class_)); + resolveSystemClass(t, root(t, Machine::BootLoader), class_->name()); } - if (classFlags(t, methodClass(t, method)) & ACC_INTERFACE) { + if (classFlags(t, method->class_()) & ACC_INTERFACE) { return findInterfaceMethod(t, method, class_); } else { return findVirtualMethod(t, method, class_); } } -object -resolveTarget(MyThread* t, object class_, unsigned index) +GcMethod* +resolveTarget(MyThread* t, GcClass* class_, unsigned index) { - if (classVmFlags(t, class_) & BootstrapFlag) { + if (class_->vmFlags() & BootstrapFlag) { PROTECT(t, class_); - resolveSystemClass(t, root(t, Machine::BootLoader), className(t, class_)); + resolveSystemClass(t, root(t, Machine::BootLoader), class_->name()); } - return arrayBody(t, classVirtualTable(t, class_), index); + return cast(t, arrayBody(t, class_->virtualTable(), index)); } object& @@ -365,20 +365,21 @@ void setRoot(Thread* t, Root root, object value); intptr_t -methodCompiled(Thread* t, object method) +methodCompiled(Thread* t, GcMethod* method) { - return codeCompiled(t, methodCode(t, method)); + return codeCompiled(t, method->code()); } unsigned -methodCompiledSize(Thread* t, object method) +methodCompiledSize(Thread* t, GcMethod* method) { - return codeCompiledSize(t, methodCode(t, method)); + return codeCompiledSize(t, method->code()); } intptr_t -compareIpToMethodBounds(Thread* t, intptr_t ip, object method) +compareIpToMethodBounds(Thread* t, intptr_t ip, object om) { + GcMethod* method = cast(t, om); intptr_t start = methodCompiled(t, method); if (DebugMethodTree) { @@ -399,7 +400,7 @@ compareIpToMethodBounds(Thread* t, intptr_t ip, object method) } } -object +GcMethod* methodForIp(MyThread* t, void* ip) { if (DebugMethodTree) { @@ -411,15 +412,15 @@ methodForIp(MyThread* t, void* ip) // compile(MyThread*, FixedAllocator*, BootContext*, object)): loadMemoryBarrier(); - return treeQuery(t, root(t, MethodTree), reinterpret_cast(ip), - root(t, MethodTreeSentinal), compareIpToMethodBounds); + return cast(t, treeQuery(t, root(t, MethodTree), reinterpret_cast(ip), + root(t, MethodTreeSentinal), compareIpToMethodBounds)); } unsigned -localSize(MyThread* t, object method) +localSize(MyThread* t, GcMethod* method) { - unsigned size = codeMaxLocals(t, methodCode(t, method)); - if ((methodFlags(t, method) & (ACC_SYNCHRONIZED | ACC_STATIC)) + unsigned size = codeMaxLocals(t, method->code()); + if ((method->flags() & (ACC_SYNCHRONIZED | ACC_STATIC)) == ACC_SYNCHRONIZED) { ++ size; @@ -428,20 +429,20 @@ localSize(MyThread* t, object method) } unsigned -alignedFrameSize(MyThread* t, object method) +alignedFrameSize(MyThread* t, GcMethod* method) { return t->arch->alignFrameSize (localSize(t, method) - - methodParameterFootprint(t, method) - + codeMaxStack(t, methodCode(t, method)) + - method->parameterFootprint() + + codeMaxStack(t, method->code()) + t->arch->frameFootprint(MaxNativeCallFootprint)); } void -nextFrame(MyThread* t, void** ip, void** sp, object method, object target, +nextFrame(MyThread* t, void** ip, void** sp, GcMethod* method, GcMethod* target, bool mostRecent) { - object code = methodCode(t, method); + object code = method->code(); intptr_t start = codeCompiled(t, code); void* link; bool methodIsMostRecent; @@ -455,11 +456,11 @@ nextFrame(MyThread* t, void** ip, void** sp, object method, object target, } // fprintf(stderr, "nextFrame %s.%s%s target %s.%s%s ip %p sp %p\n", - // &byteArrayBody(t, className(t, methodClass(t, method)), 0), - // &byteArrayBody(t, methodName(t, method), 0), - // &byteArrayBody(t, methodSpec(t, method), 0), + // &byteArrayBody(t, className(t, method->class_()), 0), + // &byteArrayBody(t, method->name(), 0), + // &byteArrayBody(t, method->spec(), 0), // target - // ? &byteArrayBody(t, className(t, methodClass(t, target)), 0) + // ? &byteArrayBody(t, className(t, target->class_()), 0) // : 0, // target // ? &byteArrayBody(t, methodName(t, target), 0) @@ -472,7 +473,7 @@ nextFrame(MyThread* t, void** ip, void** sp, object method, object target, t->arch->nextFrame (reinterpret_cast(start), codeCompiledSize(t, code), alignedFrameSize(t, method), link, methodIsMostRecent, - target ? methodParameterFootprint(t, target) : -1, ip, sp); + target ? target->parameterFootprint() : -1, ip, sp); // fprintf(stderr, "next frame ip %p sp %p\n", *ip, *sp); } @@ -538,7 +539,7 @@ class MyStackWalker: public Processor::StackWalker { ip_ = getIp(t); stack = t->stack; trace = t->trace; - continuation = t->continuation; + continuation = t->continuation; } } @@ -564,7 +565,7 @@ class MyStackWalker: public Processor::StackWalker { it.next(); } } - + bool valid() { while (true) { // fprintf(stderr, "state: %d\n", state); @@ -585,7 +586,7 @@ class MyStackWalker: public Processor::StackWalker { if (method_) { state = Method; } else if (continuation) { - method_ = continuationMethod(t, continuation); + method_ = cast(t, continuationMethod(t, continuation)); state = Continuation; } else { state = Trace; @@ -615,13 +616,13 @@ class MyStackWalker: public Processor::StackWalker { case Finish: return false; - + default: abort(t); } } } - + void next() { expect(t, count_ <= stackSizeInWords(t)); @@ -636,7 +637,7 @@ class MyStackWalker: public Processor::StackWalker { case NativeMethod: break; - + default: abort(t); } @@ -646,7 +647,7 @@ class MyStackWalker: public Processor::StackWalker { state = Next; } - virtual object method() { + virtual GcMethod* method() { // fprintf(stderr, "method %s.%s\n", &byteArrayBody // (t, className(t, methodClass(t, method_)), 0), // &byteArrayBody(t, methodName(t, method_), 0)); @@ -657,11 +658,11 @@ class MyStackWalker: public Processor::StackWalker { switch (state) { case Continuation: return reinterpret_cast(continuationAddress(t, continuation)) - - methodCompiled(t, continuationMethod(t, continuation)); + - methodCompiled(t, cast(t, continuationMethod(t, continuation))); case Method: return reinterpret_cast(ip_) - methodCompiled(t, method_); - + case NativeMethod: return 0; @@ -677,7 +678,7 @@ class MyStackWalker: public Processor::StackWalker { walker.next(); ++ count; } - + return count; } @@ -686,17 +687,17 @@ class MyStackWalker: public Processor::StackWalker { void* ip_; void* stack; MyThread::CallTrace* trace; - object method_; - object target; + GcMethod* method_; + GcMethod* target; object continuation; unsigned count_; MyProtector protector; }; int -localOffset(MyThread* t, int v, object method) +localOffset(MyThread* t, int v, GcMethod* method) { - int parameterFootprint = methodParameterFootprint(t, method); + int parameterFootprint = method->parameterFootprint(); int frameSize = alignedFrameSize(t, method); int offset = ((v < parameterFootprint) ? @@ -714,26 +715,26 @@ localOffset(MyThread* t, int v, object method) } int -localOffsetFromStack(MyThread* t, int index, object method) +localOffsetFromStack(MyThread* t, int index, GcMethod* method) { return localOffset(t, index, method) + t->arch->frameReturnAddressSize(); } object* -localObject(MyThread* t, void* stack, object method, unsigned index) +localObject(MyThread* t, void* stack, GcMethod* method, unsigned index) { return static_cast(stack) + localOffsetFromStack(t, index, method); } int -stackOffsetFromFrame(MyThread* t, object method) +stackOffsetFromFrame(MyThread* t, GcMethod* method) { return alignedFrameSize(t, method) + t->arch->frameHeaderSize(); } void* -stackForFrame(MyThread* t, void* frame, object method) +stackForFrame(MyThread* t, void* frame, GcMethod* method) { return static_cast(frame) - stackOffsetFromFrame(t, method); } @@ -799,7 +800,7 @@ class TraceElement: public avian::codegen::TraceHandler { static const unsigned TailCall = 1 << 1; static const unsigned LongCall = 1 << 2; - TraceElement(Context* context, unsigned ip, object target, unsigned flags, + TraceElement(Context* context, unsigned ip, GcMethod* target, unsigned flags, TraceElement* next, unsigned mapSize): context(context), address(0), @@ -823,7 +824,7 @@ class TraceElement: public avian::codegen::TraceHandler { Context* context; avian::codegen::Promise* address; TraceElement* next; - object target; + GcMethod* target; unsigned ip; unsigned argumentIndex; unsigned flags; @@ -859,13 +860,13 @@ enum Event { }; unsigned -frameMapSizeInBits(MyThread* t, object method) +frameMapSizeInBits(MyThread* t, GcMethod* method) { - return localSize(t, method) + codeMaxStack(t, methodCode(t, method)); + return localSize(t, method) + codeMaxStack(t, method->code()); } unsigned -frameMapSizeInWords(MyThread* t, object method) +frameMapSizeInWords(MyThread* t, GcMethod* method) { return ceilingDivide(frameMapSizeInBits(t, method), BitsPerWord); } @@ -952,7 +953,7 @@ class Context { virtual intptr_t getThunk(avian::codegen::lir::UnaryOperation, unsigned) { abort(t); } - + virtual intptr_t getThunk(avian::codegen::lir::BinaryOperation op, unsigned size, unsigned resultSize) { @@ -989,7 +990,7 @@ class Context { assert(t, resultSize == 4); return local::getThunk(t, longToFloatThunk); } - + default: abort(t); } } else { @@ -1127,7 +1128,7 @@ class Context { MyThread* t; }; - Context(MyThread* t, BootContext* bootContext, object method) + Context(MyThread* t, BootContext* bootContext, GcMethod* method) : thread(t), zone(t->m->system, t->m->heap, InitialZoneCapacityInBytes), assembler(t->arch->makeAssembler(t->m->heap, &zone)), @@ -1140,11 +1141,11 @@ class Context { traceLog(0), visitTable( Slice::allocAndSet(&zone, - codeLength(t, methodCode(t, method)), + codeLength(t, method->code()), 0)), rootTable( Slice::allocAndSet(&zone, - codeLength(t, methodCode(t, method)) + codeLength(t, method->code()) * frameMapSizeInWords(t, method), ~(uintptr_t)0)), executableAllocator(0), @@ -1227,7 +1228,7 @@ class Context { avian::codegen::Assembler* assembler; MyClient client; avian::codegen::Compiler* compiler; - object method; + GcMethod* method; BootContext* bootContext; PoolElement* objectPool; unsigned subroutineCount; @@ -1250,8 +1251,7 @@ class Context { unsigned translateLocalIndex(Context* context, unsigned footprint, unsigned index) { - unsigned parameterFootprint = methodParameterFootprint - (context->thread, context->method); + unsigned parameterFootprint = context->method->parameterFootprint(); if (index < parameterFootprint) { return parameterFootprint - index - footprint; @@ -1355,7 +1355,7 @@ class Frame { { memset(stackMap, 0, - codeMaxStack(t, methodCode(t, context->method)) * sizeof(ir::Type)); + codeMaxStack(t, context->method->code()) * sizeof(ir::Type)); } Frame(Frame* f, ir::Type* stackMap) @@ -1370,7 +1370,7 @@ class Frame { { memcpy(stackMap, f->stackMap, - codeMaxStack(t, methodCode(t, context->method)) * sizeof(ir::Type)); + codeMaxStack(t, context->method->code()) * sizeof(ir::Type)); if (level > 1) { context->eventLog.append(PushContextEvent); @@ -1394,8 +1394,8 @@ class Frame { avian::codegen::Promise* p = new (bc->zone) avian::codegen::ListenPromise(t->m->system, bc->zone); PROTECT(t, o); - object pointer = makePointer(t, p); - bc->constants = makeTriple(t, o, pointer, bc->constants); + object pointer = reinterpret_cast(makePointer(t, p)); + bc->constants = reinterpret_cast(makeTriple(t, o, pointer, bc->constants)); return c->binaryOp( lir::Add, @@ -1423,7 +1423,7 @@ class Frame { } unsigned stackSize() { - return codeMaxStack(t, methodCode(t, context->method)); + return codeMaxStack(t, context->method->code()); } unsigned frameSize() { @@ -1807,7 +1807,7 @@ class Frame { set(sp - 2, saved); } - TraceElement* trace(object target, unsigned flags) { + TraceElement* trace(GcMethod* target, unsigned flags) { unsigned mapSize = frameMapSizeInWords(t, context->method); TraceElement* e = context->traceLog = new ( @@ -1864,12 +1864,12 @@ class Frame { } void stackCall(ir::Value* methodValue, - object methodObject, + GcMethod* methodObject, unsigned flags, TraceElement* trace) { - unsigned footprint = methodParameterFootprint(t, methodObject); - unsigned returnCode = methodReturnCode(t, methodObject); + unsigned footprint = methodObject->parameterFootprint(); + unsigned returnCode = methodObject->returnCode(); ir::Value* result = c->stackCall(methodValue, flags, trace, @@ -1919,10 +1919,10 @@ class Frame { Subroutine* subroutine = new (&context->zone) Subroutine(context->subroutineCount++, returnAddress, - codeLength(t, methodCode(t, context->method)), + codeLength(t, context->method->code()), this->subroutine); - context->extendLogicalCode(codeLength(t, methodCode(t, context->method))); + context->extendLogicalCode(codeLength(t, context->method->code())); this->subroutine = subroutine; } @@ -1958,9 +1958,9 @@ class Frame { }; unsigned -savedTargetIndex(MyThread* t, object method) +savedTargetIndex(MyThread* t, GcMethod* method) { - return codeMaxLocals(t, methodCode(t, method)); + return codeMaxLocals(t, method->code()); } object @@ -1970,13 +1970,13 @@ void insertCallNode(MyThread* t, object node); void* -findExceptionHandler(Thread* t, object method, void* ip) +findExceptionHandler(Thread* t, GcMethod* method, void* ip) { if (t->exception) { - object table = codeExceptionHandlerTable(t, methodCode(t, method)); + object table = codeExceptionHandlerTable(t, method->code()); if (table) { object index = arrayBody(t, table, 0); - + uint8_t* compiled = reinterpret_cast (methodCompiled(t, method)); @@ -1986,7 +1986,7 @@ findExceptionHandler(Thread* t, object method, void* ip) unsigned key = difference(ip, compiled) - 1; if (key >= start and key < end) { - object catchType = arrayBody(t, table, i + 1); + GcClass* catchType = cast(t, arrayBody(t, table, i + 1)); if (exceptionMatch(t, catchType, t->exception)) { return compiled + intArrayBody(t, index, (i * 3) + 2); @@ -2000,19 +2000,19 @@ findExceptionHandler(Thread* t, object method, void* ip) } void -releaseLock(MyThread* t, object method, void* stack) +releaseLock(MyThread* t, GcMethod* method, void* stack) { - if (methodFlags(t, method) & ACC_SYNCHRONIZED) { + if (method->flags() & ACC_SYNCHRONIZED) { if (t->methodLockIsClean) { object lock; - if (methodFlags(t, method) & ACC_STATIC) { - lock = methodClass(t, method); + if (method->flags() & ACC_STATIC) { + lock = method->class_(); } else { lock = *localObject (t, stackForFrame(t, stack, method), method, savedTargetIndex(t, method)); } - + release(t, lock); } else { // got an exception while trying to acquire the lock for a @@ -2038,15 +2038,15 @@ findUnwindTarget(MyThread* t, void** targetIp, void** targetFrame, } else { ip = getIp(t); stack = t->stack; - continuation = t->continuation; + continuation = t->continuation; } - object target = t->trace->targetMethod; + GcMethod* target = t->trace->targetMethod; bool mostRecent = true; *targetIp = 0; while (*targetIp == 0) { - object method = methodForIp(t, ip); + GcMethod* method = methodForIp(t, ip); if (method) { void* handler = findExceptionHandler(t, method, ip); @@ -2086,7 +2086,7 @@ findUnwindTarget(MyThread* t, void** targetIp, void** targetFrame, while (Continuations and *targetContinuation) { object c = *targetContinuation; - object method = continuationMethod(t, c); + GcMethod* method = cast(t, continuationMethod(t, c)); void* handler = findExceptionHandler (t, method, continuationAddress(t, c)); @@ -2094,7 +2094,7 @@ findUnwindTarget(MyThread* t, void** targetIp, void** targetFrame, if (handler) { t->exceptionHandler = handler; - t->exceptionStackAdjustment + t->exceptionStackAdjustment = (stackOffsetFromFrame(t, method) - ((continuationFramePointerOffset(t, c) / BytesPerWord) - t->arch->framePointerOffset() @@ -2128,10 +2128,10 @@ makeCurrentContinuation(MyThread* t, void** targetIp, void** targetStack) object context = t->continuation ? continuationContext(t, t->continuation) - : makeContinuationContext(t, 0, 0, 0, 0, t->trace->originalMethod); + : reinterpret_cast(makeContinuationContext(t, 0, 0, 0, 0, reinterpret_cast(t->trace->originalMethod))); PROTECT(t, context); - object target = t->trace->targetMethod; + GcMethod* target = t->trace->targetMethod; PROTECT(t, target); object first = 0; @@ -2144,7 +2144,7 @@ makeCurrentContinuation(MyThread* t, void** targetIp, void** targetStack) *targetIp = 0; while (*targetIp == 0) { - object method = methodForIp(t, ip); + GcMethod* method = methodForIp(t, ip); if (method) { PROTECT(t, method); @@ -2152,7 +2152,7 @@ makeCurrentContinuation(MyThread* t, void** targetIp, void** targetStack) + t->arch->frameReturnAddressSize() + t->arch->frameFooterSize(); unsigned argumentFootprint - = t->arch->argumentFootprint(methodParameterFootprint(t, target)); + = t->arch->argumentFootprint(target->parameterFootprint()); unsigned alignment = t->arch->stackAlignmentInWords(); if (avian::codegen::TailCalls and argumentFootprint > alignment) { top += argumentFootprint - alignment; @@ -2166,10 +2166,10 @@ makeCurrentContinuation(MyThread* t, void** targetIp, void** targetStack) unsigned frameSize = bottom - top; unsigned totalSize = frameSize + t->arch->frameFooterSize() - + t->arch->argumentFootprint(methodParameterFootprint(t, method)); + + t->arch->argumentFootprint(method->parameterFootprint()); - object c = makeContinuation - (t, 0, context, method, ip, + object c = reinterpret_cast(makeContinuation + (t, 0, context, reinterpret_cast(method), ip, (frameSize + t->arch->frameFooterSize() + t->arch->returnAddressOffset() @@ -2178,7 +2178,7 @@ makeCurrentContinuation(MyThread* t, void** targetIp, void** targetStack) + t->arch->frameFooterSize() + t->arch->framePointerOffset() - t->arch->frameReturnAddressSize()) * BytesPerWord, - totalSize); + totalSize)); memcpy(&continuationBody(t, c, 0), top, totalSize * BytesPerWord); @@ -2255,9 +2255,9 @@ bool unresolved(MyThread* t, uintptr_t methodAddress); uintptr_t -methodAddress(Thread* t, object method) +methodAddress(Thread* t, GcMethod* method) { - if (methodFlags(t, method) & ACC_NATIVE) { + if (method->flags() & ACC_NATIVE) { return bootNativeThunk(static_cast(t)); } else { return methodCompiled(t, method); @@ -2265,53 +2265,53 @@ methodAddress(Thread* t, object method) } void -tryInitClass(MyThread* t, object class_) +tryInitClass(MyThread* t, GcClass* class_) { initClass(t, class_); } void compile(MyThread* t, FixedAllocator* allocator, BootContext* bootContext, - object method); + GcMethod* method); -object +GcMethod* resolveMethod(Thread* t, object pair) { object reference = pairSecond(t, pair); PROTECT(t, reference); - object class_ = resolveClassInObject + GcClass* class_ = resolveClassInObject (t, classLoader(t, methodClass(t, pairFirst(t, pair))), reference, ReferenceClass); - return findInHierarchy + return cast(t, findInHierarchy (t, class_, referenceName(t, reference), referenceSpec(t, reference), - findMethodInClass, Machine::NoSuchMethodErrorType); + findMethodInClass, GcNoSuchMethodError::Type)); } bool -methodAbstract(Thread* t, object method) +methodAbstract(Thread* t UNUSED, GcMethod* method) { - return methodCode(t, method) == 0 - and (methodFlags(t, method) & ACC_NATIVE) == 0; + return method->code() == 0 + and (method->flags() & ACC_NATIVE) == 0; } int64_t -prepareMethodForCall(MyThread* t, object target) +prepareMethodForCall(MyThread* t, GcMethod* target) { if (methodAbstract(t, target)) { - throwNew(t, Machine::AbstractMethodErrorType, "%s.%s%s", - &byteArrayBody(t, className(t, methodClass(t, target)), 0), - &byteArrayBody(t, methodName(t, target), 0), - &byteArrayBody(t, methodSpec(t, target), 0)); - } else { + throwNew(t, GcAbstractMethodError::Type, "%s.%s%s", + &byteArrayBody(t, className(t, target->class_()), 0), + &byteArrayBody(t, target->name(), 0), + &byteArrayBody(t, target->spec(), 0)); + } else { if (unresolved(t, methodAddress(t, target))) { PROTECT(t, target); - + compile(t, codeAllocator(t), 0, target); } - if (methodFlags(t, target) & ACC_NATIVE) { + if (target->flags() & ACC_NATIVE) { t->trace->nativeMethod = target; } @@ -2320,13 +2320,13 @@ prepareMethodForCall(MyThread* t, object target) } int64_t -findInterfaceMethodFromInstance(MyThread* t, object method, object instance) +findInterfaceMethodFromInstance(MyThread* t, GcMethod* method, object instance) { if (instance) { return prepareMethodForCall (t, findInterfaceMethod(t, method, objectClass(t, instance))); } else { - throwNew(t, Machine::NullPointerExceptionType); + throwNew(t, GcNullPointerException::Type); } } @@ -2336,20 +2336,20 @@ findInterfaceMethodFromInstanceAndReference { PROTECT(t, instance); - object method = resolveMethod(t, pair); + GcMethod* method = resolveMethod(t, pair); return findInterfaceMethodFromInstance(t, method, instance); } void -checkMethod(Thread* t, object method, bool shouldBeStatic) +checkMethod(Thread* t, GcMethod* method, bool shouldBeStatic) { - if (((methodFlags(t, method) & ACC_STATIC) == 0) == shouldBeStatic) { - throwNew(t, Machine::IncompatibleClassChangeErrorType, + if (((method->flags() & ACC_STATIC) == 0) == shouldBeStatic) { + throwNew(t, GcIncompatibleClassChangeError::Type, "expected %s.%s%s to be %s", - &byteArrayBody(t, className(t, methodClass(t, method)), 0), - &byteArrayBody(t, methodName(t, method), 0), - &byteArrayBody(t, methodSpec(t, method), 0), + &byteArrayBody(t, className(t, method->class_()), 0), + &byteArrayBody(t, method->name(), 0), + &byteArrayBody(t, method->spec(), 0), shouldBeStatic ? "static" : "non-static"); } } @@ -2358,7 +2358,7 @@ void checkField(Thread* t, object field, bool shouldBeStatic) { if (((fieldFlags(t, field) & ACC_STATIC) == 0) == shouldBeStatic) { - throwNew(t, Machine::IncompatibleClassChangeErrorType, + throwNew(t, GcIncompatibleClassChangeError::Type, "expected %s.%s to be %s", &byteArrayBody(t, className(t, fieldClass(t, field)), 0), &byteArrayBody(t, fieldName(t, field), 0), @@ -2371,11 +2371,11 @@ findSpecialMethodFromReference(MyThread* t, object pair) { PROTECT(t, pair); - object target = resolveMethod(t, pair); + GcMethod* target = resolveMethod(t, pair); - object class_ = methodClass(t, pairFirst(t, pair)); + GcClass* class_ = cast(t, methodClass(t, pairFirst(t, pair))); if (isSpecialMethod(t, target, class_)) { - target = findVirtualMethod(t, target, classSuper(t, class_)); + target = findVirtualMethod(t, target, cast(t, class_->super())); } checkMethod(t, target, false); @@ -2386,7 +2386,7 @@ findSpecialMethodFromReference(MyThread* t, object pair) int64_t findStaticMethodFromReference(MyThread* t, object pair) { - object target = resolveMethod(t, pair); + GcMethod* target = resolveMethod(t, pair); checkMethod(t, target, true); @@ -2398,7 +2398,7 @@ findVirtualMethodFromReference(MyThread* t, object pair, object instance) { PROTECT(t, instance); - object target = resolveMethod(t, pair); + GcMethod* target = resolveMethod(t, pair); target = findVirtualMethod(t, target, objectClass(t, instance)); @@ -2408,7 +2408,7 @@ findVirtualMethodFromReference(MyThread* t, object pair, object instance) } int64_t -getMethodAddress(MyThread* t, object target) +getMethodAddress(MyThread* t, GcMethod* target) { return prepareMethodForCall(t, target); } @@ -2416,11 +2416,11 @@ getMethodAddress(MyThread* t, object target) int64_t getJClassFromReference(MyThread* t, object pair) { - return reinterpret_cast - (getJClass - (t, resolveClass - (t, classLoader(t, methodClass(t, pairFirst(t, pair))), - referenceName(t, pairSecond(t, pair))))); + return reinterpret_cast(getJClass( + t, + resolveClass(t, + classLoader(t, methodClass(t, pairFirst(t, pair))), + referenceName(t, pairSecond(t, pair))))); } unsigned @@ -2440,18 +2440,18 @@ traceSize(Thread* t) t->m->processor->walkStack(t, &counter); - return FixedSizeOfArray + (counter.count * ArrayElementSizeOfArray) - + (counter.count * FixedSizeOfTraceElement); + return GcArray::FixedSize + (counter.count * ArrayElementSizeOfArray) + + (counter.count * GcTraceElement::FixedSize); } void NO_RETURN throwArithmetic(MyThread* t) { - if (ensure(t, FixedSizeOfArithmeticException + traceSize(t))) { + if (ensure(t, GcArithmeticException::FixedSize + traceSize(t))) { atomicOr(&(t->flags), Thread::TracingFlag); THREAD_RESOURCE0(t, atomicAnd(&(t->flags), ~Thread::TracingFlag)); - throwNew(t, Machine::ArithmeticExceptionType); + throwNew(t, GcArithmeticException::Type); } else { // not enough memory available for a new exception and stack trace // -- use a preallocated instance instead @@ -2496,12 +2496,12 @@ int64_t moduloInt(MyThread* t, int32_t b, int32_t a) } uint64_t -makeBlankObjectArray(MyThread* t, object class_, int32_t length) +makeBlankObjectArray(MyThread* t, GcClass* class_, int32_t length) { if (length >= 0) { return reinterpret_cast(makeObjectArray(t, class_, length)); } else { - throwNew(t, Machine::NegativeArraySizeExceptionType, "%d", length); + throwNew(t, GcNegativeArraySizeException::Type, "%d", length); } } @@ -2509,56 +2509,39 @@ uint64_t makeBlankObjectArrayFromReference(MyThread* t, object pair, int32_t length) { - return makeBlankObjectArray - (t, resolveClass - (t, classLoader(t, methodClass(t, pairFirst(t, pair))), - referenceName(t, pairSecond(t, pair))), length); + return makeBlankObjectArray( + t, + resolveClass(t, + classLoader(t, methodClass(t, pairFirst(t, pair))), + referenceName(t, pairSecond(t, pair))), + length); } uint64_t makeBlankArray(MyThread* t, unsigned type, int32_t length) { if (length >= 0) { - object (*constructor)(Thread*, uintptr_t); switch (type) { case T_BOOLEAN: - constructor = makeBooleanArray; - break; - + return reinterpret_cast(makeBooleanArray(t, length)); case T_CHAR: - constructor = makeCharArray; - break; - + return reinterpret_cast(makeCharArray(t, length)); case T_FLOAT: - constructor = makeFloatArray; - break; - + return reinterpret_cast(makeFloatArray(t, length)); case T_DOUBLE: - constructor = makeDoubleArray; - break; - + return reinterpret_cast(makeDoubleArray(t, length)); case T_BYTE: - constructor = makeByteArray; - break; - + return reinterpret_cast(makeByteArray(t, length)); case T_SHORT: - constructor = makeShortArray; - break; - + return reinterpret_cast(makeShortArray(t, length)); case T_INT: - constructor = makeIntArray; - break; - + return reinterpret_cast(makeIntArray(t, length)); case T_LONG: - constructor = makeLongArray; - break; - + return reinterpret_cast(makeLongArray(t, length)); default: abort(t); } - - return reinterpret_cast(constructor(t, length)); } else { - throwNew(t, Machine::NegativeArraySizeExceptionType, "%d", length); + throwNew(t, GcNegativeArraySizeException::Type, "%d", length); } } @@ -2591,7 +2574,7 @@ setMaybeNull(MyThread* t, object o, unsigned offset, object value) if (LIKELY(o)) { set(t, o, offset, value); } else { - throwNew(t, Machine::NullPointerExceptionType); + throwNew(t, GcNullPointerException::Type); } } @@ -2601,7 +2584,7 @@ acquireMonitorForObject(MyThread* t, object o) if (LIKELY(o)) { acquire(t, o); } else { - throwNew(t, Machine::NullPointerExceptionType); + throwNew(t, GcNullPointerException::Type); } } @@ -2613,7 +2596,7 @@ acquireMonitorForObjectOnEntrance(MyThread* t, object o) acquire(t, o); t->methodLockIsClean = true; } else { - throwNew(t, Machine::NullPointerExceptionType); + throwNew(t, GcNullPointerException::Type); } } @@ -2623,12 +2606,12 @@ releaseMonitorForObject(MyThread* t, object o) if (LIKELY(o)) { release(t, o); } else { - throwNew(t, Machine::NullPointerExceptionType); + throwNew(t, GcNullPointerException::Type); } } object -makeMultidimensionalArray2(MyThread* t, object class_, uintptr_t* countStack, +makeMultidimensionalArray2(MyThread* t, GcClass* class_, uintptr_t* countStack, int32_t dimensions) { PROTECT(t, class_); @@ -2637,13 +2620,13 @@ makeMultidimensionalArray2(MyThread* t, object class_, uintptr_t* countStack, for (int i = dimensions - 1; i >= 0; --i) { RUNTIME_ARRAY_BODY(counts)[i] = countStack[dimensions - i - 1]; if (UNLIKELY(RUNTIME_ARRAY_BODY(counts)[i] < 0)) { - throwNew(t, Machine::NegativeArraySizeExceptionType, "%d", + throwNew(t, GcNegativeArraySizeException::Type, "%d", RUNTIME_ARRAY_BODY(counts)[i]); return 0; } } - object array = makeArray(t, RUNTIME_ARRAY_BODY(counts)[0]); + object array = reinterpret_cast(makeArray(t, RUNTIME_ARRAY_BODY(counts)[0])); setObjectClass(t, array, class_); PROTECT(t, array); @@ -2653,7 +2636,7 @@ makeMultidimensionalArray2(MyThread* t, object class_, uintptr_t* countStack, } uint64_t -makeMultidimensionalArray(MyThread* t, object class_, int32_t dimensions, +makeMultidimensionalArray(MyThread* t, GcClass* class_, int32_t dimensions, int32_t offset) { return reinterpret_cast @@ -2675,11 +2658,11 @@ makeMultidimensionalArrayFromReference(MyThread* t, object pair, void NO_RETURN throwArrayIndexOutOfBounds(MyThread* t) { - if (ensure(t, FixedSizeOfArrayIndexOutOfBoundsException + traceSize(t))) { + if (ensure(t, GcArrayIndexOutOfBoundsException::FixedSize + traceSize(t))) { atomicOr(&(t->flags), Thread::TracingFlag); THREAD_RESOURCE0(t, atomicAnd(&(t->flags), ~Thread::TracingFlag)); - throwNew(t, Machine::ArrayIndexOutOfBoundsExceptionType); + throwNew(t, GcArrayIndexOutOfBoundsException::Type); } else { // not enough memory available for a new exception and stack trace // -- use a preallocated instance instead @@ -2690,7 +2673,7 @@ throwArrayIndexOutOfBounds(MyThread* t) void NO_RETURN throwStackOverflow(MyThread* t) { - throwNew(t, Machine::StackOverflowErrorType); + throwNew(t, GcStackOverflowError::Type); } void NO_RETURN @@ -2699,16 +2682,16 @@ throw_(MyThread* t, object o) if (LIKELY(o)) { vm::throw_(t, o); } else { - throwNew(t, Machine::NullPointerExceptionType); + throwNew(t, GcNullPointerException::Type); } } void -checkCast(MyThread* t, object class_, object o) +checkCast(MyThread* t, GcClass* class_, object o) { if (UNLIKELY(o and not isAssignableFrom(t, class_, objectClass(t, o)))) { - object classNameFrom = className(t, objectClass(t, o)); - object classNameTo = className(t, class_); + object classNameFrom = objectClass(t, o)->name(); + object classNameTo = 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), @@ -2716,7 +2699,7 @@ checkCast(MyThread* t, object class_, object o) replace('/', '.', RUNTIME_ARRAY_BODY(classTo), reinterpret_cast(&byteArrayBody(t, classNameTo, 0))); throwNew - (t, Machine::ClassCastExceptionType, "%s cannot be cast to %s", + (t, GcClassCastException::Type, "%s cannot be cast to %s", RUNTIME_ARRAY_BODY(classFrom), RUNTIME_ARRAY_BODY(classTo)); } } @@ -2726,7 +2709,7 @@ checkCastFromReference(MyThread* t, object pair, object o) { PROTECT(t, o); - object c = resolveClass + GcClass* c = resolveClass (t, classLoader(t, methodClass(t, pairFirst(t, pair))), referenceName(t, pairSecond(t, pair))); @@ -2739,13 +2722,13 @@ resolveField(Thread* t, object pair) object reference = pairSecond(t, pair); PROTECT(t, reference); - object class_ = resolveClassInObject + GcClass* class_ = resolveClassInObject (t, classLoader(t, methodClass(t, pairFirst(t, pair))), reference, ReferenceClass); return findInHierarchy (t, class_, referenceName(t, reference), referenceSpec(t, reference), - findFieldInClass, Machine::NoSuchFieldErrorType); + findFieldInClass, GcNoSuchFieldError::Type); } uint64_t @@ -2782,7 +2765,7 @@ getStaticFieldValueFromReference(MyThread* t, object pair) object field = resolveField(t, pair); PROTECT(t, field); - initClass(t, fieldClass(t, field)); + initClass(t, cast(t, fieldClass(t, field))); ACQUIRE_FIELD_FOR_READ(t, field); @@ -2808,7 +2791,7 @@ setStaticLongFieldValueFromReference(MyThread* t, object pair, uint64_t value) object field = resolveField(t, pair); PROTECT(t, field); - initClass(t, fieldClass(t, field)); + initClass(t, cast(t, fieldClass(t, field))); ACQUIRE_FIELD_FOR_WRITE(t, field); @@ -2838,7 +2821,7 @@ setStaticObjectFieldValueFromReference(MyThread* t, object pair, object value) object field = resolveField(t, pair); PROTECT(t, field); - initClass(t, fieldClass(t, field)); + initClass(t, cast(t, fieldClass(t, field))); ACQUIRE_FIELD_FOR_WRITE(t, field); @@ -2891,7 +2874,7 @@ setStaticFieldValueFromReference(MyThread* t, object pair, uint32_t value) object field = resolveField(t, pair); PROTECT(t, field); - initClass(t, fieldClass(t, field)); + initClass(t, cast(t, fieldClass(t, field))); ACQUIRE_FIELD_FOR_WRITE(t, field); @@ -2912,7 +2895,7 @@ setFieldValueFromReference(MyThread* t, object pair, object instance, } uint64_t -instanceOf64(Thread* t, object class_, object o) +instanceOf64(Thread* t, GcClass* class_, object o) { return instanceOf(t, class_, o); } @@ -2922,7 +2905,7 @@ instanceOfFromReference(Thread* t, object pair, object o) { PROTECT(t, o); - object c = resolveClass + GcClass* c = resolveClass (t, classLoader(t, methodClass(t, pairFirst(t, pair))), referenceName(t, pairSecond(t, pair))); @@ -2930,7 +2913,7 @@ instanceOfFromReference(Thread* t, object pair, object o) } uint64_t -makeNewGeneral64(Thread* t, object class_) +makeNewGeneral64(Thread* t, GcClass* class_) { PROTECT(t, class_); @@ -2940,7 +2923,7 @@ makeNewGeneral64(Thread* t, object class_) } uint64_t -makeNew64(Thread* t, object class_) +makeNew64(Thread* t, GcClass* class_) { PROTECT(t, class_); @@ -2952,7 +2935,7 @@ makeNew64(Thread* t, object class_) uint64_t makeNewFromReference(Thread* t, object pair) { - object class_ = resolveClass + GcClass* class_ = resolveClass (t, classLoader(t, methodClass(t, pairFirst(t, pair))), referenceName(t, pairSecond(t, pair))); @@ -2964,7 +2947,7 @@ makeNewFromReference(Thread* t, object pair) } uint64_t -getJClass64(Thread* t, object class_) +getJClass64(Thread* t, GcClass* class_) { return reinterpret_cast(getJClass(t, class_)); } @@ -3062,7 +3045,7 @@ void compileSafePoint(MyThread* t, Compiler* c, Frame* frame) { void compileDirectInvoke(MyThread* t, Frame* frame, - object target, + GcMethod* target, bool tailCall, bool useThunk, avian::codegen::Promise* addressPromise) @@ -3080,7 +3063,7 @@ void compileDirectInvoke(MyThread* t, } if (useThunk - or (avian::codegen::TailCalls and tailCall and (methodFlags(t, target) & ACC_NATIVE))) + or (avian::codegen::TailCalls and tailCall and (target->flags() & ACC_NATIVE))) { if (frame->context->bootContext == 0) { flags |= Compiler::Aligned; @@ -3106,7 +3089,7 @@ void compileDirectInvoke(MyThread* t, ir::Type::iptr(), TARGET_THREAD_TAILADDRESS)); - c->exit(c->constant((methodFlags(t, target) & ACC_NATIVE) + c->exit(c->constant((target->flags() & ACC_NATIVE) ? nativeThunk(t) : defaultThunk(t), ir::Type::iptr())); @@ -3128,40 +3111,40 @@ void compileDirectInvoke(MyThread* t, flags, tailCall ? 0 : frame->trace( - (methodFlags(t, target) & ACC_NATIVE) ? target : 0, 0)); + (target->flags() & ACC_NATIVE) ? target : 0, 0)); } } bool -compileDirectInvoke(MyThread* t, Frame* frame, object target, bool tailCall) +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, methodClass(t, target)))) + and (not classNeedsInit(t, cast(t, target->class_())))) { - frame->popFootprint(methodParameterFootprint(t, target)); + frame->popFootprint(target->parameterFootprint()); tailCall = false; } else { BootContext* bc = frame->context->bootContext; if (bc) { - if ((methodClass(t, target) == methodClass(t, frame->context->method) - or (not classNeedsInit(t, methodClass(t, target)))) + if ((target->class_() == frame->context->method->class_() + or (not classNeedsInit(t, cast(t, target->class_())))) and (not (avian::codegen::TailCalls and tailCall - and (methodFlags(t, target) & ACC_NATIVE)))) + and (target->flags() & ACC_NATIVE)))) { avian::codegen::Promise* p = new(bc->zone) avian::codegen::ListenPromise(t->m->system, bc->zone); PROTECT(t, target); - object pointer = makePointer(t, p); - bc->calls = makeTriple(t, target, pointer, bc->calls); + object pointer = reinterpret_cast(makePointer(t, p)); + bc->calls = reinterpret_cast(makeTriple(t, reinterpret_cast(target), pointer, bc->calls)); compileDirectInvoke(t, frame, target, tailCall, false, p); } else { compileDirectInvoke(t, frame, target, tailCall, true, 0); } } else if (unresolved(t, methodAddress(t, target)) - or classNeedsInit(t, methodClass(t, target))) + or classNeedsInit(t, cast(t, target->class_()))) { compileDirectInvoke(t, frame, target, tailCall, true, 0); } else { @@ -3193,7 +3176,7 @@ compileDirectReferenceInvoke(MyThread* t, Frame* frame, Thunk thunk, PROTECT(t, reference); - object pair = makePair(t, frame->context->method, reference); + object pair = reinterpret_cast(makePair(t, reinterpret_cast(frame->context->method), reference)); compileReferenceInvoke( frame, @@ -3211,7 +3194,7 @@ compileDirectReferenceInvoke(MyThread* t, Frame* frame, Thunk thunk, void compileAbstractInvoke(Frame* frame, ir::Value* method, - object target, + GcMethod* target, bool tailCall) { frame->stackCall( @@ -3220,35 +3203,34 @@ void compileAbstractInvoke(Frame* frame, void compileDirectAbstractInvoke(MyThread* t, Frame* frame, Thunk thunk, - object target, bool tailCall) + GcMethod* target, bool tailCall) { avian::codegen::Compiler* c = frame->c; - compileAbstractInvoke( - frame, - c->call(c->constant(getThunk(t, thunk), ir::Type::iptr()), - 0, - frame->trace(0, 0), - ir::Type::iptr(), - 2, - c->threadRegister(), - frame->append(target)), - target, - tailCall); + compileAbstractInvoke(frame, + c->call(c->constant(getThunk(t, thunk), ir::Type::iptr()), + 0, + frame->trace(0, 0), + ir::Type::iptr(), + 2, + c->threadRegister(), + frame->append(reinterpret_cast(target))), + target, + tailCall); } void handleMonitorEvent(MyThread* t, Frame* frame, intptr_t function) { avian::codegen::Compiler* c = frame->c; - object method = frame->context->method; + GcMethod* method = frame->context->method; - if (methodFlags(t, method) & ACC_SYNCHRONIZED) { + if (method->flags() & ACC_SYNCHRONIZED) { ir::Value* lock; - if (methodFlags(t, method) & ACC_STATIC) { + if (method->flags() & ACC_STATIC) { PROTECT(t, method); - lock = frame->append(methodClass(t, method)); + lock = frame->append(method->class_()); } else { lock = loadLocal( frame->context, 1, ir::Type::object(), savedTargetIndex(t, method)); @@ -3267,9 +3249,9 @@ handleMonitorEvent(MyThread* t, Frame* frame, intptr_t function) void handleEntrance(MyThread* t, Frame* frame) { - object method = frame->context->method; + GcMethod* method = frame->context->method; - if ((methodFlags(t, method) & (ACC_SYNCHRONIZED | ACC_STATIC)) + if ((method->flags() & (ACC_SYNCHRONIZED | ACC_STATIC)) == ACC_SYNCHRONIZED) { // save 'this' pointer in case it is overwritten. @@ -3312,10 +3294,10 @@ inTryBlock(MyThread* t, object code, unsigned ip) } bool -needsReturnBarrier(MyThread* t, object method) +needsReturnBarrier(MyThread* t, GcMethod* method) { - return (methodFlags(t, method) & ConstructorFlag) - and (classVmFlags(t, methodClass(t, method)) & HasFinalMemberFlag); + return (method->flags() & ConstructorFlag) + and (classVmFlags(t, method->class_()) & HasFinalMemberFlag); } bool @@ -3342,7 +3324,7 @@ returnsNext(MyThread* t, object code, unsigned ip) uint32_t offset = codeReadInt32(t, code, ++ip); uint32_t newIp = (ip - 5) + offset; assert(t, newIp < codeLength(t, code)); - + return returnsNext(t, code, newIp); } @@ -3352,36 +3334,36 @@ returnsNext(MyThread* t, object code, unsigned ip) } bool -isTailCall(MyThread* t, object code, unsigned ip, object caller, +isTailCall(MyThread* t, object code, unsigned ip, GcMethod* caller, int calleeReturnCode, object calleeClassName, object calleeMethodName, object calleeMethodSpec) { return avian::codegen::TailCalls - and ((methodFlags(t, caller) & ACC_SYNCHRONIZED) == 0) + and ((caller->flags() & ACC_SYNCHRONIZED) == 0) and (not inTryBlock(t, code, ip - 1)) and (not needsReturnBarrier(t, caller)) - and (methodReturnCode(t, caller) == VoidField - or methodReturnCode(t, caller) == calleeReturnCode) + and (caller->returnCode() == VoidField + or caller->returnCode() == calleeReturnCode) and returnsNext(t, code, ip) and t->m->classpath->canTailCall (t, caller, calleeClassName, calleeMethodName, calleeMethodSpec); } bool -isTailCall(MyThread* t, object code, unsigned ip, object caller, object callee) +isTailCall(MyThread* t, object code, unsigned ip, GcMethod* caller, GcMethod* callee) { return isTailCall - (t, code, ip, caller, methodReturnCode(t, callee), - className(t, methodClass(t, callee)), methodName(t, callee), - methodSpec(t, callee)); + (t, code, ip, caller, callee->returnCode(), + className(t, callee->class_()), callee->name(), + callee->spec()); } bool -isReferenceTailCall(MyThread* t, object code, unsigned ip, object caller, +isReferenceTailCall(MyThread* t, object code, unsigned ip, GcMethod* caller, object calleeReference) { object c = referenceClass(t, calleeReference); - if (objectClass(t, c) == type(t, Machine::ClassType)) { + if (objectClass(t, c) == type(t, GcClass::Type)) { c = className(t, c); } @@ -3549,34 +3531,32 @@ ir::Value* popLongAddress(Frame* frame) } bool -intrinsic(MyThread* t, Frame* frame, object target) +intrinsic(MyThread* t, Frame* frame, GcMethod* target) { -#define MATCH(name, constant) \ - (byteArrayLength(t, name) == sizeof(constant) \ - and ::strcmp(reinterpret_cast(&byteArrayBody(t, name, 0)), \ - constant) == 0) +#define MATCH(name, constant) \ + (byteArrayLength(t, name) \ + == sizeof(constant) and::strcmp( \ + reinterpret_cast(&byteArrayBody(t, name, 0)), constant) == 0) - object className = vm::className(t, methodClass(t, target)); + object className = vm::className(t, target->class_()); if (UNLIKELY(MATCH(className, "java/lang/Math"))) { avian::codegen::Compiler* c = frame->c; - if (MATCH(methodName(t, target), "sqrt") - and MATCH(methodSpec(t, target), "(D)D")) - { + if (MATCH(target->name(), "sqrt") and MATCH(target->spec(), "(D)D")) { frame->pushLarge( ir::Type::f8(), c->unaryOp(lir::FloatSquareRoot, frame->popLarge(ir::Type::f8()))); return true; - } else if (MATCH(methodName(t, target), "abs")) { - if (MATCH(methodSpec(t, target), "(I)I")) { + } else if (MATCH(target->name(), "abs")) { + if (MATCH(target->spec(), "(I)I")) { frame->push(ir::Type::i4(), c->unaryOp(lir::Absolute, frame->pop(ir::Type::i4()))); return true; - } else if (MATCH(methodSpec(t, target), "(J)J")) { + } else if (MATCH(target->spec(), "(J)J")) { frame->pushLarge( ir::Type::i8(), c->unaryOp(lir::Absolute, frame->popLarge(ir::Type::i8()))); return true; - } else if (MATCH(methodSpec(t, target), "(F)F")) { + } else if (MATCH(target->spec(), "(F)F")) { frame->push(ir::Type::f4(), c->unaryOp(lir::FloatAbsolute, frame->pop(ir::Type::f4()))); return true; @@ -3584,9 +3564,7 @@ intrinsic(MyThread* t, Frame* frame, object target) } } else if (UNLIKELY(MATCH(className, "sun/misc/Unsafe"))) { avian::codegen::Compiler* c = frame->c; - if (MATCH(methodName(t, target), "getByte") - and MATCH(methodSpec(t, target), "(J)B")) - { + if (MATCH(target->name(), "getByte") and MATCH(target->spec(), "(J)B")) { ir::Value* address = popLongAddress(frame); frame->pop(ir::Type::object()); frame->push(ir::Type::i4(), @@ -3594,19 +3572,17 @@ intrinsic(MyThread* t, Frame* frame, object target) c->memory(address, ir::Type::i1()), ir::Type::i4())); return true; - } else if (MATCH(methodName(t, target), "putByte") - and MATCH(methodSpec(t, target), "(JB)V")) - { + } else if (MATCH(target->name(), "putByte") and MATCH(target->spec(), + "(JB)V")) { ir::Value* value = frame->pop(ir::Type::i4()); ir::Value* address = popLongAddress(frame); frame->pop(ir::Type::object()); c->store(value, c->memory(address, ir::Type::i1())); return true; - } else if ((MATCH(methodName(t, target), "getShort") - and MATCH(methodSpec(t, target), "(J)S")) - or (MATCH(methodName(t, target), "getChar") - and MATCH(methodSpec(t, target), "(J)C"))) - { + } else if ((MATCH(target->name(), "getShort") and MATCH(target->spec(), + "(J)S")) + or(MATCH(target->name(), "getChar") and MATCH(target->spec(), + "(J)C"))) { ir::Value* address = popLongAddress(frame); frame->pop(ir::Type::object()); frame->push(ir::Type::i4(), @@ -3614,67 +3590,61 @@ intrinsic(MyThread* t, Frame* frame, object target) c->memory(address, ir::Type::i2()), ir::Type::i4())); return true; - } else if ((MATCH(methodName(t, target), "putShort") - and MATCH(methodSpec(t, target), "(JS)V")) - or (MATCH(methodName(t, target), "putChar") - and MATCH(methodSpec(t, target), "(JC)V"))) - { + } else if ((MATCH(target->name(), "putShort") and MATCH(target->spec(), + "(JS)V")) + or(MATCH(target->name(), "putChar") and MATCH(target->spec(), + "(JC)V"))) { ir::Value* value = frame->pop(ir::Type::i4()); ir::Value* address = popLongAddress(frame); frame->pop(ir::Type::object()); c->store(value, c->memory(address, ir::Type::i2())); return true; - } else if ((MATCH(methodName(t, target), "getInt") - and MATCH(methodSpec(t, target), "(J)I")) - or (MATCH(methodName(t, target), "getFloat") - and MATCH(methodSpec(t, target), "(J)F"))) - { + } else if ((MATCH(target->name(), "getInt") and MATCH(target->spec(), + "(J)I")) + or(MATCH(target->name(), "getFloat") and MATCH(target->spec(), + "(J)F"))) { ir::Value* address = popLongAddress(frame); frame->pop(ir::Type::object()); - ir::Type type = MATCH(methodName(t, target), "getInt") ? ir::Type::i4() - : ir::Type::f4(); + ir::Type type = MATCH(target->name(), "getInt") ? ir::Type::i4() + : ir::Type::f4(); frame->push(type, c->load(ir::SignExtend, c->memory(address, type), type)); return true; - } else if ((MATCH(methodName(t, target), "putInt") - and MATCH(methodSpec(t, target), "(JI)V")) - or (MATCH(methodName(t, target), "putFloat") - and MATCH(methodSpec(t, target), "(JF)V"))) - { - ir::Type type = MATCH(methodName(t, target), "putInt") ? ir::Type::i4() - : ir::Type::f4(); + } else if ((MATCH(target->name(), "putInt") and MATCH(target->spec(), + "(JI)V")) + or(MATCH(target->name(), "putFloat") and MATCH(target->spec(), + "(JF)V"))) { + ir::Type type = MATCH(target->name(), "putInt") ? ir::Type::i4() + : ir::Type::f4(); ir::Value* value = frame->pop(type); ir::Value* address = popLongAddress(frame); frame->pop(ir::Type::object()); c->store(value, c->memory(address, type)); return true; - } else if ((MATCH(methodName(t, target), "getLong") - and MATCH(methodSpec(t, target), "(J)J")) - or (MATCH(methodName(t, target), "getDouble") - and MATCH(methodSpec(t, target), "(J)D"))) - { + } else if ((MATCH(target->name(), "getLong") and MATCH(target->spec(), + "(J)J")) + or(MATCH(target->name(), "getDouble") and MATCH(target->spec(), + "(J)D"))) { ir::Value* address = popLongAddress(frame); frame->pop(ir::Type::object()); - ir::Type type = MATCH(methodName(t, target), "getLong") ? ir::Type::i8() - : ir::Type::f8(); + ir::Type type = MATCH(target->name(), "getLong") ? ir::Type::i8() + : ir::Type::f8(); frame->pushLarge(type, c->load(ir::SignExtend, c->memory(address, type), type)); return true; - } else if ((MATCH(methodName(t, target), "putLong") - and MATCH(methodSpec(t, target), "(JJ)V")) - or (MATCH(methodName(t, target), "putDouble") - and MATCH(methodSpec(t, target), "(JD)V"))) - { - ir::Type type = MATCH(methodName(t, target), "putLong") ? ir::Type::i8() - : ir::Type::f8(); + } else if ((MATCH(target->name(), "putLong") and MATCH(target->spec(), + "(JJ)V")) + or(MATCH(target->name(), "putDouble") and MATCH(target->spec(), + "(JD)V"))) { + ir::Type type = MATCH(target->name(), "putLong") ? ir::Type::i8() + : ir::Type::f8(); ir::Value* value = frame->popLarge(type); ir::Value* address = popLongAddress(frame); frame->pop(ir::Type::object()); c->store(value, c->memory(address, type)); return true; - } else if (MATCH(methodName(t, target), "getAddress") - and MATCH(methodSpec(t, target), "(J)J")) - { + } else if (MATCH(target->name(), "getAddress") and MATCH(target->spec(), + "(J)J")) { ir::Value* address = popLongAddress(frame); frame->pop(ir::Type::object()); frame->pushLarge(ir::Type::i8(), @@ -3682,9 +3652,8 @@ intrinsic(MyThread* t, Frame* frame, object target) c->memory(address, ir::Type::iptr()), ir::Type::i8())); return true; - } else if (MATCH(methodName(t, target), "putAddress") - and MATCH(methodSpec(t, target), "(JJ)V")) - { + } else if (MATCH(target->name(), "putAddress") and MATCH(target->spec(), + "(JJ)V")) { ir::Value* value = frame->popLarge(ir::Type::i8()); ir::Value* address = popLongAddress(frame); frame->pop(ir::Type::object()); @@ -3864,7 +3833,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, Frame* frame = initialFrame; avian::codegen::Compiler* c = frame->c; Context* context = frame->context; - unsigned stackSize = codeMaxStack(t, methodCode(t, context->method)); + unsigned stackSize = codeMaxStack(t, context->method->code()); Stack stack(t); unsigned ip = initialIp; unsigned newIp; @@ -3877,9 +3846,9 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame = new (stack.push(sizeof(Frame))) Frame(frame, stackMap); loop: - object code = methodCode(t, context->method); + object code = context->method->code(); PROTECT(t, code); - + while (ip < codeLength(t, code)) { if (context->visitTable[frame->duplicatedIp(ip)]++) { // we've already visited this part of the code @@ -4134,23 +4103,23 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case anewarray: { uint16_t index = codeReadInt16(t, code, ip); - + object reference = singletonObject - (t, codePool(t, methodCode(t, context->method)), index - 1); + (t, cast(t, codePool(t, context->method->code())), index - 1); PROTECT(t, reference); - object class_ = resolveClassInPool(t, context->method, index - 1, false); + GcClass* class_ = resolveClassInPool(t, context->method, index - 1, false); ir::Value* length = frame->pop(ir::Type::i4()); object argument; Thunk thunk; if (LIKELY(class_)) { - argument = class_; + argument = reinterpret_cast(class_); thunk = makeBlankObjectArrayThunk; } else { - argument = makePair(t, context->method, reference); + argument = reinterpret_cast(makePair(t, reinterpret_cast(context->method), reference)); thunk = makeBlankObjectArrayFromReferenceThunk; } @@ -4222,19 +4191,19 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, uint16_t index = codeReadInt16(t, code, ip); object reference = singletonObject - (t, codePool(t, methodCode(t, context->method)), index - 1); + (t, cast(t, codePool(t, context->method->code())), index - 1); PROTECT(t, reference); - object class_ = resolveClassInPool(t, context->method, index - 1, false); + GcClass* class_ = resolveClassInPool(t, context->method, index - 1, false); object argument; Thunk thunk; if (LIKELY(class_)) { - argument = class_; + argument = reinterpret_cast(class_); thunk = checkCastThunk; } else { - argument = makePair(t, context->method, reference); + argument = reinterpret_cast(makePair(t, reinterpret_cast(context->method), reference)); thunk = checkCastFromReferenceThunk; } @@ -4432,12 +4401,12 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->push(ir::Type::f4(), c->constant(floatToBits(0.0), ir::Type::f4())); break; - + case fconst_1: frame->push(ir::Type::f4(), c->constant(floatToBits(1.0), ir::Type::f4())); break; - + case fconst_2: frame->push(ir::Type::f4(), c->constant(floatToBits(2.0), ir::Type::f4())); @@ -4451,9 +4420,9 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case getfield: case getstatic: { uint16_t index = codeReadInt16(t, code, ip); - + object reference = singletonObject - (t, codePool(t, methodCode(t, context->method)), index - 1); + (t, cast(t, codePool(t, context->method->code())), index - 1); PROTECT(t, reference); @@ -4484,15 +4453,14 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, PROTECT(t, field); - if (classNeedsInit(t, fieldClass(t, field))) { - c->call( - c->constant(getThunk(t, tryInitClassThunk), ir::Type::iptr()), - 0, - frame->trace(0, 0), - ir::Type::void_(), - 2, - c->threadRegister(), - frame->append(fieldClass(t, field))); + if (classNeedsInit(t, cast(t, fieldClass(t, field)))) { + c->call(c->constant(getThunk(t, tryInitClassThunk), ir::Type::iptr()), + 0, + frame->trace(0, 0), + ir::Type::void_(), + 2, + c->threadRegister(), + frame->append(fieldClass(t, field))); } table = frame->append(classStaticTable(t, fieldClass(t, field))); @@ -4606,7 +4574,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, int fieldCode = vm::fieldCode (t, byteArrayBody(t, referenceSpec(t, reference), 0)); - object pair = makePair(t, context->method, reference); + object pair = reinterpret_cast(makePair(t, reinterpret_cast(context->method), reference)); ir::Type rType = operandTypeForFieldCode(t, fieldCode); @@ -4707,7 +4675,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ir::Type::i2(), frame->pop(ir::Type::i4()))); } break; - + case iadd: case iand: case ior: @@ -4901,21 +4869,21 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, uint16_t index = codeReadInt16(t, code, ip); object reference = singletonObject - (t, codePool(t, methodCode(t, context->method)), index - 1); + (t, cast(t, codePool(t, context->method->code())), index - 1); PROTECT(t, reference); - object class_ = resolveClassInPool(t, context->method, index - 1, false); + GcClass* class_ = resolveClassInPool(t, context->method, index - 1, false); ir::Value* instance = frame->pop(ir::Type::object()); object argument; Thunk thunk; if (LIKELY(class_)) { - argument = class_; + argument = reinterpret_cast(class_); thunk = instanceOf64Thunk; } else { - argument = makePair(t, context->method, reference); + argument = reinterpret_cast(makePair(t, reinterpret_cast(context->method), reference)); thunk = instanceOfFromReferenceThunk; } @@ -4937,11 +4905,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ip += 2; object reference = singletonObject - (t, codePool(t, methodCode(t, context->method)), index - 1); + (t, cast(t, codePool(t, context->method->code())), index - 1); PROTECT(t, reference); - object target = resolveMethod(t, context->method, index - 1, false); + GcMethod* target = resolveMethod(t, context->method, index - 1, false); object argument; Thunk thunk; @@ -4951,13 +4919,13 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, if (LIKELY(target)) { checkMethod(t, target, false); - argument = target; + argument = reinterpret_cast(target); thunk = findInterfaceMethodFromInstanceThunk; - parameterFootprint = methodParameterFootprint(t, target); - returnCode = methodReturnCode(t, target); + parameterFootprint = target->parameterFootprint(); + returnCode = target->returnCode(); tailCall = isTailCall(t, code, ip, context->method, target); } else { - argument = makePair(t, context->method, reference); + argument = reinterpret_cast(makePair(t, reinterpret_cast(context->method), reference)); thunk = findInterfaceMethodFromInstanceAndReferenceThunk; parameterFootprint = methodReferenceParameterFootprint (t, reference, false); @@ -4995,16 +4963,16 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, uint16_t index = codeReadInt16(t, code, ip); object reference = singletonObject - (t, codePool(t, methodCode(t, context->method)), index - 1); + (t, cast(t, codePool(t, context->method->code())), index - 1); PROTECT(t, reference); - object target = resolveMethod(t, context->method, index - 1, false); + GcMethod* target = resolveMethod(t, context->method, index - 1, false); if (LIKELY(target)) { - object class_ = methodClass(t, context->method); + GcClass* class_ = cast(t, context->method->class_()); if (isSpecialMethod(t, target, class_)) { - target = findVirtualMethod(t, target, classSuper(t, class_)); + target = findVirtualMethod(t, target, cast(t, class_->super())); } checkMethod(t, target, false); @@ -5030,11 +4998,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, uint16_t index = codeReadInt16(t, code, ip); object reference = singletonObject - (t, codePool(t, methodCode(t, context->method)), index - 1); + (t, cast(t, codePool(t, context->method->code())), index - 1); PROTECT(t, reference); - object target = resolveMethod(t, context->method, index - 1, false); + GcMethod* target = resolveMethod(t, context->method, index - 1, false); if (LIKELY(target)) { checkMethod(t, target, true); @@ -5056,23 +5024,23 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, uint16_t index = codeReadInt16(t, code, ip); object reference = singletonObject - (t, codePool(t, methodCode(t, context->method)), index - 1); + (t, cast(t, codePool(t, context->method->code())), index - 1); PROTECT(t, reference); - object target = resolveMethod(t, context->method, index - 1, false); + GcMethod* target = resolveMethod(t, context->method, index - 1, false); if (LIKELY(target)) { checkMethod(t, target, false); - + if (not intrinsic(t, frame, target)) { bool tailCall = isTailCall(t, code, ip, context->method, target); if (LIKELY(methodVirtual(t, target))) { - unsigned parameterFootprint = methodParameterFootprint(t, target); + unsigned parameterFootprint = target->parameterFootprint(); unsigned offset = TargetClassVtable - + (methodOffset(t, target) * TargetBytesPerWord); + + (target->offset() * TargetBytesPerWord); ir::Value* instance = c->peek(1, parameterFootprint - 1); @@ -5098,7 +5066,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, } else { PROTECT(t, reference); - object pair = makePair(t, context->method, reference); + object pair = reinterpret_cast(makePair(t, reinterpret_cast(context->method), reference)); compileReferenceInvoke( frame, @@ -5270,18 +5238,18 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, index = codeReadInt16(t, code, ip); } - object pool = codePool(t, code); + GcSingleton* pool = cast(t, codePool(t, code)); if (singletonIsObject(t, pool, index - 1)) { object v = singletonObject(t, pool, index - 1); loadMemoryBarrier(); - if (objectClass(t, v) == type(t, Machine::ReferenceType)) { + if (objectClass(t, v) == type(t, GcReference::Type)) { object reference = v; PROTECT(t, reference); - v = resolveClassInPool(t, context->method, index - 1, false); + v = reinterpret_cast(resolveClassInPool(t, context->method, index - 1, false)); if (UNLIKELY(v == 0)) { frame->push( @@ -5294,12 +5262,12 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ir::Type::object(), 2, c->threadRegister(), - frame->append(makePair(t, context->method, reference)))); + frame->append(reinterpret_cast(makePair(t, reinterpret_cast(context->method), reference))))); } } if (v) { - if (objectClass(t, v) == type(t, Machine::ClassType)) { + if (objectClass(t, v) == type(t, GcClass::Type)) { frame->push(ir::Type::object(), c->call(c->constant(getThunk(t, getJClass64Thunk), ir::Type::iptr()), @@ -5325,7 +5293,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case ldc2_w: { uint16_t index = codeReadInt16(t, code, ip); - object pool = codePool(t, code); + GcSingleton* pool = cast(t, codePool(t, code)); uint64_t v; memcpy(&v, &singletonValue(t, pool, index - 1), 8); @@ -5554,19 +5522,19 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, uint8_t dimensions = codeBody(t, code, ip++); object reference = singletonObject - (t, codePool(t, methodCode(t, context->method)), index - 1); + (t, cast(t, codePool(t, context->method->code())), index - 1); PROTECT(t, reference); - object class_ = resolveClassInPool(t, context->method, index - 1, false); + GcClass* class_ = resolveClassInPool(t, context->method, index - 1, false); object argument; Thunk thunk; if (LIKELY(class_)) { - argument = class_; + argument = reinterpret_cast(class_); thunk = makeMultidimensionalArrayThunk; } else { - argument = makePair(t, context->method, reference); + argument = reinterpret_cast(makePair(t, reinterpret_cast(context->method), reference)); thunk = makeMultidimensionalArrayFromReferenceThunk; } @@ -5592,25 +5560,25 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case new_: { uint16_t index = codeReadInt16(t, code, ip); - + object reference = singletonObject - (t, codePool(t, methodCode(t, context->method)), index - 1); + (t, cast(t, codePool(t, context->method->code())), index - 1); PROTECT(t, reference); - object class_ = resolveClassInPool(t, context->method, index - 1, false); + GcClass* class_ = resolveClassInPool(t, context->method, index - 1, false); object argument; Thunk thunk; if (LIKELY(class_)) { - argument = class_; - if (classVmFlags(t, class_) & (WeakReferenceFlag | HasFinalizerFlag)) { + argument = reinterpret_cast(class_); + if (class_->vmFlags() & (WeakReferenceFlag | HasFinalizerFlag)) { thunk = makeNewGeneral64Thunk; } else { thunk = makeNew64Thunk; } } else { - argument = makePair(t, context->method, reference); + argument = reinterpret_cast(makePair(t, reinterpret_cast(context->method), reference)); thunk = makeNewFromReferenceThunk; } @@ -5654,9 +5622,9 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case putfield: case putstatic: { uint16_t index = codeReadInt16(t, code, ip); - + object reference = singletonObject - (t, codePool(t, methodCode(t, context->method)), index - 1); + (t, cast(t, codePool(t, context->method->code())), index - 1); PROTECT(t, reference); @@ -5670,7 +5638,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, if (instruction == putstatic) { checkField(t, field, true); - if (classNeedsInit(t, fieldClass(t, field))) { + if (classNeedsInit(t, cast(t, fieldClass(t, field)))) { PROTECT(t, field); c->call( @@ -5683,7 +5651,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->append(fieldClass(t, field))); } - staticTable = classStaticTable(t, fieldClass(t, field)); + staticTable = classStaticTable(t, fieldClass(t, field)); } else { checkField(t, field, false); @@ -5821,7 +5789,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ir::Value* value = popField(t, frame, fieldCode); ir::Type rType = operandTypeForFieldCode(t, fieldCode); - object pair = makePair(t, context->method, reference); + object pair = reinterpret_cast(makePair(t, reinterpret_cast(context->method), reference)); switch (fieldCode) { case ByteField: @@ -5958,10 +5926,10 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, uint32_t defaultIp = base + codeReadInt32(t, code, ip); assert(t, defaultIp < codeLength(t, code)); - + int32_t bottom = codeReadInt32(t, code, ip); int32_t top = codeReadInt32(t, code, ip); - + avian::codegen::Promise* start = 0; unsigned count = top - bottom + 1; uint32_t* ipTable = static_cast @@ -6199,7 +6167,7 @@ resolveIpForwards(Context* context, int start, int end) while (start < end and context->visitTable[start] == 0) { ++ start; } - + if (start >= end) { return -1; } else { @@ -6211,15 +6179,15 @@ int resolveIpBackwards(Context* context, int start, int end) { Thread* t = context->thread; - if (start >= static_cast(codeLength(t, methodCode(t, context->method)) + if (start >= static_cast(codeLength(t, context->method->code()) * (context->subroutineCount + 1))) { - start = codeLength(t, methodCode(t, context->method)); + start = codeLength(t, context->method->code()); } else { while (start >= end and context->visitTable[start] == 0) { -- start; } } - + if (start < end) { return -1; } else { @@ -6234,7 +6202,7 @@ truncateIntArray(Thread* t, object array, unsigned length) PROTECT(t, array); - object newArray = makeIntArray(t, length); + object newArray = reinterpret_cast(makeIntArray(t, length)); if (length) { memcpy(&intArrayBody(t, newArray, 0), &intArrayBody(t, array, 0), length * 4); @@ -6250,7 +6218,7 @@ truncateArray(Thread* t, object array, unsigned length) PROTECT(t, array); - object newArray = makeArray(t, length); + object newArray = reinterpret_cast(makeArray(t, length)); if (length) { memcpy(&arrayBody(t, newArray, 0), &arrayBody(t, array, 0), length * BytesPerWord); @@ -6266,7 +6234,7 @@ truncateLineNumberTable(Thread* t, object table, unsigned length) PROTECT(t, table); - object newTable = makeLineNumberTable(t, length); + object newTable = reinterpret_cast(makeLineNumberTable(t, length)); if (length) { memcpy(&lineNumberTableBody(t, newTable, 0), &lineNumberTableBody(t, table, 0), @@ -6284,7 +6252,7 @@ object translateExceptionHandlerTable(MyThread* t, avian::codegen::Compiler* c = context->compiler; object oldTable = codeExceptionHandlerTable - (t, methodCode(t, context->method)); + (t, context->method->code()); if (oldTable) { PROTECT(t, oldTable); @@ -6292,16 +6260,16 @@ object translateExceptionHandlerTable(MyThread* t, unsigned length = exceptionHandlerTableLength(t, oldTable); object newIndex - = makeIntArray(t, length * (context->subroutineCount + 1) * 3); + = reinterpret_cast(makeIntArray(t, length * (context->subroutineCount + 1) * 3)); PROTECT(t, newIndex); - object newTable = makeArray(t, length * (context->subroutineCount + 1) + 1); + object newTable = reinterpret_cast(makeArray(t, length * (context->subroutineCount + 1) + 1)); PROTECT(t, newTable); unsigned ni = 0; for (unsigned subI = 0; subI <= context->subroutineCount; ++subI) { unsigned duplicatedBaseIp - = subI * codeLength(t, methodCode(t, context->method)); + = subI * codeLength(t, context->method->code()); for (unsigned oi = 0; oi < length; ++oi) { uint64_t oldHandler = exceptionHandlerTableBody(t, oldTable, oi); @@ -6315,7 +6283,7 @@ object translateExceptionHandlerTable(MyThread* t, assert( t, handlerStart - < static_cast(codeLength(t, methodCode(t, context->method)) + < static_cast(codeLength(t, context->method->code()) * (context->subroutineCount + 1))); int handlerEnd = resolveIpBackwards( @@ -6326,7 +6294,7 @@ object translateExceptionHandlerTable(MyThread* t, assert(t, handlerEnd >= 0); assert(t, handlerEnd <= static_cast( - codeLength(t, methodCode(t, context->method)) + codeLength(t, context->method->code()) * (context->subroutineCount + 1))); intArrayBody(t, newIndex, ni* 3) = c->machineIp(handlerStart)->value() @@ -6334,7 +6302,7 @@ object translateExceptionHandlerTable(MyThread* t, intArrayBody(t, newIndex, (ni* 3) + 1) = (handlerEnd == static_cast(codeLength( - t, methodCode(t, context->method))) + t, context->method->code())) ? end : c->machineIp(handlerEnd)->value()) - start; @@ -6343,8 +6311,8 @@ object translateExceptionHandlerTable(MyThread* t, object type; if (exceptionHandlerCatchType(oldHandler)) { - type = resolveClassInPool( - t, context->method, exceptionHandlerCatchType(oldHandler) - 1); + type = reinterpret_cast(resolveClassInPool( + t, context->method, exceptionHandlerCatchType(oldHandler) - 1)); } else { type = 0; } @@ -6372,12 +6340,12 @@ object translateExceptionHandlerTable(MyThread* t, object translateLineNumberTable(MyThread* t, Context* context, intptr_t start) { - object oldTable = codeLineNumberTable(t, methodCode(t, context->method)); + object oldTable = codeLineNumberTable(t, context->method->code()); if (oldTable) { PROTECT(t, oldTable); unsigned length = lineNumberTableLength(t, oldTable); - object newTable = makeLineNumberTable(t, length); + object newTable = reinterpret_cast(makeLineNumberTable(t, length)); unsigned ni = 0; for (unsigned oi = 0; oi < length; ++oi) { uint64_t oldLine = lineNumberTableBody(t, oldTable, oi); @@ -6584,7 +6552,7 @@ unsigned calculateFrameMaps(MyThread* t, printSet(RUNTIME_ARRAY_BODY(roots), mapSize); fprintf(stderr, "\n"); } - + uintptr_t* map; bool watch; map = te->map; @@ -6640,7 +6608,7 @@ compareTraceElementPointers(const void* va, const void* vb) } unsigned -simpleFrameMapTableSize(MyThread* t, object method, object map) +simpleFrameMapTableSize(MyThread* t, GcMethod* method, object map) { int size = frameMapSizeInBits(t, method); return ceilingDivide(intArrayLength(t, map) * size, 32 + size); @@ -6743,12 +6711,12 @@ class FrameMapTablePath { }; object -makeSimpleFrameMapTable(MyThread* t, Context* context, uint8_t* start, +makeSimpleFrameMapTable(MyThread* t, Context* context, uint8_t* start, TraceElement** elements, unsigned elementCount) { unsigned mapSize = frameMapSizeInBits(t, context->method); - object table = makeIntArray - (t, elementCount + ceilingDivide(elementCount * mapSize, 32)); + object table = reinterpret_cast(makeIntArray + (t, elementCount + ceilingDivide(elementCount * mapSize, 32))); assert(t, intArrayLength(t, table) == elementCount + simpleFrameMapTableSize(t, context->method, table)); @@ -6783,22 +6751,22 @@ finish(MyThread* t, FixedAllocator* allocator, Context* context) logCompile (t, 0, 0, reinterpret_cast - (&byteArrayBody(t, className(t, methodClass(t, context->method)), 0)), + (&byteArrayBody(t, className(t, context->method->class_()), 0)), reinterpret_cast - (&byteArrayBody(t, methodName(t, context->method), 0)), + (&byteArrayBody(t, context->method->name(), 0)), reinterpret_cast - (&byteArrayBody(t, methodSpec(t, context->method), 0))); + (&byteArrayBody(t, context->method->spec(), 0))); } // for debugging: if (false and ::strcmp (reinterpret_cast - (&byteArrayBody(t, className(t, methodClass(t, context->method)), 0)), + (&byteArrayBody(t, className(t, context->method->class_()), 0)), "java/lang/System") == 0 and ::strcmp (reinterpret_cast - (&byteArrayBody(t, methodName(t, context->method), 0)), + (&byteArrayBody(t, context->method->name(), 0)), "") == 0) { trap(); @@ -6830,7 +6798,7 @@ finish(MyThread* t, FixedAllocator* allocator, Context* context) if (context->objectPool) { object pool = allocate3 (t, allocator, Machine::ImmortalAllocation, - FixedSizeOfArray + ((context->objectPoolCount + 1) * BytesPerWord), + GcArray::FixedSize + ((context->objectPoolCount + 1) * BytesPerWord), true); context->executableSize = (allocator->memory.begin() + allocator->offset) @@ -6873,14 +6841,14 @@ finish(MyThread* t, FixedAllocator* allocator, Context* context) object newLineNumberTable = translateLineNumberTable (t, context, reinterpret_cast(start)); - object code = methodCode(t, context->method); + object code = context->method->code(); - code = makeCode + code = reinterpret_cast(makeCode (t, 0, newExceptionHandlerTable, newLineNumberTable, reinterpret_cast(start), codeSize, codeMaxStack(t, code), - codeMaxLocals(t, code), 0); + codeMaxLocals(t, code), 0)); - set(t, context->method, MethodCode, code); + set(t, reinterpret_cast(context->method), MethodCode, code); } if (context->traceLogCount) { @@ -6897,8 +6865,8 @@ finish(MyThread* t, FixedAllocator* allocator, Context* context) if (p->target) { insertCallNode - (t, makeCallNode - (t, p->address->value(), p->target, p->flags, 0)); + (t, reinterpret_cast(makeCallNode + (t, p->address->value(), reinterpret_cast(p->target), p->flags, 0))); } } } @@ -6909,27 +6877,27 @@ finish(MyThread* t, FixedAllocator* allocator, Context* context) object map = makeSimpleFrameMapTable( t, context, start, RUNTIME_ARRAY_BODY(elements), index); - set(t, methodCode(t, context->method), CodePool, map); + set(t, context->method->code(), CodePool, map); } logCompile (t, start, codeSize, reinterpret_cast - (&byteArrayBody(t, className(t, methodClass(t, context->method)), 0)), + (&byteArrayBody(t, className(t, context->method->class_()), 0)), reinterpret_cast - (&byteArrayBody(t, methodName(t, context->method), 0)), + (&byteArrayBody(t, context->method->name(), 0)), reinterpret_cast - (&byteArrayBody(t, methodSpec(t, context->method), 0))); + (&byteArrayBody(t, context->method->spec(), 0))); // for debugging: if (false and ::strcmp (reinterpret_cast - (&byteArrayBody(t, className(t, methodClass(t, context->method)), 0)), + (&byteArrayBody(t, className(t, context->method->class_()), 0)), "java/lang/System") == 0 and ::strcmp (reinterpret_cast - (&byteArrayBody(t, methodName(t, context->method), 0)), + (&byteArrayBody(t, context->method->name(), 0)), "") == 0) { trap(); @@ -6945,28 +6913,28 @@ compile(MyThread* t, Context* context) avian::codegen::Compiler* c = context->compiler; // fprintf(stderr, "compiling %s.%s%s\n", -// &byteArrayBody(t, className(t, methodClass(t, context->method)), 0), -// &byteArrayBody(t, methodName(t, context->method), 0), -// &byteArrayBody(t, methodSpec(t, context->method), 0)); +// &byteArrayBody(t, className(t, context->method->class_()), 0), +// &byteArrayBody(t, context->method->name(), 0), +// &byteArrayBody(t, context->method->spec(), 0)); - unsigned footprint = methodParameterFootprint(t, context->method); + unsigned footprint = context->method->parameterFootprint(); unsigned locals = localSize(t, context->method); - c->init(codeLength(t, methodCode(t, context->method)), footprint, locals, + c->init(codeLength(t, context->method->code()), footprint, locals, alignedFrameSize(t, context->method)); ir::Type* stackMap = (ir::Type*)malloc( - sizeof(ir::Type) * codeMaxStack(t, methodCode(t, context->method))); + sizeof(ir::Type) * codeMaxStack(t, context->method->code())); Frame frame(context, stackMap); - unsigned index = methodParameterFootprint(t, context->method); - if ((methodFlags(t, context->method) & ACC_STATIC) == 0) { + unsigned index = context->method->parameterFootprint(); + if ((context->method->flags() & ACC_STATIC) == 0) { frame.set(--index, ir::Type::object()); c->initLocal(index, ir::Type::object()); } for (MethodSpecIterator it (t, reinterpret_cast - (&byteArrayBody(t, methodSpec(t, context->method), 0))); + (&byteArrayBody(t, context->method->spec(), 0))); it.hasNext();) { switch (*it.next()) { @@ -7009,7 +6977,7 @@ compile(MyThread* t, Context* context) context->dirtyRoots = false; unsigned eventIndex = calculateFrameMaps(t, context, 0, 0, 0); - object eht = codeExceptionHandlerTable(t, methodCode(t, context->method)); + object eht = codeExceptionHandlerTable(t, context->method->code()); if (eht) { PROTECT(t, eht); @@ -7024,7 +6992,7 @@ compile(MyThread* t, Context* context) for (unsigned subI = 0; subI <= context->subroutineCount; ++subI) { unsigned duplicatedBaseIp - = subI * codeLength(t, methodCode(t, context->method)); + = subI * codeLength(t, context->method->code()); for (unsigned i = 0; i < exceptionHandlerTableLength(t, eht); ++i) { uint64_t eh = exceptionHandlerTableBody(t, eht, i); @@ -7042,7 +7010,7 @@ compile(MyThread* t, Context* context) ir::Type* stackMap = (ir::Type*)malloc( sizeof(ir::Type) - * codeMaxStack(t, methodCode(t, context->method))); + * codeMaxStack(t, context->method->code())); Frame frame2(&frame, stackMap); unsigned end = duplicatedBaseIp + exceptionHandlerEnd(eh); @@ -7056,7 +7024,7 @@ compile(MyThread* t, Context* context) context->eventLog.append2(end); for (unsigned i = 1; - i < codeMaxStack(t, methodCode(t, context->method)); + i < codeMaxStack(t, context->method->code()); ++i) { frame2.set(localSize(t, context->method) + i, ir::Type::i4()); } @@ -7103,7 +7071,7 @@ compileMethod(MyThread* t) } void* -compileVirtualMethod2(MyThread* t, object class_, unsigned index) +compileVirtualMethod2(MyThread* t, GcClass* class_, unsigned index) { // If class_ has BootstrapFlag set, that means its vtable is not yet // available. However, we must set t->trace->targetMethod to an @@ -7111,26 +7079,26 @@ compileVirtualMethod2(MyThread* t, object class_, unsigned index) // GC roots. We find such a method by looking for a superclass with // a vtable and using it instead: - object c = class_; + object c = reinterpret_cast(class_); while (classVmFlags(t, c) & BootstrapFlag) { c = classSuper(t, c); } - t->trace->targetMethod = arrayBody(t, classVirtualTable(t, c), index); + t->trace->targetMethod = cast(t, arrayBody(t, classVirtualTable(t, c), index)); THREAD_RESOURCE0(t, static_cast(t)->trace->targetMethod = 0;); PROTECT(t, class_); - object target = resolveTarget(t, class_, index); + GcMethod* target = resolveTarget(t, class_, index); PROTECT(t, target); compile(t, codeAllocator(t), 0, target); void* address = reinterpret_cast(methodAddress(t, target)); - if (methodFlags(t, target) & ACC_NATIVE) { + if (target->flags() & ACC_NATIVE) { t->trace->nativeMethod = target; } else { - classVtable(t, class_, methodOffset(t, target)) = address; + classVtable(t, reinterpret_cast(class_), target->offset()) = address; } return address; } @@ -7138,7 +7106,7 @@ compileVirtualMethod2(MyThread* t, object class_, unsigned index) uint64_t compileVirtualMethod(MyThread* t) { - object class_ = objectClass(t, static_cast(t->virtualCallTarget)); + GcClass* class_ = objectClass(t, static_cast(t->virtualCallTarget)); t->virtualCallTarget = 0; unsigned index = t->virtualCallIndex; @@ -7148,7 +7116,7 @@ compileVirtualMethod(MyThread* t) } uint64_t -invokeNativeFast(MyThread* t, object method, void* function) +invokeNativeFast(MyThread* t, GcMethod* method, void* function) { FastNativeFunction f; memcpy(&f, &function, sizeof(void*)); return f(t, method, @@ -7158,15 +7126,15 @@ invokeNativeFast(MyThread* t, object method, void* function) } uint64_t -invokeNativeSlow(MyThread* t, object method, void* function) +invokeNativeSlow(MyThread* t, GcMethod* method, void* function) { PROTECT(t, method); - unsigned footprint = methodParameterFootprint(t, method) + 1; - if (methodFlags(t, method) & ACC_STATIC) { + unsigned footprint = method->parameterFootprint() + 1; + if (method->flags() & ACC_STATIC) { ++ footprint; } - unsigned count = methodParameterCount(t, method) + 2; + unsigned count = method->parameterCount() + 2; THREAD_RUNTIME_ARRAY(t, uintptr_t, args, footprint); unsigned argOffset = 0; @@ -7183,8 +7151,8 @@ invokeNativeSlow(MyThread* t, object method, void* function) object jclass = 0; PROTECT(t, jclass); - if (methodFlags(t, method) & ACC_STATIC) { - jclass = getJClass(t, methodClass(t, method)); + if (method->flags() & ACC_STATIC) { + jclass = getJClass(t, cast(t, method->class_())); RUNTIME_ARRAY_BODY(args)[argOffset++] = reinterpret_cast(&jclass); } else { @@ -7195,8 +7163,8 @@ invokeNativeSlow(MyThread* t, object method, void* function) MethodSpecIterator it (t, reinterpret_cast - (&byteArrayBody(t, methodSpec(t, method), 0))); - + (&byteArrayBody(t, method->spec(), 0))); + while (it.hasNext()) { unsigned type = RUNTIME_ARRAY_BODY(types)[typeOffset++] = fieldType(t, fieldCode(t, *it.next())); @@ -7230,19 +7198,19 @@ invokeNativeSlow(MyThread* t, object method, void* function) } } - unsigned returnCode = methodReturnCode(t, method); + unsigned returnCode = method->returnCode(); unsigned returnType = fieldType(t, returnCode); uint64_t result; if (DebugNatives) { fprintf(stderr, "invoke native method %s.%s\n", - &byteArrayBody(t, className(t, methodClass(t, method)), 0), - &byteArrayBody(t, methodName(t, method), 0)); + &byteArrayBody(t, className(t, method->class_()), 0), + &byteArrayBody(t, method->name(), 0)); } - if (methodFlags(t, method) & ACC_SYNCHRONIZED) { - if (methodFlags(t, method) & ACC_STATIC) { - acquire(t, methodClass(t, method)); + if (method->flags() & ACC_SYNCHRONIZED) { + if (method->flags() & ACC_STATIC) { + acquire(t, method->class_()); } else { acquire(t, *reinterpret_cast(RUNTIME_ARRAY_BODY(args)[1])); } @@ -7264,9 +7232,9 @@ invokeNativeSlow(MyThread* t, object method, void* function) returnType); } - if (methodFlags(t, method) & ACC_SYNCHRONIZED) { - if (methodFlags(t, method) & ACC_STATIC) { - release(t, methodClass(t, method)); + if (method->flags() & ACC_SYNCHRONIZED) { + if (method->flags() & ACC_STATIC) { + release(t, method->class_()); } else { release(t, *reinterpret_cast(RUNTIME_ARRAY_BODY(args)[1])); } @@ -7274,8 +7242,8 @@ invokeNativeSlow(MyThread* t, object method, void* function) if (DebugNatives) { fprintf(stderr, "return from native method %s.%s\n", - &byteArrayBody(t, className(t, methodClass(t, method)), 0), - &byteArrayBody(t, methodName(t, method), 0)); + &byteArrayBody(t, className(t, method->class_()), 0), + &byteArrayBody(t, method->name(), 0)); } if (UNLIKELY(t->exception)) { @@ -7325,9 +7293,9 @@ invokeNativeSlow(MyThread* t, object method, void* function) return result; } - + uint64_t -invokeNative2(MyThread* t, object method) +invokeNative2(MyThread* t, GcMethod* method) { object native = methodRuntimeDataNative(t, getMethodRuntimeData(t, method)); if (nativeFast(t, native)) { @@ -7350,7 +7318,7 @@ invokeNative(MyThread* t) } object node = findCallNode(t, ip); - object target = callNodeTarget(t, node); + GcMethod* target = cast(t, callNodeTarget(t, node)); if (callNodeFlags(t, node) & TraceElement::VirtualCall) { target = resolveTarget(t, t->stack, target); } @@ -7367,8 +7335,7 @@ invokeNative(MyThread* t) result = invokeNative2(t, t->trace->nativeMethod); - unsigned parameterFootprint = methodParameterFootprint - (t, t->trace->targetMethod); + unsigned parameterFootprint = t->trace->targetMethod->parameterFootprint(); uintptr_t* stack = static_cast(t->stack); @@ -7391,20 +7358,20 @@ invokeNative(MyThread* t) } void -findFrameMapInSimpleTable(MyThread* t, object method, object table, +findFrameMapInSimpleTable(MyThread* t, GcMethod* method, object table, int32_t offset, int32_t** map, unsigned* start) { unsigned tableSize = simpleFrameMapTableSize(t, method, table); unsigned indexSize = intArrayLength(t, table) - tableSize; *map = &intArrayBody(t, table, indexSize); - + unsigned bottom = 0; unsigned top = indexSize; for (unsigned span = top - bottom; span; span = top - bottom) { unsigned middle = bottom + (span / 2); int32_t v = intArrayBody(t, table, middle); - + if (offset == v) { *start = frameMapSizeInBits(t, method) * middle; return; @@ -7419,13 +7386,13 @@ findFrameMapInSimpleTable(MyThread* t, object method, object table, } unsigned -findFrameMap(MyThread* t, void* stack, object method, object table, +findFrameMap(MyThread* t, void* stack, GcMethod* method, object table, unsigned pathIndex) { if (pathIndex) { FrameMapTablePath* path = reinterpret_cast (&byteArrayBody(t, table, pathIndex)); - + void* address = static_cast(stack)[path->stackIndex]; uint8_t* base = reinterpret_cast(methodAddress(t, method)); for (unsigned i = 0; i < path->elementCount; ++i) { @@ -7442,7 +7409,7 @@ findFrameMap(MyThread* t, void* stack, object method, object table, } void -findFrameMapInGeneralTable(MyThread* t, void* stack, object method, +findFrameMapInGeneralTable(MyThread* t, void* stack, GcMethod* method, object table, int32_t offset, int32_t** map, unsigned* start) { @@ -7460,7 +7427,7 @@ findFrameMapInGeneralTable(MyThread* t, void* stack, object method, for (unsigned span = top - bottom; span; span = top - bottom) { unsigned middle = bottom + (span / 2); FrameMapTableIndexElement* v = index + middle; - + if (offset == v->offset) { *start = v->base + (findFrameMap(t, stack, method, table, v->path) * frameMapSizeInBits(t, method)); @@ -7476,11 +7443,11 @@ findFrameMapInGeneralTable(MyThread* t, void* stack, object method, } void -findFrameMap(MyThread* t, void* stack, object method, int32_t offset, +findFrameMap(MyThread* t, void* stack, GcMethod* method, int32_t offset, int32_t** map, unsigned* start) { - object table = codePool(t, methodCode(t, method)); - if (objectClass(t, table) == type(t, Machine::IntArrayType)) { + object table = codePool(t, method->code()); + if (objectClass(t, table) == type(t, GcIntArray::Type)) { findFrameMapInSimpleTable(t, method, table, offset, map, start); } else { findFrameMapInGeneralTable(t, stack, method, table, offset, map, start); @@ -7488,7 +7455,7 @@ findFrameMap(MyThread* t, void* stack, object method, int32_t offset, } void -visitStackAndLocals(MyThread* t, Heap::Visitor* v, void* frame, object method, +visitStackAndLocals(MyThread* t, Heap::Visitor* v, void* frame, GcMethod* method, void* ip) { unsigned count = frameMapSizeInBits(t, method); @@ -7505,7 +7472,7 @@ visitStackAndLocals(MyThread* t, Heap::Visitor* v, void* frame, object method, for (unsigned i = 0; i < count; ++i) { int j = offset + i; if (map[j / 32] & (static_cast(1) << (j % 32))) { - v->visit(localObject(t, stack, method, i)); + v->visit(localObject(t, stack, method, i)); } } } @@ -7521,17 +7488,17 @@ visitArgument(MyThread* t, Heap::Visitor* v, void* stack, unsigned index) } void -visitArguments(MyThread* t, Heap::Visitor* v, void* stack, object method) +visitArguments(MyThread* t, Heap::Visitor* v, void* stack, GcMethod* method) { unsigned index = 0; - if ((methodFlags(t, method) & ACC_STATIC) == 0) { + if ((method->flags() & ACC_STATIC) == 0) { visitArgument(t, v, stack, index++); } for (MethodSpecIterator it (t, reinterpret_cast - (&byteArrayBody(t, methodSpec(t, method), 0))); + (&byteArrayBody(t, method->spec(), 0))); it.hasNext();) { switch (*it.next()) { @@ -7539,7 +7506,7 @@ visitArguments(MyThread* t, Heap::Visitor* v, void* stack, object method) case '[': visitArgument(t, v, stack, index++); break; - + case 'J': case 'D': index += 2; @@ -7559,8 +7526,8 @@ visitStack(MyThread* t, Heap::Visitor* v) void* stack = t->stack; MyThread::CallTrace* trace = t->trace; - object targetMethod = (trace ? trace->targetMethod : 0); - object target = targetMethod; + GcMethod* targetMethod = (trace ? trace->targetMethod : 0); + GcMethod* target = targetMethod; bool mostRecent = true; while (stack) { @@ -7569,7 +7536,7 @@ visitStack(MyThread* t, Heap::Visitor* v) targetMethod = 0; } - object method = methodForIp(t, ip); + GcMethod* method = methodForIp(t, ip); if (method) { PROTECT(t, method); @@ -7605,8 +7572,8 @@ walkContinuationBody(MyThread* t, Heap::Walker* w, object c, int start) { const int BodyOffset = ContinuationBody / BytesPerWord; - object method = static_cast - (t->m->heap->follow(continuationMethod(t, c))); + GcMethod* method = cast(t, static_cast + (t->m->heap->follow(continuationMethod(t, c)))); int count = frameMapSizeInBits(t, method); if (count) { @@ -7664,16 +7631,16 @@ callContinuation(MyThread* t, object continuation, object result, } int8_t* -returnSpec(MyThread* t, object method) +returnSpec(MyThread* t, GcMethod* method) { - int8_t* s = &byteArrayBody(t, methodSpec(t, method), 0); + int8_t* s = &byteArrayBody(t, method->spec(), 0); while (*s and *s != ')') ++ s; expect(t, *s == ')'); return s + 1; } -object -returnClass(MyThread* t, object method) +GcClass* +returnClass(MyThread* t, GcMethod* method) { PROTECT(t, method); @@ -7681,54 +7648,54 @@ returnClass(MyThread* t, object method) unsigned length = strlen(reinterpret_cast(spec)); object name; if (*spec == '[') { - name = makeByteArray(t, length + 1); + name = reinterpret_cast(makeByteArray(t, length + 1)); memcpy(&byteArrayBody(t, name, 0), spec, length); } else { assert(t, *spec == 'L'); assert(t, spec[length - 1] == ';'); - name = makeByteArray(t, length - 1); + name = reinterpret_cast(makeByteArray(t, length - 1)); memcpy(&byteArrayBody(t, name, 0), spec + 1, length - 2); } - return resolveClass(t, classLoader(t, methodClass(t, method)), name); + return resolveClass(t, classLoader(t, method->class_()), name); } bool -compatibleReturnType(MyThread* t, object oldMethod, object newMethod) +compatibleReturnType(MyThread* t, GcMethod* oldMethod, GcMethod* newMethod) { if (oldMethod == newMethod) { return true; - } else if (methodReturnCode(t, oldMethod) == methodReturnCode(t, newMethod)) + } else if (oldMethod->returnCode() == newMethod->returnCode()) { - if (methodReturnCode(t, oldMethod) == ObjectField) { + if (oldMethod->returnCode() == ObjectField) { PROTECT(t, newMethod); - object oldClass = returnClass(t, oldMethod); + GcClass* oldClass = returnClass(t, oldMethod); PROTECT(t, oldClass); - object newClass = returnClass(t, newMethod); + GcClass* newClass = returnClass(t, newMethod); return isAssignableFrom(t, oldClass, newClass); } else { return true; } } else { - return methodReturnCode(t, oldMethod) == VoidField; + return oldMethod->returnCode() == VoidField; } } void -jumpAndInvoke(MyThread* t, object method, void* stack, ...) +jumpAndInvoke(MyThread* t, GcMethod* method, void* stack, ...) { t->trace->targetMethod = 0; - if (methodFlags(t, method) & ACC_NATIVE) { + if (method->flags() & ACC_NATIVE) { t->trace->nativeMethod = method; } else { t->trace->nativeMethod = 0; } - unsigned argumentCount = methodParameterFootprint(t, method); + unsigned argumentCount = method->parameterFootprint(); THREAD_RUNTIME_ARRAY(t, uintptr_t, arguments, argumentCount); va_list a; va_start(a, stack); for (unsigned i = 0; i < argumentCount; ++i) { @@ -7739,7 +7706,7 @@ jumpAndInvoke(MyThread* t, object method, void* stack, ...) assert(t, t->exception == 0); popResources(t); - + vmJumpAndInvoke (t, reinterpret_cast(methodAddress(t, method)), stack, @@ -7771,8 +7738,8 @@ callContinuation(MyThread* t, object continuation, object result, PROTECT(t, exception); if (compatibleReturnType - (t, t->trace->originalMethod, continuationContextMethod - (t, continuationContext(t, continuation)))) + (t, t->trace->originalMethod, cast(t, continuationContextMethod + (t, continuationContext(t, continuation))))) { object oldContext; object unwindContext; @@ -7802,7 +7769,7 @@ callContinuation(MyThread* t, object continuation, object result, and continuationContextContinuation(t, unwindContext)) { nextContinuation = continuationContextContinuation(t, unwindContext); - result = makeUnwindResult(t, continuation, result, exception); + result = reinterpret_cast(makeUnwindResult(t, continuation, result, exception)); action = Unwind; } else if (rewindContext and continuationContextContinuation(t, rewindContext)) @@ -7812,23 +7779,23 @@ callContinuation(MyThread* t, object continuation, object result, if (root(t, RewindMethod) == 0) { PROTECT(t, nextContinuation); - - object method = resolveMethod + + GcMethod* method = resolveMethod (t, root(t, Machine::BootLoader), "avian/Continuations", "rewind", "(Ljava/lang/Runnable;Lavian/Callback;Ljava/lang/Object;" "Ljava/lang/Throwable;)V"); PROTECT(t, method); - + compile(t, local::codeAllocator(t), 0, method); - - setRoot(t, RewindMethod, method); + + setRoot(t, RewindMethod, reinterpret_cast(method)); } } else { action = Call; } } else { - throwNew(t, Machine::IncompatibleContinuationExceptionType); + throwNew(t, GcIncompatibleContinuationException::Type); } } else { action = Call; @@ -7853,7 +7820,7 @@ callContinuation(MyThread* t, object continuation, object result, transition(t, 0, 0, nextContinuation, t->trace); jumpAndInvoke - (t, root(t, RewindMethod), stack, + (t, cast(t, root(t, RewindMethod)), stack, continuationContextBefore(t, continuationContext(t, nextContinuation)), continuation, result, exception); } break; @@ -7866,22 +7833,22 @@ callContinuation(MyThread* t, object continuation, object result, void callWithCurrentContinuation(MyThread* t, object receiver) { - object method = 0; + GcMethod* method = 0; void* ip = 0; void* stack = 0; { PROTECT(t, receiver); if (root(t, ReceiveMethod) == 0) { - object m = resolveMethod + GcMethod* m = resolveMethod (t, root(t, Machine::BootLoader), "avian/Function", "call", "(Ljava/lang/Object;)Ljava/lang/Object;"); if (m) { - setRoot(t, ReceiveMethod, m); + setRoot(t, ReceiveMethod, reinterpret_cast(m)); + + object continuationClass = reinterpret_cast(type(t, GcContinuation::Type)); - object continuationClass = type(t, Machine::ContinuationType); - if (classVmFlags(t, continuationClass) & BootstrapFlag) { resolveSystemClass (t, root(t, Machine::BootLoader), @@ -7891,9 +7858,9 @@ callWithCurrentContinuation(MyThread* t, object receiver) } method = findInterfaceMethod - (t, root(t, ReceiveMethod), objectClass(t, receiver)); + (t, cast(t, root(t, ReceiveMethod)), objectClass(t, receiver)); PROTECT(t, method); - + compile(t, local::codeAllocator(t), 0, method); t->continuation = makeCurrentContinuation(t, &ip, &stack); @@ -7913,27 +7880,31 @@ dynamicWind(MyThread* t, object before, object thunk, object after) PROTECT(t, after); if (root(t, WindMethod) == 0) { - object method = resolveMethod + GcMethod* method = resolveMethod (t, root(t, Machine::BootLoader), "avian/Continuations", "wind", "(Ljava/lang/Runnable;Ljava/util/concurrent/Callable;" "Ljava/lang/Runnable;)Lavian/Continuations$UnwindResult;"); if (method) { - setRoot(t, WindMethod, method); + setRoot(t, WindMethod, reinterpret_cast(method)); compile(t, local::codeAllocator(t), 0, method); } } t->continuation = makeCurrentContinuation(t, &ip, &stack); - object newContext = makeContinuationContext - (t, continuationContext(t, t->continuation), before, after, - t->continuation, t->trace->originalMethod); + object newContext = reinterpret_cast( + makeContinuationContext(t, + continuationContext(t, t->continuation), + before, + after, + t->continuation, + reinterpret_cast(t->trace->originalMethod))); set(t, t->continuation, ContinuationContext, newContext); } - jumpAndInvoke(t, root(t, WindMethod), stack, before, thunk, after); + jumpAndInvoke(t, cast(t, root(t, WindMethod)), stack, before, thunk, after); } class ArgumentList { @@ -7963,7 +7934,7 @@ class ArgumentList { addObject(va_arg(arguments, object)); } break; - + case 'J': addLong(va_arg(arguments, uint64_t)); break; @@ -7978,7 +7949,7 @@ class ArgumentList { default: addInt(va_arg(arguments, uint32_t)); - break; + break; } } } @@ -8004,7 +7975,7 @@ class ArgumentList { object* v = arguments[index++].l; addObject(v ? *v : 0); } break; - + case 'J': addLong(arguments[index++].j); break; @@ -8019,7 +7990,7 @@ class ArgumentList { default: addInt(arguments[index++].i); - break; + break; } } } @@ -8044,7 +8015,7 @@ class ArgumentList { case '[': addObject(objectArrayBody(t, arguments, index++)); break; - + case 'J': case 'D': addLong(fieldAtOffset(objectArrayBody(t, arguments, index++), 8)); @@ -8108,7 +8079,7 @@ class ArgumentList { }; object -invoke(Thread* thread, object method, ArgumentList* arguments) +invoke(Thread* thread, GcMethod* method, ArgumentList* arguments) { MyThread* t = static_cast(thread); @@ -8128,13 +8099,13 @@ invoke(Thread* thread, object method, ArgumentList* arguments) if (stackLimit == 0) { t->stackLimit = stackPosition - t->m->stackSizeInBytes; } else if (stackPosition < stackLimit) { - throwNew(t, Machine::StackOverflowErrorType); + throwNew(t, GcStackOverflowError::Type); } THREAD_RESOURCE(t, uintptr_t, stackLimit, static_cast(t)->stackLimit = stackLimit); - unsigned returnCode = methodReturnCode(t, method); + unsigned returnCode = method->returnCode(); unsigned returnType = fieldType(t, returnCode); uint64_t result; @@ -8155,11 +8126,11 @@ invoke(Thread* thread, object method, ArgumentList* arguments) returnType); } - if (t->exception) { + if (t->exception) { if (UNLIKELY(t->flags & Thread::UseBackupHeapFlag)) { collect(t, Heap::MinorCollection); } - + object exception = t->exception; t->exception = 0; vm::throw_(t, exception); @@ -8173,12 +8144,12 @@ invoke(Thread* thread, object method, ArgumentList* arguments) case ShortField: case FloatField: case IntField: - r = makeInt(t, result); + r = reinterpret_cast(makeInt(t, result)); break; case LongField: case DoubleField: - r = makeLong(t, result); + r = reinterpret_cast(makeLong(t, result)); break; case ObjectField: @@ -8198,7 +8169,7 @@ invoke(Thread* thread, object method, ArgumentList* arguments) class SignalHandler: public SignalRegistrar::Handler { public: - SignalHandler(Machine::Type type, Machine::Root root, unsigned fixedSize): + SignalHandler(Gc::Type type, Machine::Root root, unsigned fixedSize): m(0), type(type), root(root), fixedSize(fixedSize) { } virtual bool handleSignal(void** ip, void** frame, void** stack, @@ -8206,7 +8177,7 @@ class SignalHandler: public SignalRegistrar::Handler { { MyThread* t = static_cast(m->localThread->get()); if (t and t->state == Thread::ActiveState) { - object node = methodForIp(t, *ip); + GcMethod* node = methodForIp(t, *ip); if (node) { // add one to the IP since findLineNumber will subtract one // when we make the trace: @@ -8246,7 +8217,7 @@ class SignalHandler: public SignalRegistrar::Handler { } Machine* m; - Machine::Type type; + Gc::Type type; Machine::Root root; unsigned fixedSize; }; @@ -8342,12 +8313,12 @@ class MyProcessor: public Processor { heapImage(0), codeImage(0), codeImageSize(0), - segFaultHandler(Machine::NullPointerExceptionType, + segFaultHandler(GcNullPointerException::Type, Machine::NullPointerException, - FixedSizeOfNullPointerException), - divideByZeroHandler(Machine::ArithmeticExceptionType, + GcNullPointerException::FixedSize), + divideByZeroHandler(GcArithmeticException::Type, Machine::ArithmeticException, - FixedSizeOfArithmeticException), + GcArithmeticException::FixedSize), codeAllocator(s, Slice(0, 0)), callTableSize(0), useNativeFeatures(useNativeFeatures), @@ -8456,7 +8427,7 @@ class MyProcessor: public Processor { return t; } - virtual object + virtual GcMethod* makeMethod(vm::Thread* t, uint8_t vmFlags, uint8_t returnCode, @@ -8464,22 +8435,33 @@ class MyProcessor: public Processor { uint8_t parameterFootprint, uint16_t flags, uint16_t offset, - object name, - object spec, + GcByteArray* name, + GcByteArray* spec, object addendum, - object class_, - object code) + GcClass* class_, + GcCode* code) { if (code) { - codeCompiled(t, code) = local::defaultThunk(static_cast(t)); + code->compiled() = local::defaultThunk(static_cast(t)); } - return vm::makeMethod - (t, vmFlags, returnCode, parameterCount, parameterFootprint, flags, - offset, 0, 0, name, spec, addendum, class_, code); + return vm::makeMethod(t, + vmFlags, + returnCode, + parameterCount, + parameterFootprint, + flags, + offset, + 0, + 0, + reinterpret_cast(name), + reinterpret_cast(spec), + addendum, + reinterpret_cast(class_), + reinterpret_cast(code)); } - virtual object + virtual GcClass* makeClass(vm::Thread* t, uint16_t flags, uint16_t vmFlags, @@ -8495,25 +8477,40 @@ class MyProcessor: public Processor { object fieldTable, object methodTable, object staticTable, - object addendum, + object addendum, object loader, unsigned vtableLength) { - return vm::makeClass - (t, flags, vmFlags, fixedSize, arrayElementSize, arrayDimensions, - 0, objectMask, name, sourceFile, super, interfaceTable, virtualTable, - fieldTable, methodTable, staticTable, addendum, loader, 0, - vtableLength); + return vm::makeClass(t, + flags, + vmFlags, + fixedSize, + arrayElementSize, + arrayDimensions, + 0, + objectMask, + name, + sourceFile, + super, + interfaceTable, + virtualTable, + fieldTable, + methodTable, + staticTable, + addendum, + loader, + 0, + vtableLength); } virtual void - initVtable(Thread* t, object c) + initVtable(Thread* t, GcClass* c) { PROTECT(t, c); - for (int i = classLength(t, c) - 1; i >= 0; --i) { + for (int i = c->length() - 1; i >= 0; --i) { void* thunk = reinterpret_cast (virtualThunk(static_cast(t), i)); - classVtable(t, c, i) = thunk; + classVtable(t, reinterpret_cast(c), i) = thunk; } } @@ -8552,7 +8549,7 @@ class MyProcessor: public Processor { } virtual int - lineNumber(Thread* vmt, object method, int ip) + lineNumber(Thread* vmt, GcMethod* method, int ip) { return findLineNumber(static_cast(vmt), method, ip); } @@ -8598,7 +8595,7 @@ class MyProcessor: public Processor { t->referenceFrame = new (t->m->heap->allocate(sizeof(List))) List(t->reference, t->referenceFrame); - + return true; } @@ -8617,51 +8614,21 @@ class MyProcessor: public Processor { } virtual object - invokeArray(Thread* t, object method, object this_, object arguments) + invokeArray(Thread* t, GcMethod* method, object this_, object arguments) { assert(t, t->exception == 0); assert(t, t->state == Thread::ActiveState or t->state == Thread::ExclusiveState); - assert(t, ((methodFlags(t, method) & ACC_STATIC) == 0) xor (this_ == 0)); + assert(t, ((method->flags() & ACC_STATIC) == 0) xor (this_ == 0)); method = findMethod(t, method, this_); const char* spec = reinterpret_cast - (&byteArrayBody(t, methodSpec(t, method), 0)); + (&byteArrayBody(t, method->spec(), 0)); - unsigned size = methodParameterFootprint(t, method); - THREAD_RUNTIME_ARRAY(t, uintptr_t, array, size); - THREAD_RUNTIME_ARRAY(t, bool, objectMask, size); - ArgumentList list - (t, RUNTIME_ARRAY_BODY(array), size, RUNTIME_ARRAY_BODY(objectMask), - this_, spec, arguments); - - PROTECT(t, method); - - compile(static_cast(t), - local::codeAllocator(static_cast(t)), 0, method); - - return local::invoke(t, method, &list); - } - - virtual object - invokeArray(Thread* t, object method, object this_, const jvalue* arguments) - { - assert(t, t->exception == 0); - - assert(t, t->state == Thread::ActiveState - or t->state == Thread::ExclusiveState); - - assert(t, ((methodFlags(t, method) & ACC_STATIC) == 0) xor (this_ == 0)); - - method = findMethod(t, method, this_); - - const char* spec = reinterpret_cast - (&byteArrayBody(t, methodSpec(t, method), 0)); - - unsigned size = methodParameterFootprint(t, method); + unsigned size = method->parameterFootprint(); THREAD_RUNTIME_ARRAY(t, uintptr_t, array, size); THREAD_RUNTIME_ARRAY(t, bool, objectMask, size); ArgumentList list @@ -8677,7 +8644,37 @@ class MyProcessor: public Processor { } virtual object - invokeList(Thread* t, object method, object this_, bool indirectObjects, + invokeArray(Thread* t, GcMethod* method, object this_, const jvalue* arguments) + { + assert(t, t->exception == 0); + + assert(t, t->state == Thread::ActiveState + or t->state == Thread::ExclusiveState); + + assert(t, ((method->flags() & ACC_STATIC) == 0) xor (this_ == 0)); + + method = findMethod(t, method, this_); + + const char* spec = reinterpret_cast + (&byteArrayBody(t, method->spec(), 0)); + + unsigned size = method->parameterFootprint(); + THREAD_RUNTIME_ARRAY(t, uintptr_t, array, size); + THREAD_RUNTIME_ARRAY(t, bool, objectMask, size); + ArgumentList list + (t, RUNTIME_ARRAY_BODY(array), size, RUNTIME_ARRAY_BODY(objectMask), + this_, spec, arguments); + + PROTECT(t, method); + + compile(static_cast(t), + local::codeAllocator(static_cast(t)), 0, method); + + return local::invoke(t, method, &list); + } + + virtual object + invokeList(Thread* t, GcMethod* method, object this_, bool indirectObjects, va_list arguments) { assert(t, t->exception == 0); @@ -8685,14 +8682,14 @@ class MyProcessor: public Processor { assert(t, t->state == Thread::ActiveState or t->state == Thread::ExclusiveState); - assert(t, ((methodFlags(t, method) & ACC_STATIC) == 0) xor (this_ == 0)); - + assert(t, ((method->flags() & ACC_STATIC) == 0) xor (this_ == 0)); + method = findMethod(t, method, this_); const char* spec = reinterpret_cast - (&byteArrayBody(t, methodSpec(t, method), 0)); + (&byteArrayBody(t, method->spec(), 0)); - unsigned size = methodParameterFootprint(t, method); + unsigned size = method->parameterFootprint(); THREAD_RUNTIME_ARRAY(t, uintptr_t, array, size); THREAD_RUNTIME_ARRAY(t, bool, objectMask, size); ArgumentList list @@ -8724,14 +8721,14 @@ class MyProcessor: public Processor { (t, RUNTIME_ARRAY_BODY(array), size, RUNTIME_ARRAY_BODY(objectMask), this_, methodSpec, false, arguments); - object method = resolveMethod + GcMethod* method = resolveMethod (t, loader, className, methodName, methodSpec); - assert(t, ((methodFlags(t, method) & ACC_STATIC) == 0) xor (this_ == 0)); + assert(t, ((method->flags() & ACC_STATIC) == 0) xor (this_ == 0)); PROTECT(t, method); - - compile(static_cast(t), + + compile(static_cast(t), local::codeAllocator(static_cast(t)), 0, method); return local::invoke(t, method, &list); @@ -8868,7 +8865,7 @@ class MyProcessor: public Processor { virtual void compileMethod(Thread* vmt, Zone* zone, object* constants, object* calls, avian::codegen::DelayedPromise** addresses, - object method, OffsetResolver* resolver) + GcMethod* method, OffsetResolver* resolver) { MyThread* t = static_cast(vmt); BootContext bootContext(t, *constants, *calls, *addresses, zone, resolver); @@ -8937,11 +8934,11 @@ class MyProcessor: public Processor { if (image and code) { local::boot(static_cast(t), image, code); } else { - roots = makeArray(t, RootCount); + roots = reinterpret_cast(makeArray(t, RootCount)); - setRoot(t, CallTable, makeArray(t, 128)); + setRoot(t, CallTable, reinterpret_cast(makeArray(t, 128))); - setRoot(t, MethodTreeSentinal, makeTreeNode(t, 0, 0, 0)); + setRoot(t, MethodTreeSentinal, reinterpret_cast(makeTreeNode(t, 0, 0, 0))); setRoot(t, MethodTree, root(t, MethodTreeSentinal)); set(t, root(t, MethodTree), TreeNodeLeft, root(t, MethodTreeSentinal)); @@ -9013,7 +9010,7 @@ class MyProcessor: public Processor { abort(t); } } - + System* s; SignalRegistrar signals; Allocator* allocator; @@ -9089,7 +9086,7 @@ void* compileMethod2(MyThread* t, void* ip) { object node = findCallNode(t, ip); - object target = callNodeTarget(t, node); + GcMethod* target = cast(t, callNodeTarget(t, node)); PROTECT(t, node); PROTECT(t, target); @@ -9108,7 +9105,7 @@ compileMethod2(MyThread* t, void* ip) or updateIp >= p->codeImage + p->codeImageSize; uintptr_t address; - if (methodFlags(t, target) & ACC_NATIVE) { + if (target->flags() & ACC_NATIVE) { address = useLongJump(t, reinterpret_cast(ip)) or (not updateCaller) ? bootNativeThunk(t) : nativeThunk(t); } else { @@ -9177,7 +9174,7 @@ isThunkUnsafeStack(MyProcessor::ThunkCollection* thunks, void* ip) table[2] = thunks->native; table[3] = thunks->aioob; table[4] = thunks->stackOverflow; - + for (unsigned i = 0; i < ThunkCount; ++i) { new (table + NamedThunkCount + i) MyProcessor::Thunk (thunks->table.start + (i * thunks->table.length), @@ -9260,7 +9257,7 @@ resizeTable(MyThread* t, object oldTable, unsigned newLength) object oldNode = 0; PROTECT(t, oldNode); - object newTable = makeArray(t, newLength); + object newTable = reinterpret_cast(makeArray(t, newLength)); PROTECT(t, newTable); for (unsigned i = 0; i < arrayLength(t, oldTable); ++i) { @@ -9272,11 +9269,11 @@ resizeTable(MyThread* t, object oldTable, unsigned newLength) unsigned index = k & (newLength - 1); - object newNode = makeCallNode + object newNode = reinterpret_cast(makeCallNode (t, callNodeAddress(t, oldNode), callNodeTarget(t, oldNode), callNodeFlags(t, oldNode), - arrayBody(t, newTable, index)); + arrayBody(t, newTable, index))); set(t, newTable, ArrayBody + (index * BytesPerWord), newNode); } @@ -9298,7 +9295,7 @@ insertCallNode(MyThread* t, object table, unsigned* size, object node) ++ (*size); - if (*size >= arrayLength(t, table) * 2) { + if (*size >= arrayLength(t, table) * 2) { table = resizeTable(t, table, arrayLength(t, table) * 2); } @@ -9318,14 +9315,14 @@ insertCallNode(MyThread* t, object node) (t, root(t, CallTable), &(processor(t)->callTableSize), node)); } -object +GcHashMap* makeClassMap(Thread* t, unsigned* table, unsigned count, uintptr_t* heap) { - object array = makeArray(t, nextPowerOfTwo(count)); - object map = makeHashMap(t, 0, array); + object array = reinterpret_cast(makeArray(t, nextPowerOfTwo(count))); + GcHashMap* map = makeHashMap(t, 0, array); PROTECT(t, map); - + for (unsigned i = 0; i < count; ++i) { object c = bootObject(heap, table[i]); hashMapInsert(t, map, className(t, c), c, byteArrayHash); @@ -9338,8 +9335,8 @@ object makeStaticTableArray(Thread* t, unsigned* bootTable, unsigned bootCount, unsigned* appTable, unsigned appCount, uintptr_t* heap) { - object array = makeArray(t, bootCount + appCount); - + object array = reinterpret_cast(makeArray(t, bootCount + appCount)); + for (unsigned i = 0; i < bootCount; ++i) { set(t, array, ArrayBody + (i * BytesPerWord), classStaticTable(t, bootObject(heap, bootTable[i]))); @@ -9353,16 +9350,16 @@ makeStaticTableArray(Thread* t, unsigned* bootTable, unsigned bootCount, return array; } -object +GcWeakHashMap* makeStringMap(Thread* t, unsigned* table, unsigned count, uintptr_t* heap) { - object array = makeArray(t, nextPowerOfTwo(count)); - object map = makeWeakHashMap(t, 0, array); + object array = reinterpret_cast(makeArray(t, nextPowerOfTwo(count))); + GcWeakHashMap* map = makeWeakHashMap(t, 0, array); PROTECT(t, map); - + for (unsigned i = 0; i < count; ++i) { object s = bootObject(heap, table[i]); - hashMapInsert(t, map, s, 0, stringHash); + hashMapInsert(t, map->as(t), s, 0, stringHash); } return map; @@ -9372,7 +9369,7 @@ object makeCallTable(MyThread* t, uintptr_t* heap, unsigned* calls, unsigned count, uintptr_t base) { - object table = makeArray(t, nextPowerOfTwo(count)); + object table = reinterpret_cast(makeArray(t, nextPowerOfTwo(count))); PROTECT(t, table); unsigned size = 0; @@ -9380,9 +9377,9 @@ makeCallTable(MyThread* t, uintptr_t* heap, unsigned* calls, unsigned count, unsigned address = calls[i * 2]; unsigned target = calls[(i * 2) + 1]; - object node = makeCallNode + object node = reinterpret_cast(makeCallNode (t, base + address, bootObject(heap, target & BootMask), - target >> BootShift, 0); + target >> BootShift, 0)); table = insertCallNode(t, table, &size, node); } @@ -9402,7 +9399,7 @@ fixupHeap(MyThread* t UNUSED, uintptr_t* map, unsigned size, uintptr_t* heap) uintptr_t* p = heap + index; assert(t, *p); - + uintptr_t number = *p & BootMask; uintptr_t mark = *p >> BootShift; @@ -9425,7 +9422,7 @@ resetClassRuntimeState(Thread* t, object c, uintptr_t* heap, unsigned heapSize) classRuntimeDataIndex(t, c) = 0; if (classArrayElementSize(t, c) == 0) { - object staticTable = classStaticTable(t, c); + GcSingleton* staticTable = cast(t, classStaticTable(t, c)); if (staticTable) { for (unsigned i = 0; i < singletonCount(t, staticTable); ++i) { if (singletonIsObject(t, staticTable, i) @@ -9454,11 +9451,11 @@ resetClassRuntimeState(Thread* t, object c, uintptr_t* heap, unsigned heapSize) } } - t->m->processor->initVtable(t, c); + t->m->processor->initVtable(t, cast(t, c)); } void -resetRuntimeState(Thread* t, object map, uintptr_t* heap, unsigned heapSize) +resetRuntimeState(Thread* t, GcHashMap* map, uintptr_t* heap, unsigned heapSize) { for (HashMapIterator it(t, map); it.hasMore();) { resetClassRuntimeState(t, tripleSecond(t, it.next()), heap, heapSize); @@ -9466,19 +9463,19 @@ resetRuntimeState(Thread* t, object map, uintptr_t* heap, unsigned heapSize) } void -fixupMethods(Thread* t, object map, BootImage* image UNUSED, uint8_t* code) +fixupMethods(Thread* t, GcHashMap* map, BootImage* image UNUSED, uint8_t* code) { for (HashMapIterator it(t, map); it.hasMore();) { object c = tripleSecond(t, it.next()); if (classMethodTable(t, c)) { for (unsigned i = 0; i < arrayLength(t, classMethodTable(t, c)); ++i) { - object method = arrayBody(t, classMethodTable(t, c), i); - if (methodCode(t, method)) { + GcMethod* method = cast(t, arrayBody(t, classMethodTable(t, c), i)); + if (method->code()) { assert(t, methodCompiled(t, method) <= static_cast(image->codeSize)); - codeCompiled(t, methodCode(t, method)) + codeCompiled(t, method->code()) = methodCompiled(t, method) + reinterpret_cast(code); if (DebugCompile) { @@ -9487,17 +9484,17 @@ fixupMethods(Thread* t, object map, BootImage* image UNUSED, uint8_t* code) reinterpret_cast(methodCompiled(t, method)), methodCompiledSize(t, method), reinterpret_cast - (&byteArrayBody(t, className(t, methodClass(t, method)), 0)), + (&byteArrayBody(t, className(t, method->class_()), 0)), reinterpret_cast - (&byteArrayBody(t, methodName(t, method), 0)), + (&byteArrayBody(t, method->name(), 0)), reinterpret_cast - (&byteArrayBody(t, methodSpec(t, method), 0))); + (&byteArrayBody(t, method->spec(), 0))); } } } } - t->m->processor->initVtable(t, c); + t->m->processor->initVtable(t, cast(t, c)); } } @@ -9512,7 +9509,7 @@ void findThunks(MyThread* t, BootImage* image, uint8_t* code) { MyProcessor* p = processor(t); - + p->bootThunks.default_ = thunkToThunk(image->thunks.default_, code); p->bootThunks.defaultVirtual = thunkToThunk(image->thunks.defaultVirtual, code); @@ -9565,87 +9562,87 @@ boot(MyThread* t, BootImage* image, uint8_t* code) // fprintf(stderr, "code from %p to %p\n", // code, code + image->codeSize); - + if (not image->initialized) { fixupHeap(t, heapMap, heapMapSizeInWords, heap); } - + t->m->heap->setImmortalHeap(heap, image->heapSize / BytesPerWord); t->m->types = bootObject(heap, image->types); - t->m->roots = makeArray(t, Machine::RootCount); + t->m->roots = reinterpret_cast(makeArray(t, Machine::RootCount)); setRoot(t, Machine::BootLoader, bootObject(heap, image->bootLoader)); setRoot(t, Machine::AppLoader, bootObject(heap, image->appLoader)); - p->roots = makeArray(t, RootCount); - + p->roots = reinterpret_cast(makeArray(t, RootCount)); + setRoot(t, MethodTree, bootObject(heap, image->methodTree)); setRoot(t, MethodTreeSentinal, bootObject(heap, image->methodTreeSentinal)); setRoot(t, VirtualThunks, bootObject(heap, image->virtualThunks)); - { object map = makeClassMap(t, bootClassTable, image->bootClassCount, heap); + { object map = reinterpret_cast(makeClassMap(t, bootClassTable, image->bootClassCount, heap)); set(t, root(t, Machine::BootLoader), ClassLoaderMap, map); } systemClassLoaderFinder(t, root(t, Machine::BootLoader)) = t->m->bootFinder; - { object map = makeClassMap(t, appClassTable, image->appClassCount, heap); + { object map = reinterpret_cast(makeClassMap(t, appClassTable, image->appClassCount, heap)); set(t, root(t, Machine::AppLoader), ClassLoaderMap, map); } systemClassLoaderFinder(t, root(t, Machine::AppLoader)) = t->m->appFinder; - setRoot(t, Machine::StringMap, makeStringMap - (t, stringTable, image->stringCount, heap)); + setRoot(t, Machine::StringMap, reinterpret_cast(makeStringMap + (t, stringTable, image->stringCount, heap))); p->callTableSize = image->callCount; - setRoot(t, CallTable, makeCallTable + setRoot(t, CallTable, reinterpret_cast(makeCallTable (t, heap, callTable, image->callCount, - reinterpret_cast(code))); + reinterpret_cast(code)))); - setRoot(t, StaticTableArray, makeStaticTableArray + setRoot(t, StaticTableArray, reinterpret_cast(makeStaticTableArray (t, bootClassTable, image->bootClassCount, - appClassTable, image->appClassCount, heap)); - + appClassTable, image->appClassCount, heap))); + findThunks(t, image, code); if (image->initialized) { resetRuntimeState - (t, classLoaderMap(t, root(t, Machine::BootLoader)), heap, + (t, cast(t, classLoaderMap(t, root(t, Machine::BootLoader))), heap, image->heapSize); resetRuntimeState - (t, classLoaderMap(t, root(t, Machine::AppLoader)), heap, + (t, cast(t, classLoaderMap(t, root(t, Machine::AppLoader))), heap, image->heapSize); for (unsigned i = 0; i < arrayLength(t, t->m->types); ++i) { resetClassRuntimeState - (t, type(t, static_cast(i)), heap, image->heapSize); + (t, reinterpret_cast(type(t, static_cast(i))), heap, image->heapSize); } } else { fixupVirtualThunks(t, code); fixupMethods - (t, classLoaderMap(t, root(t, Machine::BootLoader)), image, code); + (t, cast(t, classLoaderMap(t, root(t, Machine::BootLoader))), image, code); fixupMethods - (t, classLoaderMap(t, root(t, Machine::AppLoader)), image, code); + (t, cast(t, classLoaderMap(t, root(t, Machine::AppLoader))), image, code); } image->initialized = true; - setRoot(t, Machine::BootstrapClassMap, makeHashMap(t, 0, 0)); + setRoot(t, Machine::BootstrapClassMap, reinterpret_cast(makeHashMap(t, 0, 0))); } intptr_t getThunk(MyThread* t, Thunk thunk) { MyProcessor* p = processor(t); - + return reinterpret_cast (p->thunks.table.start + (thunk * p->thunks.table.length)); } @@ -9695,14 +9692,14 @@ compileThunks(MyThread* t, FixedAllocator* allocator) { Context context(t); avian::codegen::Assembler* a = context.assembler; - + a->saveFrame(TARGET_THREAD_STACK, TARGET_THREAD_IP); p->thunks.default_.frameSavedOffset = a->length(); lir::Register thread(t->arch->thread()); a->pushFrame(1, TargetBytesPerWord, lir::RegisterOperand, &thread); - + compileCall(t, &context, compileMethodIndex); a->popFrame(t->arch->alignFrameSize(1)); @@ -9719,7 +9716,7 @@ compileThunks(MyThread* t, FixedAllocator* allocator) { Context context(t); avian::codegen::Assembler* a = context.assembler; - + lir::Register class_(t->arch->virtualCallTarget()); lir::Memory virtualCallTargetSrc (t->arch->stack(), @@ -9744,7 +9741,7 @@ compileThunks(MyThread* t, FixedAllocator* allocator) a->apply(lir::Move, OperandInfo(TargetBytesPerWord, lir::RegisterOperand, &index), OperandInfo(TargetBytesPerWord, lir::MemoryOperand, &virtualCallIndex)); - + a->saveFrame(TARGET_THREAD_STACK, TARGET_THREAD_IP); p->thunks.defaultVirtual.frameSavedOffset = a->length(); @@ -9753,7 +9750,7 @@ compileThunks(MyThread* t, FixedAllocator* allocator) a->pushFrame(1, TargetBytesPerWord, lir::RegisterOperand, &thread); compileCall(t, &context, compileVirtualMethodIndex); - + a->popFrame(t->arch->alignFrameSize(1)); lir::Register result(t->arch->returnLow()); @@ -9777,7 +9774,7 @@ compileThunks(MyThread* t, FixedAllocator* allocator) a->pushFrame(1, TargetBytesPerWord, lir::RegisterOperand, &thread); compileCall(t, &context, invokeNativeIndex); - + a->popFrameAndUpdateStackAndReturn (t->arch->alignFrameSize(1), TARGET_THREAD_NEWSTACK); @@ -9807,7 +9804,7 @@ compileThunks(MyThread* t, FixedAllocator* allocator) { Context context(t); avian::codegen::Assembler* a = context.assembler; - + a->saveFrame(TARGET_THREAD_STACK, TARGET_THREAD_IP); p->thunks.stackOverflow.frameSavedOffset = a->length(); @@ -9949,7 +9946,7 @@ compileVirtualThunk(MyThread* t, unsigned index, unsigned* size) a->apply(lir::Move, OperandInfo(TargetBytesPerWord, lir::ConstantOperand, &indexConstant), OperandInfo(TargetBytesPerWord, lir::RegisterOperand, &indexRegister)); - + avian::codegen::ResolvedPromise defaultVirtualThunkPromise(defaultVirtualThunk(t)); lir::Constant thunk(&defaultVirtualThunkPromise); a->apply(lir::Jump, @@ -9984,7 +9981,7 @@ virtualThunk(MyThread* t, unsigned index) if (root(t, VirtualThunks) == 0 or wordArrayLength(t, root(t, VirtualThunks)) <= index * 2) { - object newArray = makeWordArray(t, nextPowerOfTwo((index + 1) * 2)); + object newArray = reinterpret_cast(makeWordArray(t, nextPowerOfTwo((index + 1) * 2))); if (root(t, VirtualThunks)) { memcpy(&wordArrayBody(t, newArray, 0), &wordArrayBody(t, root(t, VirtualThunks), 0), @@ -10005,19 +10002,19 @@ virtualThunk(MyThread* t, unsigned index) void compile(MyThread* t, FixedAllocator* allocator, BootContext* bootContext, - object method) + GcMethod* method) { PROTECT(t, method); - if (bootContext == 0 and methodFlags(t, method) & ACC_STATIC) { - initClass(t, methodClass(t, method)); + if (bootContext == 0 and method->flags() & ACC_STATIC) { + initClass(t, cast(t, method->class_())); } if (methodAddress(t, method) != defaultThunk(t)) { return; } - assert(t, (methodFlags(t, method) & ACC_NATIVE) == 0); + assert(t, (method->flags() & ACC_NATIVE) == 0); // We must avoid acquiring any locks until after the first pass of // compilation, since this pass may trigger classloading operations @@ -10026,7 +10023,7 @@ compile(MyThread* t, FixedAllocator* allocator, BootContext* bootContext, // method so that we won't be confused if another thread updates the // original while we're working. - object clone = methodClone(t, method); + GcMethod* clone = methodClone(t, method); loadMemoryBarrier(); @@ -10039,7 +10036,7 @@ compile(MyThread* t, FixedAllocator* allocator, BootContext* bootContext, Context context(t, bootContext, clone); compile(t, &context); - { object ehTable = codeExceptionHandlerTable(t, methodCode(t, clone)); + { object ehTable = codeExceptionHandlerTable(t, clone->code()); if (ehTable) { PROTECT(t, ehTable); @@ -10063,7 +10060,7 @@ compile(MyThread* t, FixedAllocator* allocator, BootContext* bootContext, } finish(t, allocator, &context); - + if (DebugMethodTree) { fprintf(stderr, "insert method at %p\n", reinterpret_cast(methodCompiled(t, clone))); @@ -10079,18 +10076,22 @@ compile(MyThread* t, FixedAllocator* allocator, BootContext* bootContext, // clone in its place. Later, we'll replace the clone with the // original to save memory. - setRoot - (t, MethodTree, treeInsert - (t, &(context.zone), root(t, MethodTree), - methodCompiled(t, clone), clone, root(t, MethodTreeSentinal), - compareIpToMethodBounds)); + setRoot(t, + MethodTree, + treeInsert(t, + &(context.zone), + root(t, MethodTree), + methodCompiled(t, clone), + reinterpret_cast(clone), + root(t, MethodTreeSentinal), + compareIpToMethodBounds)); storeStoreMemoryBarrier(); - set(t, method, MethodCode, methodCode(t, clone)); + set(t, reinterpret_cast(method), MethodCode, clone->code()); if (methodVirtual(t, method)) { - classVtable(t, methodClass(t, method), methodOffset(t, method)) + classVtable(t, method->class_(), method->offset()) = reinterpret_cast(methodCompiled(t, clone)); } @@ -10100,7 +10101,7 @@ compile(MyThread* t, FixedAllocator* allocator, BootContext* bootContext, context.executableAllocator = 0; treeUpdate(t, root(t, MethodTree), methodCompiled(t, clone), - method, root(t, MethodTreeSentinal), compareIpToMethodBounds); + reinterpret_cast(method), root(t, MethodTreeSentinal), compareIpToMethodBounds); } object& diff --git a/src/heapdump.cpp b/src/heapdump.cpp index 22a34f67c2..80c4522ef9 100644 --- a/src/heapdump.cpp +++ b/src/heapdump.cpp @@ -80,7 +80,7 @@ dumpHeap(Thread* t, FILE* out) local::write1(out, local::Size); local::write4(out, local::objectSize(t, p)); - if (objectClass(t, p) == type(t, Machine::ClassType)) { + if (objectClass(t, p) == type(t, GcClass::Type)) { object name = className(t, p); if (name) { local::write1(out, local::ClassName); diff --git a/src/interpret.cpp b/src/interpret.cpp index 46c3fcfaed..7c8a9b076c 100644 --- a/src/interpret.cpp +++ b/src/interpret.cpp @@ -249,10 +249,10 @@ frameNext(Thread* t, int frame) return peekInt(t, frame + FrameNextOffset); } -inline object +inline GcMethod* frameMethod(Thread* t, int frame) { - return peekObject(t, frame + FrameMethodOffset); + return cast(t, peekObject(t, frame + FrameMethodOffset)); } inline unsigned @@ -304,24 +304,24 @@ setLocalLong(Thread* t, unsigned index, uint64_t value) } void -pushFrame(Thread* t, object method) +pushFrame(Thread* t, GcMethod* method) { PROTECT(t, method); - unsigned parameterFootprint = methodParameterFootprint(t, method); + unsigned parameterFootprint = method->parameterFootprint(); unsigned base = t->sp - parameterFootprint; unsigned locals = parameterFootprint; - if (methodFlags(t, method) & ACC_SYNCHRONIZED) { + if (method->flags() & ACC_SYNCHRONIZED) { // Try to acquire the monitor before doing anything else. // Otherwise, if we were to push the frame first, we risk trying // to release a monitor we never successfully acquired when we try // to pop the frame back off. - if (methodFlags(t, method) & ACC_STATIC) { - acquire(t, methodClass(t, method)); + if (method->flags() & ACC_STATIC) { + acquire(t, method->class_()); } else { acquire(t, peekObject(t, base)); - } + } } if (t->frame >= 0) { @@ -329,8 +329,8 @@ pushFrame(Thread* t, object method) } t->ip = 0; - if ((methodFlags(t, method) & ACC_NATIVE) == 0) { - t->code = methodCode(t, method); + if ((method->flags() & ACC_NATIVE) == 0) { + t->code = method->code(); locals = codeMaxLocals(t, t->code); @@ -345,27 +345,27 @@ pushFrame(Thread* t, object method) t->sp = frame + FrameFootprint; pokeInt(t, frame + FrameBaseOffset, base); - pokeObject(t, frame + FrameMethodOffset, method); + pokeObject(t, frame + FrameMethodOffset, reinterpret_cast(method)); pokeInt(t, t->frame + FrameIpOffset, 0); } void popFrame(Thread* t) { - object method = frameMethod(t, t->frame); + GcMethod* method = frameMethod(t, t->frame); - if (methodFlags(t, method) & ACC_SYNCHRONIZED) { - if (methodFlags(t, method) & ACC_STATIC) { - release(t, methodClass(t, method)); + if (method->flags() & ACC_SYNCHRONIZED) { + if (method->flags() & ACC_STATIC) { + release(t, method->class_()); } else { release(t, peekObject(t, frameBase(t, t->frame))); - } + } } t->sp = frameBase(t, t->frame); t->frame = frameNext(t, t->frame); if (t->frame >= 0) { - t->code = methodCode(t, frameMethod(t, t->frame)); + t->code = frameMethod(t, t->frame)->code(); t->ip = frameIp(t, t->frame); } else { t->code = 0; @@ -386,7 +386,7 @@ class MyStackWalker: public Processor::StackWalker { } } - virtual object method() { + virtual GcMethod* method() { return frameMethod(t, frame); } @@ -407,16 +407,16 @@ class MyStackWalker: public Processor::StackWalker { }; inline void -checkStack(Thread* t, object method) +checkStack(Thread* t, GcMethod* method) { if (UNLIKELY(t->sp - + methodParameterFootprint(t, method) - + codeMaxLocals(t, methodCode(t, method)) + + method->parameterFootprint() + + codeMaxLocals(t, method->code()) + FrameFootprint - + codeMaxStack(t, methodCode(t, method)) + + codeMaxStack(t, method->code()) > stackSizeInWords(t) / 2)) { - throwNew(t, Machine::StackOverflowErrorType); + throwNew(t, GcStackOverflowError::Type); } } @@ -490,12 +490,12 @@ pushResult(Thread* t, unsigned returnCode, uint64_t result, bool indirect) void marshalArguments(Thread* t, uintptr_t* args, uint8_t* types, unsigned sp, - object method, bool fastCallingConvention) + GcMethod* method, bool fastCallingConvention) { MethodSpecIterator it (t, reinterpret_cast - (&byteArrayBody(t, methodSpec(t, method), 0))); - + (&byteArrayBody(t, method->spec(), 0))); + unsigned argOffset = 0; unsigned typeOffset = 0; @@ -539,17 +539,17 @@ marshalArguments(Thread* t, uintptr_t* args, uint8_t* types, unsigned sp, } unsigned -invokeNativeSlow(Thread* t, object method, void* function) +invokeNativeSlow(Thread* t, GcMethod* method, void* function) { PROTECT(t, method); pushFrame(t, method); - unsigned footprint = methodParameterFootprint(t, method) + 1; - if (methodFlags(t, method) & ACC_STATIC) { + unsigned footprint = method->parameterFootprint() + 1; + if (method->flags() & ACC_STATIC) { ++ footprint; } - unsigned count = methodParameterCount(t, method) + 2; + unsigned count = method->parameterCount() + 2; THREAD_RUNTIME_ARRAY(t, uintptr_t, args, footprint); unsigned argOffset = 0; @@ -563,9 +563,9 @@ invokeNativeSlow(Thread* t, object method, void* function) PROTECT(t, jclass); unsigned sp; - if (methodFlags(t, method) & ACC_STATIC) { + if (method->flags() & ACC_STATIC) { sp = frameBase(t, t->frame); - jclass = getJClass(t, methodClass(t, method)); + jclass = getJClass(t, cast(t, method->class_())); RUNTIME_ARRAY_BODY(args)[argOffset++] = reinterpret_cast(&jclass); } else { @@ -582,16 +582,16 @@ invokeNativeSlow(Thread* t, object method, void* function) (t, RUNTIME_ARRAY_BODY(args) + argOffset, RUNTIME_ARRAY_BODY(types) + typeOffset, sp, method, false); - unsigned returnCode = methodReturnCode(t, method); + unsigned returnCode = method->returnCode(); unsigned returnType = fieldType(t, returnCode); uint64_t result; if (DebugRun) { fprintf(stderr, "invoke native method %s.%s\n", - &byteArrayBody(t, className(t, methodClass(t, method)), 0), - &byteArrayBody(t, methodName(t, method), 0)); + &byteArrayBody(t, className(t, method->class_()), 0), + &byteArrayBody(t, method->name(), 0)); } - + { ENTER(t, Thread::IdleState); bool noThrow = t->checkpoint->noThrow; @@ -609,9 +609,9 @@ invokeNativeSlow(Thread* t, object method, void* function) if (DebugRun) { fprintf(stderr, "return from native method %s.%s\n", &byteArrayBody - (t, className(t, methodClass(t, frameMethod(t, t->frame))), 0), + (t, className(t, frameMethod(t, t->frame)->class_()), 0), &byteArrayBody - (t, methodName(t, frameMethod(t, t->frame)), 0)); + (t, frameMethod(t, t->frame)->name(), 0)); } popFrame(t); @@ -628,7 +628,7 @@ invokeNativeSlow(Thread* t, object method, void* function) } unsigned -invokeNative(Thread* t, object method) +invokeNative(Thread* t, GcMethod* method) { PROTECT(t, method); @@ -641,11 +641,11 @@ invokeNative(Thread* t, object method) uint64_t result; { THREAD_RESOURCE0(t, popFrame(static_cast(t))); - unsigned footprint = methodParameterFootprint(t, method); + unsigned footprint = method->parameterFootprint(); THREAD_RUNTIME_ARRAY(t, uintptr_t, args, footprint); unsigned sp = frameBase(t, t->frame); unsigned argOffset = 0; - if ((methodFlags(t, method) & ACC_STATIC) == 0) { + if ((method->flags() & ACC_STATIC) == 0) { RUNTIME_ARRAY_BODY(args)[argOffset++] = reinterpret_cast(peekObject(t, sp++)); } @@ -657,9 +657,9 @@ invokeNative(Thread* t, object method) (nativeFunction(t, native))(t, method, RUNTIME_ARRAY_BODY(args)); } - pushResult(t, methodReturnCode(t, method), result, false); + pushResult(t, method->returnCode(), result, false); - return methodReturnCode(t, method); + return method->returnCode(); } else { return invokeNativeSlow(t, method, nativeFunction(t, native)); } @@ -686,12 +686,12 @@ isNaN(float v) } uint64_t -findExceptionHandler(Thread* t, object method, unsigned ip) +findExceptionHandler(Thread* t, GcMethod* method, unsigned ip) { PROTECT(t, method); - object eht = codeExceptionHandlerTable(t, methodCode(t, method)); - + object eht = codeExceptionHandlerTable(t, method->code()); + if (eht) { for (unsigned i = 0; i < exceptionHandlerTableLength(t, eht); ++i) { uint64_t eh = exceptionHandlerTableBody(t, eht, i); @@ -699,7 +699,7 @@ findExceptionHandler(Thread* t, object method, unsigned ip) if (ip - 1 >= exceptionHandlerStart(eh) and ip - 1 < exceptionHandlerEnd(eh)) { - object catchType = 0; + GcClass* catchType = 0; if (exceptionHandlerCatchType(eh)) { object e = t->exception; t->exception = 0; @@ -784,7 +784,7 @@ interpret3(Thread* t, const int base) object& exception = t->exception; uintptr_t* stack = t->stack; - code = methodCode(t, frameMethod(t, frame)); + code = frameMethod(t, frame)->code(); if (UNLIKELY(exception)) { goto throw_; @@ -798,9 +798,9 @@ interpret3(Thread* t, const int base) ip - 1, instruction, &byteArrayBody - (t, className(t, methodClass(t, frameMethod(t, frame))), 0), + (t, className(t, frameMethod(t, frame)->class_()), 0), &byteArrayBody - (t, methodName(t, frameMethod(t, frame)), 0)); + (t, frameMethod(t, frame)->name(), 0)); int line = findLineNumber(t, frameMethod(t, frame), ip); switch (line) { @@ -827,12 +827,12 @@ interpret3(Thread* t, const int base) pushObject(t, objectArrayBody(t, array, index)); } else { exception = makeThrowable - (t, Machine::ArrayIndexOutOfBoundsExceptionType, "%d not in [0,%d)", + (t, GcArrayIndexOutOfBoundsException::Type, "%d not in [0,%d)", index, objectArrayLength(t, array)); goto throw_; } } else { - exception = makeThrowable(t, Machine::NullPointerExceptionType); + exception = makeThrowable(t, GcNullPointerException::Type); goto throw_; } } goto loop; @@ -849,12 +849,12 @@ interpret3(Thread* t, const int base) set(t, array, ArrayBody + (index * BytesPerWord), value); } else { exception = makeThrowable - (t, Machine::ArrayIndexOutOfBoundsExceptionType, "%d not in [0,%d)", + (t, GcArrayIndexOutOfBoundsException::Type, "%d not in [0,%d)", index, objectArrayLength(t, array)); goto throw_; } } else { - exception = makeThrowable(t, Machine::NullPointerExceptionType); + exception = makeThrowable(t, GcNullPointerException::Type); goto throw_; } } goto loop; @@ -888,13 +888,13 @@ interpret3(Thread* t, const int base) if (LIKELY(count >= 0)) { uint16_t index = codeReadInt16(t, code, ip); - - object class_ = resolveClassInPool(t, frameMethod(t, frame), index - 1); - + + GcClass* class_ = resolveClassInPool(t, frameMethod(t, frame), index - 1); + pushObject(t, makeObjectArray(t, class_, count)); } else { exception = makeThrowable - (t, Machine::NegativeArraySizeExceptionType, "%d", count); + (t, GcNegativeArraySizeException::Type, "%d", count); goto throw_; } } goto loop; @@ -915,7 +915,7 @@ interpret3(Thread* t, const int base) if (LIKELY(array)) { pushInt(t, fieldAtOffset(array, BytesPerWord)); } else { - exception = makeThrowable(t, Machine::NullPointerExceptionType); + exception = makeThrowable(t, GcNullPointerException::Type); goto throw_; } } goto loop; @@ -943,7 +943,7 @@ interpret3(Thread* t, const int base) case athrow: { exception = popObject(t); if (UNLIKELY(exception == 0)) { - exception = makeThrowable(t, Machine::NullPointerExceptionType); + exception = makeThrowable(t, GcNullPointerException::Type); } } goto throw_; @@ -952,7 +952,7 @@ interpret3(Thread* t, const int base) object array = popObject(t); if (LIKELY(array)) { - if (objectClass(t, array) == type(t, Machine::BooleanArrayType)) { + if (objectClass(t, array) == type(t, GcBooleanArray::Type)) { if (LIKELY(index >= 0 and static_cast(index) < booleanArrayLength(t, array))) @@ -960,7 +960,7 @@ interpret3(Thread* t, const int base) pushInt(t, booleanArrayBody(t, array, index)); } else { exception = makeThrowable - (t, Machine::ArrayIndexOutOfBoundsExceptionType, + (t, GcArrayIndexOutOfBoundsException::Type, "%d not in [0,%d)", index, booleanArrayLength(t, array)); goto throw_; } @@ -972,13 +972,13 @@ interpret3(Thread* t, const int base) pushInt(t, byteArrayBody(t, array, index)); } else { exception = makeThrowable - (t, Machine::ArrayIndexOutOfBoundsExceptionType, + (t, GcArrayIndexOutOfBoundsException::Type, "%d not in [0,%d)", index, byteArrayLength(t, array)); goto throw_; } } } else { - exception = makeThrowable(t, Machine::NullPointerExceptionType); + exception = makeThrowable(t, GcNullPointerException::Type); goto throw_; } } goto loop; @@ -989,7 +989,7 @@ interpret3(Thread* t, const int base) object array = popObject(t); if (LIKELY(array)) { - if (objectClass(t, array) == type(t, Machine::BooleanArrayType)) { + if (objectClass(t, array) == type(t, GcBooleanArray::Type)) { if (LIKELY(index >= 0 and static_cast(index) < booleanArrayLength(t, array))) @@ -997,7 +997,7 @@ interpret3(Thread* t, const int base) booleanArrayBody(t, array, index) = value; } else { exception = makeThrowable - (t, Machine::ArrayIndexOutOfBoundsExceptionType, + (t, GcArrayIndexOutOfBoundsException::Type, "%d not in [0,%d)", index, booleanArrayLength(t, array)); goto throw_; } @@ -1008,13 +1008,13 @@ interpret3(Thread* t, const int base) byteArrayBody(t, array, index) = value; } else { exception = makeThrowable - (t, Machine::ArrayIndexOutOfBoundsExceptionType, + (t, GcArrayIndexOutOfBoundsException::Type, "%d not in [0,%d)", index, byteArrayLength(t, array)); goto throw_; } } } else { - exception = makeThrowable(t, Machine::NullPointerExceptionType); + exception = makeThrowable(t, GcNullPointerException::Type); goto throw_; } } goto loop; @@ -1034,12 +1034,12 @@ interpret3(Thread* t, const int base) pushInt(t, charArrayBody(t, array, index)); } else { exception = makeThrowable - (t, Machine::ArrayIndexOutOfBoundsExceptionType, "%d not in [0,%d)", + (t, GcArrayIndexOutOfBoundsException::Type, "%d not in [0,%d)", index, charArrayLength(t, array)); goto throw_; } } else { - exception = makeThrowable(t, Machine::NullPointerExceptionType); + exception = makeThrowable(t, GcNullPointerException::Type); goto throw_; } } goto loop; @@ -1056,12 +1056,12 @@ interpret3(Thread* t, const int base) charArrayBody(t, array, index) = value; } else { exception = makeThrowable - (t, Machine::ArrayIndexOutOfBoundsExceptionType, "%d not in [0,%d)", + (t, GcArrayIndexOutOfBoundsException::Type, "%d not in [0,%d)", index, charArrayLength(t, array)); goto throw_; } } else { - exception = makeThrowable(t, Machine::NullPointerExceptionType); + exception = makeThrowable(t, GcNullPointerException::Type); goto throw_; } } goto loop; @@ -1070,15 +1070,15 @@ interpret3(Thread* t, const int base) uint16_t index = codeReadInt16(t, code, ip); if (peekObject(t, sp - 1)) { - object class_ = resolveClassInPool(t, frameMethod(t, frame), index - 1); + GcClass* class_ = resolveClassInPool(t, frameMethod(t, frame), index - 1); if (UNLIKELY(exception)) goto throw_; if (not instanceOf(t, class_, peekObject(t, sp - 1))) { exception = makeThrowable - (t, Machine::ClassCastExceptionType, "%s as %s", + (t, GcClassCastException::Type, "%s as %s", &byteArrayBody - (t, className(t, objectClass(t, peekObject(t, sp - 1))), 0), - &byteArrayBody(t, className(t, class_), 0)); + (t, objectClass(t, peekObject(t, sp - 1))->name(), 0), + &byteArrayBody(t, class_->name(), 0)); goto throw_; } } @@ -1115,7 +1115,7 @@ interpret3(Thread* t, const int base) case dadd: { double b = popDouble(t); double a = popDouble(t); - + pushDouble(t, a + b); } goto loop; @@ -1130,12 +1130,12 @@ interpret3(Thread* t, const int base) pushLong(t, doubleArrayBody(t, array, index)); } else { exception = makeThrowable - (t, Machine::ArrayIndexOutOfBoundsExceptionType, "%d not in [0,%d)", + (t, GcArrayIndexOutOfBoundsException::Type, "%d not in [0,%d)", index, doubleArrayLength(t, array)); goto throw_; } } else { - exception = makeThrowable(t, Machine::NullPointerExceptionType); + exception = makeThrowable(t, GcNullPointerException::Type); goto throw_; } } goto loop; @@ -1152,12 +1152,12 @@ interpret3(Thread* t, const int base) memcpy(&doubleArrayBody(t, array, index), &value, sizeof(uint64_t)); } else { exception = makeThrowable - (t, Machine::ArrayIndexOutOfBoundsExceptionType, "%d not in [0,%d)", + (t, GcArrayIndexOutOfBoundsException::Type, "%d not in [0,%d)", index, doubleArrayLength(t, array)); goto throw_; } } else { - exception = makeThrowable(t, Machine::NullPointerExceptionType); + exception = makeThrowable(t, GcNullPointerException::Type); goto throw_; } } goto loop; @@ -1165,7 +1165,7 @@ interpret3(Thread* t, const int base) case dcmpg: { double b = popDouble(t); double a = popDouble(t); - + if (isNaN(a) or isNaN(b)) { pushInt(t, 1); } if (a < b) { @@ -1182,7 +1182,7 @@ interpret3(Thread* t, const int base) case dcmpl: { double b = popDouble(t); double a = popDouble(t); - + if (isNaN(a) or isNaN(b)) { pushInt(t, static_cast(-1)); } if (a < b) { @@ -1207,34 +1207,34 @@ interpret3(Thread* t, const int base) case ddiv: { double b = popDouble(t); double a = popDouble(t); - + pushDouble(t, a / b); } goto loop; case dmul: { double b = popDouble(t); double a = popDouble(t); - + pushDouble(t, a * b); } goto loop; case dneg: { double a = popDouble(t); - + pushDouble(t, - a); } goto loop; case vm::drem: { double b = popDouble(t); double a = popDouble(t); - + pushDouble(t, fmod(a, b)); } goto loop; case dsub: { double b = popDouble(t); double a = popDouble(t); - + pushDouble(t, a - b); } goto loop; @@ -1332,7 +1332,7 @@ interpret3(Thread* t, const int base) case fadd: { float b = popFloat(t); float a = popFloat(t); - + pushFloat(t, a + b); } goto loop; @@ -1347,12 +1347,12 @@ interpret3(Thread* t, const int base) pushInt(t, floatArrayBody(t, array, index)); } else { exception = makeThrowable - (t, Machine::ArrayIndexOutOfBoundsExceptionType, "%d not in [0,%d)", + (t, GcArrayIndexOutOfBoundsException::Type, "%d not in [0,%d)", index, floatArrayLength(t, array)); goto throw_; } } else { - exception = makeThrowable(t, Machine::NullPointerExceptionType); + exception = makeThrowable(t, GcNullPointerException::Type); goto throw_; } } goto loop; @@ -1369,12 +1369,12 @@ interpret3(Thread* t, const int base) memcpy(&floatArrayBody(t, array, index), &value, sizeof(uint32_t)); } else { exception = makeThrowable - (t, Machine::ArrayIndexOutOfBoundsExceptionType, "%d not in [0,%d)", + (t, GcArrayIndexOutOfBoundsException::Type, "%d not in [0,%d)", index, floatArrayLength(t, array)); goto throw_; } } else { - exception = makeThrowable(t, Machine::NullPointerExceptionType); + exception = makeThrowable(t, GcNullPointerException::Type); goto throw_; } } goto loop; @@ -1382,7 +1382,7 @@ interpret3(Thread* t, const int base) case fcmpg: { float b = popFloat(t); float a = popFloat(t); - + if (isNaN(a) or isNaN(b)) { pushInt(t, 1); } if (a < b) { @@ -1399,7 +1399,7 @@ interpret3(Thread* t, const int base) case fcmpl: { float b = popFloat(t); float a = popFloat(t); - + if (isNaN(a) or isNaN(b)) { pushInt(t, static_cast(-1)); } if (a < b) { @@ -1428,41 +1428,41 @@ interpret3(Thread* t, const int base) case fdiv: { float b = popFloat(t); float a = popFloat(t); - + pushFloat(t, a / b); } goto loop; case fmul: { float b = popFloat(t); float a = popFloat(t); - + pushFloat(t, a * b); } goto loop; case fneg: { float a = popFloat(t); - + pushFloat(t, - a); } goto loop; case frem: { float b = popFloat(t); float a = popFloat(t); - + pushFloat(t, fmodf(a, b)); } goto loop; case fsub: { float b = popFloat(t); float a = popFloat(t); - + pushFloat(t, a - b); } goto loop; case getfield: { if (LIKELY(peekObject(t, sp - 1))) { uint16_t index = codeReadInt16(t, code, ip); - + object field = resolveField(t, frameMethod(t, frame), index - 1); assert(t, (fieldFlags(t, field) & ACC_STATIC) == 0); @@ -1473,7 +1473,7 @@ interpret3(Thread* t, const int base) pushField(t, popObject(t), field); } else { - exception = makeThrowable(t, Machine::NullPointerExceptionType); + exception = makeThrowable(t, GcNullPointerException::Type); goto throw_; } } goto loop; @@ -1487,7 +1487,7 @@ interpret3(Thread* t, const int base) PROTECT(t, field); - initClass(t, fieldClass(t, field)); + initClass(t, cast(t, fieldClass(t, field))); ACQUIRE_FIELD_FOR_READ(t, field); @@ -1498,7 +1498,7 @@ interpret3(Thread* t, const int base) int16_t offset = codeReadInt16(t, code, ip); ip = (ip - 3) + offset; } goto back_branch; - + case goto_w: { int32_t offset = codeReadInt32(t, code, ip); ip = (ip - 5) + offset; @@ -1531,7 +1531,7 @@ interpret3(Thread* t, const int base) case iadd: { int32_t b = popInt(t); int32_t a = popInt(t); - + pushInt(t, a + b); } goto loop; @@ -1546,12 +1546,12 @@ interpret3(Thread* t, const int base) pushInt(t, intArrayBody(t, array, index)); } else { exception = makeThrowable - (t, Machine::ArrayIndexOutOfBoundsExceptionType, "%d not in [0,%d)", + (t, GcArrayIndexOutOfBoundsException::Type, "%d not in [0,%d)", index, intArrayLength(t, array)); goto throw_; } } else { - exception = makeThrowable(t, Machine::NullPointerExceptionType); + exception = makeThrowable(t, GcNullPointerException::Type); goto throw_; } } goto loop; @@ -1559,7 +1559,7 @@ interpret3(Thread* t, const int base) case iand: { int32_t b = popInt(t); int32_t a = popInt(t); - + pushInt(t, a & b); } goto loop; @@ -1575,12 +1575,12 @@ interpret3(Thread* t, const int base) intArrayBody(t, array, index) = value; } else { exception = makeThrowable - (t, Machine::ArrayIndexOutOfBoundsExceptionType, "%d not in [0,%d)", + (t, GcArrayIndexOutOfBoundsException::Type, "%d not in [0,%d)", index, intArrayLength(t, array)); goto throw_; } } else { - exception = makeThrowable(t, Machine::NullPointerExceptionType); + exception = makeThrowable(t, GcNullPointerException::Type); goto throw_; } } goto loop; @@ -1618,10 +1618,10 @@ interpret3(Thread* t, const int base) int32_t a = popInt(t); if (UNLIKELY(b == 0)) { - exception = makeThrowable(t, Machine::ArithmeticExceptionType); + exception = makeThrowable(t, GcArithmeticException::Type); goto throw_; } - + pushInt(t, a / b); } goto loop; @@ -1630,7 +1630,7 @@ interpret3(Thread* t, const int base) object b = popObject(t); object a = popObject(t); - + if (a == b) { ip = (ip - 3) + offset; } @@ -1641,7 +1641,7 @@ interpret3(Thread* t, const int base) object b = popObject(t); object a = popObject(t); - + if (a != b) { ip = (ip - 3) + offset; } @@ -1652,7 +1652,7 @@ interpret3(Thread* t, const int base) int32_t b = popInt(t); int32_t a = popInt(t); - + if (a == b) { ip = (ip - 3) + offset; } @@ -1663,7 +1663,7 @@ interpret3(Thread* t, const int base) int32_t b = popInt(t); int32_t a = popInt(t); - + if (a != b) { ip = (ip - 3) + offset; } @@ -1674,7 +1674,7 @@ interpret3(Thread* t, const int base) int32_t b = popInt(t); int32_t a = popInt(t); - + if (a > b) { ip = (ip - 3) + offset; } @@ -1685,7 +1685,7 @@ interpret3(Thread* t, const int base) int32_t b = popInt(t); int32_t a = popInt(t); - + if (a >= b) { ip = (ip - 3) + offset; } @@ -1696,7 +1696,7 @@ interpret3(Thread* t, const int base) int32_t b = popInt(t); int32_t a = popInt(t); - + if (a < b) { ip = (ip - 3) + offset; } @@ -1707,7 +1707,7 @@ interpret3(Thread* t, const int base) int32_t b = popInt(t); int32_t a = popInt(t); - + if (a <= b) { ip = (ip - 3) + offset; } @@ -1780,7 +1780,7 @@ interpret3(Thread* t, const int base) case iinc: { uint8_t index = codeBody(t, code, ip++); int8_t c = codeBody(t, code, ip++); - + setLocalInt(t, index, localInt(t, index) + c); } goto loop; @@ -1812,7 +1812,7 @@ interpret3(Thread* t, const int base) case imul: { int32_t b = popInt(t); int32_t a = popInt(t); - + pushInt(t, a * b); } goto loop; @@ -1824,7 +1824,7 @@ interpret3(Thread* t, const int base) uint16_t index = codeReadInt16(t, code, ip); if (peekObject(t, sp - 1)) { - object class_ = resolveClassInPool(t, frameMethod(t, frame), index - 1); + GcClass* class_ = resolveClassInPool(t, frameMethod(t, frame), index - 1); if (instanceOf(t, class_, popObject(t))) { pushInt(t, 1); @@ -1839,18 +1839,18 @@ interpret3(Thread* t, const int base) case invokeinterface: { uint16_t index = codeReadInt16(t, code, ip); - + ip += 2; - object method = resolveMethod(t, frameMethod(t, frame), index - 1); - - unsigned parameterFootprint = methodParameterFootprint(t, method); + GcMethod* method = resolveMethod(t, frameMethod(t, frame), index - 1); + + unsigned parameterFootprint = method->parameterFootprint(); if (LIKELY(peekObject(t, sp - parameterFootprint))) { - code = findInterfaceMethod - (t, method, objectClass(t, peekObject(t, sp - parameterFootprint))); + code = reinterpret_cast(findInterfaceMethod + (t, method, objectClass(t, peekObject(t, sp - parameterFootprint)))); goto invoke; } else { - exception = makeThrowable(t, Machine::NullPointerExceptionType); + exception = makeThrowable(t, GcNullPointerException::Type); goto throw_; } } goto loop; @@ -1858,26 +1858,26 @@ interpret3(Thread* t, const int base) case invokespecial: { uint16_t index = codeReadInt16(t, code, ip); - object method = resolveMethod(t, frameMethod(t, frame), index - 1); - - unsigned parameterFootprint = methodParameterFootprint(t, method); + GcMethod* method = resolveMethod(t, frameMethod(t, frame), index - 1); + + unsigned parameterFootprint = method->parameterFootprint(); if (LIKELY(peekObject(t, sp - parameterFootprint))) { - object class_ = methodClass(t, frameMethod(t, frame)); + GcClass* class_ = cast(t, frameMethod(t, frame)->class_()); if (isSpecialMethod(t, method, class_)) { - class_ = classSuper(t, class_); + class_ = cast(t, class_->super()); PROTECT(t, method); PROTECT(t, class_); initClass(t, class_); - code = findVirtualMethod(t, method, class_); + code = reinterpret_cast(findVirtualMethod(t, method, class_)); } else { - code = method; + code = reinterpret_cast(method); } - + goto invoke; } else { - exception = makeThrowable(t, Machine::NullPointerExceptionType); + exception = makeThrowable(t, GcNullPointerException::Type); goto throw_; } } goto loop; @@ -1885,29 +1885,29 @@ interpret3(Thread* t, const int base) case invokestatic: { uint16_t index = codeReadInt16(t, code, ip); - object method = resolveMethod(t, frameMethod(t, frame), index - 1); + GcMethod* method = resolveMethod(t, frameMethod(t, frame), index - 1); PROTECT(t, method); - - initClass(t, methodClass(t, method)); - code = method; + initClass(t, cast(t, method->class_())); + + code = reinterpret_cast(method); } goto invoke; case invokevirtual: { uint16_t index = codeReadInt16(t, code, ip); - object method = resolveMethod(t, frameMethod(t, frame), index - 1); - - unsigned parameterFootprint = methodParameterFootprint(t, method); + GcMethod* method = resolveMethod(t, frameMethod(t, frame), index - 1); + + unsigned parameterFootprint = method->parameterFootprint(); if (LIKELY(peekObject(t, sp - parameterFootprint))) { - object class_ = objectClass(t, peekObject(t, sp - parameterFootprint)); + GcClass* class_ = objectClass(t, peekObject(t, sp - parameterFootprint)); PROTECT(t, method); PROTECT(t, class_); - code = findVirtualMethod(t, method, class_); + code = reinterpret_cast(findVirtualMethod(t, method, class_)); goto invoke; } else { - exception = makeThrowable(t, Machine::NullPointerExceptionType); + exception = makeThrowable(t, GcNullPointerException::Type); goto throw_; } } goto loop; @@ -1915,19 +1915,19 @@ interpret3(Thread* t, const int base) case ior: { int32_t b = popInt(t); int32_t a = popInt(t); - + pushInt(t, a | b); } goto loop; case irem: { int32_t b = popInt(t); int32_t a = popInt(t); - + if (UNLIKELY(b == 0)) { - exception = makeThrowable(t, Machine::ArithmeticExceptionType); + exception = makeThrowable(t, GcArithmeticException::Type); goto throw_; } - + pushInt(t, a % b); } goto loop; @@ -1939,21 +1939,21 @@ interpret3(Thread* t, const int base) pushInt(t, result); goto loop; } else { - return makeInt(t, result); + return reinterpret_cast(makeInt(t, result)); } } goto loop; case ishl: { int32_t b = popInt(t); int32_t a = popInt(t); - + pushInt(t, a << (b & 0x1F)); } goto loop; case ishr: { int32_t b = popInt(t); int32_t a = popInt(t); - + pushInt(t, a >> (b & 0x1F)); } goto loop; @@ -1985,21 +1985,21 @@ interpret3(Thread* t, const int base) case isub: { int32_t b = popInt(t); int32_t a = popInt(t); - + pushInt(t, a - b); } goto loop; case iushr: { int32_t b = popInt(t); uint32_t a = popInt(t); - + pushInt(t, a >> (b & 0x1F)); } goto loop; case ixor: { int32_t b = popInt(t); int32_t a = popInt(t); - + pushInt(t, a ^ b); } goto loop; @@ -2032,7 +2032,7 @@ interpret3(Thread* t, const int base) case ladd: { int64_t b = popLong(t); int64_t a = popLong(t); - + pushLong(t, a + b); } goto loop; @@ -2047,12 +2047,12 @@ interpret3(Thread* t, const int base) pushLong(t, longArrayBody(t, array, index)); } else { exception = makeThrowable - (t, Machine::ArrayIndexOutOfBoundsExceptionType, "%d not in [0,%d)", + (t, GcArrayIndexOutOfBoundsException::Type, "%d not in [0,%d)", index, longArrayLength(t, array)); goto throw_; } } else { - exception = makeThrowable(t, Machine::NullPointerExceptionType); + exception = makeThrowable(t, GcNullPointerException::Type); goto throw_; } } goto loop; @@ -2060,7 +2060,7 @@ interpret3(Thread* t, const int base) case land: { int64_t b = popLong(t); int64_t a = popLong(t); - + pushLong(t, a & b); } goto loop; @@ -2076,12 +2076,12 @@ interpret3(Thread* t, const int base) longArrayBody(t, array, index) = value; } else { exception = makeThrowable - (t, Machine::ArrayIndexOutOfBoundsExceptionType, "%d not in [0,%d)", + (t, GcArrayIndexOutOfBoundsException::Type, "%d not in [0,%d)", index, longArrayLength(t, array)); goto throw_; } } else { - exception = makeThrowable(t, Machine::NullPointerExceptionType); + exception = makeThrowable(t, GcNullPointerException::Type); goto throw_; } } goto loop; @@ -2089,7 +2089,7 @@ interpret3(Thread* t, const int base) case lcmp: { int64_t b = popLong(t); int64_t a = popLong(t); - + pushInt(t, a > b ? 1 : a == b ? 0 : -1); } goto loop; @@ -2111,18 +2111,18 @@ interpret3(Thread* t, const int base) index = codeReadInt16(t, code, ip); } - object pool = codePool(t, code); + GcSingleton* pool = cast(t, codePool(t, code)); if (singletonIsObject(t, pool, index - 1)) { object v = singletonObject(t, pool, index - 1); - if (objectClass(t, v) == type(t, Machine::ReferenceType)) { - object class_ = resolveClassInPool - (t, frameMethod(t, frame), index - 1); + if (objectClass(t, v) == type(t, GcReference::Type)) { + GcClass* class_ = resolveClassInPool + (t, frameMethod(t, frame), index - 1); pushObject(t, getJClass(t, class_)); - } else if (objectClass(t, v) == type(t, Machine::ClassType)) { - pushObject(t, getJClass(t, v)); - } else { + } else if (objectClass(t, v) == type(t, GcClass::Type)) { + pushObject(t, getJClass(t, cast(t, v))); + } else { pushObject(t, v); } } else { @@ -2133,7 +2133,7 @@ interpret3(Thread* t, const int base) case ldc2_w: { uint16_t index = codeReadInt16(t, code, ip); - object pool = codePool(t, code); + GcSingleton* pool = cast(t, codePool(t, code)); uint64_t v; memcpy(&v, &singletonValue(t, pool, index - 1), 8); @@ -2143,12 +2143,12 @@ interpret3(Thread* t, const int base) case ldiv_: { int64_t b = popLong(t); int64_t a = popLong(t); - + if (UNLIKELY(b == 0)) { - exception = makeThrowable(t, Machine::ArithmeticExceptionType); + exception = makeThrowable(t, GcArithmeticException::Type); goto throw_; } - + pushLong(t, a / b); } goto loop; @@ -2180,7 +2180,7 @@ interpret3(Thread* t, const int base) case lmul: { int64_t b = popLong(t); int64_t a = popLong(t); - + pushLong(t, a * b); } goto loop; @@ -2193,10 +2193,10 @@ interpret3(Thread* t, const int base) ip += 3; ip -= (ip % 4); - + int32_t default_ = codeReadInt32(t, code, ip); int32_t pairCount = codeReadInt32(t, code, ip); - + int32_t key = popInt(t); int32_t bottom = 0; @@ -2223,19 +2223,19 @@ interpret3(Thread* t, const int base) case lor: { int64_t b = popLong(t); int64_t a = popLong(t); - + pushLong(t, a | b); } goto loop; case lrem: { int64_t b = popLong(t); int64_t a = popLong(t); - + if (UNLIKELY(b == 0)) { - exception = makeThrowable(t, Machine::ArithmeticExceptionType); + exception = makeThrowable(t, GcArithmeticException::Type); goto throw_; } - + pushLong(t, a % b); } goto loop; @@ -2247,21 +2247,21 @@ interpret3(Thread* t, const int base) pushLong(t, result); goto loop; } else { - return makeLong(t, result); + return reinterpret_cast(makeLong(t, result)); } } goto loop; case lshl: { int32_t b = popInt(t); int64_t a = popLong(t); - + pushLong(t, a << (b & 0x3F)); } goto loop; case lshr: { int32_t b = popInt(t); int64_t a = popLong(t); - + pushLong(t, a >> (b & 0x3F)); } goto loop; @@ -2270,22 +2270,22 @@ interpret3(Thread* t, const int base) setLocalLong(t, codeBody(t, code, ip++), popLong(t)); } goto loop; - case lstore_0: + case lstore_0: case dstore_0:{ setLocalLong(t, 0, popLong(t)); } goto loop; - case lstore_1: + case lstore_1: case dstore_1: { setLocalLong(t, 1, popLong(t)); } goto loop; - case lstore_2: + case lstore_2: case dstore_2: { setLocalLong(t, 2, popLong(t)); } goto loop; - case lstore_3: + case lstore_3: case dstore_3: { setLocalLong(t, 3, popLong(t)); } goto loop; @@ -2293,21 +2293,21 @@ interpret3(Thread* t, const int base) case lsub: { int64_t b = popLong(t); int64_t a = popLong(t); - + pushLong(t, a - b); } goto loop; case lushr: { int64_t b = popInt(t); uint64_t a = popLong(t); - + pushLong(t, a >> (b & 0x3F)); } goto loop; case lxor: { int64_t b = popLong(t); int64_t a = popLong(t); - + pushLong(t, a ^ b); } goto loop; @@ -2316,7 +2316,7 @@ interpret3(Thread* t, const int base) if (LIKELY(o)) { acquire(t, o); } else { - exception = makeThrowable(t, Machine::NullPointerExceptionType); + exception = makeThrowable(t, GcNullPointerException::Type); goto throw_; } } goto loop; @@ -2326,7 +2326,7 @@ interpret3(Thread* t, const int base) if (LIKELY(o)) { release(t, o); } else { - exception = makeThrowable(t, Machine::NullPointerExceptionType); + exception = makeThrowable(t, GcNullPointerException::Type); goto throw_; } } goto loop; @@ -2335,7 +2335,7 @@ interpret3(Thread* t, const int base) uint16_t index = codeReadInt16(t, code, ip); uint8_t dimensions = codeBody(t, code, ip++); - object class_ = resolveClassInPool(t, frameMethod(t, frame), index - 1); + GcClass* class_ = resolveClassInPool(t, frameMethod(t, frame), index - 1); PROTECT(t, class_); THREAD_RUNTIME_ARRAY(t, int32_t, counts, dimensions); @@ -2343,13 +2343,13 @@ interpret3(Thread* t, const int base) RUNTIME_ARRAY_BODY(counts)[i] = popInt(t); if (UNLIKELY(RUNTIME_ARRAY_BODY(counts)[i] < 0)) { exception = makeThrowable - (t, Machine::NegativeArraySizeExceptionType, "%d", + (t, GcNegativeArraySizeException::Type, "%d", RUNTIME_ARRAY_BODY(counts)[i]); goto throw_; } } - object array = makeArray(t, RUNTIME_ARRAY_BODY(counts)[0]); + object array = reinterpret_cast(makeArray(t, RUNTIME_ARRAY_BODY(counts)[0])); setObjectClass(t, array, class_); PROTECT(t, array); @@ -2360,8 +2360,8 @@ interpret3(Thread* t, const int base) case new_: { uint16_t index = codeReadInt16(t, code, ip); - - object class_ = resolveClassInPool(t, frameMethod(t, frame), index - 1); + + GcClass* class_ = resolveClassInPool(t, frameMethod(t, frame), index - 1); PROTECT(t, class_); initClass(t, class_); @@ -2379,44 +2379,44 @@ interpret3(Thread* t, const int base) switch (type) { case T_BOOLEAN: - array = makeBooleanArray(t, count); + array = reinterpret_cast(makeBooleanArray(t, count)); break; case T_CHAR: - array = makeCharArray(t, count); + array = reinterpret_cast(makeCharArray(t, count)); break; case T_FLOAT: - array = makeFloatArray(t, count); + array = reinterpret_cast(makeFloatArray(t, count)); break; case T_DOUBLE: - array = makeDoubleArray(t, count); + array = reinterpret_cast(makeDoubleArray(t, count)); break; case T_BYTE: - array = makeByteArray(t, count); + array = reinterpret_cast(makeByteArray(t, count)); break; case T_SHORT: - array = makeShortArray(t, count); + array = reinterpret_cast(makeShortArray(t, count)); break; case T_INT: - array = makeIntArray(t, count); + array = reinterpret_cast(makeIntArray(t, count)); break; case T_LONG: - array = makeLongArray(t, count); + array = reinterpret_cast(makeLongArray(t, count)); break; default: abort(t); } - + pushObject(t, array); } else { exception = makeThrowable - (t, Machine::NegativeArraySizeExceptionType, "%d", count); + (t, GcNegativeArraySizeException::Type, "%d", count); goto throw_; } } goto loop; @@ -2433,7 +2433,7 @@ interpret3(Thread* t, const int base) case putfield: { uint16_t index = codeReadInt16(t, code, ip); - + object field = resolveField(t, frameMethod(t, frame), index - 1); assert(t, (fieldFlags(t, field) & ACC_STATIC) == 0); @@ -2456,19 +2456,19 @@ interpret3(Thread* t, const int base) case BooleanField: fieldAtOffset(o, fieldOffset(t, field)) = value; break; - + case CharField: case ShortField: fieldAtOffset(o, fieldOffset(t, field)) = value; break; - + case FloatField: case IntField: fieldAtOffset(o, fieldOffset(t, field)) = value; break; } } else { - exception = makeThrowable(t, Machine::NullPointerExceptionType); + exception = makeThrowable(t, GcNullPointerException::Type); } } break; @@ -2479,7 +2479,7 @@ interpret3(Thread* t, const int base) if (LIKELY(o)) { fieldAtOffset(o, fieldOffset(t, field)) = value; } else { - exception = makeThrowable(t, Machine::NullPointerExceptionType); + exception = makeThrowable(t, GcNullPointerException::Type); } } break; @@ -2489,7 +2489,7 @@ interpret3(Thread* t, const int base) if (LIKELY(o)) { set(t, o, fieldOffset(t, field), value); } else { - exception = makeThrowable(t, Machine::NullPointerExceptionType); + exception = makeThrowable(t, GcNullPointerException::Type); } } break; @@ -2513,8 +2513,8 @@ interpret3(Thread* t, const int base) ACQUIRE_FIELD_FOR_WRITE(t, field); - initClass(t, fieldClass(t, field)); - + initClass(t, cast(t, fieldClass(t, field))); + object table = classStaticTable(t, fieldClass(t, field)); switch (fieldCode(t, field)) { @@ -2530,12 +2530,12 @@ interpret3(Thread* t, const int base) case BooleanField: fieldAtOffset(table, fieldOffset(t, field)) = value; break; - + case CharField: case ShortField: fieldAtOffset(table, fieldOffset(t, field)) = value; break; - + case FloatField: case IntField: fieldAtOffset(table, fieldOffset(t, field)) = value; @@ -2561,9 +2561,9 @@ interpret3(Thread* t, const int base) } goto loop; case return_: { - object method = frameMethod(t, frame); - if ((methodFlags(t, method) & ConstructorFlag) - and (classVmFlags(t, methodClass(t, method)) & HasFinalMemberFlag)) + GcMethod* method = frameMethod(t, frame); + if ((method->flags() & ConstructorFlag) + and (classVmFlags(t, method->class_()) & HasFinalMemberFlag)) { storeStoreMemoryBarrier(); } @@ -2587,12 +2587,12 @@ interpret3(Thread* t, const int base) pushInt(t, shortArrayBody(t, array, index)); } else { exception = makeThrowable - (t, Machine::ArrayIndexOutOfBoundsExceptionType, "%d not in [0,%d)", + (t, GcArrayIndexOutOfBoundsException::Type, "%d not in [0,%d)", index, shortArrayLength(t, array)); goto throw_; } } else { - exception = makeThrowable(t, Machine::NullPointerExceptionType); + exception = makeThrowable(t, GcNullPointerException::Type); goto throw_; } } goto loop; @@ -2609,12 +2609,12 @@ interpret3(Thread* t, const int base) shortArrayBody(t, array, index) = value; } else { exception = makeThrowable - (t, Machine::ArrayIndexOutOfBoundsExceptionType, "%d not in [0,%d)", + (t, GcArrayIndexOutOfBoundsException::Type, "%d not in [0,%d)", index, shortArrayLength(t, array)); goto throw_; } } else { - exception = makeThrowable(t, Machine::NullPointerExceptionType); + exception = makeThrowable(t, GcNullPointerException::Type); goto throw_; } } goto loop; @@ -2635,13 +2635,13 @@ interpret3(Thread* t, const int base) ip += 3; ip -= (ip % 4); - + int32_t default_ = codeReadInt32(t, code, ip); int32_t bottom = codeReadInt32(t, code, ip); int32_t top = codeReadInt32(t, code, ip); - + int32_t key = popInt(t); - + if (key >= bottom and key <= top) { unsigned index = ip + ((key - bottom) * 4); ip = base + codeReadInt32(t, code, index); @@ -2664,14 +2664,14 @@ interpret3(Thread* t, const int base) ip -= 2; uint16_t index = codeReadInt16(t, code, ip); - object method = resolveMethod(t, frameMethod(t, frame), index - 1); + GcMethod* method = resolveMethod(t, frameMethod(t, frame), index - 1); - unsigned parameterFootprint = methodParameterFootprint(t, method); - object class_ = objectClass(t, peekObject(t, sp - parameterFootprint)); - assert(t, classVmFlags(t, class_) & BootstrapFlag); - - resolveClass(t, classLoader(t, methodClass(t, frameMethod(t, frame))), - className(t, class_)); + unsigned parameterFootprint = method->parameterFootprint(); + GcClass* class_ = objectClass(t, peekObject(t, sp - parameterFootprint)); + assert(t, class_->vmFlags() & BootstrapFlag); + + resolveClass(t, classLoader(t, frameMethod(t, frame)->class_()), + class_->name()); ip -= 3; } goto loop; @@ -2692,7 +2692,7 @@ interpret3(Thread* t, const int base) case iinc: { uint16_t index = codeReadInt16(t, code, ip); int16_t count = codeReadInt16(t, code, ip); - + setLocalInt(t, index, localInt(t, index) + count); } goto loop; @@ -2725,10 +2725,10 @@ interpret3(Thread* t, const int base) invoke: { if (methodFlags(t, code) & ACC_NATIVE) { - invokeNative(t, code); + invokeNative(t, cast(t, code)); } else { - checkStack(t, code); - pushFrame(t, code); + checkStack(t, cast(t, code)); + pushFrame(t, cast(t, code)); } } goto loop; @@ -2805,7 +2805,7 @@ pushArguments(Thread* t, object this_, const char* spec, bool indirectObjects, pushObject(t, va_arg(a, object)); } break; - + case 'J': case 'D': pushLong(t, va_arg(a, uint64_t)); @@ -2817,7 +2817,7 @@ pushArguments(Thread* t, object this_, const char* spec, bool indirectObjects, default: pushInt(t, va_arg(a, uint32_t)); - break; + break; } } } @@ -2838,7 +2838,7 @@ pushArguments(Thread* t, object this_, const char* spec, jobject v = arguments[index++].l; pushObject(t, v ? *v : 0); } break; - + case 'J': case 'D': pushLong(t, arguments[index++].j); @@ -2850,7 +2850,7 @@ pushArguments(Thread* t, object this_, const char* spec, default: pushInt(t, arguments[index++].i); - break; + break; } } } @@ -2869,7 +2869,7 @@ pushArguments(Thread* t, object this_, const char* spec, object a) case '[': pushObject(t, objectArrayBody(t, a, index++)); break; - + case 'J': case 'D': pushLong(t, fieldAtOffset(objectArrayBody(t, a, index++), 8)); @@ -2878,43 +2878,43 @@ pushArguments(Thread* t, object this_, const char* spec, object a) default: pushInt(t, fieldAtOffset(objectArrayBody(t, a, index++), BytesPerWord)); - break; + break; } } } object -invoke(Thread* t, object method) +invoke(Thread* t, GcMethod* method) { PROTECT(t, method); - object class_; + GcClass* class_; PROTECT(t, class_); if (methodVirtual(t, method)) { - unsigned parameterFootprint = methodParameterFootprint(t, method); + unsigned parameterFootprint = method->parameterFootprint(); class_ = objectClass(t, peekObject(t, t->sp - parameterFootprint)); - if (classVmFlags(t, class_) & BootstrapFlag) { - resolveClass(t, root(t, Machine::BootLoader), className(t, class_)); + if (class_->vmFlags() & BootstrapFlag) { + resolveClass(t, root(t, Machine::BootLoader), class_->name()); } - if (classFlags(t, methodClass(t, method)) & ACC_INTERFACE) { + if (classFlags(t, method->class_()) & ACC_INTERFACE) { method = findInterfaceMethod(t, method, class_); } else { method = findVirtualMethod(t, method, class_); } } else { - class_ = methodClass(t, method); + class_ = cast(t, method->class_()); } - if (methodFlags(t, method) & ACC_STATIC) { + if (method->flags() & ACC_STATIC) { initClass(t, class_); } object result = 0; - if (methodFlags(t, method) & ACC_NATIVE) { + if (method->flags() & ACC_NATIVE) { unsigned returnCode = invokeNative(t, method); switch (returnCode) { @@ -2924,14 +2924,14 @@ invoke(Thread* t, object method) case ShortField: case FloatField: case IntField: - result = makeInt(t, popInt(t)); + result = reinterpret_cast(makeInt(t, popInt(t))); break; case LongField: case DoubleField: - result = makeLong(t, popLong(t)); + result = reinterpret_cast(makeLong(t, popLong(t))); break; - + case ObjectField: result = popObject(t); break; @@ -2978,7 +2978,7 @@ class MyProcessor: public Processor { return t; } - virtual object + virtual GcMethod* makeMethod(vm::Thread* t, uint8_t vmFlags, uint8_t returnCode, @@ -2986,18 +2986,29 @@ class MyProcessor: public Processor { uint8_t parameterFootprint, uint16_t flags, uint16_t offset, - object name, - object spec, + GcByteArray* name, + GcByteArray* spec, object addendum, - object class_, - object code) + GcClass* class_, + GcCode* code) { - return vm::makeMethod - (t, vmFlags, returnCode, parameterCount, parameterFootprint, flags, - offset, 0, 0, name, spec, addendum, class_, code); + return vm::makeMethod(t, + vmFlags, + returnCode, + parameterCount, + parameterFootprint, + flags, + offset, + 0, + 0, + reinterpret_cast(name), + reinterpret_cast(spec), + addendum, + reinterpret_cast(class_), + reinterpret_cast(code)); } - virtual object + virtual GcClass* makeClass(vm::Thread* t, uint16_t flags, uint16_t vmFlags, @@ -3024,7 +3035,7 @@ class MyProcessor: public Processor { } virtual void - initVtable(vm::Thread*, object) + initVtable(vm::Thread*, GcClass*) { // ignore } @@ -3057,7 +3068,7 @@ class MyProcessor: public Processor { } virtual int - lineNumber(vm::Thread* t, object method, int ip) + lineNumber(vm::Thread* t, GcMethod* method, int ip) { return findLineNumber(static_cast(t), method, ip); } @@ -3086,7 +3097,7 @@ class MyProcessor: public Processor { if (t->sp + capacity < stackSizeInWords(t) / 2) { t->stackPointers = new(t->m->heap) List(t->sp, t->stackPointers); - + return true; } else { return false; @@ -3106,30 +3117,30 @@ class MyProcessor: public Processor { } virtual object - invokeArray(vm::Thread* vmt, object method, object this_, object arguments) + invokeArray(vm::Thread* vmt, GcMethod* method, object this_, object arguments) { Thread* t = static_cast(vmt); assert(t, t->state == Thread::ActiveState or t->state == Thread::ExclusiveState); - assert(t, ((methodFlags(t, method) & ACC_STATIC) == 0) xor (this_ == 0)); + assert(t, ((method->flags() & ACC_STATIC) == 0) xor (this_ == 0)); - if (UNLIKELY(t->sp + methodParameterFootprint(t, method) + 1 + if (UNLIKELY(t->sp + method->parameterFootprint() + 1 > stackSizeInWords(t) / 2)) { - throwNew(t, Machine::StackOverflowErrorType); + throwNew(t, GcStackOverflowError::Type); } const char* spec = reinterpret_cast - (&byteArrayBody(t, methodSpec(t, method), 0)); + (&byteArrayBody(t, method->spec(), 0)); pushArguments(t, this_, spec, arguments); return local::invoke(t, method); } virtual object - invokeArray(vm::Thread* vmt, object method, object this_, + invokeArray(vm::Thread* vmt, GcMethod* method, object this_, const jvalue* arguments) { Thread* t = static_cast(vmt); @@ -3137,23 +3148,23 @@ class MyProcessor: public Processor { assert(t, t->state == Thread::ActiveState or t->state == Thread::ExclusiveState); - assert(t, ((methodFlags(t, method) & ACC_STATIC) == 0) xor (this_ == 0)); + assert(t, ((method->flags() & ACC_STATIC) == 0) xor (this_ == 0)); - if (UNLIKELY(t->sp + methodParameterFootprint(t, method) + 1 + if (UNLIKELY(t->sp + method->parameterFootprint() + 1 > stackSizeInWords(t) / 2)) { - throwNew(t, Machine::StackOverflowErrorType); + throwNew(t, GcStackOverflowError::Type); } const char* spec = reinterpret_cast - (&byteArrayBody(t, methodSpec(t, method), 0)); + (&byteArrayBody(t, method->spec(), 0)); pushArguments(t, this_, spec, arguments); return local::invoke(t, method); } virtual object - invokeList(vm::Thread* vmt, object method, object this_, + invokeList(vm::Thread* vmt, GcMethod* method, object this_, bool indirectObjects, va_list arguments) { Thread* t = static_cast(vmt); @@ -3161,16 +3172,16 @@ class MyProcessor: public Processor { assert(t, t->state == Thread::ActiveState or t->state == Thread::ExclusiveState); - assert(t, ((methodFlags(t, method) & ACC_STATIC) == 0) xor (this_ == 0)); + assert(t, ((method->flags() & ACC_STATIC) == 0) xor (this_ == 0)); - if (UNLIKELY(t->sp + methodParameterFootprint(t, method) + 1 + if (UNLIKELY(t->sp + method->parameterFootprint() + 1 > stackSizeInWords(t) / 2)) { - throwNew(t, Machine::StackOverflowErrorType); + throwNew(t, GcStackOverflowError::Type); } const char* spec = reinterpret_cast - (&byteArrayBody(t, methodSpec(t, method), 0)); + (&byteArrayBody(t, method->spec(), 0)); pushArguments(t, this_, spec, indirectObjects, arguments); return local::invoke(t, method); @@ -3189,15 +3200,15 @@ class MyProcessor: public Processor { if (UNLIKELY(t->sp + parameterFootprint(vmt, methodSpec, false) > stackSizeInWords(t) / 2)) { - throwNew(t, Machine::StackOverflowErrorType); + throwNew(t, GcStackOverflowError::Type); } pushArguments(t, this_, methodSpec, false, arguments); - object method = resolveMethod + GcMethod* method = resolveMethod (t, loader, className, methodName, methodSpec); - assert(t, ((methodFlags(t, method) & ACC_STATIC) == 0) xor (this_ == 0)); + assert(t, ((method->flags() & ACC_STATIC) == 0) xor (this_ == 0)); return local::invoke(t, method); } @@ -3217,7 +3228,7 @@ class MyProcessor: public Processor { } virtual void compileMethod(vm::Thread*, Zone*, object*, object*, - avian::codegen::DelayedPromise**, object, OffsetResolver*) + avian::codegen::DelayedPromise**, GcMethod*, OffsetResolver*) { abort(s); } @@ -3269,7 +3280,7 @@ class MyProcessor: public Processor { this->~MyProcessor(); allocator->free(this, sizeof(*this)); } - + System* s; Allocator* allocator; SignalRegistrar signals; diff --git a/src/jnienv.cpp b/src/jnienv.cpp index dda50462c1..3b622cfa86 100644 --- a/src/jnienv.cpp +++ b/src/jnienv.cpp @@ -186,9 +186,9 @@ GetStringCritical(Thread* t, jstring s, jboolean* isCopy) if (isCopy) { *isCopy = true; } - + object data = stringData(t, *s); - if (objectClass(t, data) == type(t, Machine::ByteArrayType)) { + if (objectClass(t, data) == type(t, GcByteArray::Type)) { return GetStringChars(t, s, isCopy); } else { return &charArrayBody(t, data, stringOffset(t, *s)); @@ -198,7 +198,7 @@ GetStringCritical(Thread* t, jstring s, jboolean* isCopy) void JNICALL ReleaseStringCritical(Thread* t, jstring s, const jchar* chars) { - if (objectClass(t, stringData(t, *s)) == type(t, Machine::ByteArrayType)) { + if (objectClass(t, stringData(t, *s)) == type(t, GcByteArray::Type)) { ReleaseStringChars(t, s, chars); } @@ -260,7 +260,7 @@ newString(Thread* t, uintptr_t* arguments) const jchar* chars = reinterpret_cast(arguments[0]); jsize size = arguments[1]; - object a = makeCharArray(t, size); + object a = reinterpret_cast(makeCharArray(t, size)); if (size) { memcpy(&charArrayBody(t, a, 0), chars, size * sizeof(jchar)); } @@ -321,11 +321,13 @@ defineClass(Thread* t, uintptr_t* arguments) const uint8_t* buffer = reinterpret_cast(arguments[1]); jsize length = arguments[2]; - return reinterpret_cast - (makeLocalReference - (t, getJClass - (t, defineClass - (t, loader ? *loader : root(t, Machine::BootLoader), buffer, length)))); + return reinterpret_cast(makeLocalReference( + t, + getJClass(t, + cast(t, defineClass(t, + loader ? *loader : root(t, Machine::BootLoader), + buffer, + length))))); } jclass JNICALL @@ -344,16 +346,15 @@ findClass(Thread* t, uintptr_t* arguments) { const char* name = reinterpret_cast(arguments[0]); - object n = makeByteArray(t, strlen(name) + 1); + object n = reinterpret_cast(makeByteArray(t, strlen(name) + 1)); replace('.', '/', name, &byteArrayBody(t, n, 0)); - object caller = getCaller(t, 0); + GcMethod* caller = getCaller(t, 0); - object c - = resolveClass(t, - caller ? t->m->classpath->libraryClassLoader(t, caller) - : root(t, Machine::AppLoader), - n); + GcClass* c = resolveClass(t, + caller ? t->m->classpath->libraryClassLoader(t, caller) + : root(t, Machine::AppLoader), + n); if (t->m->classpath->mayInitClasses()) { PROTECT(t, c); @@ -388,7 +389,7 @@ throwNew(Thread* t, uintptr_t* arguments) object trace = makeTrace(t); PROTECT(t, trace); - t->exception = make(t, jclassVmClass(t, *c)); + t->exception = make(t, cast(t, jclassVmClass(t, *c))); set(t, t->exception, ThrowableMessage, m); set(t, t->exception, ThrowableTrace, trace); @@ -416,7 +417,7 @@ Throw(Thread* t, jthrowable throwable) } ENTER(t, Thread::ActiveState); - + t->exception = *throwable; return 0; @@ -424,7 +425,7 @@ Throw(Thread* t, jthrowable throwable) jobject JNICALL NewLocalRef(Thread* t, jobject o) -{ +{ ENTER(t, Thread::ActiveState); return makeLocalReference(t, *o); @@ -449,8 +450,8 @@ getObjectClass(Thread* t, uintptr_t* arguments) { jobject o = reinterpret_cast(arguments[0]); - return reinterpret_cast - (makeLocalReference(t, getJClass(t, objectClass(t, *o)))); + return reinterpret_cast(makeLocalReference( + t, getJClass(t, objectClass(t, *o)))); } jclass JNICALL @@ -470,7 +471,7 @@ getSuperclass(Thread* t, uintptr_t* arguments) } else { object super = classSuper(t, class_); return super ? reinterpret_cast - (makeLocalReference(t, getJClass(t, super))) : 0; + (makeLocalReference(t, getJClass(t, cast(t, super)))) : 0; } } @@ -488,7 +489,7 @@ isInstanceOf(Thread* t, uintptr_t* arguments) jobject o = reinterpret_cast(arguments[0]); jclass c = reinterpret_cast(arguments[1]); - return instanceOf(t, jclassVmClass(t, *c), *o); + return instanceOf(t, cast(t, jclassVmClass(t, *c)), *o); } jboolean JNICALL @@ -506,7 +507,7 @@ isAssignableFrom(Thread* t, uintptr_t* arguments) jclass b = reinterpret_cast(arguments[0]); jclass a = reinterpret_cast(arguments[1]); - return isAssignableFrom(t, jclassVmClass(t, *a), jclassVmClass(t, *b)); + return isAssignableFrom(t, cast(t, jclassVmClass(t, *a)), cast(t, jclassVmClass(t, *b))); } jboolean JNICALL @@ -518,20 +519,20 @@ IsAssignableFrom(Thread* t, jclass b, jclass a) return run(t, isAssignableFrom, arguments); } -object +GcMethod* findMethod(Thread* t, jclass c, const char* name, const char* spec) { object n = makeByteArray(t, "%s", name); PROTECT(t, n); object s = makeByteArray(t, "%s", spec); - return vm::findMethod(t, jclassVmClass(t, *c), n, s); + return vm::findMethod(t, cast(t, jclassVmClass(t, *c)), n, s); } jint -methodID(Thread* t, object method) +methodID(Thread* t, GcMethod* method) { - int id = methodNativeID(t, method); + int id = method->nativeID(); loadMemoryBarrier(); @@ -539,19 +540,19 @@ methodID(Thread* t, object method) PROTECT(t, method); ACQUIRE(t, t->m->referenceLock); - - if (methodNativeID(t, method) == 0) { + + if (method->nativeID() == 0) { setRoot(t, Machine::JNIMethodTable, vectorAppend - (t, root(t, Machine::JNIMethodTable), method)); + (t, root(t, Machine::JNIMethodTable), reinterpret_cast(method))); storeStoreMemoryBarrier(); - methodNativeID(t, method) = vectorSize + method->nativeID() = vectorSize (t, root(t, Machine::JNIMethodTable)); } } - return methodNativeID(t, method); + return method->nativeID(); } uint64_t @@ -561,11 +562,11 @@ getMethodID(Thread* t, uintptr_t* arguments) const char* name = reinterpret_cast(arguments[1]); const char* spec = reinterpret_cast(arguments[2]); - object method = findMethod(t, c, name, spec); + GcMethod* method = findMethod(t, c, name, spec); - assert(t, (methodFlags(t, method) & ACC_STATIC) == 0); + assert(t, (method->flags() & ACC_STATIC) == 0); - return methodID(t, method); + return methodID(t, method); } jmethodID JNICALL @@ -585,9 +586,9 @@ getStaticMethodID(Thread* t, uintptr_t* arguments) const char* name = reinterpret_cast(arguments[1]); const char* spec = reinterpret_cast(arguments[2]); - object method = findMethod(t, c, name, spec); + GcMethod* method = findMethod(t, c, name, spec); - assert(t, methodFlags(t, method) & ACC_STATIC); + assert(t, method->flags() & ACC_STATIC); return methodID(t, method); } @@ -602,14 +603,14 @@ GetStaticMethodID(Thread* t, jclass c, const char* name, const char* spec) return run(t, getStaticMethodID, arguments); } -object +GcMethod* getMethod(Thread* t, jmethodID m) { assert(t, m); - object method = vectorBody(t, root(t, Machine::JNIMethodTable), m - 1); + GcMethod* method = cast(t, vectorBody(t, root(t, Machine::JNIMethodTable), m - 1)); - assert(t, (methodFlags(t, method) & ACC_STATIC) == 0); + assert(t, (method->flags() & ACC_STATIC) == 0); return method; } @@ -621,7 +622,7 @@ newObjectV(Thread* t, uintptr_t* arguments) jmethodID m = arguments[1]; va_list* a = reinterpret_cast(arguments[2]); - object o = make(t, jclassVmClass(t, *c)); + object o = make(t, cast(t, jclassVmClass(t, *c))); PROTECT(t, o); t->m->processor->invokeList(t, getMethod(t, m), o, true, *a); @@ -659,7 +660,7 @@ newObjectA(Thread* t, uintptr_t* arguments) jmethodID m = arguments[1]; const jvalue* a = reinterpret_cast(arguments[2]); - object o = make(t, jclassVmClass(t, *c)); + object o = make(t, cast(t, jclassVmClass(t, *c))); PROTECT(t, o); t->m->processor->invokeArray(t, getMethod(t, m), o, a); @@ -1097,14 +1098,14 @@ CallVoidMethodA(Thread* t, jobject o, jmethodID m, const jvalue* a) run(t, callVoidMethodA, arguments); } -object +GcMethod* getStaticMethod(Thread* t, jmethodID m) { assert(t, m); - object method = vectorBody(t, root(t, Machine::JNIMethodTable), m - 1); + GcMethod* method = cast(t, vectorBody(t, root(t, Machine::JNIMethodTable), m - 1)); - assert(t, methodFlags(t, method) & ACC_STATIC); + assert(t, method->flags() & ACC_STATIC); return method; } @@ -1492,7 +1493,7 @@ fieldID(Thread* t, object field) PROTECT(t, field); ACQUIRE(t, t->m->referenceLock); - + if (fieldNativeID(t, field) == 0) { setRoot(t, Machine::JNIFieldTable, vectorAppend (t, root(t, Machine::JNIFieldTable), field)); @@ -1513,7 +1514,7 @@ getFieldID(Thread* t, uintptr_t* arguments) const char* name = reinterpret_cast(arguments[1]); const char* spec = reinterpret_cast(arguments[2]); - return fieldID(t, resolveField(t, jclassVmClass(t, *c), name, spec)); + return fieldID(t, resolveField(t, cast(t, jclassVmClass(t, *c)), name, spec)); } jfieldID JNICALL @@ -1744,12 +1745,12 @@ setObjectField(Thread* t, uintptr_t* arguments) jobject o = reinterpret_cast(arguments[0]); object field = getField(t, arguments[1]); jobject v = reinterpret_cast(arguments[2]); - + PROTECT(t, field); ACQUIRE_FIELD_FOR_WRITE(t, field); set(t, *o, fieldOffset(t, field), (v ? *v : 0)); - + return 1; } @@ -1769,12 +1770,12 @@ setBooleanField(Thread* t, uintptr_t* arguments) jobject o = reinterpret_cast(arguments[0]); object field = getField(t, arguments[1]); jboolean v = arguments[2]; - + PROTECT(t, field); ACQUIRE_FIELD_FOR_WRITE(t, field); fieldAtOffset(*o, fieldOffset(t, field)) = v; - + return 1; } @@ -1797,9 +1798,9 @@ setByteField(Thread* t, uintptr_t* arguments) PROTECT(t, field); ACQUIRE_FIELD_FOR_WRITE(t, field); - + fieldAtOffset(*o, fieldOffset(t, field)) = v; - + return 1; } @@ -1822,9 +1823,9 @@ setCharField(Thread* t, uintptr_t* arguments) PROTECT(t, field); ACQUIRE_FIELD_FOR_WRITE(t, field); - + fieldAtOffset(*o, fieldOffset(t, field)) = v; - + return 1; } @@ -1847,9 +1848,9 @@ setShortField(Thread* t, uintptr_t* arguments) PROTECT(t, field); ACQUIRE_FIELD_FOR_WRITE(t, field); - + fieldAtOffset(*o, fieldOffset(t, field)) = v; - + return 1; } @@ -1872,9 +1873,9 @@ setIntField(Thread* t, uintptr_t* arguments) PROTECT(t, field); ACQUIRE_FIELD_FOR_WRITE(t, field); - + fieldAtOffset(*o, fieldOffset(t, field)) = v; - + return 1; } @@ -1897,9 +1898,9 @@ setLongField(Thread* t, uintptr_t* arguments) PROTECT(t, field); ACQUIRE_FIELD_FOR_WRITE(t, field); - + fieldAtOffset(*o, fieldOffset(t, field)) = v; - + return 1; } @@ -1923,9 +1924,9 @@ setFloatField(Thread* t, uintptr_t* arguments) PROTECT(t, field); ACQUIRE_FIELD_FOR_WRITE(t, field); - + fieldAtOffset(*o, fieldOffset(t, field)) = v; - + return 1; } @@ -1948,9 +1949,9 @@ setDoubleField(Thread* t, uintptr_t* arguments) PROTECT(t, field); ACQUIRE_FIELD_FOR_WRITE(t, field); - + fieldAtOffset(*o, fieldOffset(t, field)) = v; - + return 1; } @@ -1982,7 +1983,7 @@ getStaticObjectField(Thread* t, uintptr_t* arguments) { jobject c = reinterpret_cast(arguments[0]); - initClass(t, jclassVmClass(t, *c)); + initClass(t, cast(t, jclassVmClass(t, *c))); object field = getStaticField(t, arguments[1]); @@ -2009,7 +2010,7 @@ getStaticBooleanField(Thread* t, uintptr_t* arguments) { jobject c = reinterpret_cast(arguments[0]); - initClass(t, jclassVmClass(t, *c)); + initClass(t, cast(t, jclassVmClass(t, *c))); object field = getStaticField(t, arguments[1]); @@ -2034,7 +2035,7 @@ getStaticByteField(Thread* t, uintptr_t* arguments) { jobject c = reinterpret_cast(arguments[0]); - initClass(t, jclassVmClass(t, *c)); + initClass(t, cast(t, jclassVmClass(t, *c))); object field = getStaticField(t, arguments[1]); @@ -2059,7 +2060,7 @@ getStaticCharField(Thread* t, uintptr_t* arguments) { jobject c = reinterpret_cast(arguments[0]); - initClass(t, jclassVmClass(t, *c)); + initClass(t, cast(t, jclassVmClass(t, *c))); object field = getStaticField(t, arguments[1]); @@ -2084,7 +2085,7 @@ getStaticShortField(Thread* t, uintptr_t* arguments) { jobject c = reinterpret_cast(arguments[0]); - initClass(t, jclassVmClass(t, *c)); + initClass(t, cast(t, jclassVmClass(t, *c))); object field = getStaticField(t, arguments[1]); @@ -2109,7 +2110,7 @@ getStaticIntField(Thread* t, uintptr_t* arguments) { jobject c = reinterpret_cast(arguments[0]); - initClass(t, jclassVmClass(t, *c)); + initClass(t, cast(t, jclassVmClass(t, *c))); object field = getStaticField(t, arguments[1]); @@ -2134,7 +2135,7 @@ getStaticLongField(Thread* t, uintptr_t* arguments) { jobject c = reinterpret_cast(arguments[0]); - initClass(t, jclassVmClass(t, *c)); + initClass(t, cast(t, jclassVmClass(t, *c))); object field = getStaticField(t, arguments[1]); @@ -2159,7 +2160,7 @@ getStaticFloatField(Thread* t, uintptr_t* arguments) { jobject c = reinterpret_cast(arguments[0]); - initClass(t, jclassVmClass(t, *c)); + initClass(t, cast(t, jclassVmClass(t, *c))); object field = getStaticField(t, arguments[1]); @@ -2185,7 +2186,7 @@ getStaticDoubleField(Thread* t, uintptr_t* arguments) { jobject c = reinterpret_cast(arguments[0]); - initClass(t, jclassVmClass(t, *c)); + initClass(t, cast(t, jclassVmClass(t, *c))); object field = getStaticField(t, arguments[1]); @@ -2211,17 +2212,17 @@ setStaticObjectField(Thread* t, uintptr_t* arguments) { jobject c = reinterpret_cast(arguments[0]); - initClass(t, jclassVmClass(t, *c)); + initClass(t, cast(t, jclassVmClass(t, *c))); object field = getStaticField(t, arguments[1]); jobject v = reinterpret_cast(arguments[2]); - + PROTECT(t, field); ACQUIRE_FIELD_FOR_WRITE(t, field); set(t, classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field), (v ? *v : 0)); - + return 1; } @@ -2240,17 +2241,17 @@ setStaticBooleanField(Thread* t, uintptr_t* arguments) { jobject c = reinterpret_cast(arguments[0]); - initClass(t, jclassVmClass(t, *c)); + initClass(t, cast(t, jclassVmClass(t, *c))); object field = getStaticField(t, arguments[1]); jboolean v = arguments[2]; - + PROTECT(t, field); ACQUIRE_FIELD_FOR_WRITE(t, field); fieldAtOffset (classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field)) = v; - + return 1; } @@ -2269,17 +2270,17 @@ setStaticByteField(Thread* t, uintptr_t* arguments) { jobject c = reinterpret_cast(arguments[0]); - initClass(t, jclassVmClass(t, *c)); + initClass(t, cast(t, jclassVmClass(t, *c))); object field = getStaticField(t, arguments[1]); jbyte v = arguments[2]; PROTECT(t, field); ACQUIRE_FIELD_FOR_WRITE(t, field); - + fieldAtOffset (classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field)) = v; - + return 1; } @@ -2298,17 +2299,17 @@ setStaticCharField(Thread* t, uintptr_t* arguments) { jobject c = reinterpret_cast(arguments[0]); - initClass(t, jclassVmClass(t, *c)); + initClass(t, cast(t, jclassVmClass(t, *c))); object field = getStaticField(t, arguments[1]); jchar v = arguments[2]; PROTECT(t, field); ACQUIRE_FIELD_FOR_WRITE(t, field); - + fieldAtOffset (classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field)) = v; - + return 1; } @@ -2327,17 +2328,17 @@ setStaticShortField(Thread* t, uintptr_t* arguments) { jobject c = reinterpret_cast(arguments[0]); - initClass(t, jclassVmClass(t, *c)); + initClass(t, cast(t, jclassVmClass(t, *c))); object field = getStaticField(t, arguments[1]); jshort v = arguments[2]; PROTECT(t, field); ACQUIRE_FIELD_FOR_WRITE(t, field); - + fieldAtOffset (classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field)) = v; - + return 1; } @@ -2356,17 +2357,17 @@ setStaticIntField(Thread* t, uintptr_t* arguments) { jobject c = reinterpret_cast(arguments[0]); - initClass(t, jclassVmClass(t, *c)); + initClass(t, cast(t, jclassVmClass(t, *c))); object field = getStaticField(t, arguments[1]); jint v = arguments[2]; PROTECT(t, field); ACQUIRE_FIELD_FOR_WRITE(t, field); - + fieldAtOffset (classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field)) = v; - + return 1; } @@ -2385,17 +2386,17 @@ setStaticLongField(Thread* t, uintptr_t* arguments) { jobject c = reinterpret_cast(arguments[0]); - initClass(t, jclassVmClass(t, *c)); + initClass(t, cast(t, jclassVmClass(t, *c))); object field = getStaticField(t, arguments[1]); jlong v; memcpy(&v, arguments + 2, sizeof(jlong)); PROTECT(t, field); ACQUIRE_FIELD_FOR_WRITE(t, field); - + fieldAtOffset (classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field)) = v; - + return 1; } @@ -2415,17 +2416,17 @@ setStaticFloatField(Thread* t, uintptr_t* arguments) { jobject c = reinterpret_cast(arguments[0]); - initClass(t, jclassVmClass(t, *c)); + initClass(t, cast(t, jclassVmClass(t, *c))); object field = getStaticField(t, arguments[1]); jfloat v = bitsToFloat(arguments[2]); PROTECT(t, field); ACQUIRE_FIELD_FOR_WRITE(t, field); - + fieldAtOffset (classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field)) = v; - + return 1; } @@ -2444,17 +2445,17 @@ setStaticDoubleField(Thread* t, uintptr_t* arguments) { jobject c = reinterpret_cast(arguments[0]); - initClass(t, jclassVmClass(t, *c)); + initClass(t, cast(t, jclassVmClass(t, *c))); object field = getStaticField(t, arguments[1]); jdouble v; memcpy(&v, arguments + 2, sizeof(jdouble)); PROTECT(t, field); ACQUIRE_FIELD_FOR_WRITE(t, field); - + fieldAtOffset (classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field)) = v; - + return 1; } @@ -2475,7 +2476,7 @@ newGlobalRef(Thread* t, jobject o, bool weak) ENTER(t, Thread::ActiveState); ACQUIRE(t, t->m->referenceLock); - + if (o) { for (Reference* r = t->m->jniReferences; r; r = r->next) { if (r->target == *o and r->weak == weak) { @@ -2508,7 +2509,7 @@ DeleteGlobalRef(Thread* t, jobject r) ENTER(t, Thread::ActiveState); ACQUIRE(t, t->m->referenceLock); - + if (r) { release(t, reinterpret_cast(r)); } @@ -2563,7 +2564,7 @@ newObjectArray(Thread* t, uintptr_t* arguments) jclass class_ = reinterpret_cast(arguments[1]); jobject init = reinterpret_cast(arguments[2]); - object a = makeObjectArray(t, jclassVmClass(t, *class_), length); + object a = makeObjectArray(t, cast(t, jclassVmClass(t, *class_)), length); object value = (init ? *init : 0); for (jsize i = 0; i < length; ++i) { set(t, a, ArrayBody + (i * BytesPerWord), value); @@ -2623,7 +2624,7 @@ NewBooleanArray(Thread* t, jsize length) object makeByteArray0(Thread* t, unsigned length) { - return makeByteArray(t, length); + return reinterpret_cast(makeByteArray(t, length)); } jbyteArray JNICALL @@ -2845,7 +2846,7 @@ ReleaseBooleanArrayElements(Thread* t, jbooleanArray array, jboolean* p, jint mode) { ENTER(t, Thread::ActiveState); - + unsigned size = booleanArrayLength(t, *array) * sizeof(jboolean); if (mode == 0 or mode == AVIAN_JNI_COMMIT) { @@ -2863,7 +2864,7 @@ void JNICALL ReleaseByteArrayElements(Thread* t, jbyteArray array, jbyte* p, jint mode) { ENTER(t, Thread::ActiveState); - + unsigned size = byteArrayLength(t, *array) * sizeof(jbyte); if (mode == 0 or mode == AVIAN_JNI_COMMIT) { @@ -2884,7 +2885,7 @@ ReleaseCharArrayElements(Thread* t, jcharArray array, jchar* p, jint mode) unsigned size = charArrayLength(t, *array) * sizeof(jchar); - if (mode == 0 or mode == AVIAN_JNI_COMMIT) { + if (mode == 0 or mode == AVIAN_JNI_COMMIT) { if (size) { memcpy(&charArrayBody(t, *array, 0), p, size); } @@ -2898,7 +2899,7 @@ ReleaseCharArrayElements(Thread* t, jcharArray array, jchar* p, jint mode) void JNICALL ReleaseShortArrayElements(Thread* t, jshortArray array, jshort* p, jint mode) { - ENTER(t, Thread::ActiveState); + ENTER(t, Thread::ActiveState); unsigned size = shortArrayLength(t, *array) * sizeof(jshort); @@ -2917,7 +2918,7 @@ void JNICALL ReleaseIntArrayElements(Thread* t, jintArray array, jint* p, jint mode) { ENTER(t, Thread::ActiveState); - + unsigned size = intArrayLength(t, *array) * sizeof(jint); if (mode == 0 or mode == AVIAN_JNI_COMMIT) { @@ -2935,7 +2936,7 @@ void JNICALL ReleaseLongArrayElements(Thread* t, jlongArray array, jlong* p, jint mode) { ENTER(t, Thread::ActiveState); - + unsigned size = longArrayLength(t, *array) * sizeof(jlong); if (mode == 0 or mode == AVIAN_JNI_COMMIT) { @@ -2953,7 +2954,7 @@ void JNICALL ReleaseFloatArrayElements(Thread* t, jfloatArray array, jfloat* p, jint mode) { ENTER(t, Thread::ActiveState); - + unsigned size = floatArrayLength(t, *array) * sizeof(jfloat); if (mode == 0 or mode == AVIAN_JNI_COMMIT) { @@ -2972,7 +2973,7 @@ ReleaseDoubleArrayElements(Thread* t, jdoubleArray array, jdouble* p, jint mode) { ENTER(t, Thread::ActiveState); - + unsigned size = doubleArrayLength(t, *array) * sizeof(jdouble); if (mode == 0 or mode == AVIAN_JNI_COMMIT) { @@ -3172,7 +3173,7 @@ GetPrimitiveArrayCritical(Thread* t, jarray array, jboolean* isCopy) } ++ t->criticalLevel; - + if (isCopy) { *isCopy = true; } @@ -3195,7 +3196,7 @@ fromReflectedMethod(Thread* t, uintptr_t* arguments) { jobject m = reinterpret_cast(arguments[0]); - return methodID(t, t->m->classpath->getVMMethod(t, *m)); + return methodID(t, cast(t, t->m->classpath->getVMMethod(t, *m))); } jmethodID JNICALL @@ -3281,10 +3282,10 @@ registerNatives(Thread* t, uintptr_t* arguments) const char* sig = methods[i].signature; if (*sig == '!') ++ sig; - object method = findMethodOrNull - (t, jclassVmClass(t, *c), methods[i].name, sig); + GcMethod* method = findMethodOrNull + (t, cast(t, jclassVmClass(t, *c)), methods[i].name, sig); - if (method == 0 or (methodFlags(t, method) & ACC_NATIVE) == 0) { + if (method == 0 or (method->flags() & ACC_NATIVE) == 0) { // The JNI spec says we must throw a NoSuchMethodError in this // case, but that would prevent using a code shrinker like // ProGuard effectively. Instead, we just ignore it. @@ -3297,7 +3298,7 @@ registerNatives(Thread* t, uintptr_t* arguments) } } - return 1; + return 1; } jint JNICALL @@ -3328,7 +3329,7 @@ monitorOp(Thread* t, uintptr_t* arguments) = reinterpret_cast(arguments[0]); jobject o = reinterpret_cast(arguments[1]); - + op(t, *o); return 1; @@ -3530,18 +3531,18 @@ uint64_t boot(Thread* t, uintptr_t*) { setRoot(t, Machine::NullPointerException, makeThrowable - (t, Machine::NullPointerExceptionType)); - + (t, GcNullPointerException::Type)); + setRoot(t, Machine::ArithmeticException, - makeThrowable(t, Machine::ArithmeticExceptionType)); + makeThrowable(t, GcArithmeticException::Type)); setRoot(t, Machine::ArrayIndexOutOfBoundsException, - makeThrowable(t, Machine::ArrayIndexOutOfBoundsExceptionType)); + makeThrowable(t, GcArrayIndexOutOfBoundsException::Type)); setRoot(t, Machine::OutOfMemoryError, - makeThrowable(t, Machine::OutOfMemoryErrorType)); + makeThrowable(t, GcOutOfMemoryError::Type)); - setRoot(t, Machine::Shutdown, makeThrowable(t, Machine::ThrowableType)); + setRoot(t, Machine::Shutdown, makeThrowable(t, GcThrowable::Type)); t->m->classpath->preBoot(t); @@ -3560,7 +3561,7 @@ boot(Thread* t, uintptr_t*) object host = makeString(t, "0.0.0.0"); PROTECT(t, host); - object method = resolveMethod + GcMethod* method = resolveMethod (t, root(t, Machine::BootLoader), "avian/Traces", "startTraceListener", "(Ljava/lang/String;I)V"); diff --git a/src/machine.cpp b/src/machine.cpp index 2f28cbf86f..2cb9f88fa7 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -189,28 +189,28 @@ turnOffTheLights(Thread* t) enter(t, Thread::ExitState); - { object p = 0; + { GcFinalizer* p = 0; PROTECT(t, p); for (p = t->m->finalizers; p;) { - object f = p; - p = finalizerNext(t, p); + GcFinalizer* f = p; + p = cast(t, p->next()); void (*function)(Thread*, object); - memcpy(&function, &finalizerFinalize(t, f), BytesPerWord); + memcpy(&function, &f->finalize(), BytesPerWord); if (function) { - function(t, finalizerTarget(t, f)); + function(t, f->target()); } } for (p = t->m->tenuredFinalizers; p;) { - object f = p; - p = finalizerNext(t, p); + GcFinalizer* f = p; + p = cast(t, p->next()); void (*function)(Thread*, object); - memcpy(&function, &finalizerFinalize(t, f), BytesPerWord); + memcpy(&function, &f->finalize(), BytesPerWord); if (function) { - function(t, finalizerTarget(t, f)); + function(t, f->target()); } } } @@ -367,17 +367,17 @@ walk(Thread*, Heap::Walker* w, uint32_t* mask, unsigned fixedSize, } object -findInInterfaces(Thread* t, object class_, object name, object spec, - object (*find)(Thread*, object, object, object)) +findInInterfaces(Thread* t, GcClass* class_, object name, object spec, + object (*find)(Thread*, GcClass*, object, object)) { object result = 0; - if (classInterfaceTable(t, class_)) { + if (class_->interfaceTable()) { for (unsigned i = 0; - i < arrayLength(t, classInterfaceTable(t, class_)) and result == 0; + i < arrayLength(t, class_->interfaceTable()) and result == 0; i += 2) { result = find - (t, arrayBody(t, classInterfaceTable(t, class_), i), name, spec); + (t, cast(t, arrayBody(t, class_->interfaceTable(), i)), name, spec); } } return result; @@ -415,7 +415,7 @@ referenceTargetUnreachable(Thread* t, Heap::Visitor* v, object* p) v->visit(p); jreferenceTarget(t, *p) = 0; - if (objectClass(t, *p) == type(t, Machine::CleanerType)) { + if (objectClass(t, *p) == type(t, GcCleaner::Type)) { object reference = *p; *p = jreferenceVmNext(t, reference); @@ -538,38 +538,38 @@ postVisit(Thread* t, Heap::Visitor* v) object lastNewTenuredFinalizer = 0; { object unreachable = 0; - for (object* p = &(m->finalizers); *p;) { + for (GcFinalizer** p = &(m->finalizers); *p;) { v->visit(p); - if (m->heap->status(finalizerTarget(t, *p)) == Heap::Unreachable) { - object finalizer = *p; - *p = finalizerNext(t, finalizer); + if (m->heap->status((*p)->target()) == Heap::Unreachable) { + GcFinalizer* finalizer = *p; + *p = cast(t, finalizer->next()); - finalizerNext(t, finalizer) = unreachable; - unreachable = finalizer; + finalizer->next() = unreachable; + unreachable = reinterpret_cast(finalizer); } else { - p = &finalizerNext(t, *p); + p = reinterpret_cast(&(*p)->next()); } } - for (object* p = &(m->finalizers); *p;) { + for (GcFinalizer** p = &(m->finalizers); *p;) { // target is reachable - v->visit(&finalizerTarget(t, *p)); + v->visit(&(*p)->target()); if (m->heap->status(*p) == Heap::Tenured) { // the finalizer is tenured, so we remove it from // m->finalizers and later add it to m->tenuredFinalizers if (lastNewTenuredFinalizer == 0) { - lastNewTenuredFinalizer = *p; + lastNewTenuredFinalizer = reinterpret_cast(*p); } - object finalizer = *p; - *p = finalizerNext(t, finalizer); - finalizerNext(t, finalizer) = firstNewTenuredFinalizer; - firstNewTenuredFinalizer = finalizer; + GcFinalizer* finalizer = *p; + *p = cast(t, finalizer->next()); + finalizer->next() = firstNewTenuredFinalizer; + firstNewTenuredFinalizer = reinterpret_cast(finalizer); } else { - p = &finalizerNext(t, *p); + p = reinterpret_cast(&(*p)->next()); } } @@ -618,24 +618,24 @@ postVisit(Thread* t, Heap::Visitor* v) if (major) { { object unreachable = 0; - for (object* p = &(m->tenuredFinalizers); *p;) { + for (GcFinalizer** p = &(m->tenuredFinalizers); *p;) { v->visit(p); - if (m->heap->status(finalizerTarget(t, *p)) == Heap::Unreachable) { - object finalizer = *p; - *p = finalizerNext(t, finalizer); + if (m->heap->status((*p)->target()) == Heap::Unreachable) { + GcFinalizer* finalizer = *p; + *p = cast(t, finalizer->next()); - finalizerNext(t, finalizer) = unreachable; - unreachable = finalizer; + finalizer->next() = unreachable; + unreachable = reinterpret_cast(finalizer); } else { - p = &finalizerNext(t, *p); + p = reinterpret_cast(&(*p)->next()); } } - for (object* p = &(m->tenuredFinalizers); *p;) { + for (GcFinalizer** p = &(m->tenuredFinalizers); *p;) { // target is reachable - v->visit(&finalizerTarget(t, *p)); - p = &finalizerNext(t, *p); + v->visit(&(*p)->target()); + p = reinterpret_cast(&(*p)->next()); } for (object* p = &unreachable; *p;) { @@ -664,8 +664,8 @@ postVisit(Thread* t, Heap::Visitor* v) } if (lastNewTenuredFinalizer) { - finalizerNext(t, lastNewTenuredFinalizer) = m->tenuredFinalizers; - m->tenuredFinalizers = firstNewTenuredFinalizer; + finalizerNext(t, lastNewTenuredFinalizer) = reinterpret_cast(m->tenuredFinalizers); + m->tenuredFinalizers = cast(t, firstNewTenuredFinalizer); } if (lastNewTenuredWeakReference) { @@ -727,7 +727,7 @@ postCollect(Thread* t) uint64_t invoke(Thread* t, uintptr_t* arguments) { - object m = *reinterpret_cast(arguments[0]); + GcMethod* m = cast(t, *reinterpret_cast(arguments[0])); object o = *reinterpret_cast(arguments[1]); t->m->processor->invoke(t, m, o); @@ -738,9 +738,9 @@ invoke(Thread* t, uintptr_t* arguments) void finalizeObject(Thread* t, object o, const char* name) { - for (object c = objectClass(t, o); c; c = classSuper(t, c)) { - for (unsigned i = 0; i < arrayLength(t, classMethodTable(t, c)); ++i) { - object m = arrayBody(t, classMethodTable(t, c), i); + for (GcClass* c = objectClass(t, o); c; c = cast(t, c->super())) { + for (unsigned i = 0; i < arrayLength(t, c->methodTable()); ++i) { + object m = arrayBody(t, c->methodTable(), i); if (vm::strcmp(reinterpret_cast(name), &byteArrayBody(t, methodName(t, m), 0)) == 0 @@ -783,7 +783,7 @@ parseUtf8NonAscii(Thread* t, AbstractStream& s, object bytesSoFar, PROTECT(t, bytesSoFar); unsigned length = byteArrayLength(t, bytesSoFar) - 1; - object value = makeCharArray(t, length + 1); + object value = reinterpret_cast(makeCharArray(t, length + 1)); unsigned vi = 0; for (; vi < byteCount; ++vi) { @@ -794,24 +794,24 @@ parseUtf8NonAscii(Thread* t, AbstractStream& s, object bytesSoFar, unsigned a = readByte(s, &byteA); if (a & 0x80) { if (a & 0x20) { - // 3 bytes - si += 2; - assert(t, si < length); + // 3 bytes + si += 2; + assert(t, si < length); unsigned b = readByte(s, &byteB); - unsigned c = s.read1(); - charArrayBody(t, value, vi++) + unsigned c = s.read1(); + charArrayBody(t, value, vi++) = ((a & 0xf) << 12) | ((b & 0x3f) << 6) | (c & 0x3f); } else { - // 2 bytes - ++ si; - assert(t, si < length); + // 2 bytes + ++ si; + assert(t, si < length); unsigned b = readByte(s, &byteB); - if (a == 0xC0 and b == 0x80) { - charArrayBody(t, value, vi++) = 0; - } else { - charArrayBody(t, value, vi++) = ((a & 0x1f) << 6) | (b & 0x3f); - } + if (a == 0xC0 and b == 0x80) { + charArrayBody(t, value, vi++) = 0; + } else { + charArrayBody(t, value, vi++) = ((a & 0x1f) << 6) | (b & 0x3f); + } } } else { charArrayBody(t, value, vi++) = a; @@ -821,7 +821,7 @@ parseUtf8NonAscii(Thread* t, AbstractStream& s, object bytesSoFar, if (vi < length) { PROTECT(t, value); - object v = makeCharArray(t, vi + 1); + object v = reinterpret_cast(makeCharArray(t, vi + 1)); memcpy(&charArrayBody(t, v, 0), &charArrayBody(t, value, 0), vi * 2); value = v; } @@ -832,25 +832,25 @@ parseUtf8NonAscii(Thread* t, AbstractStream& s, object bytesSoFar, object parseUtf8(Thread* t, AbstractStream& s, unsigned length) { - object value = makeByteArray(t, length + 1); + object value = reinterpret_cast(makeByteArray(t, length + 1)); unsigned vi = 0; for (unsigned si = 0; si < length; ++si) { unsigned a = s.read1(); if (a & 0x80) { if (a & 0x20) { - // 3 bytes + // 3 bytes return parseUtf8NonAscii(t, s, value, vi, si, a, NoByte); } else { - // 2 bytes - unsigned b = s.read1(); + // 2 bytes + unsigned b = s.read1(); - if (a == 0xC0 and b == 0x80) { + if (a == 0xC0 and b == 0x80) { ++ si; assert(t, si < length); - byteArrayBody(t, value, vi++) = 0; - } else { + byteArrayBody(t, value, vi++) = 0; + } else { return parseUtf8NonAscii(t, s, value, vi, si, a, b); - } + } } } else { byteArrayBody(t, value, vi++) = a; @@ -860,7 +860,7 @@ parseUtf8(Thread* t, AbstractStream& s, unsigned length) if (vi < length) { PROTECT(t, value); - object v = makeByteArray(t, vi + 1); + object v = reinterpret_cast(makeByteArray(t, vi + 1)); memcpy(&byteArrayBody(t, v, 0), &byteArrayBody(t, value, 0), vi); value = v; } @@ -871,7 +871,7 @@ parseUtf8(Thread* t, AbstractStream& s, unsigned length) object makeByteArray(Thread* t, Stream& s, unsigned length) { - object value = makeByteArray(t, length + 1); + object value = reinterpret_cast(makeByteArray(t, length + 1)); s.read(reinterpret_cast(&byteArrayBody(t, value, 0)), length); return value; } @@ -879,8 +879,11 @@ makeByteArray(Thread* t, Stream& s, unsigned length) void removeByteArray(Thread* t, object o) { - hashMapRemove - (t, root(t, Machine::ByteArrayMap), o, byteArrayHash, objectEqual); + hashMapRemove(t, + cast(t, root(t, Machine::ByteArrayMap)), + o, + byteArrayHash, + objectEqual); } object @@ -891,18 +894,18 @@ internByteArray(Thread* t, object array) ACQUIRE(t, t->m->referenceLock); object n = hashMapFindNode - (t, root(t, Machine::ByteArrayMap), array, byteArrayHash, byteArrayEqual); + (t, cast(t, root(t, Machine::ByteArrayMap)), array, byteArrayHash, byteArrayEqual); if (n) { return jreferenceTarget(t, tripleFirst(t, n)); } else { - hashMapInsert(t, root(t, Machine::ByteArrayMap), array, 0, byteArrayHash); + hashMapInsert(t, cast(t, root(t, Machine::ByteArrayMap)), array, 0, byteArrayHash); addFinalizer(t, array, removeByteArray); return array; } } unsigned -parsePoolEntry(Thread* t, Stream& s, uint32_t* index, object pool, unsigned i) +parsePoolEntry(Thread* t, Stream& s, uint32_t* index, GcSingleton* pool, unsigned i) { PROTECT(t, pool); @@ -932,7 +935,7 @@ parsePoolEntry(Thread* t, Stream& s, uint32_t* index, object pool, unsigned i) case CONSTANT_Utf8: { if (singletonObject(t, pool, i) == 0) { object value = internByteArray(t, makeByteArray(t, s, s.read2())); - set(t, pool, SingletonBody + (i * BytesPerWord), value); + set(t, reinterpret_cast(pool), SingletonBody + (i * BytesPerWord), value); if(DebugClassReader) { fprintf(stderr, " consts[%d] = utf8 %s\n", i, &byteArrayBody(t, value, 0)); @@ -945,8 +948,8 @@ parsePoolEntry(Thread* t, Stream& s, uint32_t* index, object pool, unsigned i) unsigned si = s.read2() - 1; parsePoolEntry(t, s, index, pool, si); - object value = makeReference(t, 0, 0, singletonObject(t, pool, si), 0); - set(t, pool, SingletonBody + (i * BytesPerWord), value); + object value = reinterpret_cast(makeReference(t, 0, 0, singletonObject(t, pool, si), 0)); + set(t, reinterpret_cast(pool), SingletonBody + (i * BytesPerWord), value); if(DebugClassReader) { fprintf(stderr, " consts[%d] = class \n", i); @@ -963,7 +966,7 @@ parsePoolEntry(Thread* t, Stream& s, uint32_t* index, object pool, unsigned i) value = t->m->classpath->makeString (t, value, 0, fieldAtOffset(value, BytesPerWord) - 1); value = intern(t, value); - set(t, pool, SingletonBody + (i * BytesPerWord), value); + set(t, reinterpret_cast(pool), SingletonBody + (i * BytesPerWord), value); if(DebugClassReader) { fprintf(stderr, " consts[%d] = string \n", i); @@ -981,8 +984,8 @@ parsePoolEntry(Thread* t, Stream& s, uint32_t* index, object pool, unsigned i) object name = singletonObject(t, pool, ni); object type = singletonObject(t, pool, ti); - object value = makePair(t, name, type); - set(t, pool, SingletonBody + (i * BytesPerWord), value); + object value = reinterpret_cast(makePair(t, name, type)); + set(t, reinterpret_cast(pool), SingletonBody + (i * BytesPerWord), value); if(DebugClassReader) { fprintf(stderr, " consts[%d] = nameAndType %s%s\n", i, &byteArrayBody(t, name, 0), &byteArrayBody(t, type, 0)); @@ -1000,15 +1003,15 @@ parsePoolEntry(Thread* t, Stream& s, uint32_t* index, object pool, unsigned i) parsePoolEntry(t, s, index, pool, ci); parsePoolEntry(t, s, index, pool, nti); - object class_ = referenceName(t, singletonObject(t, pool, ci)); + object className = referenceName(t, singletonObject(t, pool, ci)); object nameAndType = singletonObject(t, pool, nti); - object value = makeReference - (t, 0, class_, pairFirst(t, nameAndType), pairSecond(t, nameAndType)); - set(t, pool, SingletonBody + (i * BytesPerWord), value); + object value = reinterpret_cast(makeReference + (t, 0, className, pairFirst(t, nameAndType), pairSecond(t, nameAndType))); + set(t, reinterpret_cast(pool), SingletonBody + (i * BytesPerWord), value); if(DebugClassReader) { - fprintf(stderr, " consts[%d] = method %s.%s%s\n", i, &byteArrayBody(t, class_, 0), &byteArrayBody(t, pairFirst(t, nameAndType), 0), &byteArrayBody(t, pairSecond(t, nameAndType), 0)); + fprintf(stderr, " consts[%d] = method %s.%s%s\n", i, &byteArrayBody(t, className, 0), &byteArrayBody(t, pairFirst(t, nameAndType), 0), &byteArrayBody(t, pairSecond(t, nameAndType), 0)); } } } return 1; @@ -1029,11 +1032,11 @@ parsePoolEntry(Thread* t, Stream& s, uint32_t* index, object pool, unsigned i) &byteArrayBody(t, referenceSpec(t, value), 0)); } - value = makeReference + value = reinterpret_cast(makeReference (t, kind, referenceClass(t, value), referenceName(t, value), - referenceSpec(t, value)); + referenceSpec(t, value))); - set(t, pool, SingletonBody + (i * BytesPerWord), value); + set(t, reinterpret_cast(pool), SingletonBody + (i * BytesPerWord), value); } return 1; case CONSTANT_MethodType: @@ -1042,7 +1045,7 @@ parsePoolEntry(Thread* t, Stream& s, uint32_t* index, object pool, unsigned i) parsePoolEntry(t, s, index, pool, ni); - set(t, pool, SingletonBody + (i * BytesPerWord), + set(t, reinterpret_cast(pool), SingletonBody + (i * BytesPerWord), singletonObject(t, pool, ni)); } return 1; @@ -1065,25 +1068,31 @@ parsePoolEntry(Thread* t, Stream& s, uint32_t* index, object pool, unsigned i) (t, specString, true, ¶meterCount, ¶meterFootprint, &returnCode); - object template_ = makeMethod + GcMethod* template_ = makeMethod (t, 0, returnCode, parameterCount, parameterFootprint, 0, 0, 0, 0, pairFirst(t, nameAndType), pairSecond(t, nameAndType), 0, 0, 0); - object value = makeInvocation - (t, bootstrap, -1, 0, pool, template_, 0); + object value = reinterpret_cast + (makeInvocation(t, + bootstrap, + -1, + 0, + reinterpret_cast(pool), + reinterpret_cast(template_), + 0)); - set(t, pool, SingletonBody + (i * BytesPerWord), value); + set(t, reinterpret_cast(pool), SingletonBody + (i * BytesPerWord), value); } return 1; default: abort(t); } } -object +GcSingleton* parsePool(Thread* t, Stream& s) { unsigned count = s.read2() - 1; - object pool = makeSingletonOfSize(t, count + poolMaskSize(count)); + GcSingleton* pool = makeSingletonOfSize(t, count + poolMaskSize(count)); PROTECT(t, pool); if(DebugClassReader) { @@ -1172,12 +1181,12 @@ parsePool(Thread* t, Stream& s) } void -addInterfaces(Thread* t, object class_, object map) +addInterfaces(Thread* t, GcClass* class_, GcHashMap* map) { - object table = classInterfaceTable(t, class_); + object table = class_->interfaceTable(); if (table) { unsigned increment = 2; - if (classFlags(t, class_) & ACC_INTERFACE) { + if (class_->flags() & ACC_INTERFACE) { increment = 1; } @@ -1185,39 +1194,42 @@ addInterfaces(Thread* t, object class_, object map) PROTECT(t, table); for (unsigned i = 0; i < arrayLength(t, table); i += increment) { - object interface = arrayBody(t, table, i); - object name = className(t, interface); - hashMapInsertMaybe(t, map, name, interface, byteArrayHash, + GcClass* interface = cast(t, arrayBody(t, table, i)); + object name = interface->name(); + hashMapInsertMaybe(t, map, name, reinterpret_cast(interface), byteArrayHash, byteArrayEqual); } } } -object -getClassAddendum(Thread* t, object class_, object pool) +GcClassAddendum* +getClassAddendum(Thread* t, GcClass* class_, GcSingleton* pool) { - object addendum = classAddendum(t, class_); + GcClassAddendum* addendum = cast(t, class_->addendum()); if (addendum == 0) { PROTECT(t, class_); - addendum = makeClassAddendum(t, pool, 0, 0, 0, 0, -1, 0, 0); - set(t, class_, ClassAddendum, addendum); + addendum = makeClassAddendum(t, reinterpret_cast(pool), 0, 0, 0, 0, -1, 0, 0); + set(t, + reinterpret_cast(class_), + ClassAddendum, + reinterpret_cast(addendum)); } return addendum; } void -parseInterfaceTable(Thread* t, Stream& s, object class_, object pool, - Machine::Type throwType) +parseInterfaceTable(Thread* t, Stream& s, GcClass* class_, GcSingleton* pool, + Gc::Type throwType) { PROTECT(t, class_); PROTECT(t, pool); - object map = makeHashMap(t, 0, 0); + GcHashMap* map = makeHashMap(t, 0, 0); PROTECT(t, map); - if (classSuper(t, class_)) { - addInterfaces(t, classSuper(t, class_), map); + if (class_->super()) { + addInterfaces(t, cast(t, class_->super()), map); } unsigned count = s.read2(); @@ -1225,9 +1237,10 @@ parseInterfaceTable(Thread* t, Stream& s, object class_, object pool, PROTECT(t, table); if (count) { - table = makeArray(t, count); + table = reinterpret_cast(makeArray(t, count)); - object addendum = getClassAddendum(t, class_, pool); + object addendum = reinterpret_cast + (getClassAddendum(t, class_, pool)); set(t, addendum, ClassAddendumInterfaceTable, table); } @@ -1235,39 +1248,39 @@ parseInterfaceTable(Thread* t, Stream& s, object class_, object pool, object name = referenceName(t, singletonObject(t, pool, s.read2() - 1)); PROTECT(t, name); - object interface = resolveClass - (t, classLoader(t, class_), name, true, throwType); + GcClass* interface = resolveClass + (t, class_->loader(), name, true, throwType); PROTECT(t, interface); - set(t, table, ArrayBody + (i * BytesPerWord), interface); + set(t, table, ArrayBody + (i * BytesPerWord), reinterpret_cast(interface)); - hashMapInsertMaybe(t, map, name, interface, byteArrayHash, byteArrayEqual); + hashMapInsertMaybe(t, map, name, reinterpret_cast(interface), byteArrayHash, byteArrayEqual); addInterfaces(t, interface, map); } object interfaceTable = 0; - if (hashMapSize(t, map)) { - unsigned length = hashMapSize(t, map); - if ((classFlags(t, class_) & ACC_INTERFACE) == 0) { + if (map->size()) { + unsigned length = map->size(); + if ((class_->flags() & ACC_INTERFACE) == 0) { length *= 2; } - interfaceTable = makeArray(t, length); + interfaceTable = reinterpret_cast(makeArray(t, length)); PROTECT(t, interfaceTable); unsigned i = 0; for (HashMapIterator it(t, map); it.hasMore();) { - object interface = tripleSecond(t, it.next()); + GcClass* interface = cast(t, tripleSecond(t, it.next())); - set(t, interfaceTable, ArrayBody + (i * BytesPerWord), interface); + set(t, interfaceTable, ArrayBody + (i * BytesPerWord), reinterpret_cast(interface)); ++ i; - if ((classFlags(t, class_) & ACC_INTERFACE) == 0) { - if (classVirtualTable(t, interface)) { + if ((class_->flags() & ACC_INTERFACE) == 0) { + if (interface->virtualTable()) { // we'll fill in this table in parseMethodTable(): - object vtable = makeArray - (t, arrayLength(t, classVirtualTable(t, interface))); + object vtable = reinterpret_cast(makeArray + (t, arrayLength(t, interface->virtualTable()))); set(t, interfaceTable, ArrayBody + (i * BytesPerWord), vtable); } @@ -1277,18 +1290,18 @@ parseInterfaceTable(Thread* t, Stream& s, object class_, object pool, } } - set(t, class_, ClassInterfaceTable, interfaceTable); + set(t, reinterpret_cast(class_), ClassInterfaceTable, interfaceTable); } void -parseFieldTable(Thread* t, Stream& s, object class_, object pool) +parseFieldTable(Thread* t, Stream& s, GcClass* class_, GcSingleton* pool) { PROTECT(t, class_); PROTECT(t, pool); unsigned memberOffset = BytesPerWord; - if (classSuper(t, class_)) { - memberOffset = classFixedSize(t, classSuper(t, class_)); + if (class_->super()) { + memberOffset = classFixedSize(t, class_->super()); } unsigned count = s.read2(); @@ -1296,10 +1309,10 @@ parseFieldTable(Thread* t, Stream& s, object class_, object pool) unsigned staticOffset = BytesPerWord * 3; unsigned staticCount = 0; - object fieldTable = makeArray(t, count); + object fieldTable = reinterpret_cast(makeArray(t, count)); PROTECT(t, fieldTable); - object staticValueTable = makeIntArray(t, count); + object staticValueTable = reinterpret_cast(makeIntArray(t, count)); PROTECT(t, staticValueTable); object addendum = 0; @@ -1332,7 +1345,8 @@ parseFieldTable(Thread* t, Stream& s, object class_, object pool) &byteArrayBody(t, name, 0)) == 0) { if (addendum == 0) { - addendum = makeFieldAddendum(t, pool, 0, 0); + addendum = reinterpret_cast( + makeFieldAddendum(t, reinterpret_cast(pool), 0, 0)); } set(t, addendum, AddendumSignature, @@ -1342,10 +1356,11 @@ parseFieldTable(Thread* t, Stream& s, object class_, object pool) &byteArrayBody(t, name, 0)) == 0) { if (addendum == 0) { - addendum = makeFieldAddendum(t, pool, 0, 0); + addendum = reinterpret_cast( + makeFieldAddendum(t, reinterpret_cast(pool), 0, 0)); } - object body = makeByteArray(t, length); + object body = reinterpret_cast(makeByteArray(t, length)); s.read(reinterpret_cast(&byteArrayBody(t, body, 0)), length); @@ -1355,7 +1370,7 @@ parseFieldTable(Thread* t, Stream& s, object class_, object pool) } } - object field = makeField + GcField* field = makeField (t, 0, // vm flags code, @@ -1365,13 +1380,13 @@ parseFieldTable(Thread* t, Stream& s, object class_, object pool) singletonObject(t, pool, name - 1), singletonObject(t, pool, spec - 1), addendum, - class_); + reinterpret_cast(class_)); unsigned size = fieldSize(t, code); if (flags & ACC_STATIC) { staticOffset = pad(staticOffset, size); - fieldOffset(t, field) = staticOffset; + field->offset() = staticOffset; staticOffset += size; @@ -1380,28 +1395,28 @@ parseFieldTable(Thread* t, Stream& s, object class_, object pool) RUNTIME_ARRAY_BODY(staticTypes)[staticCount++] = code; } else { if (flags & ACC_FINAL) { - classVmFlags(t, class_) |= HasFinalMemberFlag; + class_->vmFlags() |= HasFinalMemberFlag; } memberOffset = pad(memberOffset, size); - fieldOffset(t, field) = memberOffset; + field->offset() = memberOffset; memberOffset += size; } - set(t, fieldTable, ArrayBody + (i * BytesPerWord), field); + set(t, fieldTable, ArrayBody + (i * BytesPerWord), reinterpret_cast(field)); } - set(t, class_, ClassFieldTable, fieldTable); + set(t, reinterpret_cast(class_), ClassFieldTable, fieldTable); if (staticCount) { unsigned footprint = ceilingDivide(staticOffset - (BytesPerWord * 2), BytesPerWord); - object staticTable = makeSingletonOfSize(t, footprint); + GcSingleton* staticTable = makeSingletonOfSize(t, footprint); uint8_t* body = reinterpret_cast - (&singletonBody(t, staticTable, 0)); + (&singletonBody(t, reinterpret_cast(staticTable), 0)); memcpy(body, &class_, BytesPerWord); singletonMarkObject(t, staticTable, 0); @@ -1452,36 +1467,39 @@ parseFieldTable(Thread* t, Stream& s, object class_, object pool) offset += size; } - set(t, class_, ClassStaticTable, staticTable); + set(t, + reinterpret_cast(class_), + ClassStaticTable, + reinterpret_cast(staticTable)); } } - classFixedSize(t, class_) = pad(memberOffset); + class_->fixedSize() = pad(memberOffset); - if (classSuper(t, class_) - and memberOffset == classFixedSize(t, classSuper(t, class_))) + if (class_->super() + and memberOffset == classFixedSize(t, class_->super())) { - set(t, class_, ClassObjectMask, - classObjectMask(t, classSuper(t, class_))); + set(t, reinterpret_cast(class_), ClassObjectMask, + classObjectMask(t, class_->super())); } else { - object mask = makeIntArray - (t, ceilingDivide(classFixedSize(t, class_), 32 * BytesPerWord)); + object mask = reinterpret_cast(makeIntArray + (t, ceilingDivide(class_->fixedSize(), 32 * BytesPerWord))); intArrayBody(t, mask, 0) = 1; object superMask = 0; - if (classSuper(t, class_)) { - superMask = classObjectMask(t, classSuper(t, class_)); + if (class_->super()) { + superMask = classObjectMask(t, class_->super()); if (superMask) { memcpy(&intArrayBody(t, mask, 0), &intArrayBody(t, superMask, 0), - ceilingDivide(classFixedSize(t, classSuper(t, class_)), + ceilingDivide(classFixedSize(t, class_->super()), 32 * BytesPerWord) * 4); } } bool sawReferenceField = false; - object fieldTable = classFieldTable(t, class_); + object fieldTable = class_->fieldTable(); if (fieldTable) { for (int i = arrayLength(t, fieldTable) - 1; i >= 0; --i) { object field = arrayBody(t, fieldTable, i); @@ -1496,7 +1514,7 @@ parseFieldTable(Thread* t, Stream& s, object class_, object pool) } if (superMask or sawReferenceField) { - set(t, class_, ClassObjectMask, mask); + set(t, reinterpret_cast(class_), ClassObjectMask, mask); } } } @@ -1880,7 +1898,7 @@ disassembleCode(const char* prefix, uint8_t* code, unsigned length) } object -parseCode(Thread* t, Stream& s, object pool) +parseCode(Thread* t, Stream& s, GcSingleton* pool) { PROTECT(t, pool); @@ -1892,7 +1910,7 @@ parseCode(Thread* t, Stream& s, object pool) fprintf(stderr, " code: maxStack %d maxLocals %d length %d\n", maxStack, maxLocals, length); } - object code = makeCode(t, pool, 0, 0, 0, 0, maxStack, maxLocals, length); + object code = reinterpret_cast(makeCode(t, reinterpret_cast(pool), 0, 0, 0, 0, maxStack, maxLocals, length)); s.read(&codeBody(t, code, 0), length); PROTECT(t, code); @@ -1902,7 +1920,7 @@ parseCode(Thread* t, Stream& s, object pool) unsigned ehtLength = s.read2(); if (ehtLength) { - object eht = makeExceptionHandlerTable(t, ehtLength); + object eht = reinterpret_cast(makeExceptionHandlerTable(t, ehtLength)); for (unsigned i = 0; i < ehtLength; ++i) { unsigned start = s.read2(); unsigned end = s.read2(); @@ -1924,7 +1942,7 @@ parseCode(Thread* t, Stream& s, object pool) &byteArrayBody(t, name, 0)) == 0) { unsigned lntLength = s.read2(); - object lnt = makeLineNumberTable(t, lntLength); + object lnt = reinterpret_cast(makeLineNumberTable(t, lntLength)); for (unsigned i = 0; i < lntLength; ++i) { unsigned ip = s.read2(); unsigned line = s.read2(); @@ -1941,10 +1959,10 @@ parseCode(Thread* t, Stream& s, object pool) } object -addInterfaceMethods(Thread* t, object class_, object virtualMap, +addInterfaceMethods(Thread* t, GcClass* class_, GcHashMap* virtualMap, unsigned* virtualCount, bool makeList) { - object itable = classInterfaceTable(t, class_); + object itable = class_->interfaceTable(); if (itable) { PROTECT(t, class_); PROTECT(t, virtualMap); @@ -1953,44 +1971,48 @@ addInterfaceMethods(Thread* t, object class_, object virtualMap, object list = 0; PROTECT(t, list); - object method = 0; + GcMethod* method = 0; PROTECT(t, method); object vtable = 0; PROTECT(t, vtable); - unsigned stride = (classFlags(t, class_) & ACC_INTERFACE) ? 1 : 2; + unsigned stride = (class_->flags() & ACC_INTERFACE) ? 1 : 2; for (unsigned i = 0; i < arrayLength(t, itable); i += stride) { vtable = classVirtualTable(t, arrayBody(t, itable, i)); if (vtable) { for (unsigned j = 0; j < arrayLength(t, vtable); ++j) { - method = arrayBody(t, vtable, j); + method = cast(t, arrayBody(t, vtable, j)); object n = hashMapFindNode - (t, virtualMap, method, methodHash, methodEqual); + (t, virtualMap, reinterpret_cast(method), methodHash, methodEqual); if (n == 0) { method = makeMethod (t, - methodVmFlags(t, method), - methodReturnCode(t, method), - methodParameterCount(t, method), - methodParameterFootprint(t, method), - methodFlags(t, method), + method->vmFlags(), + method->returnCode(), + method->parameterCount(), + method->parameterFootprint(), + method->flags(), (*virtualCount)++, 0, 0, - methodName(t, method), - methodSpec(t, method), + method->name(), + method->spec(), 0, - class_, + reinterpret_cast(class_), 0); - hashMapInsert(t, virtualMap, method, method, methodHash); + hashMapInsert(t, + virtualMap, + reinterpret_cast(method), + reinterpret_cast(method), + methodHash); if (makeList) { if (list == 0) { - list = vm::makeList(t, 0, 0, 0); + list = reinterpret_cast(vm::makeList(t, 0, 0, 0)); } - listAppend(t, list, method); + listAppend(t, list, reinterpret_cast(method)); } } } @@ -2004,12 +2026,12 @@ addInterfaceMethods(Thread* t, object class_, object virtualMap, } void -parseMethodTable(Thread* t, Stream& s, object class_, object pool) +parseMethodTable(Thread* t, Stream& s, GcClass* class_, GcSingleton* pool) { PROTECT(t, class_); PROTECT(t, pool); - object virtualMap = makeHashMap(t, 0, 0); + GcHashMap* virtualMap = makeHashMap(t, 0, 0); PROTECT(t, virtualMap); unsigned virtualCount = 0; @@ -2018,9 +2040,9 @@ parseMethodTable(Thread* t, Stream& s, object class_, object pool) object superVirtualTable = 0; PROTECT(t, superVirtualTable); - if ((classFlags(t, class_) & ACC_INTERFACE) == 0) { - if (classSuper(t, class_)) { - superVirtualTable = classVirtualTable(t, classSuper(t, class_)); + if ((class_->flags() & ACC_INTERFACE) == 0) { + if (class_->super()) { + superVirtualTable = classVirtualTable(t, class_->super()); } if (superVirtualTable) { @@ -2032,7 +2054,7 @@ parseMethodTable(Thread* t, Stream& s, object class_, object pool) } } - object newVirtuals = makeList(t, 0, 0, 0); + object newVirtuals = reinterpret_cast(makeList(t, 0, 0, 0)); PROTECT(t, newVirtuals); unsigned count = s.read2(); @@ -2042,7 +2064,7 @@ parseMethodTable(Thread* t, Stream& s, object class_, object pool) } if (count) { - object methodTable = makeArray(t, count); + object methodTable = reinterpret_cast(makeArray(t, count)); PROTECT(t, methodTable); object addendum = 0; @@ -2078,10 +2100,10 @@ parseMethodTable(Thread* t, Stream& s, object class_, object pool) &byteArrayBody(t, attributeName, 0)) == 0) { if (addendum == 0) { - addendum = makeMethodAddendum(t, pool, 0, 0, 0, 0, 0); + addendum = reinterpret_cast(makeMethodAddendum(t, reinterpret_cast(pool), 0, 0, 0, 0, 0)); } unsigned exceptionCount = s.read2(); - object body = makeShortArray(t, exceptionCount); + object body = reinterpret_cast(makeShortArray(t, exceptionCount)); for (unsigned i = 0; i < exceptionCount; ++i) { shortArrayBody(t, body, i) = s.read2(); } @@ -2091,10 +2113,10 @@ parseMethodTable(Thread* t, Stream& s, object class_, object pool) &byteArrayBody(t, attributeName, 0)) == 0) { if (addendum == 0) { - addendum = makeMethodAddendum(t, pool, 0, 0, 0, 0, 0); + addendum = reinterpret_cast(makeMethodAddendum(t, reinterpret_cast(pool), 0, 0, 0, 0, 0)); } - object body = makeByteArray(t, length); + object body = reinterpret_cast(makeByteArray(t, length)); s.read(reinterpret_cast(&byteArrayBody(t, body, 0)), length); @@ -2103,7 +2125,7 @@ parseMethodTable(Thread* t, Stream& s, object class_, object pool) &byteArrayBody(t, attributeName, 0)) == 0) { if (addendum == 0) { - addendum = makeMethodAddendum(t, pool, 0, 0, 0, 0, 0); + addendum = reinterpret_cast(makeMethodAddendum(t, reinterpret_cast(pool), 0, 0, 0, 0, 0)); } set(t, addendum, AddendumSignature, @@ -2113,10 +2135,10 @@ parseMethodTable(Thread* t, Stream& s, object class_, object pool) &byteArrayBody(t, attributeName, 0)) == 0) { if (addendum == 0) { - addendum = makeMethodAddendum(t, pool, 0, 0, 0, 0, 0); + addendum = reinterpret_cast(makeMethodAddendum(t, reinterpret_cast(pool), 0, 0, 0, 0, 0)); } - object body = makeByteArray(t, length); + object body = reinterpret_cast(makeByteArray(t, length)); s.read(reinterpret_cast(&byteArrayBody(t, body, 0)), length); @@ -2126,10 +2148,10 @@ parseMethodTable(Thread* t, Stream& s, object class_, object pool) &byteArrayBody(t, attributeName, 0)) == 0) { if (addendum == 0) { - addendum = makeMethodAddendum(t, pool, 0, 0, 0, 0, 0); + addendum = reinterpret_cast(makeMethodAddendum(t, reinterpret_cast(pool), 0, 0, 0, 0, 0)); } - object body = makeByteArray(t, length); + object body = reinterpret_cast(makeByteArray(t, length)); s.read(reinterpret_cast(&byteArrayBody(t, body, 0)), length); @@ -2148,7 +2170,7 @@ parseMethodTable(Thread* t, Stream& s, object class_, object pool) scanMethodSpec(t, specString, flags & ACC_STATIC, ¶meterCount, ¶meterFootprint, &returnCode); - object method = t->m->processor->makeMethod + GcMethod* method = t->m->processor->makeMethod (t, 0, // vm flags returnCode, @@ -2156,11 +2178,11 @@ parseMethodTable(Thread* t, Stream& s, object class_, object pool) parameterFootprint, flags, 0, // offset - singletonObject(t, pool, name - 1), - singletonObject(t, pool, spec - 1), + cast(t, singletonObject(t, pool, name - 1)), + cast(t, singletonObject(t, pool, spec - 1)), addendum, class_, - code); + cast(t, code)); PROTECT(t, method); @@ -2168,51 +2190,51 @@ parseMethodTable(Thread* t, Stream& s, object class_, object pool) ++ declaredVirtualCount; object p = hashMapFindNode - (t, virtualMap, method, methodHash, methodEqual); + (t, virtualMap, reinterpret_cast(method), methodHash, methodEqual); if (p) { - methodOffset(t, method) = methodOffset(t, tripleFirst(t, p)); + method->offset() = methodOffset(t, tripleFirst(t, p)); - set(t, p, TripleSecond, method); + set(t, p, TripleSecond, reinterpret_cast(method)); } else { - methodOffset(t, method) = virtualCount++; + method->offset() = virtualCount++; - listAppend(t, newVirtuals, method); + listAppend(t, newVirtuals, reinterpret_cast(method)); - hashMapInsert(t, virtualMap, method, method, methodHash); + hashMapInsert(t, virtualMap, reinterpret_cast(method), reinterpret_cast(method), methodHash); } - if (UNLIKELY((classFlags(t, class_) & ACC_INTERFACE) == 0 + if (UNLIKELY((class_->flags() & ACC_INTERFACE) == 0 and vm::strcmp (reinterpret_cast("finalize"), - &byteArrayBody(t, methodName(t, method), 0)) == 0 + &byteArrayBody(t, method->name(), 0)) == 0 and vm::strcmp (reinterpret_cast("()V"), - &byteArrayBody(t, methodSpec(t, method), 0)) == 0 + &byteArrayBody(t, method->spec(), 0)) == 0 and (not emptyMethod(t, method)))) { - classVmFlags(t, class_) |= HasFinalizerFlag; + class_->vmFlags() |= HasFinalizerFlag; } } else { - methodOffset(t, method) = i; + method->offset() = i; if (vm::strcmp(reinterpret_cast(""), - &byteArrayBody(t, methodName(t, method), 0)) == 0) + &byteArrayBody(t, method->name(), 0)) == 0) { - methodVmFlags(t, method) |= ClassInitFlag; - classVmFlags(t, class_) |= NeedInitFlag; + method->vmFlags() |= ClassInitFlag; + class_->vmFlags() |= NeedInitFlag; } else if (vm::strcmp (reinterpret_cast(""), - &byteArrayBody(t, methodName(t, method), 0)) == 0) + &byteArrayBody(t, method->name(), 0)) == 0) { - methodVmFlags(t, method) |= ConstructorFlag; + method->vmFlags() |= ConstructorFlag; } } - set(t, methodTable, ArrayBody + (i * BytesPerWord), method); + set(t, methodTable, ArrayBody + (i * BytesPerWord), reinterpret_cast(method)); } - set(t, class_, ClassMethodTable, methodTable); + set(t, reinterpret_cast(class_), ClassMethodTable, methodTable); } @@ -2225,36 +2247,36 @@ parseMethodTable(Thread* t, Stream& s, object class_, object pool) if (declaredVirtualCount == 0 and abstractVirtuals == 0 - and (classFlags(t, class_) & ACC_INTERFACE) == 0) + and (class_->flags() & ACC_INTERFACE) == 0) { - if (classSuper(t, class_)) { + if (class_->super()) { // inherit virtual table from superclass - set(t, class_, ClassVirtualTable, superVirtualTable); + set(t, reinterpret_cast(class_), ClassVirtualTable, superVirtualTable); - if (classInterfaceTable(t, classSuper(t, class_)) - and arrayLength(t, classInterfaceTable(t, class_)) + if (classInterfaceTable(t, class_->super()) + and arrayLength(t, class_->interfaceTable()) == arrayLength - (t, classInterfaceTable(t, classSuper(t, class_)))) + (t, classInterfaceTable(t, class_->super()))) { // inherit interface table from superclass - set(t, class_, ClassInterfaceTable, - classInterfaceTable(t, classSuper(t, class_))); + set(t, reinterpret_cast(class_), ClassInterfaceTable, + classInterfaceTable(t, class_->super())); } else { populateInterfaceVtables = true; } } else { // apparently, Object does not have any virtual methods. We // give it a vtable anyway so code doesn't break elsewhere. - object vtable = makeArray(t, 0); - set(t, class_, ClassVirtualTable, vtable); + object vtable = reinterpret_cast(makeArray(t, 0)); + set(t, reinterpret_cast(class_), ClassVirtualTable, vtable); } } else if (virtualCount) { // generate class vtable - object vtable = makeArray(t, virtualCount); + object vtable = reinterpret_cast(makeArray(t, virtualCount)); unsigned i = 0; - if (classFlags(t, class_) & ACC_INTERFACE) { + if (class_->flags() & ACC_INTERFACE) { PROTECT(t, vtable); for (HashMapIterator it(t, virtualMap); it.hasMore();) { @@ -2285,21 +2307,21 @@ parseMethodTable(Thread* t, Stream& s, object class_, object pool) if (abstractVirtuals) { PROTECT(t, vtable); - object originalMethodTable = classMethodTable(t, class_); + object originalMethodTable = class_->methodTable(); PROTECT(t, originalMethodTable); - unsigned oldLength = classMethodTable(t, class_) ? - arrayLength(t, classMethodTable(t, class_)) : 0; + unsigned oldLength = class_->methodTable() ? + arrayLength(t, class_->methodTable()) : 0; - object addendum = getClassAddendum(t, class_, pool); + object addendum = reinterpret_cast(getClassAddendum(t, class_, pool)); classAddendumDeclaredMethodCount(t, addendum) = oldLength; - object newMethodTable = makeArray - (t, oldLength + listSize(t, abstractVirtuals)); + object newMethodTable = reinterpret_cast(makeArray + (t, oldLength + listSize(t, abstractVirtuals))); if (oldLength) { memcpy(&arrayBody(t, newMethodTable, 0), - &arrayBody(t, classMethodTable(t, class_), 0), + &arrayBody(t, class_->methodTable(), 0), oldLength * sizeof(object)); } @@ -2312,7 +2334,7 @@ parseMethodTable(Thread* t, Stream& s, object class_, object pool) set(t, newMethodTable, ArrayBody + ((mti++) * BytesPerWord), pairFirst(t, p)); - if ((classFlags(t, class_) & ACC_INTERFACE) == 0) { + if ((class_->flags() & ACC_INTERFACE) == 0) { set(t, vtable, ArrayBody + ((i++) * BytesPerWord), pairFirst(t, p)); } @@ -2320,17 +2342,17 @@ parseMethodTable(Thread* t, Stream& s, object class_, object pool) assert(t, arrayLength(t, newMethodTable) == mti); - set(t, class_, ClassMethodTable, newMethodTable); + set(t, reinterpret_cast(class_), ClassMethodTable, newMethodTable); } assert(t, arrayLength(t, vtable) == i); - set(t, class_, ClassVirtualTable, vtable); + set(t, reinterpret_cast(class_), ClassVirtualTable, vtable); } if (populateInterfaceVtables) { // generate interface vtables - object itable = classInterfaceTable(t, class_); + object itable = class_->interfaceTable(); if (itable) { PROTECT(t, itable); @@ -2354,7 +2376,7 @@ parseMethodTable(Thread* t, Stream& s, object class_, object pool) } void -parseAttributeTable(Thread* t, Stream& s, object class_, object pool) +parseAttributeTable(Thread* t, Stream& s, GcClass* class_, GcSingleton* pool) { PROTECT(t, class_); PROTECT(t, pool); @@ -2367,18 +2389,18 @@ parseAttributeTable(Thread* t, Stream& s, object class_, object pool) if (vm::strcmp(reinterpret_cast("SourceFile"), &byteArrayBody(t, name, 0)) == 0) { - set(t, class_, ClassSourceFile, singletonObject(t, pool, s.read2() - 1)); + set(t, reinterpret_cast(class_), ClassSourceFile, singletonObject(t, pool, s.read2() - 1)); } else if (vm::strcmp(reinterpret_cast("Signature"), &byteArrayBody(t, name, 0)) == 0) { - object addendum = getClassAddendum(t, class_, pool); - set(t, addendum, AddendumSignature, + GcClassAddendum* addendum = getClassAddendum(t, class_, pool); + set(t, reinterpret_cast(addendum), AddendumSignature, singletonObject(t, pool, s.read2() - 1)); } else if (vm::strcmp(reinterpret_cast("InnerClasses"), &byteArrayBody(t, name, 0)) == 0) { unsigned innerClassCount = s.read2(); - object table = makeArray(t, innerClassCount); + object table = reinterpret_cast(makeArray(t, innerClassCount)); PROTECT(t, table); for (unsigned i = 0; i < innerClassCount; ++i) { @@ -2387,28 +2409,28 @@ parseAttributeTable(Thread* t, Stream& s, object class_, object pool) int16_t name = s.read2(); int16_t flags = s.read2(); - object reference = makeInnerClassReference + 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, - flags); + flags)); set(t, table, ArrayBody + (i * BytesPerWord), reference); } - object addendum = getClassAddendum(t, class_, pool); - set(t, addendum, ClassAddendumInnerClassTable, table); + GcClassAddendum* addendum = getClassAddendum(t, class_, pool); + set(t, reinterpret_cast(addendum), ClassAddendumInnerClassTable, table); } else if (vm::strcmp(reinterpret_cast ("RuntimeVisibleAnnotations"), &byteArrayBody(t, name, 0)) == 0) { - object body = makeByteArray(t, length); + object body = reinterpret_cast(makeByteArray(t, length)); PROTECT(t, body); s.read(reinterpret_cast(&byteArrayBody(t, body, 0)), length); - object addendum = getClassAddendum(t, class_, pool); - set(t, addendum, AddendumAnnotationTable, body); + GcClassAddendum* addendum = getClassAddendum(t, class_, pool); + set(t, reinterpret_cast(addendum), AddendumAnnotationTable, body); } else if (vm::strcmp(reinterpret_cast ("EnclosingMethod"), &byteArrayBody(t, name, 0)) == 0) @@ -2416,12 +2438,12 @@ parseAttributeTable(Thread* t, Stream& s, object class_, object pool) int16_t enclosingClass = s.read2(); int16_t enclosingMethod = s.read2(); - object addendum = getClassAddendum(t, class_, pool); + GcClassAddendum* addendum = getClassAddendum(t, class_, pool); - set(t, addendum, ClassAddendumEnclosingClass, + set(t, reinterpret_cast(addendum), ClassAddendumEnclosingClass, referenceName(t, singletonObject(t, pool, enclosingClass - 1))); - set(t, addendum, ClassAddendumEnclosingMethod, enclosingMethod + set(t, reinterpret_cast(addendum), ClassAddendumEnclosingMethod, enclosingMethod ? singletonObject(t, pool, enclosingMethod - 1) : 0); } else { s.skip(length); @@ -2430,76 +2452,76 @@ parseAttributeTable(Thread* t, Stream& s, object class_, object pool) } void -updateClassTables(Thread* t, object newClass, object oldClass) +updateClassTables(Thread* t, GcClass* newClass, GcClass* oldClass) { - object fieldTable = classFieldTable(t, newClass); + object fieldTable = newClass->fieldTable(); if (fieldTable) { for (unsigned i = 0; i < arrayLength(t, fieldTable); ++i) { - set(t, arrayBody(t, fieldTable, i), FieldClass, newClass); + set(t, arrayBody(t, fieldTable, i), FieldClass, reinterpret_cast(newClass)); } } - object staticTable = classStaticTable(t, newClass); + object staticTable = newClass->staticTable(); if (staticTable) { - set(t, staticTable, SingletonBody, newClass); + set(t, staticTable, SingletonBody, reinterpret_cast(newClass)); } - if (classFlags(t, newClass) & ACC_INTERFACE) { - object virtualTable = classVirtualTable(t, newClass); + if (newClass->flags() & ACC_INTERFACE) { + object virtualTable = newClass->virtualTable(); if (virtualTable) { for (unsigned i = 0; i < arrayLength(t, virtualTable); ++i) { - if (methodClass(t, arrayBody(t, virtualTable, i)) == oldClass) { - set(t, arrayBody(t, virtualTable, i), MethodClass, newClass); + if (methodClass(t, arrayBody(t, virtualTable, i)) == reinterpret_cast(oldClass)) { + set(t, arrayBody(t, virtualTable, i), MethodClass, reinterpret_cast(newClass)); } } } } - object methodTable = classMethodTable(t, newClass); + object methodTable = newClass->methodTable(); if (methodTable) { for (unsigned i = 0; i < arrayLength(t, methodTable); ++i) { - set(t, arrayBody(t, methodTable, i), MethodClass, newClass); + set(t, arrayBody(t, methodTable, i), MethodClass, reinterpret_cast(newClass)); } } } void -updateBootstrapClass(Thread* t, object bootstrapClass, object class_) +updateBootstrapClass(Thread* t, GcClass* bootstrapClass, GcClass* class_) { expect(t, bootstrapClass != class_); // verify that the classes have the same layout - expect(t, classSuper(t, bootstrapClass) == classSuper(t, class_)); + expect(t, bootstrapClass->super() == class_->super()); - expect(t, classFixedSize(t, bootstrapClass) >= classFixedSize(t, class_)); + expect(t, bootstrapClass->fixedSize() >= class_->fixedSize()); - expect(t, (classVmFlags(t, class_) & HasFinalizerFlag) == 0); + expect(t, (class_->vmFlags() & HasFinalizerFlag) == 0); PROTECT(t, bootstrapClass); PROTECT(t, class_); ENTER(t, Thread::ExclusiveState); - classVmFlags(t, bootstrapClass) &= ~BootstrapFlag; - classVmFlags(t, bootstrapClass) |= classVmFlags(t, class_); - classFlags(t, bootstrapClass) |= classFlags(t, class_); + bootstrapClass->vmFlags() &= ~BootstrapFlag; + bootstrapClass->vmFlags() |= class_->vmFlags(); + bootstrapClass->flags() |= class_->flags(); - set(t, bootstrapClass, ClassSuper, classSuper(t, class_)); - set(t, bootstrapClass, ClassInterfaceTable, classInterfaceTable(t, class_)); - set(t, bootstrapClass, ClassVirtualTable, classVirtualTable(t, class_)); - set(t, bootstrapClass, ClassFieldTable, classFieldTable(t, class_)); - set(t, bootstrapClass, ClassMethodTable, classMethodTable(t, class_)); - set(t, bootstrapClass, ClassStaticTable, classStaticTable(t, class_)); - set(t, bootstrapClass, ClassAddendum, classAddendum(t, class_)); + 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()); updateClassTables(t, bootstrapClass, class_); } -object +GcClass* makeArrayClass(Thread* t, object loader, unsigned dimensions, object spec, object elementClass) { - if (classVmFlags(t, type(t, Machine::JobjectType)) & BootstrapFlag) { + if (type(t, GcJobject::Type)->vmFlags() & BootstrapFlag) { PROTECT(t, loader); PROTECT(t, spec); PROTECT(t, elementClass); @@ -2510,22 +2532,22 @@ makeArrayClass(Thread* t, object loader, unsigned dimensions, object spec, // make a stack trace for a ClassNotFoundException. resolveSystemClass (t, root(t, Machine::BootLoader), - className(t, type(t, Machine::JobjectType)), false); + type(t, GcJobject::Type)->name(), false); } - object vtable = classVirtualTable(t, type(t, Machine::JobjectType)); + object vtable = type(t, GcJobject::Type)->virtualTable(); - object c = t->m->processor->makeClass + GcClass* c = t->m->processor->makeClass (t, 0, 0, 2 * BytesPerWord, BytesPerWord, dimensions, - classObjectMask(t, type(t, Machine::ArrayType)), + type(t, GcArray::Type)->objectMask(), spec, 0, - type(t, Machine::JobjectType), + reinterpret_cast(type(t, GcJobject::Type)), root(t, Machine::ArrayInterfaceTable), vtable, 0, @@ -2543,7 +2565,7 @@ makeArrayClass(Thread* t, object loader, unsigned dimensions, object spec, } void -saveLoadedClass(Thread* t, object loader, object c) +saveLoadedClass(Thread* t, object loader, GcClass* c) { PROTECT(t, loader); PROTECT(t, c); @@ -2551,17 +2573,20 @@ saveLoadedClass(Thread* t, object loader, object c) ACQUIRE(t, t->m->classLock); if (classLoaderMap(t, loader) == 0) { - object map = makeHashMap(t, 0, 0); - set(t, loader, ClassLoaderMap, map); + GcHashMap* map = makeHashMap(t, 0, 0); + set(t, loader, ClassLoaderMap, reinterpret_cast(map)); } - hashMapInsert - (t, classLoaderMap(t, loader), className(t, c), c, byteArrayHash); + hashMapInsert(t, + cast(t, classLoaderMap(t, loader)), + c->name(), + reinterpret_cast(c), + byteArrayHash); } -object +GcClass* makeArrayClass(Thread* t, object loader, object spec, bool throw_, - Machine::Type throwType) + Gc::Type throwType) { PROTECT(t, loader); PROTECT(t, spec); @@ -2582,7 +2607,7 @@ makeArrayClass(Thread* t, object loader, object spec, bool throw_, ++ s; } - elementSpec = makeByteArray(t, s - elementSpecStart + 1); + elementSpec = reinterpret_cast(makeByteArray(t, s - elementSpecStart + 1)); memcpy(&byteArrayBody(t, elementSpec, 0), &byteArrayBody(t, spec, elementSpecStart - start), s - elementSpecStart); @@ -2592,7 +2617,7 @@ makeArrayClass(Thread* t, object loader, object spec, bool throw_, default: if (dimensions > 1) { char c = *s; - elementSpec = makeByteArray(t, dimensions + 1); + elementSpec = reinterpret_cast(makeByteArray(t, dimensions + 1)); unsigned i; for (i = 0; i < dimensions - 1; ++i) { byteArrayBody(t, elementSpec, i) = '['; @@ -2605,9 +2630,9 @@ makeArrayClass(Thread* t, object loader, object spec, bool throw_, } } - object elementClass = hashMapFind - (t, root(t, Machine::BootstrapClassMap), elementSpec, byteArrayHash, - byteArrayEqual); + GcClass* elementClass = cast(t, hashMapFind + (t, cast(t, root(t, Machine::BootstrapClassMap)), elementSpec, byteArrayHash, + byteArrayEqual)); if (elementClass == 0) { elementClass = resolveClass(t, loader, elementSpec, throw_, throwType); @@ -2618,32 +2643,35 @@ makeArrayClass(Thread* t, object loader, object spec, bool throw_, ACQUIRE(t, t->m->classLock); - object class_ = findLoadedClass(t, classLoader(t, elementClass), spec); + GcClass* class_ = findLoadedClass(t, elementClass->loader(), spec); if (class_) { return class_; } class_ = makeArrayClass - (t, classLoader(t, elementClass), dimensions, spec, elementClass); + (t, elementClass->loader(), dimensions, spec, reinterpret_cast(elementClass)); PROTECT(t, class_); - saveLoadedClass(t, classLoader(t, elementClass), class_); + saveLoadedClass(t, elementClass->loader(), class_); return class_; } -object +GcClass* resolveArrayClass(Thread* t, object loader, object spec, bool throw_, - Machine::Type throwType) + Gc::Type throwType) { - object c = hashMapFind - (t, root(t, Machine::BootstrapClassMap), spec, byteArrayHash, - byteArrayEqual); + GcClass* c = cast(t, + hashMapFind(t, + cast(t, root(t, Machine::BootstrapClassMap)), + spec, + byteArrayHash, + byteArrayEqual)); if (c) { - set(t, c, ClassVirtualTable, - classVirtualTable(t, type(t, Machine::JobjectType))); + set(t, reinterpret_cast(c), ClassVirtualTable, + type(t, GcJobject::Type)->virtualTable()); return c; } else { @@ -2669,7 +2697,7 @@ removeMonitor(Thread* t, object o) } object m = hashMapRemove - (t, root(t, Machine::MonitorMap), o, objectHash, objectEqual); + (t, cast(t, root(t, Machine::MonitorMap)), o, objectHash, objectEqual); if (DebugMonitors) { fprintf(stderr, "dispose monitor %p for object %x\n", m, hash); @@ -2679,27 +2707,26 @@ removeMonitor(Thread* t, object o) void removeString(Thread* t, object o) { - hashMapRemove(t, root(t, Machine::StringMap), o, stringHash, objectEqual); + hashMapRemove(t, cast(t, root(t, Machine::StringMap)), o, stringHash, objectEqual); } void -bootClass(Thread* t, Machine::Type type, int superType, uint32_t objectMask, +bootClass(Thread* t, Gc::Type type, int superType, uint32_t objectMask, unsigned fixedSize, unsigned arrayElementSize, unsigned vtableLength) { - object super = (superType >= 0 - ? vm::type(t, static_cast(superType)) : 0); + GcClass* super = (superType >= 0 + ? vm::type(t, static_cast(superType)) : 0); object mask; if (objectMask) { if (super - and classObjectMask(t, super) - and intArrayBody(t, classObjectMask(t, super), 0) + and super->objectMask() + and intArrayBody(t, super->objectMask(), 0) == static_cast(objectMask)) { - mask = classObjectMask - (t, vm::type(t, static_cast(superType))); + mask = vm::type(t, static_cast(superType))->objectMask(); } else { - mask = makeIntArray(t, 1); + mask = reinterpret_cast(makeIntArray(t, 1)); intArrayBody(t, mask, 0) = objectMask; } } else { @@ -2707,66 +2734,65 @@ bootClass(Thread* t, Machine::Type type, int superType, uint32_t objectMask, } super = (superType >= 0 - ? vm::type(t, static_cast(superType)) : 0); + ? vm::type(t, static_cast(superType)) : 0); - object class_ = t->m->processor->makeClass + GcClass* class_ = t->m->processor->makeClass (t, 0, BootstrapFlag, fixedSize, arrayElementSize, - arrayElementSize ? 1 : 0, mask, 0, 0, super, 0, 0, 0, 0, 0, 0, + arrayElementSize ? 1 : 0, mask, 0, 0, reinterpret_cast(super), 0, 0, 0, 0, 0, 0, root(t, Machine::BootLoader), vtableLength); setType(t, type, class_); } void -bootJavaClass(Thread* t, Machine::Type type, int superType, const char* name, +bootJavaClass(Thread* t, Gc::Type type, int superType, const char* name, int vtableLength, object bootMethod) { PROTECT(t, bootMethod); - object n = makeByteArray(t, name); + object n = reinterpret_cast(makeByteArray(t, name)); PROTECT(t, n); - object class_ = vm::type(t, type); + GcClass* class_ = vm::type(t, type); PROTECT(t, class_); - set(t, class_, ClassName, n); + set(t, reinterpret_cast(class_), ClassName, n); object vtable; if (vtableLength >= 0) { - vtable = makeArray(t, vtableLength); + vtable = reinterpret_cast(makeArray(t, vtableLength)); for (int i = 0; i < vtableLength; ++ i) { arrayBody(t, vtable, i) = bootMethod; } } else { - vtable = classVirtualTable - (t, vm::type(t, static_cast(superType))); + vtable = vm::type(t, static_cast(superType))->virtualTable(); } - set(t, class_, ClassVirtualTable, vtable); + set(t, reinterpret_cast(class_), ClassVirtualTable, vtable); t->m->processor->initVtable(t, class_); hashMapInsert - (t, root(t, Machine::BootstrapClassMap), n, class_, byteArrayHash); + (t, cast(t, root(t, Machine::BootstrapClassMap)), n, reinterpret_cast(class_), byteArrayHash); } void -nameClass(Thread* t, Machine::Type type, const char* name) +nameClass(Thread* t, Gc::Type type, const char* name) { - object n = makeByteArray(t, name); + object n = reinterpret_cast(makeByteArray(t, name)); set(t, arrayBody(t, t->m->types, type), ClassName, n); } void makeArrayInterfaceTable(Thread* t) { - object interfaceTable = makeArray(t, 4); + object interfaceTable = reinterpret_cast(makeArray(t, 4)); - set(t, interfaceTable, ArrayBody, type - (t, Machine::SerializableType)); + set(t, interfaceTable, ArrayBody, reinterpret_cast(type + (t, GcSerializable::Type))); set(t, interfaceTable, ArrayBody + (2 * BytesPerWord), - type(t, Machine::CloneableType)); + reinterpret_cast(type(t, GcCloneable::Type))); setRoot(t, Machine::ArrayInterfaceTable, interfaceTable); } @@ -2782,95 +2808,95 @@ boot(Thread* t) arrayLength(t, m->roots) = Machine::RootCount; setRoot(t, Machine::BootLoader, - allocate(t, FixedSizeOfSystemClassLoader, true)); + allocate(t, GcSystemClassLoader::FixedSize, true)); setRoot(t, Machine::AppLoader, - allocate(t, FixedSizeOfSystemClassLoader, true)); + allocate(t, GcSystemClassLoader::FixedSize, true)); m->types = allocate(t, pad((TypeCount + 2) * BytesPerWord), true); arrayLength(t, m->types) = TypeCount; #include "type-initializations.cpp" - object arrayClass = type(t, Machine::ArrayType); - set(t, m->types, 0, arrayClass); - set(t, m->roots, 0, arrayClass); + GcClass* arrayClass = type(t, GcArray::Type); + set(t, m->types, 0, reinterpret_cast(arrayClass)); + set(t, m->roots, 0, reinterpret_cast(arrayClass)); - object loaderClass = type(t, Machine::SystemClassLoaderType); - set(t, root(t, Machine::BootLoader), 0, loaderClass); - set(t, root(t, Machine::AppLoader), 0, loaderClass); + GcClass* loaderClass = type(t, GcSystemClassLoader::Type); + set(t, root(t, Machine::BootLoader), 0, reinterpret_cast(loaderClass)); + set(t, root(t, Machine::AppLoader), 0, reinterpret_cast(loaderClass)); - object objectClass = type(t, Machine::JobjectType); + GcClass* objectClass = type(t, GcJobject::Type); - object classClass = type(t, Machine::ClassType); - set(t, classClass, 0, classClass); - set(t, classClass, ClassSuper, objectClass); + GcClass* classClass = type(t, GcClass::Type); + set(t, reinterpret_cast(classClass), 0, reinterpret_cast(classClass)); + set(t, reinterpret_cast(classClass), ClassSuper, reinterpret_cast(objectClass)); - object intArrayClass = type(t, Machine::IntArrayType); - set(t, intArrayClass, 0, classClass); - set(t, intArrayClass, ClassSuper, objectClass); + GcClass* intArrayClass = type(t, GcIntArray::Type); + set(t, reinterpret_cast(intArrayClass), 0, reinterpret_cast(classClass)); + set(t, reinterpret_cast(intArrayClass), ClassSuper, reinterpret_cast(objectClass)); m->unsafe = false; - classVmFlags(t, type(t, Machine::SingletonType)) + type(t, GcSingleton::Type)->vmFlags() |= SingletonFlag; - classVmFlags(t, type(t, Machine::ContinuationType)) + type(t, GcContinuation::Type)->vmFlags() |= ContinuationFlag; - classVmFlags(t, type(t, Machine::JreferenceType)) + type(t, GcJreference::Type)->vmFlags() |= ReferenceFlag; - classVmFlags(t, type(t, Machine::WeakReferenceType)) + type(t, GcWeakReference::Type)->vmFlags() |= ReferenceFlag | WeakReferenceFlag; - classVmFlags(t, type(t, Machine::SoftReferenceType)) + type(t, GcSoftReference::Type)->vmFlags() |= ReferenceFlag | WeakReferenceFlag; - classVmFlags(t, type(t, Machine::PhantomReferenceType)) + type(t, GcPhantomReference::Type)->vmFlags() |= ReferenceFlag | WeakReferenceFlag; - classVmFlags(t, type(t, Machine::JbooleanType)) + type(t, GcJboolean::Type)->vmFlags() |= PrimitiveFlag; - classVmFlags(t, type(t, Machine::JbyteType)) + type(t, GcJbyte::Type)->vmFlags() |= PrimitiveFlag; - classVmFlags(t, type(t, Machine::JcharType)) + type(t, GcJchar::Type)->vmFlags() |= PrimitiveFlag; - classVmFlags(t, type(t, Machine::JshortType)) + type(t, GcJshort::Type)->vmFlags() |= PrimitiveFlag; - classVmFlags(t, type(t, Machine::JintType)) + type(t, GcJint::Type)->vmFlags() |= PrimitiveFlag; - classVmFlags(t, type(t, Machine::JlongType)) + type(t, GcJlong::Type)->vmFlags() |= PrimitiveFlag; - classVmFlags(t, type(t, Machine::JfloatType)) + type(t, GcJfloat::Type)->vmFlags() |= PrimitiveFlag; - classVmFlags(t, type(t, Machine::JdoubleType)) + type(t, GcJdouble::Type)->vmFlags() |= PrimitiveFlag; - classVmFlags(t, type(t, Machine::JvoidType)) + type(t, GcJvoid::Type)->vmFlags() |= PrimitiveFlag; - set(t, type(t, Machine::BooleanArrayType), ClassStaticTable, - type(t, Machine::JbooleanType)); - set(t, type(t, Machine::ByteArrayType), ClassStaticTable, - type(t, Machine::JbyteType)); - set(t, type(t, Machine::CharArrayType), ClassStaticTable, - type(t, Machine::JcharType)); - set(t, type(t, Machine::ShortArrayType), ClassStaticTable, - type(t, Machine::JshortType)); - set(t, type(t, Machine::IntArrayType), ClassStaticTable, - type(t, Machine::JintType)); - set(t, type(t, Machine::LongArrayType), ClassStaticTable, - type(t, Machine::JlongType)); - set(t, type(t, Machine::FloatArrayType), ClassStaticTable, - type(t, Machine::JfloatType)); - set(t, type(t, Machine::DoubleArrayType), ClassStaticTable, - type(t, Machine::JdoubleType)); + set(t, reinterpret_cast(type(t, GcBooleanArray::Type)), ClassStaticTable, + reinterpret_cast(type(t, GcJboolean::Type))); + set(t, reinterpret_cast(type(t, GcByteArray::Type)), ClassStaticTable, + reinterpret_cast(type(t, GcJbyte::Type))); + set(t, reinterpret_cast(type(t, GcCharArray::Type)), ClassStaticTable, + reinterpret_cast(type(t, GcJchar::Type))); + set(t, reinterpret_cast(type(t, GcShortArray::Type)), ClassStaticTable, + reinterpret_cast(type(t, GcJshort::Type))); + set(t, reinterpret_cast(type(t, GcIntArray::Type)), ClassStaticTable, + reinterpret_cast(type(t, GcJint::Type))); + set(t, reinterpret_cast(type(t, GcLongArray::Type)), ClassStaticTable, + reinterpret_cast(type(t, GcJlong::Type))); + set(t, reinterpret_cast(type(t, GcFloatArray::Type)), ClassStaticTable, + reinterpret_cast(type(t, GcJfloat::Type))); + set(t, reinterpret_cast(type(t, GcDoubleArray::Type)), ClassStaticTable, + reinterpret_cast(type(t, GcJdouble::Type))); - { object map = makeHashMap(t, 0, 0); - set(t, root(t, Machine::BootLoader), ClassLoaderMap, map); + { GcHashMap* map = makeHashMap(t, 0, 0); + set(t, root(t, Machine::BootLoader), ClassLoaderMap, reinterpret_cast(map)); } systemClassLoaderFinder(t, root(t, Machine::BootLoader)) = m->bootFinder; - { object map = makeHashMap(t, 0, 0); - set(t, root(t, Machine::AppLoader), ClassLoaderMap, map); + { GcHashMap* map = makeHashMap(t, 0, 0); + set(t, root(t, Machine::AppLoader), ClassLoaderMap, reinterpret_cast(map)); } systemClassLoaderFinder(t, root(t, Machine::AppLoader)) = m->appFinder; @@ -2878,35 +2904,35 @@ boot(Thread* t) set(t, root(t, Machine::AppLoader), ClassLoaderParent, root(t, Machine::BootLoader)); - setRoot(t, Machine::BootstrapClassMap, makeHashMap(t, 0, 0)); + setRoot(t, Machine::BootstrapClassMap, reinterpret_cast(makeHashMap(t, 0, 0))); - setRoot(t, Machine::StringMap, makeWeakHashMap(t, 0, 0)); + setRoot(t, Machine::StringMap, reinterpret_cast(makeWeakHashMap(t, 0, 0))); makeArrayInterfaceTable(t); - set(t, type(t, Machine::BooleanArrayType), ClassInterfaceTable, + set(t, reinterpret_cast(type(t, GcBooleanArray::Type)), ClassInterfaceTable, root(t, Machine::ArrayInterfaceTable)); - set(t, type(t, Machine::ByteArrayType), ClassInterfaceTable, + set(t, reinterpret_cast(type(t, GcByteArray::Type)), ClassInterfaceTable, root(t, Machine::ArrayInterfaceTable)); - set(t, type(t, Machine::CharArrayType), ClassInterfaceTable, + set(t, reinterpret_cast(type(t, GcCharArray::Type)), ClassInterfaceTable, root(t, Machine::ArrayInterfaceTable)); - set(t, type(t, Machine::ShortArrayType), ClassInterfaceTable, + set(t, reinterpret_cast(type(t, GcShortArray::Type)), ClassInterfaceTable, root(t, Machine::ArrayInterfaceTable)); - set(t, type(t, Machine::IntArrayType), ClassInterfaceTable, + set(t, reinterpret_cast(type(t, GcIntArray::Type)), ClassInterfaceTable, root(t, Machine::ArrayInterfaceTable)); - set(t, type(t, Machine::LongArrayType), ClassInterfaceTable, + set(t, reinterpret_cast(type(t, GcLongArray::Type)), ClassInterfaceTable, root(t, Machine::ArrayInterfaceTable)); - set(t, type(t, Machine::FloatArrayType), ClassInterfaceTable, + set(t, reinterpret_cast(type(t, GcFloatArray::Type)), ClassInterfaceTable, root(t, Machine::ArrayInterfaceTable)); - set(t, type(t, Machine::DoubleArrayType), ClassInterfaceTable, + set(t, reinterpret_cast(type(t, GcDoubleArray::Type)), ClassInterfaceTable, root(t, Machine::ArrayInterfaceTable)); m->processor->boot(t, 0, 0); - { object bootCode = makeCode(t, 0, 0, 0, 0, 0, 0, 0, 1); + { object bootCode = reinterpret_cast(makeCode(t, 0, 0, 0, 0, 0, 0, 0, 1)); codeBody(t, bootCode, 0) = impdep1; - object bootMethod = makeMethod - (t, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, bootCode); + object bootMethod = reinterpret_cast(makeMethod + (t, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, bootCode)); PROTECT(t, bootMethod); #include "type-java-initializations.cpp" @@ -2940,8 +2966,8 @@ class HeapClient: public Heap::Client { object o = static_cast(m->heap->follow(maskAlignedPointer(p))); - unsigned n = baseSize(t, o, static_cast - (m->heap->follow(objectClass(t, o)))); + unsigned n = baseSize(t, o, cast(t, static_cast + (m->heap->follow(objectClass(t, o))))); if (objectExtended(t, o)) { ++ n; @@ -2956,8 +2982,8 @@ class HeapClient: public Heap::Client { object o = static_cast(m->heap->follow(maskAlignedPointer(p))); assert(t, not objectFixed(t, o)); - unsigned n = baseSize(t, o, static_cast - (m->heap->follow(objectClass(t, o)))); + unsigned n = baseSize(t, o, cast(t, static_cast + (m->heap->follow(objectClass(t, o))))); if (objectExtended(t, o) or hashTaken(t, o)) { ++ n; @@ -2972,8 +2998,8 @@ class HeapClient: public Heap::Client { object src = static_cast(m->heap->follow(maskAlignedPointer(srcp))); assert(t, not objectFixed(t, src)); - object class_ = static_cast - (m->heap->follow(objectClass(t, src))); + GcClass* class_ = cast(t, static_cast + (m->heap->follow(objectClass(t, src)))); unsigned base = baseSize(t, src, class_); unsigned n = extendedSize(t, src, base); @@ -3070,7 +3096,7 @@ doCollect(Thread* t, Heap::CollectionType type, int pendingAllocation) uint64_t invokeLoadClass(Thread* t, uintptr_t* arguments) { - object method = reinterpret_cast(arguments[0]); + GcMethod* method = cast(t, reinterpret_cast(arguments[0])); object loader = reinterpret_cast(arguments[1]); object specString = reinterpret_cast(arguments[2]); @@ -3079,7 +3105,7 @@ invokeLoadClass(Thread* t, uintptr_t* arguments) } bool -isInitializing(Thread* t, object c) +isInitializing(Thread* t, GcClass* c) { for (Thread::ClassInitStack* s = t->classInitStack; s; s = s->next) { if (s->class_ == c) { @@ -3122,15 +3148,15 @@ findInTable(Thread* t, object table, object name, object spec, } void -updatePackageMap(Thread* t, object class_) +updatePackageMap(Thread* t, GcClass* class_) { PROTECT(t, class_); if (root(t, Machine::PackageMap) == 0) { - setRoot(t, Machine::PackageMap, makeHashMap(t, 0, 0)); + setRoot(t, Machine::PackageMap, reinterpret_cast(makeHashMap(t, 0, 0))); } - object className = vm::className(t, class_); + object className = class_->name(); if ('[' != byteArrayBody(t, className, 0)) { THREAD_RUNTIME_ARRAY (t, char, packageName, byteArrayLength(t, className)); @@ -3150,10 +3176,10 @@ updatePackageMap(Thread* t, object class_) PROTECT(t, key); hashMapRemove - (t, root(t, Machine::PackageMap), key, byteArrayHash, + (t, cast(t, root(t, Machine::PackageMap)), key, byteArrayHash, byteArrayEqual); - object source = classSource(t, class_); + object source = class_->source(); if (source) { // note that we strip the "file:" prefix, since OpenJDK's // Package.defineSystemPackage expects an unadorned filename: @@ -3171,7 +3197,7 @@ updatePackageMap(Thread* t, object class_) } hashMapInsert - (t, root(t, Machine::PackageMap), key, source, byteArrayHash); + (t, cast(t, root(t, Machine::PackageMap)), key, source, byteArrayHash); } } } @@ -3414,13 +3440,13 @@ Thread::init() boot(this); } - setRoot(this, Machine::ByteArrayMap, makeWeakHashMap(this, 0, 0)); - setRoot(this, Machine::MonitorMap, makeWeakHashMap(this, 0, 0)); + setRoot(this, Machine::ByteArrayMap, reinterpret_cast(makeWeakHashMap(this, 0, 0))); + setRoot(this, Machine::MonitorMap, reinterpret_cast(makeWeakHashMap(this, 0, 0))); - setRoot(this, Machine::ClassRuntimeDataTable, makeVector(this, 0, 0)); - setRoot(this, Machine::MethodRuntimeDataTable, makeVector(this, 0, 0)); - setRoot(this, Machine::JNIMethodTable, makeVector(this, 0, 0)); - setRoot(this, Machine::JNIFieldTable, makeVector(this, 0, 0)); + setRoot(this, Machine::ClassRuntimeDataTable, reinterpret_cast(makeVector(this, 0, 0))); + setRoot(this, Machine::MethodRuntimeDataTable, reinterpret_cast(makeVector(this, 0, 0))); + setRoot(this, Machine::JNIMethodTable, reinterpret_cast(makeVector(this, 0, 0))); + setRoot(this, Machine::JNIFieldTable, reinterpret_cast(makeVector(this, 0, 0))); m->localThread->set(this); } @@ -3860,7 +3886,7 @@ collect(Thread* t, Heap::CollectionType type, int pendingAllocation) } object -makeNewGeneral(Thread* t, object class_) +makeNewGeneral(Thread* t, GcClass* class_) { assert(t, t->state == Thread::ActiveState); @@ -3869,14 +3895,14 @@ makeNewGeneral(Thread* t, object class_) object instance = makeNew(t, class_); PROTECT(t, instance); - if (classVmFlags(t, class_) & WeakReferenceFlag) { + if (class_->vmFlags() & WeakReferenceFlag) { ACQUIRE(t, t->m->referenceLock); jreferenceVmNext(t, instance) = t->m->weakReferences; t->m->weakReferences = instance; } - if (classVmFlags(t, class_) & HasFinalizerFlag) { + if (class_->vmFlags() & HasFinalizerFlag) { addFinalizer(t, instance, 0); } @@ -3902,7 +3928,7 @@ makeByteArrayV(Thread* t, const char* format, va_list a, int size) int r = vm::vsnprintf(RUNTIME_ARRAY_BODY(buffer), size - 1, format, a); if (r >= 0 and r < size - 1) { - object s = makeByteArray(t, strlen(RUNTIME_ARRAY_BODY(buffer)) + 1); + object s = reinterpret_cast(makeByteArray(t, strlen(RUNTIME_ARRAY_BODY(buffer)) + 1)); memcpy(&byteArrayBody(t, s, 0), RUNTIME_ARRAY_BODY(buffer), byteArrayLength(t, s)); return s; @@ -3954,7 +3980,7 @@ stringUTFLength(Thread* t, object string, unsigned start, unsigned length) if (length) { object data = stringData(t, string); - if (objectClass(t, data) == type(t, Machine::ByteArrayType)) { + if (objectClass(t, data) == type(t, GcByteArray::Type)) { result = length; } else { for (unsigned i = 0; i < length; ++i) { @@ -3977,7 +4003,7 @@ stringChars(Thread* t, object string, unsigned start, unsigned length, { if (length) { object data = stringData(t, string); - if (objectClass(t, data) == type(t, Machine::ByteArrayType)) { + if (objectClass(t, data) == type(t, GcByteArray::Type)) { memcpy(chars, &byteArrayBody(t, data, stringOffset(t, string) + start), length); @@ -3996,7 +4022,7 @@ stringChars(Thread* t, object string, unsigned start, unsigned length, { if (length) { object data = stringData(t, string); - if (objectClass(t, data) == type(t, Machine::ByteArrayType)) { + if (objectClass(t, data) == type(t, GcByteArray::Type)) { for (unsigned i = 0; i < length; ++i) { chars[i] = byteArrayBody(t, data, stringOffset(t, string) + start + i); } @@ -4017,7 +4043,7 @@ stringUTFChars(Thread* t, object string, unsigned start, unsigned length, (stringUTFLength(t, string, start, length)) == charsLength); object data = stringData(t, string); - if (objectClass(t, data) == type(t, Machine::ByteArrayType)) { + if (objectClass(t, data) == type(t, GcByteArray::Type)) { memcpy(chars, &byteArrayBody(t, data, stringOffset(t, string) + start), length); @@ -4055,16 +4081,16 @@ resolveBootstrap(Thread* t, uintptr_t* arguments) } bool -isAssignableFrom(Thread* t, object a, object b) +isAssignableFrom(Thread* t, GcClass* a, GcClass* b) { assert(t, a); assert(t, b); if (a == b) return true; - if (classFlags(t, a) & ACC_INTERFACE) { - if (classVmFlags(t, b) & BootstrapFlag) { - uintptr_t arguments[] = { reinterpret_cast(className(t, b)) }; + if (a->flags() & ACC_INTERFACE) { + if (b->vmFlags() & BootstrapFlag) { + uintptr_t arguments[] = { reinterpret_cast(b->name()) }; if (run(t, resolveBootstrap, arguments) == 0) { t->exception = 0; @@ -4072,24 +4098,24 @@ isAssignableFrom(Thread* t, object a, object b) } } - object itable = classInterfaceTable(t, b); + object itable = b->interfaceTable(); if (itable) { - unsigned stride = (classFlags(t, b) & ACC_INTERFACE) ? 1 : 2; + unsigned stride = (b->flags() & ACC_INTERFACE) ? 1 : 2; for (unsigned i = 0; i < arrayLength(t, itable); i += stride) { - if (arrayBody(t, itable, i) == a) { + if (arrayBody(t, itable, i) == reinterpret_cast(a)) { return true; } } } - } else if (classArrayDimensions(t, a)) { - if (classArrayDimensions(t, b)) { + } else if (a->arrayDimensions()) { + if (b->arrayDimensions()) { return isAssignableFrom - (t, classStaticTable(t, a), classStaticTable(t, b)); + (t, cast(t, a->staticTable()), cast(t, b->staticTable())); } - } else if ((classVmFlags(t, a) & PrimitiveFlag) - == (classVmFlags(t, b) & PrimitiveFlag)) + } else if ((a->vmFlags() & PrimitiveFlag) + == (b->vmFlags() & PrimitiveFlag)) { - for (; b; b = classSuper(t, b)) { + for (; b; b = cast(t, b->super())) { if (b == a) { return true; } @@ -4100,22 +4126,22 @@ isAssignableFrom(Thread* t, object a, object b) } bool -instanceOf(Thread* t, object class_, object o) +instanceOf(Thread* t, GcClass* class_, object o) { if (o == 0) { return false; } else { - return isAssignableFrom(t, class_, objectClass(t, o)); + return isAssignableFrom(t, class_, reinterpret_cast(objectClass(t, o))); } } object -classInitializer(Thread* t, object class_) +classInitializer(Thread* t, GcClass* class_) { - if (classMethodTable(t, class_)) { - for (unsigned i = 0; i < arrayLength(t, classMethodTable(t, class_)); ++i) + if (class_->methodTable()) { + for (unsigned i = 0; i < arrayLength(t, class_->methodTable()); ++i) { - object o = arrayBody(t, classMethodTable(t, class_), i); + object o = arrayBody(t, class_->methodTable(), i); if (methodVmFlags(t, o) & ClassInitFlag) { return o; @@ -4205,9 +4231,9 @@ primitiveSize(Thread* t, unsigned code) } } -object +GcClass* parseClass(Thread* t, object loader, const uint8_t* data, unsigned size, - Machine::Type throwType) + Gc::Type throwType) { PROTECT(t, loader); @@ -4233,13 +4259,13 @@ parseClass(Thread* t, object loader, const uint8_t* data, unsigned size, fprintf(stderr, "read class (minor %d major %d)\n", minorVer, majorVer); } - object pool = parsePool(t, s); + GcSingleton* pool = parsePool(t, s); PROTECT(t, pool); unsigned flags = s.read2(); unsigned name = s.read2(); - object class_ = makeClass(t, + GcClass* class_ = (GcClass*)makeClass(t, flags, 0, // VM flags 0, // fixed size @@ -4264,14 +4290,14 @@ parseClass(Thread* t, object loader, const uint8_t* data, unsigned size, unsigned super = s.read2(); if (super) { - object sc = resolveClass + GcClass* sc = resolveClass (t, loader, referenceName(t, singletonObject(t, pool, super - 1)), true, throwType); - set(t, class_, ClassSuper, sc); + set(t, reinterpret_cast(class_), ClassSuper, reinterpret_cast(sc)); - classVmFlags(t, class_) - |= (classVmFlags(t, sc) + class_->vmFlags() + |= (sc->vmFlags() & (ReferenceFlag | WeakReferenceFlag | HasFinalizerFlag | NeedInitFlag)); } @@ -4288,27 +4314,27 @@ parseClass(Thread* t, object loader, const uint8_t* data, unsigned size, parseAttributeTable(t, s, class_, pool); - object vtable = classVirtualTable(t, class_); + object vtable = class_->virtualTable(); unsigned vtableLength = (vtable ? arrayLength(t, vtable) : 0); - object real = t->m->processor->makeClass + GcClass* real = t->m->processor->makeClass (t, - classFlags(t, class_), - classVmFlags(t, class_), - classFixedSize(t, class_), - classArrayElementSize(t, class_), - classArrayDimensions(t, class_), - classObjectMask(t, class_), - className(t, class_), - classSourceFile(t, class_), - classSuper(t, class_), - classInterfaceTable(t, class_), - classVirtualTable(t, class_), - classFieldTable(t, class_), - classMethodTable(t, class_), - classAddendum(t, class_), - classStaticTable(t, class_), - classLoader(t, class_), + class_->flags(), + class_->vmFlags(), + 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(), vtableLength); PROTECT(t, real); @@ -4319,12 +4345,15 @@ parseClass(Thread* t, object loader, const uint8_t* data, unsigned size, if (root(t, Machine::PoolMap)) { object bootstrapClass = hashMapFind - (t, root(t, Machine::BootstrapClassMap), className(t, class_), + (t, cast(t, root(t, Machine::BootstrapClassMap)), class_->name(), byteArrayHash, byteArrayEqual); - hashMapInsert - (t, root(t, Machine::PoolMap), bootstrapClass ? bootstrapClass : real, - pool, objectHash); + hashMapInsert( + t, + cast(t, root(t, Machine::PoolMap)), + bootstrapClass ? bootstrapClass : reinterpret_cast(real), + reinterpret_cast(pool), + objectHash); } return real; @@ -4335,23 +4364,23 @@ runParseClass(Thread* t, uintptr_t* arguments) { object loader = reinterpret_cast(arguments[0]); System::Region* region = reinterpret_cast(arguments[1]); - Machine::Type throwType = static_cast(arguments[2]); + Gc::Type throwType = static_cast(arguments[2]); return reinterpret_cast (parseClass(t, loader, region->start(), region->length(), throwType)); } -object +GcClass* resolveSystemClass(Thread* t, object loader, object spec, bool throw_, - Machine::Type throwType) + Gc::Type throwType) { PROTECT(t, loader); PROTECT(t, spec); ACQUIRE(t, t->m->classLock); - object class_ = hashMapFind - (t, classLoaderMap(t, loader), spec, byteArrayHash, byteArrayEqual); + GcClass* class_ = cast(t, hashMapFind + (t, cast(t, classLoaderMap(t, loader)), spec, byteArrayHash, byteArrayEqual)); if (class_ == 0) { PROTECT(t, class_); @@ -4391,8 +4420,8 @@ resolveSystemClass(Thread* t, object loader, object spec, bool throw_, static_cast(throwType) }; // parse class file - class_ = reinterpret_cast - (runRaw(t, runParseClass, arguments)); + class_ = cast + (t, reinterpret_cast(runRaw(t, runParseClass, arguments))); if (UNLIKELY(t->exception)) { if (throw_) { @@ -4418,17 +4447,17 @@ resolveSystemClass(Thread* t, object loader, object spec, bool throw_, if (source) { unsigned length = strlen(source); - object array = makeByteArray(t, length + 1); + object array = reinterpret_cast(makeByteArray(t, length + 1)); memcpy(&byteArrayBody(t, array, 0), source, length); array = internByteArray(t, array); - set(t, class_, ClassSource, array); + set(t, reinterpret_cast(class_), ClassSource, array); } } - object bootstrapClass = hashMapFind - (t, root(t, Machine::BootstrapClassMap), spec, byteArrayHash, - byteArrayEqual); + GcClass* bootstrapClass = cast(t, hashMapFind + (t, cast(t, root(t, Machine::BootstrapClassMap)), spec, byteArrayHash, + byteArrayEqual)); if (bootstrapClass) { PROTECT(t, bootstrapClass); @@ -4440,7 +4469,7 @@ resolveSystemClass(Thread* t, object loader, object spec, bool throw_, } if (class_) { - hashMapInsert(t, classLoaderMap(t, loader), spec, class_, byteArrayHash); + hashMapInsert(t, cast(t, classLoaderMap(t, loader)), spec, reinterpret_cast(class_), byteArrayHash); updatePackageMap(t, class_); } else if (throw_) { @@ -4451,7 +4480,7 @@ resolveSystemClass(Thread* t, object loader, object spec, bool throw_, return class_; } -object +GcClass* findLoadedClass(Thread* t, object loader, object spec) { PROTECT(t, loader); @@ -4459,21 +4488,21 @@ findLoadedClass(Thread* t, object loader, object spec) ACQUIRE(t, t->m->classLock); - return classLoaderMap(t, loader) ? hashMapFind - (t, classLoaderMap(t, loader), spec, byteArrayHash, byteArrayEqual) : 0; + return classLoaderMap(t, loader) ? cast(t, hashMapFind + (t, cast(t, classLoaderMap(t, loader)), spec, byteArrayHash, byteArrayEqual)) : 0; } -object +GcClass* resolveClass(Thread* t, object loader, object spec, bool throw_, - Machine::Type throwType) + Gc::Type throwType) { - if (objectClass(t, loader) == type(t, Machine::SystemClassLoaderType)) { + if (objectClass(t, loader) == type(t, GcSystemClassLoader::Type)) { return resolveSystemClass(t, loader, spec, throw_, throwType); } else { PROTECT(t, loader); PROTECT(t, spec); - object c = findLoadedClass(t, loader, spec); + GcClass* c = findLoadedClass(t, loader, spec); if (c) { return c; } @@ -4482,25 +4511,25 @@ resolveClass(Thread* t, object loader, object spec, bool throw_, c = resolveArrayClass(t, loader, spec, throw_, throwType); } else { if (root(t, Machine::LoadClassMethod) == 0) { - object m = resolveMethod + GcMethod* m = resolveMethod (t, root(t, Machine::BootLoader), "java/lang/ClassLoader", "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;"); if (m) { - setRoot(t, Machine::LoadClassMethod, m); + setRoot(t, Machine::LoadClassMethod, reinterpret_cast(m)); - object classLoaderClass = type(t, Machine::ClassLoaderType); + GcClass* classLoaderClass = type(t, GcClassLoader::Type); - if (classVmFlags(t, classLoaderClass) & BootstrapFlag) { + if (classLoaderClass->vmFlags() & BootstrapFlag) { resolveSystemClass (t, root(t, Machine::BootLoader), - vm::className(t, classLoaderClass)); + classLoaderClass->name()); } } } - object method = findVirtualMethod - (t, root(t, Machine::LoadClassMethod), objectClass(t, loader)); + GcMethod* method = findVirtualMethod + (t, cast(t, root(t, Machine::LoadClassMethod)), objectClass(t, loader)); PROTECT(t, method); @@ -4519,7 +4548,7 @@ resolveClass(Thread* t, object loader, object spec, bool throw_, (runRaw(t, invokeLoadClass, arguments)); if (LIKELY(jc)) { - c = jclassVmClass(t, jc); + c = cast(t, jclassVmClass(t, jc)); } else if (t->exception) { if (throw_) { object e = type(t, throwType) == objectClass(t, t->exception) @@ -4545,62 +4574,62 @@ resolveClass(Thread* t, object loader, object spec, bool throw_, } } -object -resolveMethod(Thread* t, object class_, const char* methodName, +GcMethod* +resolveMethod(Thread* t, GcClass* class_, const char* methodName, const char* methodSpec) { PROTECT(t, class_); - object name = makeByteArray(t, methodName); + object name = reinterpret_cast(makeByteArray(t, methodName)); PROTECT(t, name); - object spec = makeByteArray(t, methodSpec); + object spec = reinterpret_cast(makeByteArray(t, methodSpec)); - object method = findMethodInClass(t, class_, name, spec); + GcMethod* method = cast(t, findMethodInClass(t, class_, name, spec)); if (method == 0) { - throwNew(t, Machine::NoSuchMethodErrorType, "%s %s not found in %s", + throwNew(t, GcNoSuchMethodError::Type, "%s %s not found in %s", methodName, methodSpec, &byteArrayBody - (t, className(t, class_), 0)); + (t, class_->name(), 0)); } else { return method; } } object -resolveField(Thread* t, object class_, const char* fieldName, +resolveField(Thread* t, GcClass* class_, const char* fieldName, const char* fieldSpec) { PROTECT(t, class_); - object name = makeByteArray(t, fieldName); + object name = reinterpret_cast(makeByteArray(t, fieldName)); PROTECT(t, name); - object spec = makeByteArray(t, fieldSpec); + object spec = reinterpret_cast(makeByteArray(t, fieldSpec)); PROTECT(t, spec); object field = findInInterfaces(t, class_, name, spec, findFieldInClass); - object c = class_; + GcClass* c = class_; PROTECT(t, c); - for (; c != 0 and field == 0; c = classSuper(t, c)) { + for (; c != 0 and field == 0; c = cast(t, c->super())) { field = findFieldInClass(t, c, name, spec); } if (field == 0) { - throwNew(t, Machine::NoSuchFieldErrorType, "%s %s not found in %s", - fieldName, fieldSpec, &byteArrayBody(t, className(t, class_), 0)); + throwNew(t, GcNoSuchFieldError::Type, "%s %s not found in %s", + fieldName, fieldSpec, &byteArrayBody(t, class_->name(), 0)); } else { return field; } } bool -classNeedsInit(Thread* t, object c) +classNeedsInit(Thread* t, GcClass* c) { - if (classVmFlags(t, c) & NeedInitFlag) { - if (classVmFlags(t, c) & InitFlag) { + if (c->vmFlags() & NeedInitFlag) { + if (c->vmFlags() & InitFlag) { // the class is currently being initialized. If this the thread // which is initializing it, we should not try to initialize it // recursively. Otherwise, we must wait for the responsible @@ -4618,9 +4647,9 @@ classNeedsInit(Thread* t, object c) } bool -preInitClass(Thread* t, object c) +preInitClass(Thread* t, GcClass* c) { - int flags = classVmFlags(t, c); + int flags = c->vmFlags(); loadMemoryBarrier(); @@ -4628,8 +4657,8 @@ preInitClass(Thread* t, object c) PROTECT(t, c); ACQUIRE(t, t->m->classLock); - if (classVmFlags(t, c) & NeedInitFlag) { - if (classVmFlags(t, c) & InitFlag) { + if (c->vmFlags() & NeedInitFlag) { + if (c->vmFlags() & InitFlag) { // If the class is currently being initialized and this the thread // which is initializing it, we should not try to initialize it // recursively. @@ -4638,15 +4667,15 @@ preInitClass(Thread* t, object c) } // some other thread is on the job - wait for it to finish. - while (classVmFlags(t, c) & InitFlag) { + while (c->vmFlags() & InitFlag) { ENTER(t, Thread::IdleState); t->m->classLock->wait(t->systemThread, 0); } - } else if (classVmFlags(t, c) & InitErrorFlag) { - throwNew(t, Machine::NoClassDefFoundErrorType, "%s", - &byteArrayBody(t, className(t, c), 0)); + } else if (c->vmFlags() & InitErrorFlag) { + throwNew(t, GcNoClassDefFoundError::Type, "%s", + &byteArrayBody(t, c->name(), 0)); } else { - classVmFlags(t, c) |= InitFlag; + c->vmFlags() |= InitFlag; return true; } } @@ -4661,7 +4690,7 @@ postInitClass(Thread* t, object c) ACQUIRE(t, t->m->classLock); if (t->exception - and instanceOf(t, type(t, Machine::ExceptionType), t->exception)) { + and instanceOf(t, type(t, GcException::Type), t->exception)) { classVmFlags(t, c) |= NeedInitFlag | InitErrorFlag; classVmFlags(t, c) &= ~InitFlag; @@ -4669,7 +4698,7 @@ postInitClass(Thread* t, object c) t->exception = 0; exception = makeThrowable - (t, Machine::ExceptionInInitializerErrorType, 0, 0, exception); + (t, GcExceptionInInitializerError::Type, 0, 0, exception); set(t, exception, ExceptionInInitializerErrorException, throwableCause(t, exception)); @@ -4682,19 +4711,19 @@ postInitClass(Thread* t, object c) } void -initClass(Thread* t, object c) +initClass(Thread* t, GcClass* c) { PROTECT(t, c); - object super = classSuper(t, c); + object super = c->super(); if (super) { - initClass(t, super); + initClass(t, cast(t, super)); } if (preInitClass(t, c)) { OBJECT_RESOURCE(t, c, postInitClass(t, c)); - object initializer = classInitializer(t, c); + GcMethod* initializer = cast(t, classInitializer(t, c)); if (initializer) { Thread::ClassInitStack stack(t, c); @@ -4704,14 +4733,14 @@ initClass(Thread* t, object c) } } -object +GcClass* resolveObjectArrayClass(Thread* t, object loader, object elementClass) { PROTECT(t, loader); PROTECT(t, elementClass); - { object arrayClass = classRuntimeDataArrayClass - (t, getClassRuntimeData(t, elementClass)); + { GcClass* arrayClass = cast(t, classRuntimeDataArrayClass + (t, getClassRuntimeData(t, cast(t, elementClass)))); if (arrayClass) { return arrayClass; } @@ -4722,13 +4751,13 @@ resolveObjectArrayClass(Thread* t, object loader, object elementClass) object spec; if (byteArrayBody(t, elementSpec, 0) == '[') { - spec = makeByteArray(t, byteArrayLength(t, elementSpec) + 1); + spec = reinterpret_cast(makeByteArray(t, byteArrayLength(t, elementSpec) + 1)); byteArrayBody(t, spec, 0) = '['; memcpy(&byteArrayBody(t, spec, 1), &byteArrayBody(t, elementSpec, 0), byteArrayLength(t, elementSpec)); } else { - spec = makeByteArray(t, byteArrayLength(t, elementSpec) + 3); + spec = reinterpret_cast(makeByteArray(t, byteArrayLength(t, elementSpec) + 3)); byteArrayBody(t, spec, 0) = '['; byteArrayBody(t, spec, 1) = 'L'; memcpy(&byteArrayBody(t, spec, 2), @@ -4738,58 +4767,58 @@ resolveObjectArrayClass(Thread* t, object loader, object elementClass) byteArrayBody(t, spec, byteArrayLength(t, elementSpec) + 2) = 0; } - object arrayClass = resolveClass(t, loader, spec); + GcClass* arrayClass = resolveClass(t, loader, spec); - set(t, getClassRuntimeData(t, elementClass), ClassRuntimeDataArrayClass, - arrayClass); + set(t, getClassRuntimeData(t, cast(t, elementClass)), ClassRuntimeDataArrayClass, + reinterpret_cast(arrayClass)); return arrayClass; } object -makeObjectArray(Thread* t, object elementClass, unsigned count) +makeObjectArray(Thread* t, GcClass* elementClass, unsigned count) { - object arrayClass = resolveObjectArrayClass - (t, classLoader(t, elementClass), elementClass); + GcClass* arrayClass = resolveObjectArrayClass + (t, elementClass->loader(), reinterpret_cast(elementClass)); PROTECT(t, arrayClass); - object array = makeArray(t, count); + object array = reinterpret_cast(makeArray(t, count)); setObjectClass(t, array, arrayClass); return array; } object -findFieldInClass(Thread* t, object class_, object name, object spec) +findFieldInClass(Thread* t, GcClass* class_, object name, object spec) { return findInTable - (t, classFieldTable(t, class_), name, spec, fieldName, fieldSpec); + (t, class_->fieldTable(), name, spec, fieldName, fieldSpec); } object -findMethodInClass(Thread* t, object class_, object name, object spec) +findMethodInClass(Thread* t, GcClass* class_, object name, object spec) { return findInTable - (t, classMethodTable(t, class_), name, spec, methodName, methodSpec); + (t, class_->methodTable(), name, spec, methodName, methodSpec); } object -findInHierarchyOrNull(Thread* t, object class_, object name, object spec, - object (*find)(Thread*, object, object, object)) +findInHierarchyOrNull(Thread* t, GcClass* class_, object name, object spec, + object (*find)(Thread*, GcClass*, object, object)) { - object originalClass = class_; + GcClass* originalClass = class_; object o = 0; - if ((classFlags(t, class_) & ACC_INTERFACE) - and classVirtualTable(t, class_)) + if ((class_->flags() & ACC_INTERFACE) + and class_->virtualTable()) { o = findInTable - (t, classVirtualTable(t, class_), name, spec, methodName, methodSpec); + (t, class_->virtualTable(), name, spec, methodName, methodSpec); } if (o == 0) { - for (; o == 0 and class_; class_ = classSuper(t, class_)) { + for (; o == 0 and class_; class_ = cast(t, class_->super())) { o = find(t, class_, name, spec); } @@ -4834,9 +4863,9 @@ addFinalizer(Thread* t, object target, void (*finalize)(Thread*, object)) void* function; memcpy(&function, &finalize, BytesPerWord); - object f = makeFinalizer(t, 0, function, 0, 0, 0); - finalizerTarget(t, f) = target; - finalizerNext(t, f) = t->m->finalizers; + GcFinalizer* f = makeFinalizer(t, 0, function, 0, 0, 0); + f->target() = target; + f->next() = reinterpret_cast(t->m->finalizers); t->m->finalizers = f; } @@ -4846,7 +4875,7 @@ objectMonitor(Thread* t, object o, bool createNew) assert(t, t->state == Thread::ActiveState); object m = hashMapFind - (t, root(t, Machine::MonitorMap), o, objectHash, objectEqual); + (t, cast(t, root(t, Machine::MonitorMap)), o, objectHash, objectEqual); if (m) { if (DebugMonitors) { @@ -4861,7 +4890,7 @@ objectMonitor(Thread* t, object o, bool createNew) { ENTER(t, Thread::ExclusiveState); m = hashMapFind - (t, root(t, Machine::MonitorMap), o, objectHash, objectEqual); + (t, cast(t, root(t, Machine::MonitorMap)), o, objectHash, objectEqual); if (m) { if (DebugMonitors) { @@ -4872,15 +4901,15 @@ objectMonitor(Thread* t, object o, bool createNew) return m; } - object head = makeMonitorNode(t, 0, 0); - m = makeMonitor(t, 0, 0, 0, head, head, 0); + object head = reinterpret_cast(makeMonitorNode(t, 0, 0)); + m = reinterpret_cast(makeMonitor(t, 0, 0, 0, head, head, 0)); if (DebugMonitors) { fprintf(stderr, "made monitor %p for object %x\n", m, objectHash(t, o)); } - hashMapInsert(t, root(t, Machine::MonitorMap), o, m, objectHash); + hashMapInsert(t, cast(t, root(t, Machine::MonitorMap)), o, m, objectHash); addFinalizer(t, o, removeMonitor); } @@ -4899,12 +4928,12 @@ intern(Thread* t, object s) ACQUIRE(t, t->m->referenceLock); object n = hashMapFindNode - (t, root(t, Machine::StringMap), s, stringHash, stringEqual); + (t, cast(t, root(t, Machine::StringMap)), s, stringHash, stringEqual); if (n) { return jreferenceTarget(t, tripleFirst(t, n)); } else { - hashMapInsert(t, root(t, Machine::StringMap), s, 0, stringHash); + hashMapInsert(t, cast(t, root(t, Machine::StringMap)), s, 0, stringHash); addFinalizer(t, s, removeString); return s; } @@ -4913,15 +4942,15 @@ intern(Thread* t, object s) void walk(Thread* t, Heap::Walker* w, object o, unsigned start) { - object class_ = static_cast(t->m->heap->follow(objectClass(t, o))); + GcClass* class_ = cast(t, static_cast(t->m->heap->follow(objectClass(t, o)))); object objectMask = static_cast - (t->m->heap->follow(classObjectMask(t, class_))); + (t->m->heap->follow(class_->objectMask())); bool more = true; if (objectMask) { - unsigned fixedSize = classFixedSize(t, class_); - unsigned arrayElementSize = classArrayElementSize(t, class_); + unsigned fixedSize = class_->fixedSize(); + unsigned arrayElementSize = class_->arrayElementSize(); unsigned arrayLength = (arrayElementSize ? fieldAtOffset(o, fixedSize - BytesPerWord) : 0); @@ -4932,11 +4961,11 @@ walk(Thread* t, Heap::Walker* w, object o, unsigned start) more = ::walk(t, w, RUNTIME_ARRAY_BODY(mask), fixedSize, arrayElementSize, arrayLength, start); - } else if (classVmFlags(t, class_) & SingletonFlag) { + } else if (class_->vmFlags() & SingletonFlag) { unsigned length = singletonLength(t, o); if (length) { - more = ::walk(t, w, singletonMask(t, o), - (singletonCount(t, o) + 2) * BytesPerWord, 0, 0, start); + more = ::walk(t, w, singletonMask(t, cast(t, o)), + (singletonCount(t, cast(t, o)) + 2) * BytesPerWord, 0, 0, start); } else if (start == 0) { more = w->visit(0); } @@ -4944,7 +4973,7 @@ walk(Thread* t, Heap::Walker* w, object o, unsigned start) more = w->visit(0); } - if (more and classVmFlags(t, class_) & ContinuationFlag) { + if (more and class_->vmFlags() & ContinuationFlag) { t->m->processor->walkContinuationBody(t, w, o, start); } } @@ -5013,7 +5042,7 @@ void printTrace(Thread* t, object exception) { if (exception == 0) { - exception = makeThrowable(t, Machine::NullPointerExceptionType); + exception = makeThrowable(t, GcNullPointerException::Type); } for (object e = exception; e; e = throwableCause(t, e)) { @@ -5022,7 +5051,7 @@ printTrace(Thread* t, object exception) } logTrace(errorLog(t), "%s", &byteArrayBody - (t, className(t, objectClass(t, e)), 0)); + (t, objectClass(t, e)->name(), 0)); if (throwableMessage(t, e)) { object m = throwableMessage(t, e); @@ -5042,7 +5071,7 @@ printTrace(Thread* t, object exception) const int8_t* method = &byteArrayBody (t, methodName(t, traceElementMethod(t, e)), 0); int line = t->m->processor->lineNumber - (t, traceElementMethod(t, e), traceElementIp(t, e)); + (t, cast(t, traceElementMethod(t, e)), traceElementIp(t, e)); logTrace(errorLog(t), " at %s.%s ", class_, method); @@ -5080,7 +5109,7 @@ makeTrace(Thread* t, Processor::StackWalker* walker) assert(t, trace); } - object e = makeTraceElement(t, walker->method(), walker->ip()); + object e = reinterpret_cast(makeTraceElement(t, reinterpret_cast(walker->method()), walker->ip())); assert(t, index < objectArrayLength(t, trace)); set(t, trace, ArrayBody + (index * BytesPerWord), e); ++ index; @@ -5236,7 +5265,7 @@ parseUtf8(Thread* t, object array) return ::parseUtf8(t, s, byteArrayLength(t, array) - 1); } -object +GcMethod* getCaller(Thread* t, unsigned target, bool skipMethodInvoke) { if (static_cast(target) == -1) { @@ -5252,13 +5281,10 @@ getCaller(Thread* t, unsigned target, bool skipMethodInvoke) virtual bool visit(Processor::StackWalker* walker) { if (skipMethodInvoke - and methodClass - (t, walker->method()) == type(t, Machine::JmethodType) - and strcmp - (&byteArrayBody(t, methodName(t, walker->method()), 0), - reinterpret_cast("invoke")) - == 0) - { + and cast(t, walker->method()->class_()) + == type(t, GcJmethod::Type) + and strcmp(&byteArrayBody(t, walker->method()->name(), 0), + reinterpret_cast("invoke")) == 0) { return true; } @@ -5272,7 +5298,7 @@ getCaller(Thread* t, unsigned target, bool skipMethodInvoke) } Thread* t; - object method; + GcMethod* method; unsigned count; unsigned target; bool skipMethodInvoke; @@ -5288,7 +5314,7 @@ defineClass(Thread* t, object loader, const uint8_t* buffer, unsigned length) { PROTECT(t, loader); - object c = parseClass(t, loader, buffer, length); + object c = reinterpret_cast(parseClass(t, loader, buffer, length)); // char name[byteArrayLength(t, className(t, c))]; // memcpy(name, &byteArrayBody(t, className(t, c), 0), @@ -5307,7 +5333,7 @@ defineClass(Thread* t, object loader, const uint8_t* buffer, unsigned length) PROTECT(t, c); - saveLoadedClass(t, loader, c); + saveLoadedClass(t, loader, cast(t, c)); return c; } @@ -5322,22 +5348,22 @@ populateMultiArray(Thread* t, object array, int32_t* counts, PROTECT(t, array); - object spec = className(t, objectClass(t, array)); + object spec = objectClass(t, array)->name(); PROTECT(t, spec); - object elementSpec = makeByteArray(t, byteArrayLength(t, spec) - 1); + object elementSpec = reinterpret_cast(makeByteArray(t, byteArrayLength(t, spec) - 1)); memcpy(&byteArrayBody(t, elementSpec, 0), &byteArrayBody(t, spec, 1), byteArrayLength(t, spec) - 1); - object class_ = resolveClass - (t, classLoader(t, objectClass(t, array)), elementSpec); + GcClass* class_ = resolveClass + (t, objectClass(t, array)->loader(), elementSpec); PROTECT(t, class_); for (int32_t i = 0; i < counts[index]; ++i) { - object a = makeArray + object a = reinterpret_cast(makeArray (t, ceilingDivide - (counts[index + 1] * classArrayElementSize(t, class_), BytesPerWord)); + (counts[index + 1] * class_->arrayElementSize(), BytesPerWord))); arrayLength(t, a) = counts[index + 1]; setObjectClass(t, a, class_); set(t, array, ArrayBody + (i * BytesPerWord), a); @@ -5358,8 +5384,8 @@ interruptLock(Thread* t, object thread) ACQUIRE(t, t->m->referenceLock); if (threadInterruptLock(t, thread) == 0) { - object head = makeMonitorNode(t, 0, 0); - object lock = makeMonitor(t, 0, 0, 0, head, head, 0); + object head = reinterpret_cast(makeMonitorNode(t, 0, 0)); + object lock = reinterpret_cast(makeMonitor(t, 0, 0, 0, head, head, 0)); storeStoreMemoryBarrier(); @@ -5424,9 +5450,9 @@ vmfPrintTrace(Thread* t, FILE* out) virtual bool visit(Processor::StackWalker* walker) { const int8_t* class_ = &byteArrayBody - (t, className(t, methodClass(t, walker->method())), 0); + (t, className(t, walker->method()->class_()), 0); const int8_t* method = &byteArrayBody - (t, methodName(t, walker->method()), 0); + (t, walker->method()->name(), 0); int line = t->m->processor->lineNumber (t, walker->method(), walker->ip()); @@ -5471,7 +5497,7 @@ vmAddressFromLine(Thread* t, object m, unsigned line) printf("code: %p\n", code); object lnt = codeLineNumberTable(t, code); printf("lnt: %p\n", lnt); - + if (lnt) { unsigned last = 0; unsigned bottom = 0; diff --git a/src/process.cpp b/src/process.cpp index 14181147f1..e5d33cce5f 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -67,18 +67,18 @@ mangle(int8_t c, char* dst) } unsigned -jniNameLength(Thread* t, object method, bool decorate) +jniNameLength(Thread* t, GcMethod* method, bool decorate) { unsigned size = 0; - object className = ::className(t, methodClass(t, method)); + object className = ::className(t, method->class_()); for (unsigned i = 0; i < byteArrayLength(t, className) - 1; ++i) { size += mangledSize(byteArrayBody(t, className, i)); } ++ size; - object methodName = ::methodName(t, method); + object methodName = 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, object method, bool decorate) if (decorate) { size += 2; - object methodSpec = ::methodSpec(t, method); + object methodSpec = method->spec(); for (unsigned i = 1; i < byteArrayLength(t, methodSpec) - 1 and byteArrayBody(t, methodSpec, i) != ')'; ++i) { @@ -99,19 +99,19 @@ jniNameLength(Thread* t, object method, bool decorate) void makeJNIName(Thread* t, const char* prefix, unsigned prefixLength, char* name, - object method, bool decorate) + GcMethod* method, bool decorate) { memcpy(name, prefix, prefixLength); name += prefixLength; - object className = ::className(t, methodClass(t, method)); + object className = ::className(t, method->class_()); for (unsigned i = 0; i < byteArrayLength(t, className) - 1; ++i) { name += mangle(byteArrayBody(t, className, i), name); } *(name++) = '_'; - object methodName = ::methodName(t, method); + object methodName = 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 = ::methodSpec(t, method); + object methodSpec = method->spec(); for (unsigned i = 1; i < byteArrayLength(t, methodSpec) - 1 and byteArrayBody(t, methodSpec, i) != ')'; ++i) { @@ -150,7 +150,7 @@ resolveNativeMethod(Thread* t, const char* undecorated, const char* decorated) } void* -resolveNativeMethod(Thread* t, object method, const char* prefix, +resolveNativeMethod(Thread* t, GcMethod* method, const char* prefix, unsigned prefixLength, int footprint UNUSED) { unsigned undecoratedSize = prefixLength + jniNameLength(t, method, false); @@ -175,7 +175,7 @@ resolveNativeMethod(Thread* t, object method, const char* prefix, // on windows, we also try the _%s@%d and %s@%d variants if (footprint == -1) { footprint = methodParameterFootprint(t, method) + 1; - if (methodFlags(t, method) & ACC_STATIC) { + if (method->flags() & ACC_STATIC) { ++ footprint; } } @@ -206,16 +206,16 @@ resolveNativeMethod(Thread* t, object method, const char* prefix, } object -resolveNativeMethod(Thread* t, object method) +resolveNativeMethod(Thread* t, GcMethod* method) { void* p = resolveNativeMethod(t, method, "Avian_", 6, 3); if (p) { - return makeNative(t, p, true); + return reinterpret_cast(makeNative(t, p, true)); } p = resolveNativeMethod(t, method, "Java_", 5, -1); if (p) { - return makeNative(t, p, false); + return reinterpret_cast(makeNative(t, p, false)); } return 0; @@ -226,21 +226,21 @@ resolveNativeMethod(Thread* t, object method) namespace vm { void -resolveNative(Thread* t, object method) +resolveNative(Thread* t, GcMethod* method) { PROTECT(t, method); - assert(t, methodFlags(t, method) & ACC_NATIVE); + assert(t, method->flags() & ACC_NATIVE); - initClass(t, methodClass(t, method)); + initClass(t, cast(t, method->class_())); if (methodRuntimeDataNative(t, getMethodRuntimeData(t, method)) == 0) { object native = resolveNativeMethod(t, method); if (UNLIKELY(native == 0)) { - throwNew(t, Machine::UnsatisfiedLinkErrorType, "%s.%s%s", - &byteArrayBody(t, className(t, methodClass(t, method)), 0), - &byteArrayBody(t, methodName(t, method), 0), - &byteArrayBody(t, methodSpec(t, method), 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)); } PROTECT(t, native); @@ -256,9 +256,9 @@ resolveNative(Thread* t, object method) } int -findLineNumber(Thread* t, object method, unsigned ip) +findLineNumber(Thread* t, GcMethod* method, unsigned ip) { - if (methodFlags(t, method) & ACC_NATIVE) { + if (method->flags() & ACC_NATIVE) { return NativeLine; } @@ -266,7 +266,7 @@ findLineNumber(Thread* t, object method, unsigned ip) // about, so we back up first: -- ip; - object code = methodCode(t, method); + object code = method->code(); object lnt = codeLineNumberTable(t, code); if (lnt) { unsigned bottom = 0; diff --git a/src/tools/bootimage-generator/main.cpp b/src/tools/bootimage-generator/main.cpp index 62b840a256..b6fc181c90 100644 --- a/src/tools/bootimage-generator/main.cpp +++ b/src/tools/bootimage-generator/main.cpp @@ -176,7 +176,7 @@ endsWith(const char* suffix, const char* s, unsigned length) } object -getNonStaticFields(Thread* t, object typeMaps, object c, object fields, +getNonStaticFields(Thread* t, GcHashMap* typeMaps, object c, object fields, unsigned* count, object* array) { PROTECT(t, typeMaps); @@ -210,12 +210,12 @@ getNonStaticFields(Thread* t, object typeMaps, object c, object fields, } object -allFields(Thread* t, object typeMaps, object c, unsigned* count, object* array) +allFields(Thread* t, GcHashMap* typeMaps, object c, unsigned* count, object* array) { PROTECT(t, typeMaps); PROTECT(t, c); - object fields = makeVector(t, 0, 0); + object fields = reinterpret_cast(makeVector(t, 0, 0)); PROTECT(t, fields); *array = hashMapFind(t, typeMaps, c, objectHash, objectEqual); @@ -248,7 +248,7 @@ allFields(Thread* t, object typeMaps, object c, unsigned* count, object* array) } TypeMap* -classTypeMap(Thread* t, object typeMaps, object p) +classTypeMap(Thread* t, GcHashMap* typeMaps, object p) { return reinterpret_cast (&byteArrayBody @@ -256,18 +256,18 @@ classTypeMap(Thread* t, object typeMaps, object p) } TypeMap* -typeMap(Thread* t, object typeMaps, object p) +typeMap(Thread* t, GcHashMap* typeMaps, object p) { return reinterpret_cast (&byteArrayBody - (t, objectClass(t, p) == type(t, Machine::SingletonType) + (t, objectClass(t, p) == type(t, GcSingleton::Type) ? hashMapFind(t, typeMaps, p, objectHash, objectEqual) - : hashMapFind(t, typeMaps, objectClass(t, p), objectHash, objectEqual), + : hashMapFind(t, typeMaps, reinterpret_cast(objectClass(t, p)), objectHash, objectEqual), 0)); } unsigned -targetFieldOffset(Thread* t, object typeMaps, object field) +targetFieldOffset(Thread* t, GcHashMap* typeMaps, object field) { // if (strcmp(reinterpret_cast // (&byteArrayBody(t, className(t, fieldClass(t, field)), 0)), @@ -282,7 +282,7 @@ targetFieldOffset(Thread* t, object typeMaps, object field) object makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, const char* className, const char* methodName, - const char* methodSpec, object typeMaps) + const char* methodSpec, GcHashMap* typeMaps) { PROTECT(t, typeMaps); @@ -301,13 +301,13 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, class MyOffsetResolver: public OffsetResolver { public: - MyOffsetResolver(object* typeMaps): typeMaps(typeMaps) { } + MyOffsetResolver(GcHashMap** typeMaps): typeMaps(typeMaps) { } virtual unsigned fieldOffset(Thread* t, object field) { return targetFieldOffset(t, *typeMaps, field); } - object* typeMaps; + GcHashMap** typeMaps; } resolver(&typeMaps); Finder* finder = static_cast @@ -321,9 +321,9 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, and (className == 0 or strncmp(name, className, nameSize - 6) == 0)) { // fprintf(stderr, "pass 1 %.*s\n", nameSize - 6, name); - object c = resolveSystemClass + object c = reinterpret_cast(resolveSystemClass (t, root(t, Machine::BootLoader), - makeByteArray(t, "%.*s", nameSize - 6, name), true); + makeByteArray(t, "%.*s", nameSize - 6, name), true)); PROTECT(t, c); @@ -399,8 +399,8 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, } } - object array = makeByteArray - (t, TypeMap::sizeInBytes(count + 2, count + 2)); + object array = reinterpret_cast(makeByteArray + (t, TypeMap::sizeInBytes(count + 2, count + 2))); TypeMap* map = new (&byteArrayBody(t, array, 0)) TypeMap (count + 2, count + 2, count + 2, TypeMap::PoolKind); @@ -417,8 +417,8 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, } hashMapInsert - (t, typeMaps, hashMapFind - (t, root(t, Machine::PoolMap), c, objectHash, objectEqual), array, + (t, typeMaps, reinterpret_cast(hashMapFind + (t, cast(t, root(t, Machine::PoolMap)), c, objectHash, objectEqual)), array, objectHash); } } @@ -548,9 +548,9 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, } if (hashMapFind(t, typeMaps, c, objectHash, objectEqual) == 0) { - object array = makeByteArray + object array = reinterpret_cast(makeByteArray (t, TypeMap::sizeInBytes - (ceilingDivide(classFixedSize(t, c), BytesPerWord), memberIndex)); + (ceilingDivide(classFixedSize(t, c), BytesPerWord), memberIndex))); TypeMap* map = new (&byteArrayBody(t, array, 0)) TypeMap (ceilingDivide(classFixedSize(t, c), BytesPerWord), @@ -571,12 +571,12 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, } if (classStaticTable(t, c)) { - object array = makeByteArray + object array = reinterpret_cast(makeByteArray (t, TypeMap::sizeInBytes - (singletonCount(t, classStaticTable(t, c)) + 2, staticIndex)); + (singletonCount(t, cast(t, classStaticTable(t, c))) + 2, staticIndex))); TypeMap* map = new (&byteArrayBody(t, array, 0)) TypeMap - (singletonCount(t, classStaticTable(t, c)) + 2, + (singletonCount(t, cast(t, classStaticTable(t, c))) + 2, ceilingDivide(targetStaticOffset, TargetBytesPerWord), staticIndex, TypeMap::SingletonKind); @@ -606,41 +606,41 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, and (className == 0 or strncmp(name, className, nameSize - 6) == 0)) { // fprintf(stderr, "pass 2 %.*s\n", nameSize - 6, name); - object c = resolveSystemClass + object c = reinterpret_cast(resolveSystemClass (t, root(t, Machine::BootLoader), - makeByteArray(t, "%.*s", nameSize - 6, name), true); + makeByteArray(t, "%.*s", nameSize - 6, name), true)); PROTECT(t, c); if (classMethodTable(t, c)) { for (unsigned i = 0; i < arrayLength(t, classMethodTable(t, c)); ++i) { - object method = arrayBody(t, classMethodTable(t, c), i); + GcMethod* method = cast(t, arrayBody(t, classMethodTable(t, c), i)); if (((methodName == 0 or ::strcmp (reinterpret_cast (&byteArrayBody - (t, vm::methodName(t, method), 0)), methodName) == 0) + (t, method->name(), 0)), methodName) == 0) and (methodSpec == 0 or ::strcmp (reinterpret_cast (&byteArrayBody - (t, vm::methodSpec(t, method), 0)), methodSpec) + (t, method->spec(), 0)), methodSpec) == 0))) { - if (methodCode(t, method) - or (methodFlags(t, method) & ACC_NATIVE)) + if (method->code() + or (method->flags() & ACC_NATIVE)) { PROTECT(t, method); t->m->processor->compileMethod (t, zone, &constants, &calls, &addresses, method, &resolver); - if (methodCode(t, method)) { - methods = makePair(t, method, methods); + if (method->code()) { + methods = reinterpret_cast(makePair(t, reinterpret_cast(method), methods)); } } - object addendum = methodAddendum(t, method); + object addendum = method->addendum(); if (addendum and methodAddendumExceptionTable(t, addendum)) { PROTECT(t, addendum); @@ -653,11 +653,11 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, (t, methodAddendumExceptionTable(t, addendum), i) - 1; object o = singletonObject - (t, addendumPool(t, addendum), index); + (t, cast(t, addendumPool(t, addendum)), index); - if (objectClass(t, o) == type(t, Machine::ReferenceType)) { - o = resolveClass - (t, root(t, Machine::BootLoader), referenceName(t, o)); + 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), SingletonBody + (index * BytesPerWord), o); @@ -671,12 +671,12 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, } for (; calls; calls = tripleThird(t, calls)) { - object method = tripleFirst(t, calls); + GcMethod* method = cast(t, tripleFirst(t, calls)); uintptr_t address; - if (methodFlags(t, method) & ACC_NATIVE) { + if (method->flags() & ACC_NATIVE) { address = reinterpret_cast(code + image->thunks.native.start); } else { - address = codeCompiled(t, methodCode(t, method)); + address = codeCompiled(t, method->code()); } static_cast(pointerValue(t, tripleSecond(t, calls))) @@ -706,7 +706,7 @@ visitRoots(Thread* t, BootImage* image, HeapWalker* w, object constants) { Machine* m = t->m; - for (HashMapIterator it(t, classLoaderMap(t, root(t, Machine::BootLoader))); + for (HashMapIterator it(t, cast(t, classLoaderMap(t, root(t, Machine::BootLoader)))); it.hasMore();) { w->visitRoot(tripleSecond(t, it.next())); @@ -724,7 +724,7 @@ visitRoots(Thread* t, BootImage* image, HeapWalker* w, object constants) } unsigned -targetOffset(Thread* t, object typeMaps, object p, unsigned offset) +targetOffset(Thread* t, GcHashMap* typeMaps, object p, unsigned offset) { TypeMap* map = typeMap(t, typeMaps, p); @@ -741,7 +741,7 @@ targetOffset(Thread* t, object typeMaps, object p, unsigned offset) } unsigned -targetSize(Thread* t, object typeMaps, object p) +targetSize(Thread* t, GcHashMap* typeMaps, object p) { TypeMap* map = typeMap(t, typeMaps, p); @@ -786,11 +786,11 @@ objectMaskCount(TypeMap* map) } unsigned -targetSize(Thread* t, object typeMaps, object referer, unsigned refererOffset, +targetSize(Thread* t, GcHashMap* typeMaps, object referer, unsigned refererOffset, object p) { if (referer - and objectClass(t, referer) == type(t, Machine::ClassType) + and objectClass(t, referer) == type(t, GcClass::Type) and (refererOffset * BytesPerWord) == ClassObjectMask) { return (TargetBytesPerWord * 2) @@ -913,7 +913,7 @@ nonObjectsEqual(TypeMap* map, uint8_t* src, uint8_t* dst) } void -copy(Thread* t, object typeMaps, object p, uint8_t* dst) +copy(Thread* t, GcHashMap* typeMaps, object p, uint8_t* dst) { TypeMap* map = typeMap(t, typeMaps, p); @@ -935,7 +935,7 @@ copy(Thread* t, object typeMaps, object p, uint8_t* dst) + (i * map->targetArrayElementSizeInBytes), map->arrayElementType); } - if (objectClass(t, p) == type(t, Machine::ClassType)) { + if (objectClass(t, p) == type(t, GcClass::Type)) { uint16_t fixedSize; uint8_t arrayElementSize; object array = hashMapFind(t, typeMaps, p, objectHash, objectEqual); @@ -971,7 +971,7 @@ copy(Thread* t, object typeMaps, object p, uint8_t* dst) } else { switch (map->kind) { case TypeMap::NormalKind: - if (objectClass(t, p) == type(t, Machine::FieldType)) { + if (objectClass(t, p) == type(t, GcField::Type)) { uint16_t offset = targetV2(targetFieldOffset(t, typeMaps, p)); memcpy(dst + TargetFieldOffset, &offset, 2); } @@ -1066,11 +1066,11 @@ copy(Thread* t, object typeMaps, object p, uint8_t* dst) } void -copy(Thread* t, object typeMaps, object referer, unsigned refererOffset, +copy(Thread* t, GcHashMap* typeMaps, object referer, unsigned refererOffset, object p, uint8_t* dst) { if (referer - and objectClass(t, referer) == type(t, Machine::ClassType) + and objectClass(t, referer) == type(t, GcClass::Type) and (refererOffset * BytesPerWord) == ClassObjectMask) { TypeMap* map = classTypeMap(t, typeMaps, referer); @@ -1115,11 +1115,11 @@ copy(Thread* t, object typeMaps, object referer, unsigned refererOffset, HeapWalker* makeHeapImage(Thread* t, BootImage* image, target_uintptr_t* heap, target_uintptr_t* map, unsigned capacity, object constants, - object typeMaps) + GcHashMap* typeMaps) { class Visitor: public HeapVisitor { public: - Visitor(Thread* t, object typeMaps, target_uintptr_t* heap, + Visitor(Thread* t, GcHashMap* typeMaps, target_uintptr_t* heap, target_uintptr_t* map, unsigned capacity): t(t), typeMaps(typeMaps), currentObject(0), currentNumber(0), currentOffset(0), heap(heap), map(map), position(0), capacity(capacity) @@ -1159,9 +1159,9 @@ makeHeapImage(Thread* t, BootImage* image, target_uintptr_t* heap, unsigned number; if ((currentObject - and objectClass(t, currentObject) == type(t, Machine::ClassType) + and objectClass(t, currentObject) == type(t, GcClass::Type) and (currentOffset * BytesPerWord) == ClassStaticTable) - or instanceOf(t, type(t, Machine::SystemClassLoaderType), p)) + or instanceOf(t, type(t, GcSystemClassLoader::Type), p)) { // Static tables and system classloaders must be allocated // as fixed objects in the heap image so that they can be @@ -1235,7 +1235,7 @@ makeHeapImage(Thread* t, BootImage* image, target_uintptr_t* heap, } Thread* t; - object typeMaps; + GcHashMap* typeMaps; object currentObject; unsigned currentNumber; unsigned currentOffset; @@ -1285,7 +1285,7 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp bool useLZMA) { setRoot(t, Machine::OutOfMemoryError, - make(t, type(t, Machine::OutOfMemoryErrorType))); + make(t, type(t, GcOutOfMemoryError::Type))); Zone zone(t->m->system, t->m->heap, 64 * 1024); @@ -1320,14 +1320,14 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp t->m->processor->addCompilationHandler(&compilationHandler); - object classPoolMap; - object typeMaps; + GcHashMap* classPoolMap; + GcHashMap* typeMaps; object constants; { classPoolMap = makeHashMap(t, 0, 0); PROTECT(t, classPoolMap); - setRoot(t, Machine::PoolMap, classPoolMap); + setRoot(t, Machine::PoolMap, reinterpret_cast(classPoolMap)); typeMaps = makeHashMap(t, 0, 0); PROTECT(t, typeMaps); @@ -1456,9 +1456,9 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp targetArrayElementSize = 0; } - object array = makeByteArray + object array = reinterpret_cast(makeByteArray (t, TypeMap::sizeInBytes - (ceilingDivide(buildOffset, BytesPerWord), fixedFieldCount)); + (ceilingDivide(buildOffset, BytesPerWord), fixedFieldCount))); TypeMap* map = new (&byteArrayBody(t, array, 0)) TypeMap (ceilingDivide(buildOffset, BytesPerWord), @@ -1478,7 +1478,7 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp } hashMapInsert - (t, typeMaps, vm::type(t, static_cast(i)), array, + (t, typeMaps, reinterpret_cast(vm::type(t, static_cast(i))), array, objectHash); } @@ -1490,62 +1490,62 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp // these roots will not be used when the bootimage is loaded, so // there's no need to preserve them: setRoot(t, Machine::PoolMap, 0); - setRoot(t, Machine::ByteArrayMap, makeWeakHashMap(t, 0, 0)); + setRoot(t, Machine::ByteArrayMap, reinterpret_cast(makeWeakHashMap(t, 0, 0))); // name all primitive classes so we don't try to update immutable // references at runtime: - { object name = makeByteArray(t, "void"); - set(t, type(t, Machine::JvoidType), ClassName, name); + { object name = reinterpret_cast(makeByteArray(t, "void")); + set(t, reinterpret_cast(type(t, GcJvoid::Type)), ClassName, name); - name = makeByteArray(t, "boolean"); - set(t, type(t, Machine::JbooleanType), ClassName, name); + name = reinterpret_cast(makeByteArray(t, "boolean")); + set(t, reinterpret_cast(type(t, GcJboolean::Type)), ClassName, name); - name = makeByteArray(t, "byte"); - set(t, type(t, Machine::JbyteType), ClassName, name); + name = reinterpret_cast(makeByteArray(t, "byte")); + set(t, reinterpret_cast(type(t, GcJbyte::Type)), ClassName, name); - name = makeByteArray(t, "short"); - set(t, type(t, Machine::JshortType), ClassName, name); + name = reinterpret_cast(makeByteArray(t, "short")); + set(t, reinterpret_cast(type(t, GcJshort::Type)), ClassName, name); - name = makeByteArray(t, "char"); - set(t, type(t, Machine::JcharType), ClassName, name); + name = reinterpret_cast(makeByteArray(t, "char")); + set(t, reinterpret_cast(type(t, GcJchar::Type)), ClassName, name); - name = makeByteArray(t, "int"); - set(t, type(t, Machine::JintType), ClassName, name); + name = reinterpret_cast(makeByteArray(t, "int")); + set(t, reinterpret_cast(type(t, GcJint::Type)), ClassName, name); - name = makeByteArray(t, "float"); - set(t, type(t, Machine::JfloatType), ClassName, name); + name = reinterpret_cast(makeByteArray(t, "float")); + set(t, reinterpret_cast(type(t, GcJfloat::Type)), ClassName, name); - name = makeByteArray(t, "long"); - set(t, type(t, Machine::JlongType), ClassName, name); + name = reinterpret_cast(makeByteArray(t, "long")); + set(t, reinterpret_cast(type(t, GcJlong::Type)), ClassName, name); - name = makeByteArray(t, "double"); - set(t, type(t, Machine::JdoubleType), ClassName, name); + name = reinterpret_cast(makeByteArray(t, "double")); + set(t, reinterpret_cast(type(t, GcJdouble::Type)), ClassName, name); } // resolve primitive array classes in case they are needed at // runtime: - { object name = makeByteArray(t, "[B"); + { object name = reinterpret_cast(makeByteArray(t, "[B")); resolveSystemClass(t, root(t, Machine::BootLoader), name, true); - name = makeByteArray(t, "[Z"); + name = reinterpret_cast(makeByteArray(t, "[Z")); resolveSystemClass(t, root(t, Machine::BootLoader), name, true); - name = makeByteArray(t, "[S"); + name = reinterpret_cast(makeByteArray(t, "[S")); resolveSystemClass(t, root(t, Machine::BootLoader), name, true); - name = makeByteArray(t, "[C"); + name = reinterpret_cast(makeByteArray(t, "[C")); resolveSystemClass(t, root(t, Machine::BootLoader), name, true); - name = makeByteArray(t, "[I"); + name = reinterpret_cast(makeByteArray(t, "[I")); resolveSystemClass(t, root(t, Machine::BootLoader), name, true); - name = makeByteArray(t, "[J"); + name = reinterpret_cast(makeByteArray(t, "[J")); resolveSystemClass(t, root(t, Machine::BootLoader), name, true); - name = makeByteArray(t, "[F"); + name = reinterpret_cast(makeByteArray(t, "[F")); resolveSystemClass(t, root(t, Machine::BootLoader), name, true); - name = makeByteArray(t, "[D"); + name = reinterpret_cast(makeByteArray(t, "[D")); resolveSystemClass(t, root(t, Machine::BootLoader), name, true); } } @@ -1570,7 +1570,7 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp { unsigned i = 0; for (HashMapIterator it - (t, classLoaderMap(t, root(t, Machine::BootLoader))); + (t, cast(t, classLoaderMap(t, root(t, Machine::BootLoader)))); it.hasMore();) { bootClassTable[i++] = targetVW @@ -1586,7 +1586,7 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp { unsigned i = 0; for (HashMapIterator it - (t, classLoaderMap(t, root(t, Machine::AppLoader))); + (t, cast(t, classLoaderMap(t, root(t, Machine::AppLoader)))); it.hasMore();) { appClassTable[i++] = targetVW @@ -1599,7 +1599,7 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp (t->m->heap->allocate(image->stringCount * sizeof(unsigned))); { unsigned i = 0; - for (HashMapIterator it(t, root(t, Machine::StringMap)); it.hasMore();) { + for (HashMapIterator it(t, cast(t, root(t, Machine::StringMap))); it.hasMore();) { stringTable[i++] = targetVW (heapWalker->map()->find (jreferenceTarget(t, tripleFirst(t, it.next())))); diff --git a/src/tools/type-generator/main.cpp b/src/tools/type-generator/main.cpp index 0bb6b14b72..257705b9b9 100644 --- a/src/tools/type-generator/main.cpp +++ b/src/tools/type-generator/main.cpp @@ -309,7 +309,7 @@ class Type : public Object { o->methods.first = o->methods.last = 0; o->overridesMethods = false; return o; - } + } }; const char* @@ -470,7 +470,7 @@ class String : public Object { String* o = allocate(); o->type = Object::String; - + unsigned length = 0; for (Object* p = s; p; p = cdr(p)) ++ length; @@ -506,7 +506,7 @@ endsWith(char c, const char* s) { assert(s); if (*s == 0) return false; - + while (*s) ++ s; return (*(s - 1) == c); } @@ -653,7 +653,7 @@ class MemberIterator { padding_(0), alignment_(BytesPerWord), sawSuperclassBoundary(true) - { + { while (skipSupers and hasMore() and this->type != type) next(); padding_ = 0; alignment_ = BytesPerWord; @@ -701,7 +701,7 @@ class MemberIterator { case Object::Scalar: { size_ = memberSize(member); padding_ = pad(size_, alignment_); - alignment_ = (alignment_ + size_ + padding_) % 8; + alignment_ = (alignment_ + size_ + padding_) % 8; } break; case Object::Array: { @@ -784,7 +784,7 @@ sizeOf(const char* type) return BytesPerWord; } else { fprintf(stderr, "unexpected type: %s\n", type); - abort(); + abort(); } } @@ -980,7 +980,7 @@ parseJavaClass(Object* type, Stream* s, Object* declarations) s->skip(interfaceCount * 2); // for (unsigned i = 0; i < interfaceCount; ++i) { // const char* name = reinterpret_cast -// (pool[pool[s->read2() - 1] - 1]); +// (pool[pool[s->read2() - 1] - 1]); // } unsigned fieldCount = s->read2(); @@ -1037,7 +1037,7 @@ parseJavaClass(Object* type, Stream* s, Object* declarations) Object* method = Method::make(type, name, spec); addMethod(type, method); typeOverridesMethods(type) = true; - } + } } } @@ -1220,10 +1220,10 @@ writeAccessor(Output* out, Object* member, Object* offset, bool unsafe = false) if (memberOwner(member)->type == Object::Type) { if (not unsafe) { out->write(" assert(t, t->m->unsafe or "); - out->write("instanceOf(t, arrayBodyUnsafe"); - out->write("(t, t->m->types, Machine::"); + 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("Type))"); out->write(", o));\n"); if (member->type != Object::Scalar) { @@ -1435,9 +1435,9 @@ writeConstructorParameters(Output* out, Object* t) out->write(" "); out->write(obfuscate(memberName(m))); } break; - + default: break; - } + } } } @@ -1451,9 +1451,9 @@ writeConstructorArguments(Output* out, Object* t) out->write(", "); out->write(obfuscate(memberName(m))); } break; - + default: break; - } + } } } @@ -1472,7 +1472,59 @@ writeConstructorInitializations(Output* out, Object* t) } break; default: break; - } + } + } +} + +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; + + default: + break; + } + } +} + +void writeClassDeclarations(Output* out, Object* declarations) +{ + 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"); + + writeClassAccessors(out, o); + + out->write("};\n\n"); + } break; + + default: + break; + } } } @@ -1486,7 +1538,7 @@ writeInitializerDeclarations(Output* out, Object* declarations) out->write("void init"); out->write(capitalize(typeName(o))); out->write("(Thread* t, object o"); - + writeConstructorParameters(out, o); out->write(");\n\n"); @@ -1504,10 +1556,12 @@ writeConstructorDeclarations(Output* out, Object* declarations) Object* o = car(p); switch (o->type) { case Object::Type: { - out->write("object make"); + out->write("Gc"); + out->write(capitalize(typeName(o))); + out->write("* make"); out->write(capitalize(typeName(o))); out->write("(Thread* t"); - + writeConstructorParameters(out, o); out->write(");\n\n"); @@ -1528,15 +1582,15 @@ writeInitializers(Output* out, Object* declarations) out->write("void\ninit"); out->write(capitalize(typeName(o))); out->write("(Thread* t, object o"); - + writeConstructorParameters(out, o); out->write(")\n{\n"); out->write(" setObjectClass(t, o, "); - out->write("arrayBody(t, t->m->types, Machine::"); + out->write("reinterpret_cast(arrayBody(t, t->m->types, Gc::"); out->write(capitalize(typeName(o))); - out->write("Type));\n"); + out->write("Type)));\n"); writeConstructorInitializations(out, o); @@ -1555,10 +1609,12 @@ writeConstructors(Output* out, Object* declarations) Object* o = car(p); switch (o->type) { case Object::Type: { - out->write("object make"); + out->write("Gc"); + out->write(capitalize(typeName(o))); + out->write("* make"); out->write(capitalize(typeName(o))); out->write("(Thread* t"); - + writeConstructorParameters(out, o); out->write(")\n{\n"); @@ -1598,7 +1654,9 @@ writeConstructors(Output* out, Object* declarations) writeConstructorArguments(out, o); out->write(");\n"); - out->write(" return o;\n}\n\n"); + out->write(" return reinterpret_castwrite(capitalize(typeName(o))); + out->write("*>(o);\n}\n\n"); } break; default: break; @@ -1629,7 +1687,7 @@ writeEnums(Output* out, Object* declarations) if (wrote) { out->write("\n"); - } + } } unsigned @@ -1685,23 +1743,23 @@ typeObjectMask(Object* type) void writeInitialization(Output* out, Object* type) { - out->write("bootClass(t, Machine::"); + out->write("bootClass(t, Gc::"); out->write(capitalize(typeName(type))); out->write("Type, "); if (typeSuper(type)) { - out->write("Machine::"); + out->write("Gc::"); out->write(capitalize(typeName(typeSuper(type)))); out->write("Type"); } else { - out->write("-1"); + out->write("-1"); } out->write(", "); if (typeObjectMask(type) != 1) { out->write(typeObjectMask(type)); } else { - out->write("0"); + out->write("0"); } out->write(", "); @@ -1769,16 +1827,16 @@ writeInitializations(Output* out, Object* declarations) void writeJavaInitialization(Output* out, Object* type) { - out->write("bootJavaClass(t, Machine::"); + out->write("bootJavaClass(t, Gc::"); out->write(capitalize(typeName(type))); out->write("Type, "); if (typeSuper(type)) { - out->write("Machine::"); + out->write("Gc::"); out->write(capitalize(typeName(typeSuper(type)))); out->write("Type"); } else { - out->write("-1"); + out->write("-1"); } out->write(", \""); @@ -1807,7 +1865,7 @@ writeJavaInitializations(Output* out, Object* declarations) void writeNameInitialization(Output* out, Object* type) { - out->write("nameClass(t, Machine::"); + out->write("nameClass(t, Gc::"); out->write(capitalize(typeName(type))); out->write("Type, \""); if (equal(typeName(type), "jbyte") @@ -1820,7 +1878,7 @@ writeNameInitialization(Output* out, Object* type) or equal(typeName(type), "jdouble") or equal(typeName(type), "jvoid")) { - out->write(typeName(type) + 1); + out->write(typeName(type) + 1); } else { out->write("vm::"); out->write(typeName(type)); @@ -2012,6 +2070,7 @@ int main(int ac, char** av) local::writeAccessors(&out, declarations); local::writeSizes(&out, declarations); + local::writeClassDeclarations(&out, declarations); local::writeInitializerDeclarations(&out, declarations); local::writeConstructorDeclarations(&out, declarations); } else if (local::equal(outputType.value, "constructors")) { diff --git a/src/util.cpp b/src/util.cpp index fce0cd538f..4a23c30b9b 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -93,8 +93,8 @@ cloneTreeNode(Thread* t, object n) { PROTECT(t, n); - object newNode = makeTreeNode - (t, getTreeNodeValue(t, n), treeNodeLeft(t, n), treeNodeRight(t, n)); + object newNode = reinterpret_cast(makeTreeNode + (t, getTreeNodeValue(t, n), treeNodeLeft(t, n), treeNodeRight(t, n))); setTreeNodeRed(t, newNode, treeNodeRed(t, n)); return newNode; } @@ -315,13 +315,13 @@ treeAdd(Thread* t, TreeContext* c) namespace vm { object -hashMapFindNode(Thread* t, object map, object key, +hashMapFindNode(Thread* t, GcHashMap* map, object key, uint32_t (*hash)(Thread*, object), bool (*equal)(Thread*, object, object)) { - bool weak = objectClass(t, map) == type(t, Machine::WeakHashMapType); + bool weak = objectClass(t, map) == type(t, GcWeakHashMap::Type); - object array = hashMapArray(t, map); + object array = map->array(); if (array) { unsigned index = hash(t, key) & (arrayLength(t, array) - 1); for (object n = arrayBody(t, array, index); n; n = tripleThird(t, n)) { @@ -342,7 +342,7 @@ hashMapFindNode(Thread* t, object map, object key, } void -hashMapResize(Thread* t, object map, uint32_t (*hash)(Thread*, object), +hashMapResize(Thread* t, GcHashMap* map, uint32_t (*hash)(Thread*, object), unsigned size) { PROTECT(t, map); @@ -350,7 +350,7 @@ hashMapResize(Thread* t, object map, uint32_t (*hash)(Thread*, object), object newArray = 0; if (size) { - object oldArray = hashMapArray(t, map); + object oldArray = map->array(); PROTECT(t, oldArray); unsigned newLength = nextPowerOfTwo(size); @@ -358,16 +358,16 @@ hashMapResize(Thread* t, object map, uint32_t (*hash)(Thread*, object), return; } - newArray = makeArray(t, newLength); + newArray = reinterpret_cast(makeArray(t, newLength)); - if (oldArray != hashMapArray(t, map)) { + if (oldArray != map->array()) { // a resize was performed during a GC via the makeArray call // above; nothing left to do return; } if (oldArray) { - bool weak = objectClass(t, map) == type(t, Machine::WeakHashMapType); + bool weak = objectClass(t, map) == type(t, GcWeakHashMap::Type); for (unsigned i = 0; i < arrayLength(t, oldArray); ++i) { object next; for (object p = arrayBody(t, oldArray, i); p; p = next) { @@ -390,11 +390,11 @@ hashMapResize(Thread* t, object map, uint32_t (*hash)(Thread*, object), } } - set(t, map, HashMapArray, newArray); + set(t, reinterpret_cast(map), HashMapArray, newArray); } void -hashMapInsert(Thread* t, object map, object key, object value, +hashMapInsert(Thread* t, GcHashMap* map, object key, object value, uint32_t (*hash)(Thread*, object)) { // note that we reinitialize the array variable whenever an @@ -405,19 +405,19 @@ hashMapInsert(Thread* t, object map, object key, object value, uint32_t h = hash(t, key); - bool weak = objectClass(t, map) == type(t, Machine::WeakHashMapType); + bool weak = objectClass(t, map) == type(t, GcWeakHashMap::Type); - object array = hashMapArray(t, map); + object array = map->array(); - ++ hashMapSize(t, map); + ++ map->size(); - if (array == 0 or hashMapSize(t, map) >= arrayLength(t, array) * 2) { + if (array == 0 or map->size() >= arrayLength(t, array) * 2) { PROTECT(t, key); PROTECT(t, value); hashMapResize(t, map, hash, array ? arrayLength(t, array) * 2 : 16); - array = hashMapArray(t, map); + array = map->array(); } object k = key; @@ -426,25 +426,25 @@ hashMapInsert(Thread* t, object map, object key, object value, PROTECT(t, key); PROTECT(t, value); - object r = makeWeakReference(t, 0, 0, 0, 0); + object r = reinterpret_cast(makeWeakReference(t, 0, 0, 0, 0)); jreferenceTarget(t, r) = key; jreferenceVmNext(t, r) = t->m->weakReferences; t->m->weakReferences = r; k = r; - array = hashMapArray(t, map); + array = map->array(); } - object n = makeTriple(t, k, value, 0); + object n = reinterpret_cast(makeTriple(t, k, value, 0)); - array = hashMapArray(t, map); + array = map->array(); unsigned index = h & (arrayLength(t, array) - 1); set(t, n, TripleThird, arrayBody(t, array, index)); set(t, array, ArrayBody + (index * BytesPerWord), n); - if (hashMapSize(t, map) <= arrayLength(t, array) / 3) { + if (map->size() <= arrayLength(t, array) / 3) { // this might happen if nodes were removed during GC in which case // we weren't able to resize at the time hashMapResize(t, map, hash, arrayLength(t, array) / 2); @@ -452,26 +452,26 @@ hashMapInsert(Thread* t, object map, object key, object value, } object -hashMapRemoveNode(Thread* t, object map, unsigned index, object p, object n) +hashMapRemoveNode(Thread* t, GcHashMap* map, unsigned index, object p, object n) { if (p) { set(t, p, TripleThird, tripleThird(t, n)); } else { - set(t, hashMapArray(t, map), ArrayBody + (index * BytesPerWord), + set(t, map->array(), ArrayBody + (index * BytesPerWord), tripleThird(t, n)); } - -- hashMapSize(t, map); + -- map->size(); return n; } object -hashMapRemove(Thread* t, object map, object key, +hashMapRemove(Thread* t, GcHashMap* map, object key, uint32_t (*hash)(Thread*, object), bool (*equal)(Thread*, object, object)) { - bool weak = objectClass(t, map) == type(t, Machine::WeakHashMapType); + bool weak = objectClass(t, map) == type(t, GcWeakHashMap::Type); - object array = hashMapArray(t, map); + object array = map->array(); object o = 0; if (array) { unsigned index = hash(t, key) & (arrayLength(t, array) - 1); @@ -496,7 +496,7 @@ hashMapRemove(Thread* t, object map, object key, } if ((not t->m->collecting) - and hashMapSize(t, map) <= arrayLength(t, array) / 3) + and map->size() <= arrayLength(t, array) / 3) { PROTECT(t, o); hashMapResize(t, map, hash, arrayLength(t, array) / 2); @@ -513,7 +513,7 @@ listAppend(Thread* t, object list, object value) ++ listSize(t, list); - object p = makePair(t, value, 0); + object p = reinterpret_cast(makePair(t, value, 0)); if (listFront(t, list)) { set(t, listRear(t, list), PairSecond, p); } else { @@ -529,8 +529,8 @@ vectorAppend(Thread* t, object vector, object value) PROTECT(t, vector); PROTECT(t, value); - object newVector = makeVector - (t, vectorSize(t, vector), max(16, vectorSize(t, vector) * 2)); + object newVector = reinterpret_cast(makeVector + (t, vectorSize(t, vector), max(16, vectorSize(t, vector) * 2))); if (vectorSize(t, vector)) { memcpy(&vectorBody(t, newVector, 0), @@ -551,8 +551,8 @@ growArray(Thread* t, object array) { PROTECT(t, array); - object newArray = makeArray - (t, array == 0 ? 16 : (arrayLength(t, array) * 2)); + object newArray = reinterpret_cast(makeArray + (t, array == 0 ? 16 : (arrayLength(t, array) * 2))); if (array) { memcpy(&arrayBody(t, newArray, 0), &arrayBody(t, array, 0), @@ -578,7 +578,7 @@ treeInsert(Thread* t, Zone* zone, object tree, intptr_t key, object value, PROTECT(t, tree); PROTECT(t, sentinal); - object node = makeTreeNode(t, value, sentinal, sentinal); + object node = reinterpret_cast(makeTreeNode(t, value, sentinal, sentinal)); TreeContext c(t, zone); treeFind(t, &c, tree, key, node, sentinal, compare);