From 659555b6cef285097781305f0ceb111577975238 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Sat, 13 Oct 2007 19:18:25 -0600 Subject: [PATCH] fix use of uninitialized values at root thread creation time when running in stress mode; allocate Thread::defaultHeap on the heap instead of as part of the Thread structure --- src/compile.cpp | 10 ++++++---- src/machine.cpp | 11 +++++++---- src/machine.h | 16 ++++++++++------ 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/compile.cpp b/src/compile.cpp index e44440cc12..de57869f1c 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -4096,11 +4096,13 @@ class MyProcessor: public Processor { { MyThread* t = static_cast(vmt); - for (Reference* r = t->reference; r; r = r->next) { - v->visit(&(r->target)); - } + if (t->m->active) { + for (Reference* r = t->reference; r; r = r->next) { + v->visit(&(r->target)); + } - visitStack(t, v); + visitStack(t, v); + } } virtual uintptr_t diff --git a/src/machine.cpp b/src/machine.cpp index c675131a07..5efd7eb328 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -1336,6 +1336,7 @@ Machine::Machine(System* system, Heap* heap, Finder* finder, weakReferences(0), tenuredWeakReferences(0), unsafe(false), + active(false), heapPoolIndex(0) { populateJNITables(&javaVMVTable, &jniEnvVTable); @@ -1386,12 +1387,12 @@ Thread::Thread(Machine* m, object javaThread, Thread* parent): heapIndex(0), heapOffset(0), protector(0), - runnable(this) + runnable(this), + defaultHeap(static_cast(m->system->allocate(HeapSizeInBytes))), + heap(defaultHeap) #ifdef VM_STRESS - , stress(false), - defaultHeap(static_cast(m->system->allocate(HeapSizeInBytes))) + , stress(false) #endif // VM_STRESS - , heap(defaultHeap) { if (parent == 0) { assert(this, m->rootThread == 0); @@ -1399,6 +1400,7 @@ Thread::Thread(Machine* m, object javaThread, Thread* parent): m->rootThread = this; m->unsafe = true; + m->active = false; if (not m->system->success(m->system->attach(&runnable))) { abort(this); @@ -1494,6 +1496,7 @@ Thread::Thread(Machine* m, object javaThread, Thread* parent): if (parent == 0) { enter(this, Thread::IdleState); + m->active = true; } } diff --git a/src/machine.h b/src/machine.h index b9b093d15e..a545abc6dc 100644 --- a/src/machine.h +++ b/src/machine.h @@ -1098,6 +1098,12 @@ class Machine { #include "type-enums.cpp" }; + enum State { + UnsafeState, + BootState, + ActiveState + }; + Machine(System* system, Heap* heap, Finder* finder, Processor* processor); ~Machine() { @@ -1136,6 +1142,7 @@ class Machine { object weakReferences; object tenuredWeakReferences; bool unsafe; + bool active; JavaVMVTable javaVMVTable; JNIEnvVTable jniEnvVTable; uintptr_t* heapPool[HeapPoolSize]; @@ -1242,14 +1249,11 @@ class Thread { unsigned heapOffset; Protector* protector; Runnable runnable; -#ifdef VM_STRESS - bool stress; uintptr_t* defaultHeap; uintptr_t* heap; -#else // not VM_STRESS - uintptr_t* heap; - uintptr_t defaultHeap[HeapSizeInWords]; -#endif // not VM_STRESS +#ifdef VM_STRESS + bool stress; +#endif // VM_STRESS }; inline object