<div dir="ltr">Hi,<div><br></div><div>I don't get it.</div><div>You are putting items in a non-concurrent hashmap from multiple threads.</div><div>I have no doubt it will eventually fail.</div><div><br></div><div>Reading quickly, the second error seems to be thrown (and could be more explanatory) when you want more threads then the number of warmup threads.</div><div>So you want more threads than the warmup could prime and you get this error.</div><div><br></div><div>Anything I'm missing?</div><div><br></div><div>Regards,</div><div>Henri </div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 22 Sept 2023 at 22:05, John Auden <<a href="mailto:lovedthefaioli@gmail.com">lovedthefaioli@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><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>
</blockquote></div>