comparison graal/com.oracle.graal.phases/src/com/oracle/graal/phases/verify/VerifyUsageWithEquals.java @ 14162:ab1c093f15c2

added unit test to ensure all classes in graal.jar comply with select global invariants
author Doug Simon <doug.simon@oracle.com>
date Wed, 12 Mar 2014 21:50:50 +0100
parents 2c4aa758ee18
children a0c31f940950
comparison
equal deleted inserted replaced
14161:f14fb79ab265 14162:ab1c093f15c2
60 60
61 private boolean checkUsage(ValueNode x, ValueNode y, MetaAccessProvider metaAccess) { 61 private boolean checkUsage(ValueNode x, ValueNode y, MetaAccessProvider metaAccess) {
62 return isAssignableType(x, metaAccess) && !isNullConstant(y); 62 return isAssignableType(x, metaAccess) && !isNullConstant(y);
63 } 63 }
64 64
65 private static boolean isEqualsMethod(StructuredGraph graph) {
66 Signature signature = graph.method().getSignature();
67 return graph.method().getName().equals("equals") && signature.getParameterCount(false) == 1 && signature.getParameterKind(0).equals(Kind.Object);
68 }
69
70 @Override 65 @Override
71 protected boolean verify(StructuredGraph graph, PhaseContext context) { 66 protected boolean verify(StructuredGraph graph, PhaseContext context) {
72 for (ObjectEqualsNode cn : graph.getNodes().filter(ObjectEqualsNode.class)) { 67 for (ObjectEqualsNode cn : graph.getNodes().filter(ObjectEqualsNode.class)) {
73 if (!isEqualsMethod(graph)) { 68 // 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) 69 assert !(checkUsage(cn.x(), cn.y(), context.getMetaAccess()) && checkUsage(cn.y(), cn.x(), context.getMetaAccess())) : "Verification of " + klass.getName() + " usage failed: Comparing " +
75 assert !(checkUsage(cn.x(), cn.y(), context.getMetaAccess()) && checkUsage(cn.y(), cn.x(), context.getMetaAccess())) : "Verification of " + klass.getName() + 70 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 }
78 } 71 }
79 return true; 72 return true;
80 } 73 }
81 } 74 }