From e44f326377d104b8d38cb9f8ffb79bb54d340f94 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Sat, 29 Nov 2008 18:39:42 -0700 Subject: [PATCH] various bugfixes --- src/bootimage.cpp | 35 +++++++++++++++++--- src/compile.cpp | 81 +++++++++++++++++++++++------------------------ src/machine.cpp | 21 ++++++++++-- 3 files changed, 89 insertions(+), 48 deletions(-) diff --git a/src/bootimage.cpp b/src/bootimage.cpp index 85737f0922..20abcc07d4 100644 --- a/src/bootimage.cpp +++ b/src/bootimage.cpp @@ -99,6 +99,21 @@ visitRoots(Thread* t, BootImage* image, HeapWalker* w, object constants) } } +void +visitReference(Thread* t, HeapWalker* w, uintptr_t* heap, uintptr_t* map, + object r) +{ + int target = w->map()->find(jreferenceTarget(t, r)); + assert(t, target > 0); + + int reference = w->map()->find(r); + assert(t, reference > 0); + + unsigned index = reference - 1 + (JreferenceTarget / BytesPerWord); + markBit(map, index); + heap[index] = target; +} + HeapWalker* makeHeapImage(Thread* t, BootImage* image, uintptr_t* heap, uintptr_t* map, unsigned capacity, object constants) @@ -161,6 +176,14 @@ makeHeapImage(Thread* t, BootImage* image, uintptr_t* heap, uintptr_t* map, HeapWalker* w = makeHeapWalker(t, &visitor); visitRoots(t, image, w, constants); + for (object r = t->m->weakReferences; r; r = jreferenceVmNext(t, r)) { + visitReference(t, w, heap, map, r); + } + + for (object r = t->m->tenuredWeakReferences; r; r = jreferenceVmNext(t, r)) { + visitReference(t, w, heap, map, r); + } + image->heapSize = visitor.position * BytesPerWord; return w; @@ -212,6 +235,9 @@ writeBootImage(Thread* t, FILE* out) (t->m->heap->allocate(heapMapSize(HeapCapacity))); memset(heapMap, 0, heapMapSize(HeapCapacity)); + PROTECT(t, constants); + collect(t, Heap::MajorCollection); + HeapWalker* heapWalker = makeHeapImage (t, &image, heap, heapMap, HeapCapacity, constants); @@ -220,11 +246,12 @@ writeBootImage(Thread* t, FILE* out) heapWalker->dispose(); image.magic = BootImage::Magic; + image.codeBase = reinterpret_cast(code); - if (false) { - fprintf(stderr, "heap size %d code size %d\n", - image.heapSize, image.codeSize); - } else { + fprintf(stderr, "heap size %d code size %d\n", + image.heapSize, image.codeSize); + + if (true) { fwrite(&image, sizeof(BootImage), 1, out); fwrite(heapMap, pad(heapMapSize(image.heapSize)), 1, out); diff --git a/src/compile.cpp b/src/compile.cpp index 9088f5c25c..02ae365d45 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1482,10 +1482,46 @@ makeBlankObjectArray(MyThread* t, object class_, int32_t length) } object FORCE_ALIGN -makeBlankArray(MyThread* t, object (*constructor)(Thread*, uintptr_t, bool), - int32_t length) +makeBlankArray(MyThread* t, unsigned type, int32_t length) { if (length >= 0) { + object (*constructor)(Thread*, uintptr_t, bool); + switch (type) { + case T_BOOLEAN: + constructor = makeBooleanArray; + break; + + case T_CHAR: + constructor = makeCharArray; + break; + + case T_FLOAT: + constructor = makeFloatArray; + break; + + case T_DOUBLE: + constructor = makeDoubleArray; + break; + + case T_BYTE: + constructor = makeByteArray; + break; + + case T_SHORT: + constructor = makeShortArray; + break; + + case T_INT: + constructor = makeIntArray; + break; + + case T_LONG: + constructor = makeLongArray; + break; + + default: abort(t); + } + return constructor(t, length, true); } else { object message = makeString(t, "%d", length); @@ -3272,51 +3308,13 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, Compiler::Operand* length = frame->popInt(); - object (*constructor)(Thread*, uintptr_t, bool); - switch (type) { - case T_BOOLEAN: - constructor = makeBooleanArray; - break; - - case T_CHAR: - constructor = makeCharArray; - break; - - case T_FLOAT: - constructor = makeFloatArray; - break; - - case T_DOUBLE: - constructor = makeDoubleArray; - break; - - case T_BYTE: - constructor = makeByteArray; - break; - - case T_SHORT: - constructor = makeShortArray; - break; - - case T_INT: - constructor = makeIntArray; - break; - - case T_LONG: - constructor = makeLongArray; - break; - - default: abort(t); - } - frame->pushObject (c->call (c->constant(getThunk(t, makeBlankArrayThunk)), 0, frame->trace(0, false), BytesPerWord, - 3, c->thread(), c->constant(reinterpret_cast(constructor)), - length)); + 3, c->thread(), c->constant(type), length)); } break; case nop: break; @@ -4693,6 +4691,7 @@ fixupCallTable(MyThread* t, object oldTable, uintptr_t oldBase, next = callNodeNext(t, p); intptr_t k = (callNodeAddress(t, p) - oldBase) + newBase; + callNodeAddress(t, p) = k; unsigned index = k & (arrayLength(t, newTable) - 1); diff --git a/src/machine.cpp b/src/machine.cpp index 9c75036e97..f57e070b33 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -1560,14 +1560,29 @@ boot(Thread* t, BootImage* image) if (classMethodTable(t, c)) { for (unsigned i = 0; i < arrayLength(t, classMethodTable(t, c)); ++i) { object method = arrayBody(t, classMethodTable(t, c), i); - methodCompiled(t, method) - = (methodCompiled(t, method) - image->codeBase) - + reinterpret_cast(code); + if (methodCode(t, method)) { + assert(t, (methodCompiled(t, method) - image->codeBase) + <= image->codeSize); + + methodCompiled(t, method) + = (methodCompiled(t, method) - image->codeBase) + + reinterpret_cast(code); + +// fprintf(stderr, "%p %p %s.%s%s\n", +// reinterpret_cast(methodCompiled(t, method)), +// reinterpret_cast(methodCompiled(t, method)) + +// reinterpret_cast(methodCompiled(t, method))[-1], +// &byteArrayBody(t, className(t, methodClass(t, method)), 0), +// &byteArrayBody(t, methodName(t, method), 0), +// &byteArrayBody(t, methodSpec(t, method), 0)); + } } } t->m->processor->initVtable(t, c); } + + t->m->bootstrapClassMap = makeHashMap(t, 0, 0); } void