Only perform one read of the hashCode field in our benign-data-racy hashCode() implementation. See http://jeremymanson.blogspot.com/2008/12/benign-data-races-in-java.html. -- MOS_MIGRATED_REVID=101490349
diff --git a/src/main/java/com/google/devtools/build/skyframe/SkyKey.java b/src/main/java/com/google/devtools/build/skyframe/SkyKey.java index 6916e66..79af14f 100644 --- a/src/main/java/com/google/devtools/build/skyframe/SkyKey.java +++ b/src/main/java/com/google/devtools/build/skyframe/SkyKey.java
@@ -79,10 +79,12 @@ // All three of these issues are benign from a correctness perspective; in the end we have no // overhead from synchronization, at the cost of potentially computing the hash code more than // once. - if (hashCode == 0) { - hashCode = computeHashCode(); + int h = hashCode; + if (h == 0) { + h = computeHashCode(); + hashCode = h; } - return hashCode; + return h; } private int computeHashCode() {