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.replacements.nodes;
26
27 import static jdk.vm.ci.code.BytecodeFrame.isPlaceholderBci;
28 import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_UNKNOWN;
29 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_UNKNOWN;
30
31 import org.graalvm.compiler.api.replacements.MethodSubstitution;
32 import org.graalvm.compiler.api.replacements.Snippet;
33 import org.graalvm.compiler.core.common.type.StampPair;
34 import org.graalvm.compiler.debug.DebugCloseable;
35 import org.graalvm.compiler.debug.DebugContext;
36 import org.graalvm.compiler.debug.GraalError;
37 import org.graalvm.compiler.graph.Node;
38 import org.graalvm.compiler.graph.NodeClass;
39 import org.graalvm.compiler.graph.NodeInputList;
40 import org.graalvm.compiler.nodeinfo.NodeInfo;
41 import org.graalvm.compiler.nodes.CallTargetNode.InvokeKind;
42 import org.graalvm.compiler.nodes.FixedNode;
43 import org.graalvm.compiler.nodes.Invokable;
44 import org.graalvm.compiler.nodes.FixedWithNextNode;
45 import org.graalvm.compiler.nodes.FrameState;
46 import org.graalvm.compiler.nodes.InvokeNode;
47 import org.graalvm.compiler.nodes.StructuredGraph;
188 assert invoke.verify();
189
190 if (replacementGraph != null) {
191 // Pull out the receiver null check so that a replaced
192 // receiver can be lowered if necessary
193 if (!targetMethod.isStatic()) {
194 ValueNode nonNullReceiver = InliningUtil.nonNullReceiver(invoke);
195 if (nonNullReceiver instanceof Lowerable) {
196 ((Lowerable) nonNullReceiver).lower(tool);
197 }
198 }
199 InliningUtil.inline(invoke, replacementGraph, false, targetMethod, "Replace with graph.", "LoweringPhase");
200 replacementGraph.getDebug().dump(DebugContext.DETAILED_LEVEL, graph(), "After inlining replacement %s", replacementGraph);
201 } else {
202 if (isPlaceholderBci(invoke.bci())) {
203 throw new GraalError("%s: cannot lower to invoke with placeholder BCI: %s", graph(), this);
204 }
205
206 if (invoke.stateAfter() == null) {
207 ResolvedJavaMethod method = graph().method();
208 if (method.getAnnotation(MethodSubstitution.class) != null || method.getAnnotation(Snippet.class) != null) {
209 // One cause for this is that a MacroNode is created for a method that
210 // no longer needs a MacroNode. For example, Class.getComponentType()
211 // only needs a MacroNode prior to JDK9 as it was given a non-native
212 // implementation in JDK9.
213 throw new GraalError("%s macro created for call to %s in %s must be lowerable to a snippet or intrinsic graph. " +
214 "Maybe a macro node is not needed for this method in the current JDK?", getClass().getSimpleName(), targetMethod.format("%h.%n(%p)"), graph());
215 }
216 throw new GraalError("%s: cannot lower to invoke without state: %s", graph(), this);
217 }
218 invoke.lower(tool);
219 }
220 }
221
222 @SuppressWarnings("try")
223 public InvokeNode replaceWithInvoke() {
224 try (DebugCloseable context = withNodeSourcePosition()) {
225 InvokeNode invoke = createInvoke();
226 graph().replaceFixedWithFixed(this, invoke);
227 return invoke;
228 }
229 }
230
231 public LocationIdentity getLocationIdentity() {
232 return LocationIdentity.any();
233 }
234
|
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.replacements.nodes;
26
27 import static jdk.vm.ci.code.BytecodeFrame.isPlaceholderBci;
28 import static jdk.vm.ci.services.Services.IS_IN_NATIVE_IMAGE;
29 import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_UNKNOWN;
30 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_UNKNOWN;
31
32 import org.graalvm.compiler.api.replacements.MethodSubstitution;
33 import org.graalvm.compiler.api.replacements.Snippet;
34 import org.graalvm.compiler.core.common.type.StampPair;
35 import org.graalvm.compiler.debug.DebugCloseable;
36 import org.graalvm.compiler.debug.DebugContext;
37 import org.graalvm.compiler.debug.GraalError;
38 import org.graalvm.compiler.graph.Node;
39 import org.graalvm.compiler.graph.NodeClass;
40 import org.graalvm.compiler.graph.NodeInputList;
41 import org.graalvm.compiler.nodeinfo.NodeInfo;
42 import org.graalvm.compiler.nodes.CallTargetNode.InvokeKind;
43 import org.graalvm.compiler.nodes.FixedNode;
44 import org.graalvm.compiler.nodes.Invokable;
45 import org.graalvm.compiler.nodes.FixedWithNextNode;
46 import org.graalvm.compiler.nodes.FrameState;
47 import org.graalvm.compiler.nodes.InvokeNode;
48 import org.graalvm.compiler.nodes.StructuredGraph;
189 assert invoke.verify();
190
191 if (replacementGraph != null) {
192 // Pull out the receiver null check so that a replaced
193 // receiver can be lowered if necessary
194 if (!targetMethod.isStatic()) {
195 ValueNode nonNullReceiver = InliningUtil.nonNullReceiver(invoke);
196 if (nonNullReceiver instanceof Lowerable) {
197 ((Lowerable) nonNullReceiver).lower(tool);
198 }
199 }
200 InliningUtil.inline(invoke, replacementGraph, false, targetMethod, "Replace with graph.", "LoweringPhase");
201 replacementGraph.getDebug().dump(DebugContext.DETAILED_LEVEL, graph(), "After inlining replacement %s", replacementGraph);
202 } else {
203 if (isPlaceholderBci(invoke.bci())) {
204 throw new GraalError("%s: cannot lower to invoke with placeholder BCI: %s", graph(), this);
205 }
206
207 if (invoke.stateAfter() == null) {
208 ResolvedJavaMethod method = graph().method();
209 if (!IS_IN_NATIVE_IMAGE) {
210 if (method.getAnnotation(MethodSubstitution.class) != null || method.getAnnotation(Snippet.class) != null) {
211 // One cause for this is that a MacroNode is created for a method that
212 // no longer needs a MacroNode. For example, Class.getComponentType()
213 // only needs a MacroNode prior to JDK9 as it was given a non-native
214 // implementation in JDK9.
215 throw new GraalError("%s macro created for call to %s in %s must be lowerable to a snippet or intrinsic graph. " +
216 "Maybe a macro node is not needed for this method in the current JDK?", getClass().getSimpleName(), targetMethod.format("%h.%n(%p)"), graph());
217 }
218 }
219 throw new GraalError("%s: cannot lower to invoke without state: %s", graph(), this);
220 }
221 invoke.lower(tool);
222 }
223 }
224
225 @SuppressWarnings("try")
226 public InvokeNode replaceWithInvoke() {
227 try (DebugCloseable context = withNodeSourcePosition()) {
228 InvokeNode invoke = createInvoke();
229 graph().replaceFixedWithFixed(this, invoke);
230 return invoke;
231 }
232 }
233
234 public LocationIdentity getLocationIdentity() {
235 return LocationIdentity.any();
236 }
237
|