more GC stress fixes

This commit is contained in:
Joel Dice 2007-07-17 19:33:00 -06:00
parent b848c09a34
commit 65c876b5f7
3 changed files with 40 additions and 8 deletions

View File

@ -187,7 +187,9 @@ class Segment {
assert(segment->context, capacity >= segment->capacity()); assert(segment->context, capacity >= segment->capacity());
uintptr_t* p = newData + offset(capacity); uintptr_t* p = newData + offset(capacity);
if (segment->position()) {
memcpy(p, data(), size(segment->position()) * BytesPerWord); memcpy(p, data(), size(segment->position()) * BytesPerWord);
}
if (child) { if (child) {
child->update(newData, capacity); child->update(newData, capacity);
@ -485,9 +487,18 @@ class Segment {
void ensure(unsigned minimum) { void ensure(unsigned minimum) {
if (remaining() < minimum) { if (remaining() < minimum) {
assert(context, rear->position);
assert(context, rear->next == 0); assert(context, rear->next == 0);
if (rear->position == 0) {
Chain* c = rear;
if (front == rear) {
front = rear = 0;
} else {
rear = rear->previous;
}
Chain::dispose(c);
}
unsigned desired = capacity() + minimum; unsigned desired = capacity() + minimum;
Chain* c = Chain::make(this, minimum, desired); Chain* c = Chain::make(this, minimum, desired);
@ -501,8 +512,12 @@ class Segment {
map->update(c->data() + c->capacity, c->offset + c->capacity); map->update(c->data() + c->capacity, c->offset + c->capacity);
} }
if (rear) {
rear->next = c; rear->next = c;
rear = c; rear = c;
} else {
front = rear = c;
}
} }
} }

View File

@ -27,6 +27,7 @@ join(Thread* t, Thread* o)
{ {
if (t != o) { if (t != o) {
o->systemThread->join(); o->systemThread->join();
o->state = Thread::JoinedState;
} }
} }
@ -97,9 +98,15 @@ killZombies(Thread* t, Thread* o)
killZombies(t, child); killZombies(t, child);
} }
if (o->state == Thread::ZombieState) { switch (o->state) {
case Thread::ZombieState:
join(t, o); join(t, o);
// fall through
case Thread::JoinedState:
dispose(t, o, true); dispose(t, o, true);
default: break;
} }
} }
@ -1386,12 +1393,16 @@ enter(Thread* t, Thread::State s)
if (s == t->state) return; if (s == t->state) return;
if (t->state == Thread::ExitState) {
// once in exit state, we stay that way
return;
}
ACQUIRE_RAW(t, t->vm->stateLock); ACQUIRE_RAW(t, t->vm->stateLock);
switch (s) { switch (s) {
case Thread::ExclusiveState: { case Thread::ExclusiveState: {
assert(t, t->state == Thread::ActiveState assert(t, t->state == Thread::ActiveState);
or t->state == Thread::ExitState);
while (t->vm->exclusive) { while (t->vm->exclusive) {
// another thread got here first. // another thread got here first.
@ -1419,8 +1430,11 @@ enter(Thread* t, Thread::State s)
default: abort(t); default: abort(t);
} }
assert(t, t->vm->activeCount > 0);
-- t->vm->activeCount; -- t->vm->activeCount;
if (s == Thread::ZombieState) { if (s == Thread::ZombieState) {
assert(t, t->vm->liveCount > 0);
-- t->vm->liveCount; -- t->vm->liveCount;
} }
t->state = s; t->state = s;
@ -1468,7 +1482,9 @@ enter(Thread* t, Thread::State s)
default: abort(t); default: abort(t);
} }
assert(t, t->vm->activeCount > 0);
-- t->vm->activeCount; -- t->vm->activeCount;
t->state = s; t->state = s;
while (t->vm->liveCount > 1) { while (t->vm->liveCount > 1) {

View File

@ -1131,6 +1131,7 @@ class Thread {
ActiveState, ActiveState,
IdleState, IdleState,
ZombieState, ZombieState,
JoinedState,
ExclusiveState, ExclusiveState,
ExitState ExitState
}; };