Search in sources :

Example 26 with Assumption

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

the class ContextObject method removeListener.

void removeListener(AllocationListener l) {
    CompilerAsserts.neverPartOfCompilation();
    boolean hasListeners = true;
    synchronized (this) {
        final int len = listeners.length;
        if (len == 1) {
            if (listeners[0] == l) {
                listeners = null;
                hasListeners = false;
            }
        } else {
            for (int i = 0; i < len; i++) {
                if (listeners[i] == l) {
                    if (i == (len - 1)) {
                        listeners = Arrays.copyOf(listeners, i);
                    } else if (i == 0) {
                        listeners = Arrays.copyOfRange(listeners, 1, len);
                    } else {
                        AllocationListener[] newListeners = new AllocationListener[len - 1];
                        System.arraycopy(listeners, 0, newListeners, 0, i);
                        System.arraycopy(listeners, i + 1, newListeners, i, len - i - 1);
                        listeners = newListeners;
                    }
                    break;
                }
            }
        }
        Assumption assumption = listenersNotChangedAssumption;
        listenersNotChangedAssumption = Truffle.getRuntime().createAssumption();
        assumption.invalidate();
    }
    if (!hasListeners) {
        propSupport.firePropertyChange(PROPERTY_ACTIVE, true, false);
    }
}
Also used : Assumption(com.oracle.truffle.api.Assumption)

Example 27 with Assumption

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

the class OptimizedCompilationProfile method injectArgumentProfile.

final Object[] injectArgumentProfile(Object[] originalArguments) {
    Assumption argumentTypesAssumption = profiledArgumentTypesAssumption;
    Object[] args = originalArguments;
    if (argumentTypesAssumption != null && argumentTypesAssumption.isValid()) {
        args = OptimizedCallTarget.unsafeCast(OptimizedCallTarget.castArrayFixedLength(args, profiledArgumentTypes.length), Object[].class, true, true, true);
        args = castArgumentsImpl(args);
    }
    return args;
}
Also used : Assumption(com.oracle.truffle.api.Assumption)

Example 28 with Assumption

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

the class AssumptionPartialEvaluationTest method constantValue.

@Test
public void constantValue() {
    Assumption assumption = Truffle.getRuntime().createAssumption();
    AbstractTestNode result = new ConstantWithAssumptionTestNode(assumption, 42);
    RootTestNode rootNode = new RootTestNode(new FrameDescriptor(), "constantValue", result);
    OptimizedCallTarget callTarget = assertPartialEvalEquals("constant42", rootNode);
    Assert.assertTrue(callTarget.isValid());
    assertDeepEquals(42, callTarget.call());
    Assert.assertTrue(callTarget.isValid());
    try {
        assumption.check();
    } catch (InvalidAssumptionException e) {
        Assert.fail("Assumption must not have been invalidated.");
    }
    assumption.invalidate();
    try {
        assumption.check();
        Assert.fail("Assumption must have been invalidated.");
    } catch (InvalidAssumptionException e) {
    }
    Assert.assertFalse(callTarget.isValid());
    assertDeepEquals(43, callTarget.call());
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) ConstantWithAssumptionTestNode(org.graalvm.compiler.truffle.test.nodes.ConstantWithAssumptionTestNode) AbstractTestNode(org.graalvm.compiler.truffle.test.nodes.AbstractTestNode) InvalidAssumptionException(com.oracle.truffle.api.nodes.InvalidAssumptionException) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) RootTestNode(org.graalvm.compiler.truffle.test.nodes.RootTestNode) Assumption(com.oracle.truffle.api.Assumption) OptimizedAssumption(org.graalvm.compiler.truffle.runtime.OptimizedAssumption) Test(org.junit.Test)

Example 29 with Assumption

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

the class AssumptionsTest method testAssumptionInvalidateTest1.

@Test
public void testAssumptionInvalidateTest1() {
    AssumptionInvalidateTest1 node = AssumptionInvalidateTest1NodeGen.create();
    node.execute(0);
    node.execute(1);
    node.execute(2);
    for (int i = 0; i < 100; i++) {
        int removeIndex = i % 3;
        Assumption a = node.assumptions[removeIndex];
        a.invalidate();
        node.execute(removeIndex);
        assertNotSame(a, node.assumptions[removeIndex]);
    }
}
Also used : Assumption(com.oracle.truffle.api.Assumption) Test(org.junit.Test)

Example 30 with Assumption

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

the class AssumptionsTest method testAssumptionArraysAreCompilationFinalCached.

@Test
public void testAssumptionArraysAreCompilationFinalCached() throws NoSuchFieldException, SecurityException, IllegalArgumentException {
    AssumptionArraysAreCompilationFinalCached node = TestHelper.createNode(AssumptionArraysAreCompilationFinalCachedFactory.getInstance(), false);
    Field doCachedField = node.getClass().getDeclaredField("do1_cache");
    doCachedField.setAccessible(true);
    Field field = doCachedField.getType().getDeclaredField("assumption0_");
    field.setAccessible(true);
    assertEquals(Assumption[].class, field.getType());
    CompilationFinal compilationFinal = field.getAnnotation(CompilationFinal.class);
    assertEquals(1, compilationFinal.dimensions());
}
Also used : NodeField(com.oracle.truffle.api.dsl.NodeField) Field(java.lang.reflect.Field) CompilationFinal(com.oracle.truffle.api.CompilerDirectives.CompilationFinal) 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