formalize MyProcessor::roots (for Compiler) in types.def

This commit is contained in:
Joshua Warner 2014-06-21 20:54:51 -06:00 committed by Joshua Warner
parent 052f2498aa
commit ed1f34dca3

View File

@ -74,18 +74,6 @@ const unsigned InitialZoneCapacityInBytes = 64 * 1024;
const unsigned ExecutableAreaSizeInBytes = 30 * 1024 * 1024; const unsigned ExecutableAreaSizeInBytes = 30 * 1024 * 1024;
enum Root {
CallTable,
MethodTree,
MethodTreeSentinal,
ObjectPools,
StaticTableArray,
VirtualThunks,
ReceiveMethod,
WindMethod,
RewindMethod
};
enum ThunkIndex { enum ThunkIndex {
compileMethodIndex, compileMethodIndex,
compileVirtualMethodIndex, compileVirtualMethodIndex,
@ -100,8 +88,6 @@ enum ThunkIndex {
dummyIndex dummyIndex
}; };
const unsigned RootCount = RewindMethod + 1;
inline bool inline bool
isVmInvokeUnsafeStack(void* ip) isVmInvokeUnsafeStack(void* ip)
{ {
@ -358,11 +344,8 @@ resolveTarget(MyThread* t, GcClass* class_, unsigned index)
return cast<GcMethod>(t, cast<GcArray>(t, class_->virtualTable())->body()[index]); return cast<GcMethod>(t, cast<GcArray>(t, class_->virtualTable())->body()[index]);
} }
object& GcCompileRoots*
root(Thread* t, Root root); compileRoots(Thread* t);
void
setRoot(Thread* t, Root root, object value);
intptr_t intptr_t
methodCompiled(Thread* t UNUSED, GcMethod* method) methodCompiled(Thread* t UNUSED, GcMethod* method)
@ -415,9 +398,9 @@ methodForIp(MyThread* t, void* ip)
return cast<GcMethod>( return cast<GcMethod>(
t, t,
treeQuery(t, treeQuery(t,
cast<GcTreeNode>(t, root(t, MethodTree)), compileRoots(t)->methodTree(),
reinterpret_cast<intptr_t>(ip), reinterpret_cast<intptr_t>(ip),
cast<GcTreeNode>(t, root(t, MethodTreeSentinal)), compileRoots(t)->methodTreeSentinal(),
compareIpToMethodBounds)); compareIpToMethodBounds));
} }
@ -6816,8 +6799,8 @@ finish(MyThread* t, FixedAllocator* allocator, Context* context)
initArray(t, reinterpret_cast<GcArray*>(pool), context->objectPoolCount + 1); initArray(t, reinterpret_cast<GcArray*>(pool), context->objectPoolCount + 1);
mark(t, pool, 0); mark(t, pool, 0);
set(t, pool, ArrayBody, root(t, ObjectPools)); set(t, pool, ArrayBody, compileRoots(t)->objectPools());
setRoot(t, ObjectPools, pool); set(t, reinterpret_cast<object>(compileRoots(t)), CompileRootsObjectPools, pool);
unsigned i = 1; unsigned i = 1;
for (PoolElement* p = context->objectPool; p; p = p->next) { for (PoolElement* p = context->objectPool; p; p = p->next) {
@ -7722,7 +7705,7 @@ callContinuation(MyThread* t, GcContinuation* continuation, object result,
nextContinuation = cast<GcContinuation>(t, rewindContext->continuation()); nextContinuation = cast<GcContinuation>(t, rewindContext->continuation());
action = Rewind; action = Rewind;
if (root(t, RewindMethod) == 0) { if (compileRoots(t)->rewindMethod() == 0) {
PROTECT(t, nextContinuation); PROTECT(t, nextContinuation);
GcMethod* method = resolveMethod GcMethod* method = resolveMethod
@ -7734,7 +7717,7 @@ callContinuation(MyThread* t, GcContinuation* continuation, object result,
compile(t, local::codeAllocator(t), 0, method); compile(t, local::codeAllocator(t), 0, method);
setRoot(t, RewindMethod, reinterpret_cast<object>(method)); set(t, compileRoots(t), CompileRootsRewindMethod, method);
} }
} else { } else {
action = Call; action = Call;
@ -7765,7 +7748,7 @@ callContinuation(MyThread* t, GcContinuation* continuation, object result,
transition(t, 0, 0, nextContinuation, t->trace); transition(t, 0, 0, nextContinuation, t->trace);
jumpAndInvoke jumpAndInvoke
(t, cast<GcMethod>(t, root(t, RewindMethod)), stack, (t, compileRoots(t)->rewindMethod(), stack,
nextContinuation->context()->before(), nextContinuation->context()->before(),
continuation, result, exception); continuation, result, exception);
} break; } break;
@ -7784,13 +7767,13 @@ callWithCurrentContinuation(MyThread* t, object receiver)
{ PROTECT(t, receiver); { PROTECT(t, receiver);
if (root(t, ReceiveMethod) == 0) { if (compileRoots(t)->receiveMethod() == 0) {
GcMethod* m = resolveMethod GcMethod* m = resolveMethod
(t, roots(t)->bootLoader(), "avian/Function", "call", (t, roots(t)->bootLoader(), "avian/Function", "call",
"(Ljava/lang/Object;)Ljava/lang/Object;"); "(Ljava/lang/Object;)Ljava/lang/Object;");
if (m) { if (m) {
setRoot(t, ReceiveMethod, reinterpret_cast<object>(m)); set(t, compileRoots(t), CompileRootsReceiveMethod, m);
GcClass* continuationClass = type(t, GcContinuation::Type); GcClass* continuationClass = type(t, GcContinuation::Type);
@ -7802,7 +7785,7 @@ callWithCurrentContinuation(MyThread* t, object receiver)
} }
method = findInterfaceMethod method = findInterfaceMethod
(t, cast<GcMethod>(t, root(t, ReceiveMethod)), objectClass(t, receiver)); (t, compileRoots(t)->receiveMethod(), objectClass(t, receiver));
PROTECT(t, method); PROTECT(t, method);
compile(t, local::codeAllocator(t), 0, method); compile(t, local::codeAllocator(t), 0, method);
@ -7823,14 +7806,14 @@ dynamicWind(MyThread* t, object before, object thunk, object after)
PROTECT(t, thunk); PROTECT(t, thunk);
PROTECT(t, after); PROTECT(t, after);
if (root(t, WindMethod) == 0) { if (compileRoots(t)->windMethod() == 0) {
GcMethod* method = resolveMethod GcMethod* method = resolveMethod
(t, roots(t)->bootLoader(), "avian/Continuations", "wind", (t, roots(t)->bootLoader(), "avian/Continuations", "wind",
"(Ljava/lang/Runnable;Ljava/util/concurrent/Callable;" "(Ljava/lang/Runnable;Ljava/util/concurrent/Callable;"
"Ljava/lang/Runnable;)Lavian/Continuations$UnwindResult;"); "Ljava/lang/Runnable;)Lavian/Continuations$UnwindResult;");
if (method) { if (method) {
setRoot(t, WindMethod, reinterpret_cast<object>(method)); set(t, compileRoots(t), CompileRootsWindMethod, method);
compile(t, local::codeAllocator(t), 0, method); compile(t, local::codeAllocator(t), 0, method);
} }
} }
@ -7848,7 +7831,7 @@ dynamicWind(MyThread* t, object before, object thunk, object after)
set(t, t->continuation, ContinuationContext, newContext); set(t, t->continuation, ContinuationContext, newContext);
} }
jumpAndInvoke(t, cast<GcMethod>(t, root(t, WindMethod)), stack, before, thunk, after); jumpAndInvoke(t, compileRoots(t)->windMethod(), stack, before, thunk, after);
} }
class ArgumentList { class ArgumentList {
@ -8829,13 +8812,16 @@ class MyProcessor: public Processor {
} }
virtual void visitRoots(Thread* t, HeapWalker* w) { virtual void visitRoots(Thread* t, HeapWalker* w) {
bootImage->methodTree = w->visitRoot(root(t, MethodTree)); bootImage->methodTree
bootImage->methodTreeSentinal = w->visitRoot(root(t, MethodTreeSentinal)); = w->visitRoot(reinterpret_cast<object>(compileRoots(t)->methodTree()));
bootImage->virtualThunks = w->visitRoot(root(t, VirtualThunks)); bootImage->methodTreeSentinal = w->visitRoot(
reinterpret_cast<object>(compileRoots(t)->methodTreeSentinal()));
bootImage->virtualThunks = w->visitRoot(
reinterpret_cast<object>(compileRoots(t)->virtualThunks()));
} }
virtual void normalizeVirtualThunks(Thread* t) { virtual void normalizeVirtualThunks(Thread* t) {
GcWordArray* a = cast<GcWordArray>(t, root(t, VirtualThunks)); GcWordArray* a = compileRoots(t)->virtualThunks();
for (unsigned i = 0; i < a->length(); for (unsigned i = 0; i < a->length();
i += 2) i += 2)
{ {
@ -8854,7 +8840,7 @@ class MyProcessor: public Processor {
(t->m->heap->allocate(callTableSize * sizeof(unsigned) * 2)); (t->m->heap->allocate(callTableSize * sizeof(unsigned) * 2));
unsigned index = 0; unsigned index = 0;
GcArray* callTable = cast<GcArray>(t, root(t, CallTable)); GcArray* callTable = compileRoots(t)->callTable();
for (unsigned i = 0; i < callTable->length(); ++i) { for (unsigned i = 0; i < callTable->length(); ++i) {
for (GcCallNode* p = cast<GcCallNode>(t, callTable->body()[i]); for (GcCallNode* p = cast<GcCallNode>(t, callTable->body()[i]);
p; p = p->next()) p; p = p->next())
@ -8887,16 +8873,19 @@ class MyProcessor: public Processor {
if (image and code) { if (image and code) {
local::boot(static_cast<MyThread*>(t), image, code); local::boot(static_cast<MyThread*>(t), image, code);
} else { } else {
roots = makeArray(t, RootCount); roots = makeCompileRoots(t, 0, 0, 0, 0, 0, 0, 0, 0, 0);
setRoot(t, CallTable, reinterpret_cast<object>(makeArray(t, 128))); {
GcArray* ct = makeArray(t, 128);
// sequence point, for gc (don't recombine statements)
set(t, compileRoots(t), CompileRootsCallTable, ct);
}
setRoot(t, MethodTreeSentinal, reinterpret_cast<object>(makeTreeNode(t, 0, 0, 0))); GcTreeNode* tree = makeTreeNode(t, 0, 0, 0);
setRoot(t, MethodTree, root(t, MethodTreeSentinal)); set(t, compileRoots(t), CompileRootsMethodTreeSentinal, tree);
set(t, root(t, MethodTree), TreeNodeLeft, set(t, compileRoots(t), CompileRootsMethodTree, tree);
root(t, MethodTreeSentinal)); set(t, tree, TreeNodeLeft, tree);
set(t, root(t, MethodTree), TreeNodeRight, set(t, tree, TreeNodeRight, tree);
root(t, MethodTreeSentinal));
} }
#ifdef AVIAN_AOT_ONLY #ifdef AVIAN_AOT_ONLY
@ -8967,7 +8956,7 @@ class MyProcessor: public Processor {
System* s; System* s;
SignalRegistrar signals; SignalRegistrar signals;
Allocator* allocator; Allocator* allocator;
GcArray* roots; GcCompileRoots* roots;
BootImage* bootImage; BootImage* bootImage;
uintptr_t* heapImage; uintptr_t* heapImage;
uint8_t* codeImage; uint8_t* codeImage;
@ -9147,7 +9136,7 @@ isThunkUnsafeStack(MyProcessor::ThunkCollection* thunks, void* ip)
bool bool
isVirtualThunk(MyThread* t, void* ip) isVirtualThunk(MyThread* t, void* ip)
{ {
GcWordArray* a = cast<GcWordArray>(t, root(t, VirtualThunks)); GcWordArray* a = compileRoots(t)->virtualThunks();
for (unsigned i = 0; i < a->length(); i += 2) for (unsigned i = 0; i < a->length(); i += 2)
{ {
uintptr_t start = a->body()[i]; uintptr_t start = a->body()[i];
@ -9185,7 +9174,7 @@ findCallNode(MyThread* t, void* address)
// compile(MyThread*, Allocator*, BootContext*, object)): // compile(MyThread*, Allocator*, BootContext*, object)):
loadMemoryBarrier(); loadMemoryBarrier();
GcArray* table = cast<GcArray>(t, root(t, CallTable)); GcArray* table = compileRoots(t)->callTable();
intptr_t key = reinterpret_cast<intptr_t>(address); intptr_t key = reinterpret_cast<intptr_t>(address);
unsigned index = static_cast<uintptr_t>(key) & (table->length() - 1); unsigned index = static_cast<uintptr_t>(key) & (table->length() - 1);
@ -9265,13 +9254,10 @@ insertCallNode(MyThread* t, GcArray* table, unsigned* size, GcCallNode* node)
void void
insertCallNode(MyThread* t, GcCallNode* node) insertCallNode(MyThread* t, GcCallNode* node)
{ {
setRoot(t, GcArray* newArray = insertCallNode(
CallTable, t, compileRoots(t)->callTable(), &(processor(t)->callTableSize), node);
reinterpret_cast<object>( // sequence point, for gc (don't recombine statements)
insertCallNode(t, set(t, compileRoots(t), CompileRootsCallTable, newArray);
cast<GcArray>(t, root(t, CallTable)),
&(processor(t)->callTableSize),
node)));
} }
GcHashMap* GcHashMap*
@ -9484,7 +9470,7 @@ findThunks(MyThread* t, BootImage* image, uint8_t* code)
void void
fixupVirtualThunks(MyThread* t, uint8_t* code) fixupVirtualThunks(MyThread* t, uint8_t* code)
{ {
GcWordArray* a = cast<GcWordArray>(t, root(t, VirtualThunks)); GcWordArray* a = compileRoots(t)->virtualThunks();
for (unsigned i = 0; i < a->length(); i += 2) for (unsigned i = 0; i < a->length(); i += 2)
{ {
if (a->body()[i]) { if (a->body()[i]) {
@ -9536,12 +9522,12 @@ boot(MyThread* t, BootImage* image, uint8_t* code)
set(t, reinterpret_cast<object>(roots(t)), RootsBootLoader, bootObject(heap, image->bootLoader)); set(t, reinterpret_cast<object>(roots(t)), RootsBootLoader, bootObject(heap, image->bootLoader));
set(t, reinterpret_cast<object>(roots(t)), RootsAppLoader, bootObject(heap, image->appLoader)); set(t, reinterpret_cast<object>(roots(t)), RootsAppLoader, bootObject(heap, image->appLoader));
p->roots = makeArray(t, RootCount); p->roots = makeCompileRoots(t, 0, 0, 0, 0, 0, 0, 0, 0, 0);
setRoot(t, MethodTree, bootObject(heap, image->methodTree)); set(t, reinterpret_cast<object>(compileRoots(t)), CompileRootsMethodTree, bootObject(heap, image->methodTree));
setRoot(t, MethodTreeSentinal, bootObject(heap, image->methodTreeSentinal)); set(t, reinterpret_cast<object>(compileRoots(t)), CompileRootsMethodTreeSentinal, bootObject(heap, image->methodTreeSentinal));
setRoot(t, VirtualThunks, bootObject(heap, image->virtualThunks)); set(t, reinterpret_cast<object>(compileRoots(t)), CompileRootsVirtualThunks, bootObject(heap, image->virtualThunks));
{ {
GcHashMap* map = makeClassMap(t, bootClassTable, image->bootClassCount, heap); GcHashMap* map = makeClassMap(t, bootClassTable, image->bootClassCount, heap);
@ -9559,18 +9545,31 @@ boot(MyThread* t, BootImage* image, uint8_t* code)
roots(t)->appLoader()->as<GcSystemClassLoader>(t)->finder() = t->m->appFinder; roots(t)->appLoader()->as<GcSystemClassLoader>(t)->finder() = t->m->appFinder;
set(t, roots(t), RootsStringMap, makeStringMap {
(t, stringTable, image->stringCount, heap)); GcWeakHashMap* map = makeStringMap(t, stringTable, image->stringCount, heap);
// sequence point, for gc (don't recombine statements)
set(t, roots(t), RootsStringMap, map);
}
p->callTableSize = image->callCount; p->callTableSize = image->callCount;
setRoot(t, CallTable, reinterpret_cast<object>(makeCallTable {
(t, heap, callTable, image->callCount, GcArray* ct = makeCallTable(t,
reinterpret_cast<uintptr_t>(code)))); heap,
callTable,
image->callCount,
reinterpret_cast<uintptr_t>(code));
// sequence point, for gc (don't recombine statements)
set(t, compileRoots(t), CompileRootsCallTable, ct);
}
setRoot(t, StaticTableArray, reinterpret_cast<object>(makeStaticTableArray {
GcArray* staticTableArray = makeStaticTableArray
(t, bootClassTable, image->bootClassCount, (t, bootClassTable, image->bootClassCount,
appClassTable, image->appClassCount, heap))); appClassTable, image->appClassCount, heap);
// sequence point, for gc (don't recombine statements)
set(t, compileRoots(t), CompileRootsStaticTableArray, staticTableArray);
}
findThunks(t, image, code); findThunks(t, image, code);
@ -9944,17 +9943,17 @@ virtualThunk(MyThread* t, unsigned index)
{ {
ACQUIRE(t, t->m->classLock); ACQUIRE(t, t->m->classLock);
GcWordArray* oldArray = cast<GcWordArray>(t, root(t, VirtualThunks)); GcWordArray* oldArray = compileRoots(t)->virtualThunks();
if (oldArray == 0 if (oldArray == 0
or oldArray->length() <= index * 2) or oldArray->length() <= index * 2)
{ {
GcWordArray* newArray = makeWordArray(t, nextPowerOfTwo((index + 1) * 2)); GcWordArray* newArray = makeWordArray(t, nextPowerOfTwo((index + 1) * 2));
if (root(t, VirtualThunks)) { if (compileRoots(t)->virtualThunks()) {
memcpy(newArray->body().begin(), memcpy(newArray->body().begin(),
oldArray->body().begin(), oldArray->body().begin(),
oldArray->length() * BytesPerWord); oldArray->length() * BytesPerWord);
} }
setRoot(t, VirtualThunks, reinterpret_cast<object>(newArray)); set(t, compileRoots(t), CompileRootsVirtualThunks, newArray);
oldArray = newArray; oldArray = newArray;
} }
@ -10044,15 +10043,15 @@ compile(MyThread* t, FixedAllocator* allocator, BootContext* bootContext,
// clone in its place. Later, we'll replace the clone with the // clone in its place. Later, we'll replace the clone with the
// original to save memory. // original to save memory.
setRoot(t, GcTreeNode* newTree = treeInsert(t,
MethodTree,
reinterpret_cast<object>(treeInsert(t,
&(context.zone), &(context.zone),
cast<GcTreeNode>(t, root(t, MethodTree)), compileRoots(t)->methodTree(),
methodCompiled(t, clone), methodCompiled(t, clone),
reinterpret_cast<object>(clone), reinterpret_cast<object>(clone),
cast<GcTreeNode>(t, root(t, MethodTreeSentinal)), compileRoots(t)->methodTreeSentinal(),
compareIpToMethodBounds))); compareIpToMethodBounds);
// sequence point, for gc (don't recombine statements)
set(t, compileRoots(t), CompileRootsMethodTree, newTree);
storeStoreMemoryBarrier(); storeStoreMemoryBarrier();
@ -10069,24 +10068,17 @@ compile(MyThread* t, FixedAllocator* allocator, BootContext* bootContext,
context.executableAllocator = 0; context.executableAllocator = 0;
treeUpdate(t, treeUpdate(t,
cast<GcTreeNode>(t, root(t, MethodTree)), compileRoots(t)->methodTree(),
methodCompiled(t, clone), methodCompiled(t, clone),
reinterpret_cast<object>(method), reinterpret_cast<object>(method),
cast<GcTreeNode>(t, root(t, MethodTreeSentinal)), compileRoots(t)->methodTreeSentinal(),
compareIpToMethodBounds); compareIpToMethodBounds);
} }
object& GcCompileRoots*
root(Thread* t, Root root) compileRoots(Thread* t)
{ {
return processor(static_cast<MyThread*>(t))->roots->body()[root]; return processor(static_cast<MyThread*>(t))->roots;
}
void
setRoot(Thread* t, Root root, object value)
{
set(t, processor(static_cast<MyThread*>(t))->roots,
ArrayBody + (root * BytesPerWord), reinterpret_cast<GcObject*>(value));
} }
avian::util::FixedAllocator* codeAllocator(MyThread* t) avian::util::FixedAllocator* codeAllocator(MyThread* t)