com.sun.jdi.Method Java Examples

The following examples show how to use com.sun.jdi.Method. 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 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 #2
Source File: InvokableTypeImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
final void addVisibleMethods(Map<String, Method> methodMap, Set<InterfaceType> seenInterfaces) {
    /*
     * Add methods from
     * parent types first, so that the methods in this class will
     * overwrite them in the hash table
     */
    Iterator<InterfaceType> iter = interfaces().iterator();
    while (iter.hasNext()) {
        InterfaceTypeImpl interfaze = (InterfaceTypeImpl) iter.next();
        if (!seenInterfaces.contains(interfaze)) {
            interfaze.addVisibleMethods(methodMap, seenInterfaces);
            seenInterfaces.add(interfaze);
        }
    }
    ClassTypeImpl clazz = (ClassTypeImpl) superclass();
    if (clazz != null) {
        clazz.addVisibleMethods(methodMap, seenInterfaces);
    }
    addToMethodMap(methodMap, methods());
}
 
Example #3
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 #4
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 #5
Source File: InvokableTypeImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
final void addVisibleMethods(Map<String, Method> methodMap, Set<InterfaceType> seenInterfaces) {
    /*
     * Add methods from
     * parent types first, so that the methods in this class will
     * overwrite them in the hash table
     */
    Iterator<InterfaceType> iter = interfaces().iterator();
    while (iter.hasNext()) {
        InterfaceTypeImpl interfaze = (InterfaceTypeImpl) iter.next();
        if (!seenInterfaces.contains(interfaze)) {
            interfaze.addVisibleMethods(methodMap, seenInterfaces);
            seenInterfaces.add(interfaze);
        }
    }
    ClassTypeImpl clazz = (ClassTypeImpl) superclass();
    if (clazz != null) {
        clazz.addVisibleMethods(methodMap, seenInterfaces);
    }
    addToMethodMap(methodMap, methods());
}
 
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: InvokableTypeImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
final void addVisibleMethods(Map<String, Method> methodMap, Set<InterfaceType> seenInterfaces) {
    /*
     * Add methods from
     * parent types first, so that the methods in this class will
     * overwrite them in the hash table
     */
    Iterator<InterfaceType> iter = interfaces().iterator();
    while (iter.hasNext()) {
        InterfaceTypeImpl interfaze = (InterfaceTypeImpl) iter.next();
        if (!seenInterfaces.contains(interfaze)) {
            interfaze.addVisibleMethods(methodMap, seenInterfaces);
            seenInterfaces.add(interfaze);
        }
    }
    ClassTypeImpl clazz = (ClassTypeImpl) superclass();
    if (clazz != null) {
        clazz.addVisibleMethods(methodMap, seenInterfaces);
    }
    addToMethodMap(methodMap, methods());
}
 
Example #8
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 #9
Source File: DebugUtility.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Suspend the main thread when the program enters the main method of the specified main class.
 * @param debugSession
 *                  the debug session.
 * @param mainClass
 *                  the fully qualified name of the main class.
 * @return
 *        a {@link CompletableFuture} that contains the suspended main thread id.
 */
public static CompletableFuture<Long> stopOnEntry(IDebugSession debugSession, String mainClass) {
    CompletableFuture<Long> future = new CompletableFuture<>();

    EventRequestManager manager = debugSession.getVM().eventRequestManager();
    MethodEntryRequest request = manager.createMethodEntryRequest();
    request.addClassFilter(mainClass);
    request.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD);

    debugSession.getEventHub().events().filter(debugEvent -> {
        return debugEvent.event instanceof MethodEntryEvent && request.equals(debugEvent.event.request());
    }).subscribe(debugEvent -> {
        Method method = ((MethodEntryEvent) debugEvent.event).method();
        if (method.isPublic() && method.isStatic() && method.name().equals("main")
                && method.signature().equals("([Ljava/lang/String;)V")) {
            deleteEventRequestSafely(debugSession.getVM().eventRequestManager(), request);
            debugEvent.shouldResume = false;
            ThreadReference bpThread = ((MethodEntryEvent) debugEvent.event).thread();
            future.complete(bpThread.uniqueID());
        }
    });
    request.enable();

    return future;
}
 
Example #10
Source File: StackTraceRequestHandler.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
private String formatMethodName(Method method, boolean showContextClass, boolean showParameter) {
    StringBuilder formattedName = new StringBuilder();
    if (showContextClass) {
        String fullyQualifiedClassName = method.declaringType().name();
        formattedName.append(SimpleTypeFormatter.trimTypeName(fullyQualifiedClassName));
        formattedName.append(".");
    }
    formattedName.append(method.name());
    if (showParameter) {
        List<String> argumentTypeNames = method.argumentTypeNames().stream().map(SimpleTypeFormatter::trimTypeName).collect(Collectors.toList());
        formattedName.append("(");
        formattedName.append(String.join(",", argumentTypeNames));
        formattedName.append(")");
    }
    return formattedName.toString();
}
 
Example #11
Source File: InvokableTypeImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
final void addVisibleMethods(Map<String, Method> methodMap, Set<InterfaceType> seenInterfaces) {
    /*
     * Add methods from
     * parent types first, so that the methods in this class will
     * overwrite them in the hash table
     */
    Iterator<InterfaceType> iter = interfaces().iterator();
    while (iter.hasNext()) {
        InterfaceTypeImpl interfaze = (InterfaceTypeImpl) iter.next();
        if (!seenInterfaces.contains(interfaze)) {
            interfaze.addVisibleMethods(methodMap, seenInterfaces);
            seenInterfaces.add(interfaze);
        }
    }
    ClassTypeImpl clazz = (ClassTypeImpl) superclass();
    if (clazz != null) {
        clazz.addVisibleMethods(methodMap, seenInterfaces);
    }
    addToMethodMap(methodMap, methods());
}
 
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: 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 #14
Source File: InvokableTypeImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
final void addVisibleMethods(Map<String, Method> methodMap, Set<InterfaceType> seenInterfaces) {
    /*
     * Add methods from
     * parent types first, so that the methods in this class will
     * overwrite them in the hash table
     */
    Iterator<InterfaceType> iter = interfaces().iterator();
    while (iter.hasNext()) {
        InterfaceTypeImpl interfaze = (InterfaceTypeImpl) iter.next();
        if (!seenInterfaces.contains(interfaze)) {
            interfaze.addVisibleMethods(methodMap, seenInterfaces);
            seenInterfaces.add(interfaze);
        }
    }
    ClassTypeImpl clazz = (ClassTypeImpl) superclass();
    if (clazz != null) {
        clazz.addVisibleMethods(methodMap, seenInterfaces);
    }
    addToMethodMap(methodMap, methods());
}
 
Example #15
Source File: InvokableTypeImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
final void addVisibleMethods(Map<String, Method> methodMap, Set<InterfaceType> seenInterfaces) {
    /*
     * Add methods from
     * parent types first, so that the methods in this class will
     * overwrite them in the hash table
     */
    Iterator<InterfaceType> iter = interfaces().iterator();
    while (iter.hasNext()) {
        InterfaceTypeImpl interfaze = (InterfaceTypeImpl) iter.next();
        if (!seenInterfaces.contains(interfaze)) {
            interfaze.addVisibleMethods(methodMap, seenInterfaces);
            seenInterfaces.add(interfaze);
        }
    }
    ClassTypeImpl clazz = (ClassTypeImpl) superclass();
    if (clazz != null) {
        clazz.addVisibleMethods(methodMap, seenInterfaces);
    }
    addToMethodMap(methodMap, methods());
}
 
Example #16
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 #17
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 #18
Source File: StackTraceRequestHandler.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
private Types.StackFrame convertDebuggerStackFrameToClient(StackFrame stackFrame, int frameId, IDebugAdapterContext context)
        throws URISyntaxException, AbsentInformationException {
    Location location = stackFrame.location();
    Method method = location.method();
    Types.Source clientSource = this.convertDebuggerSourceToClient(location, context);
    String methodName = formatMethodName(method, true, true);
    int lineNumber = AdapterUtils.convertLineNumber(location.lineNumber(), context.isDebuggerLinesStartAt1(), context.isClientLinesStartAt1());
    // Line number returns -1 if the information is not available; specifically, always returns -1 for native methods.
    if (lineNumber < 0) {
        if (method.isNative()) {
            // For native method, display a tip text "native method" in the Call Stack View.
            methodName += "[native method]";
        } else {
            // For other unavailable method, such as lambda expression's built-in methods run/accept/apply,
            // display "Unknown Source" in the Call Stack View.
            clientSource = null;
        }
    }
    return new Types.StackFrame(frameId, methodName, clientSource, lineNumber, context.isClientColumnsStartAt1() ? 1 : 0);
}
 
Example #19
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 #20
Source File: OomDebugTest.java    From openjdk-jdk8u-backup 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 #21
Source File: VisibleMethods.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startToMain("CC");

        ReferenceType ac = findReferenceType("AC");
        List<String> visible = ac.visibleMethods().
                stream().
                map(Method::toString).
                collect(Collectors.toList());

        System.out.println("visibleMethods(): " + visible);

        verifyContains(visible, 1, "Two.m(java.lang.String)");
        verifyContains(visible, 1, "One.m(java.lang.Object)");
        verifyContains(visible, 0, "Super.m(java.lang.Object)");
        verifyContains(visible, 0, "Super.m(java.lang.String)");
        verifyContains(visible, 1, "Two.m1()", "One.m1()");

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
 
Example #22
Source File: DecisionProcedureGuidanceJDI.java    From jbse with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Signature getCurrentMethodSignature() throws ThreadStackEmptyException {
    if (this.currentStepEvent == null && this.methodEntryEvent == null) {
        throw new ThreadStackEmptyException();
    }
    final Method jdiMeth = (this.currentStepEvent == null ? this.methodEntryEvent.location().method() : this.currentStepEvent.location().method());
    final String jdiMethClassName = jdiMethodClassName(jdiMeth);
    final String jdiMethDescr = jdiMeth.signature();
    final String jdiMethName = jdiMeth.name();
    return new Signature(jdiMethClassName, jdiMethDescr, jdiMethName);
}
 
Example #23
Source File: JPDADebuggerImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Value invokeMethod (
    JPDAThreadImpl thread,
    ObjectReference reference,
    Method method,
    Value[] arguments,
    InvocationExceptionTranslated existingInvocationException
) throws InvalidExpressionException {
    return invokeMethod(thread, reference, null, method, arguments, 0, existingInvocationException);
}
 
Example #24
Source File: JPDADebuggerImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Used by AbstractVariable.
 */
public Value invokeMethod (
    JPDAThreadImpl thread,
    ObjectReference reference,
    Method method,
    Value[] arguments
) throws InvalidExpressionException {
    return invokeMethod(thread, reference, method, arguments, null);
}
 
Example #25
Source File: JPDADebuggerImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Used by AbstractVariable.
 */
public Value invokeMethod (
    ObjectReference reference,
    Method method,
    Value[] arguments
) throws InvalidExpressionException {
    return invokeMethod(null, reference, null, method, arguments, 0, null);
}
 
Example #26
Source File: AWTComponentBreakpointImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private String findClassWithMethod(ObjectReference value, String name, String signature) {
    try {
        ReferenceType referenceType = ObjectReferenceWrapper.referenceType(value);
        List<Method> methods = ReferenceTypeWrapper.methodsByName(referenceType, name, signature);
        if (!methods.isEmpty()) {
            return ReferenceTypeWrapper.name(TypeComponentWrapper.declaringType(methods.get(0)));
        }
    } catch (ClassNotPreparedExceptionWrapper ex) {
    } catch (InternalExceptionWrapper iex) {
    } catch (ObjectCollectedExceptionWrapper ocex) {
    } catch (VMDisconnectedExceptionWrapper vmdex) {
    }
    return null;
}
 
Example #27
Source File: RemoteFXScreenshot.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static ReferenceType getType(VirtualMachine vm, ThreadReference tr, String name) {
    List<ReferenceType> classList = VirtualMachineWrapper.classesByName0(vm, name);
    if (!classList.isEmpty()) {
        return classList.iterator().next();
    }
    List<ReferenceType> classClassList = VirtualMachineWrapper.classesByName0(vm, "java.lang.Class"); // NOI18N
    if (classClassList.isEmpty()) {
        throw new IllegalStateException("Cannot load class Class"); // NOI18N
    }

    ClassType cls = (ClassType) classClassList.iterator().next();
    try {
        Method m = ClassTypeWrapper.concreteMethodByName(cls, "forName", "(Ljava/lang/String;)Ljava/lang/Class;"); // NOI18N
        StringReference mirrorOfName = VirtualMachineWrapper.mirrorOf(vm, name);
        ClassTypeWrapper.invokeMethod(cls, tr, m, Collections.singletonList(mirrorOfName), ObjectReference.INVOKE_SINGLE_THREADED);
        List<ReferenceType> classList2 = VirtualMachineWrapper.classesByName0(vm, name);
        if (!classList2.isEmpty()) {
            return classList2.iterator().next();
        }
    } catch (ClassNotLoadedException | ClassNotPreparedExceptionWrapper |
             IncompatibleThreadStateException | InvalidTypeException |
             InvocationException | InternalExceptionWrapper |
             ObjectCollectedExceptionWrapper | UnsupportedOperationExceptionWrapper |
             VMDisconnectedExceptionWrapper ex) {
        logger.log(Level.FINE, "Cannot load class " + name, ex); // NOI18N
    }
    
    return null;
}
 
Example #28
Source File: RemoteFXScreenshot.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void resumeMedia(ThreadReference tr, VirtualMachine vm) throws InvalidTypeException, ClassNotLoadedException, IncompatibleThreadStateException, InvocationException {
    if (!pausedPlayers.isEmpty()) {
        final InterfaceType mediaPlayerClass = getInterface(vm, tr, "com.sun.media.jfxmedia.MediaPlayer");
        List<Method> play = mediaPlayerClass.methodsByName("play", "()V");
        if (play.isEmpty()) {
            return;
        }
        Method p = play.iterator().next();
        for(ObjectReference pR : pausedPlayers) {
            pR.invokeMethod(tr, p, Collections.emptyList(), ObjectReference.INVOKE_SINGLE_THREADED);
        }
    }
}
 
Example #29
Source File: InvokableTypeImpl.java    From dragonwell8_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: JPDAStepImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean checkBoxingUnboxingMethods(Location loc, Method m) {
    try {
        String typeName = ReferenceTypeWrapper.name(LocationWrapper.declaringType(loc));
        switch (typeName) {
            case "java.lang.Boolean":
            case "java.lang.Byte":
            case "java.lang.Character":
            case "java.lang.Short":
            case "java.lang.Integer":
            case "java.lang.Long":
            case "java.lang.Float":
            case "java.lang.Double":
                break;
            default:
                return false;
        }
        String methodName = TypeComponentWrapper.name(m);
        switch(methodName) {
            case "booleanValue":
            case "byteValue":
            case "charValue":
            case "shortValue":
            case "intValue":
            case "longValue":
            case "floatValue":
            case "doubleValue":
            case "valueOf":
                break;
            default:
                return false;
        }
        return true;
    } catch (InternalExceptionWrapper |
             ObjectCollectedExceptionWrapper |
             VMDisconnectedExceptionWrapper ex) {
        return false;
    }
}