com.sun.jdi.ObjectReference Java Examples

The following examples show how to use com.sun.jdi.ObjectReference. 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: ComponentBreakpointActionProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static ComponentBreakpoint findBreakpoint (ObjectReference component) {
    Breakpoint[] breakpoints = DebuggerManager.getDebuggerManager().getBreakpoints();
    for (int i = 0; i < breakpoints.length; i++) {
        if (!(breakpoints[i] instanceof ComponentBreakpoint)) {
            continue;
        }
        ComponentBreakpoint ab = (ComponentBreakpoint) breakpoints[i];
        Session currentSession = DebuggerManager.getDebuggerManager().getCurrentSession();
        if (currentSession != null) {
            JPDADebugger debugger = currentSession.lookupFirst(null, JPDADebugger.class);
            if (debugger != null) {
                if (component.equals(ab.getComponent().getComponent(debugger))) {
                    return ab;
                }
            }
        }
    }
    return null;
}
 
Example #2
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 #3
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 #4
Source File: AWTGrabHandler.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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.<Value>emptyList(), ObjectReference.INVOKE_SINGLE_THREADED);
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("FX Window "+w+" was successfully ungrabbed.");
        }
    }
}
 
Example #5
Source File: JPDAThreadImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private Pair<List<JPDAThread>, List<JPDAThread>> updateLockerThreads(
        Map<ThreadReference, ObjectReference> lockedThreadsWithMonitors,
        ObjectReference waitingMonitor) throws InternalExceptionWrapper,
                                               VMDisconnectedExceptionWrapper,
                                               ObjectCollectedExceptionWrapper,
                                               IllegalThreadStateExceptionWrapper {
    List<JPDAThread> oldLockerThreadsList;
    List<JPDAThread> newLockerThreadsList;
    synchronized (lockerThreadsLock) {
        oldLockerThreadsList = lockerThreadsList;
        if (lockedThreadsWithMonitors != null) {
            //lockerThreads2 = lockedThreadsWithMonitors;
            lockerThreadsMonitor = waitingMonitor;
            if (!submitMonitorEnteredFor(waitingMonitor)) {
                submitCheckForMonitorEntered(waitingMonitor);
            }
            lockerThreadsList = new ThreadListDelegate(debugger, new ArrayList(lockedThreadsWithMonitors.keySet()));
        } else {
            //lockerThreads2 = null;
            lockerThreadsMonitor = null;
            lockerThreadsList = null;
        }
        newLockerThreadsList = lockerThreadsList;
    }
    return Pair.of(oldLockerThreadsList, newLockerThreadsList);
}
 
Example #6
Source File: WatchesModel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public boolean isLeaf (Object node) throws UnknownTypeException {
    if (node == ROOT) return false;
    if (node instanceof JPDAWatchEvaluating) {
        JPDAWatchEvaluating jwe = (JPDAWatchEvaluating) node;
        if (!jwe.getWatch().isEnabled()) {
            return true;
        }
        if (!jwe.isCurrent()) {
            return false; // When not yet evaluated, suppose that it's not leaf
        }
        JPDAWatch jw = jwe.getEvaluatedWatch();
        if (jw instanceof AbstractVariable) {
            return !(((AbstractVariable) jw).getInnerValue() instanceof ObjectReference);
        }
    }
    if (node == EMPTY_WATCH) return true;
    return getLocalsTreeModel ().isLeaf (node);
}
 
Example #7
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 #8
Source File: FieldVariable.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public FieldVariable (
    JPDADebuggerImpl debugger,
    PrimitiveValue value,
//    String className,
    Field field,
    String parentID,
    ObjectReference objectReference    // instance or null for static fields
) {
    super (
        debugger, 
        value, 
        getID(parentID, field)
    );
    this.field = field;
    //this.className = className;
    this.objectReference = objectReference;
}
 
Example #9
Source File: DecisionProcedureGuidanceJDI.java    From jbse with GNU General Public License v3.0 6 votes vote down vote up
@Override
public String typeOfObject(ReferenceSymbolic origin) throws GuidanceException {
    final ObjectReference object = (ObjectReference) getJDIValue(origin);
    if (object == null) {
        return null;
    }
    final StringBuilder buf = new StringBuilder();
    String name = object.referenceType().name();
    boolean isArray = false;
    while (name.endsWith("[]")) {
        isArray = true;
        buf.append("[");
        name = name.substring(0, name.length() - 2);
    }
    buf.append(isPrimitiveOrVoidCanonicalName(name) ? toPrimitiveOrVoidInternalName(name) : (isArray ? REFERENCE : "") + internalClassName(name) + (isArray ? TYPEEND : ""));
    return buf.toString();
}
 
Example #10
Source File: RemoteServices.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private synchronized boolean remove(ObjectReference component, ClassObjectReference listenerClass, LoggingListenerCallBack listener) {
    Map<ClassObjectReference, Set<LoggingListenerCallBack>> listeners = componentListeners.get(component);
    if (listeners == null) {
        return false;
    }
    Set<LoggingListenerCallBack> lcb = listeners.get(listenerClass);
    if (lcb == null) {
        return false;
    }
    boolean removed = lcb.remove(listener);
    if (removed) {
        if (lcb.isEmpty()) {
            listeners.remove(listenerClass);
            if (listeners.isEmpty()) {
                componentListeners.remove(component);
            }
        }
    }
    return removed;
}
 
Example #11
Source File: JPDAThreadImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void submitCheckForMonitorEntered(ObjectReference waitingMonitor) throws InternalExceptionWrapper, VMDisconnectedExceptionWrapper, ObjectCollectedExceptionWrapper, IllegalThreadStateExceptionWrapper {
    try {
        ThreadReferenceWrapper.suspend(threadReference);
        logger.fine("submitCheckForMonitorEntered(): suspending "+threadName);
        ObjectReference monitor = ThreadReferenceWrapper.currentContendedMonitor(threadReference);
        if (monitor == null) return ;
        Location loc = StackFrameWrapper.location(ThreadReferenceWrapper.frame(threadReference, 0));
        loc = MethodWrapper.locationOfCodeIndex(LocationWrapper.method(loc), LocationWrapper.codeIndex(loc) + 1);
        if (loc == null) return;
        BreakpointRequest br = EventRequestManagerWrapper.createBreakpointRequest(
                VirtualMachineWrapper.eventRequestManager(MirrorWrapper.virtualMachine(threadReference)), loc);
        BreakpointRequestWrapper.addThreadFilter(br, threadReference);
        submitMonitorEnteredRequest(br);
    } catch (IncompatibleThreadStateException itex) {
        Exceptions.printStackTrace(itex);
    } catch (InvalidStackFrameExceptionWrapper isex) {
        Exceptions.printStackTrace(isex);
    } finally {
        logger.fine("submitCheckForMonitorEntered(): resuming "+threadName);
        ThreadReferenceWrapper.resume(threadReference);
    }
}
 
Example #12
Source File: ObjectFieldVariable.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public ObjectFieldVariable (
    JPDADebuggerImpl debugger,
    Field field,
    String parentID,
    String genericSignature,
    ObjectReference objectReference
) {
    this (
        debugger,
        null,
        field,
        parentID,
        genericSignature,
        objectReference
    );
    this.valueSet = false;
}
 
Example #13
Source File: BooleanFormatterTest.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testAcceptType() throws Exception {
    ObjectReference foo = this.getObjectReference("Foo");

    assertFalse("Should not accept null type.", formatter.acceptType(null, new HashMap<>()));

    assertFalse("Should not accept Foo type.", formatter.acceptType(foo.referenceType(), new HashMap<>()));

    ObjectReference str = this.getObjectReference("java.lang.String");
    assertFalse("Should not accept String type.", formatter.acceptType(str.referenceType(), new HashMap<>()));

    Value boolVar = getVM().mirrorOf(true);
    assertTrue("Should accept boolean type.", formatter.acceptType(boolVar.type(), new HashMap<>()));

    boolVar = this.getLocalValue("boolVar");
    assertFalse("Should not accept Boolean type.", formatter.acceptType(boolVar.type(), new HashMap<>()));
}
 
Example #14
Source File: SetVariableRequestHandler.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
private Value handleSetValueForObject(String name, String belongToClass, String valueString,
        ObjectReference container, Map<String, Object> options) throws InvalidTypeException, ClassNotLoadedException {
    Value newValue;
    if (container instanceof ArrayReference) {
        ArrayReference array = (ArrayReference) container;
        Type eleType = ((ArrayType) array.referenceType()).componentType();
        newValue = setArrayValue(array, eleType, Integer.parseInt(name), valueString, options);
    } else {
        if (StringUtils.isBlank(belongToClass)) {
            Field field = container.referenceType().fieldByName(name);
            if (field != null) {
                if (field.isStatic()) {
                    newValue = this.setStaticFieldValue(container.referenceType(), field, name, valueString, options);
                } else {
                    newValue = this.setObjectFieldValue(container, field, name, valueString, options);
                }
            } else {
                throw new IllegalArgumentException(
                        String.format("SetVariableRequest: Variable %s cannot be found.", name));
            }
        } else {
            newValue = setFieldValueWithConflict(container, container.referenceType().allFields(), name, belongToClass, valueString, options);
        }
    }
    return newValue;
}
 
Example #15
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 #16
Source File: StringObjectFormatterTest.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testAcceptType() throws Exception {
    ObjectReference foo = this.getObjectReference("Foo");

    assertFalse("Should not accept null type.", formatter.acceptType(null, new HashMap<>()));

    assertFalse("Should not accept Foo type.", formatter.acceptType(foo.referenceType(), new HashMap<>()));

    ObjectReference str = this.getObjectReference("java.lang.String");
    assertTrue("Should accept String type.", formatter.acceptType(str.referenceType(), new HashMap<>()));

    ObjectReference clz = this.getObjectReference("java.lang.Class");
    assertFalse("Should not accept Class type.", formatter.acceptType(clz.referenceType(), new HashMap<>()));

    LocalVariable list = this.getLocalVariable("strList");
    assertFalse("Should not accept List type.", formatter.acceptType(list.type(), new HashMap<>()));

    LocalVariable arrays = this.getLocalVariable("arrays");
    assertFalse("Should not accept array type.", formatter.acceptType(arrays.type(), new HashMap<>()));
}
 
Example #17
Source File: SetVariableRequestHandler.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
private Value setFieldValueWithConflict(ObjectReference obj, List<Field> fields, String name, String belongToClass,
                                        String value, Map<String, Object> options) throws ClassNotLoadedException, InvalidTypeException {
    Field field;
    // first try to resolve field by fully qualified name
    List<Field> narrowedFields = fields.stream().filter(TypeComponent::isStatic)
            .filter(t -> t.name().equals(name) && t.declaringType().name().equals(belongToClass))
            .collect(Collectors.toList());
    if (narrowedFields.isEmpty()) {
        // second try to resolve field by formatted name
        narrowedFields = fields.stream().filter(TypeComponent::isStatic)
                .filter(t -> t.name().equals(name)
                        && context.getVariableFormatter().typeToString(t.declaringType(), options).equals(belongToClass))
                .collect(Collectors.toList());
    }
    if (narrowedFields.size() == 1) {
        field = narrowedFields.get(0);
    } else {
        throw new UnsupportedOperationException(String.format("SetVariableRequest: Name conflicted for %s.", name));
    }
    return field.isStatic() ? setStaticFieldValue(field.declaringType(), field, name, value, options)
            : this.setObjectFieldValue(obj, field, name, value, options);
}
 
Example #18
Source File: ObjectArrayFieldVariable.java    From netbeans with Apache License 2.0 6 votes vote down vote up
ObjectArrayFieldVariable (
    JPDADebuggerImpl debugger,
    ObjectReference value,
    String declaredType,
    ObjectVariable array,
    int index,
    int maxIndex,
    String parentID
) {
    super (
        debugger, 
        value, 
        parentID + '.' + index + "^"
    );
    this.index = index;
    this.maxIndexLog = ArrayFieldVariable.log10(maxIndex);
    this.declaredType = declaredType;
    this.parent = array;
    this.array = (ArrayReference) ((JDIVariable) array).getJDIValue();
}
 
Example #19
Source File: EvaluationContext.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new context in which to evaluate expressions.
 *
 * @param frame the frame in which context evaluation occurs
 * @param imports list of imports
 * @param staticImports list of static imports
 */
public EvaluationContext(JPDAThreadImpl thread, StackFrame frame, int frameDepth,
                         ObjectReference contextVariable,
                         List<String> imports, List<String> staticImports,
                         boolean canInvokeMethods, Runnable methodInvokePreproc,
                         JPDADebuggerImpl debugger, VMCache vmCache) {
    if (thread == null) throw new IllegalArgumentException("Thread argument must not be null");
    if (frame == null) throw new IllegalArgumentException("Frame argument must not be null");
    if (imports == null) throw new IllegalArgumentException("Imports argument must not be null");
    if (staticImports == null) throw new IllegalArgumentException("Static imports argument must not be null");
    this.thread = thread;
    this.frame = frame;
    this.frameDepth = frameDepth;
    this.contextVariable = contextVariable;
    this.sourceImports = imports;
    this.staticImports = staticImports;
    this.canInvokeMethods = canInvokeMethods;
    this.methodInvokePreproc = methodInvokePreproc;
    this.debugger = debugger;
    this.vmCache = vmCache;

    stack.push(new HashMap<String, ScriptVariable>());
}
 
Example #20
Source File: VariableDetailUtils.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
private static boolean containsToStringMethod(ObjectReference obj) {
    ReferenceType refType = obj.referenceType();
    if (refType instanceof ClassType) {
        Method m = ((ClassType) refType).concreteMethodByName(TO_STRING_METHOD, TO_STRING_METHOD_SIGNATURE);
        if (m != null) {
            if (!Objects.equals("Ljava/lang/Object;", m.declaringType().signature())) {
                return true;
            }
        }

        for (InterfaceType iface : ((ClassType) refType).allInterfaces()) {
            List<Method> matches = iface.methodsByName(TO_STRING_METHOD, TO_STRING_METHOD_SIGNATURE);
            for (Method ifaceMethod : matches) {
                if (!ifaceMethod.isAbstract()) {
                    return true;
                }
            }
        }
    }

    return false;
}
 
Example #21
Source File: ArrayFieldVariable.java    From netbeans with Apache License 2.0 6 votes vote down vote up
ArrayFieldVariable (
    JPDADebuggerImpl debugger,
    PrimitiveValue value,
    String declaredType,
    ObjectVariable array,
    int index,
    int maxIndex,
    String parentID
) {
    super (
        debugger, 
        value, 
        parentID + '.' + index +
            (value instanceof ObjectReference ? "^" : "")
    );
    this.index = index;
    this.maxIndexLog = log10(maxIndex);
    this.declaredType = declaredType;
    this.parent = array;
    this.array = (ArrayReference) ((JDIVariable) array).getJDIValue();
}
 
Example #22
Source File: JdtEvaluationProvider.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public CompletableFuture<Value> evaluate(String expression, ObjectReference thisContext, ThreadReference thread) {
    CompletableFuture<Value> completableFuture = new CompletableFuture<>();
    try  {
        ensureDebugTarget(thisContext.virtualMachine(), thisContext.type().name());
        JDIThread jdiThread = getMockJDIThread(thread);
        JDIObjectValue jdiObject = new JDIObjectValue(debugTarget, thisContext);
        ASTEvaluationEngine engine = new ASTEvaluationEngine(project, debugTarget);
        ICompiledExpression compiledExpression = engine.getCompiledExpression(expression, jdiObject);
        internalEvaluate(engine, compiledExpression, jdiObject, jdiThread, completableFuture);
        return completableFuture;
    } catch (Exception ex) {
        completableFuture.completeExceptionally(ex);
        return completableFuture;
    }
}
 
Example #23
Source File: JavaLogicalStructure.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
private static Value getValue(ObjectReference thisObject, LogicalStructureExpression expression, ThreadReference thread,
        IEvaluationProvider evaluationEngine) throws CancellationException, IllegalArgumentException, InterruptedException, ExecutionException {
    if (expression.type == LogicalStructureExpressionType.METHOD) {
        if (expression.value == null || expression.value.length < 2) {
            throw new IllegalArgumentException("The method expression should contain at least methodName and methodSignature!");
        }
        return evaluationEngine.invokeMethod(thisObject, expression.value[0], expression.value[1], null, thread, false).get();
    } else if (expression.type == LogicalStructureExpressionType.FIELD) {
        if (expression.value == null || expression.value.length < 1) {
            throw new IllegalArgumentException("The field expression should contain the field name!");
        }
        return getValueByField(thisObject, expression.value[0], thread);
    } else {
        if (expression.value == null || expression.value.length < 1) {
            throw new IllegalArgumentException("The evaluation expression should contain a valid expression statement!");
        }
        return evaluationEngine.evaluate(expression.value[0], thisObject, thread).get();
    }
}
 
Example #24
Source File: RemoteServices.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private synchronized boolean remove(ObjectReference component, ClassObjectReference listenerClass, LoggingListenerCallBack listener) {
    Map<ClassObjectReference, Set<LoggingListenerCallBack>> listeners = componentListeners.get(component);
    if (listeners == null) {
        return false;
    }
    Set<LoggingListenerCallBack> lcb = listeners.get(listenerClass);
    if (lcb == null) {
        return false;
    }
    boolean removed = lcb.remove(listener);
    if (removed) {
        if (lcb.isEmpty()) {
            listeners.remove(listenerClass);
            if (listeners.isEmpty()) {
                componentListeners.remove(component);
            }
        }
    }
    return removed;
}
 
Example #25
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 #26
Source File: TakeScreenshotActionProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void unmarkBreakpoint(RemoteScreenshot screenshot, ComponentBreakpoint b) {
    ComponentBreakpoint.ComponentDescription cd = ((ComponentBreakpoint) b).getComponent();
    if (cd != null) {
        ObjectReference oc = cd.getComponent(debugger);
        if (oc != null) {
            ComponentInfo ci = findComponentInfo(screenshot.getComponentInfo(), oc);
            if (ci != null) {
                screenshot.getScreenshotUIManager().unmarkBreakpoint(ci);
            }
        }
    }
}
 
Example #27
Source File: LineBreakpointImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void setFilters(BreakpointRequest br) throws InternalExceptionWrapper, VMDisconnectedExceptionWrapper {
    JPDAThread[] threadFilters = getBreakpoint().getThreadFilters(getDebugger());
    if (threadFilters != null && threadFilters.length > 0) {
        for (JPDAThread t : threadFilters) {
            BreakpointRequestWrapper.addThreadFilter(br, ((JPDAThreadImpl) t).getThreadReference());
        }
    }
    ObjectVariable[] varFilters = getBreakpoint().getInstanceFilters(getDebugger());
    if (varFilters != null && varFilters.length > 0) {
        for (ObjectVariable v : varFilters) {
            BreakpointRequestWrapper.addInstanceFilter(br, (ObjectReference) ((JDIVariable) v).getJDIValue());
        }
    }
}
 
Example #28
Source File: JavaLogicalStructureManager.java    From java-debug with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Return the provided logical structure handler for the given variable.
 */
public static JavaLogicalStructure getLogicalStructure(ObjectReference obj) {
    for (JavaLogicalStructure structure : supportedLogicalStructures) {
        if (structure.providesLogicalStructure(obj)) {
            return structure;
        }
    }

    return null;
}
 
Example #29
Source File: JPDAWatchImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
JPDAWatchImpl (JPDADebuggerImpl debugger, Watch watch, PrimitiveValue v) {
    super (
        debugger,
        v, 
        "" + watch +
            (v instanceof ObjectReference ? "^" : "")
    );
    this.debugger = debugger;
    this.watch = watch;
}
 
Example #30
Source File: TakeScreenshotActionProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private ComponentInfo findComponentInfo(ComponentInfo ci, ObjectReference oc) {
    if (ci instanceof JavaComponentInfo) {
        ObjectReference or = ((JavaComponentInfo) ci).getComponent();
        if (oc.equals(or)) {
            return ci;
        }
    }
    for (ComponentInfo sci : ci.getSubComponents()) {
        ComponentInfo fci = findComponentInfo(sci, oc);
        if (fci != null) {
            return fci;
        }
    }
    return null;
}