Package org.github.jamm
Class VM
java.lang.Object
org.github.jamm.VM
Utility class for retrieving information from the JVM.
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
Returns the number of bytes used to pad the fields/classes annotated withContended
.static boolean
Checks if@Contended
annotations are enabled.static int
Retrieve the object alignment in bytes from the JVM.static sun.misc.Unsafe
ReturnsUnsafe
if it is available.static boolean
Checks ifUnsafe
is available.static boolean
is32Bits()
Checks if the JVM is a 32 bits one.static boolean
Checks if the JVM is a pre-Java 12 version.static void
printOffsets
(Object obj) Utility method usingUnsafe
to print the field offset for debugging.static boolean
Checks if the JVM restricts the use of@Contended
to internal classes.static boolean
Checks if the JVM uses compressed class pointers.static boolean
Checks if the JVM uses compressed reference.static boolean
Checks if the JVM uses more aggressive optimizations to avoid unused gaps in instances.
-
Method Details
-
getObjectAlignmentInBytes
public static int getObjectAlignmentInBytes()Retrieve the object alignment in bytes from the JVM. If the alignment cannot be retrieved the default value will be returned.- Returns:
- the object alignment in bytes if it can be retrieved or the default value (8).
-
useCompressedOops
public static boolean useCompressedOops()Checks if the JVM uses compressed reference.- Returns:
- {
true
if the JVM use compressed referencesfalse
otherwise.
-
useCompressedClassPointers
public static boolean useCompressedClassPointers()Checks if the JVM uses compressed class pointers.- Returns:
- {
true
if the JVM use compressed class pointersfalse
otherwise.
-
useEmptySlotsInSuper
public static boolean useEmptySlotsInSuper()Checks if the JVM uses more aggressive optimizations to avoid unused gaps in instances.- Returns:
- {
true
if the JVM use empty slots in super classfalse
otherwise.
-
restrictContended
public static boolean restrictContended()Checks if the JVM restricts the use of@Contended
to internal classes.- Returns:
- {
true
if the JVM restricts the use of@Contended
to internal classes,false
otherwise.
-
enableContended
public static boolean enableContended()Checks if@Contended
annotations are enabled.- Returns:
- {
true
if@Contended
annotations are enabled,false
otherwise.
-
contendedPaddingWidth
public static int contendedPaddingWidth()Returns the number of bytes used to pad the fields/classes annotated withContended
.The value will be between 0 and 8192 (inclusive) and will be a multiple of 8.
- Returns:
- the number of bytes used to pad the fields/classes annotated with
Contended
.
-
is32Bits
public static boolean is32Bits()Checks if the JVM is a 32 bits one.- Returns:
true
if the JVM is a 32 bits version,false
otherwise.
-
isPreJava12JVM
public static boolean isPreJava12JVM()Checks if the JVM is a pre-Java 12 version.- Returns:
true
if the JVM is a pre-Java 12 version,false
otherwise.
-
hasUnsafe
public static boolean hasUnsafe()Checks ifUnsafe
is available.- Returns:
true
if unsafe is available,false
otherwise.
-
getUnsafe
public static sun.misc.Unsafe getUnsafe()ReturnsUnsafe
if it is available.- Returns:
Unsafe
if it is available,null
otherwise.
-
printOffsets
Utility method usingUnsafe
to print the field offset for debugging.- Parameters:
obj
- the object to analyze
-