various bugfixes concerning Thread.getStackTrace

This commit is contained in:
Joel Dice 2008-04-21 16:36:13 -06:00
parent 864e079aca
commit df5258d1d8
6 changed files with 38 additions and 11 deletions

View File

@ -53,6 +53,7 @@ enumerateThreads(Thread* t, Thread* x, object array, unsigned* index,
{ {
if (*index < limit) { if (*index < limit) {
set(t, array, ArrayBody + (*index * BytesPerWord), x->javaThread); set(t, array, ArrayBody + (*index * BytesPerWord), x->javaThread);
++ (*index);
if (x->peer) enumerateThreads(t, x->peer, array, index, limit); if (x->peer) enumerateThreads(t, x->peer, array, index, limit);
@ -711,7 +712,7 @@ Java_java_lang_Thread_interrupt(Thread* t, jclass, jlong peer)
} }
extern "C" JNIEXPORT jobject JNICALL extern "C" JNIEXPORT jobject JNICALL
Java_java_lang_Thread_getTrace(Thread* t, jclass, jlong peer) Java_java_lang_Thread_getStackTrace(Thread* t, jclass, jlong peer)
{ {
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);

View File

@ -172,7 +172,7 @@ class MyStackWalker: public Processor::StackWalker {
base(t->base), base(t->base),
stack(t->stack), stack(t->stack),
trace(t->trace), trace(t->trace),
nativeMethod(trace->nativeMethod), nativeMethod(trace ? trace->nativeMethod : 0),
method_(ip_ ? methodForIp(t, ip_) : 0), method_(ip_ ? methodForIp(t, ip_) : 0),
protector(this) protector(this)
{ } { }
@ -208,7 +208,7 @@ class MyStackWalker: public Processor::StackWalker {
bool next() { bool next() {
if (nativeMethod) { if (nativeMethod) {
nativeMethod = 0; nativeMethod = 0;
} else { } else if (stack) {
stack = static_cast<void**>(base) + 1; stack = static_cast<void**>(base) + 1;
base = *static_cast<void**>(base); base = *static_cast<void**>(base);
ip_ = *static_cast<void**>(stack); ip_ = *static_cast<void**>(stack);
@ -225,6 +225,8 @@ class MyStackWalker: public Processor::StackWalker {
return false; return false;
} }
} }
} else {
return false;
} }
return true; return true;
} }
@ -4639,16 +4641,15 @@ traceSize(Thread* t)
{ {
class Counter: public Processor::StackVisitor { class Counter: public Processor::StackVisitor {
public: public:
Counter(Thread* t): t(t), count(0) { } Counter(): count(0) { }
virtual bool visit(Processor::StackWalker*) { virtual bool visit(Processor::StackWalker*) {
++ count; ++ count;
return true; return true;
} }
Thread* t;
unsigned count; unsigned count;
} counter(t); } counter;
t->m->processor->walkStack(t, &counter); t->m->processor->walkStack(t, &counter);
@ -4673,7 +4674,9 @@ class SegFaultHandler: public System::SignalHandler {
ensure(t, FixedSizeOfNullPointerException + traceSize(t)); ensure(t, FixedSizeOfNullPointerException + traceSize(t));
t->tracing = true;
t->exception = makeNullPointerException(t); t->exception = makeNullPointerException(t);
t->tracing = false;
findUnwindTarget(t, ip, base, stack); findUnwindTarget(t, ip, base, stack);
*thread = t; *thread = t;
@ -5002,10 +5005,10 @@ class MyProcessor: public Processor {
Visitor(MyThread* t, MyThread* target): t(t), target(target) { } Visitor(MyThread* t, MyThread* target): t(t), target(target) { }
virtual void visit(void* ip, void* base, void* stack) { virtual void visit(void* ip, void* base, void* stack) {
ensure(t, traceSize(t)); ensure(t, traceSize(target));
void* oldIp = target->ip; void* oldIp = target->ip;
void* oldBase = target->ip; void* oldBase = target->base;
void* oldStack = target->stack; void* oldStack = target->stack;
if (methodForIp(t, ip)) { if (methodForIp(t, ip)) {
@ -5014,7 +5017,9 @@ class MyProcessor: public Processor {
target->stack = stack; target->stack = stack;
} }
t->tracing = true;
trace = makeTrace(t, target); trace = makeTrace(t, target);
t->tracing = false;
target->ip = oldIp; target->ip = oldIp;
target->base = oldBase; target->base = oldBase;
@ -5026,6 +5031,8 @@ class MyProcessor: public Processor {
object trace; object trace;
} visitor(t, target); } visitor(t, target);
t->m->system->visit(t->systemThread, target->systemThread, &visitor);
if (t->backupHeap) { if (t->backupHeap) {
PROTECT(t, visitor.trace); PROTECT(t, visitor.trace);

View File

@ -490,6 +490,7 @@ postCollect(Thread* t)
if (t->backupHeap) { if (t->backupHeap) {
t->m->heap->free t->m->heap->free
(t->backupHeap, t->backupHeapSizeInWords * BytesPerWord); (t->backupHeap, t->backupHeapSizeInWords * BytesPerWord);
t->backupHeap = 0;
t->backupHeapIndex = 0; t->backupHeapIndex = 0;
t->backupHeapSizeInWords = 0; t->backupHeapSizeInWords = 0;
} }
@ -1735,7 +1736,8 @@ Thread::Thread(Machine* m, object javaThread, Thread* parent):
heap(defaultHeap), heap(defaultHeap),
backupHeap(0), backupHeap(0),
backupHeapIndex(0), backupHeapIndex(0),
backupHeapSizeInWords(0) backupHeapSizeInWords(0),
tracing(false)
#ifdef VM_STRESS #ifdef VM_STRESS
, stress(false) , stress(false)
#endif // VM_STRESS #endif // VM_STRESS
@ -2046,6 +2048,10 @@ allocate3(Thread* t, Allocator* allocator, Machine::AllocationType type,
t->backupHeapIndex += ceiling(sizeInBytes, BytesPerWord); t->backupHeapIndex += ceiling(sizeInBytes, BytesPerWord);
cast<object>(o, 0) = 0; cast<object>(o, 0) = 0;
return o; return o;
} else if (t->tracing) {
expect(t, t->heapIndex + ceiling(sizeInBytes, BytesPerWord)
<= Thread::HeapSizeInWords);
return allocateSmall(t, sizeInBytes);
} }
ACQUIRE_RAW(t, t->m->stateLock); ACQUIRE_RAW(t, t->m->stateLock);

View File

@ -1291,6 +1291,7 @@ class Thread {
uintptr_t* backupHeap; uintptr_t* backupHeap;
unsigned backupHeapIndex; unsigned backupHeapIndex;
unsigned backupHeapSizeInWords; unsigned backupHeapSizeInWords;
bool tracing;
#ifdef VM_STRESS #ifdef VM_STRESS
bool stress; bool stress;
#endif // VM_STRESS #endif // VM_STRESS

View File

@ -793,6 +793,8 @@ handleSignal(int signal, siginfo_t* info, void* context)
System::Thread* t = system->visitTarget; System::Thread* t = system->visitTarget;
system->visitTarget = 0; system->visitTarget = 0;
ACQUIRE_MONITOR(t, system->visitLock);
system->visitLock->notifyAll(t); system->visitLock->notifyAll(t);
} break; } break;
@ -830,7 +832,13 @@ handleSignal(int signal, siginfo_t* info, void* context)
} else if (system->oldHandlers[index].sa_handler) { } else if (system->oldHandlers[index].sa_handler) {
system->oldHandlers[index].sa_handler(signal); system->oldHandlers[index].sa_handler(signal);
} else { } else {
abort(); switch (signal) {
case VisitSignal:
break;
default:
abort();
}
} }
} }

View File

@ -223,7 +223,11 @@ findLineNumber(Thread* t, object method, unsigned ip)
} }
} }
abort(t); if (top < lineNumberTableLength(t, lnt)) {
return lineNumberLine(lineNumberTableBody(t, lnt, top));
} else {
return UnknownLine;
}
} else { } else {
return UnknownLine; return UnknownLine;
} }