Package org.github.jamm

# Class VM

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

public final class VM extends Object
Utility class for retrieving information from the JVM.

## Method Summary

Modifier and Type
Method
Description
`static int`
`contendedPaddingWidth()`
Returns the number of bytes used to pad the fields/classes annotated with `Contended`.
`static boolean`
`enableContended()`
Checks if `@Contended` annotations are enabled.
`static int`
`getObjectAlignmentInBytes()`
Retrieve the object alignment in bytes from the JVM.
`static sun.misc.Unsafe`
`getUnsafe()`
Returns `Unsafe` if it is available.
`static boolean`
`hasUnsafe()`
Checks if `Unsafe` is available.
`static boolean`
`is32Bits()`
Checks if the JVM is a 32 bits one.
`static boolean`
`isPreJava12JVM()`
Checks if the JVM is a pre-Java 12 version.
`static void`
`printOffsets(Object obj)`
Utility method using `Unsafe` to print the field offset for debugging.
`static boolean`
`restrictContended()`
Checks if the JVM restricts the use of `@Contended` to internal classes.
`static boolean`
`useCompressedClassPointers()`
Checks if the JVM uses compressed class pointers.
`static boolean`
`useCompressedOops()`
Checks if the JVM uses compressed reference.
`static boolean`
`useEmptySlotsInSuper()`
Checks if the JVM uses more aggressive optimizations to avoid unused gaps in instances.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## 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