From 28da248e817762ef6e2709a8379228867862d97a Mon Sep 17 00:00:00 2001 From: Hiroshi Yamauchi Date: Thu, 23 Apr 2015 20:42:50 -0700 Subject: Fix hashCode() for the read barrier lock word change. Mask the low 28 bits of the lock word. Bug: 19355854 Bug: 12687968 Change-Id: Ic6db7e23fa1a98b28564880d78e7c7cc0c8c0bdc --- libart/src/main/java/java/lang/Object.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'libart') diff --git a/libart/src/main/java/java/lang/Object.java b/libart/src/main/java/java/lang/Object.java index 20fdbf9..5b820e3 100644 --- a/libart/src/main/java/java/lang/Object.java +++ b/libart/src/main/java/java/lang/Object.java @@ -274,10 +274,11 @@ public class Object { */ public int hashCode() { int lockWord = shadow$_monitor_; - final int lockWordMask = 0xC0000000; // Top 2 bits. + final int lockWordStateMask = 0xC0000000; // Top 2 bits. final int lockWordStateHash = 0x80000000; // Top 2 bits are value 2 (kStateHash). - if ((lockWord & lockWordMask) == lockWordStateHash) { - return lockWord & ~lockWordMask; + final int lockWordHashMask = 0x0FFFFFFF; // Low 28 bits. + if ((lockWord & lockWordStateMask) == lockWordStateHash) { + return lockWord & lockWordHashMask; } return System.identityHashCode(this); } -- cgit v1.1