Search in sources :

Example 1 with ConstantReflectionProvider

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

the class ClassIsAssignableFromNode method canonical.

@Override
public Node canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
    if (forX.isConstant() && forY.isConstant()) {
        ConstantReflectionProvider constantReflection = tool.getConstantReflection();
        ResolvedJavaType thisType = constantReflection.asJavaType(forX.asJavaConstant());
        ResolvedJavaType otherType = constantReflection.asJavaType(forY.asJavaConstant());
        if (thisType != null && otherType != null) {
            return LogicConstantNode.forBoolean(thisType.isAssignableFrom(otherType));
        }
    }
    return this;
}
Also used : ConstantReflectionProvider(jdk.vm.ci.meta.ConstantReflectionProvider) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 2 with ConstantReflectionProvider

use of jdk.vm.ci.meta.ConstantReflectionProvider 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 ConstantReflectionProvider

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

the class ReplacementsImpl method getSubstitution.

@Override
public StructuredGraph getSubstitution(ResolvedJavaMethod method, int invokeBci, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition) {
    StructuredGraph result;
    InvocationPlugin plugin = graphBuilderPlugins.getInvocationPlugins().lookupInvocation(method);
    if (plugin != null && (!plugin.inlineOnly() || invokeBci >= 0)) {
        MetaAccessProvider metaAccess = providers.getMetaAccess();
        if (plugin instanceof MethodSubstitutionPlugin) {
            MethodSubstitutionPlugin msPlugin = (MethodSubstitutionPlugin) plugin;
            ResolvedJavaMethod substitute = msPlugin.getSubstitute(metaAccess);
            StructuredGraph graph = UseSnippetGraphCache.getValue(options) ? graphs.get(substitute) : null;
            if (graph == null || graph.trackNodeSourcePosition() != trackNodeSourcePosition) {
                try (DebugContext debug = openDebugContext("Substitution_", method)) {
                    graph = makeGraph(debug, msPlugin.getBytecodeProvider(), substitute, null, method, trackNodeSourcePosition, replaceePosition);
                    if (!UseSnippetGraphCache.getValue(options)) {
                        return graph;
                    }
                    graph.freeze();
                    graphs.putIfAbsent(substitute, graph);
                    graph = graphs.get(substitute);
                }
            }
            assert graph.isFrozen();
            result = graph;
        } else {
            Bytecode code = new ResolvedJavaMethodBytecode(method);
            ConstantReflectionProvider constantReflection = providers.getConstantReflection();
            ConstantFieldProvider constantFieldProvider = providers.getConstantFieldProvider();
            StampProvider stampProvider = providers.getStampProvider();
            try (DebugContext debug = openDebugContext("Substitution_", method)) {
                result = new IntrinsicGraphBuilder(options, debug, metaAccess, constantReflection, constantFieldProvider, stampProvider, code, invokeBci).buildGraph(plugin);
            }
        }
    } else {
        result = null;
    }
    return result;
}
Also used : StampProvider(org.graalvm.compiler.nodes.spi.StampProvider) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ConstantReflectionProvider(jdk.vm.ci.meta.ConstantReflectionProvider) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) GeneratedInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.GeneratedInvocationPlugin) ResolvedJavaMethodBytecode(org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode) Bytecode(org.graalvm.compiler.bytecode.Bytecode) DebugContext(org.graalvm.compiler.debug.DebugContext) MethodSubstitutionPlugin(org.graalvm.compiler.nodes.graphbuilderconf.MethodSubstitutionPlugin) ResolvedJavaMethodBytecode(org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ConstantFieldProvider(org.graalvm.compiler.core.common.spi.ConstantFieldProvider)

Example 4 with ConstantReflectionProvider

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

the class PartialEvaluator method registerTruffleInvocationPlugins.

protected void registerTruffleInvocationPlugins(InvocationPlugins invocationPlugins, boolean canDelayIntrinsification) {
    ConstantReflectionProvider constantReflection = providers.getConstantReflection();
    TruffleGraphBuilderPlugins.registerInvocationPlugins(invocationPlugins, canDelayIntrinsification, providers.getMetaAccess(), constantReflection, knownTruffleTypes);
    for (TruffleInvocationPluginProvider p : GraalServices.load(TruffleInvocationPluginProvider.class)) {
        p.registerInvocationPlugins(providers.getMetaAccess(), invocationPlugins, canDelayIntrinsification, constantReflection);
    }
}
Also used : TruffleInvocationPluginProvider(org.graalvm.compiler.truffle.compiler.substitutions.TruffleInvocationPluginProvider) ConstantReflectionProvider(jdk.vm.ci.meta.ConstantReflectionProvider)

Example 5 with ConstantReflectionProvider

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

the class SharedRuntimeConfigurationBuilder method build.

public SharedRuntimeConfigurationBuilder build() {
    wordTypes = new WordTypes(metaAccess, FrameAccess.getWordKind());
    Providers p = createProviders(null, null, null, null, null, null, null, null);
    StampProvider stampProvider = createStampProvider(p);
    p = createProviders(null, null, null, null, null, null, stampProvider, null);
    ConstantReflectionProvider constantReflection = createConstantReflectionProvider(p);
    ConstantFieldProvider constantFieldProvider = createConstantFieldProvider(p);
    createProviders(null, constantReflection, constantFieldProvider, null, null, null, stampProvider, null);
    SnippetReflectionProvider snippetReflection = createSnippetReflectionProvider();
    createProviders(null, constantReflection, constantFieldProvider, null, null, null, stampProvider, snippetReflection);
    ForeignCallsProvider foreignCalls = createForeignCallsProvider();
    p = createProviders(null, constantReflection, constantFieldProvider, foreignCalls, null, null, stampProvider, snippetReflection);
    LoweringProvider lowerer = createLoweringProvider(p);
    p = createProviders(null, constantReflection, constantFieldProvider, foreignCalls, lowerer, null, stampProvider, snippetReflection);
    Replacements replacements = createReplacements(p, snippetReflection);
    p = createProviders(null, constantReflection, constantFieldProvider, foreignCalls, lowerer, replacements, stampProvider, snippetReflection);
    EnumMap<ConfigKind, Backend> backends = new EnumMap<>(ConfigKind.class);
    for (ConfigKind config : ConfigKind.values()) {
        RegisterConfig registerConfig = new SubstrateAMD64RegisterConfig(config, metaAccess, ConfigurationValues.getTarget());
        CodeCacheProvider codeCacheProvider = createCodeCacheProvider(registerConfig);
        Providers newProviders = createProviders(codeCacheProvider, constantReflection, constantFieldProvider, foreignCalls, lowerer, replacements, stampProvider, snippetReflection);
        backends.put(config, GraalConfiguration.instance().createBackend(newProviders));
    }
    runtimeConfig = new RuntimeConfiguration(p, snippetReflection, backends, wordTypes);
    return this;
}
Also used : ForeignCallsProvider(org.graalvm.compiler.core.common.spi.ForeignCallsProvider) SubstrateForeignCallsProvider(com.oracle.svm.core.graal.meta.SubstrateForeignCallsProvider) SubstrateStampProvider(com.oracle.svm.core.graal.meta.SubstrateStampProvider) StampProvider(org.graalvm.compiler.nodes.spi.StampProvider) RegisterConfig(jdk.vm.ci.code.RegisterConfig) SubstrateAMD64RegisterConfig(com.oracle.svm.core.graal.code.amd64.SubstrateAMD64RegisterConfig) Replacements(org.graalvm.compiler.nodes.spi.Replacements) WordTypes(org.graalvm.compiler.word.WordTypes) SubstrateAMD64RegisterConfig(com.oracle.svm.core.graal.code.amd64.SubstrateAMD64RegisterConfig) LoweringProvider(org.graalvm.compiler.nodes.spi.LoweringProvider) SubstrateLoweringProvider(com.oracle.svm.core.graal.meta.SubstrateLoweringProvider) ConfigKind(com.oracle.svm.core.graal.code.amd64.SubstrateAMD64RegisterConfig.ConfigKind) Providers(org.graalvm.compiler.phases.util.Providers) SubstrateCodeCacheProvider(com.oracle.svm.core.graal.meta.SubstrateCodeCacheProvider) CodeCacheProvider(jdk.vm.ci.code.CodeCacheProvider) RuntimeConfiguration(com.oracle.svm.core.graal.meta.RuntimeConfiguration) SubstrateSnippetReflectionProvider(com.oracle.svm.core.graal.meta.SubstrateSnippetReflectionProvider) SnippetReflectionProvider(org.graalvm.compiler.api.replacements.SnippetReflectionProvider) Backend(org.graalvm.compiler.core.target.Backend) ConstantReflectionProvider(jdk.vm.ci.meta.ConstantReflectionProvider) EnumMap(java.util.EnumMap) ConstantFieldProvider(org.graalvm.compiler.core.common.spi.ConstantFieldProvider)

Aggregations

ConstantReflectionProvider (jdk.vm.ci.meta.ConstantReflectionProvider)6 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)3 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)2 ConstantFieldProvider (org.graalvm.compiler.core.common.spi.ConstantFieldProvider)2 Stamp (org.graalvm.compiler.core.common.type.Stamp)2 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)2 StampProvider (org.graalvm.compiler.nodes.spi.StampProvider)2 SubstrateAMD64RegisterConfig (com.oracle.svm.core.graal.code.amd64.SubstrateAMD64RegisterConfig)1 ConfigKind (com.oracle.svm.core.graal.code.amd64.SubstrateAMD64RegisterConfig.ConfigKind)1 RuntimeConfiguration (com.oracle.svm.core.graal.meta.RuntimeConfiguration)1 SubstrateCodeCacheProvider (com.oracle.svm.core.graal.meta.SubstrateCodeCacheProvider)1 SubstrateForeignCallsProvider (com.oracle.svm.core.graal.meta.SubstrateForeignCallsProvider)1 SubstrateLoweringProvider (com.oracle.svm.core.graal.meta.SubstrateLoweringProvider)1 SubstrateSnippetReflectionProvider (com.oracle.svm.core.graal.meta.SubstrateSnippetReflectionProvider)1 SubstrateStampProvider (com.oracle.svm.core.graal.meta.SubstrateStampProvider)1 EnumMap (java.util.EnumMap)1 CodeCacheProvider (jdk.vm.ci.code.CodeCacheProvider)1 RegisterConfig (jdk.vm.ci.code.RegisterConfig)1 HotSpotObjectConstant (jdk.vm.ci.hotspot.HotSpotObjectConstant)1 HotSpotResolvedJavaField (jdk.vm.ci.hotspot.HotSpotResolvedJavaField)1