com.sun.jdi.ReferenceType Java Examples
The following examples show how to use
com.sun.jdi.ReferenceType.
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: InvocationExceptionTranslated.java From netbeans with Apache License 2.0 | 6 votes |
private String getMessageFromField() throws InternalExceptionWrapper, VMDisconnectedExceptionWrapper, ObjectCollectedExceptionWrapper, ClassNotPreparedExceptionWrapper { List<ReferenceType> throwableClasses = VirtualMachineWrapper.classesByName(exeption.virtualMachine(), Throwable.class.getName()); if (throwableClasses.isEmpty()) { return null; } Field detailMessageField = ReferenceTypeWrapper.fieldByName(throwableClasses.get(0), "detailMessage"); if (detailMessageField != null) { Value messageValue = ObjectReferenceWrapper.getValue(exeption, detailMessageField); if (messageValue instanceof StringReference) { message = StringReferenceWrapper.value((StringReference) messageValue); if (invocationMessage != null) { return invocationMessage + ": " + message; } else { return message; } } } return null; }
Example #2
Source File: JavaHotCodeReplaceProvider.java From java-debug with Eclipse Public License 1.0 | 6 votes |
private void filterNotLoadedTypes(List<IResource> resources, List<String> qualifiedNames) { for (int i = 0, numElements = qualifiedNames.size(); i < numElements; i++) { String name = qualifiedNames.get(i); List<ReferenceType> list = getJdiClassesByName(name); if (list.isEmpty()) { // If no classes with the given name are loaded in the VM, don't // waste // cycles trying to replace. qualifiedNames.remove(i); resources.remove(i); // Decrement the index and number of elements to compensate for // item removal i--; numElements--; } } }
Example #3
Source File: JPDAClassTypeImpl.java From netbeans with Apache License 2.0 | 6 votes |
@Override public boolean isInstanceOf(String className) { List<ReferenceType> classTypes; try { classTypes = VirtualMachineWrapper.classesByName(MirrorWrapper.virtualMachine(classType), className); } catch (InternalExceptionWrapper | VMDisconnectedExceptionWrapper ex) { return false; } for (ReferenceType rt : classTypes) { try { if (EvaluatorVisitor.instanceOf(classType, rt)) { return true; } } catch (VMDisconnectedException vmdex) { return false; } catch (InternalException iex) { // procceed } } return false; }
Example #4
Source File: VariableMirrorTranslator.java From netbeans with Apache License 2.0 | 6 votes |
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 #5
Source File: DynamothCollector.java From astor with GNU General Public License v2.0 | 6 votes |
private void processClassPrepareEvent() throws AbsentInformationException { EventRequestManager erm = vm.eventRequestManager(); List<ReferenceType> referenceTypes = vm.classesByName(this.location.getContainingClassName()); // List listOfLocations = // referenceTypes.get(0).locationsOfLine(this.location.getLineNumber()); int loc = this.location.getLineNumber(); List listOfLocations = null; do { listOfLocations = referenceTypes.get(0).locationsOfLine(loc); loc--; } while (loc > 0 && listOfLocations.isEmpty()); if (listOfLocations.size() == 0) { throw new RuntimeException("Buggy class not found " + this.location); } com.sun.jdi.Location jdiLocation = (com.sun.jdi.Location) listOfLocations.get(0); this.buggyMethod = jdiLocation.method().name(); breakpointSuspicious = erm.createBreakpointRequest(jdiLocation); breakpointSuspicious.setEnabled(true); initSpoon(); this.initExecutionTime = System.currentTimeMillis(); }
Example #6
Source File: RemoteServices.java From netbeans with Apache License 2.0 | 6 votes |
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 #7
Source File: DataBreakpointInfoRequestHandler.java From java-debug with Eclipse Public License 1.0 | 6 votes |
@Override public CompletableFuture<Response> handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { DataBreakpointInfoArguments dataBpArgs = (DataBreakpointInfoArguments) arguments; if (dataBpArgs.variablesReference > 0) { Object container = context.getRecyclableIdPool().getObjectById(dataBpArgs.variablesReference); if (container instanceof VariableProxy) { if (!(((VariableProxy) container).getProxiedVariable() instanceof StackFrameReference)) { ObjectReference containerObj = (ObjectReference) ((VariableProxy) container).getProxiedVariable(); ReferenceType type = containerObj.referenceType(); Field field = type.fieldByName(dataBpArgs.name); if (field != null) { String fullyQualifiedName = type.name(); String dataId = String.format("%s#%s", fullyQualifiedName, dataBpArgs.name); String description = String.format("%s.%s : %s", getSimpleName(fullyQualifiedName), dataBpArgs.name, getSimpleName(field.typeName())); response.body = new DataBreakpointInfoResponseBody(dataId, description, DataBreakpointAccessType.values(), true); } } } } return CompletableFuture.completedFuture(response); }
Example #8
Source File: Watchpoint.java From java-debug with Eclipse Public License 1.0 | 6 votes |
private List<WatchpointRequest> createWatchpointRequests(ReferenceType type) { List<WatchpointRequest> watchpointRequests = new ArrayList<>(); Field field = type.fieldByName(fieldName); if (field != null) { if ("read".equals(accessType)) { watchpointRequests.add(vm.eventRequestManager().createAccessWatchpointRequest(field)); } else if ("readWrite".equals(accessType)) { watchpointRequests.add(vm.eventRequestManager().createAccessWatchpointRequest(field)); watchpointRequests.add(vm.eventRequestManager().createModificationWatchpointRequest(field)); } else { watchpointRequests.add(vm.eventRequestManager().createModificationWatchpointRequest(field)); } } watchpointRequests.forEach(request -> { request.setSuspendPolicy(WatchpointRequest.SUSPEND_EVENT_THREAD); if (hitCount > 0) { request.addCountFilter(hitCount); } request.enable(); }); return watchpointRequests; }
Example #9
Source File: GetObjectLockCount.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private static void addBreakpoint(VirtualMachine vm, ReferenceType refType) { Location breakpointLocation = null; List<Location> locs; try { locs = refType.allLineLocations(); for (Location loc: locs) { if (loc.method().name().equals(METHOD_NAME)) { breakpointLocation = loc; break; } } } catch (AbsentInformationException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (breakpointLocation != null) { EventRequestManager evtReqMgr = vm.eventRequestManager(); BreakpointRequest bReq = evtReqMgr.createBreakpointRequest(breakpointLocation); bReq.setSuspendPolicy(BreakpointRequest.SUSPEND_ALL); bReq.enable(); } }
Example #10
Source File: JPDABreakpointEvent.java From netbeans with Apache License 2.0 | 6 votes |
/** * Creates a new instance of JPDABreakpointEvent. * * @param sourceBreakpoint a breakpoint * @param conditionException result of condition * @param thread a context thread * @param debugger a debugger this * @param referenceType a context class * @param variable a context variable */ public JPDABreakpointEvent ( JPDABreakpoint sourceBreakpoint, JPDADebugger debugger, Throwable conditionException, JPDAThread thread, ReferenceType referenceType, Variable variable ) { super (sourceBreakpoint); this.conditionResult = CONDITION_FAILED; this.conditionException = conditionException; this.thread = thread; this.debugger = debugger; this.referenceType = referenceType; this.variable = variable; }
Example #11
Source File: JPDABreakpointEvent.java From netbeans with Apache License 2.0 | 6 votes |
/** * Creates a new instance of JPDABreakpointEvent. This method should be * called from debuggerjpda module only. Do not create a new instances * of this class! * * @param sourceBreakpoint a breakpoint * @param debugger a debugger this * @param conditionResult a result of condition * @param thread a context thread * @param referenceType a context class * @param variable a context variable */ public JPDABreakpointEvent ( JPDABreakpoint sourceBreakpoint, JPDADebugger debugger, int conditionResult, JPDAThread thread, ReferenceType referenceType, Variable variable ) { super (sourceBreakpoint); this.conditionResult = conditionResult; this.thread = thread; this.debugger = debugger; this.referenceType = referenceType; this.variable = variable; }
Example #12
Source File: InvokableTypeImpl.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@Override boolean isAssignableTo(ReferenceType type) { ClassTypeImpl superclazz = (ClassTypeImpl) superclass(); if (this.equals(type)) { return true; } else if ((superclazz != null) && superclazz.isAssignableTo(type)) { return true; } else { List<InterfaceType> interfaces = interfaces(); Iterator<InterfaceType> iter = interfaces.iterator(); while (iter.hasNext()) { InterfaceTypeImpl interfaze = (InterfaceTypeImpl) iter.next(); if (interfaze.isAssignableTo(type)) { return true; } } return false; } }
Example #13
Source File: InvokableTypeImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override final List<ReferenceType> inheritedTypes() { List<ReferenceType> inherited = new ArrayList<>(); if (superclass() != null) { inherited.add(0, superclass()); /* insert at front */ } for (ReferenceType rt : interfaces()) { inherited.add(rt); } return inherited; }
Example #14
Source File: InvokableTypeImpl.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Override final List<ReferenceType> inheritedTypes() { List<ReferenceType> inherited = new ArrayList<>(); if (superclass() != null) { inherited.add(0, superclass()); /* insert at front */ } for (ReferenceType rt : interfaces()) { inherited.add(rt); } return inherited; }
Example #15
Source File: VMCache.java From netbeans with Apache License 2.0 | 5 votes |
/** * Get a cached type of name 'name' that encloses 'type'. * @return The cached type, or <code>null</code>. */ ReferenceType getEnclosingType(ReferenceType type, String name) { CEncl classEnclosing = new CEncl(type, name); ReferenceType enclosingType; synchronized (enclosingTypes) { enclosingType = enclosingTypes.get(classEnclosing); } return enclosingType; }
Example #16
Source File: ExceptionSpec.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * The 'refType' is known to match, return the EventRequest. */ @Override EventRequest resolveEventRequest(ReferenceType refType) { EventRequestManager em = refType.virtualMachine().eventRequestManager(); ExceptionRequest excReq = em.createExceptionRequest(refType, notifyCaught, notifyUncaught); excReq.enable(); return excReq; }
Example #17
Source File: VMCache.java From netbeans with Apache License 2.0 | 5 votes |
/** * Get a cached version of a basic Java class, which is used often. * Use for Java platform classes only. * @param name the class name * @return the reference type or <code>null</code> */ ReferenceType getClass(String name) { ReferenceType rt; synchronized (cachedClasses) { rt = cachedClasses.get(name); if (rt == null) { rt = loadClass(name); if (rt != null) { cachedClasses.put(name, rt); } } } return rt; }
Example #18
Source File: VMCache.java From netbeans with Apache License 2.0 | 5 votes |
/** * Set an enclosing type of name 'name' that encloses 'type'. */ void setEnclosingType(ReferenceType type, String name, ReferenceType enclosingType) { CEncl classEnclosing = new CEncl(type, name); synchronized (enclosingTypes) { enclosingTypes.put(classEnclosing, enclosingType); } }
Example #19
Source File: ExceptionSpec.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * The 'refType' is known to match. */ @Override void resolve(ReferenceType refType) { setRequest(refType.virtualMachine().eventRequestManager() .createExceptionRequest(refType, notifyCaught, notifyUncaught)); }
Example #20
Source File: FieldMonitor.java From hottub with GNU General Public License v2.0 | 5 votes |
private static void addFieldWatch(VirtualMachine vm, ReferenceType refType) { EventRequestManager erm = vm.eventRequestManager(); Field field = refType.fieldByName(FIELD_NAME); ModificationWatchpointRequest modificationWatchpointRequest = erm .createModificationWatchpointRequest(field); modificationWatchpointRequest.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD); modificationWatchpointRequest.setEnabled(true); }
Example #21
Source File: InvokableTypeImpl.java From hottub with GNU General Public License v2.0 | 5 votes |
@Override final List<ReferenceType> inheritedTypes() { List<ReferenceType> inherited = new ArrayList<>(); if (superclass() != null) { inherited.add(0, superclass()); /* insert at front */ } for (ReferenceType rt : interfaces()) { inherited.add(rt); } return inherited; }
Example #22
Source File: VariableMirrorTranslator.java From netbeans with Apache License 2.0 | 5 votes |
private static void setValueToFinalField(ObjectReference obj, String name, ClassType clazz, Value fv, VirtualMachine vm, ThreadReference thread) throws InternalExceptionWrapper, VMDisconnectedExceptionWrapper, ClassNotPreparedExceptionWrapper, ClassNotLoadedException, ObjectCollectedExceptionWrapper, IncompatibleThreadStateException, UnsupportedOperationExceptionWrapper, InvalidTypeException, InvalidObjectException { ObjectReference fieldRef = getDeclaredOrInheritedField(clazz, name, vm, thread); if (fieldRef == null) { InvalidObjectException ioex = new InvalidObjectException("No field "+name+" of class "+clazz); throw ioex; } // field.setAccessible(true); ClassType fieldClassType = (ClassType) ValueWrapper.type(fieldRef); com.sun.jdi.Method setAccessibleMethod = ClassTypeWrapper.concreteMethodByName( fieldClassType, "setAccessible", "(Z)V"); try { ObjectReferenceWrapper.invokeMethod(fieldRef, thread, setAccessibleMethod, Collections.singletonList(vm.mirrorOf(true)), ClassType.INVOKE_SINGLE_THREADED); // field.set(newInstance, fv); com.sun.jdi.Method setMethod = ClassTypeWrapper.concreteMethodByName( fieldClassType, "set", "(Ljava/lang/Object;Ljava/lang/Object;)V"); if (fv instanceof PrimitiveValue) { PrimitiveType pt = (PrimitiveType) ValueWrapper.type(fv); ReferenceType fieldBoxingClass = EvaluatorVisitor.adjustBoxingType(clazz, pt, null); fv = EvaluatorVisitor.box((PrimitiveValue) fv, fieldBoxingClass, thread, null); } List<Value> args = Arrays.asList(new Value[] { obj, fv }); ObjectReferenceWrapper.invokeMethod(fieldRef, thread, setMethod, args, ClassType.INVOKE_SINGLE_THREADED); } catch (InvocationException iex) { throw new InvalidObjectException( "Problem setting value "+fv+" to field "+name+" of class "+clazz+ " : "+iex.exception()); } }
Example #23
Source File: Breakpoint.java From java-debug with Eclipse Public License 1.0 | 5 votes |
private static List<Location> collectLocations(List<ReferenceType> refTypes, int lineNumber, boolean includeNestedTypes) { List<Location> locations = new ArrayList<>(); try { refTypes.forEach(refType -> { List<Location> newLocations = collectLocations(refType, lineNumber); if (!newLocations.isEmpty()) { locations.addAll(newLocations); } else if (includeNestedTypes) { // ReferenceType.nestedTypes() will invoke vm.allClasses() to list all loaded classes, // should avoid using nestedTypes for performance. for (ReferenceType nestedType : refType.nestedTypes()) { List<Location> nestedLocations = collectLocations(nestedType, lineNumber); if (!nestedLocations.isEmpty()) { locations.addAll(nestedLocations); break; } } } }); } catch (VMDisconnectedException ex) { // collect locations operation may be executing while JVM is terminating, thus the VMDisconnectedException may be // possible, in case of VMDisconnectedException, this method will return an empty array which turns out a valid // response in vscode, causing no error log in trace. } return locations; }
Example #24
Source File: JdiExecutionControl.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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 #25
Source File: InvokableTypeImpl.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@Override final List<ReferenceType> inheritedTypes() { List<ReferenceType> inherited = new ArrayList<>(); if (superclass() != null) { inherited.add(0, superclass()); /* insert at front */ } for (ReferenceType rt : interfaces()) { inherited.add(rt); } return inherited; }
Example #26
Source File: SourcePath.java From netbeans with Apache License 2.0 | 5 votes |
public String getURL ( Location loc, String stratumn ) throws InternalExceptionWrapper, VMDisconnectedExceptionWrapper, ObjectCollectedExceptionWrapper { ReferenceType declaringType = LocationWrapper.declaringType(loc); JPDAClassType classType = ((JPDADebuggerImpl) debugger).getClassType(declaringType); return getURL(classType, loc, stratumn); }
Example #27
Source File: RemoteServices.java From netbeans with Apache License 2.0 | 5 votes |
static ArrayType getArrayClass(VirtualMachine vm, String name) throws InternalExceptionWrapper, VMDisconnectedExceptionWrapper, ObjectCollectedExceptionWrapper { List<ReferenceType> classList = VirtualMachineWrapper.classesByName(vm, name); ReferenceType clazz = null; for (ReferenceType c : classList) { if (ReferenceTypeWrapper.classLoader(c) == null) { clazz = c; break; } } return (ArrayType) clazz; }
Example #28
Source File: RemoteServices.java From netbeans with Apache License 2.0 | 5 votes |
static ClassType getClass(VirtualMachine vm, String name) throws InternalExceptionWrapper, VMDisconnectedExceptionWrapper, ObjectCollectedExceptionWrapper { 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 #29
Source File: ExceptionSpec.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * The 'refType' is known to match. */ @Override void resolve(ReferenceType refType) { setRequest(refType.virtualMachine().eventRequestManager() .createExceptionRequest(refType, notifyCaught, notifyUncaught)); }
Example #30
Source File: ExceptionSpec.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * The 'refType' is known to match, return the EventRequest. */ @Override EventRequest resolveEventRequest(ReferenceType refType) { EventRequestManager em = refType.virtualMachine().eventRequestManager(); ExceptionRequest excReq = em.createExceptionRequest(refType, notifyCaught, notifyUncaught); excReq.enable(); return excReq; }