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();
}
}
}
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
}
}
}
Aggregations