@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); } }
/** * 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; }
/** * JDI addition: Determines if this is a F3 class. * * @return <code>true</code> if this is a F3 class; false otherwise. */ @Override public boolean isF3Type() { if (!isIsF3TypeSet) { isIsF3TypeSet = true; F3VirtualMachine f3vm = virtualMachine(); InterfaceType f3ObjType = (InterfaceType) F3Wrapper.unwrap(f3vm.f3ObjectType()); if (f3ObjType != null) { ClassType thisType = underlying(); List<InterfaceType> allIfaces = thisType.allInterfaces(); for (InterfaceType iface : allIfaces) { if (iface.equals(f3ObjType)) { isF3Type = true; break; } } } } return isF3Type; }
private void handleClassLoad(final ClassType classType, final ThreadReference thread) { // do not proceed if this part of the hierarchy has been processed if (contourFactory().lookupStaticContour(classType.name()) == null) { // update the meta-data for this type and all other types in its file resolveType(classType); // handle the super class final ClassType superClass = classType.superclass(); // if a class is in-model, all its ancestors must be in-model so that the proper static // contours and their members exist if (superClass != null) { handleClassLoad(superClass, thread); } // Only static and top-level types have static contours, *including* nested static types. if (classType.isStatic() || !isNestedType(classType)) { // creates and dispatches a type load event for this type manager().jiveDispatcher().dispatchLoadEvent(classType, thread); } } }
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.EMPTY_LIST, 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; }
private static ObjectReference getQuantumTookitClassLoader(VirtualMachine vm) throws InternalExceptionWrapper, VMDisconnectedExceptionWrapper, ObjectCollectedExceptionWrapper { ClassType classQuantumToolkit = getClass(vm, "com.sun.javafx.tk.quantum.QuantumToolkit"); if (classQuantumToolkit == null) { return null; } ClassLoaderReference cl = ReferenceTypeWrapper.classLoader(classQuantumToolkit); return cl; }
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); } }
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; }
private static Type boxType(Type t) { if (t instanceof ClassType) { String name = ((ClassType) t).name(); if (name.equals("java.lang.Boolean")) { t = t.virtualMachine().mirrorOf(true).type(); } else if (name.equals("java.lang.Byte")) { t = t.virtualMachine().mirrorOf((byte) 10).type(); } else if (name.equals("java.lang.Character")) { t = t.virtualMachine().mirrorOf('a').type(); } else if (name.equals("java.lang.Integer")) { t = t.virtualMachine().mirrorOf(10).type(); } else if (name.equals("java.lang.Long")) { t = t.virtualMachine().mirrorOf(10l).type(); } else if (name.equals("java.lang.Short")) { t = t.virtualMachine().mirrorOf((short)10).type(); } else if (name.equals("java.lang.Float")) { t = t.virtualMachine().mirrorOf(10f).type(); } else if (name.equals("java.lang.Double")) { t = t.virtualMachine().mirrorOf(10.0).type(); } } return t; }
@Override public Super getSuperClass() { if (classType instanceof ClassType) { try { ClassType superClass = ClassTypeWrapper.superclass((ClassType) classType); if (superClass == null) { return null; } else { return new SuperVariable(debugger, null, superClass, getName()); } } catch (InternalExceptionWrapper | VMDisconnectedExceptionWrapper ex) { return null; } } else { return null; } }
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; }
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; } }
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; }
private static Type unboxType(Type t) { if (t instanceof ClassType) { String name = ((ClassType) t).name(); if (name.equals("java.lang.Boolean")) { t = t.virtualMachine().mirrorOf(true).type(); } else if (name.equals("java.lang.Byte")) { t = t.virtualMachine().mirrorOf((byte) 10).type(); } else if (name.equals("java.lang.Character")) { t = t.virtualMachine().mirrorOf('a').type(); } else if (name.equals("java.lang.Integer")) { t = t.virtualMachine().mirrorOf(10).type(); } else if (name.equals("java.lang.Long")) { t = t.virtualMachine().mirrorOf(10l).type(); } else if (name.equals("java.lang.Short")) { t = t.virtualMachine().mirrorOf((short)10).type(); } else if (name.equals("java.lang.Float")) { t = t.virtualMachine().mirrorOf(10f).type(); } else if (name.equals("java.lang.Double")) { t = t.virtualMachine().mirrorOf(10.0).type(); } } return t; }
@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); } }
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; }
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 & VirtualMachine.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; }
void writeLocation(Location location) { ReferenceTypeImpl refType = (ReferenceTypeImpl)location.declaringType(); byte tag; if (refType instanceof ClassType) { tag = JDWP.TypeTag.CLASS; } else if (refType instanceof InterfaceType) { // It's possible to have executable code in an interface tag = JDWP.TypeTag.INTERFACE; } else { throw new InternalException("Invalid Location"); } writeByte(tag); writeClassRef(refType.ref()); writeMethodRef(((MethodImpl)location.method()).ref()); writeLong(location.codeIndex()); }
public ClassType superclass() { if (!cachedSuperclass) { ClassTypeImpl sup = null; try { sup = JDWP.ClassType.Superclass. process(vm, this).superclass; } catch (JDWPException exc) { throw exc.toJDIException(); } /* * If there is a superclass, cache its * ClassType here. Otherwise, * leave the cache reference null. */ if (sup != null) { superclass = sup; } cachedSuperclass = true; } return superclass; }
PacketStream sendNewInstanceCommand(final ThreadReferenceImpl thread, final MethodImpl method, final ValueImpl[] args, final int options) { CommandSender sender = new CommandSender() { public PacketStream send() { return JDWP.ClassType.NewInstance.enqueueCommand( vm, ClassTypeImpl.this, thread, method.ref(), args, options); } }; PacketStream stream; if ((options & INVOKE_SINGLE_THREADED) != 0) { stream = thread.sendResumingCommand(sender); } else { stream = vm.sendResumingCommand(sender); } return stream; }
List getAllMethods() { ArrayList 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 */ Iterator iter = allInterfaces().iterator(); while (iter.hasNext()) { InterfaceType interfaze = (InterfaceType)iter.next(); list.addAll(interfaze.methods()); } return list; }
@Nullable public static PsiType getCastableRuntimeType(Project project, Value value) { Type type = value.type(); PsiType psiType = findPsiType(project, type); if (psiType != null) { return psiType; } if (type instanceof ClassType) { ClassType superclass = ((ClassType)type).superclass(); if (superclass != null && !CommonClassNames.JAVA_LANG_OBJECT.equals(superclass.name())) { psiType = findPsiType(project, superclass); if (psiType != null) { return psiType; } } for (InterfaceType interfaceType : ((ClassType)type).interfaces()) { psiType = findPsiType(project, interfaceType); if (psiType != null) { return psiType; } } } return null; }
public static PsiClass getCastableRuntimeType(Project project, Value value) { Type type = value.type(); PsiClass psiClass = findPsiClass(project, type); if (psiClass != null) { return psiClass; } if (type instanceof ClassType) { ClassType superclass = ((ClassType)type).superclass(); if (superclass != null && !CommonClassNames.JAVA_LANG_OBJECT.equals(superclass.name())) { psiClass = findPsiClass(project, superclass); if (psiClass != null) { return psiClass; } } for (InterfaceType interfaceType : ((ClassType)type).interfaces()) { psiClass = findPsiClass(project, interfaceType); if (psiClass != null) { return psiClass; } } } return null; }
private ClassSummary(final String declaredTypeName, final ObjectReference object) { final String superClassName = object != null && object.type() instanceof ClassType && ((ClassType) object.type()).superclass() != null ? ((ClassType) object.type()) .superclass().toString() : ""; final String typeName = object.referenceType().toString(); // out-of-model enum types are resolved isEnum = object.referenceType() instanceof ClassType && ((ClassType) object.referenceType()).isEnum(); // string types are resolved isString = typeName.equals("java.lang.String"); // characters and strings are resolved and escaped isEscaped = typeName.equals("java.lang.Character") || isString; // all number types descendant from Number are resolved isNumber = superClassName.equals("java.lang.Number") && !typeName.contains("Atomic"); // date types are resolved isDate = typeName.equals("java.util.Date"); // boolean types are resolved isBoolean = typeName.equals("java.lang.Boolean"); // declared and actual types match matchingTypes = typeName.equals(declaredTypeName); // actual type name actualTypeName = typeName.substring(typeName.lastIndexOf(".") + 1); }
private boolean ungrabWindowFX(ThreadReference tr) { // javafx.stage.Window.impl_getWindows() - Iterator<Window> // while (iterator.hasNext()) { // Window w = iterator.next(); // ungrabWindowFX(w); // } try { VirtualMachine vm = MirrorWrapper.virtualMachine(tr); List<ReferenceType> windowClassesByName = VirtualMachineWrapper.classesByName(vm, "javafx.stage.Window"); if (windowClassesByName.isEmpty()) { logger.info("Unable to release FX X grab, no javafx.stage.Window class in target VM "+VirtualMachineWrapper.description(vm)); return true; // We do not know whether there was any grab } ClassType WindowClass = (ClassType) windowClassesByName.get(0); Method getWindowsMethod = WindowClass.concreteMethodByName("impl_getWindows", "()Ljava/util/Iterator;"); if (getWindowsMethod == null) { logger.info("Unable to release FX X grab, no impl_getWindows() method in "+WindowClass); return true; // We do not know whether there was any grab } ObjectReference windowsIterator = (ObjectReference) WindowClass.invokeMethod(tr, getWindowsMethod, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED); if (windowsIterator == null) { return true; // We do not know whether there was any grab } InterfaceType IteratorClass = (InterfaceType) VirtualMachineWrapper.classesByName(vm, Iterator.class.getName()).get(0); Method hasNext = IteratorClass.methodsByName("hasNext", "()Z").get(0); Method next = IteratorClass.methodsByName("next", "()Ljava/lang/Object;").get(0); while (hasNext(hasNext, tr, windowsIterator)) { ObjectReference w = next(next, tr, windowsIterator); ungrabWindowFX(WindowClass, w, tr); } } catch (VMDisconnectedExceptionWrapper vmdex) { return true; // Disconnected, all is good. } catch (Exception ex) { logger.log(Level.INFO, "Unable to release FX X grab (if any).", ex); return true; // We do not know whether there was any grab } return true; }
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.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED); if (logger.isLoggable(Level.FINE)) { logger.fine("FX Window "+w+" was successfully ungrabbed."); } } }
private boolean ungrabWindowFX_OLD(ThreadReference tr) { // com.sun.javafx.tk.quantum.WindowStage has: // field static Map<Window, WindowStage> platformWindows = new HashMap<>(); // com.sun.glass.ui.Window.ungrabFocus() try { VirtualMachine vm = MirrorWrapper.virtualMachine(tr); List<ReferenceType> windowStageClassesByName = VirtualMachineWrapper.classesByName(vm, "com.sun.javafx.tk.quantum.WindowStage"); if (windowStageClassesByName.isEmpty()) { logger.info("Unable to release FX X grab, no quantum WindowStage class in target VM "+VirtualMachineWrapper.description(vm)); return false; } ClassType WindowStageClass = (ClassType) windowStageClassesByName.get(0); Field platformWindowsField = WindowStageClass.fieldByName("platformWindows"); if (platformWindowsField == null) { logger.info("Unable to release FX X grab, no platformWindows field found in WindowStage in target VM "+VirtualMachineWrapper.description(vm)); return false; } ObjectReference platformWindows = (ObjectReference) WindowStageClass.getValue(platformWindowsField); if (platformWindows == null) { logger.info("Unable to release FX X grab, no platformWindows field has null value in WindowStage in target VM "+VirtualMachineWrapper.description(vm)); return false; } } catch (VMDisconnectedExceptionWrapper vmdex) { return true; // Disconnected, all is good. } catch (Exception ex) { logger.log(Level.INFO, "Unable to release FX X grab (if any).", ex); return true; // We do not know whether there was any grab } return true; }
private static boolean isAssignable(ClassType ct1, ClassType ct2) { // return ct1.isAssignableFrom(ct2) if (ct1.equals(ct2)) { return true; } ClassType cts = ct2.superclass(); if (cts != null) { return isAssignable(ct1, cts); } else { return false; } }