Search in sources :

Example 1 with OptionKey

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);
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) Field(java.lang.reflect.Field) OptionType(org.graalvm.compiler.options.OptionType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) OptionKey(org.graalvm.compiler.options.OptionKey)

Example 2 with OptionKey

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);
}
Also used : PrintStream(java.io.PrintStream) OptionValues(org.graalvm.compiler.options.OptionValues) Scope(org.graalvm.compiler.debug.DebugContext.Scope) OptionKey(org.graalvm.compiler.options.OptionKey) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DebugContext(org.graalvm.compiler.debug.DebugContext) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with OptionKey

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]);
}
Also used : CounterKey(org.graalvm.compiler.debug.CounterKey) OptionValues(org.graalvm.compiler.options.OptionValues) OptionKey(org.graalvm.compiler.options.OptionKey) DebugContext(org.graalvm.compiler.debug.DebugContext) Test(org.junit.Test)

Example 4 with OptionKey

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());
}
Also used : PrintStream(java.io.PrintStream) OptionValues(org.graalvm.compiler.options.OptionValues) Scope(org.graalvm.compiler.debug.DebugContext.Scope) OptionKey(org.graalvm.compiler.options.OptionKey) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DebugContext(org.graalvm.compiler.debug.DebugContext) IOException(java.io.IOException) Test(org.junit.Test)

Example 5 with OptionKey

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));
    }
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) OptionKey(org.graalvm.compiler.options.OptionKey) DebugContext(org.graalvm.compiler.debug.DebugContext) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) TimerKey(org.graalvm.compiler.debug.TimerKey) Test(org.junit.Test)

Aggregations

OptionKey (org.graalvm.compiler.options.OptionKey)17 OptionValues (org.graalvm.compiler.options.OptionValues)15 Test (org.junit.Test)13 DebugContext (org.graalvm.compiler.debug.DebugContext)8 IOException (java.io.IOException)4 Scope (org.graalvm.compiler.debug.DebugContext.Scope)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 PrintStream (java.io.PrintStream)3 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)2 OptionDescriptors (org.graalvm.compiler.options.OptionDescriptors)2 HostedOptionKey (com.oracle.svm.core.option.HostedOptionKey)1 File (java.io.File)1 FileReader (java.io.FileReader)1 Field (java.lang.reflect.Field)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 Path (java.nio.file.Path)1 Map (java.util.Map)1 Properties (java.util.Properties)1