Search in sources :

Example 1 with StringReference

use of com.sun.jdi.StringReference in project che by eclipse.

the class Evaluator method operation.

public ExpressionValue operation(ExpressionValue leftExpression, ExpressionValue rightExpression, int op) {
    if (JavaParser.ASSIGN == op) {
        leftExpression.setValue(rightExpression.getValue());
        return leftExpression;
    }
    Value leftValue = leftExpression.getValue();
    Value rightValue = rightExpression.getValue();
    if (leftValue instanceof StringReference || rightValue instanceof StringReference) {
        if (JavaParser.PLUS == op) {
            return value(valueToString(leftValue) + valueToString(rightValue));
        }
    }
    if (leftValue instanceof ObjectReference || rightValue instanceof ObjectReference) {
        switch(op) {
            case JavaParser.EQUAL:
                return value(leftValue != null ? leftValue.equals(rightValue) : rightValue == null);
            case JavaParser.NOT_EQUAL:
                return value(!(leftValue != null ? leftValue.equals(rightValue) : rightValue == null));
            default:
                throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + leftValue + " and " + rightValue);
        }
    }
    if (leftValue == null || rightValue == null) {
        // Neither one is object and operation is not assignation.
        throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + leftValue + " and " + rightValue);
    }
    PrimitiveValue lp = (PrimitiveValue) leftValue;
    PrimitiveValue rp = (PrimitiveValue) rightValue;
    if (lp instanceof BooleanValue && rp instanceof BooleanValue) {
        switch(op) {
            case JavaParser.LOGICAL_AND:
                return value(lp.booleanValue() && rp.booleanValue());
            case JavaParser.LOGICAL_OR:
                return value(lp.booleanValue() || rp.booleanValue());
            case JavaParser.EQUAL:
                return value(lp.booleanValue() == rp.booleanValue());
            case JavaParser.NOT_EQUAL:
                return value(lp.booleanValue() != rp.booleanValue());
            case JavaParser.OR:
                return value(lp.booleanValue() | rp.booleanValue());
            case JavaParser.XOR:
                return value(lp.booleanValue() ^ rp.booleanValue());
            case JavaParser.AND:
                return value(lp.booleanValue() & rp.booleanValue());
            case JavaParser.OR_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.booleanValue() | rp.booleanValue()));
                return leftExpression;
            case JavaParser.XOR_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.booleanValue() ^ rp.booleanValue()));
                return leftExpression;
            case JavaParser.AND_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.booleanValue() & rp.booleanValue()));
                return leftExpression;
            default:
                throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + leftValue + " and " + rightValue);
        }
    }
    switch(op) {
        case JavaParser.EQUAL:
            return value(lp.doubleValue() == rp.doubleValue());
        case JavaParser.NOT_EQUAL:
            return value(lp.doubleValue() != rp.doubleValue());
        case JavaParser.GREATER_THAN:
            return value(lp.doubleValue() > rp.doubleValue());
        case JavaParser.LESS_THAN:
            return value(lp.doubleValue() < rp.doubleValue());
        case JavaParser.GREATER_OR_EQUAL:
            return value(lp.doubleValue() >= rp.doubleValue());
        case JavaParser.LESS_OR_EQUAL:
            return value(lp.doubleValue() <= rp.doubleValue());
    }
    if (lp instanceof DoubleValue || rp instanceof DoubleValue) {
        switch(op) {
            case JavaParser.PLUS:
                return value(lp.doubleValue() + rp.doubleValue());
            case JavaParser.MINUS:
                return value(lp.doubleValue() - rp.doubleValue());
            case JavaParser.STAR:
                return value(lp.doubleValue() * rp.doubleValue());
            case JavaParser.DIV:
                return value(lp.doubleValue() / rp.doubleValue());
            case JavaParser.MOD:
                return value(lp.doubleValue() % rp.doubleValue());
            case JavaParser.PLUS_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.doubleValue() + rp.doubleValue()));
                return leftExpression;
            case JavaParser.MINUS_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.doubleValue() - rp.doubleValue()));
                return leftExpression;
            case JavaParser.STAR_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.doubleValue() * rp.doubleValue()));
                return leftExpression;
            case JavaParser.DIV_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.doubleValue() / rp.doubleValue()));
                return leftExpression;
            case JavaParser.MOD_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.doubleValue() % rp.doubleValue()));
                return leftExpression;
            default:
                throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + leftValue + " and " + rightValue);
        }
    }
    if (lp instanceof FloatValue || rp instanceof FloatValue) {
        switch(op) {
            case JavaParser.PLUS:
                return value(lp.floatValue() + rp.floatValue());
            case JavaParser.MINUS:
                return value(lp.floatValue() - rp.floatValue());
            case JavaParser.STAR:
                return value(lp.floatValue() * rp.floatValue());
            case JavaParser.DIV:
                return value(lp.floatValue() / rp.floatValue());
            case JavaParser.MOD:
                return value(lp.floatValue() % rp.floatValue());
            case JavaParser.PLUS_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.floatValue() + rp.floatValue()));
                return leftExpression;
            case JavaParser.MINUS_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.floatValue() - rp.floatValue()));
                return leftExpression;
            case JavaParser.STAR_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.floatValue() * rp.longValue()));
                return leftExpression;
            case JavaParser.DIV_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.floatValue() / rp.floatValue()));
                return leftExpression;
            case JavaParser.MOD_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.floatValue() % rp.floatValue()));
                return leftExpression;
            default:
                throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + leftValue + " and " + rightValue);
        }
    }
    if (lp instanceof LongValue || rp instanceof LongValue) {
        switch(op) {
            case JavaParser.PLUS:
                return value(lp.longValue() + rp.longValue());
            case JavaParser.MINUS:
                return value(lp.longValue() - rp.longValue());
            case JavaParser.STAR:
                return value(lp.longValue() * rp.longValue());
            case JavaParser.DIV:
                return value(lp.longValue() / rp.longValue());
            case JavaParser.MOD:
                return value(lp.longValue() % rp.longValue());
            case JavaParser.SHIFT_LEFT:
                return value(lp.longValue() << rp.longValue());
            case JavaParser.SHIFT_RIGHT:
                return value(lp.longValue() >> rp.longValue());
            case JavaParser.BIT_SHIFT_RIGHT:
                return value(lp.longValue() >>> rp.longValue());
            case JavaParser.OR:
                return value(lp.longValue() | rp.longValue());
            case JavaParser.XOR:
                return value(lp.longValue() ^ rp.longValue());
            case JavaParser.AND:
                return value(lp.longValue() & rp.longValue());
            case JavaParser.PLUS_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.longValue() + rp.longValue()));
                return leftExpression;
            case JavaParser.MINUS_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.longValue() - rp.longValue()));
                return leftExpression;
            case JavaParser.STAR_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.longValue() * rp.longValue()));
                return leftExpression;
            case JavaParser.DIV_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.longValue() / rp.longValue()));
                return leftExpression;
            case JavaParser.OR_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.longValue() | rp.longValue()));
                return leftExpression;
            case JavaParser.XOR_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.longValue() ^ rp.longValue()));
                return leftExpression;
            case JavaParser.AND_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.longValue() & rp.longValue()));
                return leftExpression;
            case JavaParser.SHIFT_LEFT_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.longValue() << rp.longValue()));
                return leftExpression;
            case JavaParser.SHIFT_RIGHT_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.longValue() >> rp.longValue()));
                return leftExpression;
            case JavaParser.BIT_SHIFT_RIGHT_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.longValue() >>> rp.longValue()));
                return leftExpression;
            default:
                throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + leftValue + " and " + rightValue);
        }
    }
    switch(op) {
        case JavaParser.PLUS:
            return value(lp.intValue() + rp.intValue());
        case JavaParser.MINUS:
            return value(lp.intValue() - rp.intValue());
        case JavaParser.STAR:
            return value(lp.intValue() * rp.intValue());
        case JavaParser.DIV:
            return value(lp.intValue() / rp.intValue());
        case JavaParser.MOD:
            return value(lp.intValue() % rp.intValue());
        case JavaParser.SHIFT_LEFT:
            return value(lp.intValue() << rp.intValue());
        case JavaParser.SHIFT_RIGHT:
            return value(lp.intValue() >> rp.intValue());
        case JavaParser.BIT_SHIFT_RIGHT:
            return value(lp.intValue() >>> rp.intValue());
        case JavaParser.OR:
            return value(lp.intValue() | rp.intValue());
        case JavaParser.XOR:
            return value(lp.intValue() ^ rp.intValue());
        case JavaParser.AND:
            return value(lp.intValue() & rp.intValue());
        case JavaParser.PLUS_ASSIGN:
            leftExpression.setValue(vm.mirrorOf(lp.intValue() + rp.intValue()));
            return leftExpression;
        case JavaParser.MINUS_ASSIGN:
            leftExpression.setValue(vm.mirrorOf(lp.intValue() - rp.intValue()));
            return leftExpression;
        case JavaParser.STAR_ASSIGN:
            leftExpression.setValue(vm.mirrorOf(lp.intValue() * rp.intValue()));
            return leftExpression;
        case JavaParser.DIV_ASSIGN:
            leftExpression.setValue(vm.mirrorOf(lp.intValue() / rp.intValue()));
            return leftExpression;
        case JavaParser.OR_ASSIGN:
            leftExpression.setValue(vm.mirrorOf(lp.intValue() | rp.intValue()));
            return leftExpression;
        case JavaParser.XOR_ASSIGN:
            leftExpression.setValue(vm.mirrorOf(lp.intValue() ^ rp.intValue()));
            return leftExpression;
        case JavaParser.AND_ASSIGN:
            leftExpression.setValue(vm.mirrorOf(lp.intValue() & rp.intValue()));
            return leftExpression;
        case JavaParser.SHIFT_LEFT_ASSIGN:
            leftExpression.setValue(vm.mirrorOf(lp.intValue() << rp.intValue()));
            return leftExpression;
        case JavaParser.SHIFT_RIGHT_ASSIGN:
            leftExpression.setValue(vm.mirrorOf(lp.intValue() >> rp.intValue()));
            return leftExpression;
        case JavaParser.BIT_SHIFT_RIGHT_ASSIGN:
            leftExpression.setValue(vm.mirrorOf(lp.intValue() >>> rp.intValue()));
            return leftExpression;
        default:
            throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + leftValue + " and " + rightValue);
    }
}
Also used : ObjectReference(com.sun.jdi.ObjectReference) DoubleValue(com.sun.jdi.DoubleValue) BooleanValue(com.sun.jdi.BooleanValue) PrimitiveValue(com.sun.jdi.PrimitiveValue) IntegerValue(com.sun.jdi.IntegerValue) LongValue(com.sun.jdi.LongValue) DoubleValue(com.sun.jdi.DoubleValue) BooleanValue(com.sun.jdi.BooleanValue) FloatValue(com.sun.jdi.FloatValue) Value(com.sun.jdi.Value) LongValue(com.sun.jdi.LongValue) FloatValue(com.sun.jdi.FloatValue) StringReference(com.sun.jdi.StringReference) PrimitiveValue(com.sun.jdi.PrimitiveValue)

Example 2 with StringReference

use of com.sun.jdi.StringReference in project jdk8u_jdk by JetBrains.

the class LambdaStepTest method runTests.

/********** test core **********/
protected void runTests() throws Exception {
    // ## Normal instance method
    BreakpointEvent bpe = startTo("LambdaStepTestTarg", "instanceTest", "()V");
    ThreadReference thread = bpe.thread();
    // step over allocation
    StepEvent se = stepOverLine(thread);
    System.out.println(se.thread().frame(0));
    // step into test();
    se = stepIntoLine(thread);
    System.out.println(se.thread().frame(0));
    // step over variable initialization
    se = stepOverLine(thread);
    System.out.println(se.thread().frame(0));
    // get value of variable "from"
    StackFrame frame = se.thread().frame(0);
    LocalVariable lv = frame.visibleVariableByName("from");
    System.out.println(lv);
    StringReference sr = (StringReference) frame.getValue(lv);
    if (!sr.value().equals("test")) {
        throw new Exception("Unexpected variable value in instanceTest: " + sr.value());
    }
    // ## Lambda method
    bpe = resumeTo("LambdaStepTestTarg", "lambdaTest", "()V");
    thread = bpe.thread();
    // step over allocation
    se = stepOverLine(thread);
    System.out.println(se.thread().frame(0));
    // step into run() of the lambda
    se = stepIntoLine(thread);
    System.out.println(se.thread().frame(0));
    // step over variable initialization
    se = stepOverLine(thread);
    System.out.println(se.thread().frame(0));
    // get value of variable "from"
    frame = se.thread().frame(0);
    lv = frame.visibleVariableByName("from");
    System.out.println(lv);
    sr = (StringReference) frame.getValue(lv);
    if (!sr.value().equals("lambda")) {
        throw new Exception("Unexpected variable value in lambdaTest: " + sr.value());
    }
    // ## Default method
    bpe = resumeTo("LambdaStepTestTarg", "defaultTest", "()V");
    thread = bpe.thread();
    // step over allocation
    se = stepOverLine(thread);
    System.out.println(se.thread().frame(0));
    // step into defaultMethod()
    se = stepIntoLine(thread);
    System.out.println(se.thread().frame(0));
    // step over variable initialization
    se = stepOverLine(thread);
    System.out.println(se.thread().frame(0));
    // get value of variable "from"
    frame = se.thread().frame(0);
    lv = frame.visibleVariableByName("from");
    System.out.println(lv);
    sr = (StringReference) frame.getValue(lv);
    if (!sr.value().equals("default")) {
        throw new Exception("Unexpected variable value in lambdaTest: " + sr.value());
    }
    /*
         * resume the target listening for events
         */
    listenUntilVMDisconnect();
}
Also used : BreakpointEvent(com.sun.jdi.event.BreakpointEvent) StepEvent(com.sun.jdi.event.StepEvent) StackFrame(com.sun.jdi.StackFrame) LocalVariable(com.sun.jdi.LocalVariable) ThreadReference(com.sun.jdi.ThreadReference) StringReference(com.sun.jdi.StringReference)

Example 3 with StringReference

use of com.sun.jdi.StringReference in project jdk8u_jdk by JetBrains.

the class GetUninitializedStringValue method runTests.

/********** 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();
}
Also used : BreakpointEvent(com.sun.jdi.event.BreakpointEvent) StackFrame(com.sun.jdi.StackFrame) StringReference(com.sun.jdi.StringReference)

Example 4 with StringReference

use of com.sun.jdi.StringReference in project gravel by gravel-st.

the class VMTargetRemoteTest method testDNU.

@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());
}
Also used : ObjectReference(com.sun.jdi.ObjectReference) BooleanValue(com.sun.jdi.BooleanValue) ThreadReference(com.sun.jdi.ThreadReference) StringReference(com.sun.jdi.StringReference) Test(org.junit.Test)

Aggregations

StringReference (com.sun.jdi.StringReference)4 BooleanValue (com.sun.jdi.BooleanValue)2 ObjectReference (com.sun.jdi.ObjectReference)2 StackFrame (com.sun.jdi.StackFrame)2 ThreadReference (com.sun.jdi.ThreadReference)2 BreakpointEvent (com.sun.jdi.event.BreakpointEvent)2 DoubleValue (com.sun.jdi.DoubleValue)1 FloatValue (com.sun.jdi.FloatValue)1 IntegerValue (com.sun.jdi.IntegerValue)1 LocalVariable (com.sun.jdi.LocalVariable)1 LongValue (com.sun.jdi.LongValue)1 PrimitiveValue (com.sun.jdi.PrimitiveValue)1 Value (com.sun.jdi.Value)1 StepEvent (com.sun.jdi.event.StepEvent)1 Test (org.junit.Test)1