diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotSpeculationLog.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotSpeculationLog.java index fd46e281c3bd0..e3d812c2e83d6 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotSpeculationLog.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotSpeculationLog.java @@ -77,7 +77,7 @@ public HotSpotSpeculationLog(long failedSpeculationsAddress) { } /** - * Gets the address of the pointer to the native failed speculations list. + * Gets the address of the pointer to the native failed speculations list. This always returns a non-zero address. * * @see #managesFailedSpeculations() */ @@ -85,8 +85,9 @@ public long getFailedSpeculationsAddress() { if (managesFailedSpeculations) { synchronized (this) { if (failedSpeculationsAddress == 0L) { - failedSpeculationsAddress = UnsafeAccess.UNSAFE.allocateMemory(HotSpotJVMCIRuntime.getHostWordKind().getByteCount()); - UnsafeAccess.UNSAFE.putAddress(failedSpeculationsAddress, 0L); + long address = UnsafeAccess.UNSAFE.allocateMemory(HotSpotJVMCIRuntime.getHostWordKind().getByteCount()); + UnsafeAccess.UNSAFE.putAddress(address, 0L); + failedSpeculationsAddress = address; LogCleaner c = new LogCleaner(this, failedSpeculationsAddress); assert c.address == failedSpeculationsAddress; } @@ -171,8 +172,16 @@ public String toString() { @Override public void collectFailedSpeculations() { - if (failedSpeculationsAddress != 0 && UnsafeAccess.UNSAFE.getLong(failedSpeculationsAddress) != 0) { - failedSpeculations = compilerToVM().getFailedSpeculations(failedSpeculationsAddress, failedSpeculations); + if (failedSpeculationsAddress == 0) { + // If no memory has been allocated then don't force its creation + return; + } + + // Go through getFailedSpeculationsAddress() to ensure that any concurrent + // initialization of failedSpeculationsAddress is seen by this thread. + long address = getFailedSpeculationsAddress(); + if (UnsafeAccess.UNSAFE.getLong(address) != 0) { + failedSpeculations = compilerToVM().getFailedSpeculations(address, failedSpeculations); assert failedSpeculations.getClass() == byte[][].class; } }