use of com.sun.jdi.InvocationException in project che by eclipse.
the class Evaluator method invokeMethod.
public ExpressionValue invokeMethod(Value value, String name, List<Value> arguments) {
if (!(value instanceof ObjectReference)) {
throw new ExpressionException("Value is not object. Cannot invoke method " + name);
}
ObjectReference object = (ObjectReference) value;
ReferenceType type = object.referenceType();
List<Method> methods = type.methodsByName(name);
Method method = findMethod(methods, arguments);
if (method == null) {
throw new ExpressionException("No method with name " + name + " matched to specified arguments for " + type.name());
}
try {
return new ReadOnlyValue(object.invokeMethod(thread, method, arguments, 0));
} catch (InvalidTypeException | ClassNotLoadedException | IncompatibleThreadStateException | InvocationException e) {
throw new ExpressionException(e.getMessage(), e);
}
}
use of com.sun.jdi.InvocationException in project jdk8u_jdk by JetBrains.
the class OomDebugTest method test1.
/*
* Test case: Object reference as method parameter.
*/
// called via reflection
@SuppressWarnings("unused")
private void test1() throws Exception {
System.out.println("DEBUG: ------------> Running test1");
try {
Field field = targetClass.fieldByName("fooCls");
ClassType clsType = (ClassType) field.type();
Method constructor = getConstructorForClass(clsType);
for (int i = 0; i < 15; i++) {
@SuppressWarnings({ "rawtypes", "unchecked" }) ObjectReference objRef = clsType.newInstance(mainThread, constructor, new ArrayList(0), ObjectReference.INVOKE_NONVIRTUAL);
if (objRef.isCollected()) {
System.out.println("DEBUG: Object got GC'ed before we can use it. NO-OP.");
continue;
}
invoke("testMethod", "(LOomDebugTestTarget$FooCls;)V", objRef);
}
} catch (InvocationException e) {
handleFailure(e);
}
}
use of com.sun.jdi.InvocationException in project jdk8u_jdk by JetBrains.
the class InvokableTypeImpl method invokeMethod.
/**
* Method invocation support.
* Shared by ClassType and InterfaceType
* @param threadIntf the thread in which to invoke.
* @param methodIntf method the {@link Method} to invoke.
* @param origArguments the list of {@link Value} arguments bound to the
* invoked method. Values from the list are assigned to arguments
* in the order they appear in the method signature.
* @param options the integer bit flag options.
* @return a {@link Value} mirror of the invoked method's return value.
* @throws java.lang.IllegalArgumentException if the method is not
* a member of this type, if the size of the argument list
* does not match the number of declared arguments for the method, or
* if the method is not static or is a static initializer.
* @throws {@link InvalidTypeException} if any argument in the
* argument list is not assignable to the corresponding method argument
* type.
* @throws ClassNotLoadedException if any argument type has not yet been loaded
* through the appropriate class loader.
* @throws IncompatibleThreadStateException if the specified thread has not
* been suspended by an event.
* @throws InvocationException if the method invocation resulted in
* an exception in the target VM.
* @throws InvalidTypeException If the arguments do not meet this requirement --
* Object arguments must be assignment compatible with the argument
* type. This implies that the argument type must be
* loaded through the enclosing class's class loader.
* Primitive arguments must be either assignment compatible with the
* argument type or must be convertible to the argument type without loss
* of information. See JLS section 5.2 for more information on assignment
* compatibility.
* @throws VMCannotBeModifiedException if the VirtualMachine is read-only - see {@link VirtualMachine#canBeModified()}.
*/
public final Value invokeMethod(ThreadReference threadIntf, Method methodIntf, List<? extends Value> origArguments, int options) throws InvalidTypeException, ClassNotLoadedException, IncompatibleThreadStateException, InvocationException {
validateMirror(threadIntf);
validateMirror(methodIntf);
validateMirrorsOrNulls(origArguments);
MethodImpl method = (MethodImpl) methodIntf;
ThreadReferenceImpl thread = (ThreadReferenceImpl) threadIntf;
validateMethodInvocation(method);
List<? extends Value> arguments = method.validateAndPrepareArgumentsForInvoke(origArguments);
ValueImpl[] args = arguments.toArray(new ValueImpl[0]);
InvocationResult ret;
try {
PacketStream stream = sendInvokeCommand(thread, method, args, options);
ret = waitForReply(stream);
} catch (JDWPException exc) {
if (exc.errorCode() == JDWP.Error.INVALID_THREAD) {
throw new IncompatibleThreadStateException();
} else {
throw exc.toJDIException();
}
}
/*
* There is an implict VM-wide suspend at the conclusion
* of a normal (non-single-threaded) method invoke
*/
if ((options & ClassType.INVOKE_SINGLE_THREADED) == 0) {
vm.notifySuspend();
}
if (ret.getException() != null) {
throw new InvocationException(ret.getException());
} else {
return ret.getResult();
}
}
Aggregations