From: Pavel Afremov Date: Wed, 27 Sep 2006 13:54:50 +0400 Subject: [DRLVM][JVMTI] The incorrect line numbers in the stack trace. In the stack ip value is return pointer, but not pointer to the current instruction. Exception is pointer to the last frame where ip is pointer to the current instruction. Fix consist in find line number for previous byte code, except line number for last frame. --- vm/vmcore/include/stack_trace.h | 2 +- vm/vmcore/src/jvmti/jvmti_stack.cpp | 8 ++++++++ .../native/org_apache_harmony_vm_VMStack.cpp | 4 ++-- vm/vmcore/src/stack/stack_dump.cpp | 8 ++++---- vm/vmcore/src/stack/stack_trace.cpp | 8 ++++++-- 5 files changed, 21 insertions(+), 9 deletions(-) mode change 100644 => 100755 vm/vmcore/include/stack_trace.h mode change 100644 => 100755 vm/vmcore/src/jvmti/jvmti_stack.cpp mode change 100644 => 100755 vm/vmcore/src/kernel_classes/native/org_apache_harmony_vm_VMStack.cpp mode change 100644 => 100755 vm/vmcore/src/stack/stack_dump.cpp mode change 100644 => 100755 vm/vmcore/src/stack/stack_trace.cpp 88344e440479fd9ca6e3b34a17208037bf4102c9 diff --git a/vm/vmcore/include/stack_trace.h b/vm/vmcore/include/stack_trace.h old mode 100644 new mode 100755 index cc984f9..8ce7727 --- a/vm/vmcore/include/stack_trace.h +++ b/vm/vmcore/include/stack_trace.h @@ -136,7 +136,7 @@ VMEXPORT void st_get_trace(VM_thread *p_ * @param[out] file - the pointer to the file reference to be filled by this function * @param[out] line - the pointer to the line number to be filled by this function */ -VMEXPORT void get_file_and_line(Method_Handle method, void *ip, const char **file, int *line); +VMEXPORT void get_file_and_line(Method_Handle method, void *ip, bool is_ip_past, const char **file, int *line); #ifdef __cplusplus } diff --git a/vm/vmcore/src/jvmti/jvmti_stack.cpp b/vm/vmcore/src/jvmti/jvmti_stack.cpp old mode 100644 new mode 100755 index 4d7b26b..558992b --- a/vm/vmcore/src/jvmti/jvmti_stack.cpp +++ b/vm/vmcore/src/jvmti/jvmti_stack.cpp @@ -217,6 +217,10 @@ jvmtiGetStackTrace(jvmtiEnv* env, jit->get_bc_location_for_native( inlined_method, ip, &bc); assert(result == EXE_ERROR_NONE); + + if (0 < stack_depth - iii) { + bc--; + } frame_buffer[count].location = bc; frame_buffer[count].method = reinterpret_cast(method); @@ -232,6 +236,10 @@ jvmtiGetStackTrace(jvmtiEnv* env, jit->get_bc_location_for_native( method, ip, &bc); assert(result == EXE_ERROR_NONE); + + if (0 < stack_depth - inlined_depth) { + bc--; + } frame_buffer[count].location = bc; } } diff --git a/vm/vmcore/src/kernel_classes/native/org_apache_harmony_vm_VMStack.cpp b/vm/vmcore/src/kernel_classes/native/org_apache_harmony_vm_VMStack.cpp old mode 100644 new mode 100755 index b5538a2..99d4243 --- a/vm/vmcore/src/kernel_classes/native/org_apache_harmony_vm_VMStack.cpp +++ b/vm/vmcore/src/kernel_classes/native/org_apache_harmony_vm_VMStack.cpp @@ -319,7 +319,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_ int lineNumber; const char* fileName; - get_file_and_line(method, ip, &fileName, &lineNumber); + get_file_and_line(method, ip, true, &fileName, &lineNumber); jstring strFileName; if (fileName != NULL) { strFileName = jenv->NewStringUTF(fileName); @@ -441,7 +441,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_ int lineNumber; const char* fileName; - get_file_and_line(method, ip, &fileName, &lineNumber); + get_file_and_line(method, ip, true, &fileName, &lineNumber); if (fileName == NULL) fileName = ""; jstring strFileName = jenv->NewStringUTF(fileName); diff --git a/vm/vmcore/src/stack/stack_dump.cpp b/vm/vmcore/src/stack/stack_dump.cpp old mode 100644 new mode 100755 index b246fe2..e0eb5cf --- a/vm/vmcore/src/stack/stack_dump.cpp +++ b/vm/vmcore/src/stack/stack_dump.cpp @@ -164,7 +164,7 @@ #else // PLATFORM_NT #endif } -static void st_get_java_method_info(MethodInfo* info, Method* m, void* ip) { +static void st_get_java_method_info(MethodInfo* info, Method* m, void* ip, bool is_ip_past) { info->file_name = NULL; info->line = -1; info->method_name = NULL; @@ -191,7 +191,7 @@ static void st_get_java_method_info(Meth info->method_name[clen + mlen + dlen + 1] = '\0'; const char* f; - get_file_and_line(m, ip, &f, &info->line); + get_file_and_line(m, ip, is_ip_past, &f, &info->line); } static void st_print_line(int count, MethodInfo* m) { @@ -234,10 +234,10 @@ void st_print_stack(Registers* regs) { uint32 offset = (POINTER_SIZE_INT)si_get_ip(si) - (POINTER_SIZE_INT)cci->get_code_block_addr(); for (uint32 j = 0; j < inlined_depth; j++) { Method *real_method = cci->get_jit()->get_inlined_method(cci->get_inline_info(), offset, j); - st_get_java_method_info(&m, real_method, frames[i].ip); + st_get_java_method_info(&m, real_method, frames[i].ip, 0 == i); st_print_line(++count, &m); } - st_get_java_method_info(&m, cci->get_method(), frames[i].ip); + st_get_java_method_info(&m, cci->get_method(), frames[i].ip, 0 == i); } si_goto_previous(si); } diff --git a/vm/vmcore/src/stack/stack_trace.cpp b/vm/vmcore/src/stack/stack_trace.cpp old mode 100644 new mode 100755 index 81ee4e3..d883533 --- a/vm/vmcore/src/stack/stack_trace.cpp +++ b/vm/vmcore/src/stack/stack_trace.cpp @@ -27,7 +27,7 @@ #include "jit_intf_cpp.h" #include "method_lookup.h" -void get_file_and_line(Method_Handle mh, void *ip, const char **file, int *line) { +void get_file_and_line(Method_Handle mh, void *ip, bool is_ip_past, const char **file, int *line) { Method *method = (Method*)mh; *file = class_get_source_file_name(method_get_class(method)); @@ -62,6 +62,10 @@ #if !defined(_IPF_) // appropriate callL // return; } + + if (is_ip_past) { + bcOffset--; + } *line = method->get_line_number(bcOffset); #endif } @@ -188,7 +192,7 @@ void st_print_frame(ExpandableMemBlock* buf->AppendFormatBlock("\tat %s.%s%s", cname, mname, dname); const char *file; int line; - get_file_and_line(stf->method, stf->ip, &file, &line); + get_file_and_line(stf->method, stf->ip, false, &file, &line); if (line==-2) // Native method -- 1.3.3