comparison graal/com.oracle.graal.phases/src/com/oracle/graal/phases/verify/VerifyUsageWithEquals.java @ 11959:23ccaa863eda

made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
author Doug Simon <doug.simon@oracle.com>
date Thu, 10 Oct 2013 16:14:55 +0200
parents eb2def6529bc
children 2c4aa758ee18
comparison
equal deleted inserted replaced
11958:a0f5be106e67 11959:23ccaa863eda
40 40
41 public VerifyUsageWithEquals(Class<?> klass) { 41 public VerifyUsageWithEquals(Class<?> klass) {
42 this.klass = klass; 42 this.klass = klass;
43 } 43 }
44 44
45 private boolean isAssignableType(ValueNode node, MetaAccessProvider runtime) { 45 private boolean isAssignableType(ValueNode node, MetaAccessProvider metaAccess) {
46 if (node.stamp() instanceof ObjectStamp) { 46 if (node.stamp() instanceof ObjectStamp) {
47 ResolvedJavaType valueType = runtime.lookupJavaType(klass); 47 ResolvedJavaType valueType = metaAccess.lookupJavaType(klass);
48 ResolvedJavaType nodeType = ObjectStamp.typeOrNull(node); 48 ResolvedJavaType nodeType = ObjectStamp.typeOrNull(node);
49 49
50 if (nodeType != null && valueType.isAssignableFrom(nodeType)) { 50 if (nodeType != null && valueType.isAssignableFrom(nodeType)) {
51 return true; 51 return true;
52 } 52 }
56 56
57 private static boolean isNullConstant(ValueNode node) { 57 private static boolean isNullConstant(ValueNode node) {
58 return node.isConstant() && node.asConstant().isNull(); 58 return node.isConstant() && node.asConstant().isNull();
59 } 59 }
60 60
61 private boolean checkUsage(ValueNode x, ValueNode y, MetaAccessProvider runtime) { 61 private boolean checkUsage(ValueNode x, ValueNode y, MetaAccessProvider metaAccess) {
62 return isAssignableType(x, runtime) && !isNullConstant(y); 62 return isAssignableType(x, metaAccess) && !isNullConstant(y);
63 } 63 }
64 64
65 private static boolean isEqualsMethod(StructuredGraph graph) { 65 private static boolean isEqualsMethod(StructuredGraph graph) {
66 Signature signature = graph.method().getSignature(); 66 Signature signature = graph.method().getSignature();
67 return graph.method().getName().equals("equals") && signature.getParameterCount(false) == 1 && signature.getParameterKind(0).equals(Kind.Object); 67 return graph.method().getName().equals("equals") && signature.getParameterCount(false) == 1 && signature.getParameterKind(0).equals(Kind.Object);
70 @Override 70 @Override
71 protected boolean verify(StructuredGraph graph, PhaseContext context) { 71 protected boolean verify(StructuredGraph graph, PhaseContext context) {
72 for (ObjectEqualsNode cn : graph.getNodes().filter(ObjectEqualsNode.class)) { 72 for (ObjectEqualsNode cn : graph.getNodes().filter(ObjectEqualsNode.class)) {
73 if (!isEqualsMethod(graph)) { 73 if (!isEqualsMethod(graph)) {
74 // bail out if we compare an object of type klass with == or != (except null checks) 74 // bail out if we compare an object of type klass with == or != (except null checks)
75 assert !(checkUsage(cn.x(), cn.y(), context.getRuntime()) && checkUsage(cn.y(), cn.x(), context.getRuntime())) : "Verifcation of " + klass.getName() + " usage failed: Comparing " + 75 assert !(checkUsage(cn.x(), cn.y(), context.getMetaAccess()) && checkUsage(cn.y(), cn.x(), context.getMetaAccess())) : "Verifcation of " + klass.getName() +
76 cn.x() + " and " + cn.y() + " in " + graph.method() + " must use .equals() for object equality, not '==' or '!='"; 76 " usage failed: Comparing " + cn.x() + " and " + cn.y() + " in " + graph.method() + " must use .equals() for object equality, not '==' or '!='";
77 } 77 }
78 } 78 }
79 return true; 79 return true;
80 } 80 }
81 } 81 }