Java Code Examples for com.sun.jdi.VirtualMachine#classesByName()

The following examples show how to use com.sun.jdi.VirtualMachine#classesByName() . 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: VariableMirrorTranslator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static ReferenceType getOrLoadClass(VirtualMachine vm, String name) {
    List<ReferenceType> types = vm.classesByName(name);
    if (types.size() > 0) {
        if (types.size() == 1) {
            return types.get(0);
        }
        try {
            ReferenceType preferedType = JPDAUtils.getPreferredReferenceType(types, null);
            if (preferedType != null) {
                return preferedType;
            }
        } catch (VMDisconnectedExceptionWrapper ex) {
            throw ex.getCause();
        }
        // No preferred, just take the first one:
        return types.get(0);
    }
    // DO NOT TRY TO LOAD CLASSES AT ALL! See http://www.netbeans.org/issues/show_bug.cgi?id=168949
    return null;
}
 
Example 2
Source File: VMCache.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private ReferenceType loadClass(String name) {
    VirtualMachine vm = debugger.getVirtualMachine();
    if (vm == null) {
        return null;
    }
    List<ReferenceType> stringClasses = vm.classesByName(name);
    if (stringClasses.isEmpty()) {
        return null;
    }
    return stringClasses.get(0);
}
 
Example 3
Source File: JdiExecutionControl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static ReferenceType nameToRef(VirtualMachine vm, String name) {
    List<ReferenceType> rtl = vm.classesByName(name);
    if (rtl.size() != 1) {
        return null;
    }
    return rtl.get(0);
}
 
Example 4
Source File: JavaHotCodeReplaceProvider.java    From java-debug with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns VirtualMachine.classesByName(String), logging any JDI exceptions.
 *
 * @see com.sun.jdi.VirtualMachine
 */
private List<ReferenceType> getJdiClassesByName(String className) {
    try {
        VirtualMachine vm = this.currentDebugSession.getVM();
        if (vm != null) {
            return vm.classesByName(className);
        }
    } catch (VMDisconnectedException ex) {
        // Ignore this exception since it will happen when the VM is still running.
    }
    return Collections.emptyList();
}
 
Example 5
Source File: VMTargetStarter.java    From gravel with Apache License 2.0 5 votes vote down vote up
private void installHaltPoint(VirtualMachine vm) {
	List<ReferenceType> targetClasses = vm
			.classesByName(VMLocalTarget.class.getName());
	ReferenceType classRef = targetClasses.get(0);
	Method meth = classRef.methodsByName("haltPoint").get(0);
	BreakpointRequest req = vm.eventRequestManager()
			.createBreakpointRequest(meth.location());
	req.setSuspendPolicy(BreakpointRequest.SUSPEND_EVENT_THREAD);
	req.enable();
}