Search in sources :

Example 6 with Assumption

use of com.oracle.truffle.api.Assumption in project graal by oracle.

the class BreakpointSnippets method sessionsAssumptionInvalidate.

private void sessionsAssumptionInvalidate() {
    assert Thread.holdsLock(this);
    Assumption assumption = sessionsUnchanged;
    if (assumption != null) {
        this.sessionsUnchanged = null;
        assumption.invalidate();
    }
}
Also used : Assumption(com.oracle.truffle.api.Assumption)

Example 7 with Assumption

use of com.oracle.truffle.api.Assumption in project graal by oracle.

the class BreakpointSnippets method setCondition.

/**
 * Assigns to this breakpoint a boolean expression whose evaluation will determine whether the
 * breakpoint suspends execution (i.e. "hits"), {@code null} to remove any condition and always
 * suspend.
 * <p>
 * Breakpoints are by default unconditional.
 * </p>
 * <p>
 * <strong>Evaluation:</strong> expressions are parsed and evaluated in the lexical context of
 * the breakpoint's location. A conditional breakpoint that applies to multiple code locations
 * will be parsed and evaluated separately for each location.
 * </p>
 * <p>
 * <strong>Evaluation failure:</strong> when evaluation of a condition fails for any reason,
 * including the return of a non-boolean value:
 * <ul>
 * <li>execution suspends, as if evaluation had returned {@code true}, and</li>
 * <li>a message is logged that can be
 * {@linkplain SuspendedEvent#getBreakpointConditionException(Breakpoint) retrieved} while
 * execution is suspended.</li>
 * </ul>
 * When not {@link #isModifiable() modifiable}, {@link IllegalStateException} is thrown.
 *
 * @param expression if non{@code -null}, a boolean expression, expressed in the guest language
 *            of the breakpoint's location.
 * @see SuspendedEvent#getBreakpointConditionException(Breakpoint)
 *
 * @since 0.9
 */
public synchronized void setCondition(String expression) {
    boolean existsChanged = (this.condition == null) != (expression == null);
    this.condition = expression;
    Assumption assumption = conditionUnchanged;
    if (assumption != null) {
        this.conditionUnchanged = null;
        assumption.invalidate();
    }
    if (existsChanged) {
        assumption = conditionExistsUnchanged;
        if (assumption != null) {
            this.conditionExistsUnchanged = null;
            assumption.invalidate();
        }
    }
}
Also used : Assumption(com.oracle.truffle.api.Assumption)

Example 8 with Assumption

use of com.oracle.truffle.api.Assumption in project graal by oracle.

the class AssumptionsTest method testAssumptionArrays.

@Test
public void testAssumptionArrays() {
    CallTarget root = createCallTarget(AssumptionArrayTestFactory.getInstance());
    AssumptionArrayTest node = getNode(root);
    Assumption a1 = Truffle.getRuntime().createAssumption();
    Assumption a2 = Truffle.getRuntime().createAssumption();
    node.assumptions = new Assumption[] { a1, a2 };
    assertEquals("do1", root.call(42));
    a2.invalidate();
    assertEquals("do2", root.call(42));
}
Also used : TestHelper.createCallTarget(com.oracle.truffle.api.dsl.test.TestHelper.createCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) Assumption(com.oracle.truffle.api.Assumption) Test(org.junit.Test)

Example 9 with Assumption

use of com.oracle.truffle.api.Assumption in project graal by oracle.

the class AssumptionsTest method testAssumptionInvalidateTest4.

@Test
public void testAssumptionInvalidateTest4() {
    AssumptionInvalidateTest4 node = AssumptionInvalidateTest4NodeGen.create();
    node.execute(0);
    for (int i = 0; i < 100; i++) {
        int removeIndex = 0;
        Assumption a = node.assumptions;
        a.invalidate();
        node.execute(removeIndex);
        assertNotSame(a, node.assumptions);
    }
}
Also used : Assumption(com.oracle.truffle.api.Assumption) Test(org.junit.Test)

Example 10 with Assumption

use of com.oracle.truffle.api.Assumption in project graal by oracle.

the class AssumptionsTest method testMultipleAssumptionArrays.

@Test
public void testMultipleAssumptionArrays() {
    CallTarget root = createCallTarget(MultipleAssumptionArraysTestFactory.getInstance());
    MultipleAssumptionArraysTest node = getNode(root);
    Assumption a1 = Truffle.getRuntime().createAssumption();
    Assumption a2 = Truffle.getRuntime().createAssumption();
    node.assumptions1 = new Assumption[] { a1 };
    node.assumptions2 = new Assumption[] { a2 };
    assertEquals("do1", root.call(42));
    a2.invalidate();
    assertEquals("do2", root.call(42));
}
Also used : TestHelper.createCallTarget(com.oracle.truffle.api.dsl.test.TestHelper.createCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) Assumption(com.oracle.truffle.api.Assumption) Test(org.junit.Test)

Aggregations

Assumption (com.oracle.truffle.api.Assumption)42 Test (org.junit.Test)25 UnionAssumption (com.oracle.truffle.api.utilities.UnionAssumption)8 CallTarget (com.oracle.truffle.api.CallTarget)5 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)5 TestHelper.createCallTarget (com.oracle.truffle.api.dsl.test.TestHelper.createCallTarget)3 Field (java.lang.reflect.Field)3 OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)3 RootTestNode (org.graalvm.compiler.truffle.test.nodes.RootTestNode)3 CompilationFinal (com.oracle.truffle.api.CompilerDirectives.CompilationFinal)2 NodeField (com.oracle.truffle.api.dsl.NodeField)2 ExplodeLoop (com.oracle.truffle.api.nodes.ExplodeLoop)2 Node (com.oracle.truffle.api.nodes.Node)2 CodeExecutableElement (com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement)2 CodeVariableElement (com.oracle.truffle.dsl.processor.java.model.CodeVariableElement)2 CompilerDirectives (com.oracle.truffle.api.CompilerDirectives)1 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 Truffle (com.oracle.truffle.api.Truffle)1 TruffleRuntime (com.oracle.truffle.api.TruffleRuntime)1 Cached (com.oracle.truffle.api.dsl.Cached)1