diff --git a/src/avian/classpath-common.h b/src/avian/classpath-common.h index d63480567b..5ad2c09463 100644 --- a/src/avian/classpath-common.h +++ b/src/avian/classpath-common.h @@ -642,7 +642,7 @@ getFinder(Thread* t, const char* name, unsigned nameLength) { ACQUIRE(t, t->m->referenceLock); - for (GcFinder* p = cast(t, root(t, Machine::VirtualFileFinders)); + for (GcFinder* p = roots(t)->virtualFileFinders(); p; p = p->next()) { if (p->name()->length() == nameLength @@ -669,9 +669,9 @@ getFinder(Thread* t, const char* name, unsigned nameLength) if (data) { Finder* f = makeFinder(t->m->system, t->m->heap, data, size); GcFinder* finder = makeFinder - (t, f, n, cast(t, root(t, Machine::VirtualFileFinders))); + (t, f, n, roots(t)->virtualFileFinders()); - setRoot(t, Machine::VirtualFileFinders, reinterpret_cast(finder)); + set(t, roots(t), RootsVirtualFileFinders, finder); return f; } diff --git a/src/avian/machine.h b/src/avian/machine.h index 641cae0a4e..e19a52dfd7 100644 --- a/src/avian/machine.h +++ b/src/avian/machine.h @@ -1211,6 +1211,7 @@ class GcClassLoader; class GcJreference; class GcArray; class GcThrowable; +class GcRoots; class Machine { public: @@ -1221,38 +1222,6 @@ class Machine { ImmortalAllocation }; - enum Root { - BootLoader, - AppLoader, - BootstrapClassMap, - PackageMap, - FindLoadedClassMethod, - LoadClassMethod, - MonitorMap, - StringMap, - ByteArrayMap, - PoolMap, - ClassRuntimeDataTable, - MethodRuntimeDataTable, - JNIMethodTable, - JNIFieldTable, - ShutdownHooks, - FinalizerThread, - ObjectsToFinalize, - ObjectsToClean, - NullPointerException, - ArithmeticException, - ArrayIndexOutOfBoundsException, - OutOfMemoryError, - Shutdown, - VirtualFileFinders, - VirtualFiles, - ArrayInterfaceTable, - ThreadTerminated - }; - - static const unsigned RootCount = ThreadTerminated + 1; - Machine(System* system, Heap* heap, Finder* bootFinder, Finder* appFinder, Processor* processor, Classpath* classpath, const char** properties, unsigned propertyCount, const char** arguments, @@ -1296,7 +1265,7 @@ class Machine { FILE* errorLog; BootImage* bootimage; GcArray* types; - GcArray* roots; + GcRoots* roots; GcFinalizer* finalizers; GcFinalizer* tenuredFinalizers; GcFinalizer* finalizeQueue; @@ -1340,8 +1309,8 @@ run(Thread* t, uint64_t (*function)(Thread*, uintptr_t*), void checkDaemon(Thread* t); -object& -root(Thread* t, Machine::Root root); +GcRoots* +roots(Thread* t); extern "C" uint64_t vmRun(uint64_t (*function)(Thread*, uintptr_t*), uintptr_t* arguments, @@ -1524,17 +1493,7 @@ class Thread { t->systemThread = st; } - virtual void run() { - enterActiveState(t); - - vm::run(t, runThread, 0); - - if (t->exception and reinterpret_cast(t->exception) != root(t, Machine::Shutdown)) { - printTrace(t, t->exception); - } - - t->exit(); - } + virtual void run(); virtual bool interrupted(); @@ -2011,6 +1970,18 @@ arrayBodyUnsafe(Thread*, GcArray* a, unsigned index) return a->body()[index]; } +inline void Thread::Runnable::run() { + enterActiveState(t); + + vm::run(t, runThread, 0); + + if (t->exception and t->exception != roots(t)->shutdownInProgress()) { + printTrace(t, t->exception); + } + + t->exit(); +} + inline bool Thread::Runnable::interrupted() { return t->javaThread and t->javaThread->interrupted(); } @@ -2194,16 +2165,10 @@ attachThread(Machine* m, bool daemon) } } -inline object& -root(Thread* t, Machine::Root root) +inline GcRoots* +roots(Thread* t) { - return t->m->roots->body()[root]; -} - -inline void -setRoot(Thread* t, Machine::Root root, object value) -{ - set(t, reinterpret_cast(t->m->roots), ArrayBody + (root * BytesPerWord), value); + return t->m->roots; } inline GcClass* @@ -3392,7 +3357,7 @@ wait(Thread* t, object o, int64_t milliseconds) t->m->classpath->clearInterrupted(t); throwNew(t, GcInterruptedException::Type); } else { - throw_(t, cast(t, root(t, Machine::Shutdown))); + throw_(t, roots(t)->shutdownInProgress()); } } } else { @@ -3471,7 +3436,7 @@ inline bool exceptionMatch(Thread* t, GcClass* type, GcThrowable* exception) { return type == 0 - or (reinterpret_cast(exception) != root(t, Machine::Shutdown) + or (exception != roots(t)->shutdownInProgress() and instanceOf(t, type, reinterpret_cast(t->exception))); } @@ -3847,7 +3812,9 @@ inline GcClassRuntimeData* getClassRuntimeDataIfExists(Thread* t, GcClass* c) { if (c->runtimeDataIndex()) { - return cast(t, cast(t, root(t, Machine::ClassRuntimeDataTable))->body()[c->runtimeDataIndex() - 1]); + return cast( + t, + roots(t)->classRuntimeDataTable()->body()[c->runtimeDataIndex() - 1]); } else { return 0; } @@ -3864,16 +3831,20 @@ getClassRuntimeData(Thread* t, GcClass* c) if (c->runtimeDataIndex() == 0) { object runtimeData = reinterpret_cast(makeClassRuntimeData(t, 0, 0, 0, 0)); - setRoot(t, Machine::ClassRuntimeDataTable, reinterpret_cast(vectorAppend - (t, cast(t, root(t, Machine::ClassRuntimeDataTable)), runtimeData))); + { + GcVector* v + = vectorAppend(t, roots(t)->classRuntimeDataTable(), runtimeData); + // sequence point, for gc (don't recombine statements) + set(t, roots(t), RootsClassRuntimeDataTable, v); + } - c->runtimeDataIndex() = cast(t, root(t, Machine::ClassRuntimeDataTable))->size(); + c->runtimeDataIndex() = roots(t)->classRuntimeDataTable()->size(); } } return cast( t, - cast(t, root(t, Machine::ClassRuntimeDataTable)) + roots(t)->classRuntimeDataTable() ->body()[c->runtimeDataIndex() - 1]); } @@ -3892,18 +3863,22 @@ getMethodRuntimeData(Thread* t, GcMethod* method) if (method->runtimeDataIndex() == 0) { object runtimeData = reinterpret_cast(makeMethodRuntimeData(t, 0)); - setRoot(t, Machine::MethodRuntimeDataTable, reinterpret_cast(vectorAppend - (t, cast(t, root(t, Machine::MethodRuntimeDataTable)), runtimeData))); + { + GcVector* v + = vectorAppend(t, roots(t)->methodRuntimeDataTable(), runtimeData); + // sequence point, for gc (don't recombine statements) + set(t, roots(t), RootsMethodRuntimeDataTable, v); + } storeStoreMemoryBarrier(); - method->runtimeDataIndex() = cast(t, root(t, Machine::MethodRuntimeDataTable))->size(); + method->runtimeDataIndex() = roots(t)->methodRuntimeDataTable()->size(); } } return cast( t, - cast(t, root(t, Machine::MethodRuntimeDataTable)) + roots(t)->methodRuntimeDataTable() ->body()[method->runtimeDataIndex() - 1]); } diff --git a/src/builtin.cpp b/src/builtin.cpp index 5be80bb6d0..56d35f16a8 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -255,7 +255,7 @@ Avian_avian_SystemClassLoader_getPackageSource GcByteArray* key = makeByteArray(t, RUNTIME_ARRAY_BODY(chars)); GcByteArray* array = cast(t, hashMapFind - (t, cast(t, root(t, Machine::PackageMap)), reinterpret_cast(key), byteArrayHash, byteArrayEqual)); + (t, roots(t)->packageMap(), reinterpret_cast(key), byteArrayHash, byteArrayEqual)); if (array) { return reinterpret_cast(makeLocalReference( diff --git a/src/classpath-android.cpp b/src/classpath-android.cpp index 4a726391f1..85c973ce17 100644 --- a/src/classpath-android.cpp +++ b/src/classpath-android.cpp @@ -81,7 +81,7 @@ finalizeAllEnqueued(Thread*, object, uintptr_t*) int64_t JNICALL appLoader(Thread* t, object, uintptr_t*) { - return reinterpret_cast(root(t, Machine::AppLoader)); + return reinterpret_cast(roots(t)->appLoader()); } int64_t JNICALL @@ -177,7 +177,7 @@ void initVmThread(Thread* t, GcThread* thread, unsigned offset) if (fieldAtOffset(thread, offset) == 0) { GcClass* c = resolveClass - (t, cast(t, root(t, Machine::BootLoader)), "java/lang/VMThread"); + (t, roots(t)->bootLoader(), "java/lang/VMThread"); PROTECT(t, c); object instance = makeNew(t, c); @@ -213,7 +213,7 @@ translateStackTrace(Thread* t, object raw) object array = makeObjectArray (t, resolveClass - (t, cast(t, root(t, Machine::BootLoader)), "java/lang/StackTraceElement"), + (t, roots(t)->bootLoader(), "java/lang/StackTraceElement"), objectArrayLength(t, raw)); PROTECT(t, array); @@ -278,7 +278,7 @@ class MyClasspath : public Classpath { group = parent->javaThread->group(); } else { resolveSystemClass - (t, cast(t, root(t, Machine::BootLoader)), + (t, roots(t)->bootLoader(), type(t, GcThreadGroup::Type)->name(), false); group = cast(t, makeNew(t, type(t, GcThreadGroup::Type))); @@ -290,7 +290,7 @@ class MyClasspath : public Classpath { } resolveSystemClass - (t, cast(t, root(t, Machine::BootLoader)), + (t, roots(t)->bootLoader(), type(t, GcThread::Type)->name(), false); GcThread* thread = cast(t, makeNew(t, type(t, GcThread::Type))); @@ -303,7 +303,7 @@ class MyClasspath : public Classpath { t->m->processor->invoke (t, constructor, reinterpret_cast(thread), group, 0, NormalPriority, false); - set(t, reinterpret_cast(thread), ThreadContextClassLoader, root(t, Machine::AppLoader)); + set(t, thread, ThreadContextClassLoader, roots(t)->appLoader()); initVmThread(t, thread); @@ -392,7 +392,7 @@ class MyClasspath : public Classpath { initVmThread(t, t->javaThread, offset); GcMethod* method = resolveMethod - (t, cast(t, root(t, Machine::BootLoader)), "java/lang/Thread", "run", "()V"); + (t, roots(t)->bootLoader(), "java/lang/Thread", "run", "()V"); t->m->processor->invoke(t, method, reinterpret_cast(t->javaThread)); } @@ -407,7 +407,7 @@ class MyClasspath : public Classpath { interceptMethods(Thread* t, bool updateRuntimeData) { { GcClass* c = resolveClass - (t, cast(t, root(t, Machine::BootLoader)), "java/lang/Runtime", false); + (t, roots(t)->bootLoader(), "java/lang/Runtime", false); if (c) { PROTECT(t, c); @@ -419,7 +419,7 @@ class MyClasspath : public Classpath { } { GcClass* c = resolveClass - (t, cast(t, root(t, Machine::BootLoader)), "java/lang/ref/FinalizerReference", + (t, roots(t)->bootLoader(), "java/lang/ref/FinalizerReference", false); if (c) { @@ -431,7 +431,7 @@ class MyClasspath : public Classpath { } { GcClass* c = resolveClass - (t, cast(t, root(t, Machine::BootLoader)), "java/lang/ClassLoader", false); + (t, roots(t)->bootLoader(), "java/lang/ClassLoader", false); if (c) { PROTECT(t, c); @@ -446,7 +446,7 @@ class MyClasspath : public Classpath { } { GcClass* c = resolveClass - (t, cast(t, root(t, Machine::BootLoader)), "libcore/util/ZoneInfoDB", false); + (t, roots(t)->bootLoader(), "libcore/util/ZoneInfoDB", false); if (c) { PROTECT(t, c); @@ -457,7 +457,7 @@ class MyClasspath : public Classpath { } { GcClass* c = resolveClass - (t, cast(t, root(t, Machine::BootLoader)), "libcore/io/MemoryMappedFile", + (t, roots(t)->bootLoader(), "libcore/io/MemoryMappedFile", false); if (c) { @@ -504,7 +504,7 @@ class MyClasspath : public Classpath { boot(Thread* t) { GcClass* c = resolveClass - (t, cast(t, root(t, Machine::BootLoader)), "java/lang/ClassLoader"); + (t, roots(t)->bootLoader(), "java/lang/ClassLoader"); PROTECT(t, c); GcMethod* constructor = resolveMethod @@ -512,11 +512,11 @@ class MyClasspath : public Classpath { PROTECT(t, constructor); t->m->processor->invoke - (t, constructor, root(t, Machine::BootLoader), 0, true); + (t, constructor, reinterpret_cast(roots(t)->bootLoader()), 0, true); t->m->processor->invoke - (t, constructor, root(t, Machine::AppLoader), - root(t, Machine::BootLoader), false); + (t, constructor, reinterpret_cast(roots(t)->appLoader()), + roots(t)->bootLoader(), false); } virtual const char* @@ -529,7 +529,7 @@ class MyClasspath : public Classpath { makeDirectByteBuffer(Thread* t, void* p, jlong capacity) { GcClass* c = resolveClass - (t, cast(t, root(t, Machine::BootLoader)), "java/nio/DirectByteBuffer"); + (t, roots(t)->bootLoader(), "java/nio/DirectByteBuffer"); PROTECT(t, c); object instance = makeNew(t, c); @@ -602,7 +602,7 @@ int64_t JNICALL mapData(Thread* t, object, uintptr_t*) { GcClass* c = resolveClass - (t, cast(t, root(t, Machine::BootLoader)), "libcore/io/MemoryMappedFile"); + (t, roots(t)->bootLoader(), "libcore/io/MemoryMappedFile"); PROTECT(t, c); object instance = makeNew(t, c); @@ -1219,7 +1219,7 @@ Avian_java_lang_Class_classForName PROTECT(t, loader); GcMethod* method = resolveMethod - (t, cast(t, root(t, Machine::BootLoader)), "avian/Classes", "forName", + (t, roots(t)->bootLoader(), "avian/Classes", "forName", "(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;"); return reinterpret_cast @@ -1238,7 +1238,7 @@ Avian_java_lang_Class_getDeclaredField PROTECT(t, name); GcMethod* method = resolveMethod - (t, cast(t, root(t, Machine::BootLoader)), "avian/Classes", "findField", + (t, roots(t)->bootLoader(), "avian/Classes", "findField", "(Lavian/VMClass;Ljava/lang/String;)I"); int index = cast @@ -1266,7 +1266,7 @@ Avian_java_lang_Class_getDeclaredConstructorOrMethod PROTECT(t, parameterTypes); GcMethod* method = resolveMethod - (t, cast(t, root(t, Machine::BootLoader)), "avian/Classes", "findMethod", + (t, roots(t)->bootLoader(), "avian/Classes", "findMethod", "(Lavian/VMClass;Ljava/lang/String;[Ljava/lang/Class;)I"); int index = cast @@ -1321,14 +1321,14 @@ extern "C" AVIAN_EXPORT int64_t JNICALL Avian_dalvik_system_VMRuntime_bootClassPath (Thread* t, object, uintptr_t*) { - return reinterpret_cast(root(t, Machine::BootLoader)); + return reinterpret_cast(roots(t)->bootLoader()); } extern "C" AVIAN_EXPORT int64_t JNICALL Avian_dalvik_system_VMRuntime_classPath (Thread* t, object, uintptr_t*) { - return reinterpret_cast(root(t, Machine::AppLoader)); + return reinterpret_cast(roots(t)->appLoader()); } extern "C" AVIAN_EXPORT int64_t JNICALL @@ -1823,7 +1823,7 @@ Avian_java_lang_Class_getDeclaredMethods bool publicOnly = arguments[1]; GcMethod* get = resolveMethod - (t, cast(t, root(t, Machine::BootLoader)), "avian/Classes", "getMethods", + (t, roots(t)->bootLoader(), "avian/Classes", "getMethods", "(Lavian/VMClass;Z)[Ljava/lang/reflect/Method;"); return reinterpret_cast @@ -1840,7 +1840,7 @@ Avian_java_lang_Class_getDeclaredFields bool publicOnly = arguments[1]; GcMethod* get = resolveMethod - (t, cast(t, root(t, Machine::BootLoader)), "avian/Classes", "getFields", + (t, roots(t)->bootLoader(), "avian/Classes", "getFields", "(Lavian/VMClass;Z)[Ljava/lang/reflect/Field;"); return reinterpret_cast @@ -1915,7 +1915,7 @@ Avian_java_lang_reflect_Method_getAnnotation PROTECT(t, table); GcMethod* get = resolveMethod - (t, cast(t, root(t, Machine::BootLoader)), "avian/Classes", "getAnnotation", + (t, roots(t)->bootLoader(), "avian/Classes", "getAnnotation", "(Ljava/lang/ClassLoader;[Ljava/lang/Object;)" "Ljava/lang/annotation/Annotation;"); @@ -1948,12 +1948,12 @@ Avian_java_lang_reflect_Method_getDeclaredAnnotations object array = makeObjectArray (t, resolveClass - (t, cast(t, root(t, Machine::BootLoader)), "java/lang/annotation/Annotation"), + (t, roots(t)->bootLoader(), "java/lang/annotation/Annotation"), objectArrayLength(t, table)); PROTECT(t, array); GcMethod* get = resolveMethod - (t, cast(t, root(t, Machine::BootLoader)), "avian/Classes", "getAnnotation", + (t, roots(t)->bootLoader(), "avian/Classes", "getAnnotation", "(Ljava/lang/ClassLoader;[Ljava/lang/Object;)" "Ljava/lang/annotation/Annotation;"); PROTECT(t, get); @@ -1973,7 +1973,7 @@ Avian_java_lang_reflect_Method_getDeclaredAnnotations return reinterpret_cast (makeObjectArray (t, resolveClass - (t, cast(t, root(t, Machine::BootLoader)), "java/lang/annotation/Annotation"), + (t, roots(t)->bootLoader(), "java/lang/annotation/Annotation"), 0)); } @@ -1997,13 +1997,13 @@ extern "C" AVIAN_EXPORT int64_t JNICALL object array = makeObjectArray(t, resolveClass(t, - cast(t, root(t, Machine::BootLoader)), + roots(t)->bootLoader(), "java/lang/annotation/Annotation"), objectArrayLength(t, table)); PROTECT(t, array); GcMethod* get = resolveMethod(t, - cast(t, root(t, Machine::BootLoader)), + roots(t)->bootLoader(), "avian/Classes", "getAnnotation", "(Ljava/lang/ClassLoader;[Ljava/lang/Object;)" @@ -2028,7 +2028,7 @@ extern "C" AVIAN_EXPORT int64_t JNICALL return reinterpret_cast(makeObjectArray( t, resolveClass( - t, cast(t, root(t, Machine::BootLoader)), "java/lang/annotation/Annotation"), + t, roots(t)->bootLoader(), "java/lang/annotation/Annotation"), 0)); } @@ -2043,7 +2043,7 @@ Avian_java_lang_reflect_Method_getDefaultValue GcMethodAddendum* addendum = method->addendum(); if (addendum) { GcMethod* get = resolveMethod - (t, cast(t, root(t, Machine::BootLoader)), "avian/Classes", + (t, roots(t)->bootLoader(), "avian/Classes", "getAnnotationDefaultValue", "(Ljava/lang/ClassLoader;Lavian/MethodAddendum;)" "Ljava/lang/Object;"); @@ -2192,7 +2192,7 @@ Avian_java_lang_reflect_Field_getAnnotation PROTECT(t, table); GcMethod* get = resolveMethod - (t, cast(t, root(t, Machine::BootLoader)), "avian/Classes", "getAnnotation", + (t, roots(t)->bootLoader(), "avian/Classes", "getAnnotation", "(Ljava/lang/ClassLoader;[Ljava/lang/Object;)" "Ljava/lang/annotation/Annotation;"); @@ -2473,7 +2473,7 @@ extern "C" AVIAN_EXPORT int64_t JNICALL Avian_libcore_io_Posix_uname(Thread* t, object, uintptr_t*) { GcClass* c = resolveClass - (t, root(t, Machine::BootLoader), "libcore/io/StructUtsname"); + (t, roots(t)->bootLoader(), "libcore/io/StructUtsname"); PROTECT(t, c); object instance = makeNew(t, c); diff --git a/src/classpath-avian.cpp b/src/classpath-avian.cpp index 985d6107a8..0fed87b61b 100644 --- a/src/classpath-avian.cpp +++ b/src/classpath-avian.cpp @@ -53,7 +53,7 @@ class MyClasspath : public Classpath { return vm::makeThread (t, 0, 0, 0, 0, 0, NewState, NormalPriority, 0, 0, 0, - cast(t, root(t, Machine::AppLoader)), 0, 0, group, 0); + roots(t)->appLoader(), 0, 0, group, 0); } virtual object @@ -97,7 +97,7 @@ class MyClasspath : public Classpath { runThread(Thread* t) { GcMethod* method = resolveMethod - (t, cast(t, root(t, Machine::BootLoader)), "java/lang/Thread", "run", + (t, roots(t)->bootLoader(), "java/lang/Thread", "run", "(Ljava/lang/Thread;)V"); t->m->processor->invoke(t, method, 0, t->javaThread); @@ -142,7 +142,7 @@ class MyClasspath : public Classpath { makeDirectByteBuffer(Thread* t, void* p, jlong capacity) { GcClass* c = resolveClass - (t, cast(t, root(t, Machine::BootLoader)), "java/nio/DirectByteBuffer"); + (t, roots(t)->bootLoader(), "java/nio/DirectByteBuffer"); PROTECT(t, c); object instance = makeNew(t, c); @@ -618,8 +618,8 @@ Avian_java_lang_Runtime_addShutdownHook ACQUIRE(t, t->m->shutdownLock); - setRoot(t, Machine::ShutdownHooks, - reinterpret_cast(makePair(t, hook, root(t, Machine::ShutdownHooks)))); + GcPair* p = makePair(t, hook, reinterpret_cast(roots(t)->shutdownHooks())); + set(t, roots(t), RootsShutdownHooks, p); } extern "C" AVIAN_EXPORT int64_t JNICALL @@ -793,7 +793,7 @@ Avian_avian_Classes_makeMethod PROTECT(t, method); GcClass* c = resolveClass - (t, cast(t, root(t, Machine::BootLoader)), "java/lang/reflect/Method"); + (t, roots(t)->bootLoader(), "java/lang/reflect/Method"); PROTECT(t, c); object instance = makeNew(t, c); @@ -807,7 +807,7 @@ Avian_avian_Classes_makeMethod object oldInstance = instance; c = resolveClass - (t, cast(t, root(t, Machine::BootLoader)), "java/lang/reflect/Constructor"); + (t, roots(t)->bootLoader(), "java/lang/reflect/Constructor"); object instance = makeNew(t, c); diff --git a/src/classpath-openjdk.cpp b/src/classpath-openjdk.cpp index dcec53bf83..004f36a58d 100644 --- a/src/classpath-openjdk.cpp +++ b/src/classpath-openjdk.cpp @@ -560,7 +560,7 @@ class MyClasspath : public Classpath { thread->group() = group; // TODO: use set / write barrier? - thread->contextClassLoader() = cast(t, root(t, Machine::AppLoader)); + thread->contextClassLoader() = roots(t)->appLoader(); PROTECT(t, thread); @@ -649,14 +649,14 @@ class MyClasspath : public Classpath { t->exception = 0; t->m->processor->invoke - (t, cast(t, root(t, Machine::ThreadTerminated)), + (t, cast(t, roots(t)->threadTerminated()), reinterpret_cast(t->javaThread->group()), t->javaThread); t->exception = e; }); GcMethod* method = resolveMethod - (t, cast(t, root(t, Machine::BootLoader)), "java/lang/Thread", "run", "()V"); + (t, roots(t)->bootLoader(), "java/lang/Thread", "run", "()V"); t->m->processor->invoke(t, method, reinterpret_cast(t->javaThread)); } @@ -703,12 +703,14 @@ class MyClasspath : public Classpath { { globalMachine = t->m; - resolveSystemClass(t, cast(t, root(t, Machine::BootLoader)), + resolveSystemClass(t, roots(t)->bootLoader(), type(t, GcClassLoader::Type)->name()); - setRoot(t, Machine::ThreadTerminated, reinterpret_cast(resolveMethod - (t, cast(t, root(t, Machine::BootLoader)), "java/lang/ThreadGroup", - "threadTerminated", "(Ljava/lang/Thread;)V"))); + GcMethod* method = resolveMethod + (t, roots(t)->bootLoader(), "java/lang/ThreadGroup", + "threadTerminated", "(Ljava/lang/Thread;)V"); + // sequence point, for gc (don't recombine statements) + set(t, roots(t), RootsThreadTerminated, method); #ifdef AVIAN_OPENJDK_SRC interceptFileOperations(t, true); @@ -721,12 +723,12 @@ class MyClasspath : public Classpath { (t, type(t, GcClassLoader::Type), "assertionLock", "Ljava/lang/Object;"); - set(t, cast(t, root(t, Machine::BootLoader)), assertionLock->offset(), - cast(t, root(t, Machine::BootLoader))); + set(t, roots(t)->bootLoader(), assertionLock->offset(), + roots(t)->bootLoader()); } { GcClass* class_ = resolveClass - (t, cast(t, root(t, Machine::BootLoader)), "java/util/Properties", true, + (t, roots(t)->bootLoader(), "java/util/Properties", true, GcNoClassDefFoundError::Type); PROTECT(t, class_); @@ -740,7 +742,7 @@ class MyClasspath : public Classpath { t->m->processor->invoke(t, constructor, instance); t->m->processor->invoke - (t, cast(t, root(t, Machine::BootLoader)), "java/lang/System", + (t, roots(t)->bootLoader(), "java/lang/System", "setProperties", "(Ljava/util/Properties;)V", 0, instance); } @@ -750,11 +752,11 @@ class MyClasspath : public Classpath { PROTECT(t, constructor); - t->m->processor->invoke(t, constructor, root(t, Machine::BootLoader), 0); + t->m->processor->invoke(t, constructor, reinterpret_cast(roots(t)->bootLoader()), 0); t->m->processor->invoke - (t, constructor, root(t, Machine::AppLoader), - cast(t, root(t, Machine::BootLoader))); + (t, constructor, reinterpret_cast(roots(t)->appLoader()), + roots(t)->bootLoader()); } { GcField* scl = resolveField @@ -766,23 +768,23 @@ class MyClasspath : public Classpath { GcField* sclSet = resolveField (t, type(t, GcClassLoader::Type), "sclSet", "Z"); - set(t, reinterpret_cast(type(t, GcClassLoader::Type)->staticTable()), - scl->offset(), root(t, Machine::AppLoader)); + set(t, type(t, GcClassLoader::Type)->staticTable(), + scl->offset(), roots(t)->appLoader()); fieldAtOffset(type(t, GcClassLoader::Type)->staticTable(), sclSet->offset()) = true; } t->m->processor->invoke - (t, cast(t, root(t, Machine::BootLoader)), "java/lang/System", + (t, roots(t)->bootLoader(), "java/lang/System", "initializeSystemClass", "()V", 0); t->m->processor->invoke - (t, cast(t, root(t, Machine::BootLoader)), "sun/misc/Launcher", + (t, roots(t)->bootLoader(), "sun/misc/Launcher", "getLauncher", "()Lsun/misc/Launcher;", 0); - set(t, reinterpret_cast(t->javaThread), ThreadContextClassLoader, - root(t, Machine::AppLoader)); + set(t, t->javaThread, ThreadContextClassLoader, + roots(t)->appLoader()); } virtual const char* @@ -795,7 +797,7 @@ class MyClasspath : public Classpath { makeDirectByteBuffer(Thread* t, void* p, jlong capacity) { GcClass* c = resolveClass - (t, cast(t, root(t, Machine::BootLoader)), "java/nio/DirectByteBuffer"); + (t, roots(t)->bootLoader(), "java/nio/DirectByteBuffer"); PROTECT(t, c); object instance = makeNew(t, c); @@ -884,7 +886,7 @@ class MyClasspath : public Classpath { shutDown(Thread* t) { GcClass* c = resolveClass - (t, cast(t, root(t, Machine::BootLoader)), "java/lang/Shutdown", false); + (t, roots(t)->bootLoader(), "java/lang/Shutdown", false); if (c) { GcMethod* m = findMethodOrNull(t, c, "shutdown", "()V"); @@ -1168,24 +1170,24 @@ openFile(Thread* t, object method, uintptr_t* arguments) ACQUIRE(t, t->m->referenceLock); int index = -1; - unsigned oldLength = root(t, Machine::VirtualFiles) - ? arrayLength(t, root(t, Machine::VirtualFiles)) : 0; + unsigned oldLength = roots(t)->virtualFiles() + ? arrayLength(t, roots(t)->virtualFiles()) : 0; for (unsigned i = 0; i < oldLength; ++i) { - if (arrayBody(t, root(t, Machine::VirtualFiles), i) == 0) { + if (arrayBody(t, roots(t)->virtualFiles(), i) == 0) { index = i; break; } } if (index == -1) { - object newArray = growArray(t, root(t, Machine::VirtualFiles)); + object newArray = growArray(t, roots(t)->virtualFiles()); setRoot(t, Machine::VirtualFiles, newArray); index = oldLength; } object region = makeRegion(t, r, 0); - set(t, root(t, Machine::VirtualFiles), ArrayBody + (index * BytesPerWord), + set(t, roots(t)->virtualFiles(), ArrayBody + (index * BytesPerWord), region); fieldAtOffset @@ -1215,7 +1217,7 @@ readByteFromFile(Thread* t, object method, uintptr_t* arguments) ACQUIRE(t, t->m->referenceLock); object region = arrayBody - (t, root(t, Machine::VirtualFiles), fd - VirtualFileBase); + (t, roots(t)->virtualFiles(), fd - VirtualFileBase); if (region) { System::Region* r = static_cast @@ -1258,7 +1260,7 @@ readBytesFromFile(Thread* t, object method, uintptr_t* arguments) ACQUIRE(t, t->m->referenceLock); object region = arrayBody - (t, root(t, Machine::VirtualFiles), fd - VirtualFileBase); + (t, roots(t)->virtualFiles(), fd - VirtualFileBase); if (region) { System::Region* r = static_cast @@ -1308,7 +1310,7 @@ skipBytesInFile(Thread* t, object method, uintptr_t* arguments) ACQUIRE(t, t->m->referenceLock); object region = arrayBody - (t, root(t, Machine::VirtualFiles), fd - VirtualFileBase); + (t, roots(t)->virtualFiles(), fd - VirtualFileBase); if (region) { System::Region* r = static_cast @@ -1349,7 +1351,7 @@ availableBytesInFile(Thread* t, object method, uintptr_t* arguments) ACQUIRE(t, t->m->referenceLock); object region = arrayBody - (t, root(t, Machine::VirtualFiles), fd - VirtualFileBase); + (t, roots(t)->virtualFiles(), fd - VirtualFileBase); if (region) { return static_cast(regionRegion(t, region))->length() @@ -1382,13 +1384,13 @@ closeFile(Thread* t, object method, uintptr_t* arguments) ACQUIRE(t, t->m->referenceLock); int index = fd - VirtualFileBase; - object region = arrayBody(t, root(t, Machine::VirtualFiles), index); + object region = arrayBody(t, roots(t)->virtualFiles(), index); if (region) { static_cast(regionRegion(t, region))->dispose(); } - set(t, root(t, Machine::VirtualFiles), ArrayBody + (index * BytesPerWord), + set(t, roots(t)->virtualFiles(), ArrayBody + (index * BytesPerWord), 0); } else { t->m->processor->invoke @@ -1848,7 +1850,7 @@ getBootstrapResource(Thread* t, object, uintptr_t* arguments) if (m) { return reinterpret_cast - (t->m->processor->invoke(t, m, cast(t, root(t, Machine::BootLoader)), name)); + (t->m->processor->invoke(t, m, roots(t)->bootLoader(), name)); } else { return 0; } @@ -1866,7 +1868,7 @@ getBootstrapResources(Thread* t, object, uintptr_t* arguments) if (m) { return reinterpret_cast - (t->m->processor->invoke(t, m, cast(t, root(t, Machine::BootLoader)), name)); + (t->m->processor->invoke(t, m, roots(t)->bootLoader(), name)); } else { return 0; } @@ -1944,7 +1946,7 @@ interceptFileOperations(Thread* t, bool updateRuntimeData) MyClasspath* cp = static_cast(t->m->classpath); { object fileClass = resolveClass - (t, cast(t, root(t, Machine::BootLoader)), "java/io/File", false); + (t, roots(t)->bootLoader(), "java/io/File", false); if (fileClass) { object filePathField = findFieldInClass2 @@ -1957,7 +1959,7 @@ interceptFileOperations(Thread* t, bool updateRuntimeData) } { object fileDescriptorClass = resolveClass - (t, cast(t, root(t, Machine::BootLoader)), "java/io/FileDescriptor", false); + (t, roots(t)->bootLoader(), "java/io/FileDescriptor", false); if (fileDescriptorClass) { object fileDescriptorFdField = findFieldInClass2 @@ -1970,7 +1972,7 @@ interceptFileOperations(Thread* t, bool updateRuntimeData) } { object fileInputStreamClass = resolveClass - (t, cast(t, root(t, Machine::BootLoader)), "java/io/FileInputStream", false); + (t, roots(t)->bootLoader(), "java/io/FileInputStream", false); if (fileInputStreamClass) { PROTECT(t, fileInputStreamClass); @@ -2008,7 +2010,7 @@ interceptFileOperations(Thread* t, bool updateRuntimeData) } { object zipFileClass = resolveClass - (t, cast(t, root(t, Machine::BootLoader)), "java/util/zip/ZipFile", false); + (t, roots(t)->bootLoader(), "java/util/zip/ZipFile", false); if (zipFileClass) { PROTECT(t, zipFileClass); @@ -2061,7 +2063,7 @@ interceptFileOperations(Thread* t, bool updateRuntimeData) } { object jarFileClass = resolveClass - (t, cast(t, root(t, Machine::BootLoader)), "java/util/jar/JarFile", false); + (t, roots(t)->bootLoader(), "java/util/jar/JarFile", false); if (jarFileClass) { intercept(t, jarFileClass, "getMetaInfEntryNames", @@ -2080,7 +2082,7 @@ interceptFileOperations(Thread* t, bool updateRuntimeData) #endif object fsClass = resolveClass - (t, cast(t, root(t, Machine::BootLoader)), fsClassName, false); + (t, roots(t)->bootLoader(), fsClassName, false); if (fsClass) { PROTECT(t, fsClass); @@ -2550,7 +2552,7 @@ Avian_sun_misc_Perf_createLong return reinterpret_cast (t->m->processor->invoke (t, resolveMethod - (t, cast(t, root(t, Machine::BootLoader)), "java/nio/ByteBuffer", "allocate", + (t, roots(t)->bootLoader(), "java/nio/ByteBuffer", "allocate", "(I)Ljava/nio/ByteBuffer;"), 0, 8)); } @@ -2956,7 +2958,7 @@ jvmInitProperties(Thread* t, uintptr_t* arguments) jobject properties = reinterpret_cast(arguments[0]); GcMethod* method = resolveMethod - (t, cast(t, root(t, Machine::BootLoader)), "java/util/Properties", "setProperty", + (t, roots(t)->bootLoader(), "java/util/Properties", "setProperty", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;"); PROTECT(t, method); @@ -3024,7 +3026,7 @@ jvmInitProperties(Thread* t, uintptr_t* arguments) local::setProperty (t, method, *properties, "sun.boot.class.path", static_cast - (cast(t, root(t, Machine::BootLoader))->finder())->path()); + (roots(t)->bootLoader()->as(t)->finder())->path()); local::setProperty(t, method, *properties, "file.encoding", "UTF-8"); #ifdef ARCH_x86_32 @@ -3526,7 +3528,7 @@ jvmGetSystemPackage(Thread* t, uintptr_t* arguments) object key = reinterpret_cast(makeByteArray(t, RUNTIME_ARRAY_BODY(chars))); GcByteArray* array = cast(t, hashMapFind - (t, cast(t, root(t, Machine::PackageMap)), key, byteArrayHash, byteArrayEqual)); + (t, roots(t)->packageMap(), key, byteArrayHash, byteArrayEqual)); if (array) { return reinterpret_cast @@ -3554,7 +3556,7 @@ jvmGetSystemPackages(Thread* t, uintptr_t*) makeObjectArray( t, resolveClass( - t, cast(t, root(t, Machine::BootLoader)), "java/lang/Package"), + t, roots(t)->bootLoader(), "java/lang/Package"), 0))); } @@ -3586,7 +3588,7 @@ EXPORT(JVM_LatestUserDefinedLoader)(Thread* t) virtual bool visit(Processor::StackWalker* walker) { GcClassLoader* loader = walker->method()->class_()->loader(); if (loader - and loader != cast(t, root(t, Machine::BootLoader)) + and loader != roots(t)->bootLoader() and strcmp (objectClass(t, loader)->name()->body().begin(), reinterpret_cast @@ -3865,7 +3867,7 @@ jvmResolveClass(Thread* t, uintptr_t* arguments) jclass c = reinterpret_cast(arguments[0]); GcMethod* method = resolveMethod - (t, cast(t, root(t, Machine::BootLoader)), "avian/Classes", "link", + (t, roots(t)->bootLoader(), "avian/Classes", "link", "(Lavian/VMClass;)V"); t->m->processor->invoke(t, method, 0, (*c)->vmClass()); @@ -3890,7 +3892,7 @@ jvmFindClassFromClassLoader(Thread* t, uintptr_t* arguments) jboolean throwError = arguments[3]; GcClass* c = resolveClass - (t, cast(t, loader ? *loader : root(t, Machine::BootLoader)), name, true, + (t, loader ? cast(t, *loader) : roots(t)->bootLoader(), name, true, throwError ? static_cast(GcNoClassDefFoundError::Type) : static_cast(GcClassNotFoundException::Type)); @@ -4046,7 +4048,7 @@ EXPORT(JVM_GetClassLoader)(Thread* t, jclass c) GcClassLoader* loader = (*c)->vmClass()->loader(); - if (loader == cast(t, root(t, Machine::BootLoader))) { + if (loader == roots(t)->bootLoader()) { // sun.misc.Unsafe.getUnsafe expects a null result if the class // loader is the boot classloader and will throw a // SecurityException otherwise. @@ -4058,7 +4060,7 @@ EXPORT(JVM_GetClassLoader)(Thread* t, jclass c) { return 0; } else { - return makeLocalReference(t, root(t, Machine::BootLoader)); + return makeLocalReference(t, reinterpret_cast(roots(t)->bootLoader())); } } else { return makeLocalReference(t, reinterpret_cast(loader)); @@ -4118,7 +4120,7 @@ jvmGetProtectionDomain(Thread* t, uintptr_t* arguments) jclass c = reinterpret_cast(arguments[0]); GcMethod* method = resolveMethod - (t, cast(t, root(t, Machine::BootLoader)), "avian/Classes", "getProtectionDomain", + (t, roots(t)->bootLoader(), "avian/Classes", "getProtectionDomain", "(Lavian/VMClass;)Ljava/security/ProtectionDomain;"); return reinterpret_cast @@ -4631,7 +4633,7 @@ maybeWrap(Thread* t, bool wrapException) PROTECT(t, exception); GcClass* paeClass = resolveClass - (t, cast(t, root(t, Machine::BootLoader)), + (t, roots(t)->bootLoader(), "java/security/PrivilegedActionException"); PROTECT(t, paeClass); @@ -4658,7 +4660,7 @@ jvmDoPrivileged(Thread* t, uintptr_t* arguments) // object: GcClass* privilegedAction = resolveClass - (t, cast(t, root(t, Machine::BootLoader)), "java/security/PrivilegedAction"); + (t, roots(t)->bootLoader(), "java/security/PrivilegedAction"); GcMethod* method; if (instanceOf(t, privilegedAction, *action)) { @@ -4666,7 +4668,7 @@ jvmDoPrivileged(Thread* t, uintptr_t* arguments) (t, privilegedAction, "run", "()Ljava/lang/Object;"); } else { GcClass* privilegedExceptionAction = resolveClass - (t, cast(t, root(t, Machine::BootLoader)), + (t, roots(t)->bootLoader(), "java/security/PrivilegedExceptionAction"); method = resolveMethod @@ -5196,7 +5198,7 @@ getMemoryManagers(Thread* t, uintptr_t*) t, makeObjectArray(t, resolveClass(t, - cast(t, root(t, Machine::BootLoader)), + roots(t)->bootLoader(), "java/lang/management/MemoryManagerMXBean"), 0))); } @@ -5214,7 +5216,7 @@ getMemoryPools(Thread* t, uintptr_t*) t, makeObjectArray(t, resolveClass(t, - cast(t, root(t, Machine::BootLoader)), + roots(t)->bootLoader(), "java/lang/management/MemoryPoolMXBean"), 0))); } diff --git a/src/compile.cpp b/src/compile.cpp index 8f918c6aa0..8f9cd2cd41 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -336,7 +336,7 @@ resolveTarget(MyThread* t, void* stack, GcMethod* method) PROTECT(t, method); PROTECT(t, class_); - resolveSystemClass(t, cast(t, root(t, Machine::BootLoader)), class_->name()); + resolveSystemClass(t, roots(t)->bootLoader(), class_->name()); } if (method->class_()->flags() & ACC_INTERFACE) { @@ -352,7 +352,7 @@ resolveTarget(MyThread* t, GcClass* class_, unsigned index) if (class_->vmFlags() & BootstrapFlag) { PROTECT(t, class_); - resolveSystemClass(t, cast(t, root(t, Machine::BootLoader)), class_->name()); + resolveSystemClass(t, roots(t)->bootLoader(), class_->name()); } return cast(t, cast(t, class_->virtualTable())->body()[index]); @@ -2460,7 +2460,7 @@ throwArithmetic(MyThread* t) } else { // not enough memory available for a new exception and stack trace // -- use a preallocated instance instead - throw_(t, cast(t, root(t, Machine::ArithmeticException))); + throw_(t, roots(t)->arithmeticException()); } } @@ -2671,7 +2671,7 @@ throwArrayIndexOutOfBounds(MyThread* t) } else { // not enough memory available for a new exception and stack trace // -- use a preallocated instance instead - throw_(t, cast(t, root(t, Machine::ArrayIndexOutOfBoundsException))); + throw_(t, roots(t)->arrayIndexOutOfBoundsException()); } } @@ -7726,7 +7726,7 @@ callContinuation(MyThread* t, GcContinuation* continuation, object result, PROTECT(t, nextContinuation); GcMethod* method = resolveMethod - (t, cast(t, root(t, Machine::BootLoader)), "avian/Continuations", "rewind", + (t, roots(t)->bootLoader(), "avian/Continuations", "rewind", "(Ljava/lang/Runnable;Lavian/Callback;Ljava/lang/Object;" "Ljava/lang/Throwable;)V"); @@ -7786,7 +7786,7 @@ callWithCurrentContinuation(MyThread* t, object receiver) if (root(t, ReceiveMethod) == 0) { GcMethod* m = resolveMethod - (t, cast(t, root(t, Machine::BootLoader)), "avian/Function", "call", + (t, roots(t)->bootLoader(), "avian/Function", "call", "(Ljava/lang/Object;)Ljava/lang/Object;"); if (m) { @@ -7796,7 +7796,7 @@ callWithCurrentContinuation(MyThread* t, object receiver) if (continuationClass->vmFlags() & BootstrapFlag) { resolveSystemClass( - t, cast(t, root(t, Machine::BootLoader)), continuationClass->name()); + t, roots(t)->bootLoader(), continuationClass->name()); } } } @@ -7825,7 +7825,7 @@ dynamicWind(MyThread* t, object before, object thunk, object after) if (root(t, WindMethod) == 0) { GcMethod* method = resolveMethod - (t, cast(t, root(t, Machine::BootLoader)), "avian/Continuations", "wind", + (t, roots(t)->bootLoader(), "avian/Continuations", "wind", "(Ljava/lang/Runnable;Ljava/util/concurrent/Callable;" "Ljava/lang/Runnable;)Lavian/Continuations$UnwindResult;"); @@ -8032,7 +8032,7 @@ invoke(Thread* thread, GcMethod* method, ArgumentList* arguments) compile(t, local::codeAllocator(static_cast(t)), 0, resolveMethod - (t, cast(t, root(t, Machine::AppLoader)), + (t, roots(t)->appLoader(), "foo/ClassName", "methodName", "()V")); @@ -8113,8 +8113,9 @@ invoke(Thread* thread, GcMethod* method, ArgumentList* arguments) class SignalHandler: public SignalRegistrar::Handler { public: - SignalHandler(Gc::Type type, Machine::Root root, unsigned fixedSize): - m(0), type(type), root(root), fixedSize(fixedSize) { } + typedef GcThrowable*& (GcRoots::*ExceptionGetter)(); + SignalHandler(Gc::Type type, ExceptionGetter exc, unsigned fixedSize): + m(0), type(type), exc(exc), fixedSize(fixedSize) { } virtual bool handleSignal(void** ip, void** frame, void** stack, void** thread) @@ -8137,7 +8138,7 @@ class SignalHandler: public SignalRegistrar::Handler { } else { // not enough memory available for a new exception and stack // trace -- use a preallocated instance instead - t->exception = cast(t, vm::root(t, root)); + t->exception = (vm::roots(t)->*exc)(); } // printTrace(t, t->exception); @@ -8162,7 +8163,7 @@ class SignalHandler: public SignalRegistrar::Handler { Machine* m; Gc::Type type; - Machine::Root root; + ExceptionGetter exc; unsigned fixedSize; }; @@ -8258,10 +8259,10 @@ class MyProcessor: public Processor { codeImage(0), codeImageSize(0), segFaultHandler(GcNullPointerException::Type, - Machine::NullPointerException, + &GcRoots::nullPointerException, GcNullPointerException::FixedSize), divideByZeroHandler(GcArithmeticException::Type, - Machine::ArithmeticException, + &GcRoots::arithmeticException, GcArithmeticException::FixedSize), codeAllocator(s, Slice(0, 0)), callTableSize(0), @@ -9530,10 +9531,10 @@ boot(MyThread* t, BootImage* image, uint8_t* code) t->m->types = reinterpret_cast(bootObject(heap, image->types)); - t->m->roots = makeArray(t, Machine::RootCount); + t->m->roots = makeRoots(t, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);; - setRoot(t, Machine::BootLoader, bootObject(heap, image->bootLoader)); - setRoot(t, Machine::AppLoader, bootObject(heap, image->appLoader)); + set(t, reinterpret_cast(roots(t)), RootsBootLoader, bootObject(heap, image->bootLoader)); + set(t, reinterpret_cast(roots(t)), RootsAppLoader, bootObject(heap, image->appLoader)); p->roots = makeArray(t, RootCount); @@ -9542,20 +9543,24 @@ boot(MyThread* t, BootImage* image, uint8_t* code) setRoot(t, VirtualThunks, bootObject(heap, image->virtualThunks)); - { object map = reinterpret_cast(makeClassMap(t, bootClassTable, image->bootClassCount, heap)); - set(t, root(t, Machine::BootLoader), ClassLoaderMap, map); + { + GcHashMap* map = makeClassMap(t, bootClassTable, image->bootClassCount, heap); + // sequence point, for gc (don't recombine statements) + set(t, roots(t)->bootLoader(), ClassLoaderMap, map); } - cast(t, root(t, Machine::BootLoader))->finder() = t->m->bootFinder; + roots(t)->bootLoader()->as(t)->finder() = t->m->bootFinder; - { object map = reinterpret_cast(makeClassMap(t, appClassTable, image->appClassCount, heap)); - set(t, root(t, Machine::AppLoader), ClassLoaderMap, map); + { + GcHashMap* map = makeClassMap(t, appClassTable, image->appClassCount, heap); + // sequence point, for gc (don't recombine statements) + set(t, roots(t)->appLoader(), ClassLoaderMap, map); } - cast(t, root(t, Machine::AppLoader))->finder() = t->m->appFinder; + roots(t)->appLoader()->as(t)->finder() = t->m->appFinder; - setRoot(t, Machine::StringMap, reinterpret_cast(makeStringMap - (t, stringTable, image->stringCount, heap))); + set(t, roots(t), RootsStringMap, makeStringMap + (t, stringTable, image->stringCount, heap)); p->callTableSize = image->callCount; @@ -9571,11 +9576,11 @@ boot(MyThread* t, BootImage* image, uint8_t* code) if (image->initialized) { resetRuntimeState - (t, cast(t, cast(t, root(t, Machine::BootLoader))->map()), heap, + (t, cast(t, roots(t)->bootLoader()->map()), heap, image->heapSize); resetRuntimeState - (t, cast(t, cast(t, root(t, Machine::AppLoader))->map()), heap, + (t, cast(t, roots(t)->appLoader()->map()), heap, image->heapSize); for (unsigned i = 0; i < t->m->types->length(); ++i) { @@ -9586,15 +9591,17 @@ boot(MyThread* t, BootImage* image, uint8_t* code) fixupVirtualThunks(t, code); fixupMethods - (t, cast(t, cast(t, root(t, Machine::BootLoader))->map()), image, code); + (t, cast(t, roots(t)->bootLoader()->map()), image, code); fixupMethods - (t, cast(t, cast(t, root(t, Machine::AppLoader))->map()), image, code); + (t, cast(t, roots(t)->appLoader()->map()), image, code); } image->initialized = true; - setRoot(t, Machine::BootstrapClassMap, reinterpret_cast(makeHashMap(t, 0, 0))); + GcHashMap* map = makeHashMap(t, 0, 0); + // sequence point, for gc (don't recombine statements) + set(t, roots(t), RootsBootstrapClassMap, map); } intptr_t diff --git a/src/interpret.cpp b/src/interpret.cpp index a9b5aaba61..ccfbe38748 100644 --- a/src/interpret.cpp +++ b/src/interpret.cpp @@ -2909,7 +2909,7 @@ invoke(Thread* t, GcMethod* method) class_ = objectClass(t, peekObject(t, t->sp - parameterFootprint)); if (class_->vmFlags() & BootstrapFlag) { - resolveClass(t, cast(t, root(t, Machine::BootLoader)), class_->name()); + resolveClass(t, roots(t)->bootLoader(), class_->name()); } if (method->class_()->flags() & ACC_INTERFACE) { diff --git a/src/jnienv.cpp b/src/jnienv.cpp index acb7024348..1b781e9319 100644 --- a/src/jnienv.cpp +++ b/src/jnienv.cpp @@ -330,8 +330,7 @@ defineClass(Thread* t, uintptr_t* arguments) t, defineClass(t, loader ? cast(t, *loader) - : cast( - t, root(t, Machine::BootLoader)), + : roots(t)->bootLoader(), buffer, length)))))); } @@ -357,11 +356,11 @@ findClass(Thread* t, uintptr_t* arguments) GcMethod* caller = getCaller(t, 0); - GcClass* c = resolveClass( - t, - caller ? t->m->classpath->libraryClassLoader(t, caller) : cast - (t, root(t, Machine::AppLoader)), - n); + GcClass* c + = resolveClass(t, + caller ? t->m->classpath->libraryClassLoader(t, caller) + : roots(t)->appLoader(), + n); if (t->m->classpath->mayInitClasses()) { PROTECT(t, c); @@ -549,13 +548,14 @@ methodID(Thread* t, GcMethod* method) ACQUIRE(t, t->m->referenceLock); if (method->nativeID() == 0) { - setRoot(t, Machine::JNIMethodTable, reinterpret_cast(vectorAppend - (t, cast(t, root(t, Machine::JNIMethodTable)), reinterpret_cast(method)))); + GcVector* v = vectorAppend( + t, roots(t)->jNIMethodTable(), reinterpret_cast(method)); + // sequence point, for gc (don't recombine statements) + set(t, roots(t), RootsJNIMethodTable, v); storeStoreMemoryBarrier(); - method->nativeID() = cast - (t, root(t, Machine::JNIMethodTable))->size(); + method->nativeID() = roots(t)->jNIMethodTable()->size(); } } @@ -615,7 +615,7 @@ getMethod(Thread* t, jmethodID m) { assertT(t, m); - GcMethod* method = cast(t, cast(t, root(t, Machine::JNIMethodTable))->body()[m - 1]); + GcMethod* method = cast(t, roots(t)->jNIMethodTable()->body()[m - 1]); assertT(t, (method->flags() & ACC_STATIC) == 0); @@ -1110,7 +1110,7 @@ getStaticMethod(Thread* t, jmethodID m) { assertT(t, m); - GcMethod* method = cast(t, cast(t, root(t, Machine::JNIMethodTable))->body()[m - 1]); + GcMethod* method = cast(t, roots(t)->jNIMethodTable()->body()[m - 1]); assertT(t, method->flags() & ACC_STATIC); @@ -1502,12 +1502,14 @@ fieldID(Thread* t, GcField* field) ACQUIRE(t, t->m->referenceLock); if (field->nativeID() == 0) { - setRoot(t, Machine::JNIFieldTable, reinterpret_cast(vectorAppend - (t, cast(t, root(t, Machine::JNIFieldTable)), reinterpret_cast(field)))); + GcVector* v = vectorAppend( + t, roots(t)->jNIFieldTable(), reinterpret_cast(field)); + // sequence point, for gc (don't recombine statements) + set(t, roots(t), RootsJNIFieldTable, v); storeStoreMemoryBarrier(); - field->nativeID() = cast(t, root(t, Machine::JNIFieldTable))->size(); + field->nativeID() = roots(t)->jNIFieldTable()->size(); } } @@ -1549,7 +1551,7 @@ getField(Thread* t, jfieldID f) { assertT(t, f); - GcField* field = cast(t, cast(t, root(t, Machine::JNIFieldTable))->body()[f - 1]); + GcField* field = cast(t, roots(t)->jNIFieldTable()->body()[f - 1]); assertT(t, (field->flags() & ACC_STATIC) == 0); @@ -1978,7 +1980,7 @@ getStaticField(Thread* t, jfieldID f) { assertT(t, f); - GcField* field = cast(t, cast(t, root(t, Machine::JNIFieldTable))->body()[f - 1]); + GcField* field = cast(t, roots(t)->jNIFieldTable()->body()[f - 1]); assertT(t, field->flags() & ACC_STATIC); @@ -3399,7 +3401,7 @@ pushLocalFrame(Thread* t, uintptr_t* arguments) if (t->m->processor->pushLocalFrame(t, arguments[0])) { return 1; } else { - throw_(t, cast(t, root(t, Machine::OutOfMemoryError))); + throw_(t, roots(t)->outOfMemoryError()); } } @@ -3537,22 +3539,25 @@ append(char** p, const char* value, unsigned length, char tail) uint64_t boot(Thread* t, uintptr_t*) { - setRoot(t, - Machine::NullPointerException, - reinterpret_cast(makeThrowable(t, GcNullPointerException::Type))); + GcThrowable* throwable = makeThrowable(t, GcNullPointerException::Type); + // sequence point, for gc (don't recombine statements) + set(t, roots(t), RootsNullPointerException, throwable); - setRoot(t, - Machine::ArithmeticException, - reinterpret_cast(makeThrowable(t, GcArithmeticException::Type))); + throwable = makeThrowable(t, GcArithmeticException::Type); + // sequence point, for gc (don't recombine statements) + set(t, roots(t), RootsArithmeticException, throwable); - setRoot(t, - Machine::ArrayIndexOutOfBoundsException, - reinterpret_cast(makeThrowable(t, GcArrayIndexOutOfBoundsException::Type))); + throwable = makeThrowable(t, GcArrayIndexOutOfBoundsException::Type); + // sequence point, for gc (don't recombine statements) + set(t, roots(t), RootsArrayIndexOutOfBoundsException, throwable); - setRoot( - t, Machine::OutOfMemoryError, reinterpret_cast(makeThrowable(t, GcOutOfMemoryError::Type))); + throwable = makeThrowable(t, GcOutOfMemoryError::Type); + // sequence point, for gc (don't recombine statements) + set(t, roots(t), RootsOutOfMemoryError, throwable); - setRoot(t, Machine::Shutdown, reinterpret_cast(makeThrowable(t, GcThrowable::Type))); + throwable = makeThrowable(t, GcThrowable::Type); + // sequence point, for gc (don't recombine statements) + set(t, roots(t), RootsShutdownInProgress, throwable); t->m->classpath->preBoot(t); @@ -3560,9 +3565,11 @@ boot(Thread* t, uintptr_t*) t->javaThread->peer() = reinterpret_cast(t); - setRoot(t, Machine::FinalizerThread, reinterpret_cast(t->m->classpath->makeThread(t, t))); + GcThread* jthread = t->m->classpath->makeThread(t, t); + // sequence point, for gc (don't recombine statements) + set(t, roots(t), RootsFinalizerThread, jthread); - cast(t, root(t, Machine::FinalizerThread))->daemon() = true; + roots(t)->finalizerThread()->daemon() = true; t->m->classpath->boot(t); @@ -3572,7 +3579,7 @@ boot(Thread* t, uintptr_t*) PROTECT(t, host); GcMethod* method = resolveMethod - (t, cast(t, root(t, Machine::BootLoader)), "avian/Traces", "startTraceListener", + (t, roots(t)->bootLoader(), "avian/Traces", "startTraceListener", "(Ljava/lang/String;I)V"); t->m->processor->invoke(t, method, 0, host, atoi(port)); diff --git a/src/machine.cpp b/src/machine.cpp index 98ed8efe0a..55150a76ee 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -215,7 +215,7 @@ turnOffTheLights(Thread* t) } } - if (GcArray* files = cast(t, root(t, Machine::VirtualFiles))) { + if (GcArray* files = roots(t)->virtualFiles()) { PROTECT(t, files); for (unsigned i = 0; i < files->length(); ++i) @@ -227,7 +227,7 @@ turnOffTheLights(Thread* t) } } - for (GcFinder* p = cast(t, root(t, Machine::VirtualFileFinders)); + for (GcFinder* p = roots(t)->virtualFileFinders(); p; p = p->next()) { static_cast(p->finder())->dispose(); @@ -402,8 +402,8 @@ finalizerTargetUnreachable(Thread* t, Heap::Visitor* v, GcFinalizer** p) t->m->finalizeQueue = finalizer; } else { set(t, reinterpret_cast(finalizer), FinalizerQueueTarget, finalizer->target()); - set(t, reinterpret_cast(finalizer), FinalizerQueueNext, root(t, Machine::ObjectsToFinalize)); - setRoot(t, Machine::ObjectsToFinalize, reinterpret_cast(finalizer)); + set(t, finalizer, FinalizerQueueNext, roots(t)->objectsToFinalize()); + set(t, roots(t), RootsObjectsToFinalize, finalizer); } } @@ -422,8 +422,8 @@ referenceTargetUnreachable(Thread* t, Heap::Visitor* v, GcJreference** p) GcJreference* reference = *p; *p = cast(t, reference->vmNext()); - set(t, reinterpret_cast(reference), CleanerQueueNext, root(t, Machine::ObjectsToClean)); - setRoot(t, Machine::ObjectsToClean, reinterpret_cast(reference)); + set(t, reference, CleanerQueueNext, roots(t)->objectsToClean()); + set(t, roots(t), RootsObjectsToClean, reference); } else { if ((*p)->queue() and t->m->heap->status((*p)->queue()) != Heap::Unreachable) @@ -437,9 +437,9 @@ referenceTargetUnreachable(Thread* t, Heap::Visitor* v, GcJreference** p) if (q->front()) { set(t, reinterpret_cast(*p), JreferenceJNext, reinterpret_cast(q->front())); } else { - set(t, reinterpret_cast(*p), JreferenceJNext, reinterpret_cast(*p)); + set(t, *p, JreferenceJNext, *p); } - set(t, reinterpret_cast(q), ReferenceQueueFront, reinterpret_cast(*p)); + set(t, q, ReferenceQueueFront, *p); (*p)->queue() = 0; } @@ -880,7 +880,7 @@ void removeByteArray(Thread* t, object o) { hashMapRemove(t, - cast(t, root(t, Machine::ByteArrayMap)), + roots(t)->byteArrayMap(), o, byteArrayHash, objectEqual); @@ -894,11 +894,11 @@ internByteArray(Thread* t, GcByteArray* array) ACQUIRE(t, t->m->referenceLock); GcTriple* n = hashMapFindNode - (t, cast(t, root(t, Machine::ByteArrayMap)), reinterpret_cast(array), byteArrayHash, byteArrayEqual); + (t, roots(t)->byteArrayMap(), reinterpret_cast(array), byteArrayHash, byteArrayEqual); if (n) { return cast(t, cast(t, n->first())->target()); } else { - hashMapInsert(t, cast(t, root(t, Machine::ByteArrayMap)), reinterpret_cast(array), 0, byteArrayHash); + hashMapInsert(t, roots(t)->byteArrayMap(), reinterpret_cast(array), 0, byteArrayHash); addFinalizer(t, reinterpret_cast(array), removeByteArray); return array; } @@ -2546,7 +2546,7 @@ makeArrayClass(Thread* t, GcClassLoader* loader, unsigned dimensions, GcByteArra // avoid infinite recursion due to trying to create an array to // make a stack trace for a ClassNotFoundException. resolveSystemClass - (t, cast(t, root(t, Machine::BootLoader)), + (t, roots(t)->bootLoader(), type(t, GcJobject::Type)->name(), false); } @@ -2564,7 +2564,7 @@ makeArrayClass(Thread* t, GcClassLoader* loader, unsigned dimensions, GcByteArra spec, 0, type(t, GcJobject::Type), - root(t, Machine::ArrayInterfaceTable), + reinterpret_cast(roots(t)->arrayInterfaceTable()), reinterpret_cast(vtable), 0, 0, @@ -2647,7 +2647,7 @@ makeArrayClass(Thread* t, GcClassLoader* loader, GcByteArray* spec, bool throw_, } GcClass* elementClass = cast(t, hashMapFind - (t, cast(t, root(t, Machine::BootstrapClassMap)), reinterpret_cast(elementSpec), byteArrayHash, + (t, roots(t)->bootstrapClassMap(), reinterpret_cast(elementSpec), byteArrayHash, byteArrayEqual)); if (elementClass == 0) { @@ -2680,7 +2680,7 @@ resolveArrayClass(Thread* t, GcClassLoader* loader, GcByteArray* spec, bool thro { GcClass* c = cast(t, hashMapFind(t, - cast(t, root(t, Machine::BootstrapClassMap)), + roots(t)->bootstrapClassMap(), reinterpret_cast(spec), byteArrayHash, byteArrayEqual)); @@ -2694,7 +2694,7 @@ resolveArrayClass(Thread* t, GcClassLoader* loader, GcByteArray* spec, bool thro PROTECT(t, loader); PROTECT(t, spec); - c = findLoadedClass(t, cast(t, root(t, Machine::BootLoader)), spec); + c = findLoadedClass(t, roots(t)->bootLoader(), spec); if (c) { return c; @@ -2713,7 +2713,7 @@ removeMonitor(Thread* t, object o) } object m = hashMapRemove - (t, cast(t, root(t, Machine::MonitorMap)), o, objectHash, objectEqual); + (t, roots(t)->monitorMap(), o, objectHash, objectEqual); if (DebugMonitors) { fprintf(stderr, "dispose monitor %p for object %x\n", m, hash); @@ -2723,7 +2723,7 @@ removeMonitor(Thread* t, object o) void removeString(Thread* t, object o) { - hashMapRemove(t, cast(t, root(t, Machine::StringMap)), o, stringHash, objectEqual); + hashMapRemove(t, roots(t)->stringMap(), o, stringHash, objectEqual); } void @@ -2755,7 +2755,7 @@ bootClass(Thread* t, Gc::Type type, int superType, uint32_t objectMask, GcClass* class_ = t->m->processor->makeClass (t, 0, BootstrapFlag, fixedSize, arrayElementSize, arrayElementSize ? 1 : 0, 0, mask, 0, 0, super, 0, 0, 0, 0, 0, 0, - cast(t, root(t, Machine::BootLoader)), vtableLength); + roots(t)->bootLoader(), vtableLength); setType(t, type, class_); } @@ -2789,7 +2789,7 @@ bootJavaClass(Thread* t, Gc::Type type, int superType, const char* name, t->m->processor->initVtable(t, class_); hashMapInsert - (t, cast(t, root(t, Machine::BootstrapClassMap)), reinterpret_cast(n), reinterpret_cast(class_), byteArrayHash); + (t, roots(t)->bootstrapClassMap(), reinterpret_cast(n), reinterpret_cast(class_), byteArrayHash); } void @@ -2810,7 +2810,7 @@ makeArrayInterfaceTable(Thread* t) set(t, interfaceTable, ArrayBody + (2 * BytesPerWord), type(t, GcCloneable::Type)); - setRoot(t, Machine::ArrayInterfaceTable, reinterpret_cast(interfaceTable)); + set(t, roots(t), RootsArrayInterfaceTable, interfaceTable); } void @@ -2820,14 +2820,15 @@ boot(Thread* t) m->unsafe = true; - m->roots = reinterpret_cast(allocate(t, pad((Machine::RootCount + 2) * BytesPerWord), true)); - m->roots->length() = Machine::RootCount; + m->roots = reinterpret_cast(allocate(t, GcRoots::FixedSize, true)); - setRoot(t, Machine::BootLoader, - allocate(t, GcSystemClassLoader::FixedSize, true)); + object classLoader = allocate(t, GcSystemClassLoader::FixedSize, true); + // sequence point, for gc (don't recombine statements) + set(t, reinterpret_cast(roots(t)), RootsBootLoader, classLoader); - setRoot(t, Machine::AppLoader, - allocate(t, GcSystemClassLoader::FixedSize, true)); + classLoader = allocate(t, GcSystemClassLoader::FixedSize, true); + // sequence point, for gc (don't recombine statements) + set(t, reinterpret_cast(roots(t)), RootsAppLoader, classLoader); m->types = reinterpret_cast(allocate(t, pad((TypeCount + 2) * BytesPerWord), true)); m->types->length() = TypeCount; @@ -2836,21 +2837,23 @@ boot(Thread* t) GcClass* arrayClass = type(t, GcArray::Type); set(t, m->types, 0, arrayClass); - set(t, m->roots, 0, arrayClass); + + GcClass* rootsClass = type(t, GcRoots::Type); + set(t, m->roots, 0, rootsClass); 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)); + set(t, roots(t)->bootLoader(), 0, loaderClass); + set(t, roots(t)->appLoader(), 0, loaderClass); GcClass* objectClass = type(t, GcJobject::Type); GcClass* classClass = type(t, GcClass::Type); - set(t, reinterpret_cast(classClass), 0, reinterpret_cast(classClass)); - set(t, reinterpret_cast(classClass), ClassSuper, reinterpret_cast(objectClass)); + set(t, classClass, 0, classClass); + set(t, classClass, 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)); + set(t, intArrayClass, 0, classClass); + set(t, intArrayClass, ClassSuper, objectClass); m->unsafe = false; @@ -2888,60 +2891,68 @@ boot(Thread* t) type(t, GcJvoid::Type)->vmFlags() |= PrimitiveFlag; - set(t, reinterpret_cast(type(t, GcBooleanArray::Type)), ClassArrayElementClass, - reinterpret_cast(type(t, GcJboolean::Type))); - set(t, reinterpret_cast(type(t, GcByteArray::Type)), ClassArrayElementClass, - reinterpret_cast(type(t, GcJbyte::Type))); - set(t, reinterpret_cast(type(t, GcCharArray::Type)), ClassArrayElementClass, - reinterpret_cast(type(t, GcJchar::Type))); - set(t, reinterpret_cast(type(t, GcShortArray::Type)), ClassArrayElementClass, - reinterpret_cast(type(t, GcJshort::Type))); - set(t, reinterpret_cast(type(t, GcIntArray::Type)), ClassArrayElementClass, - reinterpret_cast(type(t, GcJint::Type))); - set(t, reinterpret_cast(type(t, GcLongArray::Type)), ClassArrayElementClass, - reinterpret_cast(type(t, GcJlong::Type))); - set(t, reinterpret_cast(type(t, GcFloatArray::Type)), ClassArrayElementClass, - reinterpret_cast(type(t, GcJfloat::Type))); - set(t, reinterpret_cast(type(t, GcDoubleArray::Type)), ClassArrayElementClass, - reinterpret_cast(type(t, GcJdouble::Type))); + set(t, type(t, GcBooleanArray::Type), ClassArrayElementClass, + type(t, GcJboolean::Type)); + set(t, type(t, GcByteArray::Type), ClassArrayElementClass, + type(t, GcJbyte::Type)); + set(t, type(t, GcCharArray::Type), ClassArrayElementClass, + type(t, GcJchar::Type)); + set(t, type(t, GcShortArray::Type), ClassArrayElementClass, + type(t, GcJshort::Type)); + set(t, type(t, GcIntArray::Type), ClassArrayElementClass, + type(t, GcJint::Type)); + set(t, type(t, GcLongArray::Type), ClassArrayElementClass, + type(t, GcJlong::Type)); + set(t, type(t, GcFloatArray::Type), ClassArrayElementClass, + type(t, GcJfloat::Type)); + set(t, type(t, GcDoubleArray::Type), ClassArrayElementClass, + type(t, GcJdouble::Type)); { GcHashMap* map = makeHashMap(t, 0, 0); - set(t, root(t, Machine::BootLoader), ClassLoaderMap, reinterpret_cast(map)); + set(t, roots(t)->bootLoader(), ClassLoaderMap, map); } - cast(t, root(t, Machine::BootLoader))->finder() = m->bootFinder; + roots(t)->bootLoader()->as(t)->finder() = m->bootFinder; { GcHashMap* map = makeHashMap(t, 0, 0); - set(t, root(t, Machine::AppLoader), ClassLoaderMap, reinterpret_cast(map)); + set(t, roots(t)->appLoader(), ClassLoaderMap, map); } - cast(t, root(t, Machine::AppLoader))->finder() = m->appFinder; + roots(t)->appLoader()->as(t)->finder() = m->appFinder; - set(t, root(t, Machine::AppLoader), ClassLoaderParent, - root(t, Machine::BootLoader)); + set(t, roots(t)->appLoader(), ClassLoaderParent, + roots(t)->bootLoader()); - setRoot(t, Machine::BootstrapClassMap, reinterpret_cast(makeHashMap(t, 0, 0))); + { + GcHashMap* map = makeHashMap(t, 0, 0); + // sequence point, for gc (don't recombine statements) + set(t, roots(t), RootsBootstrapClassMap, map); + } - setRoot(t, Machine::StringMap, reinterpret_cast(makeWeakHashMap(t, 0, 0))); + { + GcWeakHashMap* map = makeWeakHashMap(t, 0, 0); + // sequence point, for gc (don't recombine statements) + set(t, roots(t), RootsStringMap, map); + } makeArrayInterfaceTable(t); - set(t, reinterpret_cast(type(t, GcBooleanArray::Type)), ClassInterfaceTable, - root(t, Machine::ArrayInterfaceTable)); - set(t, reinterpret_cast(type(t, GcByteArray::Type)), ClassInterfaceTable, - root(t, Machine::ArrayInterfaceTable)); - set(t, reinterpret_cast(type(t, GcCharArray::Type)), ClassInterfaceTable, - root(t, Machine::ArrayInterfaceTable)); - set(t, reinterpret_cast(type(t, GcShortArray::Type)), ClassInterfaceTable, - root(t, Machine::ArrayInterfaceTable)); - set(t, reinterpret_cast(type(t, GcIntArray::Type)), ClassInterfaceTable, - root(t, Machine::ArrayInterfaceTable)); - set(t, reinterpret_cast(type(t, GcLongArray::Type)), ClassInterfaceTable, - root(t, Machine::ArrayInterfaceTable)); - set(t, reinterpret_cast(type(t, GcFloatArray::Type)), ClassInterfaceTable, - root(t, Machine::ArrayInterfaceTable)); - set(t, reinterpret_cast(type(t, GcDoubleArray::Type)), ClassInterfaceTable, - root(t, Machine::ArrayInterfaceTable)); + set(t, type(t, GcBooleanArray::Type), ClassInterfaceTable, + roots(t)->arrayInterfaceTable()); + set(t, type(t, GcByteArray::Type), ClassInterfaceTable, + roots(t)->arrayInterfaceTable()); + set(t, type(t, GcCharArray::Type), ClassInterfaceTable, + roots(t)->arrayInterfaceTable()); + set(t, type(t, GcShortArray::Type), ClassInterfaceTable, + roots(t)->arrayInterfaceTable()); + set(t, type(t, GcIntArray::Type), ClassInterfaceTable, + roots(t)->arrayInterfaceTable()); + set(t, type(t, GcLongArray::Type), ClassInterfaceTable, + roots(t)->arrayInterfaceTable()); + set(t, type(t, GcFloatArray::Type), ClassInterfaceTable, + roots(t)->arrayInterfaceTable()); + set(t, type(t, GcDoubleArray::Type), ClassInterfaceTable, + roots(t)->arrayInterfaceTable()); m->processor->boot(t, 0, 0); @@ -3090,12 +3101,12 @@ doCollect(Thread* t, Heap::CollectionType type, int pendingAllocation) function(t, finalizeQueue->target()); } - if ((root(t, Machine::ObjectsToFinalize) or root(t, Machine::ObjectsToClean)) + if ((roots(t)->objectsToFinalize() or roots(t)->objectsToClean()) and m->finalizeThread == 0 and t->state != Thread::ExitState) { m->finalizeThread = m->processor->makeThread - (m, cast(t, root(t, Machine::FinalizerThread)), m->rootThread); + (m, roots(t)->finalizerThread(), m->rootThread); addThread(t, m->finalizeThread); @@ -3165,8 +3176,10 @@ updatePackageMap(Thread* t, GcClass* class_) { PROTECT(t, class_); - if (root(t, Machine::PackageMap) == 0) { - setRoot(t, Machine::PackageMap, reinterpret_cast(makeHashMap(t, 0, 0))); + if (roots(t)->packageMap() == 0) { + GcHashMap* map = makeHashMap(t, 0, 0); + // sequence point, for gc (don't recombine statements) + set(t, roots(t), RootsPackageMap, map); } GcByteArray* className = class_->name(); @@ -3189,7 +3202,7 @@ updatePackageMap(Thread* t, GcClass* class_) PROTECT(t, key); hashMapRemove - (t, cast(t, root(t, Machine::PackageMap)), reinterpret_cast(key), byteArrayHash, + (t, roots(t)->packageMap(), reinterpret_cast(key), byteArrayHash, byteArrayEqual); GcByteArray* source = class_->source(); @@ -3210,7 +3223,7 @@ updatePackageMap(Thread* t, GcClass* class_) } hashMapInsert - (t, cast(t, root(t, Machine::PackageMap)), reinterpret_cast(key), reinterpret_cast(source), byteArrayHash); + (t, roots(t)->packageMap(), reinterpret_cast(key), reinterpret_cast(source), byteArrayHash); } } } @@ -3453,13 +3466,29 @@ Thread::init() boot(this); } - setRoot(this, Machine::ByteArrayMap, reinterpret_cast(makeWeakHashMap(this, 0, 0))); - setRoot(this, Machine::MonitorMap, reinterpret_cast(makeWeakHashMap(this, 0, 0))); + GcWeakHashMap* map = makeWeakHashMap(this, 0, 0); + // sequence point, for gc (don't recombine statements) + set(this, roots(this), RootsByteArrayMap, map); - 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))); + map = makeWeakHashMap(this, 0, 0); + // sequence point, for gc (don't recombine statements) + set(this, roots(this), RootsMonitorMap, map); + + GcVector* v = makeVector(this, 0, 0); + // sequence point, for gc (don't recombine statements) + set(this, roots(this), RootsClassRuntimeDataTable, v); + + v = makeVector(this, 0, 0); + // sequence point, for gc (don't recombine statements) + set(this, roots(this), RootsMethodRuntimeDataTable, v); + + v = makeVector(this, 0, 0); + // sequence point, for gc (don't recombine statements) + set(this, roots(this), RootsJNIMethodTable, v); + + v = makeVector(this, 0, 0); + // sequence point, for gc (don't recombine statements) + set(this, roots(this), RootsJNIFieldTable, v); m->localThread->set(this); } @@ -3508,10 +3537,10 @@ shutDown(Thread* t) { ACQUIRE(t, t->m->shutdownLock); - GcPair* hooks = cast(t, root(t, Machine::ShutdownHooks)); + GcPair* hooks = roots(t)->shutdownHooks(); PROTECT(t, hooks); - setRoot(t, Machine::ShutdownHooks, 0); + set(t, roots(t), RootsShutdownHooks, 0); GcPair* h = hooks; PROTECT(t, h); @@ -3835,7 +3864,7 @@ allocate3(Thread* t, Allocator* allocator, Machine::AllocationType type, } if (t->m->heap->limitExceeded(pendingAllocation)) { - throw_(t, cast(t, root(t, Machine::OutOfMemoryError))); + throw_(t, roots(t)->outOfMemoryError()); } } while (type == Machine::MovableAllocation and t->heapIndex + ceilingDivide(sizeInBytes, BytesPerWord) @@ -4093,7 +4122,7 @@ resolveBootstrap(Thread* t, uintptr_t* arguments) { GcByteArray* name = cast(t, reinterpret_cast(arguments[0])); - resolveSystemClass(t, cast(t, root(t, Machine::BootLoader)), name); + resolveSystemClass(t, roots(t)->bootLoader(), name); return 1; } @@ -4363,14 +4392,14 @@ parseClass(Thread* t, GcClassLoader* loader, const uint8_t* data, unsigned size, updateClassTables(t, real, class_); - if (root(t, Machine::PoolMap)) { + if (roots(t)->poolMap()) { object bootstrapClass = hashMapFind - (t, cast(t, root(t, Machine::BootstrapClassMap)), reinterpret_cast(class_->name()), + (t, roots(t)->bootstrapClassMap(), reinterpret_cast(class_->name()), byteArrayHash, byteArrayEqual); hashMapInsert( t, - cast(t, root(t, Machine::PoolMap)), + roots(t)->poolMap(), bootstrapClass ? bootstrapClass : reinterpret_cast(real), reinterpret_cast(pool), objectHash); @@ -4479,7 +4508,7 @@ resolveSystemClass(Thread* t, GcClassLoader* loader, GcByteArray* spec, bool thr } GcClass* bootstrapClass = cast(t, hashMapFind - (t, cast(t, root(t, Machine::BootstrapClassMap)), reinterpret_cast(spec), byteArrayHash, + (t, roots(t)->bootstrapClassMap(), reinterpret_cast(spec), byteArrayHash, byteArrayEqual)); if (bootstrapClass) { @@ -4533,26 +4562,26 @@ resolveClass(Thread* t, GcClassLoader* loader, GcByteArray* spec, bool throw_, if (spec->body()[0] == '[') { c = resolveArrayClass(t, loader, spec, throw_, throwType); } else { - if (root(t, Machine::LoadClassMethod) == 0) { + if (roots(t)->loadClassMethod() == 0) { GcMethod* m = resolveMethod - (t, cast(t, root(t, Machine::BootLoader)), "java/lang/ClassLoader", + (t, roots(t)->bootLoader(), "java/lang/ClassLoader", "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;"); if (m) { - setRoot(t, Machine::LoadClassMethod, reinterpret_cast(m)); + set(t, roots(t), RootsLoadClassMethod, m); GcClass* classLoaderClass = type(t, GcClassLoader::Type); if (classLoaderClass->vmFlags() & BootstrapFlag) { resolveSystemClass - (t, cast(t, root(t, Machine::BootLoader)), + (t, roots(t)->bootLoader(), classLoaderClass->name()); } } } GcMethod* method = findVirtualMethod - (t, cast(t, root(t, Machine::LoadClassMethod)), objectClass(t, loader)); + (t, roots(t)->loadClassMethod(), objectClass(t, loader)); PROTECT(t, method); @@ -4912,7 +4941,7 @@ objectMonitor(Thread* t, object o, bool createNew) assertT(t, t->state == Thread::ActiveState); object m = hashMapFind - (t, cast(t, root(t, Machine::MonitorMap)), o, objectHash, objectEqual); + (t, roots(t)->monitorMap(), o, objectHash, objectEqual); if (m) { if (DebugMonitors) { @@ -4927,7 +4956,7 @@ objectMonitor(Thread* t, object o, bool createNew) { ENTER(t, Thread::ExclusiveState); m = hashMapFind - (t, cast(t, root(t, Machine::MonitorMap)), o, objectHash, objectEqual); + (t, roots(t)->monitorMap(), o, objectHash, objectEqual); if (m) { if (DebugMonitors) { @@ -4946,7 +4975,7 @@ objectMonitor(Thread* t, object o, bool createNew) objectHash(t, o)); } - hashMapInsert(t, cast(t, root(t, Machine::MonitorMap)), o, m, objectHash); + hashMapInsert(t, roots(t)->monitorMap(), o, m, objectHash); addFinalizer(t, o, removeMonitor); } @@ -4965,12 +4994,12 @@ intern(Thread* t, object s) ACQUIRE(t, t->m->referenceLock); GcTriple* n = hashMapFindNode - (t, cast(t, root(t, Machine::StringMap)), s, stringHash, stringEqual); + (t, roots(t)->stringMap(), s, stringHash, stringEqual); if (n) { return reinterpret_cast(cast(t, n->first())->target()); } else { - hashMapInsert(t, cast(t, root(t, Machine::StringMap)), s, 0, stringHash); + hashMapInsert(t, roots(t)->stringMap(), s, 0, stringHash); addFinalizer(t, s, removeString); return s; } @@ -5196,8 +5225,8 @@ runFinalizeThread(Thread* t) { ACQUIRE(t, t->m->stateLock); while (t->m->finalizeThread - and root(t, Machine::ObjectsToFinalize) == 0 - and root(t, Machine::ObjectsToClean) == 0) + and roots(t)->objectsToFinalize() == 0 + and roots(t)->objectsToClean() == 0) { ENTER(t, Thread::IdleState); t->m->stateLock->wait(t->systemThread, 0); @@ -5206,11 +5235,11 @@ runFinalizeThread(Thread* t) if (t->m->finalizeThread == 0) { return; } else { - finalizeList = cast(t, root(t, Machine::ObjectsToFinalize)); - setRoot(t, Machine::ObjectsToFinalize, 0); + finalizeList = roots(t)->objectsToFinalize(); + set(t, roots(t), RootsObjectsToFinalize, 0); - cleanList = cast(t, root(t, Machine::ObjectsToClean)); - setRoot(t, Machine::ObjectsToClean, 0); + cleanList = roots(t)->objectsToClean(); + set(t, roots(t), RootsObjectsToClean, 0); } } diff --git a/src/tools/bootimage-generator/main.cpp b/src/tools/bootimage-generator/main.cpp index c3d4c7f44d..3e88793bac 100644 --- a/src/tools/bootimage-generator/main.cpp +++ b/src/tools/bootimage-generator/main.cpp @@ -312,7 +312,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, } resolver(&typeMaps); Finder* finder = static_cast - (cast(t, root(t, Machine::BootLoader))->finder()); + (roots(t)->bootLoader()->as(t)->finder()); for (Finder::Iterator it(finder); it.hasMore();) { unsigned nameSize = 0; @@ -323,7 +323,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, { // fprintf(stderr, "pass 1 %.*s\n", nameSize - 6, name); GcClass* c = resolveSystemClass - (t, cast(t, root(t, Machine::BootLoader)), + (t, roots(t)->bootLoader(), makeByteArray(t, "%.*s", nameSize - 6, name), true); PROTECT(t, c); @@ -419,7 +419,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, hashMapInsert (t, typeMaps, reinterpret_cast(hashMapFind - (t, cast(t, root(t, Machine::PoolMap)), reinterpret_cast(c), objectHash, objectEqual)), reinterpret_cast(array), + (t, roots(t)->poolMap(), reinterpret_cast(c), objectHash, objectEqual)), reinterpret_cast(array), objectHash); } } @@ -611,7 +611,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, PROTECT(t, c); c = resolveSystemClass - (t, cast(t, root(t, Machine::BootLoader)), + (t, roots(t)->bootLoader(), makeByteArray(t, "%.*s", nameSize - 6, name), true); if (GcArray* mtable = cast(t, c->methodTable())) { @@ -657,7 +657,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, if (objectClass(t, o) == type(t, GcReference::Type)) { o = reinterpret_cast(resolveClass - (t, cast(t, root(t, Machine::BootLoader)), cast(t, o)->name())); + (t, roots(t)->bootLoader(), cast(t, o)->name())); set(t, reinterpret_cast(addendum->pool()), SingletonBody + (index * BytesPerWord), o); @@ -706,14 +706,14 @@ visitRoots(Thread* t, BootImage* image, HeapWalker* w, GcTriple* constants) { Machine* m = t->m; - for (HashMapIterator it(t, cast(t, cast(t, root(t, Machine::BootLoader))->map())); + for (HashMapIterator it(t, cast(t, roots(t)->bootLoader()->map())); it.hasMore();) { w->visitRoot(it.next()->second()); } - image->bootLoader = w->visitRoot(root(t, Machine::BootLoader)); - image->appLoader = w->visitRoot(root(t, Machine::AppLoader)); + image->bootLoader = w->visitRoot(reinterpret_cast(roots(t)->bootLoader())); + image->appLoader = w->visitRoot(reinterpret_cast(roots(t)->appLoader())); image->types = w->visitRoot(reinterpret_cast(m->types)); m->processor->visitRoots(t, w); @@ -1288,8 +1288,9 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp const char* codeimageStart, const char* codeimageEnd, bool useLZMA) { - setRoot(t, Machine::OutOfMemoryError, - make(t, type(t, GcOutOfMemoryError::Type))); + GcThrowable* throwable = cast(t, make(t, type(t, GcOutOfMemoryError::Type))); + // sequence point, for gc (don't recombine statements) + set(t, roots(t), RootsOutOfMemoryError, throwable); Zone zone(t->m->system, t->m->heap, 64 * 1024); @@ -1331,7 +1332,7 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp { classPoolMap = makeHashMap(t, 0, 0); PROTECT(t, classPoolMap); - setRoot(t, Machine::PoolMap, reinterpret_cast(classPoolMap)); + set(t, roots(t), RootsPoolMap, classPoolMap); typeMaps = makeHashMap(t, 0, 0); PROTECT(t, typeMaps); @@ -1493,8 +1494,11 @@ 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, reinterpret_cast(makeWeakHashMap(t, 0, 0))); + set(t, roots(t), RootsPoolMap, 0); + + GcWeakHashMap* map = makeWeakHashMap(t, 0, 0); + // sequence point, for gc (don't recombine statements) + set(t, roots(t), RootsByteArrayMap, map); // name all primitive classes so we don't try to update immutable // references at runtime: @@ -1529,28 +1533,28 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp // resolve primitive array classes in case they are needed at // runtime: { GcByteArray* name = makeByteArray(t, "[B"); - resolveSystemClass(t, cast(t, root(t, Machine::BootLoader)), name, true); + resolveSystemClass(t, roots(t)->bootLoader(), name, true); name = makeByteArray(t, "[Z"); - resolveSystemClass(t, cast(t, root(t, Machine::BootLoader)), name, true); + resolveSystemClass(t, roots(t)->bootLoader(), name, true); name = makeByteArray(t, "[S"); - resolveSystemClass(t, cast(t, root(t, Machine::BootLoader)), name, true); + resolveSystemClass(t, roots(t)->bootLoader(), name, true); name = makeByteArray(t, "[C"); - resolveSystemClass(t, cast(t, root(t, Machine::BootLoader)), name, true); + resolveSystemClass(t, roots(t)->bootLoader(), name, true); name = makeByteArray(t, "[I"); - resolveSystemClass(t, cast(t, root(t, Machine::BootLoader)), name, true); + resolveSystemClass(t, roots(t)->bootLoader(), name, true); name = makeByteArray(t, "[J"); - resolveSystemClass(t, cast(t, root(t, Machine::BootLoader)), name, true); + resolveSystemClass(t, roots(t)->bootLoader(), name, true); name = makeByteArray(t, "[F"); - resolveSystemClass(t, cast(t, root(t, Machine::BootLoader)), name, true); + resolveSystemClass(t, roots(t)->bootLoader(), name, true); name = makeByteArray(t, "[D"); - resolveSystemClass(t, cast(t, root(t, Machine::BootLoader)), name, true); + resolveSystemClass(t, roots(t)->bootLoader(), name, true); } } @@ -1567,14 +1571,14 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp updateConstants(t, constants, heapWalker->map()); image->bootClassCount = cast - (t, cast(t, root(t, Machine::BootLoader))->map())->size(); + (t, roots(t)->bootLoader()->map())->size(); unsigned* bootClassTable = static_cast (t->m->heap->allocate(image->bootClassCount * sizeof(unsigned))); { unsigned i = 0; for (HashMapIterator it - (t, cast(t, cast(t, root(t, Machine::BootLoader))->map())); + (t, cast(t, roots(t)->bootLoader()->map())); it.hasMore();) { bootClassTable[i++] = targetVW @@ -1583,14 +1587,14 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp } image->appClassCount = cast - (t, cast(t, root(t, Machine::AppLoader))->map())->size(); + (t, roots(t)->appLoader()->map())->size(); unsigned* appClassTable = static_cast (t->m->heap->allocate(image->appClassCount * sizeof(unsigned))); { unsigned i = 0; for (HashMapIterator it - (t, cast(t, cast(t, root(t, Machine::AppLoader))->map())); + (t, cast(t, roots(t)->appLoader()->map())); it.hasMore();) { appClassTable[i++] = targetVW @@ -1598,12 +1602,12 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp } } - image->stringCount = cast(t, root(t, Machine::StringMap))->size(); + image->stringCount = roots(t)->stringMap()->size(); unsigned* stringTable = static_cast (t->m->heap->allocate(image->stringCount * sizeof(unsigned))); { unsigned i = 0; - for (HashMapIterator it(t, cast(t, root(t, Machine::StringMap))); it.hasMore();) { + for (HashMapIterator it(t, roots(t)->stringMap()); it.hasMore();) { stringTable[i++] = targetVW (heapWalker->map()->find (reinterpret_cast(cast(t, it.next()->first())->target()))); diff --git a/src/types.def b/src/types.def index f61d7c2774..0aa683d7dc 100644 --- a/src/types.def +++ b/src/types.def @@ -376,3 +376,43 @@ (type jvoid (extends jobject)) + +(type roots + (classLoader bootLoader) + (classLoader appLoader) + (hashMap bootstrapClassMap) + (hashMap packageMap) + (method findLoadedClassMethod) + (method loadClassMethod) + (hashMap monitorMap) + (hashMap stringMap) + (hashMap byteArrayMap) + (hashMap poolMap) + (vector classRuntimeDataTable) + (vector methodRuntimeDataTable) + (vector jNIMethodTable) + (vector jNIFieldTable) + (pair shutdownHooks) + (thread finalizerThread) + (finalizer objectsToFinalize) + (cleaner objectsToClean) + (throwable nullPointerException) + (throwable arithmeticException) + (throwable arrayIndexOutOfBoundsException) + (throwable outOfMemoryError) + (throwable shutdownInProgress) + (finder virtualFileFinders) + (field array virtualFiles) + (field array arrayInterfaceTable) + (object threadTerminated)) + +(type compileRoots + (field array callTable) + (treeNode methodTree) + (treeNode methodTreeSentinal) + (object objectPools) + (object staticTableArray) + (wordArray virtualThunks) + (method receiveMethod) + (method windMethod) + (method rewindMethod))