use of org.graalvm.compiler.debug.DebugContext.Scope in project graal by oracle.
the class DebugContextTest method testDisableIntercept.
@Test
public void testDisableIntercept() {
EconomicMap<OptionKey<?>, Object> map = EconomicMap.create();
// Configure with an option that enables scopes
map.put(DebugOptions.DumpOnError, true);
OptionValues options = new OptionValues(map);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DebugContext debug = DebugContext.create(options, NO_DESCRIPTION, NO_GLOBAL_METRIC_VALUES, new PrintStream(baos), DebugHandlersFactory.LOADER);
Exception e = new Exception();
try {
try (DebugCloseable disabled = debug.disableIntercept();
Scope s1 = debug.scope("ScopeWithDisabledIntercept")) {
try (Scope s2 = debug.scope("InnerScopeInheritsDisabledIntercept")) {
throw e;
}
} catch (Throwable t) {
assert e == t;
debug.handle(t);
}
} catch (Throwable t) {
// The exception object should propagate all the way out through
// an intercept disabled scope
Assert.assertEquals(e, t);
}
String logged = baos.toString();
Assert.assertEquals("Exception should not have been intercepted", "", logged);
}
use of org.graalvm.compiler.debug.DebugContext.Scope in project graal by oracle.
the class DebugContextTest method testDumping.
@Test
public void testDumping() {
for (int level = DebugContext.BASIC_LEVEL; level <= DebugContext.VERY_DETAILED_LEVEL; level++) {
OptionValues options = new OptionValues(EconomicMap.create());
options = new OptionValues(options, DebugOptions.Dump, "Scope" + level + ":" + level);
DebugContextSetup setup = new DebugContextSetup();
try (DebugContext debug = setup.openDebugContext(options);
DebugContext.Scope s0 = debug.scope("TestDumping")) {
try (DebugContext.Scope s1 = debug.scope("Scope1")) {
try (DebugContext.Scope s2 = debug.scope("Scope2")) {
try (DebugContext.Scope s3 = debug.scope("Scope3")) {
try (DebugContext.Scope s4 = debug.scope("Scope4")) {
try (DebugContext.Scope s5 = debug.scope("Scope5")) {
debug.dump(level, "an object", "at level %d", level);
}
}
}
}
}
}
String expect = String.format("Dumping an object with label \"at level %d\"%n", level);
String dump = setup.dumpOutput.toString();
Assert.assertEquals(expect, dump);
}
}
use of org.graalvm.compiler.debug.DebugContext.Scope in project graal by oracle.
the class DebugContextTest method testDisabledSandbox.
@Test
public void testDisabledSandbox() {
EconomicMap<OptionKey<?>, Object> map = EconomicMap.create();
// Configure with an option that enables scopes
map.put(DebugOptions.DumpOnError, true);
OptionValues options = new OptionValues(map);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DebugContext debug = DebugContext.create(options, NO_DESCRIPTION, NO_GLOBAL_METRIC_VALUES, new PrintStream(baos), DebugHandlersFactory.LOADER);
Exception e = new Exception("testDisabledSandbox");
try {
// Test a disabled sandbox scope
try (DebugContext.Scope d = debug.sandbox("TestExceptionHandling", null)) {
throw e;
} catch (Throwable t) {
assert e == t;
debug.handle(t);
}
} catch (Throwable t) {
// The exception object should propagate all the way out through
// a disabled sandbox scope
Assert.assertEquals(e, t);
}
String logged = baos.toString();
Assert.assertTrue(logged, logged.isEmpty());
}
use of org.graalvm.compiler.debug.DebugContext.Scope in project graal by oracle.
the class DerivedOopTest method testFieldOffsetMergeNonLiveBasePointer.
@Test
@SuppressWarnings("try")
public void testFieldOffsetMergeNonLiveBasePointer() {
thrown.expect(GraalError.class);
thrown.expectMessage(UNKNOWN_REFERENCE_AT_SAFEPOINT_MSG);
DebugContext debug = getDebugContext();
try (Scope s = debug.disable()) {
// Run a couple times to encourage objects to move
for (int i = 0; i < 4; i++) {
Result r = new Result();
test("fieldOffsetMergeSnippet01", r, 8L, 16L);
Assert.assertEquals(r.beforeGC.delta(), r.afterGC.delta());
}
}
}
use of org.graalvm.compiler.debug.DebugContext.Scope in project graal by oracle.
the class WriteBarrierVerificationTest method testPredicate.
@SuppressWarnings("try")
private void testPredicate(final String snippet, final GraphPredicate expectedBarriers, final int... removedBarrierIndices) {
DebugContext debug = getDebugContext();
try (DebugCloseable d = debug.disableIntercept();
DebugContext.Scope s = debug.scope("WriteBarrierVerificationTest", new DebugDumpScope(snippet))) {
final StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES, debug);
HighTierContext highTierContext = getDefaultHighTierContext();
new InliningPhase(new CanonicalizerPhase()).apply(graph, highTierContext);
MidTierContext midTierContext = new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, graph.getProfilingInfo());
new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, highTierContext);
new GuardLoweringPhase().apply(graph, midTierContext);
new LoopSafepointInsertionPhase().apply(graph);
new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, highTierContext);
new WriteBarrierAdditionPhase(config).apply(graph);
int barriers = 0;
// First, the total number of expected barriers is checked.
if (config.useG1GC) {
barriers = graph.getNodes().filter(G1PreWriteBarrier.class).count() + graph.getNodes().filter(G1PostWriteBarrier.class).count() + graph.getNodes().filter(G1ArrayRangePreWriteBarrier.class).count() + graph.getNodes().filter(G1ArrayRangePostWriteBarrier.class).count();
Assert.assertTrue(expectedBarriers.apply(graph) * 2 == barriers);
} else {
barriers = graph.getNodes().filter(SerialWriteBarrier.class).count() + graph.getNodes().filter(SerialArrayRangeWriteBarrier.class).count();
Assert.assertTrue(expectedBarriers.apply(graph) == barriers);
}
ResolvedJavaField barrierIndexField = getMetaAccess().lookupJavaField(WriteBarrierVerificationTest.class.getDeclaredField("barrierIndex"));
LocationIdentity barrierIdentity = new FieldLocationIdentity(barrierIndexField);
// Iterate over all write nodes and remove barriers according to input indices.
NodeIteratorClosure<Boolean> closure = new NodeIteratorClosure<Boolean>() {
@Override
protected Boolean processNode(FixedNode node, Boolean currentState) {
if (node instanceof WriteNode) {
WriteNode write = (WriteNode) node;
LocationIdentity obj = write.getLocationIdentity();
if (obj.equals(barrierIdentity)) {
/*
* A "barrierIndex" variable was found and is checked against the input
* barrier array.
*/
if (eliminateBarrier(write.value().asJavaConstant().asInt(), removedBarrierIndices)) {
return true;
}
}
} else if (node instanceof SerialWriteBarrier || node instanceof G1PostWriteBarrier) {
// Remove flagged write barriers.
if (currentState) {
graph.removeFixed(((FixedWithNextNode) node));
return false;
}
}
return currentState;
}
private boolean eliminateBarrier(int index, int[] map) {
for (int i = 0; i < map.length; i++) {
if (map[i] == index) {
return true;
}
}
return false;
}
@Override
protected EconomicMap<LoopExitNode, Boolean> processLoop(LoopBeginNode loop, Boolean initialState) {
return ReentrantNodeIterator.processLoop(this, loop, initialState).exitStates;
}
@Override
protected Boolean merge(AbstractMergeNode merge, List<Boolean> states) {
return false;
}
@Override
protected Boolean afterSplit(AbstractBeginNode node, Boolean oldState) {
return false;
}
};
try (Scope disabled = debug.disable()) {
ReentrantNodeIterator.apply(closure, graph.start(), false);
new WriteBarrierVerificationPhase(config).apply(graph);
} catch (AssertionError error) {
/*
* Catch assertion, test for expected one and re-throw in order to validate unit
* test.
*/
Assert.assertTrue(error.getMessage().contains("Write barrier must be present"));
throw error;
}
} catch (Throwable e) {
throw debug.handle(e);
}
}
Aggregations