<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Helvetica;
        panose-1:0 11 5 0 0 0 0 0 0 0;}
@font-face
        {font-family:Helvetica;
        panose-1:0 11 5 0 0 0 0 0 0 0;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.E-MailFormatvorlage17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=DE link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Thanks,<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>This was very helpful. We used the Unsafe methods to improve our RAM usage estimation, the MX bean was not needed to detect the ref size, but we use it to detect another thing: object alignment (all object sizes are multiples of that because they are aligned using that factor). For 32 bit JVMs it is always 8, but in 64 bit JVMs it can be changed by &#8211;XX:ObjectAlignmentInBytes parameter.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>To detect this parameter we use the following code:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'>&nbsp;&nbsp;&nbsp; </span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:#3F7F5F;mso-fareast-language:EN-US'>// Try to get the object alignment (the default seems to be 8 on <u>Hotspot</u>, </span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;mso-fareast-language:EN-US'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'>&nbsp;&nbsp;&nbsp;&nbsp;</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:#3F7F5F;mso-fareast-language:EN-US'>// regardless of the architecture).</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;mso-fareast-language:EN-US'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'>&nbsp;&nbsp;&nbsp; </span><b><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:#7F0055;mso-fareast-language:EN-US'>int</span></b><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'> objectAlignment = 8;</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;mso-fareast-language:EN-US'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'>&nbsp;&nbsp;&nbsp; </span><b><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:#7F0055;mso-fareast-language:EN-US'>try</span></b><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'> {</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;mso-fareast-language:EN-US'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:#7F0055;mso-fareast-language:EN-US'>final</span></b><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'> Class&lt;?&gt; beanClazz = Class.<i>forName</i>(</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:#2A00FF;mso-fareast-language:EN-US'>&quot;com.sun.management.HotSpotDiagnosticMXBean&quot;</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'>);</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;mso-fareast-language:EN-US'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:#7F0055;mso-fareast-language:EN-US'>final</span></b><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'> Object <span style='background:yellow;mso-highlight:yellow'>hotSpotBean</span> = ManagementFactory.<i>newPlatformMXBeanProxy</i>(</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;mso-fareast-language:EN-US'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ManagementFactory.<i>getPlatformMBeanServer</i>(),</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;mso-fareast-language:EN-US'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:#2A00FF;mso-fareast-language:EN-US'>&quot;com.sun.management:type=HotSpotDiagnostic&quot;</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'>,</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;mso-fareast-language:EN-US'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; beanClazz</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;mso-fareast-language:EN-US'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;mso-fareast-language:EN-US'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:#7F0055;mso-fareast-language:EN-US'>final</span></b><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'> Method getVMOptionMethod = beanClazz.getMethod(</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:#2A00FF;mso-fareast-language:EN-US'>&quot;getVMOption&quot;</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'>, String.</span><b><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:#7F0055;mso-fareast-language:EN-US'>class</span></b><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'>);</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;mso-fareast-language:EN-US'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:#7F0055;mso-fareast-language:EN-US'>final</span></b><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'> Object vmOption = getVMOptionMethod.invoke(<span style='background:silver;mso-highlight:silver'>hotSpotBean</span>, </span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:#2A00FF;mso-fareast-language:EN-US'>&quot;ObjectAlignmentInBytes&quot;</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'>);</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;mso-fareast-language:EN-US'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objectAlignment = Integer.<i>parseInt</i>(</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;mso-fareast-language:EN-US'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vmOption.getClass().getMethod(</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:#2A00FF;mso-fareast-language:EN-US'>&quot;getValue&quot;</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'>).invoke(vmOption).toString()</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;mso-fareast-language:EN-US'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;mso-fareast-language:EN-US'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><i><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:#0000C0;mso-fareast-language:EN-US'>supportedFeatures</span></i><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'>.add(JvmFeature.</span><i><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:#0000C0;mso-fareast-language:EN-US'>OBJECT_ALIGNMENT</span></i><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'>);</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;mso-fareast-language:EN-US'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'>&nbsp;&nbsp;&nbsp; } </span><b><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:#7F0055;mso-fareast-language:EN-US'>catch</span></b><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'> (Exception e) {</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;mso-fareast-language:EN-US'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:#3F7F5F;mso-fareast-language:EN-US'>// Ignore.</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;mso-fareast-language:EN-US'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'>&nbsp;&nbsp;&nbsp; }</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;mso-fareast-language:EN-US'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;mso-fareast-language:EN-US'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'>&nbsp;&nbsp;&nbsp; </span><i><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:#0000C0;mso-fareast-language:EN-US'>NUM_BYTES_OBJECT_ALIGNMENT</span></i><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black;mso-fareast-language:EN-US'> = objectAlignment;</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;mso-fareast-language:EN-US'><o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>This works fine for detection of the object alignment. The above code is in a static class initializer. Full class can be found here: <a href="http://goo.gl/haE55">http://goo.gl/haE55</a><o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Now the question:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>The daily Lucene benchmark tests had suddenly a slowdown in query rate (queries to Lucene index per second, see <a href="http://people.apache.org/~mikemccand/lucenebench/IntNRQ.html">http://people.apache.org/~mikemccand/lucenebench/IntNRQ.html</a> - it went down after the commit of above code on March 18th). We were looking the whole day to find the issue (there was another possible commit on this day causing problems, but this one caused this). The interesting thing, by uncommenting the above code that retrieves the HotspotMXBream, the slowdown disappears.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Does getting the HotSpotDiagnosticMXBean somehow trigger some internal state in the virtual machine (e.g. attaching an agent lib), so this slows down hotspot a little bit?<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Uwe<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>-----<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Uwe Schindler<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>uschindler@apache.org <o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Apache Lucene PMC Member / Committer<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Bremen, Germany<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>http://lucene.apache.org/<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><div style='border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt'><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> hotspot-compiler-dev-bounces@openjdk.java.net [mailto:hotspot-compiler-dev-bounces@openjdk.java.net] <b>On Behalf Of </b>Krystal Mok<br><b>Sent:</b> Wednesday, March 14, 2012 7:13 PM<br><b>To:</b> John Rose<br><b>Cc:</b> hotspot compiler<br><b>Subject:</b> Re: How to detect if the VM is running with compact refs from within the VM (no agent)?<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p>&nbsp;</o:p></p><div><p class=MsoNormal>Couldn't find these two fields in sun.misc.Unsafe (in JDK6u30), found arrayIndexScale(Class) and addressSize() methods instead.<o:p></o:p></p></div><p class=MsoNormal>Experiment:&nbsp; <a href="https://gist.github.com/2038305">https://gist.github.com/2038305</a>&nbsp;<o:p></o:p></p><div><p class=MsoNormal style='margin-bottom:12.0pt'>Works as advertised. Thanks John! Learning new bits everday for me, too :-)<br><br>- Kris<o:p></o:p></p><div><p class=MsoNormal>On Thu, Mar 15, 2012 at 1:53 AM, John Rose &lt;<a href="mailto:john.r.rose@oracle.com">john.r.rose@oracle.com</a>&gt; wrote:<o:p></o:p></p><div><div><div><div><p class=MsoNormal>On Mar 14, 2012, at 1:41 AM, Krystal Mok wrote:<o:p></o:p></p></div><p class=MsoNormal><br><br><o:p></o:p></p><p class=MsoNormal><span style='font-size:13.5pt;font-family:"Helvetica","sans-serif"'>I'm not aware of any way to get the exact &quot;reference size&quot; (or &quot;oop size&quot; in HotSpot's terms). But it's possible to know whether compressed oops is in use or not.&nbsp;</span><o:p></o:p></p></div><p class=MsoNormal><o:p>&nbsp;</o:p></p></div><div><p class=MsoNormal>For some platforms, you could inspect sun.misc.Unsafe.ARRAY_OBJECT_INDEX_SCALE (= oopSize) and ADDRESS_SIZE (= wordSize).<o:p></o:p></p></div><div><p class=MsoNormal><o:p>&nbsp;</o:p></p></div><div><p class=MsoNormal><span style='color:#888888'>&#8212; John<o:p></o:p></span></p></div></div></div><p class=MsoNormal><o:p>&nbsp;</o:p></p></div></div></div></body></html>