Search in sources :

Example 26 with Builder

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

the class HotSpotGraalRuntime method openDebugContext.

@Override
public DebugContext openDebugContext(OptionValues compilationOptions, CompilationIdentifier compilationId, Object compilable, Iterable<DebugHandlersFactory> factories, PrintStream logStream) {
    if (management != null && management.poll(false) != null) {
        if (compilable instanceof HotSpotResolvedJavaMethod) {
            HotSpotResolvedObjectType type = ((HotSpotResolvedJavaMethod) compilable).getDeclaringClass();
            if (type instanceof HotSpotResolvedJavaType) {
                Class<?> clazz = runtime().getMirror(type);
                if (clazz != null) {
                    try {
                        ClassLoader cl = clazz.getClassLoader();
                        if (cl != null) {
                            loaders.add(cl);
                        }
                    } catch (SecurityException e) {
                    // This loader can obviously not be used for resolving class names
                    }
                }
            }
        }
    }
    Description description = new Description(compilable, compilationId.toString(CompilationIdentifier.Verbosity.ID));
    Builder builder = // 
    new Builder(compilationOptions, factories).globalMetrics(// 
    metricValues).description(// 
    description).logStream(logStream);
    if (compilerProfiler != null) {
        int compileId = ((HotSpotCompilationIdentifier) compilationId).getRequest().getId();
        builder.compilationListener(new CompilationListenerProfiler(compilerProfiler, compileId));
    }
    return builder.build();
}
Also used : HotSpotResolvedJavaMethod(jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod) Description(org.graalvm.compiler.debug.DebugContext.Description) HotSpotResolvedObjectType(jdk.vm.ci.hotspot.HotSpotResolvedObjectType) HotSpotResolvedJavaType(jdk.vm.ci.hotspot.HotSpotResolvedJavaType) Builder(org.graalvm.compiler.debug.DebugContext.Builder) CompilationListenerProfiler(org.graalvm.compiler.core.common.CompilationListenerProfiler)

Example 27 with Builder

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

the class PerformanceWarningTest method testHelper.

@SuppressWarnings("try")
private void testHelper(RootNode rootNode, boolean expectException, String... outputStrings) {
    // Compile and capture output to logger's stream.
    boolean seenException = false;
    try {
        OptimizedCallTarget target = (OptimizedCallTarget) rootNode.getCallTarget();
        DebugContext debug = new Builder(GraalTruffleRuntime.getRuntime().getGraalOptions(OptionValues.class)).build();
        try (DebugCloseable d = debug.disableIntercept();
            DebugContext.Scope s = debug.scope("PerformanceWarningTest")) {
            final OptimizedCallTarget compilable = target;
            CompilationIdentifier compilationId = getTruffleCompiler(target).createCompilationIdentifier(compilable);
            getTruffleCompiler(target).compileAST(compilable.getOptionValues(), debug, compilable, compilationId, new TruffleCompilerImpl.CancellableTruffleCompilationTask(new TruffleCompilationTask() {

                private TruffleInliningData inlining = new TruffleInlining();

                @Override
                public boolean isCancelled() {
                    return false;
                }

                @Override
                public boolean isLastTier() {
                    return true;
                }

                @Override
                public TruffleInliningData inliningData() {
                    return inlining;
                }

                @Override
                public boolean hasNextTier() {
                    return false;
                }
            }), null);
            assertTrue(compilable.isValid());
        }
    } catch (AssertionError e) {
        seenException = true;
        if (!expectException) {
            throw new AssertionError("Unexpected exception caught." + (outContent.size() > 0 ? '\n' + outContent.toString() : ""), e);
        }
    }
    if (expectException && !seenException) {
        Assert.assertTrue("Expected exception not caught.", false);
    }
    // Check output on TTY.
    String output = outContent.toString();
    if (outputStrings == EMPTY_PERF_WARNINGS) {
        Assert.assertEquals("", output);
    } else {
        for (String s : outputStrings) {
            Assert.assertTrue(String.format("Root node class %s: \"%s\" not found in output \"%s\"", rootNode.getClass().getName(), s, output), output.contains(s));
        }
    }
}
Also used : CompilationIdentifier(org.graalvm.compiler.core.common.CompilationIdentifier) TruffleCompilerImpl(org.graalvm.compiler.truffle.compiler.TruffleCompilerImpl) Builder(org.graalvm.compiler.debug.DebugContext.Builder) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) TruffleInliningData(org.graalvm.compiler.truffle.common.TruffleInliningData) DebugContext(org.graalvm.compiler.debug.DebugContext) TruffleCompilationTask(org.graalvm.compiler.truffle.common.TruffleCompilationTask) TruffleInlining(org.graalvm.compiler.truffle.runtime.TruffleInlining) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable)

Example 28 with Builder

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

the class StaticInterfaceFieldTest method eagerlyParseMethod.

@SuppressWarnings("try")
private void eagerlyParseMethod(Class<C> clazz, String methodName) {
    RuntimeProvider rt = Graal.getRequiredCapability(RuntimeProvider.class);
    Providers providers = rt.getHostBackend().getProviders();
    MetaAccessProvider metaAccess = providers.getMetaAccess();
    PhaseSuite<HighTierContext> graphBuilderSuite = new PhaseSuite<>();
    Plugins plugins = new Plugins(new InvocationPlugins());
    GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true).withUnresolvedIsError(true);
    graphBuilderSuite.appendPhase(new GraphBuilderPhase(config));
    HighTierContext context = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.NONE);
    Assume.assumeTrue(VerifyPhase.class.desiredAssertionStatus());
    final Method m = getMethod(clazz, methodName);
    ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
    OptionValues options = getInitialOptions();
    DebugContext debug = new Builder(options).build();
    StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).build();
    try (DebugCloseable s = debug.disableIntercept();
        DebugContext.Scope ds = debug.scope("GraphBuilding", graph, method)) {
        graphBuilderSuite.apply(graph, context);
    } catch (Throwable e) {
        throw debug.handle(e);
    }
}
Also used : InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) OptionValues(org.graalvm.compiler.options.OptionValues) Builder(org.graalvm.compiler.debug.DebugContext.Builder) RuntimeProvider(org.graalvm.compiler.runtime.RuntimeProvider) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) Method(java.lang.reflect.Method) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) DebugContext(org.graalvm.compiler.debug.DebugContext) Providers(org.graalvm.compiler.phases.util.Providers) VerifyPhase(org.graalvm.compiler.phases.VerifyPhase) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) PhaseSuite(org.graalvm.compiler.phases.PhaseSuite) GraphBuilderPhase(org.graalvm.compiler.java.GraphBuilderPhase) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) Plugins(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)

Example 29 with Builder

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

the class VerifyBailoutUsageTest method testBailoutUsage.

@SuppressWarnings("try")
private static void testBailoutUsage(Class<?> c) {
    RuntimeProvider rt = Graal.getRequiredCapability(RuntimeProvider.class);
    Providers providers = rt.getHostBackend().getProviders();
    MetaAccessProvider metaAccess = providers.getMetaAccess();
    PhaseSuite<HighTierContext> graphBuilderSuite = new PhaseSuite<>();
    Plugins plugins = new Plugins(new InvocationPlugins());
    GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true).withUnresolvedIsError(true);
    graphBuilderSuite.appendPhase(new GraphBuilderPhase(config));
    HighTierContext context = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.NONE);
    OptionValues options = getInitialOptions();
    DebugContext debug = new Builder(options).build();
    for (Method m : c.getDeclaredMethods()) {
        if (!Modifier.isNative(m.getModifiers()) && !Modifier.isAbstract(m.getModifiers())) {
            ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
            StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).build();
            graphBuilderSuite.apply(graph, context);
            try (DebugCloseable s = debug.disableIntercept()) {
                new VerifyBailoutUsage().apply(graph, context);
            }
        }
    }
}
Also used : InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) OptionValues(org.graalvm.compiler.options.OptionValues) Builder(org.graalvm.compiler.debug.DebugContext.Builder) RuntimeProvider(org.graalvm.compiler.runtime.RuntimeProvider) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) DebugContext(org.graalvm.compiler.debug.DebugContext) Method(java.lang.reflect.Method) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Providers(org.graalvm.compiler.phases.util.Providers) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) PhaseSuite(org.graalvm.compiler.phases.PhaseSuite) GraphBuilderPhase(org.graalvm.compiler.java.GraphBuilderPhase) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) Plugins(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)

Example 30 with Builder

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

the class TruffleCompilerImpl method openDebugContext.

@Override
public final TruffleDebugContext openDebugContext(Map<String, Object> options, TruffleCompilation compilation) {
    OptionValues graalOptions = TruffleCompilerRuntime.getRuntime().getGraalOptions(OptionValues.class);
    final DebugContext debugContext;
    if (compilation == null) {
        debugContext = new Builder(graalOptions).build();
    } else {
        TruffleCompilationIdentifier ident = asTruffleCompilationIdentifier(compilation);
        CompilableTruffleAST compilable = ident.getCompilable();
        org.graalvm.options.OptionValues truffleOptions = getOptionsForCompiler(options);
        if (ExpansionStatistics.isEnabled(truffleOptions)) {
            graalOptions = enableNodeSourcePositions(graalOptions);
        }
        debugContext = createDebugContext(graalOptions, ident, compilable, DebugContext.getDefaultLogStream());
    }
    return new TruffleDebugContextImpl(debugContext);
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) Builder(org.graalvm.compiler.debug.DebugContext.Builder) TruffleDebugContext(org.graalvm.compiler.truffle.common.TruffleDebugContext) DebugContext(org.graalvm.compiler.debug.DebugContext) CompilableTruffleAST(org.graalvm.compiler.truffle.common.CompilableTruffleAST)

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