< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/ReplacementsImpl.java

Print this page




  64 import org.graalvm.compiler.graph.NodeSourcePosition;
  65 import org.graalvm.compiler.java.GraphBuilderPhase;
  66 import org.graalvm.compiler.java.GraphBuilderPhase.Instance;
  67 import org.graalvm.compiler.nodes.CallTargetNode;
  68 import org.graalvm.compiler.nodes.Invoke;
  69 import org.graalvm.compiler.nodes.StateSplit;
  70 import org.graalvm.compiler.nodes.StructuredGraph;
  71 import org.graalvm.compiler.nodes.ValueNode;
  72 import org.graalvm.compiler.nodes.graphbuilderconf.GeneratedInvocationPlugin;
  73 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
  74 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
  75 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
  76 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderPlugin;
  77 import org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin;
  78 import org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext;
  79 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin;
  80 import org.graalvm.compiler.nodes.graphbuilderconf.MethodSubstitutionPlugin;
  81 import org.graalvm.compiler.nodes.java.MethodCallTargetNode;
  82 import org.graalvm.compiler.nodes.spi.Replacements;
  83 import org.graalvm.compiler.nodes.spi.StampProvider;



  84 import org.graalvm.compiler.options.OptionValues;
  85 import org.graalvm.compiler.phases.OptimisticOptimizations;
  86 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
  87 import org.graalvm.compiler.phases.common.ConvertDeoptimizeToGuardPhase;
  88 import org.graalvm.compiler.phases.common.DeadCodeEliminationPhase;
  89 import org.graalvm.compiler.phases.tiers.PhaseContext;
  90 import org.graalvm.compiler.phases.util.Providers;
  91 import org.graalvm.compiler.word.Word;
  92 import org.graalvm.compiler.word.WordOperationPlugin;
  93 
  94 import jdk.vm.ci.code.TargetDescription;
  95 import jdk.vm.ci.meta.ConstantReflectionProvider;
  96 import jdk.vm.ci.meta.MetaAccessProvider;
  97 import jdk.vm.ci.meta.ResolvedJavaMethod;
  98 import jdk.vm.ci.meta.ResolvedJavaType;
  99 
 100 public class ReplacementsImpl implements Replacements, InlineInvokePlugin {
 101 







 102     protected final OptionValues options;
 103 
 104     public Providers getProviders() {
 105         return providers;
 106     }
 107 
 108     public void setProviders(Providers providers) {
 109         this.providers = providers.copyWith(this);
 110     }
 111 
 112     protected Providers providers;
 113     public final SnippetReflectionProvider snippetReflection;
 114     public final TargetDescription target;
 115     private GraphBuilderConfiguration.Plugins graphBuilderPlugins;
 116     private final DebugHandlersFactory debugHandlersFactory;
 117 
 118     @Override
 119     public OptionValues getOptions() {
 120         return options;
 121     }


 205     }
 206 
 207     // This map is key'ed by a class name instead of a Class object so that
 208     // it is stable across VM executions (in support of replay compilation).
 209     private final EconomicMap<String, SnippetTemplateCache> snippetTemplateCache;
 210 
 211     public ReplacementsImpl(OptionValues options, DebugHandlersFactory debugHandlersFactory, Providers providers, SnippetReflectionProvider snippetReflection, BytecodeProvider bytecodeProvider,
 212                     TargetDescription target) {
 213         this.options = options;
 214         this.providers = providers.copyWith(this);
 215         this.snippetReflection = snippetReflection;
 216         this.target = target;
 217         this.graphs = new ConcurrentHashMap<>();
 218         this.snippetTemplateCache = EconomicMap.create(Equivalence.DEFAULT);
 219         this.defaultBytecodeProvider = bytecodeProvider;
 220         this.debugHandlersFactory = debugHandlersFactory;
 221 
 222     }
 223 
 224     private static final TimerKey SnippetPreparationTime = DebugContext.timer("SnippetPreparationTime");
 225 
 226     @Override
 227     public StructuredGraph getSnippet(ResolvedJavaMethod method, Object[] args, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition) {
 228         return getSnippet(method, null, args, trackNodeSourcePosition, replaceePosition);
 229     }
 230 
 231     private static final AtomicInteger nextDebugContextId = new AtomicInteger();
 232 
 233     public DebugContext openDebugContext(String idPrefix, ResolvedJavaMethod method) {
 234         DebugContext outer = DebugContext.forCurrentThread();
 235         Description description = new Description(method, idPrefix + nextDebugContextId.incrementAndGet());
 236         List<DebugHandlersFactory> factories = debugHandlersFactory == null ? Collections.emptyList() : Collections.singletonList(debugHandlersFactory);
 237         return DebugContext.create(options, description, outer.getGlobalMetrics(), DEFAULT_LOG_STREAM, factories);
 238     }
 239 
 240     @Override
 241     @SuppressWarnings("try")
 242     public StructuredGraph getSnippet(ResolvedJavaMethod method, ResolvedJavaMethod recursiveEntry, Object[] args, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition) {
 243         assert method.getAnnotation(Snippet.class) != null : "Snippet must be annotated with @" + Snippet.class.getSimpleName();
 244         assert method.hasBytecodes() : "Snippet must not be abstract or native";
 245 
 246         StructuredGraph graph = UseSnippetGraphCache.getValue(options) ? graphs.get(method) : null;
 247         if (graph == null || (trackNodeSourcePosition && !graph.trackNodeSourcePosition())) {
 248             try (DebugContext debug = openDebugContext("Snippet_", method);
 249                             DebugCloseable a = SnippetPreparationTime.start(debug)) {




  64 import org.graalvm.compiler.graph.NodeSourcePosition;
  65 import org.graalvm.compiler.java.GraphBuilderPhase;
  66 import org.graalvm.compiler.java.GraphBuilderPhase.Instance;
  67 import org.graalvm.compiler.nodes.CallTargetNode;
  68 import org.graalvm.compiler.nodes.Invoke;
  69 import org.graalvm.compiler.nodes.StateSplit;
  70 import org.graalvm.compiler.nodes.StructuredGraph;
  71 import org.graalvm.compiler.nodes.ValueNode;
  72 import org.graalvm.compiler.nodes.graphbuilderconf.GeneratedInvocationPlugin;
  73 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
  74 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
  75 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
  76 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderPlugin;
  77 import org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin;
  78 import org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext;
  79 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin;
  80 import org.graalvm.compiler.nodes.graphbuilderconf.MethodSubstitutionPlugin;
  81 import org.graalvm.compiler.nodes.java.MethodCallTargetNode;
  82 import org.graalvm.compiler.nodes.spi.Replacements;
  83 import org.graalvm.compiler.nodes.spi.StampProvider;
  84 import org.graalvm.compiler.options.Option;
  85 import org.graalvm.compiler.options.OptionKey;
  86 import org.graalvm.compiler.options.OptionType;
  87 import org.graalvm.compiler.options.OptionValues;
  88 import org.graalvm.compiler.phases.OptimisticOptimizations;
  89 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
  90 import org.graalvm.compiler.loop.phases.ConvertDeoptimizeToGuardPhase;
  91 import org.graalvm.compiler.phases.common.DeadCodeEliminationPhase;
  92 import org.graalvm.compiler.phases.tiers.PhaseContext;
  93 import org.graalvm.compiler.phases.util.Providers;
  94 import org.graalvm.compiler.word.Word;
  95 import org.graalvm.compiler.word.WordOperationPlugin;
  96 
  97 import jdk.vm.ci.code.TargetDescription;
  98 import jdk.vm.ci.meta.ConstantReflectionProvider;
  99 import jdk.vm.ci.meta.MetaAccessProvider;
 100 import jdk.vm.ci.meta.ResolvedJavaMethod;
 101 import jdk.vm.ci.meta.ResolvedJavaType;
 102 
 103 public class ReplacementsImpl implements Replacements, InlineInvokePlugin {
 104 
 105     public static class Options {
 106         // @formatter:off
 107         @Option(help = "This is a testing option to exercise the SymbolicSnippetEncoder", type = OptionType.Expert)
 108         public static final OptionKey<Boolean> UseEncodedSnippets = new OptionKey<>(false);
 109         // @formatter:on
 110     }
 111 
 112     protected final OptionValues options;
 113 
 114     public Providers getProviders() {
 115         return providers;
 116     }
 117 
 118     public void setProviders(Providers providers) {
 119         this.providers = providers.copyWith(this);
 120     }
 121 
 122     protected Providers providers;
 123     public final SnippetReflectionProvider snippetReflection;
 124     public final TargetDescription target;
 125     private GraphBuilderConfiguration.Plugins graphBuilderPlugins;
 126     private final DebugHandlersFactory debugHandlersFactory;
 127 
 128     @Override
 129     public OptionValues getOptions() {
 130         return options;
 131     }


 215     }
 216 
 217     // This map is key'ed by a class name instead of a Class object so that
 218     // it is stable across VM executions (in support of replay compilation).
 219     private final EconomicMap<String, SnippetTemplateCache> snippetTemplateCache;
 220 
 221     public ReplacementsImpl(OptionValues options, DebugHandlersFactory debugHandlersFactory, Providers providers, SnippetReflectionProvider snippetReflection, BytecodeProvider bytecodeProvider,
 222                     TargetDescription target) {
 223         this.options = options;
 224         this.providers = providers.copyWith(this);
 225         this.snippetReflection = snippetReflection;
 226         this.target = target;
 227         this.graphs = new ConcurrentHashMap<>();
 228         this.snippetTemplateCache = EconomicMap.create(Equivalence.DEFAULT);
 229         this.defaultBytecodeProvider = bytecodeProvider;
 230         this.debugHandlersFactory = debugHandlersFactory;
 231 
 232     }
 233 
 234     private static final TimerKey SnippetPreparationTime = DebugContext.timer("SnippetPreparationTime");





 235 
 236     private static final AtomicInteger nextDebugContextId = new AtomicInteger();
 237 
 238     public DebugContext openDebugContext(String idPrefix, ResolvedJavaMethod method) {
 239         DebugContext outer = DebugContext.forCurrentThread();
 240         Description description = new Description(method, idPrefix + nextDebugContextId.incrementAndGet());
 241         List<DebugHandlersFactory> factories = debugHandlersFactory == null ? Collections.emptyList() : Collections.singletonList(debugHandlersFactory);
 242         return DebugContext.create(options, description, outer.getGlobalMetrics(), DEFAULT_LOG_STREAM, factories);
 243     }
 244 
 245     @Override
 246     @SuppressWarnings("try")
 247     public StructuredGraph getSnippet(ResolvedJavaMethod method, ResolvedJavaMethod recursiveEntry, Object[] args, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition) {
 248         assert method.getAnnotation(Snippet.class) != null : "Snippet must be annotated with @" + Snippet.class.getSimpleName();
 249         assert method.hasBytecodes() : "Snippet must not be abstract or native";
 250 
 251         StructuredGraph graph = UseSnippetGraphCache.getValue(options) ? graphs.get(method) : null;
 252         if (graph == null || (trackNodeSourcePosition && !graph.trackNodeSourcePosition())) {
 253             try (DebugContext debug = openDebugContext("Snippet_", method);
 254                             DebugCloseable a = SnippetPreparationTime.start(debug)) {


< prev index next >