use of org.graalvm.compiler.debug.DebugContext.Builder in project graal by oracle.
the class DebugContextTest method testDisableIntercept.
@Test
public void testDisableIntercept() {
TimerKeyTest.assumeManagementLibraryIsLoadable();
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 = new Builder(options).globalMetrics(NO_GLOBAL_METRIC_VALUES).description(NO_DESCRIPTION).logStream(new PrintStream(baos)).build();
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.Builder in project graal by oracle.
the class DebugContextTest method testDisabledSandbox.
@Test
public void testDisabledSandbox() {
TimerKeyTest.assumeManagementLibraryIsLoadable();
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 = new Builder(options).globalMetrics(NO_GLOBAL_METRIC_VALUES).description(NO_DESCRIPTION).logStream(new PrintStream(baos)).build();
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.Builder in project graal by oracle.
the class DebugContextTest method testInvariantChecking.
/**
* Tests that using a {@link DebugContext} on a thread other than the one on which it was
* created causes an assertion failure.
*/
@Test
public void testInvariantChecking() throws InterruptedException {
Assume.assumeTrue(Assertions.assertionsEnabled());
EconomicMap<OptionKey<?>, Object> map = EconomicMap.create();
// Configure with an option that enables counters
map.put(DebugOptions.Counters, "");
OptionValues options = new OptionValues(map);
DebugContext debug = new Builder(options).build();
CounterKey counter = DebugContext.counter("DebugContextTestCounter");
AssertionError[] result = { null };
Thread thread = new Thread() {
@Override
public void run() {
try {
counter.add(debug, 1);
} catch (AssertionError e) {
result[0] = e;
}
}
};
thread.start();
thread.join();
Assert.assertNotNull("Expected thread to throw AssertionError", result[0]);
}
use of org.graalvm.compiler.debug.DebugContext.Builder in project graal by oracle.
the class GraphTest method getDebug.
protected DebugContext getDebug(OptionValues options) {
DebugContext cached = cachedDebug.get();
if (cached != null) {
if (cached.getOptions() == options) {
return cached;
}
throw new AssertionError("At most one " + DebugContext.class.getName() + " object should be created per test");
}
DebugContext debug = new Builder(options).build();
cachedDebug.set(debug);
return debug;
}
use of org.graalvm.compiler.debug.DebugContext.Builder in project graal by oracle.
the class TimerKeyTest method test2.
/**
* Asserts that a timer replied recursively without any other interleaving timers has the same
* flat and accumulated times.
*/
@Test
public void test2() {
EconomicMap<OptionKey<?>, Object> map = EconomicMap.create();
map.put(DebugOptions.Time, "");
OptionValues options = new OptionValues(map);
DebugContext debug = new Builder(options, NO_CONFIG_CUSTOMIZERS).build();
TimerKey timerC = DebugContext.timer("TimerC");
try (DebugCloseable c1 = timerC.start(debug)) {
spin(50);
try (DebugCloseable c2 = timerC.start(debug)) {
spin(50);
try (DebugCloseable c3 = timerC.start(debug)) {
spin(50);
try (DebugCloseable c4 = timerC.start(debug)) {
spin(50);
try (DebugCloseable c5 = timerC.start(debug)) {
spin(50);
}
}
}
}
}
if (timerC.getFlat() != null) {
assertEquals(timerC.getFlat().getCurrentValue(debug), timerC.getCurrentValue(debug));
}
}
Aggregations