From 51368651dc14f24678da7a4c98b6b30fc4be2662 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 28 Jun 2014 13:16:26 -0600 Subject: [PATCH] better statically type Processor interface --- src/avian/machine.h | 2 +- src/avian/processor.h | 34 +++++++++------- src/builtin.cpp | 6 +-- src/classpath-android.cpp | 24 ++++++------ src/classpath-avian.cpp | 2 +- src/classpath-openjdk.cpp | 8 ++-- src/compile.cpp | 54 +++++++++++++------------- src/interpret.cpp | 40 +++++++++---------- src/machine.cpp | 36 ++++++++--------- src/tools/bootimage-generator/main.cpp | 2 +- 10 files changed, 108 insertions(+), 100 deletions(-) diff --git a/src/avian/machine.h b/src/avian/machine.h index ea697dcdc2..beb92a4790 100644 --- a/src/avian/machine.h +++ b/src/avian/machine.h @@ -2081,7 +2081,7 @@ removeThread(Thread* t, Thread* p) } inline Thread* -startThread(Thread* t, object javaThread) +startThread(Thread* t, GcThread* javaThread) { { PROTECT(t, javaThread); diff --git a/src/avian/processor.h b/src/avian/processor.h index 8d2e773b8c..6960145bd2 100644 --- a/src/avian/processor.h +++ b/src/avian/processor.h @@ -36,8 +36,16 @@ class GcByteArray; class GcCode; class GcClass; class GcMethod; +class GcMethodAddendum; +class GcIntArray; +class GcContinuation; +class GcThrowable; +class GcThread; class GcClassAddendum; +class GcClassLoader; +class GcArray; class GcSingleton; +class GcTriple; class Processor { public: @@ -67,7 +75,7 @@ class Processor { }; virtual Thread* - makeThread(Machine* m, object javaThread, Thread* parent) = 0; + makeThread(Machine* m, GcThread* javaThread, Thread* parent) = 0; virtual GcMethod* makeMethod(Thread* t, @@ -79,7 +87,7 @@ class Processor { uint16_t offset, GcByteArray* name, GcByteArray* spec, - object addendum, + GcMethodAddendum* addendum, GcClass* class_, GcCode* code) = 0; @@ -91,17 +99,17 @@ class Processor { uint8_t arrayElementSize, uint8_t arrayDimensions, GcClass* arrayElementClass, - object objectMask, - object name, - object sourceFile, - object super, + GcIntArray* objectMask, + GcByteArray* name, + GcByteArray* sourceFile, + GcClass* super, object interfaceTable, object virtualTable, object fieldTable, object methodTable, GcClassAddendum* addendum, GcSingleton* staticTable, - object loader, + GcClassLoader* loader, unsigned vtableLength) = 0; virtual void @@ -140,7 +148,7 @@ class Processor { va_list arguments) = 0; virtual object - invokeList(Thread* t, object loader, const char* className, + invokeList(Thread* t, GcClassLoader* loader, const char* className, const char* methodName, const char* methodSpec, object this_, va_list arguments) = 0; @@ -160,7 +168,7 @@ class Processor { addCompilationHandler(CompilationHandler* handler) = 0; virtual void - compileMethod(Thread* t, Zone* zone, object* constants, object* calls, + compileMethod(Thread* t, Zone* zone, GcTriple** constants, GcTriple** calls, avian::codegen::DelayedPromise** addresses, GcMethod* method, OffsetResolver* resolver) = 0; @@ -183,11 +191,11 @@ class Processor { dynamicWind(Thread* t, object before, object thunk, object after) = 0; virtual void - feedResultToContinuation(Thread* t, object continuation, object result) = 0; + feedResultToContinuation(Thread* t, GcContinuation* continuation, object result) = 0; virtual void - feedExceptionToContinuation(Thread* t, object continuation, - object exception) = 0; + feedExceptionToContinuation(Thread* t, GcContinuation* continuation, + GcThrowable* exception) = 0; virtual void walkContinuationBody(Thread* t, Heap::Walker* w, object o, unsigned start) @@ -207,7 +215,7 @@ class Processor { } object - invoke(Thread* t, object loader, const char* className, + invoke(Thread* t, GcClassLoader* loader, const char* className, const char* methodName, const char* methodSpec, object this_, ...) { va_list a; diff --git a/src/builtin.cpp b/src/builtin.cpp index 72f26ecb67..e4bbbd6563 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -447,7 +447,7 @@ Avian_avian_Continuations_00024Continuation_handleResult (Thread* t, object, uintptr_t* arguments) { t->m->processor->feedResultToContinuation - (t, reinterpret_cast(arguments[0]), + (t, cast(t, reinterpret_cast(arguments[0])), reinterpret_cast(arguments[1])); abort(t); @@ -458,8 +458,8 @@ Avian_avian_Continuations_00024Continuation_handleException (Thread* t, object, uintptr_t* arguments) { t->m->processor->feedExceptionToContinuation - (t, reinterpret_cast(arguments[0]), - reinterpret_cast(arguments[1])); + (t, cast(t, reinterpret_cast(arguments[0])), + cast(t, reinterpret_cast(arguments[1]))); abort(t); } diff --git a/src/classpath-android.cpp b/src/classpath-android.cpp index 5e67d54bc2..e597ef70b6 100644 --- a/src/classpath-android.cpp +++ b/src/classpath-android.cpp @@ -172,7 +172,7 @@ makeField(Thread* t, GcJclass* c, unsigned index) return reinterpret_cast(makeJfield(t, 0, c, type, 0, 0, name, index)); } -void initVmThread(Thread* t, object thread, unsigned offset) +void initVmThread(Thread* t, GcThread* thread, unsigned offset) { PROTECT(t, thread); @@ -189,16 +189,16 @@ void initVmThread(Thread* t, object thread, unsigned offset) t->m->processor->invoke(t, constructor, instance, thread); - set(t, thread, offset, instance); + set(t, reinterpret_cast(thread), offset, instance); } - if (threadGroup(t, thread) == 0) { - set(t, thread, ThreadGroup, threadGroup(t, t->javaThread)); - expect(t, threadGroup(t, thread)); + if (thread->group() == 0) { + set(t, reinterpret_cast(thread), ThreadGroup, threadGroup(t, t->javaThread)); + expect(t, thread->group()); } } -void initVmThread(Thread* t, object thread) +void initVmThread(Thread* t, GcThread* thread) { initVmThread( t, @@ -294,7 +294,7 @@ class MyClasspath : public Classpath { (t, root(t, Machine::BootLoader), reinterpret_cast(type(t, GcThread::Type)->name()), false); - object thread = makeNew(t, type(t, GcThread::Type)); + GcThread* thread = cast(t, makeNew(t, type(t, GcThread::Type))); PROTECT(t, thread); GcMethod* constructor = resolveMethod @@ -302,13 +302,13 @@ class MyClasspath : public Classpath { "(Ljava/lang/ThreadGroup;Ljava/lang/String;IZ)V"); t->m->processor->invoke - (t, constructor, thread, group, 0, NormalPriority, false); + (t, constructor, reinterpret_cast(thread), group, 0, NormalPriority, false); - set(t, thread, ThreadContextClassLoader, root(t, Machine::AppLoader)); + set(t, reinterpret_cast(thread), ThreadContextClassLoader, root(t, Machine::AppLoader)); initVmThread(t, thread); - return thread; + return reinterpret_cast(thread); } virtual object @@ -393,7 +393,7 @@ class MyClasspath : public Classpath { vm::release(t, t->javaThread); }); - initVmThread(t, t->javaThread, offset); + initVmThread(t, cast(t, t->javaThread), offset); GcMethod* method = resolveMethod (t, root(t, Machine::BootLoader), "java/lang/Thread", "run", "()V"); @@ -1468,7 +1468,7 @@ extern "C" AVIAN_EXPORT void JNICALL Avian_java_lang_VMThread_create (Thread* t, object, uintptr_t* arguments) { - object thread = reinterpret_cast(arguments[0]); + GcThread* thread = cast(t, reinterpret_cast(arguments[0])); PROTECT(t, thread); local::initVmThread(t, thread); diff --git a/src/classpath-avian.cpp b/src/classpath-avian.cpp index aab301a791..16e6574801 100644 --- a/src/classpath-avian.cpp +++ b/src/classpath-avian.cpp @@ -661,7 +661,7 @@ Avian_java_lang_Thread_doStart (Thread* t, object, uintptr_t* arguments) { return reinterpret_cast - (startThread(t, reinterpret_cast(*arguments))); + (startThread(t, cast(t, reinterpret_cast(*arguments)))); } extern "C" AVIAN_EXPORT void JNICALL diff --git a/src/classpath-openjdk.cpp b/src/classpath-openjdk.cpp index 9f2ddf34be..26f5ff4e24 100644 --- a/src/classpath-openjdk.cpp +++ b/src/classpath-openjdk.cpp @@ -728,7 +728,7 @@ class MyClasspath : public Classpath { t->m->processor->invoke(t, constructor, instance); t->m->processor->invoke - (t, root(t, Machine::BootLoader), "java/lang/System", + (t, cast(t, root(t, Machine::BootLoader)), "java/lang/System", "setProperties", "(Ljava/util/Properties;)V", 0, instance); } @@ -762,11 +762,11 @@ class MyClasspath : public Classpath { } t->m->processor->invoke - (t, root(t, Machine::BootLoader), "java/lang/System", + (t, cast(t, root(t, Machine::BootLoader)), "java/lang/System", "initializeSystemClass", "()V", 0); t->m->processor->invoke - (t, root(t, Machine::BootLoader), "sun/misc/Launcher", + (t, cast(t, root(t, Machine::BootLoader)), "sun/misc/Launcher", "getLauncher", "()Lsun/misc/Launcher;", 0); set(t, t->javaThread, ThreadContextClassLoader, @@ -3268,7 +3268,7 @@ jvmStartThread(Thread* t, uintptr_t* arguments) { jobject thread = reinterpret_cast(arguments[0]); - return startThread(t, *thread) != 0; + return startThread(t, cast(t, *thread)) != 0; } extern "C" AVIAN_EXPORT void JNICALL diff --git a/src/compile.cpp b/src/compile.cpp index 86b193cb80..f7d9279655 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -245,9 +245,9 @@ class MyThread: public Thread { t->transition = 0; } - MyThread(Machine* m, object javaThread, MyThread* parent, + MyThread(Machine* m, GcThread* javaThread, MyThread* parent, bool useNativeFeatures): - Thread(m, javaThread, parent), + Thread(m, reinterpret_cast(javaThread), parent), ip(0), stack(0), newStack(0), @@ -8285,7 +8285,7 @@ class MyProcessor: public Processor { } virtual Thread* - makeThread(Machine* m, object javaThread, Thread* parent) + makeThread(Machine* m, GcThread* javaThread, Thread* parent) { MyThread* t = new (m->heap->allocate(sizeof(MyThread))) MyThread(m, javaThread, static_cast(parent), @@ -8377,7 +8377,7 @@ class MyProcessor: public Processor { uint16_t offset, GcByteArray* name, GcByteArray* spec, - object addendum, + GcMethodAddendum* addendum, GcClass* class_, GcCode* code) { @@ -8396,7 +8396,7 @@ class MyProcessor: public Processor { 0, name, spec, - cast(t, addendum), + addendum, class_, code); } @@ -8409,17 +8409,17 @@ class MyProcessor: public Processor { uint8_t arrayElementSize, uint8_t arrayDimensions, GcClass* arrayElementClass, - object objectMask, - object name, - object sourceFile, - object super, + GcIntArray* objectMask, + GcByteArray* name, + GcByteArray* sourceFile, + GcClass* super, object interfaceTable, object virtualTable, object fieldTable, object methodTable, GcClassAddendum* addendum, GcSingleton* staticTable, - object loader, + GcClassLoader* loader, unsigned vtableLength) { return vm::makeClass(t, @@ -8430,17 +8430,17 @@ class MyProcessor: public Processor { arrayDimensions, arrayElementClass, 0, - cast(t, objectMask), - cast(t, name), - cast(t, sourceFile), - cast(t, super), + objectMask, + name, + sourceFile, + super, interfaceTable, virtualTable, fieldTable, methodTable, addendum, staticTable, - cast(t, loader), + loader, 0, vtableLength); } @@ -8647,7 +8647,7 @@ class MyProcessor: public Processor { } virtual object - invokeList(Thread* t, object loader, const char* className, + invokeList(Thread* t, GcClassLoader* loader, const char* className, const char* methodName, const char* methodSpec, object this_, va_list arguments) { @@ -8664,7 +8664,7 @@ class MyProcessor: public Processor { this_, methodSpec, false, arguments); GcMethod* method = resolveMethod - (t, loader, className, methodName, methodSpec); + (t, reinterpret_cast(loader), className, methodName, methodSpec); assertT(t, ((method->flags() & ACC_STATIC) == 0) xor (this_ == 0)); @@ -8805,17 +8805,17 @@ class MyProcessor: public Processor { CompilationHandlerList(compilationHandlers, handler); } - virtual void compileMethod(Thread* vmt, Zone* zone, object* constants, - object* calls, avian::codegen::DelayedPromise** addresses, + virtual void compileMethod(Thread* vmt, Zone* zone, GcTriple** constants, + GcTriple** calls, avian::codegen::DelayedPromise** addresses, GcMethod* method, OffsetResolver* resolver) { MyThread* t = static_cast(vmt); - BootContext bootContext(t, *constants, *calls, *addresses, zone, resolver); + BootContext bootContext(t, reinterpret_cast(*constants), reinterpret_cast(*calls), *addresses, zone, resolver); compile(t, &codeAllocator, &bootContext, method); - *constants = bootContext.constants; - *calls = bootContext.calls; + *constants = cast(t, bootContext.constants); + *calls = cast(t, bootContext.calls); *addresses = bootContext.addresses; } @@ -8923,21 +8923,21 @@ class MyProcessor: public Processor { } } - virtual void feedResultToContinuation(Thread* t, object continuation, + virtual void feedResultToContinuation(Thread* t, GcContinuation* continuation, object result) { if (Continuations) { - callContinuation(static_cast(t), continuation, result, 0); + callContinuation(static_cast(t), reinterpret_cast(continuation), result, 0); } else { abort(t); } } - virtual void feedExceptionToContinuation(Thread* t, object continuation, - object exception) + virtual void feedExceptionToContinuation(Thread* t, GcContinuation* continuation, + GcThrowable* exception) { if (Continuations) { - callContinuation(static_cast(t), continuation, 0, exception); + callContinuation(static_cast(t), reinterpret_cast(continuation), 0, reinterpret_cast(exception)); } else { abort(t); } diff --git a/src/interpret.cpp b/src/interpret.cpp index c59b79a1f5..e0acedcabf 100644 --- a/src/interpret.cpp +++ b/src/interpret.cpp @@ -35,8 +35,8 @@ const unsigned FrameFootprint = 4; class Thread: public vm::Thread { public: - Thread(Machine* m, object javaThread, vm::Thread* parent): - vm::Thread(m, javaThread, parent), + Thread(Machine* m, GcThread* javaThread, vm::Thread* parent): + vm::Thread(m, reinterpret_cast(javaThread), parent), ip(0), sp(0), frame(-1), @@ -2965,7 +2965,7 @@ class MyProcessor: public Processor { } virtual vm::Thread* - makeThread(Machine* m, object javaThread, vm::Thread* parent) + makeThread(Machine* m, GcThread* javaThread, vm::Thread* parent) { Thread* t = new (m->heap->allocate(sizeof(Thread) + m->stackSizeInBytes)) Thread(m, javaThread, parent); @@ -2983,7 +2983,7 @@ class MyProcessor: public Processor { uint16_t offset, GcByteArray* name, GcByteArray* spec, - object addendum, + GcMethodAddendum* addendum, GcClass* class_, GcCode* code) { @@ -2998,7 +2998,7 @@ class MyProcessor: public Processor { 0, name, spec, - cast(t, addendum), + addendum, class_, code); } @@ -3011,17 +3011,17 @@ class MyProcessor: public Processor { uint8_t arrayElementSize, uint8_t arrayDimensions, GcClass* arrayElementClass, - object objectMask, - object name, - object sourceFile, - object super, + GcIntArray* objectMask, + GcByteArray* name, + GcByteArray* sourceFile, + GcClass* super, object interfaceTable, object virtualTable, object fieldTable, object methodTable, GcClassAddendum* addendum, GcSingleton* staticTable, - object loader, + GcClassLoader* loader, unsigned vtableLength UNUSED) { return vm::makeClass(t, @@ -3032,17 +3032,17 @@ class MyProcessor: public Processor { arrayDimensions, arrayElementClass, 0, - cast(t, objectMask), - cast(t, name), - cast(t, sourceFile), - cast(t, super), + objectMask, + name, + sourceFile, + super, interfaceTable, virtualTable, fieldTable, methodTable, addendum, staticTable, - cast(t, loader), + loader, 0, 0); } @@ -3201,7 +3201,7 @@ class MyProcessor: public Processor { } virtual object - invokeList(vm::Thread* vmt, object loader, const char* className, + invokeList(vm::Thread* vmt, GcClassLoader* loader, const char* className, const char* methodName, const char* methodSpec, object this_, va_list arguments) { @@ -3219,7 +3219,7 @@ class MyProcessor: public Processor { pushArguments(t, this_, methodSpec, false, arguments); GcMethod* method = resolveMethod - (t, loader, className, methodName, methodSpec); + (t, reinterpret_cast(loader), className, methodName, methodSpec); assertT(t, ((method->flags() & ACC_STATIC) == 0) xor (this_ == 0)); @@ -3240,7 +3240,7 @@ class MyProcessor: public Processor { abort(s); } - virtual void compileMethod(vm::Thread*, Zone*, object*, object*, + virtual void compileMethod(vm::Thread*, Zone*, GcTriple**, GcTriple**, avian::codegen::DelayedPromise**, GcMethod*, OffsetResolver*) { abort(s); @@ -3270,11 +3270,11 @@ class MyProcessor: public Processor { abort(s); } - virtual void feedResultToContinuation(vm::Thread*, object, object){ + virtual void feedResultToContinuation(vm::Thread*, GcContinuation*, object){ abort(s); } - virtual void feedExceptionToContinuation(vm::Thread*, object, object) { + virtual void feedExceptionToContinuation(vm::Thread*, GcContinuation*, GcThrowable*) { abort(s); } diff --git a/src/machine.cpp b/src/machine.cpp index 6855ad22e4..28dd1b8947 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -2184,7 +2184,7 @@ parseMethodTable(Thread* t, Stream& s, GcClass* class_, GcSingleton* pool) 0, // offset cast(t, singletonObject(t, pool, name - 1)), cast(t, singletonObject(t, pool, spec - 1)), - addendum, + cast(t, addendum), class_, cast(t, code)); @@ -2550,17 +2550,17 @@ makeArrayClass(Thread* t, object loader, unsigned dimensions, object spec, BytesPerWord, dimensions, cast(t, elementClass), - reinterpret_cast(type(t, GcArray::Type)->objectMask()), - spec, + type(t, GcArray::Type)->objectMask(), + cast(t, spec), 0, - reinterpret_cast(type(t, GcJobject::Type)), + type(t, GcJobject::Type), root(t, Machine::ArrayInterfaceTable), vtable, 0, 0, 0, 0, - loader, + cast(t, loader), arrayLength(t, vtable)); PROTECT(t, c); @@ -2744,8 +2744,8 @@ 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, reinterpret_cast(super), 0, 0, 0, 0, 0, 0, - root(t, Machine::BootLoader), vtableLength); + arrayElementSize ? 1 : 0, 0, cast(t, mask), 0, 0, super, 0, 0, 0, 0, 0, 0, + cast(t, root(t, Machine::BootLoader)), vtableLength); setType(t, type, class_); } @@ -3088,7 +3088,7 @@ doCollect(Thread* t, Heap::CollectionType type, int pendingAllocation) and t->state != Thread::ExitState) { m->finalizeThread = m->processor->makeThread - (m, root(t, Machine::FinalizerThread), m->rootThread); + (m, cast(t, root(t, Machine::FinalizerThread)), m->rootThread); addThread(t, m->finalizeThread); @@ -3509,7 +3509,7 @@ shutDown(Thread* t) object h = hooks; PROTECT(t, h); for (; h; h = pairSecond(t, h)) { - startThread(t, pairFirst(t, h)); + startThread(t, cast(t, pairFirst(t, h))); } // wait for hooks to exit @@ -4331,17 +4331,17 @@ parseClass(Thread* t, object loader, const uint8_t* data, unsigned size, class_->arrayElementSize(), class_->arrayDimensions(), class_->arrayElementClass(), - reinterpret_cast(class_->objectMask()), - reinterpret_cast(class_->name()), - reinterpret_cast(class_->sourceFile()), - reinterpret_cast(class_->super()), - reinterpret_cast(class_->interfaceTable()), - reinterpret_cast(class_->virtualTable()), - reinterpret_cast(class_->fieldTable()), - reinterpret_cast(class_->methodTable()), + class_->objectMask(), + class_->name(), + class_->sourceFile(), + class_->super(), + class_->interfaceTable(), + class_->virtualTable(), + class_->fieldTable(), + class_->methodTable(), class_->addendum(), class_->staticTable(), - reinterpret_cast(class_->loader()), + class_->loader(), vtableLength); PROTECT(t, real); diff --git a/src/tools/bootimage-generator/main.cpp b/src/tools/bootimage-generator/main.cpp index 302edd7ccc..4b20d0078a 100644 --- a/src/tools/bootimage-generator/main.cpp +++ b/src/tools/bootimage-generator/main.cpp @@ -631,7 +631,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, PROTECT(t, method); t->m->processor->compileMethod - (t, zone, &constants, &calls, &addresses, method, &resolver); + (t, zone, reinterpret_cast(&constants), reinterpret_cast(&calls), &addresses, method, &resolver); if (method->code()) { methods = reinterpret_cast(makePair(t, reinterpret_cast(method), methods));