Skip to content

Instantly share code, notes, and snippets.

@rednaxelafx
Created March 14, 2012 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rednaxelafx/2038305 to your computer and use it in GitHub Desktop.
Save rednaxelafx/2038305 to your computer and use it in GitHub Desktop.
Getting the HeapOopSize through sun.misc.Unsafe. Refer to http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/2012-March/007445.html
D:\experiment>java -version
java version "1.6.0_30"
Java(TM) SE Runtime Environment (build 1.6.0_30-b12)
Java HotSpot(TM) 64-Bit Server VM (build 20.5-b03, mixed mode)
D:\experiment>groovysh
Groovy Shell (1.8.4, JVM: 1.6.0_30)
Type 'help' or '\h' for help.
---------------------------------------------------------------------------------------------------
groovy:000> sun.misc.Unsafe.theUnsafe.arrayIndexScale(Object[].class)
===> 4
groovy:000> sun.misc.Unsafe.theUnsafe.arrayBaseOffset(Object[].class)
===> 16
groovy:000> quit
D:\experiment>set JAVA_OPTS=-XX:-UseCompressedOops
D:\experiment>groovysh
Groovy Shell (1.8.4, JVM: 1.6.0_30)
Type 'help' or '\h' for help.
---------------------------------------------------------------------------------------------------
groovy:000> sun.misc.Unsafe.theUnsafe.arrayIndexScale(Object[].class)
===> 8
groovy:000> sun.misc.Unsafe.theUnsafe.arrayBaseOffset(Object[].class)
===> 24
groovy:000> quit
D:\experiment>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment