use of org.graalvm.compiler.options.OptionKey in project graal by oracle.
the class ReflectionOptionDescriptors method addOption.
private void addOption(Class<?> declaringClass, String fieldName, String help) {
try {
Field f = declaringClass.getDeclaredField(fieldName);
if (!OptionKey.class.isAssignableFrom(f.getType())) {
throw new IllegalArgumentException(String.format("Option field must be of type %s: %s", OptionKey.class.getName(), f));
}
if (!Modifier.isStatic(f.getModifiers())) {
throw new IllegalArgumentException(String.format("Option field must be static: %s", f));
}
f.setAccessible(true);
Type declaredType = f.getAnnotatedType().getType();
if (!(declaredType instanceof ParameterizedType)) {
throw new IllegalArgumentException(String.format("Option field must have a parameterized type: %s", f));
}
ParameterizedType pt = (ParameterizedType) declaredType;
Type[] actualTypeArguments = pt.getActualTypeArguments();
assert actualTypeArguments.length == 1;
Class<?> optionValueType = (Class<?>) actualTypeArguments[0];
descriptors.put(fieldName, OptionDescriptor.create(fieldName, OptionType.Debug, optionValueType, help, declaringClass, fieldName, (OptionKey<?>) f.get(null)));
} catch (IllegalAccessException | NoSuchFieldException e) {
throw new IllegalArgumentException(e);
}
}
use of org.graalvm.compiler.options.OptionKey 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.options.OptionKey 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 = DebugContext.create(options, DebugHandlersFactory.LOADER);
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.options.OptionKey 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.options.OptionKey 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 = DebugContext.create(options, NO_DESCRIPTION, NO_GLOBAL_METRIC_VALUES, DEFAULT_LOG_STREAM, NO_CONFIG_CUSTOMIZERS);
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