This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Re: [RFA] Add NormalBreakpoint
Tom Tromey wrote:
Classic OO would be to put a method on the Breakpoint so the different
types know how to handle themselves :-)
Yes, that is true, but I thought in this instance that polymorphism
would make the code a whole lot more difficult to read (we'll have
interpreter code in three separate files, not including interpret.cc).
Nonetheless, I have recoded the whole thing using this more standard
approach.
I'm also attaching a new ChangeLog, since I accidentally omitted all the
regenerated files: they got lost by the classpath merge mess (forgot to
commit the class files for the merge??).
Keith
ChangeLog
2007-06-14 Keith Seitz <keiths@redhat.com>
* gnu/gcj/jvmti/Breakpoint.java: Make abstract.
(method): Change from private to protected.
(location): Likewise.
(Breakpoint): Change argument list to take only integer type.
Add default constructor.
(initialize_native): Renamed to ...
(_save_insn): ... this to make function more explicit.
(execute): New method.
* gnu/gcj/jvmti/Breakpoint.h: Regenerate.
* gnu/gcj/jvmti/natBreakpoint.cc (initialize_native): Rename to...
(_save_insn): ... this.
(install): Save the original instruction.
* gnu/gcj/jvmti/NormalBreakpoint.java: New file.
* gnu/gcj/jvmti/NormalBreakpoint.h: New file.
* gnu/gcj/jvmti/natNormalBreakpoint.cc: New file.
* gnu/gcj/jvmti/BreakpointManager.java (newBreakpoint):
Instantiate a NormalBreakpoint instead of Breakpoint.
* interpret-run.cc (insn_breakpoint): Remove breakpoint actions
and call Breakpoint.execute to do them.
* classpath/lib/gnu/gcj/jvmti/Breakpoint.class: Regenerate.
* classpath/lib/gnu/gcj/jvmti/BreakpointManager.class: Likewise.
* classpath/lib/gnu/gcj/jvmti/NormalBreakpoint.class: New file.
* sources.am: Regenerate.
* Makefile.am (nat_source_files): Add natNormalBreakpoint.cc.
Index: gnu/gcj/jvmti/Breakpoint.java
===================================================================
--- gnu/gcj/jvmti/Breakpoint.java (revision 125581)
+++ gnu/gcj/jvmti/Breakpoint.java (working copy)
@@ -1,6 +1,6 @@
-// Breakpoint.java - a breakpoint in the interpreter
+// Breakpoint.java - a base class for interpreter breakpoints
-/* Copyright (C) 2006 Free Software Foundation
+/* Copyright (C) 2006, 2007 Free Software Foundation
This file is part of libgcj.
@@ -13,37 +13,48 @@
import gnu.gcj.RawDataManaged;
/**
- * Class representing a Breakpoint.
+ * Base class representing a type of breakpoint in the interpreter.
+ * This class deals with saving insns and installing and
+ * uninstalling insns in the interpreter for all breakpoint classes.
*
* @author Keith Seitz (keiths@redhat.com)
*/
-public class Breakpoint
+public abstract class Breakpoint
{
// Location of this breakpoint
- private long method;
- private long location;
+ protected long method;
+ protected long location;
// The original instruction that this breakpoint replaced
private RawDataManaged data;
/**
- * Constructs a new Breakpoint. SetBreakpoint will verify the
- * validity of the arguments.
+ * Constructs a new Breakpoint
*
- * @param method the method (a jmethodID)
- * @param location the jlocation of the breakpoint (a jlocation)
+ * @param method the method in which to set the breakpoint
+ * @param location the location at which to set the breakpoint
*/
public Breakpoint (long method, long location)
{
this.method = method;
this.location = location;
- initialize_native ();
}
- private native void initialize_native ();
+ public Breakpoint ()
+ {
+ }
+ private native void _save_insn ();
+
+ /**
+ * Installs the breakpoint into the interpreter
+ */
public native void install ();
+ /**
+ * Removes the breakpoint from the interpreter, re-installing
+ * the original instruction.
+ */
public native void remove ();
/**
@@ -54,4 +65,9 @@
{
return data;
}
+
+ /**
+ * Execute the actions of this breakpoint
+ */
+ public abstract void execute ();
}
Index: gnu/gcj/jvmti/natBreakpoint.cc
===================================================================
--- gnu/gcj/jvmti/natBreakpoint.cc (revision 125581)
+++ gnu/gcj/jvmti/natBreakpoint.cc (working copy)
@@ -32,7 +32,7 @@
}
void
-gnu::gcj::jvmti::Breakpoint::initialize_native ()
+gnu::gcj::jvmti::Breakpoint::_save_insn ()
{
_Jv_InterpMethod *imeth = get_interp_method (method);
@@ -45,6 +45,7 @@
void
gnu::gcj::jvmti::Breakpoint::install ()
{
+ _save_insn ();
_Jv_InterpMethod *imeth = get_interp_method (method);
imeth->install_break (location);
}
Index: gnu/gcj/jvmti/NormalBreakpoint.java
===================================================================
--- gnu/gcj/jvmti/NormalBreakpoint.java (revision 0)
+++ gnu/gcj/jvmti/NormalBreakpoint.java (revision 0)
@@ -0,0 +1,29 @@
+// NormalBreakpoint.java - a "normal" breakpoint in the interpreter
+
+/* Copyright (C) 2007 Free Software Foundation
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+package gnu.gcj.jvmti;
+
+/**
+ * This class represents a "normal" breakpoint in the interpreter.
+ * When the interpreter hits this breakpoint type, it will send out
+ * a JVMTI breakpoint notification.
+ *
+ * @author Keith Seitz (keiths@redhat.com)
+ */
+public class NormalBreakpoint
+ extends Breakpoint
+{
+ public NormalBreakpoint (long method, long id)
+ {
+ super (method, id);
+ }
+
+ public native void execute ();
+}
Index: gnu/gcj/jvmti/natNormalBreakpoint.cc
===================================================================
--- gnu/gcj/jvmti/natNormalBreakpoint.cc (revision 0)
+++ gnu/gcj/jvmti/natNormalBreakpoint.cc (revision 0)
@@ -0,0 +1,31 @@
+// natNormalBreakpoint.cc - C++ side of NormalBreakpoint
+
+/* Copyright (C) 2007 Free Software Foundation
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+#include <config.h>
+#include <gcj/cni.h>
+#include <java-interp.h>
+#include <jvmti.h>
+#include "jvmti-int.h"
+
+#include <gnu/gcj/jvmti/NormalBreakpoint.h>
+#include <java/lang/Thread.h>
+
+void
+gnu::gcj::jvmti::NormalBreakpoint::execute ()
+{
+ using namespace ::java::lang;
+
+ Thread *thread = Thread::currentThread ();
+ JNIEnv *jni_env = _Jv_GetCurrentJNIEnv ();
+
+ JvAssert (JVMTI_REQUESTED_EVENT (Breakpoint));
+ _Jv_JVMTI_PostEvent (JVMTI_EVENT_BREAKPOINT, thread, jni_env,
+ method, location);
+}
Index: gnu/gcj/jvmti/BreakpointManager.java
===================================================================
--- gnu/gcj/jvmti/BreakpointManager.java (revision 125581)
+++ gnu/gcj/jvmti/BreakpointManager.java (working copy)
@@ -43,7 +43,7 @@
*/
public static Breakpoint newBreakpoint (long method, long location)
{
- Breakpoint bp = new Breakpoint (method, location);
+ NormalBreakpoint bp = new NormalBreakpoint (method, location);
Location loc = new Location (method, location);
bp.install ();
_instance._breakpoints.put (loc, bp);
Index: interpret-run.cc
===================================================================
--- interpret-run.cc (revision 125581)
+++ interpret-run.cc (working copy)
@@ -2619,26 +2619,21 @@
insn_breakpoint:
{
- JvAssert (JVMTI_REQUESTED_EVENT (Breakpoint));
-
- // Send JVMTI notification
using namespace ::java::lang;
jmethodID method = meth->self;
jlocation location = meth->insn_index (pc - 1);
- Thread *thread = Thread::currentThread ();
- JNIEnv *jni_env = _Jv_GetCurrentJNIEnv ();
- // Save the insn here since the breakpoint could be removed
- // before the JVMTI notification returns.
using namespace gnu::gcj::jvmti;
Breakpoint *bp
= BreakpointManager::getBreakpoint (reinterpret_cast<jlong> (method),
location);
JvAssert (bp != NULL);
+
+ // Save the insn here since the breakpoint could be removed
+ // before the JVMTI notification returns.
pc_t opc = reinterpret_cast<pc_t> (bp->getInsn ());
- _Jv_JVMTI_PostEvent (JVMTI_EVENT_BREAKPOINT, thread, jni_env,
- method, location);
+ bp->execute ();
// Continue execution
#ifdef DIRECT_THREADED