Search in sources :

Example 11 with MetaAccessProvider

use of jdk.vm.ci.meta.MetaAccessProvider in project graal by oracle.

the class SnippetStub method getGraph.

@Override
@SuppressWarnings("try")
protected StructuredGraph getGraph(DebugContext debug, CompilationIdentifier compilationId) {
    Plugins defaultPlugins = providers.getGraphBuilderPlugins();
    MetaAccessProvider metaAccess = providers.getMetaAccess();
    SnippetReflectionProvider snippetReflection = providers.getSnippetReflection();
    Plugins plugins = new Plugins(defaultPlugins);
    plugins.prependParameterPlugin(new ConstantBindingParameterPlugin(makeConstArgs(), metaAccess, snippetReflection));
    GraphBuilderConfiguration config = GraphBuilderConfiguration.getSnippetDefault(plugins);
    // Stubs cannot have optimistic assumptions since they have
    // to be valid for the entire run of the VM.
    final StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).compilationId(compilationId).build();
    try (DebugContext.Scope outer = debug.scope("SnippetStub", graph)) {
        graph.disableUnsafeAccessTracking();
        IntrinsicContext initialIntrinsicContext = new IntrinsicContext(method, method, getReplacementsBytecodeProvider(), INLINE_AFTER_PARSING);
        GraphBuilderPhase.Instance instance = new GraphBuilderPhase.Instance(metaAccess, providers.getStampProvider(), providers.getConstantReflection(), providers.getConstantFieldProvider(), config, OptimisticOptimizations.NONE, initialIntrinsicContext);
        instance.apply(graph);
        for (ParameterNode param : graph.getNodes(ParameterNode.TYPE)) {
            int index = param.index();
            if (method.getParameterAnnotation(NonNullParameter.class, index) != null) {
                param.setStamp(param.stamp(NodeView.DEFAULT).join(StampFactory.objectNonNull()));
            }
        }
        new RemoveValueProxyPhase().apply(graph);
        graph.setGuardsStage(GuardsStage.FLOATING_GUARDS);
        CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
        PhaseContext context = new PhaseContext(providers);
        canonicalizer.apply(graph, context);
        new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    } catch (Throwable e) {
        throw debug.handle(e);
    }
    return graph;
}
Also used : RemoveValueProxyPhase(org.graalvm.compiler.phases.common.RemoveValueProxyPhase) IntrinsicContext(org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) DebugContext(org.graalvm.compiler.debug.DebugContext) ConstantBindingParameterPlugin(org.graalvm.compiler.replacements.ConstantBindingParameterPlugin) NonNullParameter(org.graalvm.compiler.api.replacements.Snippet.NonNullParameter) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) SnippetReflectionProvider(org.graalvm.compiler.api.replacements.SnippetReflectionProvider) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) GraphBuilderPhase(org.graalvm.compiler.java.GraphBuilderPhase) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) Plugins(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)

Example 12 with MetaAccessProvider

use of jdk.vm.ci.meta.MetaAccessProvider in project graal by oracle.

the class GraphKit method inline.

/**
 * Inlines a given invocation to a method. The graph of the inlined method is processed in the
 * same manner as for snippets and method substitutions.
 */
public void inline(InvokeNode invoke) {
    ResolvedJavaMethod method = ((MethodCallTargetNode) invoke.callTarget()).targetMethod();
    MetaAccessProvider metaAccess = providers.getMetaAccess();
    Plugins plugins = new Plugins(graphBuilderPlugins);
    GraphBuilderConfiguration config = GraphBuilderConfiguration.getSnippetDefault(plugins);
    StructuredGraph calleeGraph = new StructuredGraph.Builder(invoke.getOptions(), invoke.getDebug()).method(method).build();
    if (invoke.graph().trackNodeSourcePosition()) {
        calleeGraph.setTrackNodeSourcePosition();
    }
    IntrinsicContext initialReplacementContext = new IntrinsicContext(method, method, providers.getReplacements().getDefaultReplacementBytecodeProvider(), INLINE_AFTER_PARSING);
    GraphBuilderPhase.Instance instance = new GraphBuilderPhase.Instance(metaAccess, providers.getStampProvider(), providers.getConstantReflection(), providers.getConstantFieldProvider(), config, OptimisticOptimizations.NONE, initialReplacementContext);
    instance.apply(calleeGraph);
    // Remove all frame states from inlinee
    calleeGraph.clearAllStateAfter();
    new DeadCodeEliminationPhase(Optionality.Required).apply(calleeGraph);
    InliningUtil.inline(invoke, calleeGraph, false, method);
}
Also used : MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) FrameStateBuilder(org.graalvm.compiler.java.FrameStateBuilder) IntrinsicContext(org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) GraphBuilderPhase(org.graalvm.compiler.java.GraphBuilderPhase) DeadCodeEliminationPhase(org.graalvm.compiler.phases.common.DeadCodeEliminationPhase) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) Plugins(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)

Example 13 with MetaAccessProvider

use of jdk.vm.ci.meta.MetaAccessProvider in project graal by oracle.

the class ClassfileBytecodeProviderTest method test.

@Test
public void test() {
    RuntimeProvider rt = Graal.getRequiredCapability(RuntimeProvider.class);
    Providers providers = rt.getHostBackend().getProviders();
    MetaAccessProvider metaAccess = providers.getMetaAccess();
    Assume.assumeTrue(VerifyPhase.class.desiredAssertionStatus());
    String propertyName = Java8OrEarlier ? "sun.boot.class.path" : "jdk.module.path";
    String bootclasspath = System.getProperty(propertyName);
    Assert.assertNotNull("Cannot find value of " + propertyName, bootclasspath);
    for (String path : bootclasspath.split(File.pathSeparator)) {
        if (shouldProcess(path)) {
            try {
                final ZipFile zipFile = new ZipFile(new File(path));
                for (final Enumeration<? extends ZipEntry> entry = zipFile.entries(); entry.hasMoreElements(); ) {
                    final ZipEntry zipEntry = entry.nextElement();
                    String name = zipEntry.getName();
                    if (name.endsWith(".class") && !name.equals("module-info.class") && !name.startsWith("META-INF/versions/")) {
                        String className = name.substring(0, name.length() - ".class".length()).replace('/', '.');
                        if (isInNativeImage(className)) {
                            /*
                                 * Native image requires non-graalsdk classes to be present in the
                                 * classpath.
                                 */
                            continue;
                        }
                        try {
                            checkClass(metaAccess, getSnippetReflection(), className);
                        } catch (ClassNotFoundException e) {
                            throw new AssertionError(e);
                        }
                    }
                }
            } catch (IOException ex) {
                Assert.fail(ex.toString());
            }
        }
    }
}
Also used : VerifyPhase(org.graalvm.compiler.phases.VerifyPhase) ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) RuntimeProvider(org.graalvm.compiler.runtime.RuntimeProvider) IOException(java.io.IOException) Providers(org.graalvm.compiler.phases.util.Providers) ZipFile(java.util.zip.ZipFile) File(java.io.File) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest) Test(org.junit.Test)

Example 14 with MetaAccessProvider

use of jdk.vm.ci.meta.MetaAccessProvider in project graal by oracle.

the class HotSpotGraalMBeanTest method dumpOperation.

@Test
public void dumpOperation() throws Exception {
    Field field = null;
    try {
        field = stopMBeanServer();
    } catch (Exception ex) {
        if (ex.getClass().getName().equals("java.lang.reflect.InaccessibleObjectException")) {
            // skip on JDK9
            return;
        }
    }
    assertNull("The platformMBeanServer isn't initialized now", field.get(null));
    ObjectName name;
    assertNotNull("Server is started", ManagementFactory.getPlatformMBeanServer());
    HotSpotGraalMBean realBean = HotSpotGraalMBean.create(null);
    assertNotNull("Bean is registered", name = realBean.ensureRegistered(false));
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    ObjectInstance bean = server.getObjectInstance(name);
    assertNotNull("Bean is registered", bean);
    MBeanInfo info = server.getMBeanInfo(name);
    assertNotNull("Info is found", info);
    final MBeanOperationInfo[] arr = info.getOperations();
    assertEquals("Currently three overloads", 3, arr.length);
    MBeanOperationInfo dumpOp = null;
    for (int i = 0; i < arr.length; i++) {
        assertEquals("dumpMethod", arr[i].getName());
        if (arr[i].getSignature().length == 3) {
            dumpOp = arr[i];
        }
    }
    assertNotNull("three args variant found", dumpOp);
    server.invoke(name, "dumpMethod", new Object[] { "java.util.Arrays", "asList", ":3" }, null);
    MBeanAttributeInfo dump = (MBeanAttributeInfo) findAttributeInfo("Dump", info);
    Attribute dumpTo1 = new Attribute(dump.getName(), "");
    server.setAttribute(name, dumpTo1);
    Object after = server.getAttribute(name, dump.getName());
    assertEquals("", after);
    OptionValues empty = new OptionValues(EconomicMap.create());
    OptionValues unsetDump = realBean.optionsFor(empty, null);
    final MetaAccessProvider metaAccess = jdk.vm.ci.runtime.JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess();
    ResolvedJavaMethod method = metaAccess.lookupJavaMethod(Arrays.class.getMethod("asList", Object[].class));
    final OptionValues forMethod = realBean.optionsFor(unsetDump, method);
    assertNotSame(unsetDump, forMethod);
    Object nothing = unsetDump.getMap().get(DebugOptions.Dump);
    assertEquals("Empty string", "", nothing);
    Object specialValue = forMethod.getMap().get(DebugOptions.Dump);
    assertEquals(":3", specialValue);
    OptionValues normalMethod = realBean.optionsFor(unsetDump, null);
    Object noSpecialValue = normalMethod.getMap().get(DebugOptions.Dump);
    assertEquals("Empty string", "", noSpecialValue);
}
Also used : MBeanInfo(javax.management.MBeanInfo) OptionValues(org.graalvm.compiler.options.OptionValues) Attribute(javax.management.Attribute) MBeanOperationInfo(javax.management.MBeanOperationInfo) ObjectInstance(javax.management.ObjectInstance) HotSpotGraalMBean(org.graalvm.compiler.hotspot.HotSpotGraalMBean) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) Field(java.lang.reflect.Field) Arrays(java.util.Arrays) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) MBeanServer(javax.management.MBeanServer) GraalTest(org.graalvm.compiler.test.GraalTest) Test(org.junit.Test)

Example 15 with MetaAccessProvider

use of jdk.vm.ci.meta.MetaAccessProvider in project graal by oracle.

the class VerifyGetOptionsUsage method verify.

@Override
protected boolean verify(StructuredGraph graph, PhaseContext context) {
    MetaAccessProvider metaAccess = context.getMetaAccess();
    ResolvedJavaType canonicalizerToolClass = metaAccess.lookupJavaType(CanonicalizerTool.class);
    boolean hasTool = false;
    try {
        for (ResolvedJavaMethod.Parameter parameter : graph.method().getParameters()) {
            if (parameter.getType().getName().equals(canonicalizerToolClass.getName())) {
                hasTool = true;
                break;
            }
        }
    } catch (MalformedParametersException e) {
    // Lambdas sometimes have malformed parameters so ignore this.
    }
    if (hasTool) {
        ResolvedJavaMethod getOptionsMethod = metaAccess.lookupJavaMethod(lookupMethod(Node.class, "getOptions"));
        for (MethodCallTargetNode t : graph.getNodes(MethodCallTargetNode.TYPE)) {
            ResolvedJavaMethod callee = t.targetMethod();
            if (callee.equals(getOptionsMethod)) {
                if (hasTool) {
                    throw new VerificationError("Must use CanonicalizerTool.getOptions() instead of Node.getOptions() in method '%s' of class '%s'.", graph.method().getName(), graph.method().getDeclaringClass().getName());
                }
            }
        }
    }
    return true;
}
Also used : MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) Node(org.graalvm.compiler.graph.Node) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) MalformedParametersException(java.lang.reflect.MalformedParametersException) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)34 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)18 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)13 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)11 DebugContext (org.graalvm.compiler.debug.DebugContext)9 GraphBuilderConfiguration (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration)9 OptionValues (org.graalvm.compiler.options.OptionValues)9 GraphBuilderPhase (org.graalvm.compiler.java.GraphBuilderPhase)8 Plugins (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)8 Method (java.lang.reflect.Method)7 InvocationPlugins (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins)7 Providers (org.graalvm.compiler.phases.util.Providers)7 RuntimeProvider (org.graalvm.compiler.runtime.RuntimeProvider)7 ValueNode (org.graalvm.compiler.nodes.ValueNode)6 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)6 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)5 PhaseSuite (org.graalvm.compiler.phases.PhaseSuite)5 ArrayList (java.util.ArrayList)4 JavaKind (jdk.vm.ci.meta.JavaKind)4 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)4