Search in sources :

Example 41 with OptionValues

use of org.graalvm.compiler.options.OptionValues 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 42 with OptionValues

use of org.graalvm.compiler.options.OptionValues 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 43 with OptionValues

use of org.graalvm.compiler.options.OptionValues 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 44 with OptionValues

use of org.graalvm.compiler.options.OptionValues 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 45 with OptionValues

use of org.graalvm.compiler.options.OptionValues 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

OptionValues (org.graalvm.compiler.options.OptionValues)158 Test (org.junit.Test)65 DebugContext (org.graalvm.compiler.debug.DebugContext)50 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)36 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)30 Graph (org.graalvm.compiler.graph.Graph)22 OptionKey (org.graalvm.compiler.options.OptionKey)16 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)13 Plugins (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)11 GraphBuilderConfiguration (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration)10 InvocationPlugins (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins)10 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)10 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)9 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)9 GraphBuilderPhase (org.graalvm.compiler.java.GraphBuilderPhase)9 Providers (org.graalvm.compiler.phases.util.Providers)9 IOException (java.io.IOException)8 Method (java.lang.reflect.Method)8 CompilationResult (org.graalvm.compiler.code.CompilationResult)7 CompilationIdentifier (org.graalvm.compiler.core.common.CompilationIdentifier)7