classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] [PATCH/JDWP] VMVirtualMachine, JdwpConstants, Jdwp


From: Keith Seitz
Subject: [cp-patches] [PATCH/JDWP] VMVirtualMachine, JdwpConstants, Jdwp
Date: Fri, 02 Sep 2005 17:18:11 -0700
User-agent: Mozilla Thunderbird 1.0.6-1.1.fc4 (X11/20050720)

Hello,

This is the last of the outstanding files that I have for gnu.classpath.jdwp. JdwpConstants is self-explanatory. Jdwp is the main entry for the back-end, containing methods to send events and get the back-end started (and stopped). VMVirtualMachine contains methods for the back-end to use to fetch VM-specific things.

While these are the last of the outstanding files, rest assured that both Jdwp.java and VMVirtualMachine.java are exceptionally likely to change (perhaps quite dramatically) in the coming weeks, as I begin checking in a gcj-specific implementation to utilize all this code.

With this, classpath should now also build with jdwp code. At the maintainer's discretion, vm/reference/standard.omit and lib/standard.omit may both be changed to permit the inclusion of this code.

Keith

ChangeLog
2005-09-02  Keith Seitz  <address@hidden>

        * gnu/classpath/jdwp/Jdwp.java: New file.
        * gnu/classpath/jdwp/JdwpConstants.java: New file.
        * vm/reference/gnu/classpath/jdwp/VMVirtualMachine.java: New file.
Index: gnu/classpath/jdwp/JdwpConstants.java
===================================================================
RCS file: gnu/classpath/jdwp/JdwpConstants.java
diff -N gnu/classpath/jdwp/JdwpConstants.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ gnu/classpath/jdwp/JdwpConstants.java       3 Sep 2005 00:08:09 -0000
@@ -0,0 +1,901 @@
+/* JdwpConstants.java -- Constants defined by JDWP 1.4 specification
+   Copyright (C) 2005 Free Software Foundation
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.classpath.jdwp;
+
+/**
+ * Constants defined by JDWP specification.
+ *
+ * @author Keith Seitz  (address@hidden)
+ */
+public class JdwpConstants
+{
+  public static final class Version
+  {
+    public static final int MAJOR = 1;
+    public static final int MINOR = 4;
+  }
+  
+  ////////////////////////////////////////
+  //           Commands/Sets            //
+  ////////////////////////////////////////
+
+  public static final class CommandSet
+  {
+    public static final class VirtualMachine
+    {
+      public static final byte CS_VALUE = 1;
+
+      // commands
+      public static final byte VERSION = 1;
+      public static final byte CLASSES_BY_SIGNATURE = 2;
+      public static final byte ALL_CLASSES = 3;
+      public static final byte ALL_THREADS = 4;
+      public static final byte TOP_LEVEL_THREAD_GROUPS = 5;
+      public static final byte DISPOSE = 6;
+      public static final byte IDSIZES = 7;
+      public static final byte SUSPEND = 8;
+      public static final byte RESUME = 9;
+      public static final byte EXIT = 10;
+      public static final byte CREATE_STRING = 11;
+      public static final byte CAPABILITIES = 12;
+      public static final byte CLASS_PATHS = 13;
+      public static final byte DISPOSE_OBJECTS = 14;
+      public static final byte HOLD_EVENTS = 15; 
+      public static final byte RELEASE_EVENTS = 16;
+      public static final byte CAPABILITIES_NEW = 17;
+      public static final byte REDEFINE_CLASSES = 18;
+      public static final byte SET_DEFAULT_STRATUM = 19;
+      public static final byte ALL_CLASSES_WITH_GENERIC = 20;
+    }
+
+    public static final class ReferenceType
+    {
+      public static final byte CS_VALUE = 2;
+
+      // commands
+      public static final byte SIGNATURE= 1;
+      public static final byte CLASS_LOADER= 2;
+      public static final byte MODIFIERS = 3;
+      public static final byte FIELDS = 4;
+      public static final byte METHODS = 5; 
+      public static final byte GET_VALUES = 6;
+      public static final byte SOURCE_FILE = 7;
+      public static final byte NESTED_TYPES = 8;
+      public static final byte STATUS = 9;
+      public static final byte INTERFACES= 10;
+      public static final byte CLASS_OBJECT = 11;
+      public static final byte SOURCE_DEBUG_EXTENSION = 12;
+      public static final byte SIGNATURE_WITH_GENERIC = 13;
+      public static final byte FIELDS_WITH_GENERIC = 14;
+      public static final byte METHODS_WITH_GENERIC = 15;
+    }
+
+    public static final class ClassType
+    {
+      public static final byte CS_VALUE = 3;
+
+      // commands
+      public static final byte SUPERCLASS = 1;
+      public static final byte SET_VALUES = 2;
+      public static final byte INVOKE_METHOD = 3;
+      public static final byte NEW_INSTANCE = 4;
+    }
+
+    public static final class ArrayType
+    {
+      public static final byte CS_VALUE = 4;
+
+      // commands
+      public static final byte NEW_INSTANCE = 1;
+    }
+
+    public static final class InterfaceType
+    {
+      public static final byte CS_VALUE = 5;
+
+      // commands
+    }
+
+    public static final class Method
+    {
+      public static final byte CS_VALUE = 6;
+
+      // commands
+      public static final byte LINE_TABLE = 1;
+      public static final byte VARIABLE_TABLE = 2;
+      public static final byte BYTE_CODES = 3;
+      public static final byte IS_OBSOLETE = 4;
+      public static final byte VARIABLE_TABLE_WITH_GENERIC = 5;
+    }
+
+    public static final class Field
+    {
+      public static final byte CS_VALUE = 8;
+
+      // commands
+    }
+
+    public static final class ObjectReference
+    {
+      public static final byte CS_VALUE = 9;
+
+      // commands
+      public static final byte REFERENCE_TYPE = 1;
+      public static final byte GET_VALUES = 2;
+      public static final byte SET_VALUES = 3;
+      public static final byte MONITOR_INFO = 5;
+      public static final byte INVOKE_METHOD = 6;
+      public static final byte DISABLE_COLLECTION = 7;
+      public static final byte ENABLE_COLLECTION = 8;
+      public static final byte IS_COLLECTED = 9;
+    }
+
+    public static final class StringReference
+    {
+      public static final byte CS_VALUE = 10;
+
+      // commands
+      public static final byte VALUE = 1;
+    }
+
+    public static final class ThreadReference
+    {
+      public static final byte CS_VALUE = 11;
+
+      // commands
+      public static final byte NAME = 1;
+      public static final byte SUSPEND = 2;
+      public static final byte RESUME = 3;
+      public static final byte STATUS = 4;
+      public static final byte THREAD_GROUP = 5;
+      public static final byte FRAMES = 6;
+      public static final byte FRAME_COUNT = 7;
+      public static final byte OWNED_MONITORS = 8;
+      public static final byte CURRENT_CONTENDED_MONITOR = 9;
+      public static final byte STOP = 10;
+      public static final byte INTERRUPT = 11;
+      public static final byte SUSPEND_COUNT = 12;
+    }
+
+    public static final class ThreadGroupReference
+    {
+      public static final byte CS_VALUE = 12;
+
+      // commands
+      public static final byte NAME = 1;
+      public static final byte PARENT = 2;
+      public static final byte CHILDREN = 3;
+    }
+
+    public static final class ArrayReference
+    {
+      public static final byte CS_VALUE = 13;
+
+      // commands
+      public static final byte LENGTH = 1;
+      public static final byte GET_VALUES = 2;
+      public static final byte SET_VALUES = 3;
+    }
+
+    public static final class ClassLoaderReference
+    {
+      public static final byte CS_VALUE = 14;
+
+      // commands
+      public static final byte VISIBLE_CLASSES = 1;
+    }
+
+    public static final class EventRequest
+    {
+      public static final byte CS_VALUE = 15;
+
+      // commands
+      public static final byte SET = 1;
+      public static final byte CLEAR = 2;
+      public static final byte CLEAR_ALL_BREAKPOINTS = 3;
+    }
+
+    public static final class StackFrame
+    {
+      public static final byte CS_VALUE = 16;
+
+      // commands
+      public static final byte GET_VALUES = 1;
+      public static final byte SET_VALUES = 2;
+      public static final byte THIS_OBJECT = 3;
+      public static final byte POP_FRAMES = 4;
+    }
+
+    public static final class ClassObjectReference
+    {
+      public static final byte CS_VALUE = 17;
+
+      // commands
+      public static final byte REFLECTED_TYPE = 1;
+    }
+
+    public static final int MAXIMUM = ClassObjectReference.CS_VALUE;
+
+    public static final class Event
+    {
+      public static final byte CS_VALUE = 64;
+
+      // commands
+      public static final byte COMPOSITE = 100;
+    }
+  }
+
+  ////////////////////////////////////////
+  //             Constants              //
+  ////////////////////////////////////////
+
+  /*
+   * Error constants
+   */
+  public static final class Error
+  {
+    /**
+     * No error has occurred
+     */
+    public static final short NONE = 0;
+
+    /**
+     * Passed thread is null, is not a valid thread or has exited
+     */
+    public static final short INVALID_THREAD = 10;
+
+    /**
+     * Thread group invalid
+     */
+    public static final short INVALID_THREAD_GROUP = 11;
+
+    /**
+     * Invalid priority
+     */
+    public static final short INVALID_PRIORITY = 12;
+
+    /**
+     * Specified thread has not been suspended by an event
+     */
+    public static final short THREAD_NOT_SUSPENDED = 13;
+
+    /**
+     * Thread already suspended
+     */
+    public static final short THREAD_SUSPENDED = 14;
+
+    /**
+     * Reference type has been unloaded and garbage collected
+     */
+    public static final short INVALID_OBJECT = 20;
+
+    /**
+     * Invalid class
+     */
+    public static final short INVALID_CLASS = 21;
+
+    /**
+     * Class has been loaded but not yet prepared
+     */
+    public static final short CLASS_NOT_PREPARED = 22;
+
+    /**
+     * Invalid method
+     */
+    public static final short INVALID_METHODID = 23;
+
+    /**
+     * Invalid location
+     */
+    public static final short INVALID_LOCATION = 24;
+
+    /**
+     * Invalid field
+     */
+    public static final short INVALID_FIELDID = 25;
+
+    /**
+     * Invaliid frame
+     */
+    public static final short INVALID_FRAMEID = 30;
+
+    /**
+     * There are no more Java or JNI frames on the call stack
+     */
+    public static final short NO_MORE_FRAMES = 31;
+
+    /**
+     * Information about the frame is not available
+     */
+    public static final short OPAQUE_FRAME = 32;
+
+    /**
+     * Operation can only be performed on current frame
+     */
+    public static final short NOT_CURRENT_FRAME = 33;
+
+    /**
+     * Variable is not an appropriate type for the function used
+     */
+    public static final short TYPE_MISMATCH = 34;
+
+    /**
+     * Invalid slot
+     */
+    public static final short INVALID_SLOT = 35;
+
+    /**
+     * Item already set
+     */
+    public static final short DUPLICATE = 40;
+
+    /**
+     * Desired element not found
+     */
+    public static final short NOT_FOUND = 41;
+
+    /**
+     * Invalid monitor
+     */
+    public static final short INVALID_MONITOR = 50;
+
+    /**
+     * Thread doesn't own the monitor
+     */
+    public static final short NOT_MONITOR_OWNER = 51;
+
+    /**
+     * Call has been interrupted before completion
+     */
+    public static final short INTERRUPT = 52;
+
+    /**
+     * Virtual machine attempted to read a class file and determined that
+     * the file is malformed or otherwise cannot be interpreted as a class
+     * file
+     */
+    public static final short INVALID_CLASS_FORMAT = 60;
+
+    /**
+     * Circularity has been detected while initializing a class
+     */
+    public static final short CIRCULAR_CLASS_DEFINITION = 61;
+
+    /**
+     * Verifier detected that a class file, though well formed, contained
+     * some sort of internal inconsistency or security problem
+     */
+    public static final short FAILS_VERIFICATION = 62;
+
+    /**
+     * Adding methods has not been implemented
+     */
+    public static final short ADD_METHOD_NOT_IMPLEMENTED = 63;
+
+    /**
+     * Schema change has not been implemented
+     */
+    public static final short SCHEMA_CHANGE_NOT_IMPLEMENTED = 64;
+
+    /**
+     * State of the thread has been modified and is now inconsistent
+     */
+    public static final short INVALID_TYPESTATE = 65;
+
+    /**
+     * A direct superclass is different for the new class version, or the set
+     * of directly implemented interfaces is different and
+     * <code>canUnrestrictedlyRedefineClasses</code> is false
+     */
+    public static final short HIERARCHY_CHANGE_NOT_IMPLEMENTED = 66;
+
+    /**
+     * New class version does not declare a method declared in the old
+     * class version and <code>canUnrestrictedlyRedefineClasses</code>
+     * is false
+     */
+    public static final short DELETE_METHOD_NOT_IMPLEMENTED = 67;
+
+    /**
+     * Class file has a version number not supported by this VM
+     */
+    public static final short UNSUPPORTED_VERSION = 68;
+
+    /**
+     * Class name defined in the new class file is different from the name
+     * in the old class object
+     */
+    public static final short NAMES_DONT_MATCH = 69;
+
+    /**
+     * New class version has different modifiers and
+     * <code>canUnrestrictedlyRedefineClasses</code> is false
+     */
+    public static final short CLASS_MODIFIERS_CHANGE_NOT_IMPLEMENTED = 70;
+
+    /**
+     * A method in the new class version has different modifiers than its
+     * counterpart in the old class version and
+     * <code>canUnrestrictedlyRedefineClasses</code> is false.
+     */
+    public static final short METHOD_MODIFIERS_CHANGE_NOT_IMPLEMENTED = 71;
+
+    /**
+     * Functionality is not implemented in this virtual machine
+     */
+    public static final short NOT_IMPLEMENTED = 99;
+
+    /**
+     * Invalid pointer
+     */
+    public static final short NULL_POINTER = 100;
+
+    /**
+     * Desired information is not available
+     */
+    public static final short ABSENT_INFORMATION = 101;
+
+    /**
+     * Specified event type id is not recognized
+     */
+    public static final short INVALID_EVENT_TYPE = 102;
+
+    /**
+     * Illegal argument
+     */
+    public static final short ILLEGAL_ARGUMENT = 103;
+
+    /**
+     * The function needed to allocate memory and no more memory was
+     * available for allocation
+     */
+    public static final short OUT_OF_MEMORY = 110;
+
+    /**
+     * Debugging has not been enabled in this virtual machine. JVMDI cannot
+     * be used
+     */
+    public static final short ACCESS_DENIED = 111;
+
+    /**
+     * The virtual machine is not running
+     */
+    public static final short VM_DEAD = 112;
+
+    /**
+     * An unexpected internal error has occurred
+     */
+    public static final short INTERNAL = 113;
+
+    /**
+     * The thread being used to call this function is not attached to the
+     * virtual machine. Calls must be made from attached threads.
+     */
+    public static final short UNATTACHED_THREAD = 115;
+
+    /**
+     * Invalid object type id or class tag
+     */
+    public static final short INVALID_TAG = 500;
+
+    /**
+     * Previous invoke not complete
+     */
+    public static final short ALREADY_INVOKING = 502;
+
+    /**
+     * Invalid index
+     */
+    public static final short INVALID_INDEX = 503;
+
+    /**
+     * Invalid length
+     */
+    public static final short INVALID_LENGTH = 504;
+
+    /**
+     * Invalid string
+     */
+    public static final short INVALID_STRING = 506;
+
+    /**
+     * Invalid class loader
+     */
+    public static final short INVALID_CLASS_LOADER = 507;
+
+    /**
+     * Invalid array
+     */
+    public static final short INVALID_ARRAY = 508;
+
+    /**
+     * Unable to load the transport
+     */
+    public static final short TRANSPORT_LOAD = 509;
+
+    /**
+     * Unablie to initialize the transport
+     */
+    public static final short TRANSPORT_INIT = 510;
+
+    /**
+     * Method is native
+     */
+    public static final short NATIVE_METHOD = 511;
+
+    /**
+     * Invalid count
+     */
+    public static final short INVALID_COUNT = 512;
+  }
+
+  /*
+   * EventKind constants
+   */
+  public static final class EventKind
+  {
+    public static final byte SINGLE_STEP = 1;
+    public static final byte BREAKPOINT = 2;
+    public static final byte FRAME_POP = 3;
+    public static final byte EXCEPTION = 4;
+    public static final byte USER_DEFINED = 5;
+    public static final byte THREAD_START = 6;
+    public static final byte THREAD_END = 7;
+    public static final byte CLASS_PREPARE = 8;
+    public static final byte CLASS_UNLOAD = 9;
+    public static final byte CLASS_LOAD = 10;
+    public static final byte FIELD_ACCESS = 20;
+    public static final byte FIELD_MODIFICATION = 21;
+    public static final byte EXCEPTION_CATCH = 30;
+    public static final byte METHOD_ENTRY = 40;
+    public static final byte METHOD_EXIT = 41;
+    public static final byte VM_INIT = 90;
+    public static final byte VM_DEATH = 99;    
+    public static final byte VM_DISCONNECTED = 100;
+
+    public static final byte VM_START = VM_INIT;
+    public static final byte THREAD_DEATH = THREAD_END;
+  }
+
+  /*
+   * ModKind constants (event filters)
+   */
+  public static final class ModKind
+  {
+    /**
+     * Limit the requested event to be reported at most once after a
+     * given number of occurrences. May be used with any event.
+     */
+    public static final byte COUNT = 1;
+
+    /**
+     * Conditional on expression
+     */
+    public static final byte CONDITIONAL = 2;
+
+    /**
+     * Restricts reported events to those in the given thread.
+     * May be used with any event except for class unload.
+     */
+    public static final byte THREAD_ONLY = 3;
+
+    /**
+     * For class prepare events, restricts generated events 
+     * to be the preparation of the given reference type and any
+     * subtypes.
+     *
+     * For other events, restricts the generated events to those where
+     * location is in the given reference type or any of its subtypes.
+     *
+     * An event will be generated for any location in a reference type
+     * that can be safely cast to the given reference type.
+     *
+     * May be used with any event except class unload, thread start,
+     * and thread end.
+     */
+    public static final byte CLASS_ONLY = 4;
+
+    /**
+     * Restricts reported events to those for classes whose name matches
+     * the given restricted regular expression.
+     *
+     * For class prepare events, the prepared class name is matched.
+     * For class unload events, the unloaded class name is matched.
+     * For other events, the class name of the event's location is matched.
+     *
+     * May be used with any event except thread start and thread end.
+     */
+    public static final byte CLASS_MATCH = 5;
+
+    /**
+     * Restricts reported events to those for classes whose name does not
+     * match the given restricted regular expression.
+     * 
+     * For class prepare events, the prepared class name is matched.
+     * For class unload events, the unloaded class name is matched.
+     * For other events, the class name of the event's location is matched.
+     *
+     * May be used with any event except thread start and thread end.
+     */
+    public static final byte CLASS_EXCLUDE = 6;
+
+    /**
+     * Restricts reported events to those that occur at the given location.
+     *
+     * May be used with breakpoint, field access, field modification, step,
+     * and exception event kinds.
+     */
+    public static final byte LOCATION_ONLY = 7;
+
+    /**
+     * Restricts reported exceptions by their class and whether they are
+     * caught or uncaught.
+     *
+     * May be used with exception event kinds only.
+     */
+    public static final byte EXCEPTION_ONLY = 8;
+
+    /**
+     * Restricts reported events to those that occur for a given field.
+     *
+     * May be used with field access and field modification event kinds only.
+     */
+    public static final byte FIELD_ONLY = 9;
+
+    /**
+     * Restricts reported step events to those which satisfy depth and
+     * size constraints.
+     * 
+     * May be used with step event kinds only.
+     */
+    public static final byte STEP = 10;
+
+    /**
+     * Restricts reported events to those whose active 'this' object is
+     * the given object. Match value is the null object for static methods.
+     *
+     * May be used with any event except class prepare, class unload,
+     * thread start, and thread end.
+     */
+    public static final byte INSTANCE_ONLY = 11;
+  }
+
+  /*
+   * ThreadStatus constants
+   */
+  public static final class ThreadStatus
+  {
+    public static final int ZOMBIE = 0;
+    public static final int RUNNING = 1;
+    public static final int SLEEPING = 2;
+    public static final int MONITOR = 3;
+    public static final int WAIT = 4;
+  }
+
+  /*
+   * SuspendStatus constants
+   */
+  public static final class SuspendStatus
+  {
+    public static final byte SUSPENDED = 1;
+  }
+
+  /*
+   * ClassStatus constants
+   */
+  public static final class ClassStatus
+  {
+    public static final int VERIFIED = 1;
+    public static final int PREPARED = 2;
+    public static final int INITIALIZED = 4;
+    public static final int ERROR = 8;
+  }
+
+  /*
+   * TypeTag constants
+   */
+  public static final class TypeTag
+  {
+    public static final byte CLASS = 1;
+    public static final byte INTERFACE = 2;
+    public static final byte ARRAY = 3;
+  }
+
+  /*
+   * Tag constants
+   */
+  public static final class Tag
+  {
+    /**
+     * Array object (objectID size)
+     */
+    public static final byte ARRAY = '[';
+
+    /**
+     * Byte value (1 byte)
+     */
+    public static final byte BYTE = 'B';
+
+    /**
+     * Character value (2 bytes)
+     */
+    public static final byte CHAR = 'C';
+
+    /**
+     * Object (objectID size)
+     */
+    public static final byte OBJECT = 'L';
+
+    /**
+     * Float value (4 bytes)
+     */
+    public static final byte FLOAT = 'F';
+
+    /**
+     * Double value (8 bytes)
+     */
+    public static final byte DOUBLE = 'D';
+
+    /**
+     * Int value (4 bytes)
+     */
+    public static final byte INT = 'I';
+
+    /**
+     * Long value (8 bytes)
+     */
+    public static final byte LONG = 'J';
+
+    /**
+     * Short value (2 bytes)
+     */
+    public static final byte SHORT = 'S';
+
+    /**
+     * Void value (no bytes)
+     */
+    public static final byte  VOID = 'V';
+
+    /**
+     * Boolean value (1 byte)
+     */
+    public static final byte BOOLEAN = 'Z';
+
+    /**
+     * String object (objectID size)
+     */
+    public static final byte STRING = 's';
+
+    /**
+     * Thread object (objectID size)
+     */
+    public static final byte THREAD = 't';
+
+    /**
+     * ThreadGroup object (objectID size)
+     */
+    public static final byte THREAD_GROUP = 'g';
+
+    /**
+     * ClassLoader object (objectID size)
+     */
+    public static final byte CLASS_LOADER = 'l';
+
+    /**
+     * Class object object (objectID size)
+     */
+    public static final byte CLASS_OBJECT = 'c';
+  }
+
+  /*
+   * StepDepth constants
+   */
+  public static final class StepDepth
+  {
+    /**
+     * Step into any method calls that occur before the end of the step
+     */
+    public static final int INTO = 0;
+
+    /**
+     * Step over any method calls that occur before the end of the step
+     */
+    public static final int OVER = 1;
+
+    /**
+     * Step out of the current method
+     */
+    public static final int OUT = 2;
+  }
+
+  /*
+   * StepSize constants
+   */
+  public static final class StepSize
+  {
+    /**
+     * Step by the minimum possible amount (often a bytecode instruction)
+     */
+    public static final int MIN = 0;
+
+    /**
+     * Step to the next source line unless there is no line number information,
+     * in which case MIN step is done instead
+     */
+    public static final int LINE = 1;
+  }
+
+  /*
+   * SuspendPolicy constants
+   */
+  public static final class SuspendPolicy
+  {
+    /**
+     * Suspend no threads when this event is encountered
+     */
+    public static final byte NONE = 0;
+
+    /**
+     * Suspend the event thread when this event is encountered
+     */
+    public static final byte EVENT_THREAD = 1;
+
+    /**
+     * Suspend all threads when this event is encountered
+     */
+    public static final byte ALL = 2;
+  }
+
+  /*
+   * InvokeOptions flag constants
+   */
+  public static final class InvokeOptions
+  {
+    /**
+     * otherwise, all threads started
+     */
+    public static final int INVOKE_SINGLE_THREADED = 0x1;
+
+    /**
+     * otherwise, normal virtual invoke (instance methods only)
+     */
+    public static final int INVOKE_NONVIRTUAL = 0x2;
+  }
+}
Index: gnu/classpath/jdwp/Jdwp.java
===================================================================
RCS file: gnu/classpath/jdwp/Jdwp.java
diff -N gnu/classpath/jdwp/Jdwp.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ gnu/classpath/jdwp/Jdwp.java        3 Sep 2005 00:08:09 -0000
@@ -0,0 +1,302 @@
+/* Jdwp.java -- Virtual machine to JDWP back-end programming interface
+   Copyright (C) 2005 Free Software Foundation
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.classpath.jdwp;
+
+import gnu.classpath.jdwp.event.Event;
+import gnu.classpath.jdwp.event.EventManager;
+import gnu.classpath.jdwp.event.EventRequest;
+import gnu.classpath.jdwp.id.ThreadId;
+import gnu.classpath.jdwp.processor.PacketProcessor;
+import gnu.classpath.jdwp.transport.ITransport;
+import gnu.classpath.jdwp.transport.JdwpConnection;
+import gnu.classpath.jdwp.transport.TransportException;
+import gnu.classpath.jdwp.transport.TransportFactory;
+
+import java.io.IOException;
+import java.security.AccessController;
+import java.util.HashMap;
+
+/**
+ * Main interface from the virtual machine to the JDWP back-end.
+ *
+ * @author Keith Seitz (address@hidden)
+ */
+public class Jdwp
+  extends Thread
+{
+  // The single instance of the back-end
+  private static Jdwp _instance = null;
+
+  /**
+   * Are we debugging?
+   */
+  public static boolean isDebugging = false;
+
+  // Packet processor
+  private PacketProcessor _packetProcessor;
+  private Thread _ppThread;
+
+  // JDWP configuration properties
+  private HashMap _properties;
+
+  // The suspend property of the configure string
+  // (-Xrunjdwp:..suspend=<boolean>)
+  private static final String _PROPERTY_SUSPEND = "suspend";
+
+  // User's main application thread
+  private Thread _mainThread;
+
+  // Connection to debugger
+  private JdwpConnection _connection;
+
+  // Are we shutting down the current session?
+  private boolean _shutdown;
+
+  // A thread group for the JDWP threads
+  private ThreadGroup _group;
+
+  /**
+   * constructor
+   */
+  public Jdwp ()
+  {
+    _shutdown = false;
+    isDebugging = true;
+    _instance = this;
+  }
+
+  /**
+   * Returns the JDWP back-end, creating an instance of it
+   * if one does not already exist.
+   */
+  public static Jdwp getDefault ()
+  {
+    return _instance;
+  }
+
+  /**
+   * Should the virtual machine suspend on startup?
+   */
+  public static boolean suspendOnStartup ()
+  {
+    Jdwp jdwp = getDefault ();
+    if (jdwp != null)
+      {
+       String suspend = (String) jdwp._properties.get (_PROPERTY_SUSPEND);
+       if (suspend != null && suspend.equals ("y"))
+         return true;
+      }
+
+    return false;
+  }
+
+  /**
+   * Configures the back-end
+   *
+   * @param configArgs  a string of configury options
+   * @param mainThread  the main application thread
+   */
+  public void configure (String configArgs, Thread mainThread)
+  {
+    _mainThread = mainThread;
+    _processConfigury (configArgs);
+  }
+
+  // A helper function to initialize the transport layer
+  private void _doInitialization ()
+    throws TransportException
+  {
+    _group = new ThreadGroup ("JDWP threads");
+    // initialize transport
+    ITransport transport = TransportFactory.newInstance (_properties);
+    _connection = new JdwpConnection (_group, transport);
+    _connection.initialize ();
+    _connection.start ();
+
+    // Create processor
+    _packetProcessor = new PacketProcessor (_connection);
+    _ppThread = new Thread (_group, new Runnable ()
+      {
+       public void run ()
+       {
+         AccessController.doPrivileged (_packetProcessor);
+       }
+      });
+    _ppThread.start ();
+  }
+
+  /**
+   * Shutdown the JDWP back-end
+   *
+   * NOTE: This does not quite work properly. See notes in 
+   * run() on this subject (catch of InterruptedException).
+   */
+  public void shutdown ()
+  {
+    if (!_shutdown)
+      {
+       _packetProcessor.shutdown ();
+       _ppThread.interrupt ();
+       _connection.shutdown ();
+       _shutdown = true;
+       isDebugging = false;
+
+       /* FIXME: probably need to check state of user's
+          program -- if it is suspended, we need to either
+          resume or kill them. */
+
+       interrupt ();
+      }
+  }
+
+  /**
+   * Notify the debugger of an event. This method should not
+   * be called if debugging is not active (but it would not
+   * cause any harm). Places where event notifications occur
+   * should check isDebugging before doing anything.
+   *
+   * The event is filtered through the event manager before being
+   * sent.
+   *
+   * FIXME: Probably need logic to send multiple events
+   * @param event the event to report
+   */
+  public static void notify (Event event)
+  {
+    Jdwp jdwp = getDefault ();
+    if (jdwp != null)
+      {
+       EventManager em = EventManager.getDefault ();
+       EventRequest request = em.getEventRequest (event);
+       if (request != null)
+         sendEvent (request, event);
+      }
+  }
+  
+  /**
+   * Sends the event to the debugger.
+   *
+   * This method bypasses the event manager's filtering.
+   *
+   * @param  request  the debugger request for the event
+   * @param  event    the event to send
+   */
+  public static void sendEvent (EventRequest request, Event event)
+  {
+    Jdwp jdwp = getDefault ();
+    if (jdwp != null)
+      {
+       try
+         {
+           // !! May need to implement send queue?
+           synchronized (jdwp._connection)
+             {
+               jdwp._connection.sendEvent (request, event);
+             }
+           
+           // Follow suspend policy
+           jdwp._enforceSuspendPolicy (request.getSuspendPolicy ());
+         }
+       catch (IOException ie)
+         {
+           System.out.println ("Jdwp.notify: caught exception: " + ie);
+         }
+      }
+  }
+
+  // Helper function to enforce suspend policies on event notification
+  private void _enforceSuspendPolicy (byte suspendPolicy)
+  {
+    switch (suspendPolicy)
+      {
+      case EventRequest.SUSPEND_NONE:
+       // do nothing
+       break;
+
+      case EventRequest.SUSPEND_THREAD:
+       VMVirtualMachine.suspendThread (this);
+       break;
+
+      case EventRequest.SUSPEND_ALL:
+       VMVirtualMachine.suspendAllThreads ();
+       break;
+      }
+  }
+
+  public void run ()
+  {
+    try
+      {
+       _doInitialization ();
+
+       _mainThread.start ();
+
+       _mainThread.join ();
+      }
+    catch (InterruptedException ie)
+      {
+       /* Shutting down. If we're in server mode, we should
+          prepare for a new connection. Otherwise, we should
+          simply exit. */
+       // FIXME
+      }
+    catch (Throwable t)
+      {
+       System.out.println ("Exception in JDWP back-end: " + t);
+       System.exit (1);
+      }
+  }
+
+  // A helper function to process the configure string "-Xrunjdwp:..."
+  private void _processConfigury (String configString)
+  {
+    // Loop through configuration arguments looking for a
+    // transport name
+    _properties = new HashMap ();
+    String[] options = configString.split (",");
+    for (int i = 0; i < options.length; ++i)
+      {
+       String[] property = options[i].split ("=");
+       if (property.length == 2)
+         _properties.put (property[0], property[1]);
+       // ignore malformed options
+      }
+  }
+}
Index: vm/reference/gnu/classpath/jdwp/VMVirtualMachine.java
===================================================================
RCS file: vm/reference/gnu/classpath/jdwp/VMVirtualMachine.java
diff -N vm/reference/gnu/classpath/jdwp/VMVirtualMachine.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ vm/reference/gnu/classpath/jdwp/VMVirtualMachine.java       3 Sep 2005 
00:08:09 -0000
@@ -0,0 +1,318 @@
+/* VMVirtualMachine.java -- A reference implementation of a JDWP virtual
+   machine
+
+   Copyright (C) 2005 Free Software Foundation
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.classpath.jdwp;
+
+import gnu.classpath.jdwp.event.EventRequest;
+import gnu.classpath.jdwp.exception.InvalidClassException;
+import gnu.classpath.jdwp.exception.InvalidObjectException;
+import gnu.classpath.jdwp.id.ObjectId;
+import gnu.classpath.jdwp.id.ReferenceTypeId;
+import gnu.classpath.jdwp.util.LineTable;
+import gnu.classpath.jdwp.util.MethodResult;
+import gnu.classpath.jdwp.util.VariableTable;
+
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+/**
+ * A virtual machine according to JDWP.
+ *
+ * @author Keith Seitz  <address@hidden>
+ */
+public class VMVirtualMachine
+{
+  /**
+   * Suspend a thread
+   *
+   * @param  thread  the thread to suspend
+   */
+  public static native void suspendThread (Thread thread);
+
+  /**
+   * Suspend all threads
+   */
+  public static void suspendAllThreads ()
+  {
+    // Our JDWP thread group -- don't suspend any of those threads
+    Thread current = Thread.currentThread ();
+    ThreadGroup jdwpGroup = current.getThreadGroup ();
+
+    // Find the root ThreadGroup
+    ThreadGroup group = jdwpGroup;
+    ThreadGroup parent = group.getParent ();
+    while (parent != null)
+      {
+       group = parent;
+       parent = group.getParent ();
+      }
+    
+    // Get all the threads in the system
+    int num = group.activeCount ();
+    Thread[] threads = new Thread[num];
+    group.enumerate (threads);
+
+    for (int i = 0; i < num; ++i)
+      {
+       Thread t = threads[i];
+       if (t != null)
+         {
+           if (t.getThreadGroup () == jdwpGroup || t == current)
+             {
+               // Don't suspend the current thread or any JDWP thread
+               continue;
+             }
+           else
+             suspendThread (t);
+         }
+      }
+
+    // Now suspend the current thread
+    suspendThread (current);
+  }
+
+  /**
+   * Resume a thread. A thread must be resumed as many times
+   * as it has been suspended.
+   *
+   * @param  thread  the thread to resume
+   */
+  public static native void resumeThread (Thread thread);
+
+  /**
+   * Resume all threads. This simply decrements the thread's
+   * suspend count. It can not be used to force the application
+   * to run.
+   */
+  public static void resumeAllThreads ()
+  {
+    // Our JDWP thread group -- don't resume
+    Thread current = Thread.currentThread ();
+    ThreadGroup jdwpGroup = current.getThreadGroup ();
+
+    // Find the root ThreadGroup
+    ThreadGroup group = jdwpGroup;
+    ThreadGroup parent = group.getParent ();
+    while (parent != null)
+      {
+       group = parent;
+       parent = group.getParent ();
+      }
+    
+    // Get all the threads in the system
+    int num = group.activeCount ();
+    Thread[] threads = new Thread[num];
+    group.enumerate (threads);
+
+    for (int i = 0; i < num; ++i)
+      {
+       Thread t = threads[i];
+       if (t != null)
+         {
+           if (t.getThreadGroup () == jdwpGroup || t == current)
+             {
+               // Don't resume the current thread or any JDWP thread
+               continue;
+             }
+           else
+             resumeThread (t);
+         }
+      }
+  }
+
+  /**
+   * Get the suspend count for a give thread
+   *
+   * @param  thread  the thread whose suspend count is desired
+   * @return the number of times the thread has been suspended
+   */
+  public static native int getSuspendCount (Thread thread);
+ 
+  /**
+   * Returns a count of the number of loaded classes in the VM
+   */
+  public static native int getAllLoadedClassesCount ();
+
+  /**
+   * Returns an iterator over all the loaded classes in the VM
+   */
+  public static native Iterator getAllLoadedClasses ();
+
+  /**
+   * Returns the status of the given class
+   *
+   * @param  clazz  the class whose status is desired
+   * @return a flag containing the class's status
+   * @see JdwpConstants.ClassStatus
+   */
+  public static native int getClassStatus (Class clazz);
+
+
+  /**
+   * Returns the thread's call stack
+   *
+   * @param  thread  thread for which to get call stack
+   * @param  start   index of first frame to return
+   * @param  length  number of frames to return (-1 for all frames)
+   * @return a list of frames
+   */
+  public static native ArrayList getFrames (Thread thread, int strart,
+                                           int length);
+
+  /**
+   * Returns the frame for a given thread with the frame ID in
+   * the buffer
+   *
+   * I don't like this.
+   *
+   * @param  thread  the frame's thread
+   * @param  bb      buffer containing the frame's ID
+   * @return the desired frame
+   */
+  public static native VMFrame getFrame (Thread thread, ByteBuffer bb);
+
+  /**
+   * Returns the number of frames in the thread's stack
+   *
+   * @param  thread  the thread for which to get a frame count
+   * @return the number of frames in the thread's stack
+   */
+  public static native int getFrameCount (Thread thread);
+
+
+  /**
+   * Returns the status of a thread
+   *
+   * @param  thread  the thread for which to get status
+   * @return integer status of the thread
+   * @see JdwpConstants.ThreadStatus
+   */
+  public static native int getThreadStatus (Thread thread);
+
+  /**
+   * Returns a list of all classes which this class loader has been
+   * requested to load
+   *
+   * @param  cl  the class loader
+   * @return a list of all visible classes
+   */
+  public static native ArrayList getLoadRequests (ClassLoader cl);
+
+  /**
+   * Executes a method in the virtual machine
+   *
+   * @param  obj         instance in which to invoke method (null for static)
+   * @param  thread      the thread in which to invoke the method
+   * @param  clazz       the class in which the method is defined
+   * @param  method      the method to invoke
+   * @param  values      arguments to pass to method
+   * @param  nonVirtual  "otherwise, normal virtual invoke
+   *                     (instance methods only) "
+   * @return a result object containing the results of the invocation
+   */
+  public static native MethodResult executeMethod (Object obj, Thread thread,
+                                           Class clazz, Method method,
+                                           Object[] values,
+                                           boolean nonVirtual);
+
+  /**
+   * "Returns variable information for the method. The variable table
+   * includes arguments and locals declared within the method. For instance
+   * methods, the "this" reference is included in the table. Also, synthetic
+   * variables may be present."
+   *
+   * @param  clazz   the class in which the method is defined
+   * @param  method  the method for which variable information is desired
+   * @return a result object containing the information
+   */
+  public static native VariableTable getVarTable (Class clazz, Method method);
+
+  /**
+   * "Returns line number information for the method, if present. The line
+   * table maps source line numbers to the initial code index of the line.
+   * The line table is ordered by code index (from lowest to highest). The
+   * line number information is constant unless a new class definition is
+   * installed using RedefineClasses."
+   *
+   * @param  clazz   the class in which the method is defined
+   * @param  method  the method whose line table is desired
+   * @return a result object containing the line table
+   */
+  public static native LineTable getLineTable (Class clazz, Method method);
+
+  /**
+   * "Returns the name of source file in which a reference type was declared"
+   *
+   * @param  clazz  the class for which to return a source file
+   * @return a string containing the source file name; "no path information
+   *         for the file is included"
+   */
+  public static native String getSourceFile (Class clazz);
+
+  /**
+   * Register a request from the debugger
+   *
+   * Virtual machines have two options. Either do nothing and allow
+   * the event manager to take care of the request (useful for broadcast-type
+   * events like class prepare/load/unload, thread start/end, etc.)
+   * or do some internal work to set up the event notification (useful for
+   * execution-related events like breakpoints, single-stepping, etc.).
+   */
+  public static native void registerEvent (EventRequest request);
+
+  /**
+   * Unregisters the given request
+   *
+   * @param  request  the request to unregister
+   */
+  public static native void unregisterEvent (EventRequest request);
+
+
+  /**
+   * Clear all events of the given kind
+   *
+   * @param  kind  the type of events to clear
+   */
+  public static native void clearEvents (byte kind);
+}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]