| commit | 87992dccc6fafa864c3e03417ef58c0db3071b2f | [log] [tgz] |
|---|---|---|
| author | Nathan Harmata <nharmata@google.com> | Tue Aug 25 18:53:55 2015 +0000 |
| committer | Lukacs Berki <lberki@google.com> | Wed Aug 26 07:40:37 2015 +0000 |
| tree | b5b39d56902b57b0ae26a54016ad1d229ae887f1 | |
| parent | 3a280ea336090d745cc65829c463c30d7cda700a [diff] [blame] |
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() {