From 1b0d929fdc8bd6f1237cc453f503d7388545640c Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Sat, 6 Sep 2014 14:25:55 -0700 Subject: 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 --- libart/src/main/java/java/lang/Object.java | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'libart') 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); } -- cgit v1.1