various bugfixes

This commit is contained in:
Joel Dice 2008-11-29 18:39:42 -07:00
parent 0ec5ad3701
commit e44f326377
3 changed files with 89 additions and 48 deletions

View File

@ -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<uintptr_t>(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);

View File

@ -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<intptr_t>(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);

View File

@ -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<uintptr_t>(code);
if (methodCode(t, method)) {
assert(t, (methodCompiled(t, method) - image->codeBase)
<= image->codeSize);
methodCompiled(t, method)
= (methodCompiled(t, method) - image->codeBase)
+ reinterpret_cast<uintptr_t>(code);
// fprintf(stderr, "%p %p %s.%s%s\n",
// reinterpret_cast<uint8_t*>(methodCompiled(t, method)),
// reinterpret_cast<uint8_t*>(methodCompiled(t, method)) +
// reinterpret_cast<uintptr_t*>(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