com.sun.jdi.ClassType Java Examples

The following examples show how to use com.sun.jdi.ClassType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InvokableTypeImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Shared implementation of {@linkplain ClassType#allMethods()} and
 * {@linkplain InterfaceType#allMethods()}
 * @return A list of all methods (recursively)
 */
public final List<Method> allMethods() {
    ArrayList<Method> list = new ArrayList<>(methods());
    ClassType clazz = superclass();
    while (clazz != null) {
        list.addAll(clazz.methods());
        clazz = clazz.superclass();
    }
    /*
     * Avoid duplicate checking on each method by iterating through
     * duplicate-free allInterfaces() rather than recursing
     */
    for (InterfaceType interfaze : getAllInterfaces()) {
        list.addAll(interfaze.methods());
    }
    return list;
}
 
Example #2
Source File: OomDebugTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unused") // called via reflection
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);
    }
}
 
Example #3
Source File: OomDebugTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unused") // called via reflection
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);
    }
}
 
Example #4
Source File: OomDebugTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unused") // called via reflection
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);
    }
}
 
Example #5
Source File: InvokableTypeImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Shared implementation of {@linkplain ClassType#allMethods()} and
 * {@linkplain InterfaceType#allMethods()}
 * @return A list of all methods (recursively)
 */
public final List<Method> allMethods() {
    ArrayList<Method> list = new ArrayList<>(methods());
    ClassType clazz = superclass();
    while (clazz != null) {
        list.addAll(clazz.methods());
        clazz = clazz.superclass();
    }
    /*
     * Avoid duplicate checking on each method by iterating through
     * duplicate-free allInterfaces() rather than recursing
     */
    for (InterfaceType interfaze : getAllInterfaces()) {
        list.addAll(interfaze.methods());
    }
    return list;
}
 
Example #6
Source File: InvokableTypeImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Shared implementation of {@linkplain ClassType#allMethods()} and
 * {@linkplain InterfaceType#allMethods()}
 * @return A list of all methods (recursively)
 */
public final List<Method> allMethods() {
    ArrayList<Method> list = new ArrayList<>(methods());
    ClassType clazz = superclass();
    while (clazz != null) {
        list.addAll(clazz.methods());
        clazz = clazz.superclass();
    }
    /*
     * Avoid duplicate checking on each method by iterating through
     * duplicate-free allInterfaces() rather than recursing
     */
    for (InterfaceType interfaze : getAllInterfaces()) {
        list.addAll(interfaze.methods());
    }
    return list;
}
 
Example #7
Source File: InvokableTypeImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Shared implementation of {@linkplain ClassType#allMethods()} and
 * {@linkplain InterfaceType#allMethods()}
 * @return A list of all methods (recursively)
 */
public final List<Method> allMethods() {
    ArrayList<Method> list = new ArrayList<>(methods());
    ClassType clazz = superclass();
    while (clazz != null) {
        list.addAll(clazz.methods());
        clazz = clazz.superclass();
    }
    /*
     * Avoid duplicate checking on each method by iterating through
     * duplicate-free allInterfaces() rather than recursing
     */
    for (InterfaceType interfaze : getAllInterfaces()) {
        list.addAll(interfaze.methods());
    }
    return list;
}
 
Example #8
Source File: InvokableTypeImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private PacketStream sendInvokeCommand(final ThreadReferenceImpl thread,
                                       final MethodImpl method,
                                       final ValueImpl[] args,
                                       final int options) {
    /*
     * Cache the values of args when TRACE_SENDS is enabled, for later printing.
     * If not cached, printing causes a remote call while synchronized, and deadlock.
     */
    if ((vm.traceFlags & VirtualMachineImpl.TRACE_SENDS) != 0) {
       for (ValueImpl arg: args) {
          arg.toString();
       }
    }
    CommandSender sender = getInvokeMethodSender(thread, method, args, options);
    PacketStream stream;
    if ((options & ClassType.INVOKE_SINGLE_THREADED) != 0) {
        stream = thread.sendResumingCommand(sender);
    } else {
        stream = vm.sendResumingCommand(sender);
    }
    return stream;
}
 
Example #9
Source File: InvokableTypeImpl.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Shared implementation of {@linkplain ClassType#allMethods()} and
 * {@linkplain InterfaceType#allMethods()}
 * @return A list of all methods (recursively)
 */
public final List<Method> allMethods() {
    ArrayList<Method> list = new ArrayList<>(methods());
    ClassType clazz = superclass();
    while (clazz != null) {
        list.addAll(clazz.methods());
        clazz = clazz.superclass();
    }
    /*
     * Avoid duplicate checking on each method by iterating through
     * duplicate-free allInterfaces() rather than recursing
     */
    for (InterfaceType interfaze : getAllInterfaces()) {
        list.addAll(interfaze.methods());
    }
    return list;
}
 
Example #10
Source File: AWTGrabHandler.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private boolean ungrabWindowAWT(ThreadReference tr, ObjectReference grabbedWindow) {
    // Call XBaseWindow.ungrabInput()
    try {
        VirtualMachine vm = MirrorWrapper.virtualMachine(grabbedWindow);
        List<ReferenceType> xbaseWindowClassesByName = VirtualMachineWrapper.classesByName(vm, "sun.awt.X11.XBaseWindow");
        if (xbaseWindowClassesByName.isEmpty()) {
            logger.info("Unable to release X grab, no XBaseWindow class in target VM "+VirtualMachineWrapper.description(vm));
            return false;
        }
        ClassType XBaseWindowClass = (ClassType) xbaseWindowClassesByName.get(0);
        Method ungrabInput = XBaseWindowClass.concreteMethodByName("ungrabInput", "()V");
        if (ungrabInput == null) {
            logger.info("Unable to release X grab, method ungrabInput not found in target VM "+VirtualMachineWrapper.description(vm));
            return false;
        }
        XBaseWindowClass.invokeMethod(tr, ungrabInput, Collections.<Value>emptyList(), ObjectReference.INVOKE_SINGLE_THREADED);
    } catch (VMDisconnectedExceptionWrapper vmdex) {
        return true; // Disconnected, all is good.
    } catch (Exception ex) {
        logger.log(Level.INFO, "Unable to release X grab.", ex);
        return false;
    }
    return true;
}
 
Example #11
Source File: AWTGrabHandler.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void ungrabWindowFX(ClassType WindowClass, ObjectReference w, ThreadReference tr) throws Exception {
    // javafx.stage.Window w
    // w.focusGrabCounter
    // while (focusGrabCounter-- > 0) {
    //     w.impl_getPeer().ungrabFocus(); OR: w.impl_peer.ungrabFocus();
    // }
    Field focusGrabCounterField = WindowClass.fieldByName("focusGrabCounter");
    if (focusGrabCounterField == null) {
        logger.info("Unable to release FX X grab, no focusGrabCounter field in "+w);
        return ;
    }
    Value focusGrabCounterValue = w.getValue(focusGrabCounterField);
    if (!(focusGrabCounterValue instanceof IntegerValue)) {
        logger.info("Unable to release FX X grab, focusGrabCounter does not have an integer value in "+w);
        return ;
    }
    int focusGrabCounter = ((IntegerValue) focusGrabCounterValue).intValue();
    if (logger.isLoggable(Level.FINE)) {
        logger.fine("Focus grab counter of "+w+" is: "+focusGrabCounter);
    }
    while (focusGrabCounter-- > 0) {
        //Method impl_getPeerMethod = WindowClass.concreteMethodByName("impl_getPeer", "");
        Field impl_peerField = WindowClass.fieldByName("impl_peer");
        if (impl_peerField == null) {
            logger.info("Unable to release FX X grab, no impl_peer field in "+w);
            return ;
        }
        ObjectReference impl_peer = (ObjectReference) w.getValue(impl_peerField);
        if (impl_peer == null) {
            continue;
        }
        InterfaceType TKStageClass = (InterfaceType) w.virtualMachine().classesByName("com.sun.javafx.tk.TKStage").get(0);
        Method ungrabFocusMethod = TKStageClass.methodsByName("ungrabFocus", "()V").get(0);
        impl_peer.invokeMethod(tr, ungrabFocusMethod, Collections.<Value>emptyList(), ObjectReference.INVOKE_SINGLE_THREADED);
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("FX Window "+w+" was successfully ungrabbed.");
        }
    }
}
 
Example #12
Source File: InvokableTypeImpl.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Shared implementation of {@linkplain ClassType#allMethods()} and
 * {@linkplain InterfaceType#allMethods()}
 * @return A list of all methods (recursively)
 */
public final List<Method> allMethods() {
    ArrayList<Method> list = new ArrayList<>(methods());
    ClassType clazz = superclass();
    while (clazz != null) {
        list.addAll(clazz.methods());
        clazz = clazz.superclass();
    }
    /*
     * Avoid duplicate checking on each method by iterating through
     * duplicate-free allInterfaces() rather than recursing
     */
    for (InterfaceType interfaze : getAllInterfaces()) {
        list.addAll(interfaze.methods());
    }
    return list;
}
 
Example #13
Source File: VisualDebuggerListener.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void stopDebuggerRemoteService(JPDADebugger d) {
    ClassObjectReference serviceClass = RemoteServices.getServiceClass(d, RemoteServices.ServiceType.AWT);
    if (serviceClass == null) {
        return ;
    }
    try {
        ReferenceType serviceType = serviceClass.reflectedType();
        Field awtAccessLoop = serviceType.fieldByName("awtAccessLoop"); // NOI18N
        if (awtAccessLoop != null) {
            ((ClassType) serviceType).setValue(awtAccessLoop, serviceClass.virtualMachine().mirrorOf(false));
        }
        serviceClass.enableCollection();
    } catch (VMDisconnectedException vdex) {
        // Ignore
    } catch (Exception ex) {
        Exceptions.printStackTrace(ex);
    }
}
 
Example #14
Source File: InvokableTypeImpl.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Shared implementation of {@linkplain ClassType#allMethods()} and
 * {@linkplain InterfaceType#allMethods()}
 * @return A list of all methods (recursively)
 */
public final List<Method> allMethods() {
    ArrayList<Method> list = new ArrayList<>(methods());
    ClassType clazz = superclass();
    while (clazz != null) {
        list.addAll(clazz.methods());
        clazz = clazz.superclass();
    }
    /*
     * Avoid duplicate checking on each method by iterating through
     * duplicate-free allInterfaces() rather than recursing
     */
    for (InterfaceType interfaze : getAllInterfaces()) {
        list.addAll(interfaze.methods());
    }
    return list;
}
 
Example #15
Source File: DebugJUnitRunner.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public static boolean loadClass(String className, VirtualMachine vm) {
	boolean result = false;
	ClassType classReference = (ClassType) vm.classesByName("java.lang.Class").get(0);
	for (int i = 0; i < vm.allThreads().size(); i++) {
		ThreadReference thread = vm.allThreads().get(i);
		try {
			classReference.invokeMethod(thread, classReference.methodsByName("forName").get(0),
					Arrays.asList(vm.mirrorOf(className)), ObjectReference.INVOKE_SINGLE_THREADED);
		} catch (Exception e) {
			continue;
		}
		result = true;
		break;
	}
	return result;
}
 
Example #16
Source File: InvokableTypeImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Shared implementation of {@linkplain ClassType#allMethods()} and
 * {@linkplain InterfaceType#allMethods()}
 * @return A list of all methods (recursively)
 */
public final List<Method> allMethods() {
    ArrayList<Method> list = new ArrayList<>(methods());
    ClassType clazz = superclass();
    while (clazz != null) {
        list.addAll(clazz.methods());
        clazz = clazz.superclass();
    }
    /*
     * Avoid duplicate checking on each method by iterating through
     * duplicate-free allInterfaces() rather than recursing
     */
    for (InterfaceType interfaze : getAllInterfaces()) {
        list.addAll(interfaze.methods());
    }
    return list;
}
 
Example #17
Source File: OomDebugTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unused") // called via reflection
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);
    }
}
 
Example #18
Source File: InvokableTypeImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private PacketStream sendInvokeCommand(final ThreadReferenceImpl thread,
                                       final MethodImpl method,
                                       final ValueImpl[] args,
                                       final int options) {
    /*
     * Cache the values of args when TRACE_SENDS is enabled, for later printing.
     * If not cached, printing causes a remote call while synchronized, and deadlock.
     */
    if ((vm.traceFlags & VirtualMachineImpl.TRACE_SENDS) != 0) {
       for (ValueImpl arg: args) {
          arg.toString();
       }
    }
    CommandSender sender = getInvokeMethodSender(thread, method, args, options);
    PacketStream stream;
    if ((options & ClassType.INVOKE_SINGLE_THREADED) != 0) {
        stream = thread.sendResumingCommand(sender);
    } else {
        stream = vm.sendResumingCommand(sender);
    }
    return stream;
}
 
Example #19
Source File: InvokableTypeImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Shared implementation of {@linkplain ClassType#allMethods()} and
 * {@linkplain InterfaceType#allMethods()}
 * @return A list of all methods (recursively)
 */
public final List<Method> allMethods() {
    ArrayList<Method> list = new ArrayList<>(methods());
    ClassType clazz = superclass();
    while (clazz != null) {
        list.addAll(clazz.methods());
        clazz = clazz.superclass();
    }
    /*
     * Avoid duplicate checking on each method by iterating through
     * duplicate-free allInterfaces() rather than recursing
     */
    for (InterfaceType interfaze : getAllInterfaces()) {
        list.addAll(interfaze.methods());
    }
    return list;
}
 
Example #20
Source File: InvokableTypeImpl.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private PacketStream sendInvokeCommand(final ThreadReferenceImpl thread,
                                       final MethodImpl method,
                                       final ValueImpl[] args,
                                       final int options) {
    /*
     * Cache the values of args when TRACE_SENDS is enabled, for later printing.
     * If not cached, printing causes a remote call while synchronized, and deadlock.
     */
    if ((vm.traceFlags & VirtualMachineImpl.TRACE_SENDS) != 0) {
       for (ValueImpl arg: args) {
          arg.toString();
       }
    }
    CommandSender sender = getInvokeMethodSender(thread, method, args, options);
    PacketStream stream;
    if ((options & ClassType.INVOKE_SINGLE_THREADED) != 0) {
        stream = thread.sendResumingCommand(sender);
    } else {
        stream = vm.sendResumingCommand(sender);
    }
    return stream;
}
 
Example #21
Source File: EvaluationContext.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void setValue(Value value) {
    try {
        if (fieldObject != null) {
            fieldObject.setValue(field, value);
        } else {
            ((ClassType) field.declaringType()).setValue(field, value);
        }
    } catch (IllegalArgumentException iaex) {
        throw new IllegalStateException(new InvalidExpressionException (iaex));
    } catch (InvalidTypeException itex) {
        throw new IllegalStateException(new InvalidExpressionException (itex));
    } catch (ClassNotLoadedException cnlex) {
        throw new IllegalStateException(cnlex);
    }
}
 
Example #22
Source File: RemoteServices.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static ClassType getClass(VirtualMachine vm, String name) throws InternalExceptionWrapper,
                                                                         ObjectCollectedExceptionWrapper,
                                                                         VMDisconnectedExceptionWrapper {
    List<ReferenceType> classList = VirtualMachineWrapper.classesByName(vm, name);
    ReferenceType clazz = null;
    for (ReferenceType c : classList) {
        if (ReferenceTypeWrapper.classLoader(c) == null) {
            clazz = c;
            break;
        }
    }
    if (clazz == null && classList.size() > 0) {
        clazz = classList.get(0);
    }
    return (ClassType) clazz;
}
 
Example #23
Source File: AbstractObjectVariable.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public List<JPDAClassType> getAllInterfaces() {
    if (getInnerValue () == null) {
        return null;
    }
    try {
        Type t = getCachedType();
        if (!(t instanceof ClassType)) {
            return null;
        }
        ClassType ct = (ClassType) t;
        return getDebugger().getAllInterfaces(ct);
    } catch (ObjectCollectedExceptionWrapper ocex) {
        return null;
    } catch (InternalExceptionWrapper ex) {
        return null;
    } catch (VMDisconnectedExceptionWrapper e) {
        return null;
    }
}
 
Example #24
Source File: AbstractObjectVariable.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public boolean hasAllTypes() {
    if (getInnerValue () == null) {
        return true;
    }
    Type t;
    synchronized (valueTypeLoaded) {
        if (!valueTypeLoaded[0]) {
            return false;
        }
        t = valueType;
    }
    if (t instanceof ClassType) {
        ClassType ct = (ClassType) t;
        if (!getDebugger().hasAllInterfaces(ct)) {
            return false;
        }
        synchronized (superClassLoaded) {
            if (!superClassLoaded[0]) {
                return false;
            }
        }
    }
    return true;
}
 
Example #25
Source File: JavaLogicalStructure.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns whether to support the logical structure view for the given object instance.
 */
public boolean providesLogicalStructure(ObjectReference obj) {
    Type variableType = obj.type();
    if (!(variableType instanceof ClassType)) {
        return false;
    }

    ClassType classType = (ClassType) variableType;
    while (classType != null) {
        if (Objects.equals(type, classType.name())) {
            return true;
        }

        classType = classType.superclass();
    }

    List<InterfaceType> interfaceTypes = ((ClassType) variableType).allInterfaces();
    for (InterfaceType interfaceType : interfaceTypes) {
        if (Objects.equals(type, interfaceType.name())) {
            return true;
        }
    }

    return false;
}
 
Example #26
Source File: JPDADebuggerImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public boolean hasAllInterfaces(ClassType ct) {
    List allInterfaces;
    synchronized (allInterfacesMap) {
        allInterfaces = allInterfacesMap.get(ct);
    }
    if (allInterfaces == null) {
        return false;
    } else {
        synchronized (allInterfaces) {
            if (allInterfaces.contains("computing")) {      // NOI18N
                return false;
            }
        }
    }
    return true;
}
 
Example #27
Source File: OomDebugTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private Method getConstructorForClass(ClassType clsType) {
    List<Method> methods = clsType.methodsByName("<init>");
    if (methods.size() != 1) {
        throw new RuntimeException("FAIL. Expected only one, the default, constructor");
    }
    return methods.get(0);
}
 
Example #28
Source File: SuperVariable.java    From netbeans with Apache License 2.0 5 votes vote down vote up
SuperVariable (
    JPDADebuggerImpl debugger,
    ObjectReference value,
    ClassType classType,
    String parentID
) {
    super (
        debugger, 
        value,
        classType,
        parentID + ".super^"
    );
    this.classType = classType;
}
 
Example #29
Source File: InvokableTypeImpl.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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()}.
 */
final public 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();
    }
}
 
Example #30
Source File: InvokableTypeImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private PacketStream sendInvokeCommand(final ThreadReferenceImpl thread,
                                       final MethodImpl method,
                                       final ValueImpl[] args,
                                       final int options) {

    CommandSender sender = getInvokeMethodSender(thread, method, args, options);
    PacketStream stream;
    if ((options & ClassType.INVOKE_SINGLE_THREADED) != 0) {
        stream = thread.sendResumingCommand(sender);
    } else {
        stream = vm.sendResumingCommand(sender);
    }
    return stream;
}