tag:blogger.com,1999:blog-2319831394620195922.post4692334609647791079..comments2026-04-20T12:53:56.430+01:00Comments on Rational Java: An Unexpected Allocation - JIT Compilation JitterAnonymoushttp://www.blogger.com/profile/09391434492829452178noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-2319831394620195922.post-58740024767272092832015-09-14T06:38:25.509+01:002015-09-14T06:38:25.509+01:00Jean-Philippe, the interesting thing about that pr...Jean-Philippe, the interesting thing about that property is that it is not exposed in the ThreadMXBean, but you can see it as a property in JConsole (which is where I found it whilst dicking around during a live presentation in one of my courses). So I&#39;m not even sure if our code is going to be fully compatible and work in other JVMs. Anybody care to try it out in IBM?<br /><br />For the calibration code, I did know that tiered compilation makes things more tricky, but also didn&#39;t want to force users to have to turn it off, just to use the code. This is why I increased the repeats to hopefully catch all the JITter up front :-)Heinzhttps://www.blogger.com/profile/09376313150990118752noreply@blogger.comtag:blogger.com,1999:blog-2319831394620195922.post-57958478540283181442015-09-08T19:10:32.932+01:002015-09-08T19:10:32.932+01:00Thanks - interesting point about the tiered compil...Thanks - interesting point about the tiered compilation.<br />Goes to prove that compilation jitter does cause allocation :)Anonymoushttps://www.blogger.com/profile/09391434492829452178noreply@blogger.comtag:blogger.com,1999:blog-2319831394620195922.post-79771293926757550192015-09-08T13:26:32.773+01:002015-09-08T13:26:32.773+01:00Hi, Did you try without TieredCompilation (enable...Hi,<br /><br />Did you try without TieredCompilation (enabled by default on JDK8) ?<br />I think it will be more predictable (10K) without it.<br /><br />why not using<br />(<br />(com.sun.management.ThreadMXBean) ManagementFactory.getThreadMXBean()).getThreadAllocatedBytes(Thread.currentThread().getId());<br /><br />less overhead (48 bytes)<br />But may not be portable because using com.sun.management package<br /><br /> int VALUE_COUNT = 1000*1000;<br /> long[] values = new long[VALUE_COUNT];<br /> for (int i = 0; i &lt; VALUE_COUNT; i++)<br /> {<br /> values[i] = ((ThreadMXBean) ManagementFactory.getThreadMXBean()).getThreadAllocatedBytes(Thread.currentThread().getId());<br /> }<br /> long prevDiff = -1;<br /> for (int i = 1; i &lt; VALUE_COUNT; i++)<br /> {<br /> long diff = values[i] - values[i - 1];<br /> if (prevDiff != diff)<br /> System.out.println(&quot;Allocation changed at iteration &quot; + i + &quot;-&gt;&quot; + diff);<br /> prevDiff = diff;<br /> }<br /><br />With TieredCompilation:<br />Allocation changed at iteration 1-&gt;48<br />Allocation changed at iteration 5631-&gt;560<br />Allocation changed at iteration 5632-&gt;48<br />Allocation changed at iteration 6655-&gt;1304<br />Allocation changed at iteration 6656-&gt;48<br />Allocation changed at iteration 95122-&gt;376<br />Allocation changed at iteration 95123-&gt;48<br /><br />No Tiered compilation:<br />Allocation changed at iteration 1-&gt;48<br />Allocation changed at iteration 4999-&gt;2480<br />Allocation changed at iteration 5000-&gt;424<br />Allocation changed at iteration 5001-&gt;48<br />Allocation changed at iteration 9912-&gt;816<br />Allocation changed at iteration 9913-&gt;48<br />Allocation changed at iteration 9999-&gt;560<br />Allocation changed at iteration 10000-&gt;48<br />Allocation changed at iteration 14563-&gt;200<br />Allocation changed at iteration 14564-&gt;48<br />Jean-Philippe Bempelhttps://www.blogger.com/profile/06767056355047105540noreply@blogger.com