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]

Re: [RFA/JVMTI] SingleStep notification


Tom Tromey wrote:

Keith> I share your reservations about the performance hit this entails. So
Keith> perhaps a little tweaking is in order. Perhaps the "debug" interpreter
Keith> should be extended to include not only JDWP but also JVMTI?

My view is that we're only writing this for the sake of JDWP.
But perhaps that's just my first reaction :)
Any idea how much this slows things down?

Okay, I think that I have that tweak figured out. I was right: something was using _Jv_InterpMethod::run instead of _Jv_InterpMethod::run_debug, and we had the two versions of NEXT_INSN confusing the interpreter. [_Jv_CompileMethod didn't take into account debug vs non-debug.]


So I have done what I mentioned above: We presume that when any JVMTI environment is created, we will use the debug stuff from there on out. There's no going back. If no JVMTI environment is ever created, it uses the code the faster code path, skipping JVMTI altogether.

Any less offensive?

Keith

ChangeLog
2007-01-29  Keith Seitz  <keiths@redhat.com>

        * include/jvmti-int.h (JVMTI): Declare member "enabled".
        * jvmti.cc (JVMTI): Add member "enabled".
        (_Jv_GetJVMTIEnv): Mark JVMTI enabled.
        * interpret.cc (_Jv_InterpMethod::ncode): Use JVMTI::enabled
        instead of gnu::classpath::jdwp::Jdwp::isDebugging.
        (_Jv_CompileMethod): If JVMTI is enabled, use run_debug
        instead of run to compile the method.
        * interpret-run.cc [DEBUG] (NEXT_INSN): Add JVMTI single step
        notification.

Index: include/jvmti-int.h
===================================================================
--- include/jvmti-int.h	(revision 121189)
+++ include/jvmti-int.h	(working copy)
@@ -37,6 +37,10 @@
    False means no JVMTI environment requested that event type. */
 namespace JVMTI
 {
+  // Is JVMTI enabled? (i.e., any jvmtiEnv created?)
+  extern bool enabled;
+
+  // Event notifications
   extern bool VMInit;
   extern bool VMDeath;
   extern bool ThreadStart;
Index: jvmti.cc
===================================================================
--- jvmti.cc	(revision 121296)
+++ jvmti.cc	(working copy)
@@ -44,6 +44,10 @@
 
 namespace JVMTI
 {
+  // Is JVMTI enabled? (i.e., any jvmtiEnv created?)
+  bool enabled;
+
+  // Event notifications
   bool VMInit = false;
   bool VMDeath = false;
   bool ThreadStart = false;
@@ -1650,6 +1654,10 @@
       }
   }
 
+  /* Mark JVMTI active. This is used to force the interpreter
+     to use either debugging or non-debugging code. Once JVMTI
+     has been enabled, the non-debug interpreter cannot be used. */
+  JVMTI::enabled = true;
   return env;
 }
 
Index: interpret.cc
===================================================================
--- interpret.cc	(revision 121326)
+++ interpret.cc	(working copy)
@@ -1297,34 +1297,34 @@
     {
       if (staticp)
         {
-        if (::gnu::classpath::jdwp::Jdwp::isDebugging)
-		  fun = (ffi_closure_fun)&_Jv_InterpMethod::run_synch_class_debug;
-		else
-		  fun = (ffi_closure_fun)&_Jv_InterpMethod::run_synch_class;
+	  if (JVMTI::enabled)
+	    fun = (ffi_closure_fun)&_Jv_InterpMethod::run_synch_class_debug;
+	  else
+	    fun = (ffi_closure_fun)&_Jv_InterpMethod::run_synch_class;
         }
       else
         {
-	      if (::gnu::classpath::jdwp::Jdwp::isDebugging)
-		    fun = (ffi_closure_fun)&_Jv_InterpMethod::run_synch_object_debug;
-		  else
-		  	fun = (ffi_closure_fun)&_Jv_InterpMethod::run_synch_object;
-        } 
+	  if (JVMTI::enabled)
+	    fun = (ffi_closure_fun)&_Jv_InterpMethod::run_synch_object_debug;
+	  else
+	    fun = (ffi_closure_fun)&_Jv_InterpMethod::run_synch_object;
+        }
     }
   else
     {
       if (staticp)
         {
-	      if (::gnu::classpath::jdwp::Jdwp::isDebugging)
-		    fun = (ffi_closure_fun)&_Jv_InterpMethod::run_class_debug;
-		  else
-		    fun = (ffi_closure_fun)&_Jv_InterpMethod::run_class;
+	  if (JVMTI::enabled)
+	    fun = (ffi_closure_fun)&_Jv_InterpMethod::run_class_debug;
+	  else
+	    fun = (ffi_closure_fun)&_Jv_InterpMethod::run_class;
         }
       else
         {
-	      if (::gnu::classpath::jdwp::Jdwp::isDebugging)
-		    fun = (ffi_closure_fun)&_Jv_InterpMethod::run_normal_debug;
-		  else
-		    fun = (ffi_closure_fun)&_Jv_InterpMethod::run_normal;
+	  if (JVMTI::enabled)
+	    fun = (ffi_closure_fun)&_Jv_InterpMethod::run_normal_debug;
+	  else
+	    fun = (ffi_closure_fun)&_Jv_InterpMethod::run_normal;
         }
     }
 
@@ -1680,7 +1680,12 @@
 _Jv_CompileMethod (_Jv_InterpMethod* method)
 {
   if (method->prepared == NULL)
-    _Jv_InterpMethod::run (NULL, NULL, method);
+    {
+      if (JVMTI::enabled)
+	_Jv_InterpMethod::run_debug (NULL, NULL, method);
+      else
+      _Jv_InterpMethod::run (NULL, NULL, method);
+    }
 }
 #endif // DIRECT_THREADED
 
Index: interpret-run.cc
===================================================================
--- interpret-run.cc	(revision 121189)
+++ interpret-run.cc	(working copy)
@@ -248,7 +248,27 @@
 
 #ifdef DIRECT_THREADED
 
+#ifdef DEBUG
+#undef NEXT_INSN
+#define NEXT_INSN							\
+  do									\
+    {									\
+      if (JVMTI_REQUESTED_EVENT (SingleStep))				\
+	{								\
+	  JNIEnv *env = _Jv_GetCurrentJNIEnv ();			\
+	  jmethodID method = meth->self;				\
+	  jlocation loc = meth->insn_index (pc);			\
+	  _Jv_JVMTI_PostEvent (JVMTI_EVENT_SINGLE_STEP, thread,		\
+			       env, method, loc);			\
+	}								\
+      goto *((pc++)->insn);						\
+    }									\
+  while (0)
+#else
+#undef NEXT_INSN
 #define NEXT_INSN goto *((pc++)->insn)
+#endif
+
 #define INTVAL() ((pc++)->int_val)
 #define AVAL() ((pc++)->datum)
 
@@ -281,7 +301,22 @@
 
 #else
 
+#ifdef DEBUG
+#define NEXT_INSN							\
+  do									\
+    {									\
+      if (JVMTI_REQUESTED_EVENT (SingleStep))				\
+	{								\
+	  JNIEnv *env = _Jv_GetCurrentJNIEnv ();			\
+	  jmethodID method = meth->self;				\
+	  jlocation loc = meth->insn_index (pc);			\
+	  _Jv_JVMTI_PostEvent (JVMTI_EVENT_SINGLE_STEP, thread,		\
+			       env, method, loc);			\
+	}								\
+      goto *(insn_target[*pc++])
+#else
 #define NEXT_INSN goto *(insn_target[*pc++])
+#endif
 
 #define GET1S() get1s (pc++)
 #define GET2S() (pc += 2, get2s (pc- 2))

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