8185950: [JVMCI] fix NPE possibility in HotSpotSpeculationLog.speculate
authordnsimon
Thu, 10 Aug 2017 10:38:17 -0700
changeset 46793 27a0fdda79c3
parent 46792 1f9002906ea9
child 46794 aa0b86e09f9a
8185950: [JVMCI] fix NPE possibility in HotSpotSpeculationLog.speculate Reviewed-by: thartmann, kvn
hotspot/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotSpeculationLog.java
--- a/hotspot/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotSpeculationLog.java	Wed Aug 02 10:17:14 2017 +0200
+++ b/hotspot/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotSpeculationLog.java	Thu Aug 10 10:38:17 2017 -0700
@@ -39,7 +39,7 @@
     private Set<SpeculationReason> failedSpeculations;
 
     /** Strong references to all reasons embedded in the current nmethod. */
-    private volatile Collection<SpeculationReason> speculations;
+    private Collection<SpeculationReason> speculations;
 
     @Override
     public synchronized void collectFailedSpeculations() {
@@ -70,14 +70,12 @@
          * reason objects that are embedded in nmethods, so we add them to the speculations
          * collection.
          */
-        if (speculations == null) {
-            synchronized (this) {
-                if (speculations == null) {
-                    speculations = new ConcurrentLinkedQueue<>();
-                }
+        synchronized (this) {
+            if (speculations == null) {
+                speculations = new ConcurrentLinkedQueue<>();
             }
+            speculations.add(reason);
         }
-        speculations.add(reason);
 
         return HotSpotObjectConstantImpl.forObject(reason);
     }