This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA] Fix mutual off-by-one error


Hi,

While working on JVMTI/JDWP exception reporting, I noticed that we have two off-by-one errors in both the stack tracing and breakpoint code. It just so happens that they mutually cancel each other out, so it wasn't obvious!

The stack tracing-related bug is that _Jv_InterpFrame::get_pc returns the PC in the interpreter. While executing any insn, the PC always points to the NEXT instruction, not the current.

The bug in breakpoint code deals with not incrementing the PC until AFTER the breakpoint had executed. So while stopped at a breakpoint, "PC" actually pointed to the current instruction not the next.

With the attached patch, both JVMTI breakpoint callbacks and the stack agree where the interpreter is stopped.

QCC? (Questions/comments/concerns - Did I just invent a new acronym?)

Keith

ChangeLog
2007-04-27  Keith Seitz  <keiths@redhat.com>

        * interpret-run.cc (NEXT_INSN)[DEBUG]: Advance PC before
        executing the instruction.
        * include/java-interp.h (_Jv_InterpFrame::get_pc): Subtract
        one insn from the frame's PC. _Jv_InterpMethod::run et al
        will advance the PC before executing the instruction.

Index: interpret-run.cc
===================================================================
--- interpret-run.cc	(revision 124241)
+++ interpret-run.cc	(working copy)
@@ -348,15 +348,16 @@
 #define NEXT_INSN							\
   do									\
     {									\
+      pc_t insn = pc++;							\
       if (JVMTI_REQUESTED_EVENT (SingleStep))				\
 	{								\
 	  JNIEnv *env = _Jv_GetCurrentJNIEnv ();			\
 	  jmethodID method = meth->self;				\
-	  jlocation loc = meth->insn_index (pc);			\
+	  jlocation loc = meth->insn_index (insn);			\
 	  _Jv_JVMTI_PostEvent (JVMTI_EVENT_SINGLE_STEP, thread,		\
 			       env, method, loc);			\
 	}								\
-      goto *((pc++)->insn);						\
+      goto *(insn->insn);						\
     }									\
   while (0)
 
Index: include/java-interp.h
===================================================================
--- include/java-interp.h	(revision 124241)
+++ include/java-interp.h	(working copy)
@@ -465,7 +465,7 @@
     else
       pc = *pc_ptr;
     
-    return pc;
+    return pc - 1;
   }
 };
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]