better statically type Processor interface

This commit is contained in:
Joshua Warner 2014-06-28 13:16:26 -06:00 committed by Joshua Warner
parent 0ec87c6aa1
commit 51368651dc
10 changed files with 108 additions and 100 deletions

View File

@ -2081,7 +2081,7 @@ removeThread(Thread* t, Thread* p)
}
inline Thread*
startThread(Thread* t, object javaThread)
startThread(Thread* t, GcThread* javaThread)
{
{ PROTECT(t, javaThread);

View File

@ -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;

View File

@ -447,7 +447,7 @@ Avian_avian_Continuations_00024Continuation_handleResult
(Thread* t, object, uintptr_t* arguments)
{
t->m->processor->feedResultToContinuation
(t, reinterpret_cast<object>(arguments[0]),
(t, cast<GcContinuation>(t, reinterpret_cast<object>(arguments[0])),
reinterpret_cast<object>(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<object>(arguments[0]),
reinterpret_cast<object>(arguments[1]));
(t, cast<GcContinuation>(t, reinterpret_cast<object>(arguments[0])),
cast<GcThrowable>(t, reinterpret_cast<object>(arguments[1])));
abort(t);
}

View File

@ -172,7 +172,7 @@ makeField(Thread* t, GcJclass* c, unsigned index)
return reinterpret_cast<object>(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<object>(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<object>(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<object>(type(t, GcThread::Type)->name()), false);
object thread = makeNew(t, type(t, GcThread::Type));
GcThread* thread = cast<GcThread>(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<object>(thread), group, 0, NormalPriority, false);
set(t, thread, ThreadContextClassLoader, root(t, Machine::AppLoader));
set(t, reinterpret_cast<object>(thread), ThreadContextClassLoader, root(t, Machine::AppLoader));
initVmThread(t, thread);
return thread;
return reinterpret_cast<object>(thread);
}
virtual object
@ -393,7 +393,7 @@ class MyClasspath : public Classpath {
vm::release(t, t->javaThread);
});
initVmThread(t, t->javaThread, offset);
initVmThread(t, cast<GcThread>(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<object>(arguments[0]);
GcThread* thread = cast<GcThread>(t, reinterpret_cast<object>(arguments[0]));
PROTECT(t, thread);
local::initVmThread(t, thread);

View File

@ -661,7 +661,7 @@ Avian_java_lang_Thread_doStart
(Thread* t, object, uintptr_t* arguments)
{
return reinterpret_cast<int64_t>
(startThread(t, reinterpret_cast<object>(*arguments)));
(startThread(t, cast<GcThread>(t, reinterpret_cast<object>(*arguments))));
}
extern "C" AVIAN_EXPORT void JNICALL

View File

@ -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<GcClassLoader>(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<GcClassLoader>(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<GcClassLoader>(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<jobject>(arguments[0]);
return startThread(t, *thread) != 0;
return startThread(t, cast<GcThread>(t, *thread)) != 0;
}
extern "C" AVIAN_EXPORT void JNICALL

View File

@ -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<object>(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<MyThread*>(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<GcMethodAddendum>(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<GcIntArray>(t, objectMask),
cast<GcByteArray>(t, name),
cast<GcByteArray>(t, sourceFile),
cast<GcClass>(t, super),
objectMask,
name,
sourceFile,
super,
interfaceTable,
virtualTable,
fieldTable,
methodTable,
addendum,
staticTable,
cast<GcClassLoader>(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<object>(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<MyThread*>(vmt);
BootContext bootContext(t, *constants, *calls, *addresses, zone, resolver);
BootContext bootContext(t, reinterpret_cast<object>(*constants), reinterpret_cast<object>(*calls), *addresses, zone, resolver);
compile(t, &codeAllocator, &bootContext, method);
*constants = bootContext.constants;
*calls = bootContext.calls;
*constants = cast<GcTriple>(t, bootContext.constants);
*calls = cast<GcTriple>(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<MyThread*>(t), continuation, result, 0);
callContinuation(static_cast<MyThread*>(t), reinterpret_cast<object>(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<MyThread*>(t), continuation, 0, exception);
callContinuation(static_cast<MyThread*>(t), reinterpret_cast<object>(continuation), 0, reinterpret_cast<object>(exception));
} else {
abort(t);
}

View File

@ -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<object>(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<GcMethodAddendum>(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<GcIntArray>(t, objectMask),
cast<GcByteArray>(t, name),
cast<GcByteArray>(t, sourceFile),
cast<GcClass>(t, super),
objectMask,
name,
sourceFile,
super,
interfaceTable,
virtualTable,
fieldTable,
methodTable,
addendum,
staticTable,
cast<GcClassLoader>(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<object>(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);
}

View File

@ -2184,7 +2184,7 @@ parseMethodTable(Thread* t, Stream& s, GcClass* class_, GcSingleton* pool)
0, // offset
cast<GcByteArray>(t, singletonObject(t, pool, name - 1)),
cast<GcByteArray>(t, singletonObject(t, pool, spec - 1)),
addendum,
cast<GcMethodAddendum>(t, addendum),
class_,
cast<GcCode>(t, code));
@ -2550,17 +2550,17 @@ makeArrayClass(Thread* t, object loader, unsigned dimensions, object spec,
BytesPerWord,
dimensions,
cast<GcClass>(t, elementClass),
reinterpret_cast<object>(type(t, GcArray::Type)->objectMask()),
spec,
type(t, GcArray::Type)->objectMask(),
cast<GcByteArray>(t, spec),
0,
reinterpret_cast<object>(type(t, GcJobject::Type)),
type(t, GcJobject::Type),
root(t, Machine::ArrayInterfaceTable),
vtable,
0,
0,
0,
0,
loader,
cast<GcClassLoader>(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<object>(super), 0, 0, 0, 0, 0, 0,
root(t, Machine::BootLoader), vtableLength);
arrayElementSize ? 1 : 0, 0, cast<GcIntArray>(t, mask), 0, 0, super, 0, 0, 0, 0, 0, 0,
cast<GcClassLoader>(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<GcThread>(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<GcThread>(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<object>(class_->objectMask()),
reinterpret_cast<object>(class_->name()),
reinterpret_cast<object>(class_->sourceFile()),
reinterpret_cast<object>(class_->super()),
reinterpret_cast<object>(class_->interfaceTable()),
reinterpret_cast<object>(class_->virtualTable()),
reinterpret_cast<object>(class_->fieldTable()),
reinterpret_cast<object>(class_->methodTable()),
class_->objectMask(),
class_->name(),
class_->sourceFile(),
class_->super(),
class_->interfaceTable(),
class_->virtualTable(),
class_->fieldTable(),
class_->methodTable(),
class_->addendum(),
class_->staticTable(),
reinterpret_cast<object>(class_->loader()),
class_->loader(),
vtableLength);
PROTECT(t, real);

View File

@ -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<GcTriple**>(&constants), reinterpret_cast<GcTriple**>(&calls), &addresses, method, &resolver);
if (method->code()) {
methods = reinterpret_cast<object>(makePair(t, reinterpret_cast<object>(method), methods));