From 2cf62a5926dbd5d3e405652635342b68d33acb13 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Thu, 10 Apr 2008 17:48:28 -0600 Subject: [PATCH] various bugfixes in new stack trace code --- src/compile.cpp | 55 ++++++++++++++++++++++++++++++++++++++----------- src/process.h | 6 ++---- src/util.cpp | 11 +++++++--- src/util.h | 2 +- 4 files changed, 54 insertions(+), 20 deletions(-) diff --git a/src/compile.cpp b/src/compile.cpp index e48f47404e..ae27261c7e 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -26,9 +26,10 @@ vmCall(); namespace { -const bool Verbose = false; +const bool Verbose = true; const bool DebugNatives = false; const bool DebugCallTable = false; +const bool DebugMethodTree = true; const bool DebugFrameMaps = false; const bool CheckArrayBounds = true; @@ -119,9 +120,18 @@ compareIpToMethodBounds(Thread* t, intptr_t ip, object method) { intptr_t start = reinterpret_cast (&singletonValue(t, methodCompiled(t, method), 0)); + + if (DebugMethodTree) { + fprintf(stderr, "find 0x%lx in (0x%lx,0x%lx)\n", ip, start, + start + (singletonCount(t, methodCompiled(t, method)) + * BytesPerWord)); + } + if (ip < start) { return -1; - } else if (ip < start + singletonCount(t, methodCompiled(t, method))) { + } else if (ip < start + (singletonCount(t, methodCompiled(t, method)) + * BytesPerWord)) + { return 0; } else { return 1; @@ -131,6 +141,10 @@ compareIpToMethodBounds(Thread* t, intptr_t ip, object method) object methodForIp(MyThread* t, void* ip) { + if (DebugMethodTree) { + fprintf(stderr, "query for method containing %p\n", ip); + } + return treeQuery(t, methodTree(t), reinterpret_cast(ip), methodTreeSentinal(t), compareIpToMethodBounds); } @@ -153,7 +167,7 @@ class MyStackWalker: public Processor::StackWalker { MyStackWalker(MyThread* t): t(t), - ip_(t->ip ? t->ip : (stack ? *static_cast(stack) : 0)), + ip_(t->ip ? t->ip : (t->stack ? *static_cast(t->stack) : 0)), base(t->base), stack(t->stack), trace(t->trace), @@ -164,6 +178,7 @@ class MyStackWalker: public Processor::StackWalker { MyStackWalker(MyStackWalker* w): t(w->t), + ip_(w->ip_), base(w->base), stack(w->stack), trace(w->trace), @@ -173,6 +188,8 @@ class MyStackWalker: public Processor::StackWalker { { } virtual void walk(Processor::StackVisitor* v) { + fprintf(stderr, "ip: %p stack: %p method: %p\n", ip_, stack, method_); + if (stack == 0) { return; } @@ -3714,6 +3731,12 @@ compareTraceElementPointers(const void* va, const void* vb) intptr_t compareMethodBounds(Thread* t, object a, object b) { + if (DebugMethodTree) { + fprintf(stderr, "compare %p to %p\n", + &singletonValue(t, methodCompiled(t, a), 0), + &singletonValue(t, methodCompiled(t, b), 0)); + } + return reinterpret_cast (&singletonValue(t, methodCompiled(t, a), 0)) - reinterpret_cast @@ -3813,13 +3836,6 @@ finish(MyThread* t, Context* context, const char* name) updateLineNumberTable(t, c, methodCode(t, context->method), reinterpret_cast(start)); - { object node = makeTreeNode - (t, context->method, methodTreeSentinal(t), methodTreeSentinal(t)); - - methodTree(t) = treeInsert - (t, methodTree(t), node, methodTreeSentinal(t), compareMethodBounds); - } - if (Verbose) { logCompile (start, c->codeSize(), @@ -3836,11 +3852,11 @@ finish(MyThread* t, Context* context, const char* name) strcmp (reinterpret_cast (&byteArrayBody(t, className(t, methodClass(t, context->method)), 0)), - "Misc") == 0 and + "java/lang/System") == 0 and strcmp (reinterpret_cast (&byteArrayBody(t, methodName(t, context->method), 0)), - "main") == 0) + "getProperty") == 0) { asm("int3"); } @@ -4223,12 +4239,15 @@ invokeNative(MyThread* t) result = invokeNative2(t, t->trace->nativeMethod); } + t->trace->nativeMethod = 0; + if (UNLIKELY(t->exception)) { unwind(t); } else { return result; } } + unsigned frameMapIndex(MyThread* t, object method, int32_t offset) { @@ -5001,6 +5020,7 @@ compile(MyThread* t, object method) } else { Context context(t, method, p->indirectCaller); compiled = compile(t, &context); + if (UNLIKELY(t->exception)) return; } set(t, method, MethodCompiled, compiled); @@ -5009,6 +5029,17 @@ compile(MyThread* t, object method) classVtable(t, methodClass(t, method), methodOffset(t, method)) = &singletonValue(t, compiled, 0); } + + if ((methodFlags(t, method) & ACC_NATIVE) == 0) { + if (DebugMethodTree) { + fprintf(stderr, "insert method at %p\n", + &singletonValue(t, methodCompiled(t, method), 0)); + } + + methodTree(t) = treeInsert + (t, methodTree(t), method, methodTreeSentinal(t), + compareMethodBounds); + } } } } diff --git a/src/process.h b/src/process.h index 46ff7d585d..8bf372d095 100644 --- a/src/process.h +++ b/src/process.h @@ -40,8 +40,7 @@ inline object resolveClassInObject(Thread* t, object container, unsigned classOffset) { object o = cast(container, classOffset); - if (objectClass(t, o) == arrayBody(t, t->m->types, Machine::ByteArrayType)) - { + if (objectClass(t, o) == arrayBody(t, t->m->types, Machine::ByteArrayType)) { PROTECT(t, container); o = resolveClass(t, o); @@ -56,8 +55,7 @@ inline object resolveClassInPool(Thread* t, object pool, unsigned index) { object o = singletonObject(t, pool, index); - if (objectClass(t, o) == arrayBody(t, t->m->types, Machine::ByteArrayType)) - { + if (objectClass(t, o) == arrayBody(t, t->m->types, Machine::ByteArrayType)) { PROTECT(t, pool); o = resolveClass(t, o); diff --git a/src/util.cpp b/src/util.cpp index 4b6db26fd0..7f7325f463 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -77,7 +77,7 @@ treeFind(Thread* t, object old, object node, object sentinal, ancestors = makePair(t, new_, ancestors); intptr_t difference = compare - (t, getTreeNodeValue(t, node), getTreeNodeValue(t, node)); + (t, getTreeNodeValue(t, node), getTreeNodeValue(t, old)); if (difference < 0) { old = treeNodeLeft(t, old); @@ -522,7 +522,7 @@ treeQuery(Thread* t, object tree, intptr_t key, object sentinal, } else if (difference > 0) { node = treeNodeRight(t, node); } else { - return node; + return getTreeNodeValue(t, node); } } @@ -530,9 +530,14 @@ treeQuery(Thread* t, object tree, intptr_t key, object sentinal, } object -treeInsert(Thread* t, object tree, object node, object sentinal, +treeInsert(Thread* t, object tree, object value, object sentinal, intptr_t (*compare)(Thread* t, object a, object b)) { + PROTECT(t, tree); + PROTECT(t, sentinal); + + object node = makeTreeNode(t, value, sentinal, sentinal); + object path = treeFind(t, tree, node, sentinal, compare); if (treePathFresh(t, path)) { return treeAdd(t, path); diff --git a/src/util.h b/src/util.h index 12ad95e0f6..ce0f81a63b 100644 --- a/src/util.h +++ b/src/util.h @@ -88,7 +88,7 @@ treeQuery(Thread* t, object tree, intptr_t key, object sentinal, intptr_t (*compare)(Thread* t, intptr_t key, object b)); object -treeInsert(Thread* t, object tree, object node, object sentinal, +treeInsert(Thread* t, object tree, object value, object sentinal, intptr_t (*compare)(Thread* t, object a, object b)); } // vm