1 /* |
1 /* |
2 * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
39 import org.graalvm.compiler.debug.DebugContext; |
39 import org.graalvm.compiler.debug.DebugContext; |
40 import org.graalvm.compiler.debug.GraalError; |
40 import org.graalvm.compiler.debug.GraalError; |
41 import org.graalvm.compiler.graph.NodeSourcePosition; |
41 import org.graalvm.compiler.graph.NodeSourcePosition; |
42 import org.graalvm.compiler.hotspot.meta.HotSpotWordOperationPlugin; |
42 import org.graalvm.compiler.hotspot.meta.HotSpotWordOperationPlugin; |
43 import org.graalvm.compiler.hotspot.word.HotSpotOperation; |
43 import org.graalvm.compiler.hotspot.word.HotSpotOperation; |
|
44 import org.graalvm.compiler.nodes.Cancellable; |
44 import org.graalvm.compiler.nodes.Invoke; |
45 import org.graalvm.compiler.nodes.Invoke; |
45 import org.graalvm.compiler.nodes.StructuredGraph; |
46 import org.graalvm.compiler.nodes.StructuredGraph; |
46 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext; |
47 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext; |
47 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderPlugin; |
48 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderPlugin; |
48 import org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext; |
49 import org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext; |
89 } |
90 } |
90 } |
91 } |
91 } |
92 } |
92 |
93 |
93 @Override |
94 @Override |
94 public StructuredGraph getIntrinsicGraph(ResolvedJavaMethod method, CompilationIdentifier compilationId, DebugContext debug) { |
95 public StructuredGraph getIntrinsicGraph(ResolvedJavaMethod method, CompilationIdentifier compilationId, DebugContext debug, Cancellable cancellable) { |
95 boolean useEncodedGraphs = UseEncodedGraphs.getValue(debug.getOptions()); |
96 boolean useEncodedGraphs = UseEncodedGraphs.getValue(debug.getOptions()); |
96 if (IS_IN_NATIVE_IMAGE || useEncodedGraphs) { |
97 if (IS_IN_NATIVE_IMAGE || useEncodedGraphs) { |
97 HotSpotReplacementsImpl replacements = (HotSpotReplacementsImpl) providers.getReplacements(); |
98 HotSpotReplacementsImpl replacements = (HotSpotReplacementsImpl) providers.getReplacements(); |
98 InvocationPlugin plugin = replacements.getGraphBuilderPlugins().getInvocationPlugins().lookupInvocation(method); |
99 InvocationPlugin plugin = replacements.getGraphBuilderPlugins().getInvocationPlugins().lookupInvocation(method); |
99 if (plugin instanceof MethodSubstitutionPlugin) { |
100 if (plugin instanceof MethodSubstitutionPlugin) { |
100 MethodSubstitutionPlugin msp = (MethodSubstitutionPlugin) plugin; |
101 MethodSubstitutionPlugin msp = (MethodSubstitutionPlugin) plugin; |
101 if (useEncodedGraphs) { |
102 if (useEncodedGraphs) { |
102 replacements.registerMethodSubstitution(msp, method, ROOT_COMPILATION, debug.getOptions()); |
103 replacements.registerMethodSubstitution(msp, method, ROOT_COMPILATION, debug.getOptions()); |
103 } |
104 } |
104 StructuredGraph methodSubstitution = replacements.getMethodSubstitution(msp, method, ROOT_COMPILATION, StructuredGraph.AllowAssumptions.YES, debug.getOptions()); |
105 StructuredGraph methodSubstitution = replacements.getMethodSubstitution(msp, method, ROOT_COMPILATION, StructuredGraph.AllowAssumptions.YES, cancellable, debug.getOptions()); |
105 methodSubstitution.resetDebug(debug); |
106 methodSubstitution.resetDebug(debug); |
106 return methodSubstitution; |
107 return methodSubstitution; |
107 } |
108 } |
108 return null; |
109 return null; |
109 } |
110 } |
110 return super.getIntrinsicGraph(method, compilationId, debug); |
111 return super.getIntrinsicGraph(method, compilationId, debug, cancellable); |
111 } |
112 } |
112 |
113 |
113 @Override |
114 @Override |
114 public StructuredGraph getSubstitution(ResolvedJavaMethod targetMethod, int invokeBci, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition, OptionValues options) { |
115 public StructuredGraph getSubstitution(ResolvedJavaMethod targetMethod, int invokeBci, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition, OptionValues options) { |
115 boolean useEncodedGraphs = UseEncodedGraphs.getValue(options); |
116 boolean useEncodedGraphs = UseEncodedGraphs.getValue(options); |
120 if (!IS_IN_NATIVE_IMAGE && useEncodedGraphs) { |
121 if (!IS_IN_NATIVE_IMAGE && useEncodedGraphs) { |
121 registerMethodSubstitution(msPlugin, targetMethod, INLINE_AFTER_PARSING, options); |
122 registerMethodSubstitution(msPlugin, targetMethod, INLINE_AFTER_PARSING, options); |
122 } |
123 } |
123 // This assumes the normal path creates the graph using |
124 // This assumes the normal path creates the graph using |
124 // GraphBuilderConfiguration.getSnippetDefault with omits exception edges |
125 // GraphBuilderConfiguration.getSnippetDefault with omits exception edges |
125 StructuredGraph subst = getMethodSubstitution(msPlugin, targetMethod, INLINE_AFTER_PARSING, StructuredGraph.AllowAssumptions.NO, options); |
126 StructuredGraph subst = getMethodSubstitution(msPlugin, targetMethod, INLINE_AFTER_PARSING, StructuredGraph.AllowAssumptions.NO, null, options); |
126 return subst; |
127 return subst; |
127 } |
128 } |
128 } |
129 } |
129 |
130 |
130 return super.getSubstitution(targetMethod, invokeBci, trackNodeSourcePosition, replaceePosition, options); |
131 return super.getSubstitution(targetMethod, invokeBci, trackNodeSourcePosition, replaceePosition, options); |
205 |
206 |
206 assert !IS_IN_NATIVE_IMAGE : "should be using encoded snippets"; |
207 assert !IS_IN_NATIVE_IMAGE : "should be using encoded snippets"; |
207 return super.getSnippet(method, recursiveEntry, args, trackNodeSourcePosition, replaceePosition, options); |
208 return super.getSnippet(method, recursiveEntry, args, trackNodeSourcePosition, replaceePosition, options); |
208 } |
209 } |
209 |
210 |
|
211 @SuppressWarnings("try") |
210 private StructuredGraph getEncodedSnippet(ResolvedJavaMethod method, Object[] args, StructuredGraph.AllowAssumptions allowAssumptions, OptionValues options) { |
212 private StructuredGraph getEncodedSnippet(ResolvedJavaMethod method, Object[] args, StructuredGraph.AllowAssumptions allowAssumptions, OptionValues options) { |
211 boolean useEncodedGraphs = UseEncodedGraphs.getValue(options); |
213 boolean useEncodedGraphs = UseEncodedGraphs.getValue(options); |
212 if (IS_IN_NATIVE_IMAGE || useEncodedGraphs) { |
214 if (IS_IN_NATIVE_IMAGE || useEncodedGraphs) { |
213 synchronized (HotSpotReplacementsImpl.class) { |
215 synchronized (HotSpotReplacementsImpl.class) { |
214 if (!IS_IN_NATIVE_IMAGE) { |
216 if (!IS_IN_NATIVE_IMAGE) { |
216 } |
218 } |
217 |
219 |
218 if (getEncodedSnippets() == null) { |
220 if (getEncodedSnippets() == null) { |
219 throw GraalError.shouldNotReachHere("encoded snippets not found"); |
221 throw GraalError.shouldNotReachHere("encoded snippets not found"); |
220 } |
222 } |
221 StructuredGraph graph = getEncodedSnippets().getEncodedSnippet(method, this, args, allowAssumptions, options); |
223 // Snippets graphs can contain foreign object reference and |
222 if (graph == null) { |
224 // outlive a single compilation. |
223 throw GraalError.shouldNotReachHere("snippet not found: " + method.format("%H.%n(%p)")); |
225 try (CompilationContext scope = HotSpotGraalServices.enterGlobalCompilationContext()) { |
224 } |
226 StructuredGraph graph = getEncodedSnippets().getEncodedSnippet(method, this, args, allowAssumptions, options); |
225 return graph; |
227 if (graph == null) { |
|
228 throw GraalError.shouldNotReachHere("snippet not found: " + method.format("%H.%n(%p)")); |
|
229 } |
|
230 return graph; |
|
231 } |
226 } |
232 } |
227 } else { |
233 } else { |
228 assert registeredSnippets == null || registeredSnippets.contains(method) : "Asking for snippet method that was never registered: " + method.format("%H.%n(%p)"); |
234 assert registeredSnippets == null || registeredSnippets.contains(method) : "Asking for snippet method that was never registered: " + method.format("%H.%n(%p)"); |
229 } |
235 } |
230 return null; |
236 return null; |
231 } |
237 } |
232 |
238 |
233 @Override |
239 @Override |
234 public StructuredGraph getMethodSubstitution(MethodSubstitutionPlugin plugin, ResolvedJavaMethod original, IntrinsicContext.CompilationContext context, |
240 public StructuredGraph getMethodSubstitution(MethodSubstitutionPlugin plugin, ResolvedJavaMethod original, IntrinsicContext.CompilationContext context, |
235 StructuredGraph.AllowAssumptions allowAssumptions, OptionValues options) { |
241 StructuredGraph.AllowAssumptions allowAssumptions, Cancellable cancellable, OptionValues options) { |
236 boolean useEncodedGraphs = UseEncodedGraphs.getValue(options); |
242 boolean useEncodedGraphs = UseEncodedGraphs.getValue(options); |
237 if (IS_IN_NATIVE_IMAGE || useEncodedGraphs) { |
243 if (IS_IN_NATIVE_IMAGE || useEncodedGraphs) { |
238 if (!IS_IN_NATIVE_IMAGE) { |
244 if (!IS_IN_NATIVE_IMAGE) { |
239 snippetEncoder.encode(options); |
245 snippetEncoder.encode(options); |
240 } |
246 } |
241 |
247 |
242 if (getEncodedSnippets() == null) { |
248 if (getEncodedSnippets() == null) { |
243 throw GraalError.shouldNotReachHere("encoded snippets not found"); |
249 throw GraalError.shouldNotReachHere("encoded snippets not found"); |
244 } |
250 } |
245 return getEncodedSnippets().getMethodSubstitutionGraph(plugin, original, this, context, allowAssumptions, options); |
251 return getEncodedSnippets().getMethodSubstitutionGraph(plugin, original, this, context, allowAssumptions, cancellable, options); |
246 } |
252 } |
247 return null; |
253 return null; |
248 } |
254 } |
249 |
255 |
250 } |
256 } |