annotate graal/com.oracle.graal.word/src/com/oracle/graal/word/phases/WordTypeVerificationPhase.java @ 18995:a2cb19764970

Rename MergeNode to AbstractMergeNode.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Wed, 28 Jan 2015 01:04:20 +0100
parents f0a8b72315c1
children 14e703edb2ab
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
1 /*
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
4 *
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
8 *
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
13 * accompanied this code).
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
14 *
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
18 *
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
21 * questions.
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
22 */
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.word.phases;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
24
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
25 import com.oracle.graal.api.meta.*;
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14978
diff changeset
26 import com.oracle.graal.api.replacements.*;
15193
96bb07a5d667 Spit up and move GraalInternalError.
Josef Eisl <josef.eisl@jku.at>
parents: 15018
diff changeset
27 import com.oracle.graal.compiler.common.*;
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
28 import com.oracle.graal.graph.*;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
29 import com.oracle.graal.graph.Node.NodeIntrinsic;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
30 import com.oracle.graal.nodes.*;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
31 import com.oracle.graal.nodes.calc.*;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
32 import com.oracle.graal.nodes.java.*;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
33 import com.oracle.graal.nodes.util.*;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
34 import com.oracle.graal.phases.*;
13941
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents: 12570
diff changeset
35 import com.oracle.graal.phases.graph.*;
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
36 import com.oracle.graal.word.*;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
37 import com.oracle.graal.word.Word.Operation;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
38
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
39 /**
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
40 * Verifies invariants that must hold for code that uses the {@link WordBase word type} above and
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
41 * beyond normal bytecode verification.
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
42 */
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
43 public class WordTypeVerificationPhase extends Phase {
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
44
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
45 private final WordTypeRewriterPhase wordAccess;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
46
18465
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18191
diff changeset
47 public WordTypeVerificationPhase(MetaAccessProvider metaAccess, SnippetReflectionProvider snippetReflection, ConstantReflectionProvider constantReflection, Kind wordKind) {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18191
diff changeset
48 this.wordAccess = new WordTypeRewriterPhase(metaAccess, snippetReflection, constantReflection, wordKind);
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
49 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
50
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
51 @Override
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
52 protected void run(StructuredGraph graph) {
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
53 assert verify(graph);
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
54 }
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
55
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
56 protected boolean verify(StructuredGraph inputGraph) {
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
57 /*
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
58 * This is a verification phase, so we do not want to have side effects. Since inferStamps()
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
59 * modifies the stamp of nodes, we copy the graph before running the verification.
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
60 */
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
61 StructuredGraph graph = inputGraph.copy();
13941
a55d85c207be Move stamp inference in its own class, and make it extensible via the ValueAndStampProxy interface
Christian Wimmer <christian.wimmer@oracle.com>
parents: 12570
diff changeset
62 InferStamps.inferStamps(graph);
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
63
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
64 for (ValueNode node : graph.getNodes().filter(ValueNode.class)) {
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
65 for (Node usage : node.usages()) {
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
66 if (usage instanceof AccessMonitorNode) {
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
67 verify(!isWord(node), node, usage, "word value has no monitor");
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
68 } else if (usage instanceof LoadFieldNode) {
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
69 verify(!isWord(node) || ((LoadFieldNode) usage).object() != node, node, usage, "cannot load from word value");
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
70 } else if (usage instanceof StoreFieldNode) {
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
71 verify(!isWord(node) || ((StoreFieldNode) usage).object() != node, node, usage, "cannot store to word value");
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
72 } else if (usage instanceof CheckCastNode) {
16567
164b644daa83 Minor simplification in WordTypeVerificationPhase
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 16480
diff changeset
73 verify(isWord(((CheckCastNode) usage).type()) == isWord(node), node, usage, "word cannot be cast to object, and vice versa");
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
74 } else if (usage instanceof LoadIndexedNode) {
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
75 verify(!isWord(node) || ((LoadIndexedNode) usage).array() != node, node, usage, "cannot load from word value");
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
76 verify(!isWord(node) || ((LoadIndexedNode) usage).index() != node, node, usage, "cannot use word value as index");
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
77 } else if (usage instanceof StoreIndexedNode) {
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
78 verify(!isWord(node) || ((StoreIndexedNode) usage).array() != node, node, usage, "cannot store to word value");
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
79 verify(!isWord(node) || ((StoreIndexedNode) usage).index() != node, node, usage, "cannot use word value as index");
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
80 } else if (usage instanceof MethodCallTargetNode) {
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
81 MethodCallTargetNode callTarget = (MethodCallTargetNode) usage;
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
82 verifyInvoke(node, callTarget);
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
83 } else if (usage instanceof ObjectEqualsNode) {
16207
df6f2365b153 rename of x() to getX(), y() to getY() and object() to getValue()
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15722
diff changeset
84 verify(!isWord(node) || ((ObjectEqualsNode) usage).getX() != node, node, usage, "cannot use word type in comparison");
df6f2365b153 rename of x() to getX(), y() to getY() and object() to getValue()
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15722
diff changeset
85 verify(!isWord(node) || ((ObjectEqualsNode) usage).getY() != node, node, usage, "cannot use word type in comparison");
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
86 } else if (usage instanceof ArrayLengthNode) {
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
87 verify(!isWord(node) || ((ArrayLengthNode) usage).array() != node, node, usage, "cannot get array length from word value");
14978
e302df8bf51c separate subclasses for value and guard phis and proxies
Lukas Stadler <lukas.stadler@oracle.com>
parents: 13941
diff changeset
88 } else if (usage instanceof ValuePhiNode) {
18995
a2cb19764970 Rename MergeNode to AbstractMergeNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18465
diff changeset
89 if (!(node instanceof AbstractMergeNode)) {
14978
e302df8bf51c separate subclasses for value and guard phis and proxies
Lukas Stadler <lukas.stadler@oracle.com>
parents: 13941
diff changeset
90 ValuePhiNode phi = (ValuePhiNode) usage;
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
91 for (ValueNode input : phi.values()) {
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
92 verify(isWord(node) == isWord(input), node, input, "cannot merge word and non-word values");
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
93 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
94 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
95 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
96 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
97 }
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
98 return true;
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
99 }
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
100
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
101 protected void verifyInvoke(ValueNode node, MethodCallTargetNode callTarget) {
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
102 ResolvedJavaMethod method = callTarget.targetMethod();
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
103 if (method.getAnnotation(NodeIntrinsic.class) == null) {
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
104 Invoke invoke = (Invoke) callTarget.usages().first();
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
105 NodeInputList<ValueNode> arguments = callTarget.arguments();
15311
820c6d353358 added ModifiersProvider as superinterface for ResolvedJava[Method|Field|Type] and implemented all checks against modifiers as default methods
Doug Simon <doug.simon@oracle.com>
parents: 15193
diff changeset
106 boolean isStatic = method.isStatic();
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
107 int argc = 0;
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
108 if (!isStatic) {
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
109 ValueNode receiver = arguments.get(argc);
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
110 if (receiver == node && isWord(node)) {
18191
839f97696479 Rename ResolvedJavaMethod.resolvedMethod() to resolveConcreteMethod() the reflect its actual behavior.
Josef Eisl <josef.eisl@jku.at>
parents: 17064
diff changeset
111 ResolvedJavaMethod resolvedMethod = wordAccess.wordImplType.resolveConcreteMethod(method, invoke.getContextType());
16480
10c12d09a8d2 moved format(String format, JavaMethod method) from MetaUtil to be a default method in JavaMethod
Doug Simon <doug.simon@oracle.com>
parents: 16207
diff changeset
112 verify(resolvedMethod != null, node, invoke.asNode(), "cannot resolve method on Word class: " + method.format("%H.%n(%P) %r"));
11698
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
113 Operation operation = resolvedMethod.getAnnotation(Word.Operation.class);
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
114 verify(operation != null, node, invoke.asNode(), "cannot dispatch on word value to non @Operation annotated method " + resolvedMethod);
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
115 }
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
116 argc++;
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
117 }
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
118 Signature signature = method.getSignature();
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
119 for (int i = 0; i < signature.getParameterCount(false); i++) {
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
120 ValueNode argument = arguments.get(argc);
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
121 if (argument == node) {
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
122 ResolvedJavaType type = (ResolvedJavaType) signature.getParameterType(i, method.getDeclaringClass());
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
123 verify(isWord(type) == isWord(argument), node, invoke.asNode(), "cannot pass word value to non-word parameter " + i + " or vice-versa");
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
124 }
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
125 argc++;
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
126 }
4eec2ac671c2 Refactor the WordTypeVerificationPhase to use fewer graph iterations, and invoke it a fewer places
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9721
diff changeset
127 }
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
128 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
129
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
130 private boolean isWord(ValueNode node) {
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
131 return wordAccess.isWord(node);
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
132 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
133
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
134 private boolean isWord(ResolvedJavaType type) {
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
135 return wordAccess.isWord(type);
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
136 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
137
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
138 private static void verify(boolean condition, Node node, Node usage, String message) {
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
139 if (!condition) {
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
140 error(node, usage, message);
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
141 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
142 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
143
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
144 private static void error(Node node, Node usage, String message) {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7302
diff changeset
145 throw new GraalInternalError(String.format("Snippet verification error: %s" + "%n node: %s (%s)" + "%n usage: %s (%s)", message, node, sourceLocation(node), usage, sourceLocation(usage)));
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
146 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
147
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
148 private static String sourceLocation(Node n) {
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
149 if (n instanceof PhiNode) {
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
150 StringBuilder buf = new StringBuilder();
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
151 for (Node usage : n.usages()) {
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
152 String loc = sourceLocation(usage);
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
153 if (!loc.equals("<unknown>")) {
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
154 if (buf.length() != 0) {
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
155 buf.append(", ");
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
156 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
157 buf.append(loc);
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
158 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
159 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
160 return buf.toString();
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
161 } else {
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
162 String loc = GraphUtil.approxSourceLocation(n);
16480
10c12d09a8d2 moved format(String format, JavaMethod method) from MetaUtil to be a default method in JavaMethod
Doug Simon <doug.simon@oracle.com>
parents: 16207
diff changeset
163 return loc == null ? ((StructuredGraph) n.graph()).method().format("method %h.%n") : loc;
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
164 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
165 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
166 }