< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/meta/HotSpotInvocationPlugins.java

Print this page
rev 56282 : [mq]: graal
   1 /*
   2  * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 
  25 package org.graalvm.compiler.hotspot.meta;
  26 
  27 import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime;
  28 
  29 import java.lang.reflect.Type;
  30 import java.util.function.Predicate;
  31 
  32 import org.graalvm.compiler.core.common.GraalOptions;

  33 import org.graalvm.compiler.graph.Node;
  34 import org.graalvm.compiler.graph.iterators.NodeIterable;
  35 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;

  36 import org.graalvm.compiler.hotspot.phases.AheadOfTimeVerificationPhase;
  37 import org.graalvm.compiler.nodes.ConstantNode;
  38 import org.graalvm.compiler.nodes.FrameState;
  39 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
  40 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin;
  41 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
  42 import org.graalvm.compiler.nodes.type.StampTool;
  43 import org.graalvm.compiler.phases.tiers.CompilerConfiguration;
  44 import org.graalvm.compiler.replacements.nodes.MacroNode;
  45 
  46 import jdk.vm.ci.meta.JavaKind;
  47 import jdk.vm.ci.meta.ResolvedJavaType;
  48 
  49 /**
  50  * Extension of {@link InvocationPlugins} that disables plugins based on runtime configuration.
  51  */
  52 final class HotSpotInvocationPlugins extends InvocationPlugins {

  53     private final GraalHotSpotVMConfig config;
  54     private final Predicate<ResolvedJavaType> intrinsificationPredicate;
  55 
  56     HotSpotInvocationPlugins(GraalHotSpotVMConfig config, CompilerConfiguration compilerConfiguration) {

  57         this.config = config;
  58         this.intrinsificationPredicate = runtime().getIntrinsificationTrustPredicate(compilerConfiguration.getClass());
  59     }
  60 
  61     @Override
  62     protected void register(InvocationPlugin plugin, boolean isOptional, boolean allowOverwrite, Type declaringClass, String name, Type... argumentTypes) {
  63         if (!config.usePopCountInstruction) {
  64             if (name.equals("bitCount")) {
  65                 assert declaringClass.equals(Integer.class) || declaringClass.equals(Long.class);
  66                 return;
  67             }
  68         }
  69         super.register(plugin, isOptional, allowOverwrite, declaringClass, name, argumentTypes);
  70     }
  71 
  72     @Override
  73     public void checkNewNodes(GraphBuilderContext b, InvocationPlugin plugin, NodeIterable<Node> newNodes) {
  74         for (Node node : newNodes) {
  75             if (node instanceof MacroNode) {
  76                 // MacroNode based plugins can only be used for inlining since they


  89                         } else {
  90                             // Tolerate uses in unused FrameStates
  91                             if (node.usages().filter((n) -> !(n instanceof FrameState) || n.hasUsages()).isNotEmpty()) {
  92                                 throw new AssertionError("illegal constant node in AOT: " + node);
  93                             }
  94                         }
  95                     }
  96                 }
  97             }
  98         }
  99         super.checkNewNodes(b, plugin, newNodes);
 100     }
 101 
 102     private static boolean isClass(ConstantNode node) {
 103         ResolvedJavaType type = StampTool.typeOrNull(node);
 104         return type != null && "Ljava/lang/Class;".equals(type.getName());
 105     }
 106 
 107     @Override
 108     public boolean canBeIntrinsified(ResolvedJavaType declaringClass) {
 109         return intrinsificationPredicate.test(declaringClass);







 110     }
 111 }
   1 /*
   2  * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 
  25 package org.graalvm.compiler.hotspot.meta;
  26 
  27 import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime;
  28 
  29 import java.lang.reflect.Type;
  30 import java.util.function.Predicate;
  31 
  32 import org.graalvm.compiler.core.common.GraalOptions;
  33 import org.graalvm.compiler.debug.GraalError;
  34 import org.graalvm.compiler.graph.Node;
  35 import org.graalvm.compiler.graph.iterators.NodeIterable;
  36 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
  37 import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider;
  38 import org.graalvm.compiler.hotspot.phases.AheadOfTimeVerificationPhase;
  39 import org.graalvm.compiler.nodes.ConstantNode;
  40 import org.graalvm.compiler.nodes.FrameState;
  41 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
  42 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin;
  43 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
  44 import org.graalvm.compiler.nodes.type.StampTool;
  45 import org.graalvm.compiler.phases.tiers.CompilerConfiguration;
  46 import org.graalvm.compiler.replacements.nodes.MacroNode;
  47 
  48 import jdk.vm.ci.meta.JavaKind;
  49 import jdk.vm.ci.meta.ResolvedJavaType;
  50 
  51 /**
  52  * Extension of {@link InvocationPlugins} that disables plugins based on runtime configuration.
  53  */
  54 final class HotSpotInvocationPlugins extends InvocationPlugins {
  55     private final HotSpotGraalRuntimeProvider graalRuntime;
  56     private final GraalHotSpotVMConfig config;
  57     private final Predicate<ResolvedJavaType> intrinsificationPredicate;
  58 
  59     HotSpotInvocationPlugins(HotSpotGraalRuntimeProvider graalRuntime, GraalHotSpotVMConfig config, CompilerConfiguration compilerConfiguration) {
  60         this.graalRuntime = graalRuntime;
  61         this.config = config;
  62         this.intrinsificationPredicate = runtime().getIntrinsificationTrustPredicate(compilerConfiguration.getClass());
  63     }
  64 
  65     @Override
  66     protected void register(InvocationPlugin plugin, boolean isOptional, boolean allowOverwrite, Type declaringClass, String name, Type... argumentTypes) {
  67         if (!config.usePopCountInstruction) {
  68             if (name.equals("bitCount")) {
  69                 assert declaringClass.equals(Integer.class) || declaringClass.equals(Long.class);
  70                 return;
  71             }
  72         }
  73         super.register(plugin, isOptional, allowOverwrite, declaringClass, name, argumentTypes);
  74     }
  75 
  76     @Override
  77     public void checkNewNodes(GraphBuilderContext b, InvocationPlugin plugin, NodeIterable<Node> newNodes) {
  78         for (Node node : newNodes) {
  79             if (node instanceof MacroNode) {
  80                 // MacroNode based plugins can only be used for inlining since they


  93                         } else {
  94                             // Tolerate uses in unused FrameStates
  95                             if (node.usages().filter((n) -> !(n instanceof FrameState) || n.hasUsages()).isNotEmpty()) {
  96                                 throw new AssertionError("illegal constant node in AOT: " + node);
  97                             }
  98                         }
  99                     }
 100                 }
 101             }
 102         }
 103         super.checkNewNodes(b, plugin, newNodes);
 104     }
 105 
 106     private static boolean isClass(ConstantNode node) {
 107         ResolvedJavaType type = StampTool.typeOrNull(node);
 108         return type != null && "Ljava/lang/Class;".equals(type.getName());
 109     }
 110 
 111     @Override
 112     public boolean canBeIntrinsified(ResolvedJavaType declaringClass) {
 113         if (!intrinsificationPredicate.test(declaringClass)) {
 114             if (graalRuntime.isBootstrapping()) {
 115                 throw GraalError.shouldNotReachHere("Class declaring a method for which a Graal intrinsic is available should be trusted for intrinsification: " + declaringClass.toJavaName());
 116             }
 117             return false;
 118         }
 119         return true;
 120 
 121     }
 122 }
< prev index next >