am c703df81: am ff66631f: Merge "Fix the HashMap performance regression."
* commit 'c703df8116e92a98f33f6baf4eb4c7bf78584fd1':
Fix the HashMap performance regression.
diff --git a/luni/src/main/java/java/util/HashMap.java b/luni/src/main/java/java/util/HashMap.java
index b6fe646..80fbd0c 100644
--- a/luni/src/main/java/java/util/HashMap.java
+++ b/luni/src/main/java/java/util/HashMap.java
@@ -297,7 +297,12 @@
return e == null ? null : e.value;
}
- int hash = Collections.secondaryHash(key);
+ // Doug Lea's supplemental secondaryHash function (inlined).
+ // Replace with Collections.secondaryHash when the VM is fast enough (http://b/8290590).
+ int hash = key.hashCode();
+ hash ^= (hash >>> 20) ^ (hash >>> 12);
+ hash ^= (hash >>> 7) ^ (hash >>> 4);
+
HashMapEntry<K, V>[] tab = table;
for (HashMapEntry<K, V> e = tab[hash & (tab.length - 1)];
e != null; e = e.next) {
@@ -322,7 +327,12 @@
return entryForNullKey != null;
}
- int hash = Collections.secondaryHash(key);
+ // Doug Lea's supplemental secondaryHash function (inlined).
+ // Replace with Collections.secondaryHash when the VM is fast enough (http://b/8290590).
+ int hash = key.hashCode();
+ hash ^= (hash >>> 20) ^ (hash >>> 12);
+ hash ^= (hash >>> 7) ^ (hash >>> 4);
+
HashMapEntry<K, V>[] tab = table;
for (HashMapEntry<K, V> e = tab[hash & (tab.length - 1)];
e != null; e = e.next) {
@@ -334,6 +344,15 @@
return false;
}
+ // Doug Lea's supplemental secondaryHash function (non-inlined).
+ // Replace with Collections.secondaryHash when the VM is fast enough (http://b/8290590).
+ static int secondaryHash(Object key) {
+ int hash = key.hashCode();
+ hash ^= (hash >>> 20) ^ (hash >>> 12);
+ hash ^= (hash >>> 7) ^ (hash >>> 4);
+ return hash;
+ }
+
/**
* Returns whether this map contains the specified value.
*
@@ -382,7 +401,7 @@
return putValueForNullKey(value);
}
- int hash = Collections.secondaryHash(key);
+ int hash = secondaryHash(key);
HashMapEntry<K, V>[] tab = table;
int index = hash & (tab.length - 1);
for (HashMapEntry<K, V> e = tab[index]; e != null; e = e.next) {
@@ -445,7 +464,7 @@
return;
}
- int hash = Collections.secondaryHash(key);
+ int hash = secondaryHash(key);
HashMapEntry<K, V>[] tab = table;
int index = hash & (tab.length - 1);
HashMapEntry<K, V> first = tab[index];
@@ -613,7 +632,7 @@
if (key == null) {
return removeNullKey();
}
- int hash = Collections.secondaryHash(key);
+ int hash = secondaryHash(key);
HashMapEntry<K, V>[] tab = table;
int index = hash & (tab.length - 1);
for (HashMapEntry<K, V> e = tab[index], prev = null;
@@ -833,7 +852,7 @@
return e != null && Objects.equal(value, e.value);
}
- int hash = Collections.secondaryHash(key);
+ int hash = secondaryHash(key);
HashMapEntry<K, V>[] tab = table;
int index = hash & (tab.length - 1);
for (HashMapEntry<K, V> e = tab[index]; e != null; e = e.next) {
@@ -861,7 +880,7 @@
return true;
}
- int hash = Collections.secondaryHash(key);
+ int hash = secondaryHash(key);
HashMapEntry<K, V>[] tab = table;
int index = hash & (tab.length - 1);
for (HashMapEntry<K, V> e = tab[index], prev = null;
diff --git a/luni/src/main/java/java/util/LinkedHashMap.java b/luni/src/main/java/java/util/LinkedHashMap.java
index d2c6b76..e61b0f9 100644
--- a/luni/src/main/java/java/util/LinkedHashMap.java
+++ b/luni/src/main/java/java/util/LinkedHashMap.java
@@ -247,7 +247,8 @@
return e.value;
}
- int hash = Collections.secondaryHash(key);
+ // Replace with Collections.secondaryHash when the VM is fast enough (http://b/8290590).
+ int hash = secondaryHash(key);
HashMapEntry<K, V>[] tab = table;
for (HashMapEntry<K, V> e = tab[hash & (tab.length - 1)];
e != null; e = e.next) {