Class VM

java.lang.Object
org.github.jamm.VM

public final class VM extends Object
Utility class for retrieving information from the JVM.
  • 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 references false otherwise.
    • useCompressedClassPointers

      public static boolean useCompressedClassPointers()
      Checks if the JVM uses compressed class pointers.
      Returns:
      {true if the JVM use compressed class pointers false 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 class false 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 with Contended.

      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 if Unsafe is available.
      Returns:
      true if unsafe is available, false otherwise.
    • getUnsafe

      public static sun.misc.Unsafe getUnsafe()
      Returns Unsafe if it is available.
      Returns:
      Unsafe if it is available, null otherwise.
    • printOffsets

      public static void printOffsets(Object obj)
      Utility method using Unsafe to print the field offset for debugging.
      Parameters:
      obj - the object to analyze