8185950: [JVMCI] fix NPE possibility in HotSpotSpeculationLog.speculate
Reviewed-by: thartmann, kvn
--- 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);
}