Java Code Examples for com.sun.jdi.StackFrame#thisObject()

The following examples show how to use com.sun.jdi.StackFrame#thisObject() . 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: GetUninitializedStringValue.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
 
Example 2
Source File: GetUninitializedStringValue.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
 
Example 3
Source File: GetUninitializedStringValue.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
 
Example 4
Source File: GetUninitializedStringValue.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
 
Example 5
Source File: GetUninitializedStringValue.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
 
Example 6
Source File: GetUninitializedStringValue.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
 
Example 7
Source File: GetUninitializedStringValue.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
 
Example 8
Source File: GetUninitializedStringValue.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
 
Example 9
Source File: GetUninitializedStringValue.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
 
Example 10
Source File: GetUninitializedStringValue.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
 
Example 11
Source File: GetUninitializedStringValue.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
 
Example 12
Source File: GetUninitializedStringValue.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
 
Example 13
Source File: GetUninitializedStringValue.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
 
Example 14
Source File: VariableUtils.java    From java-debug with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Get the this variable of an stack frame.
 *
 * @param stackFrame
 *            the stack frame
 * @return this variable
 */
public static Variable getThisVariable(StackFrame stackFrame) {
    ObjectReference thisObject = stackFrame.thisObject();
    if (thisObject == null) {
        return null;
    }
    return new Variable("this", thisObject);
}
 
Example 15
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 16
Source File: DynamothCollector.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private void getCurrentTest(ThreadReference threadRef) {
	try {
		List<StackFrame> frames = threadRef.frames();
		for (StackFrame stackFrame : frames) {
			for (String test : tests) {
				String[] splitted = test.split("#");
				test = splitted[0];
				ObjectReference thisObject = stackFrame.thisObject();
				if (thisObject == null) {
					continue;
				}
				String frameClass = thisObject.referenceType().name();
				if (frameClass.equals(test)) {
					String frameMethod = stackFrame.location().method().name();
					if (oracle.containsKey(test + "#" + frameMethod)) {
						if (frameClass.equals(currentTestClass) && frameMethod.equals(currentTestMethod)) {
							this.currentIteration++;
						} else {
							currentTestClass = test;
							currentTestMethod = frameMethod;
							this.currentIteration = 0;
						}
						// logger.info("[test] " + currentTestClass + "#" + currentTestMethod + "
						// iteration "
						// + this.currentIteration);
						return;
					}
				}
			}
		}
	} catch (IncompatibleThreadStateException e) {
		e.printStackTrace();
	}
	throw new RuntimeException("Unable to identify the current test");
}
 
Example 17
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 18
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();
        }
    }
}