use of org.graalvm.compiler.truffle.runtime.OptimizedAssumption 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