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 VMVirtualMachine from Classpath


Hi,

I've committed the classpath bits of this patch upstream already, and I'd like to do the same for us. This patch updates the VM interface's executeMethod function, and fixes several related bugs with processing method invocations.

The cp-*.patch is the classpath/ portion and the gcj-*.patch is the gcj-specific change to support this.

Ok?
Keith

ChangeLog
2007-07-19  Keith Seitz  <keiths@redhat.com>

* gnu/classpath/jdwp/VMVirtualMachine.java (executeMethod):
Update from reference implementation.
* gnu/classpath/jdwp/natVMVirtualMachine.cc (executeMethod):
Update parameter list to match new VMVirtualMachine interface.
* classpath/lib/gnu/classpath/jdwp/processor/ClassTypeCommandSet.class:
Regenerate.
* classpath/lib/gnu/classpath/jdwp/processor/
ObjectReferenceCommandSet.class: Regenerate.
* classpath/lib/gnu/classpath/jdwp/value/ObjectValue.class: Regenerate.
* classpath/lib/gnu/classpath/jdwp/VMVirtualMachine.class: Regenerate.
* classpath/lib/gnu/classpath/jdwp/util/MethodResult.class: Regenerate.


classpath/ChangeLog
2007-07-19  Keith Seitz  <keiths@redhat.com>

        * gnu/classpath/jdwp/processor/ClassTypeCommandSet.java
        (executeInvokeMethod): No need to use ValueFactory any more;
        MethodResult.getReturnedValue now returns a Value.
        (executeNewInstance): Double-check that return result is
        an ObjectValue; throw JdwpInternalErrorException if it is not.
        (invokeMethod): Method IDs come from VMMethod, not VMIdManager.
        Arguments are Values not Objects.
        Use ValueFactory to create arguments.
        Pass invocation options to VMVirtualMachine.executeMethod.
        Don't do any thread suspend/resume work: VMVM.executeMethod
        will take care of it.
        * gnu/classpath/jdwp/processor/ObjectReferenceCommandSet.java
        (executeInvokeMethod): Method IDs come from VMMethod, not
        VMIdManager.
        Arguments should be Values instead of Objects.
        Use ValueFactory to create Values.
        Remove specific option handling and pass options to
        VMVirtualMachine.executeMethod.
        Remove thread suspension.
        Use MethodResult.getReturnedValue to get method's result.
        * gnu/classpath/jdwp/util/MethodResult.java
        (returnedValue): Change type to Value.
        (thrownException): Change type to Throwable.
        (resType): Remove.
        (MethodResult): New constructor.
        (setReturnedValue): Remove.
        (SetThrownException): Remove.
        (getResultType): Remove.
        (setResultType): Remove.
        * gnu/classpath/jdwp/value/ObjectValue.java (getValue):
        New method.
        * vm/reference/gnu/classpath/jdwp/VMVirtualMachine.java
        (executeMethod): Replace "nonVirtual" parameter with more
        generic "options" parameter.
        Replace java.lang.reflect.Method parameter with VMMethod.
        Replace Object[] parameter with Value[] parameter.
Index: gnu/classpath/jdwp/VMVirtualMachine.java
===================================================================
--- gnu/classpath/jdwp/VMVirtualMachine.java	(revision 125863)
+++ gnu/classpath/jdwp/VMVirtualMachine.java	(working copy)
@@ -46,8 +46,8 @@
 import gnu.classpath.jdwp.exception.JdwpException;
 import gnu.classpath.jdwp.util.MethodResult;
 import gnu.classpath.jdwp.util.MonitorInfo;
+import gnu.classpath.jdwp.value.Value;
 
-import java.lang.reflect.Method;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -296,21 +296,23 @@
     throws JdwpException;
 
   /**
-   * Executes a method in the virtual machine
+   * Executes a method in the virtual machine. The thread must already
+   * be suspended by a previous event. When the method invocation is
+   * complete, the thread (or all threads if INVOKE_SINGLE_THREADED is
+   * not set in options) must be suspended before this method returns.
    *
    * @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) "
+   * @param  options     invocation options
    * @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)
+					    Class clazz, VMMethod method,
+					    Value[] values,
+					    int options)
     throws JdwpException;
 
   /**
Index: gnu/classpath/jdwp/natVMVirtualMachine.cc
===================================================================
--- gnu/classpath/jdwp/natVMVirtualMachine.cc	(revision 125863)
+++ gnu/classpath/jdwp/natVMVirtualMachine.cc	(working copy)
@@ -695,9 +695,9 @@
 MethodResult *
 gnu::classpath::jdwp::VMVirtualMachine::
 executeMethod (MAYBE_UNUSED jobject obj, MAYBE_UNUSED Thread *thread,
-	       MAYBE_UNUSED jclass clazz, MAYBE_UNUSED reflect::Method *method,
-	       MAYBE_UNUSED jobjectArray values,
-	       MAYBE_UNUSED jboolean nonVirtual)
+	       MAYBE_UNUSED jclass clazz, MAYBE_UNUSED VMMethod *method,
+	       MAYBE_UNUSED JArray<value::Value *> *values,
+	       MAYBE_UNUSED jint options)
 {
   return NULL;
 }
Index: classpath/gnu/classpath/jdwp/processor/ClassTypeCommandSet.java
===================================================================
--- classpath/gnu/classpath/jdwp/processor/ClassTypeCommandSet.java	(revision 125863)
+++ classpath/gnu/classpath/jdwp/processor/ClassTypeCommandSet.java	(working copy)
@@ -41,6 +41,7 @@
 package gnu.classpath.jdwp.processor;
 
 import gnu.classpath.jdwp.JdwpConstants;
+import gnu.classpath.jdwp.VMMethod;
 import gnu.classpath.jdwp.VMVirtualMachine;
 import gnu.classpath.jdwp.exception.InvalidFieldException;
 import gnu.classpath.jdwp.exception.JdwpException;
@@ -49,13 +50,13 @@
 import gnu.classpath.jdwp.id.ObjectId;
 import gnu.classpath.jdwp.id.ReferenceTypeId;
 import gnu.classpath.jdwp.util.MethodResult;
+import gnu.classpath.jdwp.value.ObjectValue;
 import gnu.classpath.jdwp.value.Value;
 import gnu.classpath.jdwp.value.ValueFactory;
 
 import java.io.DataOutputStream;
 import java.io.IOException;
 import java.lang.reflect.Field;
-import java.lang.reflect.Method;
 import java.nio.ByteBuffer;
 
 /**
@@ -151,12 +152,9 @@
   {
     MethodResult mr = invokeMethod(bb);
 
-    Object value = mr.getReturnedValue();
-    Exception exception = mr.getThrownException();
+    Throwable exception = mr.getThrownException();
     ObjectId eId = idMan.getObjectId(exception);
-
-    Value val = ValueFactory.createFromObject(value, mr.getResultType());
-    val.writeTagged(os);
+    mr.getReturnedValue().writeTagged(os);
     eId.writeTagged(os);
   }
 
@@ -164,10 +162,14 @@
       throws JdwpException, IOException
   {
     MethodResult mr = invokeMethod(bb);
+    Throwable exception = mr.getThrownException();
 
-    Object obj = mr.getReturnedValue();
-    ObjectId oId = idMan.getObjectId(obj);
-    Exception exception = mr.getThrownException();
+    if (exception == null && ! (mr.getReturnedValue() instanceof ObjectValue))
+      throw new JdwpInternalErrorException("new instance returned non-object");
+
+    ObjectValue ov = (ObjectValue) mr.getReturnedValue();
+    ObjectId oId = idMan.getObjectId(ov.getValue());
+
     ObjectId eId = idMan.getObjectId(exception);
 
     oId.writeTagged(os);
@@ -177,8 +179,8 @@
   /**
    * Execute the static method and return the resulting MethodResult.
    */
-  private MethodResult invokeMethod(ByteBuffer bb) throws JdwpException,
-      IOException
+  private MethodResult invokeMethod(ByteBuffer bb)
+    throws JdwpException, IOException
   {
     ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
     Class clazz = refId.getType();
@@ -186,42 +188,18 @@
     ObjectId tId = idMan.readObjectId(bb);
     Thread thread = (Thread) tId.getObject();
 
-    ObjectId mId = idMan.readObjectId(bb);
-    Method method = (Method) mId.getObject();
+    VMMethod method = VMMethod.readId(clazz, bb);
 
     int args = bb.getInt();
-    Object[] values = new Object[args];
+    Value[] values = new Value[args];
 
     for (int i = 0; i < args; i++)
-      {
-        values[i] = Value.getTaggedObject(bb);
-      }
+      values[i] = ValueFactory.createFromTagged(bb);
 
     int invokeOpts = bb.getInt();
-    boolean suspend = ((invokeOpts
-			& JdwpConstants.InvokeOptions.INVOKE_SINGLE_THREADED)
-		       != 0);
-    try
-      {
-        if (suspend)
-	  VMVirtualMachine.suspendAllThreads ();
-
-        MethodResult mr = VMVirtualMachine.executeMethod(null, thread,
-							 clazz, method,
-							 values, false);
-        mr.setResultType(method.getReturnType());
-        
-        if (suspend)
-	  VMVirtualMachine.resumeAllThreads ();
-
-        return mr;
-      }
-    catch (Exception ex)
-      {
-        if (suspend)
-	  VMVirtualMachine.resumeAllThreads ();
-
-        throw new JdwpInternalErrorException(ex);
-      }
+    MethodResult mr = VMVirtualMachine.executeMethod(null, thread,
+						     clazz, method,
+						     values, invokeOpts);
+    return mr;
   }
 }
Index: classpath/gnu/classpath/jdwp/processor/ObjectReferenceCommandSet.java
===================================================================
--- classpath/gnu/classpath/jdwp/processor/ObjectReferenceCommandSet.java	(revision 125863)
+++ classpath/gnu/classpath/jdwp/processor/ObjectReferenceCommandSet.java	(working copy)
@@ -40,6 +40,7 @@
 package gnu.classpath.jdwp.processor;
 
 import gnu.classpath.jdwp.JdwpConstants;
+import gnu.classpath.jdwp.VMMethod;
 import gnu.classpath.jdwp.VMVirtualMachine;
 import gnu.classpath.jdwp.exception.InvalidFieldException;
 import gnu.classpath.jdwp.exception.JdwpException;
@@ -213,42 +214,21 @@
     ReferenceTypeId rid = idMan.readReferenceTypeId(bb);
     Class clazz = rid.getType();
 
-    ObjectId mid = idMan.readObjectId(bb);
-    Method method = (Method) mid.getObject();
+    VMMethod method = VMMethod.readId(clazz, bb);
 
     int args = bb.getInt();
-    Object[] values = new Object[args];
+    Value[] values = new Value[args];
 
     for (int i = 0; i < args; i++)
-      {
-        values[i] = Value.getTaggedObject(bb);
-      }
+      values[i] = ValueFactory.createFromTagged(bb);
 
     int invokeOptions = bb.getInt();
-    boolean suspend = ((invokeOptions
-			& JdwpConstants.InvokeOptions.INVOKE_SINGLE_THREADED)
-		       != 0);
-    if (suspend)
-      {
-	// We must suspend all other running threads first
-        VMVirtualMachine.suspendAllThreads ();
-      }
-
-    boolean nonVirtual = ((invokeOptions
-			   & JdwpConstants.InvokeOptions.INVOKE_NONVIRTUAL)
-			  != 0);
-
     MethodResult mr = VMVirtualMachine.executeMethod(obj, thread,
 						     clazz, method,
-						     values, nonVirtual);
-    mr.setResultType (method.getReturnType());
-    
-    Object value = mr.getReturnedValue();
-    Exception exception = mr.getThrownException();
-
+						     values, invokeOptions);
+    Throwable exception = mr.getThrownException();
     ObjectId eId = idMan.getObjectId(exception);
-    Value val = ValueFactory.createFromObject(value, mr.getResultType());
-    val.writeTagged(os);
+    mr.getReturnedValue().writeTagged(os);
     eId.writeTagged(os);
   }
 
Index: classpath/gnu/classpath/jdwp/util/MethodResult.java
===================================================================
--- classpath/gnu/classpath/jdwp/util/MethodResult.java	(revision 125863)
+++ classpath/gnu/classpath/jdwp/util/MethodResult.java	(working copy)
@@ -1,6 +1,6 @@
 /* MethodResult.java -- class to wrap around values returned from a Method call
    in the VM 
-   Copyright (C) 2005 Free Software Foundation
+   Copyright (C) 2005, 2007 Free Software Foundation
 
 This file is part of GNU Classpath.
 
@@ -40,6 +40,8 @@
 
 package gnu.classpath.jdwp.util;
 
+import gnu.classpath.jdwp.value.Value;
+
 /**
  * A class to wrap around values returned from a Method call in the VM.
  * 
@@ -48,42 +50,37 @@
 public class MethodResult
 {
   // The Object returned by the executing method
-  private Object returnedValue;
+  private Value returnedValue;
   
   // Any Exception that was thrown by the executing method
-  private Exception thrownException;
+  private Throwable thrownException;
   
-  // The type of this result
-  private Class resType;
-
-  public Object getReturnedValue()
+  /**
+   * Constructs a new MethodResult object
+   *
+   * @param return_value the return value of the method invocation
+   * @param exc exception thrown during the invocation (or null if none)
+   */
+  public MethodResult (Value return_value, Throwable exc)
   {
-    return returnedValue;
+    returnedValue = return_value;
+    thrownException = exc;
   }
 
-  public void setReturnedValue(Object returnedValue)
+  /**
+   * Returns the return value of the method invocation
+   */
+  public Value getReturnedValue()
   {
-    this.returnedValue = returnedValue;
+    return returnedValue;
   }
 
-  public Exception getThrownException()
+  /**
+   * Returns the exception thrown during the method invocation
+   * (or null if none)
+   */
+  public Throwable getThrownException()
   {
     return thrownException;
   }
-
-  public void setThrownException(Exception thrownException)
-  {
-    this.thrownException = thrownException;
-  }
-  
-  public Class getResultType()
-  {
-    return resType;
-  }
-  
-  public void setResultType(Class type)
-  {
-    resType = type;
-  }
-  
 }
Index: classpath/gnu/classpath/jdwp/value/ObjectValue.java
===================================================================
--- classpath/gnu/classpath/jdwp/value/ObjectValue.java	(revision 125863)
+++ classpath/gnu/classpath/jdwp/value/ObjectValue.java	(working copy)
@@ -67,6 +67,16 @@
   }
   
   /**
+   * Get the value held in this Value
+   * 
+   * @return the value represented by this Value object
+   */
+  public Object getValue()
+  {
+    return _value;
+  }
+
+  /**
    * Return an object representing this type
    * 
    * @return an Object represntation of this value
Index: classpath/vm/reference/gnu/classpath/jdwp/VMVirtualMachine.java
===================================================================
--- classpath/vm/reference/gnu/classpath/jdwp/VMVirtualMachine.java	(revision 125863)
+++ classpath/vm/reference/gnu/classpath/jdwp/VMVirtualMachine.java	(working copy)
@@ -46,8 +46,8 @@
 import gnu.classpath.jdwp.exception.JdwpException;
 import gnu.classpath.jdwp.util.MethodResult;
 import gnu.classpath.jdwp.util.MonitorInfo;
+import gnu.classpath.jdwp.value.Value;
 
-import java.lang.reflect.Method;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -284,21 +284,23 @@
     throws JdwpException;
 
   /**
-   * Executes a method in the virtual machine
+   * Executes a method in the virtual machine. The thread must already
+   * be suspended by a previous event. When the method invocation is
+   * complete, the thread (or all threads if INVOKE_SINGLE_THREADED is
+   * not set in options) must be suspended before this method returns.
    *
    * @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) "
+   * @param  options     invocation options
    * @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)
+  public static native MethodResult executeMethod (Object obj, Thread thread,
+					    Class clazz, VMMethod method,
+					    Value[] values,
+					    int options)
     throws JdwpException;
 
   /**
Index: gnu/classpath/jdwp/VMVirtualMachine.java
===================================================================
--- gnu/classpath/jdwp/VMVirtualMachine.java	(revision 125863)
+++ gnu/classpath/jdwp/VMVirtualMachine.java	(working copy)
@@ -46,8 +46,8 @@
 import gnu.classpath.jdwp.exception.JdwpException;
 import gnu.classpath.jdwp.util.MethodResult;
 import gnu.classpath.jdwp.util.MonitorInfo;
+import gnu.classpath.jdwp.value.Value;
 
-import java.lang.reflect.Method;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -296,21 +296,23 @@
     throws JdwpException;
 
   /**
-   * Executes a method in the virtual machine
+   * Executes a method in the virtual machine. The thread must already
+   * be suspended by a previous event. When the method invocation is
+   * complete, the thread (or all threads if INVOKE_SINGLE_THREADED is
+   * not set in options) must be suspended before this method returns.
    *
    * @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) "
+   * @param  options     invocation options
    * @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)
+					    Class clazz, VMMethod method,
+					    Value[] values,
+					    int options)
     throws JdwpException;
 
   /**

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