RFR (S) : JDK-8245043 : Simplified contention benchmark
Sergey Kuksenko
sergey.kuksenko at oracle.com
Mon May 18 23:48:03 UTC 2020
On 5/18/20 4:35 PM, David Holmes wrote:
> On 19/05/2020 8:38 am, Sergey Kuksenko wrote:
>> 2. Does "volatile Table[] sharedLocks" need to be volatile?
>
> I think the intent is that the array needs to be published safely -
> though without knowing full details of JMH it is impossible to see how
> the array creation and filling relates to threads being started (ie
> does setup() happen-before any threads are started? If so then
> publication is already safe.) But if the intent is to do safe
> publication then refreshArray is wrong:
>
> 85 void refreshArray() {
> 86 sharedLocks = new Table[locksSize];
> 87 for (int i = 0; i < locksSize; i++) {
> 88 sharedLocks[i] = new Table(i);
> 89 }
> 90 }
>
> you would need to create a tmp array and fill it, then assign to
> sharedLocks with the volatile write that publishes the array.
JMH does safe publication between @Setup and @Benchmark methods. And
yes, I was asking - because of either volatile is not required or tmp
local array reference is required.
More information about the hotspot-runtime-dev
mailing list