Search in sources :

Example 1 with NodeClass

use of org.graalvm.compiler.graph.NodeClass in project graal by oracle.

the class FieldsOffsetsFeature method registerFields.

private static void registerFields(FieldIntrospection<?> introspection, BeforeAnalysisAccessImpl config) {
    if (introspection instanceof NodeClass<?>) {
        NodeClass<?> nodeClass = (NodeClass<?>) introspection;
        Fields dataFields = nodeClass.getData();
        registerFields(dataFields, DefaultUnsafePartition.get(), config);
        Fields inputEdges = nodeClass.getInputEdges();
        registerFields(inputEdges, GraalEdgeUnsafePartition.get(), config);
        Fields successorEdges = nodeClass.getSuccessorEdges();
        registerFields(successorEdges, GraalEdgeUnsafePartition.get(), config);
        /* Ensure field shortName is initialized, so that the instance is immutable. */
        nodeClass.shortName();
    } else {
        for (Fields fields : introspection.getAllFields()) {
            registerFields(fields, DefaultUnsafePartition.get(), config);
        }
    }
}
Also used : NodeClass(org.graalvm.compiler.graph.NodeClass) Fields(org.graalvm.compiler.core.common.Fields)

Example 2 with NodeClass

use of org.graalvm.compiler.graph.NodeClass in project graal by oracle.

the class RuntimeStrengthenStampsPhase method duringAnalysis.

@Override
public void duringAnalysis(DuringAnalysisAccess c) {
    DuringAnalysisAccessImpl config = (DuringAnalysisAccessImpl) c;
    GraalSupport.registerPhaseStatistics(config);
    Deque<CallTreeNode> worklist = new ArrayDeque<>();
    worklist.addAll(methods.values());
    while (!worklist.isEmpty()) {
        processMethod(worklist.removeFirst(), worklist, config.getBigBang());
    }
    SubstrateMethod[] methodsToCompileArr = new SubstrateMethod[methods.size()];
    int idx = 0;
    for (CallTreeNode node : methods.values()) {
        methodsToCompileArr[idx++] = objectReplacer.createMethod(node.implementationMethod);
    }
    if (GraalSupport.setMethodsToCompile(methodsToCompileArr)) {
        config.requireAnalysisIteration();
    }
    graphEncoder.finishPrepare();
    AnalysisMetaAccess metaAccess = config.getMetaAccess();
    NodeClass<?>[] nodeClasses = graphEncoder.getNodeClasses();
    for (NodeClass<?> nodeClass : nodeClasses) {
        metaAccess.lookupJavaType(nodeClass.getClazz()).registerAsAllocated(null);
    }
    if (GraalSupport.setGraphEncoding(graphEncoder.getEncoding(), graphEncoder.getObjects(), nodeClasses)) {
        config.requireAnalysisIteration();
    }
    if (objectReplacer.updateDataDuringAnalysis(config.getMetaAccess())) {
        config.requireAnalysisIteration();
    }
}
Also used : SubstrateMethod(com.oracle.svm.graal.meta.SubstrateMethod) NodeClass(org.graalvm.compiler.graph.NodeClass) DuringAnalysisAccessImpl(com.oracle.svm.hosted.FeatureImpl.DuringAnalysisAccessImpl) AnalysisMetaAccess(com.oracle.graal.pointsto.meta.AnalysisMetaAccess) ArrayDeque(java.util.ArrayDeque)

Example 3 with NodeClass

use of org.graalvm.compiler.graph.NodeClass in project graal by oracle.

the class RuntimeStrengthenStampsPhase method beforeAnalysis.

@Override
public void beforeAnalysis(BeforeAnalysisAccess c) {
    BeforeAnalysisAccessImpl config = (BeforeAnalysisAccessImpl) c;
    GraalSupport.allocatePhaseStatisticsCache();
    populateMatchRuleRegistry();
    Function<Providers, Backend> backendProvider = GraalSupport.getRuntimeBackendProvider();
    Providers originalProviders = GraalAccess.getOriginalProviders();
    runtimeConfigBuilder = new SubstrateRuntimeConfigurationBuilder(RuntimeOptionValues.singleton(), config.getHostVM(), config.getUniverse(), config.getMetaAccess(), originalProviders.getConstantReflection(), backendProvider).build();
    RuntimeConfiguration runtimeConfig = runtimeConfigBuilder.getRuntimeConfig();
    Providers runtimeProviders = runtimeConfig.getProviders();
    WordTypes wordTypes = runtimeConfigBuilder.getWordTypes();
    hostedProviders = new HostedProviders(runtimeProviders.getMetaAccess(), runtimeProviders.getCodeCache(), runtimeProviders.getConstantReflection(), runtimeProviders.getConstantFieldProvider(), runtimeProviders.getForeignCalls(), runtimeProviders.getLowerer(), runtimeProviders.getReplacements(), runtimeProviders.getStampProvider(), runtimeConfig.getSnippetReflection(), wordTypes);
    SubstrateGraalRuntime graalRuntime = new SubstrateGraalRuntime();
    objectReplacer.setGraalRuntime(graalRuntime);
    ImageSingletons.add(GraalRuntime.class, graalRuntime);
    RuntimeSupport.getRuntimeSupport().addShutdownHook(new GraalSupport.GraalShutdownHook());
    FeatureHandler featureHandler = config.getFeatureHandler();
    NativeImageGenerator.registerGraphBuilderPlugins(featureHandler, runtimeConfig, hostedProviders, config.getMetaAccess(), config.getUniverse(), null, null, config.getNativeLibraries(), config.getImageClassLoader(), false, false);
    DebugContext debug = DebugContext.forCurrentThread();
    NativeImageGenerator.registerReplacements(debug, featureHandler, runtimeConfig, runtimeConfig.getProviders(), runtimeConfig.getSnippetReflection(), false);
    featureHandler.forEachGraalFeature(feature -> feature.registerCodeObserver(runtimeConfig));
    Suites suites = NativeImageGenerator.createSuites(featureHandler, runtimeConfig, runtimeConfig.getSnippetReflection(), false);
    LIRSuites lirSuites = NativeImageGenerator.createLIRSuites(featureHandler, runtimeConfig.getProviders(), false);
    GraalSupport.setRuntimeConfig(runtimeConfig, suites, lirSuites);
    NodeClass<?>[] snippetNodeClasses = ((SubstrateReplacements) runtimeProviders.getReplacements()).getSnippetNodeClasses();
    for (NodeClass<?> nodeClass : snippetNodeClasses) {
        config.getMetaAccess().lookupJavaType(nodeClass.getClazz()).registerAsAllocated(null);
    }
    /* Initialize configuration with reasonable default values. */
    graphBuilderConfig = GraphBuilderConfiguration.getDefault(hostedProviders.getGraphBuilderPlugins()).withBytecodeExceptionMode(BytecodeExceptionMode.ExplicitOnly);
    includeCalleePredicate = GraalFeature::defaultIncludeCallee;
    optimisticOpts = OptimisticOptimizations.ALL.remove(OptimisticOptimizations.Optimization.UseLoopLimitChecks);
    methods = new LinkedHashMap<>();
    graphEncoder = new GraphEncoder(ConfigurationValues.getTarget().arch);
    /*
         * Ensure that all snippet methods have their SubstrateMethod object created by the object
         * replacer, to avoid corner cases later when writing the native image.
         */
    for (ResolvedJavaMethod method : ((SubstrateReplacements) runtimeProviders.getReplacements()).getSnippetMethods()) {
        objectReplacer.apply(method);
    }
}
Also used : BeforeAnalysisAccessImpl(com.oracle.svm.hosted.FeatureImpl.BeforeAnalysisAccessImpl) SubstrateGraalRuntime(com.oracle.svm.graal.SubstrateGraalRuntime) GraalSupport(com.oracle.svm.graal.GraalSupport) WordTypes(org.graalvm.compiler.word.WordTypes) DebugContext(org.graalvm.compiler.debug.DebugContext) GraphEncoder(org.graalvm.compiler.nodes.GraphEncoder) HostedProviders(com.oracle.graal.pointsto.meta.HostedProviders) Providers(org.graalvm.compiler.phases.util.Providers) RuntimeConfiguration(com.oracle.svm.core.graal.meta.RuntimeConfiguration) HostedProviders(com.oracle.graal.pointsto.meta.HostedProviders) NodeClass(org.graalvm.compiler.graph.NodeClass) Backend(org.graalvm.compiler.core.target.Backend) SubstrateReplacements(com.oracle.svm.core.graal.meta.SubstrateReplacements) FeatureHandler(com.oracle.svm.hosted.FeatureHandler) SubstrateRuntimeConfigurationBuilder(com.oracle.svm.graal.meta.SubstrateRuntimeConfigurationBuilder) LIRSuites(org.graalvm.compiler.lir.phases.LIRSuites) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) LIRSuites(org.graalvm.compiler.lir.phases.LIRSuites) Suites(org.graalvm.compiler.phases.tiers.Suites)

Example 4 with NodeClass

use of org.graalvm.compiler.graph.NodeClass in project graal by oracle.

the class NodeCostDumpUtil method main.

public static void main(String[] args) {
    if (args.length != 1) {
        System.err.println("NodeCostDumpUtil expects exactly one argument, the node name regex to match against.");
        System.exit(-1);
    }
    final String pattern = getArgumentRegex(args[0]);
    String version = System.getProperty("java.specification.version");
    if (version.compareTo("1.9") >= 0) {
        System.err.printf("NodeCostDumpUtil does not support JDK versions greater than 1.8, current version is %s.\n", version);
        System.exit(-1);
    }
    String[] jvmciCP = System.getProperty("jvmci.class.path.append").split(File.pathSeparator);
    String[] primarySuiteCP = System.getProperty("primary.suite.cp").split(File.pathSeparator);
    ClassLoader applicationClassLoader = Thread.currentThread().getContextClassLoader();
    HashSet<Class<?>> classes = new HashSet<>();
    try {
        Set<String> uniquePaths = new HashSet<>(Arrays.asList(primarySuiteCP));
        uniquePaths.addAll(Arrays.asList(jvmciCP));
        for (String path : uniquePaths) {
            if (new File(path).exists()) {
                if (path.endsWith(".jar")) {
                    try (FileSystem jarFileSystem = FileSystems.newFileSystem(URI.create("jar:file:" + path), Collections.emptyMap())) {
                        initAllClasses(jarFileSystem.getPath("/"), applicationClassLoader, classes);
                    }
                } else {
                    initAllClasses(FileSystems.getDefault().getPath(path), applicationClassLoader, classes);
                }
            }
        }
    } catch (IOException ex) {
        GraalError.shouldNotReachHere();
    }
    System.err.printf("Loaded %d classes...\n", classes.size());
    List<Class<?>> nodeClasses = new ArrayList<>();
    for (Class<?> loaded : classes) {
        if (Node.class.isAssignableFrom(loaded) && !loaded.isArray()) {
            nodeClasses.add(loaded);
        }
    }
    System.err.printf("Loaded %s node classes...\n", nodeClasses.size());
    List<NodeClass<?>> nc = new ArrayList<>();
    for (Class<?> c : nodeClasses) {
        try {
            nc.add(NodeClass.get(c));
        } catch (Throwable t) {
        // Silently ignore problems here
        }
    }
    System.err.printf("Read TYPE field from %s node classes...\n", nc.size());
    nc = nc.stream().filter(x -> x != null).collect(Collectors.toList());
    nc.sort((x, y) -> {
        String a = x.getJavaClass().getName();
        String b = y.getJavaClass().getName();
        return a.compareTo(b);
    });
    CSVUtil.Escape.println(System.out, FMT, "NodeName", "Size", "Overrides Size Method", "Cycles", "Overrides Cycles Method", "Canonicalizable", "MemoryCheckPoint", "Virtualizable");
    for (NodeClass<?> nodeclass : nc) {
        String packageStrippedName = null;
        try {
            packageStrippedName = nodeclass.getJavaClass().getCanonicalName().replace(prefix1, "").replace(prefix2, "");
        } catch (Throwable t) {
            // do nothing
            continue;
        }
        if (pattern != null && !packageStrippedName.matches(pattern)) {
            continue;
        }
        boolean overridesSizeMethod = false;
        boolean overridesCyclesMethod = false;
        Class<?> c = nodeclass.getJavaClass();
        try {
            c.getDeclaredMethod("estimatedNodeSize");
            overridesSizeMethod = true;
        } catch (Throwable t) {
        // do nothing
        }
        try {
            c.getDeclaredMethod("estimatedNodeCycles");
            overridesCyclesMethod = true;
        } catch (Throwable t) {
        // do nothing
        }
        CSVUtil.Escape.println(System.out, FMT, packageStrippedName, nodeclass.size(), overridesSizeMethod, nodeclass.cycles(), overridesCyclesMethod, canonicalizable(c), memoryCheckPoint(c), virtualizable(c));
    }
}
Also used : Node(org.graalvm.compiler.graph.Node) ArrayList(java.util.ArrayList) IOException(java.io.IOException) NodeClass(org.graalvm.compiler.graph.NodeClass) FileSystem(java.nio.file.FileSystem) URLClassLoader(java.net.URLClassLoader) NodeClass(org.graalvm.compiler.graph.NodeClass) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

NodeClass (org.graalvm.compiler.graph.NodeClass)4 AnalysisMetaAccess (com.oracle.graal.pointsto.meta.AnalysisMetaAccess)1 HostedProviders (com.oracle.graal.pointsto.meta.HostedProviders)1 RuntimeConfiguration (com.oracle.svm.core.graal.meta.RuntimeConfiguration)1 SubstrateReplacements (com.oracle.svm.core.graal.meta.SubstrateReplacements)1 GraalSupport (com.oracle.svm.graal.GraalSupport)1 SubstrateGraalRuntime (com.oracle.svm.graal.SubstrateGraalRuntime)1 SubstrateMethod (com.oracle.svm.graal.meta.SubstrateMethod)1 SubstrateRuntimeConfigurationBuilder (com.oracle.svm.graal.meta.SubstrateRuntimeConfigurationBuilder)1 FeatureHandler (com.oracle.svm.hosted.FeatureHandler)1 BeforeAnalysisAccessImpl (com.oracle.svm.hosted.FeatureImpl.BeforeAnalysisAccessImpl)1 DuringAnalysisAccessImpl (com.oracle.svm.hosted.FeatureImpl.DuringAnalysisAccessImpl)1 File (java.io.File)1 IOException (java.io.IOException)1 URLClassLoader (java.net.URLClassLoader)1 FileSystem (java.nio.file.FileSystem)1 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1