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 intReturns the number of bytes used to pad the fields/classes annotated withContended.static booleanChecks if@Contendedannotations are enabled.static intRetrieve the object alignment in bytes from the JVM.static sun.misc.UnsafeReturnsUnsafeif it is available.static booleanChecks ifUnsafeis available.static booleanis32Bits()Checks if the JVM is a 32 bits one.static booleanChecks if the JVM is a pre-Java 12 version.static voidprintOffsets(Object obj) Utility method usingUnsafeto print the field offset for debugging.static booleanChecks if the JVM restricts the use of@Contendedto internal classes.static booleanChecks if the JVM uses compressed class pointers.static booleanChecks if the JVM uses compressed reference.static booleanChecks 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:
- {
trueif the JVM use compressed referencesfalseotherwise.
-
useCompressedClassPointers
public static boolean useCompressedClassPointers()Checks if the JVM uses compressed class pointers.- Returns:
- {
trueif the JVM use compressed class pointersfalseotherwise.
-
useEmptySlotsInSuper
public static boolean useEmptySlotsInSuper()Checks if the JVM uses more aggressive optimizations to avoid unused gaps in instances.- Returns:
- {
trueif the JVM use empty slots in super classfalseotherwise.
-
restrictContended
public static boolean restrictContended()Checks if the JVM restricts the use of@Contendedto internal classes.- Returns:
- {
trueif the JVM restricts the use of@Contendedto internal classes,falseotherwise.
-
enableContended
public static boolean enableContended()Checks if@Contendedannotations are enabled.- Returns:
- {
trueif@Contendedannotations are enabled,falseotherwise.
-
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:
trueif the JVM is a 32 bits version,falseotherwise.
-
isPreJava12JVM
public static boolean isPreJava12JVM()Checks if the JVM is a pre-Java 12 version.- Returns:
trueif the JVM is a pre-Java 12 version,falseotherwise.
-
hasUnsafe
public static boolean hasUnsafe()Checks ifUnsafeis available.- Returns:
trueif unsafe is available,falseotherwise.
-
getUnsafe
public static sun.misc.Unsafe getUnsafe()ReturnsUnsafeif it is available.- Returns:
Unsafeif it is available,nullotherwise.
-
printOffsets
Utility method usingUnsafeto print the field offset for debugging.- Parameters:
obj- the object to analyze
-