How to detect if the VM is running with compact refs from within the VM (no agent)?

Krystal Mok rednaxelafx at gmail.com
Wed Mar 14 07:45:31 PDT 2012


Hi,

Just in case you'd care, the same MXBean could be used to detect compressed
references on JRockit, too. It's probably available starting from JRockit
R28.

Instead of "UseCompressedOops", use "CompressedRefs" as the VM option name
on JRockit.

Don't know how to extract this information for J9 without another whole
bunch of hackeries...well, you could try this, on a "best-effort" basis for
platform detection:
IBM J9's VM version string contains the compressed reference information.
Example:

$ export JAVA_OPTS='-Xcompressedrefs'
$ groovysh
Groovy Shell (1.7.7, JVM: 1.7.0)
Type 'help' or '\h' for help.
----------------------------------------------------------------------------------------------------------------------------
groovy:000> System.getProperty 'java.vm.info'
===> JRE 1.7.0 Linux amd64-64 Compressed References 20110810_88604 (JIT
enabled, AOT enabled)
J9VM - R26_Java726_GA_20110810_1208_B88592
JIT  - r11_20110810_20466
GC   - R26_Java726_GA_20110810_1208_B88592_CMPRSS
J9CL - 20110810_88604
groovy:000> quit

So grepping for "Compressed References" in the "java.vm.info" system
property gives you the clue.

- Kris

On Wed, Mar 14, 2012 at 9:06 PM, Uwe Schindler <uschindler at apache.org>wrote:

> Hi,****
>
> ** **
>
> I tried this code as platform (means JVM independent) detection for
> compressed Oops:****
>
> ** **
>
> boolean compressedOops = false;****
>
> if (JRE_IS_64BIT) try {****
>
>   final Class<?> beanClazz =
> Class.forName("com.sun.management.HotSpotDiagnosticMXBean");****
>
>   final Object hotSpotBean = ManagementFactory.newPlatformMXBeanProxy(****
>
>     ManagementFactory.getPlatformMBeanServer(),****
>
>     "com.sun.management:type=HotSpotDiagnostic",****
>
>     beanClazz****
>
>   );****
>
>   final Object vmOption = hotSpotBean.getClass().getMethod("getVMOption",
> String.class)****
>
>     .invoke(hotSpotBean, "UseCompressedOops");****
>
>   compressedOops = Boolean.valueOf(****
>
>     vmOption.getClass().getMethod("getValue")****
>
>     .invoke(vmOption).toString()****
>
>   ).booleanValue();****
>
> } catch (Exception e) {****
>
>   // if anything fails before, we assume that oops are not compressed****
>
>   compressedOops = false;****
>
> }****
>
> ** **
>
> If anybody finds this useful, here it is,****
>
> ** **
>
> -----****
>
> 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 10:42 AM
> *To:* Dawid Weiss
>
> *Cc:* hotspot compiler
> *Subject:* Re: How to detect if the VM is running with compact refs from
> within the VM (no agent)?****
>
> ** **
>
> Hi Dawid,****
>
> ** **
>
> For product releases of Oracle/Sun JDK:****
>
> ** **
>
> The option -XX:+UseCompressedOops became available from around JDK6u14 [1].
> ****
>
> Before 6u23, the option has to be explicitly set on the command line or
> from a config file (.hotspotrc) in order to use compressed oops.****
>
> From 6u23 and on, the ergonomics in HotSpot VM will automatically enable
> UseCompressedOops when the whole GC heap is less than around 32GB and G1GC
> is not in use. 7017008 [2] removed the G1GC limitation, and was delivered
> in JDK7 (but not in any of the released JDK6 versions).****
>
> ** **
>
> - Kris****
>
> ** **
>
> [1]:  http://www.oracle.com/technetwork/java/javase/6u14-137039.html
> [2]:  http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7017008 ****
>
> On Wed, Mar 14, 2012 at 4:44 PM, Dawid Weiss <dawid.weiss at gmail.com>
> wrote:****
>
> Thanks Kris!
>
> I thought about parsing command-line but I wasn't sure about the
> runtime -- can it switch to compressed OOPS on its own (or rather: is
> there a heuristic to switch to compressed OOPS or is it always full
> refs in 64 bit mode unless an explicit command line option's been
> given)?
>
> Dawid****
>
>
> > You could use HotSpotDiagnosticMXBean via JMX to get VM options. An
> example
> > here [1].
> >
> > If you're trying to get this information from the command line, use:
> >   jinfo -flag UseCompressedOops <pid>
> >
> > HTH,
> > - Kris
> >
> > [1]:  https://gist.github.com/1333043
> >
> >
> > On Wed, Mar 14, 2012 at 4:30 PM, Dawid Weiss <dawid.weiss at gmail.com>
> wrote:
> >>
> >> Hi everyone,
> >>
> >> This has been asked on Apache Lucene JIRA and I admit I don't know the
> >> answer:
> >>
> >> Is there a way to detect the reference size (which boils down to
> >> compact vs. full reference on 64 bit machines) from within Java?
> >>
> >> I assume the VM starts without an agent so Instrumentation is not
> >> available. I'd appreciate a comment if somebody knows right away (even
> >> if it's a: "no"), otherwise I'll go through the sources and try to
> >> figure it out on my own.
> >>
> >> Thanks,
> >> Dawid
> >
> >****
>
> ** **
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/attachments/20120314/d2ef35e3/attachment-0001.html 


More information about the hotspot-compiler-dev mailing list