Commit a7eeed04 by Keith Seitz Committed by Keith Seitz

Update from classpath trunk:

        * 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.

From-SVN: r125895
parent 7e657ec2
2007-07-20 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.
2007-05-19 Andreas Tobler <a.tobler@schweiz.org> 2007-05-19 Andreas Tobler <a.tobler@schweiz.org>
PR libgcj/31659 PR libgcj/31659
......
...@@ -41,6 +41,7 @@ exception statement from your version. */ ...@@ -41,6 +41,7 @@ exception statement from your version. */
package gnu.classpath.jdwp.processor; package gnu.classpath.jdwp.processor;
import gnu.classpath.jdwp.JdwpConstants; import gnu.classpath.jdwp.JdwpConstants;
import gnu.classpath.jdwp.VMMethod;
import gnu.classpath.jdwp.VMVirtualMachine; import gnu.classpath.jdwp.VMVirtualMachine;
import gnu.classpath.jdwp.exception.InvalidFieldException; import gnu.classpath.jdwp.exception.InvalidFieldException;
import gnu.classpath.jdwp.exception.JdwpException; import gnu.classpath.jdwp.exception.JdwpException;
...@@ -49,13 +50,13 @@ import gnu.classpath.jdwp.exception.NotImplementedException; ...@@ -49,13 +50,13 @@ import gnu.classpath.jdwp.exception.NotImplementedException;
import gnu.classpath.jdwp.id.ObjectId; import gnu.classpath.jdwp.id.ObjectId;
import gnu.classpath.jdwp.id.ReferenceTypeId; import gnu.classpath.jdwp.id.ReferenceTypeId;
import gnu.classpath.jdwp.util.MethodResult; import gnu.classpath.jdwp.util.MethodResult;
import gnu.classpath.jdwp.value.ObjectValue;
import gnu.classpath.jdwp.value.Value; import gnu.classpath.jdwp.value.Value;
import gnu.classpath.jdwp.value.ValueFactory; import gnu.classpath.jdwp.value.ValueFactory;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
/** /**
...@@ -151,12 +152,9 @@ public class ClassTypeCommandSet ...@@ -151,12 +152,9 @@ public class ClassTypeCommandSet
{ {
MethodResult mr = invokeMethod(bb); MethodResult mr = invokeMethod(bb);
Object value = mr.getReturnedValue(); Throwable exception = mr.getThrownException();
Exception exception = mr.getThrownException();
ObjectId eId = idMan.getObjectId(exception); ObjectId eId = idMan.getObjectId(exception);
mr.getReturnedValue().writeTagged(os);
Value val = ValueFactory.createFromObject(value, mr.getResultType());
val.writeTagged(os);
eId.writeTagged(os); eId.writeTagged(os);
} }
...@@ -164,10 +162,14 @@ public class ClassTypeCommandSet ...@@ -164,10 +162,14 @@ public class ClassTypeCommandSet
throws JdwpException, IOException throws JdwpException, IOException
{ {
MethodResult mr = invokeMethod(bb); MethodResult mr = invokeMethod(bb);
Throwable 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());
Object obj = mr.getReturnedValue();
ObjectId oId = idMan.getObjectId(obj);
Exception exception = mr.getThrownException();
ObjectId eId = idMan.getObjectId(exception); ObjectId eId = idMan.getObjectId(exception);
oId.writeTagged(os); oId.writeTagged(os);
...@@ -177,8 +179,8 @@ public class ClassTypeCommandSet ...@@ -177,8 +179,8 @@ public class ClassTypeCommandSet
/** /**
* Execute the static method and return the resulting MethodResult. * Execute the static method and return the resulting MethodResult.
*/ */
private MethodResult invokeMethod(ByteBuffer bb) throws JdwpException, private MethodResult invokeMethod(ByteBuffer bb)
IOException throws JdwpException, IOException
{ {
ReferenceTypeId refId = idMan.readReferenceTypeId(bb); ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
Class clazz = refId.getType(); Class clazz = refId.getType();
...@@ -186,42 +188,18 @@ public class ClassTypeCommandSet ...@@ -186,42 +188,18 @@ public class ClassTypeCommandSet
ObjectId tId = idMan.readObjectId(bb); ObjectId tId = idMan.readObjectId(bb);
Thread thread = (Thread) tId.getObject(); Thread thread = (Thread) tId.getObject();
ObjectId mId = idMan.readObjectId(bb); VMMethod method = VMMethod.readId(clazz, bb);
Method method = (Method) mId.getObject();
int args = bb.getInt(); int args = bb.getInt();
Object[] values = new Object[args]; Value[] values = new Value[args];
for (int i = 0; i < args; i++) for (int i = 0; i < args; i++)
{ values[i] = ValueFactory.createFromTagged(bb);
values[i] = Value.getTaggedObject(bb);
}
int invokeOpts = bb.getInt(); int invokeOpts = bb.getInt();
boolean suspend = ((invokeOpts MethodResult mr = VMVirtualMachine.executeMethod(null, thread,
& JdwpConstants.InvokeOptions.INVOKE_SINGLE_THREADED) clazz, method,
!= 0); values, invokeOpts);
try return mr;
{
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);
}
} }
} }
...@@ -40,6 +40,7 @@ exception statement from your version. */ ...@@ -40,6 +40,7 @@ exception statement from your version. */
package gnu.classpath.jdwp.processor; package gnu.classpath.jdwp.processor;
import gnu.classpath.jdwp.JdwpConstants; import gnu.classpath.jdwp.JdwpConstants;
import gnu.classpath.jdwp.VMMethod;
import gnu.classpath.jdwp.VMVirtualMachine; import gnu.classpath.jdwp.VMVirtualMachine;
import gnu.classpath.jdwp.exception.InvalidFieldException; import gnu.classpath.jdwp.exception.InvalidFieldException;
import gnu.classpath.jdwp.exception.JdwpException; import gnu.classpath.jdwp.exception.JdwpException;
...@@ -213,42 +214,21 @@ public class ObjectReferenceCommandSet ...@@ -213,42 +214,21 @@ public class ObjectReferenceCommandSet
ReferenceTypeId rid = idMan.readReferenceTypeId(bb); ReferenceTypeId rid = idMan.readReferenceTypeId(bb);
Class clazz = rid.getType(); Class clazz = rid.getType();
ObjectId mid = idMan.readObjectId(bb); VMMethod method = VMMethod.readId(clazz, bb);
Method method = (Method) mid.getObject();
int args = bb.getInt(); int args = bb.getInt();
Object[] values = new Object[args]; Value[] values = new Value[args];
for (int i = 0; i < args; i++) for (int i = 0; i < args; i++)
{ values[i] = ValueFactory.createFromTagged(bb);
values[i] = Value.getTaggedObject(bb);
}
int invokeOptions = bb.getInt(); 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, MethodResult mr = VMVirtualMachine.executeMethod(obj, thread,
clazz, method, clazz, method,
values, nonVirtual); values, invokeOptions);
mr.setResultType (method.getReturnType()); Throwable exception = mr.getThrownException();
Object value = mr.getReturnedValue();
Exception exception = mr.getThrownException();
ObjectId eId = idMan.getObjectId(exception); ObjectId eId = idMan.getObjectId(exception);
Value val = ValueFactory.createFromObject(value, mr.getResultType()); mr.getReturnedValue().writeTagged(os);
val.writeTagged(os);
eId.writeTagged(os); eId.writeTagged(os);
} }
......
/* MethodResult.java -- class to wrap around values returned from a Method call /* MethodResult.java -- class to wrap around values returned from a Method call
in the VM in the VM
Copyright (C) 2005 Free Software Foundation Copyright (C) 2005, 2007 Free Software Foundation
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -40,6 +40,8 @@ exception statement from your version. */ ...@@ -40,6 +40,8 @@ exception statement from your version. */
package gnu.classpath.jdwp.util; 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. * A class to wrap around values returned from a Method call in the VM.
* *
...@@ -48,42 +50,37 @@ package gnu.classpath.jdwp.util; ...@@ -48,42 +50,37 @@ package gnu.classpath.jdwp.util;
public class MethodResult public class MethodResult
{ {
// The Object returned by the executing method // The Object returned by the executing method
private Object returnedValue; private Value returnedValue;
// Any Exception that was thrown by the executing method // Any Exception that was thrown by the executing method
private Exception thrownException; private Throwable thrownException;
// The type of this result /**
private Class resType; * Constructs a new MethodResult object
*
public Object getReturnedValue() * @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; return thrownException;
} }
public void setThrownException(Exception thrownException)
{
this.thrownException = thrownException;
}
public Class getResultType()
{
return resType;
}
public void setResultType(Class type)
{
resType = type;
}
} }
...@@ -67,6 +67,16 @@ public final class ObjectValue ...@@ -67,6 +67,16 @@ public final class ObjectValue
} }
/** /**
* 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 representing this type
* *
* @return an Object represntation of this value * @return an Object represntation of this value
......
...@@ -46,8 +46,8 @@ import gnu.classpath.jdwp.exception.InvalidMethodException; ...@@ -46,8 +46,8 @@ import gnu.classpath.jdwp.exception.InvalidMethodException;
import gnu.classpath.jdwp.exception.JdwpException; import gnu.classpath.jdwp.exception.JdwpException;
import gnu.classpath.jdwp.util.MethodResult; import gnu.classpath.jdwp.util.MethodResult;
import gnu.classpath.jdwp.util.MonitorInfo; import gnu.classpath.jdwp.util.MonitorInfo;
import gnu.classpath.jdwp.value.Value;
import java.lang.reflect.Method;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
...@@ -284,21 +284,23 @@ public class VMVirtualMachine ...@@ -284,21 +284,23 @@ public class VMVirtualMachine
throws JdwpException; 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 obj instance in which to invoke method (null for static)
* @param thread the thread in which to invoke the method * @param thread the thread in which to invoke the method
* @param clazz the class in which the method is defined * @param clazz the class in which the method is defined
* @param method the method to invoke * @param method the method to invoke
* @param values arguments to pass to method * @param values arguments to pass to method
* @param nonVirtual "otherwise, normal virtual invoke * @param options invocation options
* (instance methods only) "
* @return a result object containing the results of the invocation * @return a result object containing the results of the invocation
*/ */
public static native MethodResult executeMethod(Object obj, Thread thread, public static native MethodResult executeMethod (Object obj, Thread thread,
Class clazz, Method method, Class clazz, VMMethod method,
Object[] values, Value[] values,
boolean nonVirtual) int options)
throws JdwpException; throws JdwpException;
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment