Search in sources :

Example 6 with Builder

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

Example 7 with Builder

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());
}
Also used : PrintStream(java.io.PrintStream) OptionValues(org.graalvm.compiler.options.OptionValues) Builder(org.graalvm.compiler.debug.DebugContext.Builder) 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 8 with Builder

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

Example 9 with Builder

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;
}
Also used : Builder(org.graalvm.compiler.debug.DebugContext.Builder) DebugContext(org.graalvm.compiler.debug.DebugContext)

Example 10 with Builder

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));
    }
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) Builder(org.graalvm.compiler.debug.DebugContext.Builder) 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

Builder (org.graalvm.compiler.debug.DebugContext.Builder)31 DebugContext (org.graalvm.compiler.debug.DebugContext)27 OptionValues (org.graalvm.compiler.options.OptionValues)21 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)10 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)9 GraalDebugHandlersFactory (org.graalvm.compiler.printer.GraalDebugHandlersFactory)8 Test (org.junit.Test)8 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)7 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)7 Providers (org.graalvm.compiler.phases.util.Providers)7 GraphBuilderConfiguration (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration)6 Method (java.lang.reflect.Method)5 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)5 GraphBuilderPhase (org.graalvm.compiler.java.GraphBuilderPhase)5 Plugins (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)5 InvocationPlugins (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins)5 PhaseSuite (org.graalvm.compiler.phases.PhaseSuite)5 RuntimeProvider (org.graalvm.compiler.runtime.RuntimeProvider)5 IOException (java.io.IOException)4 OptionKey (org.graalvm.compiler.options.OptionKey)4