summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathieu Chartier <mathieuc@google.com>2014-09-06 14:25:55 -0700
committerMathieu Chartier <mathieuc@google.com>2014-09-08 14:29:16 -0700
commit1b0d929fdc8bd6f1237cc453f503d7388545640c (patch)
treef5d72fcd1d7c4fd8ccdb744438368541322e34bf
parentf48abd8f339755928b516dca8a939a5b7b799bd4 (diff)
downloadlibcore-1b0d929fdc8bd6f1237cc453f503d7388545640c.zip
libcore-1b0d929fdc8bd6f1237cc453f503d7388545640c.tar.gz
libcore-1b0d929fdc8bd6f1237cc453f503d7388545640c.tar.bz2
Add handling for hashed uninflated object.
This is an Optimization to reduce how often we call System.identityHashCode. If the lockword is set to the hash code state then we simply return this value. Otherwise, we use System.identityHashCode. Maps launch exclusive time spent in System.identityHashCode: Before: 4.5% After: 2.4% Bug: 16828525 (cherry picked from commit 6917aebf2eb26c2b003a72d09c1c5bb6310160b0) Change-Id: I0ccad53cb5f8f4f27fe11725a91ab45a117452a3
-rw-r--r--libart/src/main/java/java/lang/Object.java6
1 files changed, 6 insertions, 0 deletions
diff --git a/libart/src/main/java/java/lang/Object.java b/libart/src/main/java/java/lang/Object.java
index acae8ca..20fdbf9 100644
--- a/libart/src/main/java/java/lang/Object.java
+++ b/libart/src/main/java/java/lang/Object.java
@@ -273,6 +273,12 @@ public class Object {
* @see #equals
*/
public int hashCode() {
+ int lockWord = shadow$_monitor_;
+ final int lockWordMask = 0xC0000000; // Top 2 bits.
+ final int lockWordStateHash = 0x80000000; // Top 2 bits are value 2 (kStateHash).
+ if ((lockWord & lockWordMask) == lockWordStateHash) {
+ return lockWord & ~lockWordMask;
+ }
return System.identityHashCode(this);
}