Search in sources :

Example 21 with Builder

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

the class DebugContextTest method testEnabledSandbox.

@Test
public void testEnabledSandbox() {
    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("testEnabledSandbox");
    String scopeName = "";
    try {
        try (DebugContext.Scope d = debug.sandbox("TestExceptionHandling", debug.getConfig())) {
            scopeName = d.getQualifiedName();
            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 enabled sandbox scope
        Assert.assertEquals(e, t);
    }
    String logged = baos.toString();
    String expected = String.format("Exception raised in scope %s: %s", scopeName, e);
    String line = "-------------------------------------------------------";
    Assert.assertTrue(String.format("Could not find \"%s\" in content between lines below:%n%s%n%s%s", expected, line, logged, line), logged.contains(expected));
}
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 22 with Builder

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

the class NegateNodeCanonicalizationTest method before.

@Before
public void before() {
    OptionValues options = getInitialOptions();
    DebugContext debug = new Builder(options).build();
    graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.YES).build();
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) Builder(org.graalvm.compiler.debug.DebugContext.Builder) DebugContext(org.graalvm.compiler.debug.DebugContext) Before(org.junit.Before)

Example 23 with Builder

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

the class StructuredGraphTest method testGetBytecodeSize.

@Test
public void testGetBytecodeSize() {
    OptionValues options = getInitialOptions();
    DebugContext debug = new Builder(options).build();
    ResolvedJavaMethod rootMethod = getResolvedJavaMethod("testGetBytecodeSize");
    // Test graph with root method and inlined methods
    StructuredGraph graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.YES).method(rootMethod).build();
    ResolvedJavaMethod otherMethod = getResolvedJavaMethod(GraalCompilerTest.class, "createSuites");
    int expectedBytecodeSize = rootMethod.getCodeSize();
    for (int i = 0; i < 10; i++) {
        graph.recordMethod(otherMethod);
        expectedBytecodeSize += otherMethod.getCodeSize();
    }
    Assert.assertEquals(expectedBytecodeSize, graph.getBytecodeSize());
    // Test graph with only root method, no inlined methods
    graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.YES).method(rootMethod).build();
    expectedBytecodeSize = rootMethod.getCodeSize();
    Assert.assertEquals(expectedBytecodeSize, graph.getBytecodeSize());
    // Test graph with no root method, only inlined methods
    graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.YES).build();
    expectedBytecodeSize = 0;
    for (int i = 0; i < 10; i++) {
        graph.recordMethod(otherMethod);
        expectedBytecodeSize += otherMethod.getCodeSize();
    }
    Assert.assertEquals(expectedBytecodeSize, graph.getBytecodeSize());
    // Test graph with no root method, no inlined methods
    graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.YES).build();
    expectedBytecodeSize = 0;
    Assert.assertEquals(expectedBytecodeSize, graph.getBytecodeSize());
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Builder(org.graalvm.compiler.debug.DebugContext.Builder) DebugContext(org.graalvm.compiler.debug.DebugContext) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Test(org.junit.Test) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest)

Example 24 with Builder

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

the class AbortOnDisallowedNode method canInitializeWithoutSideEffects.

@SuppressWarnings("try")
boolean canInitializeWithoutSideEffects(Class<?> clazz, Set<Class<?>> existingAnalyzedClasses) {
    ResolvedJavaType type = originalProviders.getMetaAccess().lookupJavaType(clazz);
    assert type.getSuperclass() == null || type.getSuperclass().isInitialized() : "This analysis assumes that the superclass was successfully analyzed and initialized beforehand: " + type.toJavaName(true);
    ResolvedJavaMethod clinit = type.getClassInitializer();
    if (clinit == null) {
        /* No class initializer, so the class can trivially be initialized. */
        return true;
    } else if (clinit.getCode() == null) {
        /*
             * Happens e.g. when linking of the class failed. Note that we really need to check for
             * getCode(), because getCodeSize() still returns a value > 0 for such methods.
             */
        return false;
    }
    Set<Class<?>> analyzedClasses = existingAnalyzedClasses;
    if (analyzedClasses == null) {
        analyzedClasses = new HashSet<>();
    } else if (analyzedClasses.contains(clazz)) {
        /* Cyclic dependency of class initializers. */
        return false;
    }
    analyzedClasses.add(clazz);
    OptionValues options = HostedOptionValues.singleton();
    DebugContext debug = new Builder(options).build();
    try (DebugContext.Scope s = debug.scope("EarlyClassInitializerAnalysis", clinit)) {
        return canInitializeWithoutSideEffects(clinit, analyzedClasses, options, debug);
    } catch (Throwable ex) {
        throw debug.handle(ex);
    }
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) HostedOptionValues(com.oracle.svm.core.option.HostedOptionValues) Builder(org.graalvm.compiler.debug.DebugContext.Builder) DebugContext(org.graalvm.compiler.debug.DebugContext) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 25 with Builder

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

the class LambdaProxyRenamingSubstitutionProcessor method getSubstitution.

private LambdaSubstitutionType getSubstitution(ResolvedJavaType original) {
    return typeSubstitutions.computeIfAbsent(original, (key) -> {
        OptionValues options = bb.getOptions();
        DebugContext debug = new Builder(options, new GraalDebugHandlersFactory(bb.getProviders().getSnippetReflection())).build();
        Providers providers = GraalAccess.getOriginalProviders();
        String lambdaTargetName = LambdaUtils.findStableLambdaName(new NoClassInitializationPlugin(), providers, key, options, debug, this);
        return new LambdaSubstitutionType(key, findUniqueLambdaProxyName(lambdaTargetName));
    });
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) Builder(org.graalvm.compiler.debug.DebugContext.Builder) DebugContext(org.graalvm.compiler.debug.DebugContext) Providers(org.graalvm.compiler.phases.util.Providers) NoClassInitializationPlugin(com.oracle.graal.pointsto.phases.NoClassInitializationPlugin) GraalDebugHandlersFactory(org.graalvm.compiler.printer.GraalDebugHandlersFactory)

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