Search in sources :

Example 1 with OptimizedAssumptionDependency

use of org.graalvm.compiler.truffle.common.OptimizedAssumptionDependency in project graal by oracle.

the class OptimizedAssumption method invalidateImpl.

@TruffleBoundary
private synchronized void invalidateImpl(String message) {
    /*
         * Check again, now that we are holding the lock. Since isValid is defined volatile,
         * double-checked locking is allowed.
         */
    if (!isValid) {
        return;
    }
    boolean invalidatedADependency = false;
    Entry e = dependencies;
    while (e != null) {
        OptimizedAssumptionDependency dependency = e.awaitDependency();
        if (dependency != null) {
            OptimizedCallTarget callTarget = invalidateWithReason(dependency, "assumption invalidated");
            invalidatedADependency = true;
            if (TruffleCompilerOptions.getValue(TraceTruffleAssumptions)) {
                logInvalidatedDependency(dependency, message);
            }
            if (callTarget != null) {
                callTarget.getCompilationProfile().reportInvalidated();
            }
        }
        e = e.next;
    }
    dependencies = null;
    size = 0;
    sizeAfterLastRemove = 0;
    isValid = false;
    if (TruffleCompilerOptions.getValue(TraceTruffleAssumptions)) {
        if (invalidatedADependency) {
            logStackTrace();
        }
    }
}
Also used : OptimizedAssumptionDependency(org.graalvm.compiler.truffle.common.OptimizedAssumptionDependency) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 2 with OptimizedAssumptionDependency

use of org.graalvm.compiler.truffle.common.OptimizedAssumptionDependency in project graal by oracle.

the class AssumptionPartialEvaluationTest method testAssumptionDependencyManagement.

@Test
public void testAssumptionDependencyManagement() {
    OptimizedAssumption assumption = (OptimizedAssumption) Truffle.getRuntime().createAssumption();
    Assert.assertEquals(0, assumption.countDependencies());
    OptimizedAssumptionDependency failedCodeInstall = null;
    assumption.registerDependency().accept(failedCodeInstall);
    TestOptimizedAssumptionDependency[] deps = new TestOptimizedAssumptionDependency[100];
    for (int i = 0; i < deps.length; i++) {
        TestOptimizedAssumptionDependency dep = new TestOptimizedAssumptionDependency();
        assumption.registerDependency().accept(dep);
        deps[i] = dep;
    }
    Assert.assertEquals(deps.length, assumption.countDependencies());
    int invalidated = 0;
    for (int i = 0; i < deps.length; i++) {
        if (i % 2 == 0) {
            deps[i].invalidate();
            invalidated++;
        }
    }
    assumption.removeInvalidDependencies();
    Assert.assertEquals(invalidated, assumption.countDependencies());
    for (int i = 0; i < deps.length; i++) {
        deps[i].invalidate();
    }
    assumption.removeInvalidDependencies();
    Assert.assertEquals(0, assumption.countDependencies());
    WeakReference<TestOptimizedAssumptionDependency> dep = new WeakReference<>(new TestOptimizedAssumptionDependency());
    if (dep.get() != null) {
        Assert.assertTrue(dep.get().reachabilityDeterminesValidity());
        assumption.registerDependency().accept(dep.get());
        Assert.assertEquals(1, assumption.countDependencies());
        int attempts = 10;
        while (dep.get() != null && attempts-- > 0) {
            System.gc();
        }
        if (dep.get() == null) {
            assumption.removeInvalidDependencies();
            Assert.assertEquals(0, assumption.countDependencies());
        } else {
        // System.gc is not guaranteed to do anything
        // so we can end up here
        }
    }
}
Also used : WeakReference(java.lang.ref.WeakReference) OptimizedAssumption(org.graalvm.compiler.truffle.runtime.OptimizedAssumption) OptimizedAssumptionDependency(org.graalvm.compiler.truffle.common.OptimizedAssumptionDependency) Test(org.junit.Test)

Aggregations

OptimizedAssumptionDependency (org.graalvm.compiler.truffle.common.OptimizedAssumptionDependency)2 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 WeakReference (java.lang.ref.WeakReference)1 OptimizedAssumption (org.graalvm.compiler.truffle.runtime.OptimizedAssumption)1 Test (org.junit.Test)1