How to detect if the VM is running with compact refs from within the VM (no agent)?
Uwe Schindler
uschindler at apache.org
Wed Mar 28 14:45:45 PDT 2012
Thanks,
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 -XX:ObjectAlignmentInBytes
parameter.
To detect this parameter we use the following code:
// Try to get the object alignment (the default seems to be 8 on
Hotspot,
// regardless of the architecture).
int objectAlignment = 8;
try {
final Class<?> beanClazz =
Class.forName("com.sun.management.HotSpotDiagnosticMXBean");
final Object hotSpotBean = ManagementFactory.newPlatformMXBeanProxy(
ManagementFactory.getPlatformMBeanServer(),
"com.sun.management:type=HotSpotDiagnostic",
beanClazz
);
final Method getVMOptionMethod = beanClazz.getMethod("getVMOption",
String.class);
final Object vmOption = getVMOptionMethod.invoke(hotSpotBean,
"ObjectAlignmentInBytes");
objectAlignment = Integer.parseInt(
vmOption.getClass().getMethod("getValue").invoke(vmOption).toString()
);
supportedFeatures.add(JvmFeature.OBJECT_ALIGNMENT);
} catch (Exception e) {
// Ignore.
}
NUM_BYTES_OBJECT_ALIGNMENT = objectAlignment;
This works fine for detection of the object alignment. The above code is in
a static class initializer. Full class can be found here:
http://goo.gl/haE55
Now the question:
The daily Lucene benchmark tests had suddenly a slowdown in query rate
(queries to Lucene index per second, see
http://people.apache.org/~mikemccand/lucenebench/IntNRQ.html - 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.
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?
Uwe
-----
Uwe Schindler
uschindler at apache.org
Apache Lucene PMC Member / Committer
Bremen, Germany
http://lucene.apache.org/
From: hotspot-compiler-dev-bounces at openjdk.java.net
[mailto:hotspot-compiler-dev-bounces at openjdk.java.net] On Behalf Of Krystal
Mok
Sent: Wednesday, March 14, 2012 7:13 PM
To: John Rose
Cc: hotspot compiler
Subject: Re: How to detect if the VM is running with compact refs from
within the VM (no agent)?
Couldn't find these two fields in sun.misc.Unsafe (in JDK6u30), found
arrayIndexScale(Class) and addressSize() methods instead.
Experiment: https://gist.github.com/2038305
Works as advertised. Thanks John! Learning new bits everday for me, too :-)
- Kris
On Thu, Mar 15, 2012 at 1:53 AM, John Rose <john.r.rose at oracle.com> wrote:
On Mar 14, 2012, at 1:41 AM, Krystal Mok wrote:
I'm not aware of any way to get the exact "reference size" (or "oop size" in
HotSpot's terms). But it's possible to know whether compressed oops is in
use or not.
For some platforms, you could inspect
sun.misc.Unsafe.ARRAY_OBJECT_INDEX_SCALE (= oopSize) and ADDRESS_SIZE (=
wordSize).
- John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/attachments/20120328/e39fca05/attachment.html
More information about the hotspot-compiler-dev
mailing list