From e4fbadd0518d4a4656af6f4886368b2ab42db7bb Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Sun, 16 Dec 2007 15:41:07 -0700 Subject: [PATCH] JIT-related GC safety fixes --- makefile | 6 +++--- src/compile.cpp | 26 ++++++++++++++++++++------ src/heap.cpp | 6 +++--- src/machine.cpp | 9 +++++++++ 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/makefile b/makefile index 241f607fd5..9754eb923e 100644 --- a/makefile +++ b/makefile @@ -28,7 +28,7 @@ src = src classpath = classpath test = test -input = $(test-build)/Exceptions.class +input = $(test-build)/GC.class build-cxx = g++ build-cc = gcc @@ -109,10 +109,10 @@ ifeq ($(mode),debug) cflags += -O0 -g3 endif ifeq ($(mode),stress) - cflags += -O0 -g3 -DNDEBUG -DVM_STRESS + cflags += -O0 -g3 -DVM_STRESS endif ifeq ($(mode),stress-major) - cflags += -O0 -g3 -DNDEBUG -DVM_STRESS -DVM_STRESS_MAJOR + cflags += -O0 -g3 -DVM_STRESS -DVM_STRESS_MAJOR endif ifeq ($(mode),fast) cflags += -O3 -g3 -DNDEBUG diff --git a/src/compile.cpp b/src/compile.cpp index 23f0c64e64..f25651c16d 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -2914,6 +2914,7 @@ finish(MyThread* t, Compiler* c, object method, Vector* objectPool, if (method) { PROTECT(t, method); + PROTECT(t, result); for (unsigned i = 0; i < objectPool->length(); i += sizeof(PoolElement)) { PoolElement* e = objectPool->peek(i); @@ -3076,17 +3077,20 @@ void compile(MyThread* t, object method); void* -compileMethod(MyThread* t) +compileMethod2(MyThread* t) { object node = findTraceNode(t, *static_cast(t->stack)); + PROTECT(t, node); + object target = resolveTarget(t, t->stack, traceNodeTarget(t, node)); + PROTECT(t, target); if (LIKELY(t->exception == 0)) { compile(t, target); } if (UNLIKELY(t->exception)) { - unwind(t); + return 0; } else { if (not traceNodeVirtualCall(t, node)) { Compiler* c = makeCompiler(t->m->system, 0); @@ -3098,6 +3102,18 @@ compileMethod(MyThread* t) } } +void* +compileMethod(MyThread* t) +{ + void* r = compileMethod2(t); + + if (UNLIKELY(t->exception)) { + unwind(t); + } else { + return r; + } +} + uint64_t invokeNative2(MyThread* t, object method) { @@ -3302,7 +3318,7 @@ visitStack(MyThread* t, Heap::Visitor* v) void** stack = static_cast(t->stack); MyThread::CallTrace* trace = t->trace; - while (true) { + while (stack) { object node = findTraceNode(t, *stack); if (node) { PROTECT(t, node); @@ -3316,7 +3332,7 @@ visitStack(MyThread* t, Heap::Visitor* v) visitParameters(t, v, base, method); } - visitStackAndLocals(t, v, base, method); + visitStackAndLocals(t, v, base, node); stack = static_cast(base) + 1; base = *static_cast(base); @@ -3838,8 +3854,6 @@ compile(MyThread* t, object method) ACQUIRE(t, t->m->classLock); if (methodCompiled(t, method) == p->getDefaultCompiled(t)) { - PROTECT(t, method); - Compiler* c = makeCompiler(t->m->system, p->indirectCaller); object compiled = compile(t, c, method); diff --git a/src/heap.cpp b/src/heap.cpp index 4c9921e40b..12eeb91617 100644 --- a/src/heap.cpp +++ b/src/heap.cpp @@ -332,7 +332,7 @@ class Segment { } void replaceWith(Segment* s) { - system(context)->free(data); + if (data) system(context)->free(data); data = s->data; s->data = 0; @@ -350,7 +350,7 @@ class Segment { abort(context); } } else { - map = 0; + assert(context, map == 0); } } @@ -467,7 +467,7 @@ class Context { ageMap(&gen1, max(1, log(TenureThreshold)), 1, 0, false), gen1(this, &ageMap, 0, 0), - nextAgeMap(&nextGen1, max(1, log(TenureThreshold)), 1, 0, false), + nextAgeMap(&nextGen1, max(1, log(TenureThreshold)), 1, 0, false), nextGen1(this, &nextAgeMap, 0, 0), pointerMap(&gen2, 1, 1, 0, true), diff --git a/src/machine.cpp b/src/machine.cpp index de06be8065..728da1fe83 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -2777,6 +2777,11 @@ intern(Thread* t, object s) void collect(Thread* t, Heap::CollectionType type) { +#ifdef VM_STRESS + bool stress = t->stress; + if (not stress) t->stress = true; +#endif + Machine* m = t->m; m->unsafe = true; @@ -2800,6 +2805,10 @@ collect(Thread* t, Heap::CollectionType type) m->heapPoolIndex = 0; m->fixedFootprint = 0; + +#ifdef VM_STRESS + if (not stress) t->stress = false; +#endif } void