com.sun.jdi.BooleanValue Java Examples

The following examples show how to use com.sun.jdi.BooleanValue. 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: BooleanFormatterTest.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testValueOf() throws Exception {
    Map<String, Object> options = formatter.getDefaultOptions();
    Value boolVar = getVM().mirrorOf(true);
    Value newValue = formatter.valueOf("true", boolVar.type(), options);
    assertTrue("should return boolean type", newValue instanceof BooleanValue);
    assertTrue("should return boolean type", ((BooleanValue)newValue).value());
    assertEquals("Should be able to restore boolean value.", "true",
        formatter.toString(newValue, options));

    newValue = formatter.valueOf("True", boolVar.type(), options);
    assertTrue("should return boolean type", newValue instanceof BooleanValue);
    assertTrue("should return boolean type", ((BooleanValue)newValue).value());

    newValue = formatter.valueOf("false", boolVar.type(), options);
    assertTrue("should return boolean type", newValue instanceof BooleanValue);
    assertFalse("should return boolean 'false'", ((BooleanValue)newValue).value());

    newValue = formatter.valueOf("False", boolVar.type(), options);
    assertTrue("should return boolean type", newValue instanceof BooleanValue);
    assertFalse("should return boolean 'false'", ((BooleanValue)newValue).value());

    newValue = formatter.valueOf("abc", boolVar.type(), options);
    assertTrue("should return boolean type", newValue instanceof BooleanValue);
    assertFalse("should return boolean 'false'", ((BooleanValue)newValue).value());
}
 
Example #2
Source File: DecisionProcedureGuidanceJDI.java    From jbse with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Object getValue(Symbolic origin) throws GuidanceException {
    final com.sun.jdi.Value val = (com.sun.jdi.Value) getJDIValue(origin);
    if (val instanceof IntegerValue) {
        return this.calc.valInt(((IntegerValue) val).intValue());
    } else if (val instanceof BooleanValue) {
        return this.calc.valBoolean(((BooleanValue) val).booleanValue());
    } else if (val instanceof CharValue) {
        return this.calc.valChar(((CharValue) val).charValue());
    } else if (val instanceof ByteValue) {
        return this.calc.valByte(((ByteValue) val).byteValue());
    } else if (val instanceof DoubleValue) {
        return this.calc.valDouble(((DoubleValue) val).doubleValue());
    } else if (val instanceof FloatValue) {
        return this.calc.valFloat(((FloatValue) val).floatValue());
    } else if (val instanceof LongValue) {
        return this.calc.valLong(((LongValue) val).longValue());
    } else if (val instanceof ShortValue) {
        return this.calc.valShort(((ShortValue) val).shortValue());
    } else if (val instanceof ObjectReference) {
        return val;
    } else { //val instanceof VoidValue || val == null
        return null;
    }
}
 
Example #3
Source File: VMTargetRemoteTest.java    From gravel with Apache License 2.0 6 votes vote down vote up
@Test
public void testEvaluate() throws Throwable {
	ObjectReference promise = remote.evaluateForked("3+4");
	ThreadReference thread = ((ThreadReference) remote.invokeMethod(
			promise, "thread"));
	Value result1 = remote.invokeMethod(promise, "result");
	Value ex = remote.invokeMethod(promise, "throwable");
	printThreadState();
	VMTargetStarter.sleep(100);
	printThreadState();

	boolean isFinished = ((BooleanValue) remote.invokeMethod(promise,
			"isFinished")).booleanValue();

	assertTrue(isFinished);
	ObjectReference result = (ObjectReference) remote.invokeMethod(promise,
			"result");
	IntegerValue intValue = (IntegerValue) remote.invokeMethod(result,
			"intValue");
	assertEquals(7, intValue.intValue());
}
 
Example #4
Source File: RemoteFXScreenshot.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void retrieveScreenshots(JPDAThreadImpl t, final ThreadReference tr, VirtualMachine vm, DebuggerEngine engine, JPDADebuggerImpl d, final List<RemoteScreenshot> screenshots) throws RetrievalException {
    try {
        final ClassType windowClass = getClass(vm, tr, "javafx.stage.Window");
        
        Method getWindows = windowClass.concreteMethodByName("impl_getWindows", "()Ljava/util/Iterator;");
        Method windowName = windowClass.concreteMethodByName("impl_getMXWindowType", "()Ljava/lang/String;");

        ObjectReference iterator = (ObjectReference)windowClass.invokeMethod(tr, getWindows, Collections.emptyList(), ObjectReference.INVOKE_SINGLE_THREADED);
        ClassType iteratorClass = (ClassType)iterator.referenceType();
        Method hasNext = iteratorClass.concreteMethodByName("hasNext", "()Z");
        Method next = iteratorClass.concreteMethodByName("next", "()Ljava/lang/Object;");
        
        boolean nextFlag = false;
        do {
            BooleanValue bv = (BooleanValue)iterator.invokeMethod(tr, hasNext, Collections.emptyList(), ObjectReference.INVOKE_SINGLE_THREADED);
            nextFlag = bv.booleanValue();
            if (nextFlag) {
                ObjectReference window = (ObjectReference)iterator.invokeMethod(tr, next, Collections.emptyList(), ObjectReference.INVOKE_SINGLE_THREADED);
                StringReference name = (StringReference)window.invokeMethod(tr, windowName, Collections.emptyList(), ObjectReference.INVOKE_SINGLE_THREADED);
                SGComponentInfo windowInfo = new SGComponentInfo(t, window);
                
                screenshots.add(createRemoteFXScreenshot(engine, vm, tr, name.value(), window, windowInfo));
            }
        } while (nextFlag);
    } catch (Exception e) {
        throw new RetrievalException(e.getMessage(), e);
    }
}
 
Example #5
Source File: DebugExecutionEnvironment.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public boolean sendStopUserCode() throws IllegalStateException {
    if (closed) {
        return false;
    }
    vm.suspend();
    try {
        ObjectReference myRef = getAgentObjectReference();

        OUTER:
        for (ThreadReference thread : vm.allThreads()) {
            // could also tag the thread (e.g. using name), to find it easier
            AGENT: for (StackFrame frame : thread.frames()) {
                if (REMOTE_AGENT_CLASS.equals(frame.location().declaringType().name())) {
                    String n = frame.location().method().name();
                    if (AGENT_INVOKE_METHOD.equals(n) || AGENT_VARVALUE_METHOD.equals(n)) {
                        ObjectReference thiz = frame.thisObject();
                        if (myRef != null && myRef != thiz) {
                            break AGENT;
                        }
                        if (((BooleanValue) thiz.getValue(thiz.referenceType().fieldByName("inClientCode"))).value()) {
                            thiz.setValue(thiz.referenceType().fieldByName("expectingStop"), vm.mirrorOf(true));
                            ObjectReference stopInstance = (ObjectReference) thiz.getValue(thiz.referenceType().fieldByName("stopException"));
                            vm.resume();
                            thread.stop(stopInstance);
                            thiz.setValue(thiz.referenceType().fieldByName("expectingStop"), vm.mirrorOf(false));
                        }
                        return true;
                    }
                }
            }
        }
    } catch (ClassNotLoadedException | IncompatibleThreadStateException | InvalidTypeException ex) {
        throw new IllegalStateException(ex);
    } finally {
        vm.resume();
    }
    return false;
}
 
Example #6
Source File: VMTargetRemoteTest.java    From gravel with Apache License 2.0 5 votes vote down vote up
@Test
	public void testDNU() throws Throwable {
		ObjectReference promise = remote.evaluateForked("3 fromage");
		ThreadReference thread = ((ThreadReference) remote.invokeMethod(
				promise, "thread"));
		remote.invokeMethod(thread, "start");
		ObjectReference state = (ObjectReference) remote.invokeMethod(thread, "getState");
		StringReference str = (StringReference) remote.invokeMethod(state, "toString");
		System.out.println(str.value());
		
		printStack(thread);
//		assertFalse(thread.isSuspended());
		printThreadState();
		System.out.println("VMTargetStarter.sleep(1000)");
		VMTargetStarter.sleep(1000);
		printStack(thread);
		printThreadState();

		boolean isFinished = ((BooleanValue) remote.invokeMethod(promise,
				"isFinished")).booleanValue();

		assertFalse(isFinished);
		printThreadState();

		printStack(thread);
		assertTrue(thread.isAtBreakpoint());
	}
 
Example #7
Source File: RemoteFXScreenshot.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static void pauseMedia(ThreadReference tr, VirtualMachine vm) throws InvalidTypeException, ClassNotLoadedException, IncompatibleThreadStateException, InvocationException {
    final ClassType audioClipClass = getClass(vm, tr, "com.sun.media.jfxmedia.AudioClip");
    final ClassType mediaManagerClass = getClass(vm, tr, "com.sun.media.jfxmedia.MediaManager");
    final InterfaceType mediaPlayerClass = getInterface(vm, tr, "com.sun.media.jfxmedia.MediaPlayer");
    final ClassType playerStateEnum = getClass(vm, tr, "com.sun.media.jfxmedia.events.PlayerStateEvent$PlayerState");
    
    if (audioClipClass != null) {
        Method stopAllClips = audioClipClass.concreteMethodByName("stopAllClips", "()V");
        audioClipClass.invokeMethod(tr, stopAllClips, Collections.emptyList(), ObjectReference.INVOKE_SINGLE_THREADED);
    }
    
    if (mediaManagerClass != null && mediaPlayerClass != null && playerStateEnum != null) {
        Method getAllPlayers = mediaManagerClass.concreteMethodByName("getAllMediaPlayers", "()Ljava/util/List;");

        ObjectReference plList = (ObjectReference)mediaManagerClass.invokeMethod(tr, getAllPlayers, Collections.emptyList(), ObjectReference.INVOKE_SINGLE_THREADED);

        if (plList != null) {
            ClassType listType = (ClassType)plList.referenceType();
            Method iterator = listType.concreteMethodByName("iterator", "()Ljava/util/Iterator;");
            ObjectReference plIter = (ObjectReference)plList.invokeMethod(tr, iterator, Collections.emptyList(), ObjectReference.INVOKE_SINGLE_THREADED);

            ClassType iterType = (ClassType)plIter.referenceType();
            Method hasNext = iterType.concreteMethodByName("hasNext", "()Z");
            Method next = iterType.concreteMethodByName("next", "()Ljava/lang/Object;");


            Field playingState = playerStateEnum.fieldByName("PLAYING");

            Method getState = mediaPlayerClass.methodsByName("getState", "()Lcom/sun/media/jfxmedia/events/PlayerStateEvent$PlayerState;").get(0);
            Method pausePlayer = mediaPlayerClass.methodsByName("pause", "()V").get(0);
            boolean hasNextFlag = false;
            do {
                BooleanValue v = (BooleanValue)plIter.invokeMethod(tr, hasNext, Collections.emptyList(), ObjectReference.INVOKE_SINGLE_THREADED);
                hasNextFlag = v.booleanValue();
                if (hasNextFlag) {
                    ObjectReference player = (ObjectReference)plIter.invokeMethod(tr, next, Collections.emptyList(), ObjectReference.INVOKE_SINGLE_THREADED);
                    ObjectReference curState = (ObjectReference)player.invokeMethod(tr, getState, Collections.emptyList(), ObjectReference.INVOKE_SINGLE_THREADED);
                    if (playingState.equals(curState)) {
                        player.invokeMethod(tr, pausePlayer, Collections.emptyList(), ObjectReference.INVOKE_SINGLE_THREADED);
                        pausedPlayers.add(player);
                    }
                }
            } while (hasNextFlag);
        }
    }
}
 
Example #8
Source File: LaunchJDIAgent.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Interrupts a running remote invoke by manipulating remote variables
 * and sending a stop via JDI.
 *
 * @throws EngineTerminationException the execution engine has terminated
 * @throws InternalException an internal problem occurred
 */
@Override
public void stop() throws ExecutionControl.EngineTerminationException, ExecutionControl.InternalException {
    synchronized (STOP_LOCK) {
        if (!userCodeRunning) {
            return;
        }

        vm().suspend();
        try {
            OUTER:
            for (ThreadReference thread : vm().allThreads()) {
                // could also tag the thread (e.g. using name), to find it easier
                for (StackFrame frame : thread.frames()) {
                    if (REMOTE_AGENT.equals(frame.location().declaringType().name()) &&
                            (    "invoke".equals(frame.location().method().name())
                            || "varValue".equals(frame.location().method().name()))) {
                        ObjectReference thiz = frame.thisObject();
                        com.sun.jdi.Field inClientCode = thiz.referenceType().fieldByName("inClientCode");
                        com.sun.jdi.Field expectingStop = thiz.referenceType().fieldByName("expectingStop");
                        com.sun.jdi.Field stopException = thiz.referenceType().fieldByName("stopException");
                        if (((BooleanValue) thiz.getValue(inClientCode)).value()) {
                            thiz.setValue(expectingStop, vm().mirrorOf(true));
                            ObjectReference stopInstance = (ObjectReference) thiz.getValue(stopException);

                            vm().resume();
                            debug("Attempting to stop the client code...\n");
                            thread.stop(stopInstance);
                            thiz.setValue(expectingStop, vm().mirrorOf(false));
                        }

                        break OUTER;
                    }
                }
            }
        } catch (ClassNotLoadedException | IncompatibleThreadStateException | InvalidTypeException ex) {
            throw new ExecutionControl.InternalException("Exception on remote stop: " + ex);
        } finally {
            vm().resume();
        }
    }
}
 
Example #9
Source File: DebugManagerHandler.java    From netbeans with Apache License 2.0 4 votes vote down vote up
void newPolyglotEngineInstance(ObjectReference engine, JPDAThreadImpl thread) {
    LOG.log(Level.FINE, "Engine created breakpoint hit: engine = {0} in thread = {1}", new Object[] { engine, thread.getThreadReference()});
    if (inited.compareAndSet(false, true)) {
        initDebuggerRemoteService(thread);
    }
    if (accessorClass == null) {
        // No accessor
        return ;
    }
    InvocationExceptionTranslated iextr = null;
    try {
        // Create an instance of JPDATruffleDebugManager in the backend
        // and submit breakpoints:
        thread.notifyMethodInvoking();
        VirtualMachine vm = ((JPDADebuggerImpl) debugger).getVirtualMachine();
        if (vm == null) {
            return ;
        }
        BooleanValue includeInternal = vm.mirrorOf(TruffleOptions.isLanguageDeveloperMode());
        BooleanValue doStepInto = vm.mirrorOf(isStepInto());
        Method debugManagerMethod = ClassTypeWrapper.concreteMethodByName(
                accessorClass,
                ACCESSOR_SET_UP_DEBUG_MANAGER_FOR,
                ACCESSOR_SET_UP_DEBUG_MANAGER_FOR_SGN);
        ThreadReference tr = thread.getThreadReference();
        List<Value> dmArgs = Arrays.asList(engine, includeInternal, doStepInto);
        LOG.log(Level.FINE, "Setting engine and step into = {0}", isStepInto());
        Object ret = ClassTypeWrapper.invokeMethod(accessorClass, tr, debugManagerMethod, dmArgs, ObjectReference.INVOKE_SINGLE_THREADED);
        if (ret instanceof ObjectReference) {   // Can be null when an existing debug manager is reused.
            //debugManager = (ObjectReference) ret;
            breakpointsHandler.submitBreakpoints(accessorClass, (ObjectReference) ret, thread);
        }
    } catch (VMDisconnectedExceptionWrapper vmd) {
    } catch (InvocationException iex) {
        iextr = new InvocationExceptionTranslated(iex, thread.getDebugger());
        Exceptions.printStackTrace(iex);
    } catch (Exception ex) {
        Exceptions.printStackTrace(ex);
    } finally {
        thread.notifyMethodInvokeDone();
    }
    if (iextr != null) {
        iextr.preload(thread);
        Exceptions.printStackTrace(iextr);
    }
}
 
Example #10
Source File: RemoteServices.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public static boolean interruptServiceAccessThread(JPDADebugger debugger) {
    ClassObjectReference serviceClass = getServiceClass(debugger);
    if (serviceClass != null) {
        ThreadReference accessThread;
        synchronized (remoteServiceAccess) {
            accessThread = remoteServiceAccess.get(debugger);
        }
        if (accessThread == null) {
            return false;
        }
        logger.fine("RemoteServices.interruptServiceAccessThread()");
        try {
            ClassType serviceClassType = (ClassType) ClassObjectReferenceWrapper.reflectedType(serviceClass);
            Field accessLoopSleepingField = ReferenceTypeWrapper.fieldByName(serviceClassType, "accessLoopSleeping");
            synchronized (accessThread) {
                boolean isSleeping;
                int repeatCheck = 10;
                do {
                    BooleanValue sleepingValue = (BooleanValue) serviceClassType.getValue(accessLoopSleepingField);
                    isSleeping = sleepingValue.booleanValue();
                    if (isSleeping || --repeatCheck < 0) {
                        break;
                    } else {
                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException iex) {}
                    }
                    logger.log(Level.FINE, "  isSleeping = {0}", isSleeping);
                } while (!isSleeping);
                if (isSleeping) {
                    ThreadReferenceWrapper.interrupt(accessThread);
                    //System.err.println("  INTERRUPTED.");
                    return true;
                }
            }
        } catch (InternalExceptionWrapper |
                 VMDisconnectedExceptionWrapper |
                 ObjectCollectedExceptionWrapper |
                 ClassNotPreparedExceptionWrapper |
                 IllegalThreadStateExceptionWrapper ex) {
            logger.log(Level.FINE, "  NOT interrupted: ", ex);
        }
        logger.fine("  NOT Interrupted.");
    }
    return false;
}
 
Example #11
Source File: JdiDefaultExecutionControl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Interrupts a running remote invoke by manipulating remote variables
 * and sending a stop via JDI.
 *
 * @throws EngineTerminationException the execution engine has terminated
 * @throws InternalException an internal problem occurred
 */
@Override
public void stop() throws EngineTerminationException, InternalException {
    synchronized (STOP_LOCK) {
        if (!userCodeRunning) {
            return;
        }

        vm().suspend();
        try {
            OUTER:
            for (ThreadReference thread : vm().allThreads()) {
                // could also tag the thread (e.g. using name), to find it easier
                for (StackFrame frame : thread.frames()) {
                    if (remoteAgent.equals(frame.location().declaringType().name()) &&
                            (    "invoke".equals(frame.location().method().name())
                            || "varValue".equals(frame.location().method().name()))) {
                        ObjectReference thiz = frame.thisObject();
                        Field inClientCode = thiz.referenceType().fieldByName("inClientCode");
                        Field expectingStop = thiz.referenceType().fieldByName("expectingStop");
                        Field stopException = thiz.referenceType().fieldByName("stopException");
                        if (((BooleanValue) thiz.getValue(inClientCode)).value()) {
                            thiz.setValue(expectingStop, vm().mirrorOf(true));
                            ObjectReference stopInstance = (ObjectReference) thiz.getValue(stopException);

                            vm().resume();
                            debug("Attempting to stop the client code...\n");
                            thread.stop(stopInstance);
                            thiz.setValue(expectingStop, vm().mirrorOf(false));
                        }

                        break OUTER;
                    }
                }
            }
        } catch (ClassNotLoadedException | IncompatibleThreadStateException | InvalidTypeException ex) {
            throw new InternalException("Exception on remote stop: " + ex);
        } finally {
            vm().resume();
        }
    }
}
 
Example #12
Source File: SetBreakpointsRequestHandler.java    From java-debug with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Check whether the condition expression is satisfied, and return a boolean value to determine to resume the thread or not.
 */
public static boolean handleEvaluationResult(IDebugAdapterContext context, ThreadReference bpThread, IEvaluatableBreakpoint breakpoint,
    Value value, Throwable ex) {
    if (StringUtils.isNotBlank(breakpoint.getLogMessage())) {
        if (ex != null) {
            logger.log(Level.SEVERE, String.format("[Logpoint]: %s", ex.getMessage() != null ? ex.getMessage() : ex.toString()), ex);
            context.getProtocolServer().sendEvent(new Events.UserNotificationEvent(
                Events.UserNotificationEvent.NotificationType.ERROR,
                String.format("[Logpoint] Log message '%s' error: %s", breakpoint.getLogMessage(), ex.getMessage())));
        }
        return true;
    } else {
        boolean resume = false;
        boolean resultNotBoolean = false;
        if (value != null && ex == null) {
            if (value instanceof BooleanValue) {
                resume = !((BooleanValue) value).booleanValue();
            } else if (value instanceof ObjectReference
                    && ((ObjectReference) value).type().name().equals("java.lang.Boolean")) {
                // get boolean value from java.lang.Boolean object
                Field field = ((ReferenceType) ((ObjectReference) value).type()).fieldByName("value");
                resume = !((BooleanValue) ((ObjectReference) value).getValue(field)).booleanValue();
            } else {
                resultNotBoolean = true;
            }
        }
        if (resume) {
            return true;
        } else {
            if (context.isVmTerminated()) {
                // do nothing
            } else if (ex != null) {
                if (!(ex instanceof VMDisconnectedException || ex.getCause() instanceof VMDisconnectedException)) {
                    logger.log(Level.SEVERE, String.format("[ConditionalBreakpoint]: %s", ex.getMessage() != null ? ex.getMessage() : ex.toString()), ex);
                    context.getProtocolServer().sendEvent(new Events.UserNotificationEvent(
                            Events.UserNotificationEvent.NotificationType.ERROR,
                            String.format("Breakpoint condition '%s' error: %s", breakpoint.getCondition(), ex.getMessage())));
                }
            } else if (value == null || resultNotBoolean) {
                context.getProtocolServer().sendEvent(new Events.UserNotificationEvent(
                        Events.UserNotificationEvent.NotificationType.WARNING,
                        String.format("Result of breakpoint condition '%s' is not a boolean, please correct your expression.", breakpoint.getCondition())));
            }
            return false;
        }
    }
}
 
Example #13
Source File: VMRemoteProcess.java    From gravel with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isFinished() throws Throwable {
	return ((BooleanValue) invokeMethod("isFinished")).booleanValue();
}