add Machine::heapPool, allowing threads to acquire replacement heaps up to a point before forcing a GC

This commit is contained in:
Joel Dice 2007-08-22 08:50:29 -06:00
parent 27c8511c5e
commit f148fd0668
2 changed files with 35 additions and 11 deletions

View File

@ -132,8 +132,6 @@ void
visitRoots(Thread* t, Heap::Visitor* v) visitRoots(Thread* t, Heap::Visitor* v)
{ {
if (t->state != Thread::ZombieState) { if (t->state != Thread::ZombieState) {
t->heapIndex = 0;
v->visit(&(t->javaThread)); v->visit(&(t->javaThread));
v->visit(&(t->code)); v->visit(&(t->code));
v->visit(&(t->exception)); v->visit(&(t->exception));
@ -362,11 +360,14 @@ void
postCollect(Thread* t) postCollect(Thread* t)
{ {
#ifdef VM_STRESS #ifdef VM_STRESS
t->vm->system->free(t->heap); t->vm->system->free(t->defaultHeap);
t->heap = static_cast<object*> t->defaultHeap = static_cast<object*>
(t->vm->system->allocate(Thread::HeapSizeInBytes)); (t->vm->system->allocate(Thread::HeapSizeInBytes));
#endif #endif
t->heap = t->defaultHeap;
t->heapIndex = 0;
if (t->large) { if (t->large) {
t->vm->system->free(t->large); t->vm->system->free(t->large);
t->large = 0; t->large = 0;
@ -1289,7 +1290,8 @@ Machine::Machine(System* system, Heap* heap, Finder* finder):
finalizeQueue(0), finalizeQueue(0),
weakReferences(0), weakReferences(0),
tenuredWeakReferences(0), tenuredWeakReferences(0),
unsafe(false) unsafe(false),
heapPoolIndex(0)
{ {
populateJNITable(&jniEnvVTable); populateJNITable(&jniEnvVTable);
@ -1335,8 +1337,9 @@ Thread::Thread(Machine* m, object javaThread, Thread* parent):
runnable(this) runnable(this)
#ifdef VM_STRESS #ifdef VM_STRESS
, stress(false), , stress(false),
heap(static_cast<object*>(m->system->allocate(HeapSizeInBytes))) defaultHeap(static_cast<object*>(m->system->allocate(HeapSizeInBytes)))
#endif // VM_STRESS #endif // VM_STRESS
, heap(defaultHeap)
{ {
if (parent == 0) { if (parent == 0) {
assert(this, m->rootThread == 0); assert(this, m->rootThread == 0);
@ -1613,8 +1616,19 @@ allocate2(Thread* t, unsigned sizeInBytes)
if (t->heapIndex + ceiling(sizeInBytes, BytesPerWord) if (t->heapIndex + ceiling(sizeInBytes, BytesPerWord)
>= Thread::HeapSizeInWords) >= Thread::HeapSizeInWords)
{ {
ENTER(t, Thread::ExclusiveState); t->heap = 0;
collect(t, Heap::MinorCollection); if (t->vm->heapPoolIndex < Machine::HeapPoolSize) {
t->heap = static_cast<object*>
(t->vm->system->tryAllocate(Thread::HeapSizeInBytes));
if (t->heap) {
t->vm->heapPool[t->vm->heapPoolIndex++] = t->heap;
}
}
if (t->heap == 0) {
ENTER(t, Thread::ExclusiveState);
collect(t, Heap::MinorCollection);
}
} }
if (sizeInBytes > Thread::HeapSizeInBytes) { if (sizeInBytes > Thread::HeapSizeInBytes) {
@ -2535,6 +2549,11 @@ collect(Thread* t, Heap::CollectionType type)
m->finalizeQueue = 0; m->finalizeQueue = 0;
killZombies(t, m->rootThread); killZombies(t, m->rootThread);
for (unsigned i = 0; i < m->heapPoolIndex; ++i) {
m->system->free(m->heapPool[i]);
}
m->heapPoolIndex = 0;
} }
void void

View File

@ -1098,6 +1098,8 @@ class Machine {
dispose(); dispose();
} }
static const unsigned HeapPoolSize = 16;
void dispose(); void dispose();
System* system; System* system;
@ -1125,6 +1127,8 @@ class Machine {
object tenuredWeakReferences; object tenuredWeakReferences;
bool unsafe; bool unsafe;
JNIEnvVTable jniEnvVTable; JNIEnvVTable jniEnvVTable;
object* heapPool[HeapPoolSize];
unsigned heapPoolIndex;
}; };
object object
@ -1193,7 +1197,7 @@ class Thread {
Thread* t; Thread* t;
}; };
static const unsigned HeapSizeInBytes = 512 * 1024; static const unsigned HeapSizeInBytes = 64 * 1024;
static const unsigned StackSizeInBytes = 64 * 1024; static const unsigned StackSizeInBytes = 64 * 1024;
static const unsigned HeapSizeInWords = HeapSizeInBytes / BytesPerWord; static const unsigned HeapSizeInWords = HeapSizeInBytes / BytesPerWord;
@ -1221,11 +1225,12 @@ class Thread {
unsigned heapIndex; unsigned heapIndex;
Protector* protector; Protector* protector;
Runnable runnable; Runnable runnable;
object* heap;
#ifdef VM_STRESS #ifdef VM_STRESS
bool stress; bool stress;
object* heap; object* defaultHeap;
#else // not VM_STRESS #else // not VM_STRESS
object heap[HeapSizeInWords]; object defaultHeap[HeapSizeInWords];
#endif // not VM_STRESS #endif // not VM_STRESS
uintptr_t stack[StackSizeInWords]; uintptr_t stack[StackSizeInWords];
}; };