diff options
author | 2015-08-25 18:53:55 +0000 | |
---|---|---|
committer | 2015-08-26 07:40:37 +0000 | |
commit | 87992dccc6fafa864c3e03417ef58c0db3071b2f (patch) | |
tree | b5b39d56902b57b0ae26a54016ad1d229ae887f1 /src/main | |
parent | 3a280ea336090d745cc65829c463c30d7cda700a (diff) |
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
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/google/devtools/build/skyframe/SkyKey.java | 8 |
1 files changed, 5 insertions, 3 deletions
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 6916e663e7..79af14f429 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 @@ public final class SkyKey implements Serializable { // 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() { |