Search in sources :

Example 1 with HotSpotReflectionGetCallerClassNode

use of org.graalvm.compiler.hotspot.replacements.HotSpotReflectionGetCallerClassNode in project graal by oracle.

the class HotSpotGraphBuilderPlugins method registerReflectionPlugins.

private static void registerReflectionPlugins(InvocationPlugins plugins, Replacements replacements, GraalHotSpotVMConfig config) {
    Registration r = new Registration(plugins, reflectionClass, replacements);
    r.register(new InlineOnlyInvocationPlugin("getCallerClass") {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.addPush(JavaKind.Object, new HotSpotReflectionGetCallerClassNode(MacroParams.of(b, targetMethod)));
            return true;
        }
    });
    r.register(new InvocationPlugin("getClassAccessFlags", Class.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg) {
            try (HotSpotInvocationPluginHelper helper = new HotSpotInvocationPluginHelper(b, targetMethod, config)) {
                ValueNode klass = helper.readKlassFromClass(b.nullCheckedValue(arg));
                // Primitive Class case
                ValueNode klassNonNull = helper.emitNullReturnGuard(klass, ConstantNode.forInt(Modifier.ABSTRACT | Modifier.FINAL | Modifier.PUBLIC), GraalDirectives.UNLIKELY_PROBABILITY);
                // Return (Klass::_access_flags & jvmAccWrittenFlags)
                ValueNode accessFlags = helper.readKlassAccessFlags(klassNonNull);
                helper.emitFinalReturn(JavaKind.Int, new AndNode(accessFlags, ConstantNode.forInt(config.jvmAccWrittenFlags)));
            }
            return true;
        }
    });
}
Also used : HotSpotReflectionGetCallerClassNode(org.graalvm.compiler.hotspot.replacements.HotSpotReflectionGetCallerClassNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) InlineOnlyInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin) ValueNode(org.graalvm.compiler.nodes.ValueNode) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) SnippetSubstitutionInvocationPlugin(org.graalvm.compiler.replacements.SnippetSubstitutionInvocationPlugin) InlineOnlyInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin) AndNode(org.graalvm.compiler.nodes.calc.AndNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) HotSpotInvocationPluginHelper(org.graalvm.compiler.hotspot.replacements.HotSpotInvocationPluginHelper)

Aggregations

ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 HotSpotInvocationPluginHelper (org.graalvm.compiler.hotspot.replacements.HotSpotInvocationPluginHelper)1 HotSpotReflectionGetCallerClassNode (org.graalvm.compiler.hotspot.replacements.HotSpotReflectionGetCallerClassNode)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1 AndNode (org.graalvm.compiler.nodes.calc.AndNode)1 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)1 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)1 InlineOnlyInvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin)1 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)1 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)1 SnippetSubstitutionInvocationPlugin (org.graalvm.compiler.replacements.SnippetSubstitutionInvocationPlugin)1