Search in sources :

Example 86 with DebugContext

use of org.graalvm.compiler.debug.DebugContext 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 87 with DebugContext

use of org.graalvm.compiler.debug.DebugContext in project graal by oracle.

the class DebugContextTest method testLogging.

@Test
public void testLogging() throws IOException {
    OptionValues options = new OptionValues(EconomicMap.create());
    options = new OptionValues(options, DebugOptions.Log, ":5");
    DebugContextSetup setup = new DebugContextSetup();
    try (DebugContext debug = setup.openDebugContext(options)) {
        for (int level = DebugContext.BASIC_LEVEL; level <= DebugContext.VERY_DETAILED_LEVEL; level++) {
            try (DebugContext.Scope s0 = debug.scope("TestLogging")) {
                debug.log(level, "log statement at level %d", level);
                try (DebugContext.Scope s1 = debug.scope("Level1")) {
                    debug.log(level, "log statement at level %d", level);
                    try (DebugContext.Scope s2 = debug.scope("Level2")) {
                        debug.log(level, "log statement at level %d", level);
                        try (DebugContext.Scope s3 = debug.scope("Level3")) {
                            debug.log(level, "log statement at level %d", level);
                            try (DebugContext.Scope s4 = debug.scope("Level4")) {
                                debug.log(level, "log statement at level %d", level);
                                try (DebugContext.Scope s5 = debug.scope("Level5")) {
                                    debug.log(level, "log statement at level %d", level);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    DataInputStream in = new DataInputStream(getClass().getResourceAsStream(getClass().getSimpleName() + ".testLogging.input"));
    byte[] buf = new byte[in.available()];
    in.readFully(buf);
    String threadLabel = "[thread:" + Thread.currentThread().getId() + "]";
    String expect = new String(buf).replace("[thread:1]", threadLabel);
    String log = setup.logOutput.toString();
    Assert.assertEquals(expect, log);
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) Scope(org.graalvm.compiler.debug.DebugContext.Scope) DebugContext(org.graalvm.compiler.debug.DebugContext) DataInputStream(java.io.DataInputStream) Test(org.junit.Test)

Example 88 with DebugContext

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

Example 89 with DebugContext

use of org.graalvm.compiler.debug.DebugContext 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 90 with DebugContext

use of org.graalvm.compiler.debug.DebugContext 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

DebugContext (org.graalvm.compiler.debug.DebugContext)234 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)87 OptionValues (org.graalvm.compiler.options.OptionValues)50 Indent (org.graalvm.compiler.debug.Indent)37 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)31 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)29 Test (org.junit.Test)27 Node (org.graalvm.compiler.graph.Node)24 PhaseContext (org.graalvm.compiler.phases.tiers.PhaseContext)24 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)22 LIRInstruction (org.graalvm.compiler.lir.LIRInstruction)20 Scope (org.graalvm.compiler.debug.DebugContext.Scope)18 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)18 DebugDumpScope (org.graalvm.compiler.debug.DebugDumpScope)17 ValueNode (org.graalvm.compiler.nodes.ValueNode)16 FixedNode (org.graalvm.compiler.nodes.FixedNode)14 CompilationResult (org.graalvm.compiler.code.CompilationResult)13 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)13 GraphBuilderConfiguration (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration)12 LIR (org.graalvm.compiler.lir.LIR)11