Search in sources :

Example 1 with MetaAccessProvider

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

the class HotSpotTruffleRuntime method setDontInlineCallBoundaryMethod.

/**
 * Prevents C1 or C2 from inlining a call to a method annotated by {@link TruffleCallBoundary}
 * so that we never miss the chance to switch from the Truffle interpreter to compiled code.
 *
 * @see HotSpotTruffleCompiler#installTruffleCallBoundaryMethods()
 */
public static void setDontInlineCallBoundaryMethod() {
    MetaAccessProvider metaAccess = getMetaAccess();
    ResolvedJavaType type = metaAccess.lookupJavaType(OptimizedCallTarget.class);
    for (ResolvedJavaMethod method : type.getDeclaredMethods()) {
        if (method.getAnnotation(TruffleCallBoundary.class) != null) {
            setNotInlinableOrCompilable(method);
        }
    }
}
Also used : TruffleCallBoundary(org.graalvm.compiler.truffle.runtime.TruffleCallBoundary) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) HotSpotResolvedJavaMethod(jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 2 with MetaAccessProvider

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

the class LoadJavaMirrorWithKlassPhase method getClassConstantReplacement.

private ValueNode getClassConstantReplacement(StructuredGraph graph, PhaseContext context, JavaConstant constant) {
    if (constant instanceof HotSpotObjectConstant) {
        ConstantReflectionProvider constantReflection = context.getConstantReflection();
        ResolvedJavaType type = constantReflection.asJavaType(constant);
        if (type != null) {
            MetaAccessProvider metaAccess = context.getMetaAccess();
            Stamp stamp = StampFactory.objectNonNull(TypeReference.createExactTrusted(metaAccess.lookupJavaType(Class.class)));
            if (type instanceof HotSpotResolvedObjectType) {
                ConstantNode klass = ConstantNode.forConstant(KlassPointerStamp.klassNonNull(), ((HotSpotResolvedObjectType) type).klass(), metaAccess, graph);
                ValueNode getClass = graph.unique(new HubGetClassNode(metaAccess, klass));
                if (((HotSpotObjectConstant) constant).isCompressed()) {
                    return HotSpotCompressionNode.compress(getClass, oopEncoding);
                } else {
                    return getClass;
                }
            } else {
                /*
                     * Primitive classes are more difficult since they don't have a corresponding
                     * Klass* so get them from Class.TYPE for the java box type.
                     */
                HotSpotResolvedPrimitiveType primitive = (HotSpotResolvedPrimitiveType) type;
                ResolvedJavaType boxingClass = metaAccess.lookupJavaType(primitive.getJavaKind().toBoxedJavaClass());
                ConstantNode clazz = ConstantNode.forConstant(context.getConstantReflection().asJavaClass(boxingClass), metaAccess, graph);
                HotSpotResolvedJavaField[] a = (HotSpotResolvedJavaField[]) boxingClass.getStaticFields();
                HotSpotResolvedJavaField typeField = null;
                for (HotSpotResolvedJavaField f : a) {
                    if (f.getName().equals("TYPE")) {
                        typeField = f;
                        break;
                    }
                }
                if (typeField == null) {
                    throw new GraalError("Can't find TYPE field in class");
                }
                if (oopEncoding != null) {
                    stamp = HotSpotNarrowOopStamp.compressed((AbstractObjectStamp) stamp, oopEncoding);
                }
                AddressNode address = graph.unique(new OffsetAddressNode(clazz, ConstantNode.forLong(typeField.offset(), graph)));
                ValueNode read = graph.unique(new FloatingReadNode(address, FINAL_LOCATION, null, stamp));
                if (oopEncoding == null || ((HotSpotObjectConstant) constant).isCompressed()) {
                    return read;
                } else {
                    return HotSpotCompressionNode.uncompress(read, oopEncoding);
                }
            }
        }
    }
    return null;
}
Also used : KlassPointerStamp(org.graalvm.compiler.hotspot.nodes.type.KlassPointerStamp) AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) HotSpotNarrowOopStamp(org.graalvm.compiler.hotspot.nodes.type.HotSpotNarrowOopStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) HubGetClassNode(org.graalvm.compiler.hotspot.replacements.HubGetClassNode) HotSpotResolvedPrimitiveType(jdk.vm.ci.hotspot.HotSpotResolvedPrimitiveType) AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) HotSpotResolvedJavaField(jdk.vm.ci.hotspot.HotSpotResolvedJavaField) HotSpotObjectConstant(jdk.vm.ci.hotspot.HotSpotObjectConstant) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) GraalError(org.graalvm.compiler.debug.GraalError) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) ConstantReflectionProvider(jdk.vm.ci.meta.ConstantReflectionProvider) HotSpotResolvedObjectType(jdk.vm.ci.hotspot.HotSpotResolvedObjectType) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider)

Example 3 with MetaAccessProvider

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

the class ReadNode method canonicalizeRead.

public static ValueNode canonicalizeRead(ValueNode read, AddressNode address, LocationIdentity locationIdentity, CanonicalizerTool tool) {
    NodeView view = NodeView.from(tool);
    MetaAccessProvider metaAccess = tool.getMetaAccess();
    if (tool.canonicalizeReads() && address instanceof OffsetAddressNode) {
        OffsetAddressNode objAddress = (OffsetAddressNode) address;
        ValueNode object = objAddress.getBase();
        if (metaAccess != null && object.isConstant() && !object.isNullConstant() && objAddress.getOffset().isConstant()) {
            long displacement = objAddress.getOffset().asJavaConstant().asLong();
            int stableDimension = ((ConstantNode) object).getStableDimension();
            if (locationIdentity.isImmutable() || stableDimension > 0) {
                Constant constant = read.stamp(view).readConstant(tool.getConstantReflection().getMemoryAccessProvider(), object.asConstant(), displacement);
                boolean isDefaultStable = locationIdentity.isImmutable() || ((ConstantNode) object).isDefaultStable();
                if (constant != null && (isDefaultStable || !constant.isDefaultForKind())) {
                    return ConstantNode.forConstant(read.stamp(view), constant, Math.max(stableDimension - 1, 0), isDefaultStable, metaAccess);
                }
            }
        }
        if (locationIdentity.equals(ARRAY_LENGTH_LOCATION)) {
            ValueNode length = GraphUtil.arrayLength(object);
            if (length != null) {
                return length;
            }
        }
        if (locationIdentity instanceof CanonicalizableLocation) {
            CanonicalizableLocation canonicalize = (CanonicalizableLocation) locationIdentity;
            ValueNode result = canonicalize.canonicalizeRead(read, address, object, tool);
            assert result != null && result.stamp(view).isCompatible(read.stamp(view));
            return result;
        }
    }
    return read;
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) Constant(jdk.vm.ci.meta.Constant) ValueNode(org.graalvm.compiler.nodes.ValueNode) NodeView(org.graalvm.compiler.nodes.NodeView) CanonicalizableLocation(org.graalvm.compiler.nodes.CanonicalizableLocation) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider)

Example 4 with MetaAccessProvider

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

the class StampFactoryTest method testParameters.

@Test
public void testParameters() throws NoSuchMethodException, SecurityException {
    Method method = StampFactoryTest.class.getMethod("test", Integer.TYPE, Object.class, Double.TYPE);
    MetaAccessProvider metaAccess = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend().getProviders().getMetaAccess();
    Stamp[] parameterStamps = StampFactory.createParameterStamps(null, metaAccess.lookupJavaMethod(method));
    Stamp[] expected = { StampFactory.objectNonNull(TypeReference.createWithoutAssumptions(metaAccess.lookupJavaType(StampFactoryTest.class))), StampFactory.forKind(JavaKind.Int), StampFactory.object(TypeReference.createWithoutAssumptions(metaAccess.lookupJavaType(Object.class))), StampFactory.forKind(JavaKind.Double) };
    Assert.assertArrayEquals(expected, parameterStamps);
}
Also used : Stamp(org.graalvm.compiler.core.common.type.Stamp) RuntimeProvider(org.graalvm.compiler.runtime.RuntimeProvider) Method(java.lang.reflect.Method) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) Test(org.junit.Test)

Example 5 with MetaAccessProvider

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

the class HotSpotTruffleCompilerImpl method compileTruffleCallBoundaryMethod.

/**
 * Compiles a method denoted as a
 * {@linkplain HotSpotTruffleCompilerRuntime#getTruffleCallBoundaryMethods() Truffle call
 * boundary}. The compiled code has a special entry point generated by an
 * {@link TruffleCallBoundaryInstrumentationFactory}.
 */
private CompilationResult compileTruffleCallBoundaryMethod(ResolvedJavaMethod javaMethod, CompilationIdentifier compilationId, DebugContext debug) {
    Suites newSuites = this.suites.copy();
    removeInliningPhase(newSuites);
    OptionValues options = TruffleCompilerOptions.getOptions();
    StructuredGraph graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.NO).method(javaMethod).compilationId(compilationId).build();
    MetaAccessProvider metaAccess = providers.getMetaAccess();
    Plugins plugins = new Plugins(new InvocationPlugins());
    HotSpotCodeCacheProvider codeCache = (HotSpotCodeCacheProvider) providers.getCodeCache();
    boolean infoPoints = codeCache.shouldDebugNonSafepoints();
    GraphBuilderConfiguration newConfig = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true).withUnresolvedIsError(true).withNodeSourcePosition(infoPoints);
    new GraphBuilderPhase.Instance(metaAccess, providers.getStampProvider(), providers.getConstantReflection(), providers.getConstantFieldProvider(), newConfig, OptimisticOptimizations.ALL, null).apply(graph);
    PhaseSuite<HighTierContext> graphBuilderSuite = getGraphBuilderSuite(codeCache, backend.getSuites());
    CompilationResultBuilderFactory factory = getTruffleCallBoundaryInstrumentationFactory(backend.getTarget().arch.getName());
    return compileGraph(graph, javaMethod, providers, backend, graphBuilderSuite, OptimisticOptimizations.ALL, graph.getProfilingInfo(), newSuites, lirSuites, new CompilationResult(compilationId), factory);
}
Also used : InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) HotSpotCodeCacheProvider(jdk.vm.ci.hotspot.HotSpotCodeCacheProvider) OptionValues(org.graalvm.compiler.options.OptionValues) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) CompilationResult(org.graalvm.compiler.code.CompilationResult) GraphBuilderPhase(org.graalvm.compiler.java.GraphBuilderPhase) CompilationResultBuilderFactory(org.graalvm.compiler.lir.asm.CompilationResultBuilderFactory) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) LIRSuites(org.graalvm.compiler.lir.phases.LIRSuites) Suites(org.graalvm.compiler.phases.tiers.Suites) InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) Plugins(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)

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