Search in sources :

Example 1 with GraalDebugHandlersFactory

use of org.graalvm.compiler.printer.GraalDebugHandlersFactory in project graal by oracle.

the class HotSpotHostBackend method completeInitialization.

@Override
@SuppressWarnings("try")
public void completeInitialization(HotSpotJVMCIRuntime jvmciRuntime, OptionValues options) {
    final HotSpotProviders providers = getProviders();
    HotSpotHostForeignCallsProvider foreignCalls = (HotSpotHostForeignCallsProvider) providers.getForeignCalls();
    final HotSpotLoweringProvider lowerer = (HotSpotLoweringProvider) providers.getLowerer();
    try (InitTimer st = timer("foreignCalls.initialize")) {
        foreignCalls.initialize(providers, options);
    }
    try (InitTimer st = timer("lowerer.initialize")) {
        Iterable<DebugHandlersFactory> factories = Collections.singletonList(new GraalDebugHandlersFactory(providers.getSnippetReflection()));
        lowerer.initialize(options, factories, providers, config);
    }
}
Also used : HotSpotHostForeignCallsProvider(org.graalvm.compiler.hotspot.meta.HotSpotHostForeignCallsProvider) InitTimer(jdk.vm.ci.common.InitTimer) HotSpotLoweringProvider(org.graalvm.compiler.hotspot.meta.HotSpotLoweringProvider) DebugHandlersFactory(org.graalvm.compiler.debug.DebugHandlersFactory) GraalDebugHandlersFactory(org.graalvm.compiler.printer.GraalDebugHandlersFactory) HotSpotProviders(org.graalvm.compiler.hotspot.meta.HotSpotProviders) GraalDebugHandlersFactory(org.graalvm.compiler.printer.GraalDebugHandlersFactory)

Example 2 with GraalDebugHandlersFactory

use of org.graalvm.compiler.printer.GraalDebugHandlersFactory in project graal by oracle.

the class SimpleCFGTest method testImplies.

@Test
public void testImplies() {
    OptionValues options = getInitialOptions();
    DebugContext debug = DebugContext.create(options, new GraalDebugHandlersFactory(getSnippetReflection()));
    StructuredGraph graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.YES).build();
    EndNode trueEnd = graph.add(new EndNode());
    EndNode falseEnd = graph.add(new EndNode());
    AbstractBeginNode trueBegin = graph.add(new BeginNode());
    trueBegin.setNext(trueEnd);
    AbstractBeginNode falseBegin = graph.add(new BeginNode());
    falseBegin.setNext(falseEnd);
    IfNode ifNode = graph.add(new IfNode(null, trueBegin, falseBegin, 0.5));
    graph.start().setNext(ifNode);
    AbstractMergeNode merge = graph.add(new MergeNode());
    merge.addForwardEnd(trueEnd);
    merge.addForwardEnd(falseEnd);
    ReturnNode returnNode = graph.add(new ReturnNode(null));
    merge.setNext(returnNode);
    dumpGraph(graph);
    ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, true, true, true);
    Block[] blocks = cfg.getBlocks();
    // check number of blocks
    assertDeepEquals(4, blocks.length);
    // check block - node assignment
    assertDeepEquals(blocks[0], cfg.blockFor(graph.start()));
    assertDeepEquals(blocks[0], cfg.blockFor(ifNode));
    assertDeepEquals(blocks[1], cfg.blockFor(trueBegin));
    assertDeepEquals(blocks[1], cfg.blockFor(trueEnd));
    assertDeepEquals(blocks[2], cfg.blockFor(falseBegin));
    assertDeepEquals(blocks[2], cfg.blockFor(falseEnd));
    assertDeepEquals(blocks[3], cfg.blockFor(merge));
    assertDeepEquals(blocks[3], cfg.blockFor(returnNode));
    // check dominators
    assertDominator(blocks[0], null);
    assertDominator(blocks[1], blocks[0]);
    assertDominator(blocks[2], blocks[0]);
    assertDominator(blocks[3], blocks[0]);
    // check dominated
    assertDominatedSize(blocks[0], 3);
    assertDominatedSize(blocks[1], 0);
    assertDominatedSize(blocks[2], 0);
    assertDominatedSize(blocks[3], 0);
    // check postdominators
    assertPostdominator(blocks[0], blocks[3]);
    assertPostdominator(blocks[1], blocks[3]);
    assertPostdominator(blocks[2], blocks[3]);
    assertPostdominator(blocks[3], null);
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) DebugContext(org.graalvm.compiler.debug.DebugContext) IfNode(org.graalvm.compiler.nodes.IfNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) GraalDebugHandlersFactory(org.graalvm.compiler.printer.GraalDebugHandlersFactory) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) EndNode(org.graalvm.compiler.nodes.EndNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) BeginNode(org.graalvm.compiler.nodes.BeginNode) ControlFlowGraph(org.graalvm.compiler.nodes.cfg.ControlFlowGraph) Block(org.graalvm.compiler.nodes.cfg.Block) Test(org.junit.Test)

Example 3 with GraalDebugHandlersFactory

use of org.graalvm.compiler.printer.GraalDebugHandlersFactory in project graal by oracle.

the class NativeImageGenerator method registerReplacements.

@SuppressWarnings("try")
public static void registerReplacements(DebugContext debug, FeatureHandler featureHandler, RuntimeConfiguration runtimeConfig, Providers providers, SnippetReflectionProvider snippetReflection, boolean hosted) {
    OptionValues options = hosted ? HostedOptionValues.singleton() : RuntimeOptionValues.singleton();
    Providers runtimeCallProviders = runtimeConfig != null ? runtimeConfig.getBackendForNormalMethod().getProviders() : providers;
    SubstrateForeignCallsProvider foreignCallsProvider = (SubstrateForeignCallsProvider) providers.getForeignCalls();
    for (SubstrateForeignCallDescriptor descriptor : SnippetRuntime.getRuntimeCalls()) {
        foreignCallsProvider.getForeignCalls().put(descriptor, new SubstrateForeignCallLinkage(runtimeCallProviders, descriptor));
    }
    featureHandler.forEachGraalFeature(feature -> feature.registerForeignCalls(runtimeConfig, runtimeCallProviders, snippetReflection, foreignCallsProvider.getForeignCalls(), hosted));
    try (DebugContext.Scope s = debug.scope("RegisterLowerings", new DebugDumpScope("RegisterLowerings"))) {
        SubstrateLoweringProvider lowerer = (SubstrateLoweringProvider) providers.getLowerer();
        Map<Class<? extends Node>, NodeLoweringProvider<?>> lowerings = lowerer.getLowerings();
        Iterable<DebugHandlersFactory> factories = runtimeConfig != null ? runtimeConfig.getDebugHandlersFactories() : Collections.singletonList(new GraalDebugHandlersFactory(snippetReflection));
        lowerer.setConfiguration(runtimeConfig, options, factories, providers, snippetReflection);
        NonSnippetLowerings.registerLowerings(runtimeConfig, options, factories, providers, snippetReflection, lowerings);
        ArithmeticSnippets.registerLowerings(options, factories, providers, snippetReflection, lowerings);
        MonitorSnippets.registerLowerings(options, factories, providers, snippetReflection, lowerings);
        TypeSnippets.registerLowerings(runtimeConfig, options, factories, providers, snippetReflection, lowerings);
        ExceptionSnippets.registerLowerings(options, factories, providers, snippetReflection, lowerings);
        if (hosted) {
            AssertSnippets.registerLowerings(options, factories, providers, snippetReflection, lowerings);
            DeoptHostedSnippets.registerLowerings(options, factories, providers, snippetReflection, lowerings);
        } else {
            DeoptRuntimeSnippets.registerLowerings(options, factories, providers, snippetReflection, lowerings);
        }
        if (NativeImageOptions.DeoptimizeAll.getValue()) {
            DeoptTestSnippets.registerLowerings(options, factories, providers, snippetReflection, lowerings);
        }
        featureHandler.forEachGraalFeature(feature -> feature.registerLowerings(runtimeConfig, options, factories, providers, snippetReflection, lowerings, hosted));
    } catch (Throwable e) {
        throw debug.handle(e);
    }
    SubstrateReplacements replacements = (SubstrateReplacements) providers.getReplacements();
    assert checkInvocationPluginMethods(replacements);
    replacements.encodeSnippets();
}
Also used : SubstrateForeignCallDescriptor(com.oracle.svm.core.snippets.SnippetRuntime.SubstrateForeignCallDescriptor) HostedOptionValues(com.oracle.svm.core.option.HostedOptionValues) RuntimeOptionValues(com.oracle.svm.core.option.RuntimeOptionValues) OptionValues(org.graalvm.compiler.options.OptionValues) SubstrateLoweringProvider(com.oracle.svm.core.graal.meta.SubstrateLoweringProvider) DebugHandlersFactory(org.graalvm.compiler.debug.DebugHandlersFactory) GraalDebugHandlersFactory(org.graalvm.compiler.printer.GraalDebugHandlersFactory) DebugDumpScope(org.graalvm.compiler.debug.DebugDumpScope) StackValueNode(com.oracle.svm.core.graal.stackvalue.StackValueNode) Node(org.graalvm.compiler.graph.Node) SubstrateForeignCallsProvider(com.oracle.svm.core.graal.meta.SubstrateForeignCallsProvider) SubstrateForeignCallLinkage(com.oracle.svm.core.graal.meta.SubstrateForeignCallLinkage) DebugContext(org.graalvm.compiler.debug.DebugContext) Providers(org.graalvm.compiler.phases.util.Providers) HostedProviders(com.oracle.graal.pointsto.meta.HostedProviders) GraalDebugHandlersFactory(org.graalvm.compiler.printer.GraalDebugHandlersFactory) SubstrateReplacements(com.oracle.svm.core.graal.meta.SubstrateReplacements) NodeLoweringProvider(com.oracle.svm.core.graal.snippets.NodeLoweringProvider)

Example 4 with GraalDebugHandlersFactory

use of org.graalvm.compiler.printer.GraalDebugHandlersFactory in project graal by oracle.

the class NativeImageGeneratorRunner method buildImage.

@SuppressWarnings("try")
private int buildImage(String[] arguments, String[] classpath, ClassLoader classLoader) {
    if (!verifyValidJavaVersionAndPlatform()) {
        return -1;
    }
    Timer totalTimer = new Timer("[total]", false);
    ForkJoinPool analysisExecutor = null;
    ForkJoinPool compilationExecutor = null;
    try (StopTimer ignored = totalTimer.start()) {
        ImageClassLoader imageClassLoader;
        Timer classlistTimer = new Timer("classlist", false);
        try (StopTimer ignored1 = classlistTimer.start()) {
            imageClassLoader = ImageClassLoader.create(defaultPlatform(), classpath, classLoader);
        }
        HostedOptionParser optionParser = new HostedOptionParser(imageClassLoader);
        String[] remainingArgs = optionParser.parse(arguments);
        if (remainingArgs.length > 0) {
            throw UserError.abort("Unknown options: " + Arrays.toString(remainingArgs));
        }
        /*
             * We do not have the VMConfiguration and the HostedOptionValues set up yet, so we need
             * to pass the OptionValues explicitly when accessing options.
             */
        OptionValues parsedHostedOptions = new OptionValues(optionParser.getHostedValues());
        DebugContext debug = DebugContext.create(parsedHostedOptions, new GraalDebugHandlersFactory(GraalAccess.getOriginalSnippetReflection()));
        String imageName = NativeImageOptions.Name.getValue(parsedHostedOptions);
        if (imageName.length() == 0) {
            throw UserError.abort("No output file name specified. " + "Use '" + SubstrateOptionsParser.commandArgument(NativeImageOptions.Name, "<output-file>") + "'.");
        }
        // print the time here to avoid interactions with flags processing
        classlistTimer.print();
        Map<Method, CEntryPointData> entryPoints = new HashMap<>();
        Method mainEntryPoint = null;
        JavaMainSupport javaMainSupport = null;
        AbstractBootImage.NativeImageKind k = AbstractBootImage.NativeImageKind.valueOf(NativeImageOptions.Kind.getValue(parsedHostedOptions));
        if (k == AbstractBootImage.NativeImageKind.EXECUTABLE) {
            String className = NativeImageOptions.Class.getValue(parsedHostedOptions);
            if (className == null || className.length() == 0) {
                throw UserError.abort("Must specify main entry point class when building " + AbstractBootImage.NativeImageKind.EXECUTABLE + " native image. " + "Use '" + SubstrateOptionsParser.commandArgument(NativeImageOptions.Class, "<fully-qualified-class-name>") + "'.");
            }
            Class<?> mainClass;
            try {
                mainClass = Class.forName(className, false, classLoader);
            } catch (ClassNotFoundException ex) {
                throw UserError.abort("Main entry point class '" + className + "' not found.");
            }
            String mainEntryPointName = NativeImageOptions.Method.getValue(parsedHostedOptions);
            if (mainEntryPointName == null || mainEntryPointName.length() == 0) {
                throw UserError.abort("Must specify main entry point method when building " + AbstractBootImage.NativeImageKind.EXECUTABLE + " native image. " + "Use '" + SubstrateOptionsParser.commandArgument(NativeImageOptions.Method, "<method-name>") + "'.");
            }
            try {
                /* First look for an main method with the C-level signature for arguments. */
                mainEntryPoint = mainClass.getDeclaredMethod(mainEntryPointName, int.class, CCharPointerPointer.class);
            } catch (NoSuchMethodException ignored2) {
                try {
                    /*
                         * If no C-level main method was found, look for a Java-level main method
                         * and use our wrapper to invoke it.
                         */
                    Method javaMainMethod = mainClass.getDeclaredMethod(mainEntryPointName, String[].class);
                    javaMainMethod.setAccessible(true);
                    if (javaMainMethod.getReturnType() != void.class) {
                        throw UserError.abort("Java main method must have return type void. Change the return type of method '" + mainClass.getName() + "." + mainEntryPointName + "(String[])'.");
                    }
                    final int mainMethodModifiers = javaMainMethod.getModifiers();
                    if (!Modifier.isPublic(mainMethodModifiers)) {
                        throw UserError.abort("Method '" + mainClass.getName() + "." + mainEntryPointName + "(String[])' is not accessible.  Please make it 'public'.");
                    }
                    javaMainSupport = new JavaMainSupport(javaMainMethod);
                    mainEntryPoint = JavaMainWrapper.class.getDeclaredMethod("run", int.class, CCharPointerPointer.class);
                } catch (NoSuchMethodException ex) {
                    throw UserError.abort("Method '" + mainClass.getName() + "." + mainEntryPointName + "' is declared as the main entry point but it can not be found. " + "Make sure that class '" + mainClass.getName() + "' is on the classpath and that method '" + mainEntryPointName + "(String[])' exists in that class.");
                }
            }
            CEntryPoint annotation = mainEntryPoint.getAnnotation(CEntryPoint.class);
            if (annotation == null) {
                throw UserError.abort("Entry point must have the '@" + CEntryPoint.class.getSimpleName() + "' annotation");
            }
            entryPoints.put(mainEntryPoint, CEntryPointData.create(mainEntryPoint));
            Class<?>[] pt = mainEntryPoint.getParameterTypes();
            if (pt.length != 2 || pt[0] != int.class || pt[1] != CCharPointerPointer.class || mainEntryPoint.getReturnType() != int.class) {
                throw UserError.abort("Main entry point must have signature 'int main(int argc, CCharPointerPointer argv)'.");
            }
        }
        int maxConcurrentThreads = NativeImageOptions.getMaximumNumberOfConcurrentThreads(parsedHostedOptions);
        analysisExecutor = Inflation.createExecutor(debug, NativeImageOptions.getMaximumNumberOfAnalysisThreads(parsedHostedOptions));
        compilationExecutor = Inflation.createExecutor(debug, maxConcurrentThreads);
        generator = new NativeImageGenerator(imageClassLoader, optionParser);
        generator.run(entryPoints, mainEntryPoint, javaMainSupport, imageName, k, SubstitutionProcessor.IDENTITY, analysisExecutor, compilationExecutor, optionParser.getRuntimeOptionNames());
    } catch (InterruptImageBuilding e) {
        if (analysisExecutor != null) {
            analysisExecutor.shutdownNow();
        }
        if (compilationExecutor != null) {
            compilationExecutor.shutdownNow();
        }
        e.getReason().ifPresent(NativeImageGeneratorRunner::info);
        return 0;
    } catch (UserException e) {
        e.getMessages().iterator().forEachRemaining(NativeImageGeneratorRunner::reportUserError);
        return -1;
    } catch (AnalysisError e) {
        NativeImageGeneratorRunner.reportUserError(e.getMessage());
        return -1;
    } catch (ParallelExecutionException pee) {
        boolean hasUserError = false;
        for (Throwable exception : pee.getExceptions()) {
            if (exception instanceof UserException) {
                ((UserException) exception).getMessages().iterator().forEachRemaining(NativeImageGeneratorRunner::reportUserError);
                hasUserError = true;
            } else if (exception instanceof AnalysisError) {
                NativeImageGeneratorRunner.reportUserError(exception.getMessage());
                hasUserError = true;
            }
        }
        if (hasUserError) {
            return -1;
        }
        if (pee.getExceptions().size() > 1) {
            System.err.println(pee.getExceptions().size() + " fatal errors detected:");
        }
        for (Throwable exception : pee.getExceptions()) {
            NativeImageGeneratorRunner.reportFatalError(exception);
        }
        return -1;
    } catch (Throwable e) {
        NativeImageGeneratorRunner.reportFatalError(e);
        return -1;
    }
    totalTimer.print();
    return 0;
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) HashMap(java.util.HashMap) AnalysisError(com.oracle.graal.pointsto.util.AnalysisError) AbstractBootImage(com.oracle.svm.hosted.image.AbstractBootImage) HostedOptionParser(com.oracle.svm.hosted.option.HostedOptionParser) CEntryPointData(com.oracle.svm.hosted.code.CEntryPointData) ParallelExecutionException(com.oracle.graal.pointsto.util.ParallelExecutionException) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) InterruptImageBuilding(com.oracle.svm.core.util.InterruptImageBuilding) UserException(com.oracle.svm.core.util.UserError.UserException) DebugContext(org.graalvm.compiler.debug.DebugContext) Method(java.lang.reflect.Method) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) GraalDebugHandlersFactory(org.graalvm.compiler.printer.GraalDebugHandlersFactory) JavaMainSupport(com.oracle.svm.core.JavaMainWrapper.JavaMainSupport) StopTimer(com.oracle.graal.pointsto.util.Timer.StopTimer) Timer(com.oracle.graal.pointsto.util.Timer) StopTimer(com.oracle.graal.pointsto.util.Timer.StopTimer) CCharPointerPointer(org.graalvm.nativeimage.c.type.CCharPointerPointer) ForkJoinPool(java.util.concurrent.ForkJoinPool)

Example 5 with GraalDebugHandlersFactory

use of org.graalvm.compiler.printer.GraalDebugHandlersFactory in project graal by oracle.

the class HotSpotTruffleCompilerImpl method getDebugHandlerFactories.

private List<DebugHandlersFactory> getDebugHandlerFactories() {
    if (factories == null) {
        // Multiple initialization by racing threads is harmless
        List<DebugHandlersFactory> list = new ArrayList<>();
        list.add(new GraalDebugHandlersFactory(snippetReflection));
        for (DebugHandlersFactory factory : DebugHandlersFactory.LOADER) {
            // Ignore other instances of GraalDebugHandlersFactory
            if (!(factory instanceof GraalDebugHandlersFactory)) {
                list.add(factory);
            }
        }
        factories = list;
    }
    return factories;
}
Also used : DebugHandlersFactory(org.graalvm.compiler.debug.DebugHandlersFactory) GraalDebugHandlersFactory(org.graalvm.compiler.printer.GraalDebugHandlersFactory) ArrayList(java.util.ArrayList) GraalDebugHandlersFactory(org.graalvm.compiler.printer.GraalDebugHandlersFactory)

Aggregations

GraalDebugHandlersFactory (org.graalvm.compiler.printer.GraalDebugHandlersFactory)8 DebugContext (org.graalvm.compiler.debug.DebugContext)6 OptionValues (org.graalvm.compiler.options.OptionValues)5 HostedProviders (com.oracle.graal.pointsto.meta.HostedProviders)2 Timer (com.oracle.graal.pointsto.util.Timer)2 StopTimer (com.oracle.graal.pointsto.util.Timer.StopTimer)2 SubstrateForeignCallsProvider (com.oracle.svm.core.graal.meta.SubstrateForeignCallsProvider)2 SubstrateLoweringProvider (com.oracle.svm.core.graal.meta.SubstrateLoweringProvider)2 SubstrateReplacements (com.oracle.svm.core.graal.meta.SubstrateReplacements)2 NodeLoweringProvider (com.oracle.svm.core.graal.snippets.NodeLoweringProvider)2 HostedOptionValues (com.oracle.svm.core.option.HostedOptionValues)2 RuntimeOptionValues (com.oracle.svm.core.option.RuntimeOptionValues)2 InterruptImageBuilding (com.oracle.svm.core.util.InterruptImageBuilding)2 ArrayList (java.util.ArrayList)2 DebugHandlersFactory (org.graalvm.compiler.debug.DebugHandlersFactory)2 Indent (org.graalvm.compiler.debug.Indent)2 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)2 AnalysisPolicy (com.oracle.graal.pointsto.AnalysisPolicy)1 UnsupportedFeatureException (com.oracle.graal.pointsto.constraints.UnsupportedFeatureException)1 SubstitutionProcessor (com.oracle.graal.pointsto.infrastructure.SubstitutionProcessor)1