# HG changeset patch # User Roland Schatz # Date 1383753365 -3600 # Node ID 22780dc399dafdbe574ce05ccbc7da06442aee55 # Parent 4aec62c32a821a6d7e42da887215e270afd03fd2 Support arbitrary array types in global value numbering. diff -r 4aec62c32a82 -r 22780dc399da graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java Wed Nov 06 16:29:54 2013 +0100 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java Wed Nov 06 16:56:05 2013 +0100 @@ -677,6 +677,32 @@ } } + private static int deepHashCode0(Object o) { + if (o instanceof Object[]) { + return Arrays.deepHashCode((Object[]) o); + } else if (o instanceof byte[]) { + return Arrays.hashCode((byte[]) o); + } else if (o instanceof short[]) { + return Arrays.hashCode((short[]) o); + } else if (o instanceof int[]) { + return Arrays.hashCode((int[]) o); + } else if (o instanceof long[]) { + return Arrays.hashCode((long[]) o); + } else if (o instanceof char[]) { + return Arrays.hashCode((char[]) o); + } else if (o instanceof float[]) { + return Arrays.hashCode((float[]) o); + } else if (o instanceof double[]) { + return Arrays.hashCode((double[]) o); + } else if (o instanceof boolean[]) { + return Arrays.hashCode((boolean[]) o); + } else if (o != null) { + return o.hashCode(); + } else { + return 0; + } + } + public int valueNumber(Node n) { int number = 0; if (canGVN) { @@ -700,11 +726,7 @@ } } else { Object o = unsafe.getObject(n, dataOffsets[i]); - if (o instanceof Object[]) { - number += Arrays.deepHashCode((Object[]) o); - } else if (o != null) { - number += o.hashCode(); - } + number += deepHashCode0(o); } number *= 13; } @@ -743,6 +765,33 @@ } } + private static boolean deepEquals0(Object e1, Object e2) { + assert e1 != null; + boolean eq; + if (e1 instanceof Object[] && e2 instanceof Object[]) { + eq = Arrays.deepEquals((Object[]) e1, (Object[]) e2); + } else if (e1 instanceof byte[] && e2 instanceof byte[]) { + eq = Arrays.equals((byte[]) e1, (byte[]) e2); + } else if (e1 instanceof short[] && e2 instanceof short[]) { + eq = Arrays.equals((short[]) e1, (short[]) e2); + } else if (e1 instanceof int[] && e2 instanceof int[]) { + eq = Arrays.equals((int[]) e1, (int[]) e2); + } else if (e1 instanceof long[] && e2 instanceof long[]) { + eq = Arrays.equals((long[]) e1, (long[]) e2); + } else if (e1 instanceof char[] && e2 instanceof char[]) { + eq = Arrays.equals((char[]) e1, (char[]) e2); + } else if (e1 instanceof float[] && e2 instanceof float[]) { + eq = Arrays.equals((float[]) e1, (float[]) e2); + } else if (e1 instanceof double[] && e2 instanceof double[]) { + eq = Arrays.equals((double[]) e1, (double[]) e2); + } else if (e1 instanceof boolean[] && e2 instanceof boolean[]) { + eq = Arrays.equals((boolean[]) e1, (boolean[]) e2); + } else { + eq = e1.equals(e2); + } + return eq; + } + public boolean valueEqual(Node a, Node b) { if (!canGVN || a.getClass() != b.getClass()) { return a == b; @@ -782,14 +831,8 @@ Object objectB = unsafe.getObject(b, dataOffsets[i]); if (objectA != objectB) { if (objectA != null && objectB != null) { - if (objectA instanceof Object[] && objectB instanceof Object[]) { - if (!Arrays.deepEquals((Object[]) objectA, (Object[]) objectB)) { - return false; - } - } else { - if (!(objectA.equals(objectB))) { - return false; - } + if (!deepEquals0(objectA, objectB)) { + return false; } } else { return false;