Search in sources :

Example 16 with Builder

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

the class IsolatedGraalUtils method compileInNewIsolate.

public static void compileInNewIsolate(SubstrateMethod method) {
    if (SubstrateOptions.shouldCompileInIsolates()) {
        CompilerIsolateThread context = createCompilationIsolate();
        IsolatedCompileClient.set(new IsolatedCompileClient(context));
        compileInNewIsolate0(context, (ClientIsolateThread) CurrentIsolate.getCurrentThread(), ImageHeapObjects.ref(method));
        Isolates.tearDownIsolate(context);
        IsolatedCompileClient.set(null);
    } else {
        try (DebugContext debug = new Builder(RuntimeOptionValues.singleton(), new GraalDebugHandlersFactory(GraalSupport.getRuntimeConfig().getSnippetReflection())).build()) {
            SubstrateGraalUtils.compile(debug, method);
        }
    }
}
Also used : Builder(org.graalvm.compiler.debug.DebugContext.Builder) DebugContext(org.graalvm.compiler.debug.DebugContext) GraalDebugHandlersFactory(org.graalvm.compiler.printer.GraalDebugHandlersFactory)

Example 17 with Builder

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

the class CheckGraalInvariants method runTest.

@SuppressWarnings("try")
public static void runTest(InvariantsTool tool) {
    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());
    String bootclasspath = tool.getClassPath();
    Assert.assertNotNull("Cannot find boot class path", bootclasspath);
    final List<String> classNames = new ArrayList<>();
    for (String path : bootclasspath.split(File.pathSeparator)) {
        if (tool.shouldProcess(path)) {
            try {
                if (path.equals(JRT_CLASS_PATH_ENTRY)) {
                    for (String className : ModuleSupport.getJRTGraalClassNames()) {
                        if (isGSON(className)) {
                            continue;
                        }
                        classNames.add(className);
                    }
                } else {
                    File file = new File(path);
                    if (!file.exists()) {
                        continue;
                    }
                    if (file.isDirectory()) {
                        Path root = file.toPath();
                        Files.walk(root).forEach(p -> {
                            String name = root.relativize(p).toString();
                            if (name.endsWith(".class") && !name.startsWith("META-INF/versions/")) {
                                String className = name.substring(0, name.length() - ".class".length()).replace('/', '.');
                                if (!(isInNativeImage(className) || isGSON(className))) {
                                    classNames.add(className);
                                }
                            }
                        });
                    } else {
                        final ZipFile zipFile = new ZipFile(file);
                        for (final Enumeration<? extends ZipEntry> entry = zipFile.entries(); entry.hasMoreElements(); ) {
                            final ZipEntry zipEntry = entry.nextElement();
                            String name = zipEntry.getName();
                            if (name.endsWith(".class") && !name.startsWith("META-INF/versions/")) {
                                String className = name.substring(0, name.length() - ".class".length()).replace('/', '.');
                                if (isInNativeImage(className) || isGSON(className)) {
                                    continue;
                                }
                                classNames.add(className);
                            }
                        }
                    }
                }
            } catch (IOException ex) {
                throw new AssertionError(ex);
            }
        }
    }
    Assert.assertFalse("Could not find graal jars on boot class path: " + bootclasspath, classNames.isEmpty());
    // Allows a subset of methods to be checked through use of a system property
    String property = System.getProperty(CheckGraalInvariants.class.getName() + ".filters");
    String[] filters = property == null ? null : property.split(",");
    OptionValues options = getInitialOptions();
    CompilerThreadFactory factory = new CompilerThreadFactory("CheckInvariantsThread");
    int availableProcessors = Runtime.getRuntime().availableProcessors();
    ThreadPoolExecutor executor = new ThreadPoolExecutor(availableProcessors, availableProcessors, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), factory);
    List<String> errors = Collections.synchronizedList(new ArrayList<>());
    List<VerifyPhase<CoreProviders>> verifiers = new ArrayList<>();
    // If you add a new type to test here, be sure to add appropriate
    // methods to the BadUsageWithEquals class below
    verifiers.add(new VerifyUsageWithEquals(Value.class));
    verifiers.add(new VerifyUsageWithEquals(Register.class));
    verifiers.add(new VerifyUsageWithEquals(RegisterCategory.class));
    verifiers.add(new VerifyUsageWithEquals(JavaType.class));
    verifiers.add(new VerifyUsageWithEquals(JavaMethod.class));
    verifiers.add(new VerifyUsageWithEquals(JavaField.class));
    verifiers.add(new VerifyUsageWithEquals(LocationIdentity.class));
    verifiers.add(new VerifyUsageWithEquals(LIRKind.class));
    verifiers.add(new VerifyUsageWithEquals(ArithmeticOpTable.class));
    verifiers.add(new VerifyUsageWithEquals(ArithmeticOpTable.Op.class));
    verifiers.add(new VerifyDebugUsage());
    verifiers.add(new VerifyVirtualizableUsage());
    verifiers.add(new VerifyUpdateUsages());
    verifiers.add(new VerifyBailoutUsage());
    verifiers.add(new VerifySystemPropertyUsage());
    verifiers.add(new VerifyInstanceOfUsage());
    verifiers.add(new VerifyGraphAddUsage());
    verifiers.add(new VerifyGetOptionsUsage());
    verifiers.add(new VerifyUnsafeAccess());
    verifiers.add(new VerifyVariableCasts());
    verifiers.add(new VerifyIterableNodeType());
    verifiers.add(new VerifyArchUsageInPlugins());
    verifiers.add(new VerifyStatelessPhases());
    loadVerifiers(verifiers);
    VerifyFoldableMethods foldableMethodsVerifier = new VerifyFoldableMethods();
    if (tool.shouldVerifyFoldableMethods()) {
        verifiers.add(foldableMethodsVerifier);
    }
    tool.updateVerifiers(verifiers);
    for (Method m : BadUsageWithEquals.class.getDeclaredMethods()) {
        ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
        try (DebugContext debug = new Builder(options).build()) {
            StructuredGraph graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.YES).method(method).build();
            try (DebugCloseable s = debug.disableIntercept();
                DebugContext.Scope ds = debug.scope("CheckingGraph", graph, method)) {
                graphBuilderSuite.apply(graph, context);
                // update phi stamps
                graph.getNodes().filter(PhiNode.class).forEach(PhiNode::inferStamp);
                checkGraph(verifiers, context, graph);
                errors.add(String.format("Expected error while checking %s", m));
            } catch (VerificationError e) {
            // expected!
            } catch (Throwable e) {
                errors.add(String.format("Error while checking %s:%n%s", m, printStackTraceToString(e)));
            }
        }
    }
    Map<ResolvedJavaField, Set<ResolvedJavaMethod>> optionFieldUsages = initOptionFieldUsagesMap(tool, metaAccess, errors);
    ResolvedJavaType optionDescriptorsType = metaAccess.lookupJavaType(OptionDescriptors.class);
    if (errors.isEmpty()) {
        // Order outer classes before the inner classes
        classNames.sort((String a, String b) -> a.compareTo(b));
        // Initialize classes in single thread to avoid deadlocking issues during initialization
        List<Class<?>> classes = initializeClasses(tool, classNames);
        for (Class<?> c : classes) {
            String className = c.getName();
            executor.execute(() -> {
                try {
                    checkClass(c, metaAccess, verifiers);
                } catch (Throwable e) {
                    errors.add(String.format("Error while checking %s:%n%s", className, printStackTraceToString(e)));
                }
            });
            ResolvedJavaType type = metaAccess.lookupJavaType(c);
            List<ResolvedJavaMethod> methods = new ArrayList<>();
            try {
                methods.addAll(Arrays.asList(type.getDeclaredMethods()));
                methods.addAll(Arrays.asList(type.getDeclaredConstructors()));
            } catch (Throwable e) {
                errors.add(String.format("Error while checking %s:%n%s", className, printStackTraceToString(e)));
            }
            ResolvedJavaMethod clinit = type.getClassInitializer();
            if (clinit != null) {
                methods.add(clinit);
            }
            for (ResolvedJavaMethod method : methods) {
                if (Modifier.isNative(method.getModifiers()) || Modifier.isAbstract(method.getModifiers())) {
                // ignore
                } else {
                    String methodName = className + "." + method.getName();
                    if (matches(filters, methodName)) {
                        executor.execute(() -> {
                            try (DebugContext debug = new Builder(options).build()) {
                                boolean isSubstitution = method.getAnnotation(Snippet.class) != null;
                                StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).setIsSubstitution(isSubstitution).build();
                                try (DebugCloseable s = debug.disableIntercept();
                                    DebugContext.Scope ds = debug.scope("CheckingGraph", graph, method)) {
                                    checkMethod(method);
                                    graphBuilderSuite.apply(graph, context);
                                    // update phi stamps
                                    graph.getNodes().filter(PhiNode.class).forEach(PhiNode::inferStamp);
                                    collectOptionFieldUsages(optionFieldUsages, optionDescriptorsType, method, graph);
                                    checkGraph(verifiers, context, graph);
                                } catch (VerificationError e) {
                                    errors.add(e.getMessage());
                                } catch (LinkageError e) {
                                // suppress linkages errors resulting from eager resolution
                                } catch (BailoutException e) {
                                // Graal bail outs on certain patterns in Java bytecode
                                // (e.g.,
                                // unbalanced monitors introduced by jacoco).
                                } catch (Throwable e) {
                                    try {
                                        tool.handleParsingException(e);
                                    } catch (Throwable t) {
                                        errors.add(String.format("Error while checking %s:%n%s", methodName, printStackTraceToString(e)));
                                    }
                                }
                            }
                        });
                    }
                }
            }
        }
        executor.shutdown();
        try {
            executor.awaitTermination(1, TimeUnit.HOURS);
        } catch (InterruptedException e1) {
            throw new RuntimeException(e1);
        }
        if (tool.shouldVerifyFoldableMethods()) {
            try {
                foldableMethodsVerifier.finish();
            } catch (Throwable e) {
                errors.add(e.getMessage());
            }
        }
    }
    checkOptionFieldUsages(errors, optionFieldUsages);
    if (!errors.isEmpty()) {
        StringBuilder msg = new StringBuilder();
        String nl = String.format("%n");
        for (String e : errors) {
            if (msg.length() != 0) {
                msg.append(nl);
            }
            msg.append(e);
        }
        Assert.fail(msg.toString());
    }
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) VerificationError(org.graalvm.compiler.phases.VerifyPhase.VerificationError) Builder(org.graalvm.compiler.debug.DebugContext.Builder) ArrayList(java.util.ArrayList) VerifyPhase(org.graalvm.compiler.phases.VerifyPhase) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) JavaField(jdk.vm.ci.meta.JavaField) JavaMethod(jdk.vm.ci.meta.JavaMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) LocationIdentity(org.graalvm.word.LocationIdentity) InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) PhiNode(org.graalvm.compiler.nodes.PhiNode) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) Method(java.lang.reflect.Method) JavaMethod(jdk.vm.ci.meta.JavaMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) DebugContext(org.graalvm.compiler.debug.DebugContext) Snippet(org.graalvm.compiler.api.replacements.Snippet) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) Value(jdk.vm.ci.meta.Value) NodeClass(org.graalvm.compiler.graph.NodeClass) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) LIRKind(org.graalvm.compiler.core.common.LIRKind) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) ZipFile(java.util.zip.ZipFile) File(java.io.File) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) CompilerThreadFactory(org.graalvm.compiler.core.CompilerThreadFactory) Set(java.util.Set) HashSet(java.util.HashSet) ZipEntry(java.util.zip.ZipEntry) RuntimeProvider(org.graalvm.compiler.runtime.RuntimeProvider) CoreProviders(org.graalvm.compiler.nodes.spi.CoreProviders) Providers(org.graalvm.compiler.phases.util.Providers) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) ArithmeticOpTable(org.graalvm.compiler.core.common.type.ArithmeticOpTable) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GraphBuilderPhase(org.graalvm.compiler.java.GraphBuilderPhase) InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) Plugins(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins) Path(java.nio.file.Path) RegisterCategory(jdk.vm.ci.code.Register.RegisterCategory) IOException(java.io.IOException) BailoutException(jdk.vm.ci.code.BailoutException) ZipFile(java.util.zip.ZipFile) Register(jdk.vm.ci.code.Register) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) PhaseSuite(org.graalvm.compiler.phases.PhaseSuite) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 18 with Builder

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

the class NativeImageGenerator method doRun.

@SuppressWarnings("try")
private void doRun(Map<Method, CEntryPointData> entryPoints, JavaMainSupport javaMainSupport, String imageName, NativeImageKind k, SubstitutionProcessor harnessSubstitutions, ForkJoinPool compilationExecutor, ForkJoinPool analysisExecutor) {
    List<HostedMethod> hostedEntryPoints = new ArrayList<>();
    OptionValues options = HostedOptionValues.singleton();
    SnippetReflectionProvider originalSnippetReflection = GraalAccess.getOriginalSnippetReflection();
    try (DebugContext debug = new Builder(options, new GraalDebugHandlersFactory(originalSnippetReflection)).build();
        DebugCloseable featureCleanup = () -> featureHandler.forEachFeature(Feature::cleanup)) {
        setupNativeImage(imageName, options, entryPoints, javaMainSupport, harnessSubstitutions, analysisExecutor, originalSnippetReflection, debug);
        reporter.printFeatures(featureHandler.getUserFeatureNames());
        boolean returnAfterAnalysis = runPointsToAnalysis(imageName, options, debug);
        if (returnAfterAnalysis) {
            return;
        }
        NativeImageHeap heap;
        HostedMetaAccess hMetaAccess;
        SharedRuntimeConfigurationBuilder runtime;
        try (ReporterClosable c = reporter.printUniverse()) {
            bb.getHeartbeatCallback().run();
            hUniverse = new HostedUniverse(bb);
            hMetaAccess = new HostedMetaAccess(hUniverse, bb.getMetaAccess());
            ((SVMImageHeapScanner) aUniverse.getHeapScanner()).setHostedMetaAccess(hMetaAccess);
            BeforeUniverseBuildingAccessImpl beforeUniverseBuildingConfig = new BeforeUniverseBuildingAccessImpl(featureHandler, loader, debug, hMetaAccess);
            featureHandler.forEachFeature(feature -> feature.beforeUniverseBuilding(beforeUniverseBuildingConfig));
            new UniverseBuilder(aUniverse, bb.getMetaAccess(), hUniverse, hMetaAccess, HostedConfiguration.instance().createStaticAnalysisResultsBuilder(bb, hUniverse), bb.getUnsupportedFeatures()).build(debug);
            BuildPhaseProvider.markHostedUniverseBuilt();
            ClassInitializationSupport classInitializationSupport = bb.getHostVM().getClassInitializationSupport();
            runtime = new HostedRuntimeConfigurationBuilder(options, bb.getHostVM(), hUniverse, hMetaAccess, bb.getProviders(), nativeLibraries, classInitializationSupport, GraalAccess.getOriginalProviders().getLoopsDataProvider()).build();
            registerGraphBuilderPlugins(featureHandler, runtime.getRuntimeConfig(), (HostedProviders) runtime.getRuntimeConfig().getProviders(), bb.getMetaAccess(), aUniverse, hMetaAccess, hUniverse, nativeLibraries, loader, ParsingReason.AOTCompilation, bb.getAnnotationSubstitutionProcessor(), new SubstrateClassInitializationPlugin((SVMHost) aUniverse.hostVM()), classInitializationSupport, ConfigurationValues.getTarget());
            if (NativeImageOptions.PrintUniverse.getValue()) {
                printTypes();
            }
            /* Find the entry point methods in the hosted world. */
            for (AnalysisMethod m : aUniverse.getMethods()) {
                if (m.isEntryPoint()) {
                    HostedMethod found = hUniverse.lookup(m);
                    assert found != null;
                    hostedEntryPoints.add(found);
                }
            }
            if (hostedEntryPoints.size() == 0) {
                throw UserError.abort("Warning: no entry points found, i.e., no method annotated with @%s", CEntryPoint.class.getSimpleName());
            }
            bb.getUnsupportedFeatures().report(bb);
            recordRestrictHeapAccessCallees(aUniverse.getMethods());
            /*
                 * After this point, all TypeFlow (and therefore also TypeState) objects are
                 * unreachable and can be garbage collected. This is important to keep the overall
                 * memory footprint low. However, this also means we no longer have complete call
                 * chain information. Only the summarized information stored in the
                 * StaticAnalysisResult objects is available after this point.
                 */
            bb.cleanupAfterAnalysis();
        } catch (UnsupportedFeatureException ufe) {
            throw FallbackFeature.reportAsFallback(ufe);
        }
        heap = new NativeImageHeap(aUniverse, hUniverse, hMetaAccess, ImageSingletons.lookup(ImageHeapLayouter.class));
        BeforeCompilationAccessImpl beforeCompilationConfig = new BeforeCompilationAccessImpl(featureHandler, loader, aUniverse, hUniverse, heap, debug, runtime);
        featureHandler.forEachFeature(feature -> feature.beforeCompilation(beforeCompilationConfig));
        runtime.updateLazyState(hMetaAccess);
        NativeImageCodeCache codeCache;
        CompileQueue compileQueue;
        try (StopTimer t = TimerCollection.createTimerAndStart(TimerCollection.Registry.COMPILE_TOTAL)) {
            compileQueue = HostedConfiguration.instance().createCompileQueue(debug, featureHandler, hUniverse, runtime, DeoptTester.enabled(), bb.getProviders().getSnippetReflection(), compilationExecutor);
            compileQueue.finish(debug);
            /* release memory taken by graphs for the image writing */
            hUniverse.getMethods().forEach(HostedMethod::clear);
            codeCache = NativeImageCodeCacheFactory.get().newCodeCache(compileQueue, heap, loader.platform, ImageSingletons.lookup(TemporaryBuildDirectoryProvider.class).getTemporaryBuildDirectory());
            codeCache.layoutConstants();
            codeCache.layoutMethods(debug, imageName, bb, compilationExecutor);
            AfterCompilationAccessImpl config = new AfterCompilationAccessImpl(featureHandler, loader, aUniverse, hUniverse, compileQueue.getCompilationTasks(), heap, debug, runtime);
            featureHandler.forEachFeature(feature -> feature.afterCompilation(config));
        }
        CodeCacheProvider codeCacheProvider = runtime.getRuntimeConfig().getBackendForNormalMethod().getProviders().getCodeCache();
        reporter.printCreationStart();
        try (Indent indent = debug.logAndIndent("create native image")) {
            try (DebugContext.Scope buildScope = debug.scope("CreateImage", codeCacheProvider)) {
                try (StopTimer t = TimerCollection.createTimerAndStart(TimerCollection.Registry.IMAGE)) {
                    bb.getHeartbeatCallback().run();
                    // Start building the model of the native image heap.
                    heap.addInitialObjects();
                    // Then build the model of the code cache, which can
                    // add objects to the native image heap.
                    codeCache.addConstantsToHeap();
                    // Finish building the model of the native image heap.
                    heap.addTrailingObjects();
                    AfterHeapLayoutAccessImpl config = new AfterHeapLayoutAccessImpl(featureHandler, loader, heap, hMetaAccess, debug);
                    featureHandler.forEachFeature(feature -> feature.afterHeapLayout(config));
                    this.image = AbstractImage.create(k, hUniverse, hMetaAccess, nativeLibraries, heap, codeCache, hostedEntryPoints, loader.getClassLoader());
                    image.build(imageName, debug);
                    if (NativeImageOptions.PrintUniverse.getValue()) {
                        /*
                             * This debug output must be printed _after_ and not _during_ image
                             * building, because it adds some PrintStream objects to static fields,
                             * which disrupts the heap.
                             */
                        codeCache.printCompilationResults();
                    }
                }
            } catch (Throwable e) {
                throw VMError.shouldNotReachHere(e);
            }
        }
        try (StopTimer t = TimerCollection.createTimerAndStart(TimerCollection.Registry.WRITE)) {
            bb.getHeartbeatCallback().run();
            BeforeImageWriteAccessImpl beforeConfig = new BeforeImageWriteAccessImpl(featureHandler, loader, imageName, image, runtime.getRuntimeConfig(), aUniverse, hUniverse, optionProvider, hMetaAccess, debug);
            featureHandler.forEachFeature(feature -> feature.beforeImageWrite(beforeConfig));
            /*
                 * This will write the debug info too -- i.e. we may be writing more than one file,
                 * if the debug info is in a separate file. We need to push writing the file to the
                 * image implementation, because whether the debug info and image share a file or
                 * not is an implementation detail of the image.
                 */
            Path tmpDir = ImageSingletons.lookup(TemporaryBuildDirectoryProvider.class).getTemporaryBuildDirectory();
            LinkerInvocation inv = image.write(debug, generatedFiles(HostedOptionValues.singleton()), tmpDir, imageName, beforeConfig);
            if (NativeImageOptions.ExitAfterRelocatableImageWrite.getValue()) {
                return;
            }
            AfterImageWriteAccessImpl afterConfig = new AfterImageWriteAccessImpl(featureHandler, loader, hUniverse, inv, tmpDir, image.getImageKind(), debug);
            featureHandler.forEachFeature(feature -> feature.afterImageWrite(afterConfig));
        }
        reporter.printCreationEnd(image.getImageSize(), bb.getUniverse(), heap.getObjectCount(), image.getImageHeapSize(), codeCache.getCodeCacheSize(), codeCache.getCompilations().size(), image.getDebugInfoSize());
        if (SubstrateOptions.BuildOutputBreakdowns.getValue()) {
            ProgressReporter.singleton().printBreakdowns(compileQueue.getCompilationTasks(), image.getHeap().getObjects());
        }
    }
}
Also used : Indent(org.graalvm.compiler.debug.Indent) HostedOptionValues(com.oracle.svm.core.option.HostedOptionValues) RuntimeOptionValues(com.oracle.svm.core.option.RuntimeOptionValues) OptionValues(org.graalvm.compiler.options.OptionValues) AfterCompilationAccessImpl(com.oracle.svm.hosted.FeatureImpl.AfterCompilationAccessImpl) AfterImageWriteAccessImpl(com.oracle.svm.hosted.FeatureImpl.AfterImageWriteAccessImpl) ReporterClosable(com.oracle.svm.hosted.ProgressReporter.ReporterClosable) HostedRuntimeConfigurationBuilder(com.oracle.svm.hosted.code.HostedRuntimeConfigurationBuilder) UniverseBuilder(com.oracle.svm.hosted.meta.UniverseBuilder) Builder(org.graalvm.compiler.debug.DebugContext.Builder) SharedRuntimeConfigurationBuilder(com.oracle.svm.hosted.code.SharedRuntimeConfigurationBuilder) BeforeImageWriteAccessImpl(com.oracle.svm.hosted.FeatureImpl.BeforeImageWriteAccessImpl) ArrayList(java.util.ArrayList) LinkerInvocation(com.oracle.svm.core.LinkerInvocation) BeforeUniverseBuildingAccessImpl(com.oracle.svm.hosted.FeatureImpl.BeforeUniverseBuildingAccessImpl) HostedRuntimeConfigurationBuilder(com.oracle.svm.hosted.code.HostedRuntimeConfigurationBuilder) CodeCacheProvider(jdk.vm.ci.code.CodeCacheProvider) LocalizationFeature(com.oracle.svm.hosted.jdk.localization.LocalizationFeature) ClassInitializationFeature(com.oracle.svm.hosted.classinitialization.ClassInitializationFeature) Feature(org.graalvm.nativeimage.hosted.Feature) SubstrateClassInitializationPlugin(com.oracle.svm.hosted.phases.SubstrateClassInitializationPlugin) SVMImageHeapScanner(com.oracle.svm.hosted.heap.SVMImageHeapScanner) SnippetReflectionProvider(org.graalvm.compiler.api.replacements.SnippetReflectionProvider) HostedSnippetReflectionProvider(com.oracle.svm.hosted.meta.HostedSnippetReflectionProvider) SubstrateSnippetReflectionProvider(com.oracle.svm.core.graal.meta.SubstrateSnippetReflectionProvider) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) Path(java.nio.file.Path) CompileQueue(com.oracle.svm.hosted.code.CompileQueue) UnsupportedFeatureException(com.oracle.graal.pointsto.constraints.UnsupportedFeatureException) AfterHeapLayoutAccessImpl(com.oracle.svm.hosted.FeatureImpl.AfterHeapLayoutAccessImpl) NativeImageHeap(com.oracle.svm.hosted.image.NativeImageHeap) NativeImageCodeCache(com.oracle.svm.hosted.image.NativeImageCodeCache) DebugContext(org.graalvm.compiler.debug.DebugContext) HostedUniverse(com.oracle.svm.hosted.meta.HostedUniverse) HostedMetaAccess(com.oracle.svm.hosted.meta.HostedMetaAccess) SharedRuntimeConfigurationBuilder(com.oracle.svm.hosted.code.SharedRuntimeConfigurationBuilder) GraalDebugHandlersFactory(org.graalvm.compiler.printer.GraalDebugHandlersFactory) UniverseBuilder(com.oracle.svm.hosted.meta.UniverseBuilder) AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) PointsToAnalysisMethod(com.oracle.graal.pointsto.meta.PointsToAnalysisMethod) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) StopTimer(com.oracle.graal.pointsto.util.Timer.StopTimer) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) ClassInitializationSupport(com.oracle.svm.hosted.classinitialization.ClassInitializationSupport) RuntimeClassInitializationSupport(org.graalvm.nativeimage.impl.RuntimeClassInitializationSupport) TemporaryBuildDirectoryProvider(com.oracle.svm.core.c.libc.TemporaryBuildDirectoryProvider) BeforeCompilationAccessImpl(com.oracle.svm.hosted.FeatureImpl.BeforeCompilationAccessImpl)

Example 19 with Builder

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

the class IsolatedGraalUtils method compileInNewIsolateAndInstall0.

@CEntryPoint(include = CEntryPoint.NotIncludedAutomatically.class)
@CEntryPointOptions(publishAs = CEntryPointOptions.Publish.NotPublished)
private static ClientHandle<SubstrateInstalledCode> compileInNewIsolateAndInstall0(@SuppressWarnings("unused") @CEntryPoint.IsolateThreadContext CompilerIsolateThread isolate, ClientIsolateThread clientIsolate, ImageHeapRef<SubstrateMethod> methodRef) {
    IsolatedCompileContext.set(new IsolatedCompileContext(clientIsolate));
    SubstrateMethod method = ImageHeapObjects.deref(methodRef);
    DebugContext debug = new Builder(RuntimeOptionValues.singleton(), new GraalDebugHandlersFactory(GraalSupport.getRuntimeConfig().getSnippetReflection())).build();
    CompilationResult compilationResult = SubstrateGraalUtils.doCompile(debug, GraalSupport.getRuntimeConfig(), GraalSupport.getSuites(), GraalSupport.getLIRSuites(), method);
    ClientHandle<SubstrateInstalledCode> installedCodeHandle = IsolatedRuntimeCodeInstaller.installInClientIsolate(methodRef, compilationResult, IsolatedHandles.nullHandle());
    Log.log().string("Code for " + method.format("%H.%n(%p)") + ": " + compilationResult.getTargetCodeSize() + " bytes").newline();
    IsolatedCompileContext.set(null);
    return installedCodeHandle;
}
Also used : SubstrateMethod(com.oracle.svm.graal.meta.SubstrateMethod) Builder(org.graalvm.compiler.debug.DebugContext.Builder) SubstrateInstalledCode(com.oracle.svm.core.deopt.SubstrateInstalledCode) DebugContext(org.graalvm.compiler.debug.DebugContext) CompilationResult(org.graalvm.compiler.code.CompilationResult) GraalDebugHandlersFactory(org.graalvm.compiler.printer.GraalDebugHandlersFactory) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Example 20 with Builder

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

the class IsolatedGraalUtils method createCompilationIsolate.

public static CompilerIsolateThread createCompilationIsolate() {
    CreateIsolateParameters.Builder builder = new CreateIsolateParameters.Builder();
    long addressSpaceSize = SubstrateOptions.CompilationIsolateAddressSpaceSize.getValue();
    if (addressSpaceSize > 0) {
        builder.reservedAddressSpaceSize(WordFactory.signed(addressSpaceSize));
    }
    // Compilation isolates do the reference handling manually to avoid the extra thread.
    builder.appendArgument(getOptionString(SubstrateOptions.ConcealedOptions.AutomaticReferenceHandling, false));
    CreateIsolateParameters params = builder.build();
    CompilerIsolateThread isolate = (CompilerIsolateThread) Isolates.createIsolate(params);
    initializeCompilationIsolate(isolate);
    return isolate;
}
Also used : CreateIsolateParameters(org.graalvm.nativeimage.Isolates.CreateIsolateParameters) Builder(org.graalvm.compiler.debug.DebugContext.Builder)

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