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] Update PC values for JVMTI stack tracing code


Since the PC values stored in _Jv_InterpFrame are only updated when an
exception can be thrown, it is possible that the location value obtained
when getting a stack trace can be incorrect.  Since threads can be
suspended any time through ThreadReference.Suspend, it is necessary that
the stack tracing code have access to the value of the PC in the
interpreter at all times.  This patch pins the PC with a pointer in
_Jv_InterpFrame when debugging, and provides a method to retrieve the PC
value for use in stack tracing code.  This corrects a problem with
eclipse not updating the source line display properly as well.

ChangeLog
2007-04-16  Kyle Galloway  <kgallowa@redhat.com>

    * include/java-interp.h (_Jv_InterpFrame) Add pointer to the
interpreter PC.
    (<init>): Add a pointer to the interpreter PC as a parameter with
default value NULL.
    (get_pc): New method.
    * interpret-run.cc: If debugging, pass a pointer to the PC when
creating the stack frame.
    * jvmti.cc (_Jv_JVMTI_GetStackTrace): Call _Jv_InterpFrame::get_pc
to get the PC.

Questions/comments/concerns?

Thanks,
Kyle
Index: libjava/include/java-interp.h
===================================================================
--- libjava/include/java-interp.h	(revision 123872)
+++ libjava/include/java-interp.h	(working copy)
@@ -422,6 +422,9 @@
     pc_t pc;
     jclass proxyClass;
   };
+  
+  // Pointer to the actual pc value.
+  pc_t *pc_ptr;
 
   //Debug info for local variables.
   _Jv_word *locals;
@@ -430,7 +433,8 @@
   // Object pointer for this frame ("this")
   jobject obj_ptr;
 
-  _Jv_InterpFrame (void *meth, java::lang::Thread *thr, jclass proxyCls = NULL)
+  _Jv_InterpFrame (void *meth, java::lang::Thread *thr, jclass proxyCls = NULL,
+                   pc_t *pc = NULL)
   : _Jv_Frame (reinterpret_cast<_Jv_MethodBase *> (meth), thr,
 	             frame_interpreter)
   {
@@ -438,6 +442,7 @@
     proxyClass = proxyCls;
     thr->interp_frame = (gnu::gcj::RawData *) this;
     obj_ptr = NULL;
+    pc_ptr = pc;
   }
 
   ~_Jv_InterpFrame ()
@@ -448,7 +453,21 @@
   jobject get_this_ptr ()
   {
     return obj_ptr;
-  } 
+  }
+  
+  pc_t get_pc ()
+  {
+    pc_t pc;
+    
+    // If the pc is NULL, either we are not debugging, or the method has not
+    // started.
+    if (pc_ptr == NULL)
+      pc = 0;
+    else
+      pc = *pc_ptr;
+    
+    return pc;
+  }
 };
 
 // A native frame in the call stack really just a placeholder
Index: libjava/jvmti.cc
===================================================================
--- libjava/jvmti.cc	(revision 123872)
+++ libjava/jvmti.cc	(working copy)
@@ -1245,7 +1245,7 @@
             = static_cast<_Jv_InterpMethod *> (frame->self);
           _Jv_InterpFrame *interp_frame 
             = static_cast<_Jv_InterpFrame *> (frame);
-          frames[i].location = imeth->insn_index (interp_frame->pc);
+          frames[i].location = imeth->insn_index (interp_frame->get_pc ());
         }
       else
         frames[i].location = -1;
Index: libjava/interpret-run.cc
===================================================================
--- libjava/interpret-run.cc	(revision 123872)
+++ libjava/interpret-run.cc	(working copy)
@@ -12,6 +12,8 @@
  * compiled directly.	*/
 
   using namespace java::lang::reflect;
+  
+  pc_t pc;
 
   // FRAME_DESC registers this particular invocation as the top-most
   // interpreter frame.  This lets the stack tracing code (for
@@ -20,7 +22,12 @@
   // destructor so it cleans up automatically when the interpreter
   // returns.
   java::lang::Thread *thread = java::lang::Thread::currentThread();
+  
+#ifdef DEBUG
+  _Jv_InterpFrame frame_desc (meth, thread, NULL, &pc);
+#else
   _Jv_InterpFrame frame_desc (meth, thread);
+#endif
 
   _Jv_word stack[meth->max_stack];
   _Jv_word *sp = stack;
@@ -334,8 +341,6 @@
 #endif
   };
 
-  pc_t pc;
-
 #ifdef DIRECT_THREADED
 
 #ifdef DEBUG

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