annotate graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/NodeIntrinsificationPhase.java @ 8575:ea3ae49a7fa3

NodeIntrinsifcationPhase: allow non-static @Fold methods
author Mick Jordan <mick.jordan@oracle.com>
date Thu, 28 Mar 2013 21:01:48 -0700
parents 8e022657ca0b
children 653110156f8a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
8415
2361bf148c06 rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents: 8409
diff changeset
23 package com.oracle.graal.replacements;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
7059
e4d9f153934f removed ResolvedJavaType.toJava() and introduced ResolvedJavaType.isPrimitive()
Doug Simon <doug.simon@oracle.com>
parents: 7054
diff changeset
25 import static com.oracle.graal.api.meta.MetaUtil.*;
e4d9f153934f removed ResolvedJavaType.toJava() and introduced ResolvedJavaType.isPrimitive()
Doug Simon <doug.simon@oracle.com>
parents: 7054
diff changeset
26
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
27 import java.lang.reflect.*;
5175
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
28 import java.util.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
29
5507
dc71b06d09f8 Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5503
diff changeset
30 import com.oracle.graal.api.meta.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
31 import com.oracle.graal.graph.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
32 import com.oracle.graal.graph.Node.ConstantNodeParameter;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
33 import com.oracle.graal.graph.Node.NodeIntrinsic;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
34 import com.oracle.graal.nodes.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
35 import com.oracle.graal.nodes.extended.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
36 import com.oracle.graal.nodes.java.*;
6408
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 5764
diff changeset
37 import com.oracle.graal.nodes.type.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
38 import com.oracle.graal.nodes.util.*;
6526
ee651c726397 split phases out of graal.phases project into graal.phases.common project
Doug Simon <doug.simon@oracle.com>
parents: 6525
diff changeset
39 import com.oracle.graal.phases.*;
8415
2361bf148c06 rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents: 8409
diff changeset
40 import com.oracle.graal.replacements.Snippet.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
41
8409
c3fc0e257800 rename: SnippetIntrinsificationPhase -> NodeIntrinsificationPhase
Doug Simon <doug.simon@oracle.com>
parents: 8378
diff changeset
42 /**
c3fc0e257800 rename: SnippetIntrinsificationPhase -> NodeIntrinsificationPhase
Doug Simon <doug.simon@oracle.com>
parents: 8378
diff changeset
43 * Replaces calls to {@link NodeIntrinsic}s with nodes and calls to methods annotated with
c3fc0e257800 rename: SnippetIntrinsificationPhase -> NodeIntrinsificationPhase
Doug Simon <doug.simon@oracle.com>
parents: 8378
diff changeset
44 * {@link Fold} with the result of invoking the annotated method via reflection.
c3fc0e257800 rename: SnippetIntrinsificationPhase -> NodeIntrinsificationPhase
Doug Simon <doug.simon@oracle.com>
parents: 8378
diff changeset
45 */
c3fc0e257800 rename: SnippetIntrinsificationPhase -> NodeIntrinsificationPhase
Doug Simon <doug.simon@oracle.com>
parents: 8378
diff changeset
46 public class NodeIntrinsificationPhase extends Phase {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47
5755
12e5956a8fdd Use MetaAccessProvider instead of CodeCacheProvider wherever possible.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5719
diff changeset
48 private final MetaAccessProvider runtime;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
49 private final BoxingMethodPool pool;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
50
8409
c3fc0e257800 rename: SnippetIntrinsificationPhase -> NodeIntrinsificationPhase
Doug Simon <doug.simon@oracle.com>
parents: 8378
diff changeset
51 public NodeIntrinsificationPhase(MetaAccessProvider runtime, BoxingMethodPool pool) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
52 this.runtime = runtime;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
53 this.pool = pool;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
54 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
55
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
56 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
57 protected void run(StructuredGraph graph) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
58 for (Invoke i : graph.getInvokes()) {
8175
11298242e782 removed use of NonConstantParameterError (GRAAL-147)
Doug Simon <doug.simon@oracle.com>
parents: 7897
diff changeset
59 if (i.callTarget() instanceof MethodCallTargetNode) {
11298242e782 removed use of NonConstantParameterError (GRAAL-147)
Doug Simon <doug.simon@oracle.com>
parents: 7897
diff changeset
60 tryIntrinsify(i);
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
61 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
62 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
63 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
64
8575
ea3ae49a7fa3 NodeIntrinsifcationPhase: allow non-static @Fold methods
Mick Jordan <mick.jordan@oracle.com>
parents: 8487
diff changeset
65 public static Class<?>[] signatureToTypes(Signature signature, JavaType receiverType, ResolvedJavaType accessingClass) {
ea3ae49a7fa3 NodeIntrinsifcationPhase: allow non-static @Fold methods
Mick Jordan <mick.jordan@oracle.com>
parents: 8487
diff changeset
66 int count = signature.getParameterCount(receiverType != null);
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7257
diff changeset
67 Class<?>[] result = new Class<?>[count];
8575
ea3ae49a7fa3 NodeIntrinsifcationPhase: allow non-static @Fold methods
Mick Jordan <mick.jordan@oracle.com>
parents: 8487
diff changeset
68 int j = 0;
ea3ae49a7fa3 NodeIntrinsifcationPhase: allow non-static @Fold methods
Mick Jordan <mick.jordan@oracle.com>
parents: 8487
diff changeset
69 if (receiverType != null) {
ea3ae49a7fa3 NodeIntrinsifcationPhase: allow non-static @Fold methods
Mick Jordan <mick.jordan@oracle.com>
parents: 8487
diff changeset
70 result[0] = getMirrorOrFail(receiverType.resolve(accessingClass), Thread.currentThread().getContextClassLoader());
ea3ae49a7fa3 NodeIntrinsifcationPhase: allow non-static @Fold methods
Mick Jordan <mick.jordan@oracle.com>
parents: 8487
diff changeset
71 j = 1;
ea3ae49a7fa3 NodeIntrinsifcationPhase: allow non-static @Fold methods
Mick Jordan <mick.jordan@oracle.com>
parents: 8487
diff changeset
72 }
ea3ae49a7fa3 NodeIntrinsifcationPhase: allow non-static @Fold methods
Mick Jordan <mick.jordan@oracle.com>
parents: 8487
diff changeset
73 for (int i = 0; i + j < result.length; ++i) {
ea3ae49a7fa3 NodeIntrinsifcationPhase: allow non-static @Fold methods
Mick Jordan <mick.jordan@oracle.com>
parents: 8487
diff changeset
74 result[i + j] = getMirrorOrFail(signature.getParameterType(i, accessingClass).resolve(accessingClass), Thread.currentThread().getContextClassLoader());
7054
5d4676ae84a4 removed usages of ResolvedJavaType.toJava() from bytecode interpreter
Doug Simon <doug.simon@oracle.com>
parents: 7027
diff changeset
75 }
5d4676ae84a4 removed usages of ResolvedJavaType.toJava() from bytecode interpreter
Doug Simon <doug.simon@oracle.com>
parents: 7027
diff changeset
76 return result;
5d4676ae84a4 removed usages of ResolvedJavaType.toJava() from bytecode interpreter
Doug Simon <doug.simon@oracle.com>
parents: 7027
diff changeset
77 }
5d4676ae84a4 removed usages of ResolvedJavaType.toJava() from bytecode interpreter
Doug Simon <doug.simon@oracle.com>
parents: 7027
diff changeset
78
8175
11298242e782 removed use of NonConstantParameterError (GRAAL-147)
Doug Simon <doug.simon@oracle.com>
parents: 7897
diff changeset
79 private boolean tryIntrinsify(Invoke invoke) {
6409
823a2978e7ba Lowering of call targets to direct / indirect call targets
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6408
diff changeset
80 ResolvedJavaMethod target = invoke.methodCallTarget().targetMethod();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
81 NodeIntrinsic intrinsic = target.getAnnotation(Node.NodeIntrinsic.class);
7027
58dbea9fb973 CompilerToVM.lookupType() now fails with an exception if eagerResolve is true and resolution fails
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
82 ResolvedJavaType declaringClass = target.getDeclaringClass();
8575
ea3ae49a7fa3 NodeIntrinsifcationPhase: allow non-static @Fold methods
Mick Jordan <mick.jordan@oracle.com>
parents: 8487
diff changeset
83 JavaType receiverType = invoke.methodCallTarget().isStatic() ? null : declaringClass;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
84 if (intrinsic != null) {
5576
a4d0ded32ddd moved @Fold from Node.java to Snippet.java
Doug Simon <doug.simon@oracle.com>
parents: 5572
diff changeset
85 assert target.getAnnotation(Fold.class) == null;
5175
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
86
8575
ea3ae49a7fa3 NodeIntrinsifcationPhase: allow non-static @Fold methods
Mick Jordan <mick.jordan@oracle.com>
parents: 8487
diff changeset
87 // TODO mjj non-static intrinsic?
ea3ae49a7fa3 NodeIntrinsifcationPhase: allow non-static @Fold methods
Mick Jordan <mick.jordan@oracle.com>
parents: 8487
diff changeset
88 Class<?>[] parameterTypes = signatureToTypes(target.getSignature(), null, declaringClass);
7027
58dbea9fb973 CompilerToVM.lookupType() now fails with an exception if eagerResolve is true and resolution fails
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
89 ResolvedJavaType returnType = target.getSignature().getReturnType(declaringClass).resolve(declaringClass);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
90
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
91 // Prepare the arguments for the reflective constructor call on the node class.
5175
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
92 Object[] nodeConstructorArguments = prepareArguments(invoke, parameterTypes, target, false);
8175
11298242e782 removed use of NonConstantParameterError (GRAAL-147)
Doug Simon <doug.simon@oracle.com>
parents: 7897
diff changeset
93 if (nodeConstructorArguments == null) {
11298242e782 removed use of NonConstantParameterError (GRAAL-147)
Doug Simon <doug.simon@oracle.com>
parents: 7897
diff changeset
94 return false;
11298242e782 removed use of NonConstantParameterError (GRAAL-147)
Doug Simon <doug.simon@oracle.com>
parents: 7897
diff changeset
95 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
96
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
97 // Create the new node instance.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7257
diff changeset
98 Class<?> c = getNodeClass(target, intrinsic);
8487
8e022657ca0b support for constructors corresponding to node intrinsics to take a leading MetaAccessProvider argument that is automatically filled in during node intrinsification
Doug Simon <doug.simon@oracle.com>
parents: 8416
diff changeset
99 Node newInstance = createNodeInstance(runtime, c, parameterTypes, returnType, intrinsic.setStampFromReturnType(), nodeConstructorArguments);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
100
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
101 // Replace the invoke with the new node.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
102 invoke.node().graph().add(newInstance);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
103 invoke.intrinsify(newInstance);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
104
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
105 // Clean up checkcast instructions inserted by javac if the return type is generic.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
106 cleanUpReturnCheckCast(newInstance);
5576
a4d0ded32ddd moved @Fold from Node.java to Snippet.java
Doug Simon <doug.simon@oracle.com>
parents: 5572
diff changeset
107 } else if (target.getAnnotation(Fold.class) != null) {
8575
ea3ae49a7fa3 NodeIntrinsifcationPhase: allow non-static @Fold methods
Mick Jordan <mick.jordan@oracle.com>
parents: 8487
diff changeset
108 Class<?>[] parameterTypes = signatureToTypes(target.getSignature(), receiverType, declaringClass);
5175
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
109
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
110 // Prepare the arguments for the reflective method call
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
111 Object[] arguments = prepareArguments(invoke, parameterTypes, target, true);
8175
11298242e782 removed use of NonConstantParameterError (GRAAL-147)
Doug Simon <doug.simon@oracle.com>
parents: 7897
diff changeset
112 if (arguments == null) {
11298242e782 removed use of NonConstantParameterError (GRAAL-147)
Doug Simon <doug.simon@oracle.com>
parents: 7897
diff changeset
113 return false;
11298242e782 removed use of NonConstantParameterError (GRAAL-147)
Doug Simon <doug.simon@oracle.com>
parents: 7897
diff changeset
114 }
5175
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
115 Object receiver = null;
6409
823a2978e7ba Lowering of call targets to direct / indirect call targets
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6408
diff changeset
116 if (!invoke.methodCallTarget().isStatic()) {
5175
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
117 receiver = arguments[0];
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
118 arguments = Arrays.asList(arguments).subList(1, arguments.length).toArray();
8575
ea3ae49a7fa3 NodeIntrinsifcationPhase: allow non-static @Fold methods
Mick Jordan <mick.jordan@oracle.com>
parents: 8487
diff changeset
119 parameterTypes = Arrays.asList(parameterTypes).subList(1, parameterTypes.length).toArray(new Class<?>[parameterTypes.length - 1]);
5175
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
120 }
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
121
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
122 // Call the method
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7257
diff changeset
123 Constant constant = callMethod(target.getSignature().getReturnKind(), getMirrorOrFail(declaringClass, Thread.currentThread().getContextClassLoader()), target.getName(), parameterTypes,
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7257
diff changeset
124 receiver, arguments);
5175
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
125
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
126 if (constant != null) {
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
127 // Replace the invoke with the result of the call
5572
8f9c9d372e31 small renaming and doc fixes
Lukas Stadler <lukas.stadler@jku.at>
parents: 5563
diff changeset
128 ConstantNode node = ConstantNode.forConstant(constant, runtime, invoke.node().graph());
5175
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
129 invoke.intrinsify(node);
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
130
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
131 // Clean up checkcast instructions inserted by javac if the return type is generic.
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
132 cleanUpReturnCheckCast(node);
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
133 } else {
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
134 // Remove the invoke
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
135 invoke.intrinsify(null);
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
136 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
137 }
8175
11298242e782 removed use of NonConstantParameterError (GRAAL-147)
Doug Simon <doug.simon@oracle.com>
parents: 7897
diff changeset
138 return true;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
139 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
140
5175
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
141 /**
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
142 * Converts the arguments of an invoke node to object values suitable for use as the arguments
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
143 * to a reflective invocation of a Java constructor or method.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7257
diff changeset
144 *
5175
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
145 * @param folding specifies if the invocation is for handling a {@link Fold} annotation
8175
11298242e782 removed use of NonConstantParameterError (GRAAL-147)
Doug Simon <doug.simon@oracle.com>
parents: 7897
diff changeset
146 * @return the arguments for the reflective invocation or null if an argument of {@code invoke}
11298242e782 removed use of NonConstantParameterError (GRAAL-147)
Doug Simon <doug.simon@oracle.com>
parents: 7897
diff changeset
147 * that is expected to be constant isn't
5175
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
148 */
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7257
diff changeset
149 private Object[] prepareArguments(Invoke invoke, Class<?>[] parameterTypes, ResolvedJavaMethod target, boolean folding) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
150 NodeInputList<ValueNode> arguments = invoke.callTarget().arguments();
5175
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
151 Object[] reflectionCallArguments = new Object[arguments.size()];
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
152 for (int i = 0; i < reflectionCallArguments.length; ++i) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
153 int parameterIndex = i;
6409
823a2978e7ba Lowering of call targets to direct / indirect call targets
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6408
diff changeset
154 if (!invoke.methodCallTarget().isStatic()) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
155 parameterIndex--;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
156 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
157 ValueNode argument = tryBoxingElimination(parameterIndex, target, arguments.get(i));
5719
429accae15aa moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents: 5663
diff changeset
158 if (folding || MetaUtil.getParameterAnnotation(ConstantNodeParameter.class, parameterIndex, target) != null) {
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
159 if (!(argument instanceof ConstantNode)) {
8175
11298242e782 removed use of NonConstantParameterError (GRAAL-147)
Doug Simon <doug.simon@oracle.com>
parents: 7897
diff changeset
160 return null;
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
161 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
162 ConstantNode constantNode = (ConstantNode) argument;
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5531
diff changeset
163 Constant constant = constantNode.asConstant();
6539
2463eb24b644 Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6526
diff changeset
164 Object o = constant.asBoxedValue();
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7257
diff changeset
165 if (o instanceof Class<?>) {
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7257
diff changeset
166 reflectionCallArguments[i] = runtime.lookupJavaType((Class<?>) o);
5541
b4c406861c33 More renamings to drop Ri* prefix completely. Deleted graph.BitMap class and replaced with java.util.BitSet.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5540
diff changeset
167 parameterTypes[i] = ResolvedJavaType.class;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
168 } else {
5463
b6311d367bd6 support use of boolean, byte, char and short constant arguments in @NodeIntrinsic methods
Doug Simon <doug.simon@oracle.com>
parents: 5372
diff changeset
169 if (parameterTypes[i] == boolean.class) {
b6311d367bd6 support use of boolean, byte, char and short constant arguments in @NodeIntrinsic methods
Doug Simon <doug.simon@oracle.com>
parents: 5372
diff changeset
170 reflectionCallArguments[i] = Boolean.valueOf(constant.asInt() != 0);
b6311d367bd6 support use of boolean, byte, char and short constant arguments in @NodeIntrinsic methods
Doug Simon <doug.simon@oracle.com>
parents: 5372
diff changeset
171 } else if (parameterTypes[i] == byte.class) {
b6311d367bd6 support use of boolean, byte, char and short constant arguments in @NodeIntrinsic methods
Doug Simon <doug.simon@oracle.com>
parents: 5372
diff changeset
172 reflectionCallArguments[i] = Byte.valueOf((byte) constant.asInt());
b6311d367bd6 support use of boolean, byte, char and short constant arguments in @NodeIntrinsic methods
Doug Simon <doug.simon@oracle.com>
parents: 5372
diff changeset
173 } else if (parameterTypes[i] == short.class) {
b6311d367bd6 support use of boolean, byte, char and short constant arguments in @NodeIntrinsic methods
Doug Simon <doug.simon@oracle.com>
parents: 5372
diff changeset
174 reflectionCallArguments[i] = Short.valueOf((short) constant.asInt());
b6311d367bd6 support use of boolean, byte, char and short constant arguments in @NodeIntrinsic methods
Doug Simon <doug.simon@oracle.com>
parents: 5372
diff changeset
175 } else if (parameterTypes[i] == char.class) {
b6311d367bd6 support use of boolean, byte, char and short constant arguments in @NodeIntrinsic methods
Doug Simon <doug.simon@oracle.com>
parents: 5372
diff changeset
176 reflectionCallArguments[i] = Character.valueOf((char) constant.asInt());
b6311d367bd6 support use of boolean, byte, char and short constant arguments in @NodeIntrinsic methods
Doug Simon <doug.simon@oracle.com>
parents: 5372
diff changeset
177 } else {
b6311d367bd6 support use of boolean, byte, char and short constant arguments in @NodeIntrinsic methods
Doug Simon <doug.simon@oracle.com>
parents: 5372
diff changeset
178 reflectionCallArguments[i] = o;
b6311d367bd6 support use of boolean, byte, char and short constant arguments in @NodeIntrinsic methods
Doug Simon <doug.simon@oracle.com>
parents: 5372
diff changeset
179 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
180 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
181 } else {
5175
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
182 reflectionCallArguments[i] = argument;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
183 parameterTypes[i] = ValueNode.class;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
184 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
185 }
5175
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
186 return reflectionCallArguments;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
187 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
188
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7257
diff changeset
189 private static Class<?> getNodeClass(ResolvedJavaMethod target, NodeIntrinsic intrinsic) {
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7257
diff changeset
190 Class<?> result = intrinsic.value();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
191 if (result == NodeIntrinsic.class) {
7129
04632e376bd8 Provide Thread context class loader to getMirrorOrFail. This is a workaround until the Graal API is complete enough so that getMirrorOrFail is not necessary at all.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7123
diff changeset
192 return getMirrorOrFail(target.getDeclaringClass(), Thread.currentThread().getContextClassLoader());
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
193 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
194 assert Node.class.isAssignableFrom(result);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
195 return result;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
196 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
197
5541
b4c406861c33 More renamings to drop Ri* prefix completely. Deleted graph.BitMap class and replaced with java.util.BitSet.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5540
diff changeset
198 private ValueNode tryBoxingElimination(int parameterIndex, ResolvedJavaMethod target, ValueNode node) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
199 if (parameterIndex >= 0) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
200 Type type = target.getGenericParameterTypes()[parameterIndex];
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
201 if (type instanceof TypeVariable) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
202 TypeVariable typeVariable = (TypeVariable) type;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
203 if (typeVariable.getBounds().length == 1) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
204 Type boundType = typeVariable.getBounds()[0];
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
205 if (boundType instanceof Class && ((Class) boundType).getSuperclass() == null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
206 // Unbound generic => try boxing elimination
7123
b914b9b4c578 graal.graph refactorings
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7098
diff changeset
207 if (node.usages().count() == 2) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
208 if (node instanceof Invoke) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
209 Invoke invokeNode = (Invoke) node;
6409
823a2978e7ba Lowering of call targets to direct / indirect call targets
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6408
diff changeset
210 MethodCallTargetNode callTarget = invokeNode.methodCallTarget();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
211 if (pool.isBoxingMethod(callTarget.targetMethod())) {
4310
72d099e5be61 more CanonicalizerPhase simplifications, added Simplifiable interface
Lukas Stadler <lukas.stadler@jku.at>
parents: 4309
diff changeset
212 FrameState stateAfter = invokeNode.stateAfter();
7123
b914b9b4c578 graal.graph refactorings
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7098
diff changeset
213 assert stateAfter.usages().count() == 1;
4310
72d099e5be61 more CanonicalizerPhase simplifications, added Simplifiable interface
Lukas Stadler <lukas.stadler@jku.at>
parents: 4309
diff changeset
214 invokeNode.node().replaceAtUsages(null);
72d099e5be61 more CanonicalizerPhase simplifications, added Simplifiable interface
Lukas Stadler <lukas.stadler@jku.at>
parents: 4309
diff changeset
215 ValueNode result = callTarget.arguments().get(0);
72d099e5be61 more CanonicalizerPhase simplifications, added Simplifiable interface
Lukas Stadler <lukas.stadler@jku.at>
parents: 4309
diff changeset
216 StructuredGraph graph = (StructuredGraph) node.graph();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
217 if (invokeNode instanceof InvokeWithExceptionNode) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
218 // Destroy exception edge & clear stateAfter.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
219 InvokeWithExceptionNode invokeWithExceptionNode = (InvokeWithExceptionNode) invokeNode;
4310
72d099e5be61 more CanonicalizerPhase simplifications, added Simplifiable interface
Lukas Stadler <lukas.stadler@jku.at>
parents: 4309
diff changeset
220
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
221 invokeWithExceptionNode.killExceptionEdge();
7257
b1ebd583be14 Remove @Successor private final NodeSuccessorList<BeginNode> blockSuccessors from ControlSplitNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7129
diff changeset
222 graph.removeSplit(invokeWithExceptionNode, invokeWithExceptionNode.next());
4310
72d099e5be61 more CanonicalizerPhase simplifications, added Simplifiable interface
Lukas Stadler <lukas.stadler@jku.at>
parents: 4309
diff changeset
223 } else {
72d099e5be61 more CanonicalizerPhase simplifications, added Simplifiable interface
Lukas Stadler <lukas.stadler@jku.at>
parents: 4309
diff changeset
224 graph.removeFixed((InvokeNode) invokeNode);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
225 }
4310
72d099e5be61 more CanonicalizerPhase simplifications, added Simplifiable interface
Lukas Stadler <lukas.stadler@jku.at>
parents: 4309
diff changeset
226 stateAfter.safeDelete();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
227 GraphUtil.propagateKill(callTarget);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
228 return result;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
229 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
230 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
231 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
232 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
233 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
234 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
235 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
236 return node;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
237 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
238
5578
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
239 private static Class asBoxedType(Class type) {
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
240 if (!type.isPrimitive()) {
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
241 return type;
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
242 }
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
243
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
244 if (Boolean.TYPE == type) {
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
245 return Boolean.class;
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
246 }
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
247 if (Character.TYPE == type) {
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
248 return Character.class;
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
249 }
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
250 if (Byte.TYPE == type) {
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
251 return Byte.class;
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
252 }
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
253 if (Short.TYPE == type) {
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
254 return Short.class;
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
255 }
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
256 if (Integer.TYPE == type) {
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
257 return Integer.class;
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
258 }
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
259 if (Long.TYPE == type) {
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
260 return Long.class;
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
261 }
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
262 if (Float.TYPE == type) {
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
263 return Float.class;
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
264 }
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
265 assert Double.TYPE == type;
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
266 return Double.class;
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
267 }
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
268
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
269 static final int VARARGS = 0x00000080;
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
270
8487
8e022657ca0b support for constructors corresponding to node intrinsics to take a leading MetaAccessProvider argument that is automatically filled in during node intrinsification
Doug Simon <doug.simon@oracle.com>
parents: 8416
diff changeset
271 private static Node createNodeInstance(MetaAccessProvider runtime, Class<?> nodeClass, Class<?>[] parameterTypes, ResolvedJavaType returnType, boolean setStampFromReturnType,
8e022657ca0b support for constructors corresponding to node intrinsics to take a leading MetaAccessProvider argument that is automatically filled in during node intrinsification
Doug Simon <doug.simon@oracle.com>
parents: 8416
diff changeset
272 Object[] nodeConstructorArguments) {
5578
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
273 Object[] arguments = null;
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7257
diff changeset
274 Constructor<?> constructor = null;
8487
8e022657ca0b support for constructors corresponding to node intrinsics to take a leading MetaAccessProvider argument that is automatically filled in during node intrinsification
Doug Simon <doug.simon@oracle.com>
parents: 8416
diff changeset
275 boolean needsMetaAccessProviderArgument = false;
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7257
diff changeset
276 nextConstructor: for (Constructor c : nodeClass.getDeclaredConstructors()) {
8487
8e022657ca0b support for constructors corresponding to node intrinsics to take a leading MetaAccessProvider argument that is automatically filled in during node intrinsification
Doug Simon <doug.simon@oracle.com>
parents: 8416
diff changeset
277 needsMetaAccessProviderArgument = false;
5578
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
278 Class[] signature = c.getParameterTypes();
8487
8e022657ca0b support for constructors corresponding to node intrinsics to take a leading MetaAccessProvider argument that is automatically filled in during node intrinsification
Doug Simon <doug.simon@oracle.com>
parents: 8416
diff changeset
279 if (signature.length != 0 && signature[0] == MetaAccessProvider.class) {
8e022657ca0b support for constructors corresponding to node intrinsics to take a leading MetaAccessProvider argument that is automatically filled in during node intrinsification
Doug Simon <doug.simon@oracle.com>
parents: 8416
diff changeset
280 // Chop off the MetaAccessProvider first parameter
8e022657ca0b support for constructors corresponding to node intrinsics to take a leading MetaAccessProvider argument that is automatically filled in during node intrinsification
Doug Simon <doug.simon@oracle.com>
parents: 8416
diff changeset
281 signature = Arrays.copyOfRange(signature, 1, signature.length);
8e022657ca0b support for constructors corresponding to node intrinsics to take a leading MetaAccessProvider argument that is automatically filled in during node intrinsification
Doug Simon <doug.simon@oracle.com>
parents: 8416
diff changeset
282 needsMetaAccessProviderArgument = true;
8e022657ca0b support for constructors corresponding to node intrinsics to take a leading MetaAccessProvider argument that is automatically filled in during node intrinsification
Doug Simon <doug.simon@oracle.com>
parents: 8416
diff changeset
283 }
5578
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
284 if ((c.getModifiers() & VARARGS) != 0) {
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
285 int fixedArgs = signature.length - 1;
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
286 if (parameterTypes.length < fixedArgs) {
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
287 continue nextConstructor;
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
288 }
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
289
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
290 for (int i = 0; i < fixedArgs; i++) {
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
291 if (!parameterTypes[i].equals(signature[i])) {
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
292 continue nextConstructor;
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
293 }
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
294 }
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
295
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
296 Class componentType = signature[fixedArgs].getComponentType();
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
297 assert componentType != null : "expected last parameter of varargs constructor " + c + " to be an array type";
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
298 Class boxedType = asBoxedType(componentType);
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
299 for (int i = fixedArgs; i < nodeConstructorArguments.length; i++) {
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
300 if (!boxedType.isInstance(nodeConstructorArguments[i])) {
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
301 continue nextConstructor;
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
302 }
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
303 }
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
304 arguments = Arrays.copyOf(nodeConstructorArguments, fixedArgs + 1);
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
305 int varargsLength = nodeConstructorArguments.length - fixedArgs;
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
306 Object varargs = Array.newInstance(componentType, varargsLength);
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
307 for (int i = fixedArgs; i < nodeConstructorArguments.length; i++) {
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
308 Array.set(varargs, i - fixedArgs, nodeConstructorArguments[i]);
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
309 }
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
310 arguments[fixedArgs] = varargs;
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
311 constructor = c;
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
312 break;
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
313 } else if (Arrays.equals(parameterTypes, signature)) {
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
314 arguments = nodeConstructorArguments;
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
315 constructor = c;
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
316 break;
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
317 }
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
318 }
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
319 if (constructor == null) {
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
320 throw new GraalInternalError("Could not find constructor in " + nodeClass + " compatible with signature " + Arrays.toString(parameterTypes));
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
321 }
8487
8e022657ca0b support for constructors corresponding to node intrinsics to take a leading MetaAccessProvider argument that is automatically filled in during node intrinsification
Doug Simon <doug.simon@oracle.com>
parents: 8416
diff changeset
322 if (needsMetaAccessProviderArgument) {
8e022657ca0b support for constructors corresponding to node intrinsics to take a leading MetaAccessProvider argument that is automatically filled in during node intrinsification
Doug Simon <doug.simon@oracle.com>
parents: 8416
diff changeset
323 Object[] copy = new Object[arguments.length + 1];
8e022657ca0b support for constructors corresponding to node intrinsics to take a leading MetaAccessProvider argument that is automatically filled in during node intrinsification
Doug Simon <doug.simon@oracle.com>
parents: 8416
diff changeset
324 System.arraycopy(arguments, 0, copy, 1, arguments.length);
8e022657ca0b support for constructors corresponding to node intrinsics to take a leading MetaAccessProvider argument that is automatically filled in during node intrinsification
Doug Simon <doug.simon@oracle.com>
parents: 8416
diff changeset
325 copy[0] = runtime;
8e022657ca0b support for constructors corresponding to node intrinsics to take a leading MetaAccessProvider argument that is automatically filled in during node intrinsification
Doug Simon <doug.simon@oracle.com>
parents: 8416
diff changeset
326 arguments = copy;
8e022657ca0b support for constructors corresponding to node intrinsics to take a leading MetaAccessProvider argument that is automatically filled in during node intrinsification
Doug Simon <doug.simon@oracle.com>
parents: 8416
diff changeset
327 }
5578
445dd1a9b8d8 enhanced @NodeIntrinsic intrinsification to take into account varargs in the node constructors when matching call arguments
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
328 constructor.setAccessible(true);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
329 try {
6419
b74402a7079b fixed oopmap bug caused by unsafe mixing of word and object values
Doug Simon <doug.simon@oracle.com>
parents: 6409
diff changeset
330 ValueNode intrinsicNode = (ValueNode) constructor.newInstance(arguments);
b74402a7079b fixed oopmap bug caused by unsafe mixing of word and object values
Doug Simon <doug.simon@oracle.com>
parents: 6409
diff changeset
331 if (setStampFromReturnType) {
7098
e23980f4a890 Cleanup of Kind class: remove isXxx methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7059
diff changeset
332 if (returnType.getKind() == Kind.Object) {
6419
b74402a7079b fixed oopmap bug caused by unsafe mixing of word and object values
Doug Simon <doug.simon@oracle.com>
parents: 6409
diff changeset
333 intrinsicNode.setStamp(StampFactory.declared(returnType));
b74402a7079b fixed oopmap bug caused by unsafe mixing of word and object values
Doug Simon <doug.simon@oracle.com>
parents: 6409
diff changeset
334 } else {
6539
2463eb24b644 Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6526
diff changeset
335 intrinsicNode.setStamp(StampFactory.forKind(returnType.getKind()));
6419
b74402a7079b fixed oopmap bug caused by unsafe mixing of word and object values
Doug Simon <doug.simon@oracle.com>
parents: 6409
diff changeset
336 }
b74402a7079b fixed oopmap bug caused by unsafe mixing of word and object values
Doug Simon <doug.simon@oracle.com>
parents: 6409
diff changeset
337 }
b74402a7079b fixed oopmap bug caused by unsafe mixing of word and object values
Doug Simon <doug.simon@oracle.com>
parents: 6409
diff changeset
338 return intrinsicNode;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
339 } catch (Exception e) {
5463
b6311d367bd6 support use of boolean, byte, char and short constant arguments in @NodeIntrinsic methods
Doug Simon <doug.simon@oracle.com>
parents: 5372
diff changeset
340 throw new RuntimeException(constructor + Arrays.toString(nodeConstructorArguments), e);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
341 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
342 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
343
5175
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
344 /**
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
345 * Calls a Java method via reflection.
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
346 */
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7257
diff changeset
347 private static Constant callMethod(Kind returnKind, Class<?> holder, String name, Class<?>[] parameterTypes, Object receiver, Object[] arguments) {
5175
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
348 Method method;
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
349 try {
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
350 method = holder.getDeclaredMethod(name, parameterTypes);
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
351 method.setAccessible(true);
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
352 } catch (Exception e) {
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
353 throw new RuntimeException(e);
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
354 }
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
355 try {
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
356 Object result = method.invoke(receiver, arguments);
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
357 if (result == null) {
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
358 return null;
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
359 }
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5531
diff changeset
360 return Constant.forBoxed(returnKind, result);
5175
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
361 } catch (Exception e) {
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
362 throw new RuntimeException(e);
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
363 }
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
364 }
a8c5283a835c added @Fold to folding methods during snippet intrinsification; replaced CardTableStartNode and CardTableShiftNode with @Fold methods
Doug Simon <doug.simon@oracle.com>
parents: 5061
diff changeset
365
5563
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5547
diff changeset
366 private static String sourceLocation(Node n) {
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5547
diff changeset
367 String loc = GraphUtil.approxSourceLocation(n);
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5547
diff changeset
368 return loc == null ? "<unknown>" : loc;
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5547
diff changeset
369 }
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5547
diff changeset
370
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
371 public void cleanUpReturnCheckCast(Node newInstance) {
6408
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 5764
diff changeset
372 if (newInstance instanceof ValueNode && (((ValueNode) newInstance).kind() != Kind.Object || ((ValueNode) newInstance).stamp() == StampFactory.forNodeIntrinsic())) {
4309
4a609a685fa4 changes to Node structures:
Lukas Stadler <lukas.stadler@jku.at>
parents: 4199
diff changeset
373 StructuredGraph graph = (StructuredGraph) newInstance.graph();
4411
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4310
diff changeset
374 for (CheckCastNode checkCastNode : newInstance.usages().filter(CheckCastNode.class).snapshot()) {
7897
a58851061377 rename ValueProxyNode to ProxyNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 7530
diff changeset
375 for (ProxyNode vpn : checkCastNode.usages().filter(ProxyNode.class).snapshot()) {
5210
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5175
diff changeset
376 graph.replaceFloating(vpn, checkCastNode);
e3e7542d78b7 Loop-closed form GraphBuidling
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5175
diff changeset
377 }
4411
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4310
diff changeset
378 for (Node checkCastUsage : checkCastNode.usages().snapshot()) {
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4310
diff changeset
379 if (checkCastUsage instanceof ValueAnchorNode) {
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4310
diff changeset
380 ValueAnchorNode valueAnchorNode = (ValueAnchorNode) checkCastUsage;
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4310
diff changeset
381 graph.removeFixed(valueAnchorNode);
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4310
diff changeset
382 } else if (checkCastUsage instanceof MethodCallTargetNode) {
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4310
diff changeset
383 MethodCallTargetNode checkCastCallTarget = (MethodCallTargetNode) checkCastUsage;
8364
a2f83d256423 Eliminate checkcast between two NodeIntrinsic calls.
Roland Schatz <roland.schatz@oracle.com>
parents: 8175
diff changeset
384 if (pool.isUnboxingMethod(checkCastCallTarget.targetMethod())) {
a2f83d256423 Eliminate checkcast between two NodeIntrinsic calls.
Roland Schatz <roland.schatz@oracle.com>
parents: 8175
diff changeset
385 Invoke invokeNode = checkCastCallTarget.invoke();
a2f83d256423 Eliminate checkcast between two NodeIntrinsic calls.
Roland Schatz <roland.schatz@oracle.com>
parents: 8175
diff changeset
386 invokeNode.node().replaceAtUsages(newInstance);
a2f83d256423 Eliminate checkcast between two NodeIntrinsic calls.
Roland Schatz <roland.schatz@oracle.com>
parents: 8175
diff changeset
387 if (invokeNode instanceof InvokeWithExceptionNode) {
a2f83d256423 Eliminate checkcast between two NodeIntrinsic calls.
Roland Schatz <roland.schatz@oracle.com>
parents: 8175
diff changeset
388 // Destroy exception edge & clear stateAfter.
a2f83d256423 Eliminate checkcast between two NodeIntrinsic calls.
Roland Schatz <roland.schatz@oracle.com>
parents: 8175
diff changeset
389 InvokeWithExceptionNode invokeWithExceptionNode = (InvokeWithExceptionNode) invokeNode;
4309
4a609a685fa4 changes to Node structures:
Lukas Stadler <lukas.stadler@jku.at>
parents: 4199
diff changeset
390
8364
a2f83d256423 Eliminate checkcast between two NodeIntrinsic calls.
Roland Schatz <roland.schatz@oracle.com>
parents: 8175
diff changeset
391 invokeWithExceptionNode.killExceptionEdge();
a2f83d256423 Eliminate checkcast between two NodeIntrinsic calls.
Roland Schatz <roland.schatz@oracle.com>
parents: 8175
diff changeset
392 graph.removeSplit(invokeWithExceptionNode, invokeWithExceptionNode.next());
a2f83d256423 Eliminate checkcast between two NodeIntrinsic calls.
Roland Schatz <roland.schatz@oracle.com>
parents: 8175
diff changeset
393 } else {
a2f83d256423 Eliminate checkcast between two NodeIntrinsic calls.
Roland Schatz <roland.schatz@oracle.com>
parents: 8175
diff changeset
394 graph.removeFixed((InvokeNode) invokeNode);
a2f83d256423 Eliminate checkcast between two NodeIntrinsic calls.
Roland Schatz <roland.schatz@oracle.com>
parents: 8175
diff changeset
395 }
a2f83d256423 Eliminate checkcast between two NodeIntrinsic calls.
Roland Schatz <roland.schatz@oracle.com>
parents: 8175
diff changeset
396 checkCastCallTarget.safeDelete();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
397 } else {
8364
a2f83d256423 Eliminate checkcast between two NodeIntrinsic calls.
Roland Schatz <roland.schatz@oracle.com>
parents: 8175
diff changeset
398 assert checkCastCallTarget.targetMethod().getAnnotation(NodeIntrinsic.class) != null : "checkcast at " + sourceLocation(checkCastNode) +
a2f83d256423 Eliminate checkcast between two NodeIntrinsic calls.
Roland Schatz <roland.schatz@oracle.com>
parents: 8175
diff changeset
399 " not used by an unboxing method or node intrinsic, but by a call at " + sourceLocation(checkCastCallTarget.usages().first()) + " to " +
a2f83d256423 Eliminate checkcast between two NodeIntrinsic calls.
Roland Schatz <roland.schatz@oracle.com>
parents: 8175
diff changeset
400 checkCastCallTarget.targetMethod();
a2f83d256423 Eliminate checkcast between two NodeIntrinsic calls.
Roland Schatz <roland.schatz@oracle.com>
parents: 8175
diff changeset
401 checkCastUsage.replaceFirstInput(checkCastNode, checkCastNode.object());
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
402 }
4411
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4310
diff changeset
403 } else if (checkCastUsage instanceof FrameState) {
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4310
diff changeset
404 checkCastUsage.replaceFirstInput(checkCastNode, null);
6408
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 5764
diff changeset
405 } else if (checkCastUsage instanceof ReturnNode && checkCastNode.object().stamp() == StampFactory.forNodeIntrinsic()) {
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 5764
diff changeset
406 checkCastUsage.replaceFirstInput(checkCastNode, checkCastNode.object());
4411
cd2b68ef8e23 cleanup around filter and predicates :
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4310
diff changeset
407 } else {
5563
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents: 5547
diff changeset
408 assert false : sourceLocation(checkCastUsage) + " has unexpected usage " + checkCastUsage + " of checkcast at " + sourceLocation(checkCastNode);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
409 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
410 }
5372
4485e0edd1af made CheckCastNode be a FixedNode instead of a BooleanNode
Doug Simon <doug.simon@oracle.com>
parents: 5210
diff changeset
411 FixedNode next = checkCastNode.next();
4485e0edd1af made CheckCastNode be a FixedNode instead of a BooleanNode
Doug Simon <doug.simon@oracle.com>
parents: 5210
diff changeset
412 checkCastNode.setNext(null);
5487
9743ae819f73 Move virtual chain help methods from SuperBlock to GraphUtil
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5463
diff changeset
413 checkCastNode.replaceAtPredecessor(next);
5372
4485e0edd1af made CheckCastNode be a FixedNode instead of a BooleanNode
Doug Simon <doug.simon@oracle.com>
parents: 5210
diff changeset
414 GraphUtil.killCFG(checkCastNode);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
415 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
416 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
417 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
418 }