com.sun.jdi.InvocationException Java Examples

The following examples show how to use com.sun.jdi.InvocationException. 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: 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 #2
Source File: OomDebugTest.java    From openjdk-jdk8u 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 hottub 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 " + testMethodName);
    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);
            invoke("testMethod", "(LOomDebugTestTarget$FooCls;)V", objRef);
        }
    } catch (InvocationException e) {
        handleFailure(e);
    }
}
 
Example #4
Source File: OomDebugTest.java    From jdk8u-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 #5
Source File: OomDebugTest.java    From jdk8u_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 #6
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 #7
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 #8
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 #9
Source File: OomDebugTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings({ "unused", "unchecked", "rawtypes" }) // called via reflection
private void test5() throws Exception {
    System.out.println("DEBUG: ------------> Running test5");
    try {
        ClassType type = (ClassType)thisObject.type();
        for (int i = 0; i < 15; i++) {
            type.newInstance(mainThread,
                             findMethod(targetClass, "<init>", "()V"),
                             new ArrayList(0),
                             ObjectReference.INVOKE_NONVIRTUAL);
        }
    } catch (InvocationException e) {
        handleFailure(e);
    }
}
 
Example #10
Source File: OomDebugTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void handleFailure(InvocationException e) {
    // There is no good way to see the OOME diagnostic message in the target since the
    // TestScaffold might throw an exception while trying to print the stack trace. I.e
    // it might get a a VMDisconnectedException before the stack trace printing finishes.
    System.err.println("FAILURE: InvocationException thrown. Trying to determine cause...");
    defaultHandleOOMFailure(e);
}
 
Example #11
Source File: OomDebugTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unused") // called via reflection
private void test4() throws Exception {
    System.out.println("DEBUG: ------------> Running test4");
    try {
        for (int i = 0; i < 15; i++) {
            invoke("testFooClsRetval",
                   "()LOomDebugTestTarget$FooCls;",
                   Collections.EMPTY_LIST,
                   vm().mirrorOfVoid());
        }
    } catch (InvocationException e) {
        handleFailure(e);
    }
}
 
Example #12
Source File: InvokableTypeImpl.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void validateMethodInvocation(Method method)
                                        throws InvalidTypeException,
                                               InvocationException {
    if (!canInvoke(method)) {
        throw new IllegalArgumentException("Invalid method");
    }
    /*
     * Method must be a static and not a static initializer
     */
    if (!method.isStatic()) {
        throw new IllegalArgumentException("Cannot invoke instance method on a class/interface type");
    } else if (method.isStaticInitializer()) {
        throw new IllegalArgumentException("Cannot invoke static initializer");
    }
}
 
Example #13
Source File: OomDebugTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unused") // called via reflection
private void test3() throws Exception {
    System.out.println("DEBUG: ------------> Running test3");
    try {
        for (int i = 0; i < 15; i++) {
            invoke("testPrimitiveArrRetval",
                   "()[B",
                   Collections.EMPTY_LIST,
                   vm().mirrorOfVoid());
        }
    } catch (InvocationException e) {
        handleFailure(e);
    }
}
 
Example #14
Source File: InvokableTypeImpl.java    From jdk8u-dev-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 #15
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 #16
Source File: OomDebugTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void handleFailure(InvocationException e) {
    // There is no good way to see the OOME diagnostic message in the target since the
    // TestScaffold might throw an exception while trying to print the stack trace. I.e
    // it might get a a VMDisconnectedException before the stack trace printing finishes.
    System.err.println("FAILURE: InvocationException thrown. Trying to determine cause...");
    defaultHandleOOMFailure(e);
}
 
Example #17
Source File: OomDebugTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings({ "unused", "unchecked", "rawtypes" }) // called via reflection
private void test5() throws Exception {
    System.out.println("DEBUG: ------------> Running test5");
    try {
        ClassType type = (ClassType)thisObject.type();
        for (int i = 0; i < 15; i++) {
            type.newInstance(mainThread,
                             findMethod(targetClass, "<init>", "()V"),
                             new ArrayList(0),
                             ObjectReference.INVOKE_NONVIRTUAL);
        }
    } catch (InvocationException e) {
        handleFailure(e);
    }
}
 
Example #18
Source File: OomDebugTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unused") // called via reflection
private void test4() throws Exception {
    System.out.println("DEBUG: ------------> Running test4");
    try {
        for (int i = 0; i < 15; i++) {
            invoke("testFooClsRetval",
                   "()LOomDebugTestTarget$FooCls;",
                   Collections.EMPTY_LIST,
                   vm().mirrorOfVoid());
        }
    } catch (InvocationException e) {
        handleFailure(e);
    }
}
 
Example #19
Source File: InvokableTypeImpl.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void validateMethodInvocation(Method method)
                                        throws InvalidTypeException,
                                               InvocationException {
    if (!canInvoke(method)) {
        throw new IllegalArgumentException("Invalid method");
    }
    /*
     * Method must be a static and not a static initializer
     */
    if (!method.isStatic()) {
        throw new IllegalArgumentException("Cannot invoke instance method on a class/interface type");
    } else if (method.isStaticInitializer()) {
        throw new IllegalArgumentException("Cannot invoke static initializer");
    }
}
 
Example #20
Source File: OomDebugTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unused") // called via reflection
private void test3() throws Exception {
    System.out.println("DEBUG: ------------> Running test3");
    try {
        for (int i = 0; i < 15; i++) {
            invoke("testPrimitiveArrRetval",
                   "()[B",
                   Collections.EMPTY_LIST,
                   vm().mirrorOfVoid());
        }
    } catch (InvocationException e) {
        handleFailure(e);
    }
}
 
Example #21
Source File: InvokableTypeImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void validateMethodInvocation(Method method)
                                        throws InvalidTypeException,
                                               InvocationException {
    if (!canInvoke(method)) {
        throw new IllegalArgumentException("Invalid method");
    }
    /*
     * Method must be a static and not a static initializer
     */
    if (!method.isStatic()) {
        throw new IllegalArgumentException("Cannot invoke instance method on a class/interface type");
    } else if (method.isStaticInitializer()) {
        throw new IllegalArgumentException("Cannot invoke static initializer");
    }
}
 
Example #22
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 #23
Source File: OomDebugTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void handleFailure(InvocationException e) {
    // There is no good way to see the OOME diagnostic message in the target since the
    // TestScaffold might throw an exception while trying to print the stack trace. I.e
    // it might get a a VMDisconnectedException before the stack trace printing finishes.
    System.err.println("FAILURE: InvocationException thrown. Trying to determine cause...");
    defaultHandleOOMFailure(e);
}
 
Example #24
Source File: OomDebugTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings({ "unused", "unchecked", "rawtypes" }) // called via reflection
private void test5() throws Exception {
    System.out.println("DEBUG: ------------> Running test5");
    try {
        ClassType type = (ClassType)thisObject.type();
        for (int i = 0; i < 15; i++) {
            type.newInstance(mainThread,
                             findMethod(targetClass, "<init>", "()V"),
                             new ArrayList(0),
                             ObjectReference.INVOKE_NONVIRTUAL);
        }
    } catch (InvocationException e) {
        handleFailure(e);
    }
}
 
Example #25
Source File: OomDebugTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unused") // called via reflection
private void test4() throws Exception {
    System.out.println("DEBUG: ------------> Running test4");
    try {
        for (int i = 0; i < 15; i++) {
            invoke("testFooClsRetval",
                   "()LOomDebugTestTarget$FooCls;",
                   Collections.EMPTY_LIST,
                   vm().mirrorOfVoid());
        }
    } catch (InvocationException e) {
        handleFailure(e);
    }
}
 
Example #26
Source File: OomDebugTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unused") // called via reflection
private void test3() throws Exception {
    System.out.println("DEBUG: ------------> Running test3");
    try {
        for (int i = 0; i < 15; i++) {
            invoke("testPrimitiveArrRetval",
                   "()[B",
                   Collections.EMPTY_LIST,
                   vm().mirrorOfVoid());
        }
    } catch (InvocationException e) {
        handleFailure(e);
    }
}
 
Example #27
Source File: InvokableTypeImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void validateMethodInvocation(Method method)
                                        throws InvalidTypeException,
                                               InvocationException {
    if (!canInvoke(method)) {
        throw new IllegalArgumentException("Invalid method");
    }
    /*
     * Method must be a static and not a static initializer
     */
    if (!method.isStatic()) {
        throw new IllegalArgumentException("Cannot invoke instance method on a class/interface type");
    } else if (method.isStaticInitializer()) {
        throw new IllegalArgumentException("Cannot invoke static initializer");
    }
}
 
Example #28
Source File: InvokableTypeImpl.java    From openjdk-jdk9 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 #29
Source File: OomDebugTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void handleFailure(InvocationException e) {
    // There is no good way to see the OOME diagnostic message in the target since the
    // TestScaffold might throw an exception while trying to print the stack trace. I.e
    // it might get a a VMDisconnectedException before the stack trace printing finishes.
    System.err.println("FAILURE: InvocationException thrown. Trying to determine cause...");
    defaultHandleOOMFailure(e);
}
 
Example #30
Source File: OomDebugTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings({ "unused", "unchecked", "rawtypes" }) // called via reflection
private void test5() throws Exception {
    System.out.println("DEBUG: ------------> Running test5");
    try {
        ClassType type = (ClassType)thisObject.type();
        for (int i = 0; i < 15; i++) {
            type.newInstance(mainThread,
                             findMethod(targetClass, "<init>", "()V"),
                             new ArrayList(0),
                             ObjectReference.INVOKE_NONVIRTUAL);
        }
    } catch (InvocationException e) {
        handleFailure(e);
    }
}