Search in sources :

Example 11 with SnippetReflectionProvider

use of org.graalvm.compiler.api.replacements.SnippetReflectionProvider in project graal by oracle.

the class UnsafeAutomaticSubstitutionProcessor method processUnsafeObjectFieldOffsetInvoke.

/**
 * Process call to {@link sun.misc.Unsafe#objectFieldOffset(Field)}. The matching logic below
 * applies to the following code pattern:
 *
 * <code> static final long fieldOffset = Unsafe.getUnsafe().objectFieldOffset(X.class.getDeclaredField("f")); </code>
 */
private void processUnsafeObjectFieldOffsetInvoke(ResolvedJavaType type, Invoke unsafeObjectFieldOffsetInvoke) {
    SnippetReflectionProvider snippetReflectionProvider = GraalAccess.getOriginalSnippetReflection();
    List<String> unsuccessfulReasons = new ArrayList<>();
    Class<?> targetFieldHolder = null;
    String targetFieldName = null;
    ValueNode fieldArgument = unsafeObjectFieldOffsetInvoke.callTarget().arguments().get(1);
    if (fieldArgument instanceof Invoke && isInvokeTo((Invoke) fieldArgument, classGetDeclaredFieldMethod)) {
        Invoke getDeclaredFieldInvoke = (Invoke) fieldArgument;
        /*
             * If the first argument of Unsafe.objectFieldOffset() is a call to
             * Class.getDeclaredField() and the arguments of Class.getDeclaredField(), i.e., the
             * class and the field name, are constants then unwrap them.
             */
        ValueNode holderClassNode = getDeclaredFieldInvoke.callTarget().arguments().get(0);
        if (holderClassNode.isJavaConstant()) {
            targetFieldHolder = snippetReflectionProvider.asObject(Class.class, holderClassNode.asJavaConstant());
        } else {
            unsuccessfulReasons.add("The receiver of the call to Class.getDeclaredField(), i.e., the field holder class, is not a constant.");
        }
        ValueNode fieldNameNode = getDeclaredFieldInvoke.callTarget().arguments().get(1);
        if (fieldNameNode.isJavaConstant()) {
            targetFieldName = snippetReflectionProvider.asObject(String.class, fieldNameNode.asJavaConstant());
        } else {
            unsuccessfulReasons.add("The first argument of the call to Class.getDeclaredField(), i.e., the field name, is not a constant.");
        }
    } else {
        unsuccessfulReasons.add("The first argument of Unsafe.objectFieldOffset() is not a call to Class.getDeclaredField()");
    }
    /*
         * If the value returned by the call to Unsafe.objectFieldOffset() is stored into a field
         * then that must be the offset field.
         */
    ResolvedJavaField offsetField = extractValueStoreField(unsafeObjectFieldOffsetInvoke.asNode(), unsuccessfulReasons);
    /*
         * If the target field holder and name, and the offset field were found try to register a
         * substitution.
         */
    if (targetFieldHolder != null && targetFieldName != null && offsetField != null) {
        Class<?> finalTargetFieldHolder = targetFieldHolder;
        String finalTargetFieldName = targetFieldName;
        Supplier<ComputedValueField> supplier = () -> new ComputedValueField(offsetField, null, Kind.FieldOffset, finalTargetFieldHolder, finalTargetFieldName, false);
        if (tryAutomaticRecomputation(offsetField, Kind.FieldOffset, supplier)) {
            reportSuccessfulAutomaticRecomputation(Kind.FieldOffset, offsetField, targetFieldHolder.getName() + "." + targetFieldName);
        }
    } else {
        reportUnsuccessfulAutomaticRecomputation(type, unsafeObjectFieldOffsetInvoke, Kind.FieldOffset, unsuccessfulReasons);
    }
}
Also used : SnippetReflectionProvider(org.graalvm.compiler.api.replacements.SnippetReflectionProvider) ArrayList(java.util.ArrayList) ValueNode(org.graalvm.compiler.nodes.ValueNode) Invoke(org.graalvm.compiler.nodes.Invoke) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField)

Example 12 with SnippetReflectionProvider

use of org.graalvm.compiler.api.replacements.SnippetReflectionProvider in project graal by oracle.

the class GraalTruffleRuntime method getCallTargetForCallNode.

@Override
public JavaConstant getCallTargetForCallNode(JavaConstant callNodeConstant) {
    SnippetReflectionProvider snippetReflection = getGraalRuntime().getRequiredCapability(SnippetReflectionProvider.class);
    OptimizedDirectCallNode callNode = snippetReflection.asObject(OptimizedDirectCallNode.class, callNodeConstant);
    return snippetReflection.forObject(callNode.getCallTarget());
}
Also used : SnippetReflectionProvider(org.graalvm.compiler.api.replacements.SnippetReflectionProvider)

Example 13 with SnippetReflectionProvider

use of org.graalvm.compiler.api.replacements.SnippetReflectionProvider in project graal by oracle.

the class TruffleInlining method getPosition.

@Override
public SourceLanguagePosition getPosition(JavaConstant node) {
    SnippetReflectionProvider snippetReflection = runtime().getGraalRuntime().getRequiredCapability(SnippetReflectionProvider.class);
    Node truffleNode = snippetReflection.asObject(Node.class, node);
    if (truffleNode == null) {
        return null;
    }
    SourceSection section = null;
    if (truffleNode instanceof DirectCallNode) {
        section = ((DirectCallNode) truffleNode).getCurrentRootNode().getSourceSection();
    }
    if (section == null) {
        section = truffleNode.getSourceSection();
    }
    if (section == null) {
        Node cur = truffleNode.getParent();
        while (cur != null) {
            section = cur.getSourceSection();
            if (section != null) {
                break;
            }
            cur = cur.getParent();
        }
    }
    if (section != null) {
        return new TruffleSourceLanguagePosition(section);
    }
    return null;
}
Also used : SnippetReflectionProvider(org.graalvm.compiler.api.replacements.SnippetReflectionProvider) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) Node(com.oracle.truffle.api.nodes.Node) SourceSection(com.oracle.truffle.api.source.SourceSection) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode)

Example 14 with SnippetReflectionProvider

use of org.graalvm.compiler.api.replacements.SnippetReflectionProvider in project graal by oracle.

the class TruffleInlining method findDecision.

@Override
public Decision findDecision(JavaConstant callNodeConstant) {
    SnippetReflectionProvider snippetReflection = runtime().getGraalRuntime().getRequiredCapability(SnippetReflectionProvider.class);
    OptimizedDirectCallNode callNode = snippetReflection.asObject(OptimizedDirectCallNode.class, callNodeConstant);
    return findByCall(callNode);
}
Also used : SnippetReflectionProvider(org.graalvm.compiler.api.replacements.SnippetReflectionProvider)

Example 15 with SnippetReflectionProvider

use of org.graalvm.compiler.api.replacements.SnippetReflectionProvider 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

SnippetReflectionProvider (org.graalvm.compiler.api.replacements.SnippetReflectionProvider)17 ResolvedJavaField (jdk.vm.ci.meta.ResolvedJavaField)5 ValueNode (org.graalvm.compiler.nodes.ValueNode)5 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)4 ArrayList (java.util.ArrayList)3 WordTypes (org.graalvm.compiler.word.WordTypes)3 UnsupportedFeatureException (com.oracle.graal.pointsto.constraints.UnsupportedFeatureException)2 AnalysisMethod (com.oracle.graal.pointsto.meta.AnalysisMethod)2 HostedProviders (com.oracle.graal.pointsto.meta.HostedProviders)2 SubstrateForeignCallsProvider (com.oracle.svm.core.graal.meta.SubstrateForeignCallsProvider)2 SubstrateLoweringProvider (com.oracle.svm.core.graal.meta.SubstrateLoweringProvider)2 SubstrateSnippetReflectionProvider (com.oracle.svm.core.graal.meta.SubstrateSnippetReflectionProvider)2 SubstrateStampProvider (com.oracle.svm.core.graal.meta.SubstrateStampProvider)2 GraalFeature (com.oracle.svm.graal.hosted.GraalFeature)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 JavaConstant (jdk.vm.ci.meta.JavaConstant)2 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)2 ForeignCallsProvider (org.graalvm.compiler.core.common.spi.ForeignCallsProvider)2 DebugContext (org.graalvm.compiler.debug.DebugContext)2 GraphBuilderPhase (org.graalvm.compiler.java.GraphBuilderPhase)2