<div dir="ltr">Hi,<div><br></div><div>I was trying to create a concurrency benchmark, but noticed that it fails in a very basic logic block. </div><div><i>I know that it is a bad idea to run benchmarks inside a VM, but I do it rather for quick check and because I have debug JDK releases + hsdis there. This email is not to submit a bug, but rather just for your information.</i></div><div>Host: 16 cores Azure VM (Intel(R) Xeon(R) CPU E5-2673 v4 @ 2.30GHz)</div><div>$ lscpu<br>Architecture:          x86_64<br>CPU op-mode(s):        32-bit, 64-bit<br>Byte Order:            Little Endian<br>CPU(s):                16<br>On-line CPU(s) list:   0-15<br></div><div><br></div><div>OS: CentOS Linux release 7.9.2009</div><div>JDK: 17.0.5</div><div><pre style="color:rgb(8,8,8);font-family:"JetBrains Mono",monospace;font-size:10.5pt"><span style="color:rgb(158,136,13)">@Threads</span>(<span style="color:rgb(158,136,13)">Threads</span>.<span style="color:rgb(135,16,148);font-style:italic">MAX</span>)<br><span style="color:rgb(0,51,179)">public class </span><span style="color:rgb(0,0,0)">HMBenchmark </span>{<br>  <span style="color:rgb(0,51,179)">private final static </span><span style="color:rgb(0,0,0)">Map</span><<span style="color:rgb(0,0,0)">Long</span>, <span style="color:rgb(0,0,0)">Long</span>> <span style="color:rgb(135,16,148);font-style:italic">map </span>= <span style="color:rgb(0,51,179)">new </span>HashMap<>(<span style="color:rgb(0,0,0)">Runtime</span>.<span style="font-style:italic">getRuntime</span>().availableProcessors());<br><br>  <span style="color:rgb(158,136,13)">@Benchmark<br></span><span style="color:rgb(158,136,13)">  </span><span style="color:rgb(0,51,179)">public void </span><span style="color:rgb(0,98,122)">testHM</span>() {<br>    <span style="color:rgb(0,0,0)">Long id </span>= <span style="color:rgb(0,0,0)">Thread</span>.<span style="font-style:italic">currentThread</span>().getId();<br>    <span style="color:rgb(135,16,148);font-style:italic">map</span>.put(<span style="color:rgb(0,0,0)">id</span>, <span style="color:rgb(23,80,235)">0L</span>);<br>    <span style="color:rgb(0,51,179)">for </span>(<span style="color:rgb(0,51,179)">long </span><span style="color:rgb(0,0,0)">i </span>= <span style="color:rgb(23,80,235)">0</span>; <span style="color:rgb(0,0,0)">i </span>< <span style="color:rgb(23,80,235)">100_000</span>; <span style="color:rgb(0,0,0)">i</span>++) {<br>      <span style="color:rgb(135,16,148);font-style:italic">map</span>.put(<span style="color:rgb(0,0,0)">id</span>, <span style="color:rgb(135,16,148);font-style:italic">map</span>.get(<span style="color:rgb(0,0,0)">id</span>) + <span style="color:rgb(0,0,0)">i</span>);<br>    }<br>  }<br>}</pre>If the number of threads is set above 12 (up to Threads.MAX) this benchmark starts to fail. WIth 13, 14, 15 it fails with NPE (even though program order should theoretically protect code against NPE):</div><div><b>java.lang.NullPointerException: Cannot invoke "java.lang.Long.longValue()" because the return value of "java.util.Map.get(Object)" is null<br>  at org.ad.HMBenchmark.testHM(HMBenchmark.java:33)<br>     at org.ad.jmh_generated.HMBenchmark_testHM_jmhTest.testHM_Throughput(HMBenchmark_testHM_jmhTest.java:78)<br></b></div><div><br></div><div>WIth MAX threads (or 16) there is also this interesting exception:</div><div><b>java.lang.IllegalStateException: More threads than expected<br>     at org.openjdk.jmh.runner.InfraControlL2.announceWarmupReady(InfraControl.java:222)<br>   at org.openjdk.jmh.runner.InfraControl.announceWarmupReady(InfraControl.java:40)<br>      at org.ad.jmh_generated.HMBenchmark_testHM_jmhTest.testHM_Throughput(HMBenchmark_testHM_jmhTest.java:76)<br></b></div><div><br></div><div>Regards,</div><div>Alex Dubrouski</div><div><br></div></div>