Package org.openjdk.jol.vm
Class HotspotUnsafe
- java.lang.Object
-
- org.openjdk.jol.vm.HotspotUnsafe
-
- All Implemented Interfaces:
VirtualMachine
class HotspotUnsafe extends java.lang.Object implements VirtualMachine
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
HotspotUnsafe.Sizes
-
Field Summary
Fields Modifier and Type Field Description private int
addressSize
private int
arrayHeaderSize
private long
arrayObjectBase
private java.lang.ThreadLocal<java.lang.Object[]>
BUFFERS
private boolean
compressedKlassOopsEnabled
private boolean
compressedOopsEnabled
private java.lang.instrument.Instrumentation
instrumentation
private boolean
isAccurate
private boolean
lilliputVM
private static boolean
MAGIC_FIELD_OFFSET
private static java.lang.String
MAGIC_FIELD_OFFSET_OPTION
private boolean
mfoInitialized
private java.lang.reflect.Method
mfoMethod
private java.lang.Object
mfoUnsafe
private long
narrowKlassBase
private int
narrowKlassShift
private long
narrowOopBase
private int
narrowOopShift
private int
objectAlignment
private int
objectHeaderSize
private int
oopSize
private HotspotUnsafe.Sizes
sizes
private sun.misc.Unsafe
U
-
Constructor Summary
Constructors Constructor Description HotspotUnsafe(sun.misc.Unsafe u, java.lang.instrument.Instrumentation inst)
HotspotUnsafe(sun.misc.Unsafe u, java.lang.instrument.Instrumentation inst, UniverseData saDetails)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description long
addressOf(java.lang.Object o)
Returns the machine address of the given object.int
addressSize()
Returns native address size.int
arrayBaseOffset(java.lang.String arrayComponentKlass)
Returns the array base offset for an array of a given component type.int
arrayHeaderSize()
Returns the array header size.int
arrayIndexScale(java.lang.String arrayComponentKlass)
Returns the array index scale for an array of a given component type.int
classPointerSize()
Returns class pointer size.java.lang.String
details()
Returns the informational details about the current VM modelong
fieldOffset(java.lang.reflect.Field field)
Returns the field offset for a given field, starting from the object base.private java.lang.String
formatAddressAsHexByAddressSize(long address)
boolean
getBoolean(java.lang.Object obj, long offset)
Reads a boolean off the object at given offset.byte
getByte(java.lang.Object obj, long offset)
Reads a byte off the object at given offset.char
getChar(java.lang.Object obj, long offset)
Reads a char off the object at given offset.double
getDouble(java.lang.Object obj, long offset)
Reads a double off the object at given offset.float
getFloat(java.lang.Object obj, long offset)
Reads a float off the object at given offset.int
getInt(java.lang.Object obj, long offset)
Reads an int off the object at given offset.long
getLong(java.lang.Object obj, long offset)
Reads a long off the object at given offset.private int
getMinDiff(java.lang.Class<?> klass)
java.lang.Object
getObject(java.lang.Object obj, long offset)
Reads an object off the object at given offset.short
getShort(java.lang.Object obj, long offset)
Reads a short off the object at given offset.private int
guessAlignment()
private int
guessHeaderSize()
private boolean
guessLilliput(int addressSize)
private long
guessNarrowOopBase()
private int
guessOopSize()
private static java.lang.Object
instantiateType(int type)
private long
magicFieldOffset(java.lang.reflect.Field field, java.lang.RuntimeException original)
int
objectAlignment()
Returns the object alignment.int
objectHeaderSize()
Returns the object header size.long
sizeOf(java.lang.Object o)
Returns the shallow size of the given object.long
sizeOfField(java.lang.String klassName)
Returns the size of a field holding the type.private long
toJvmAddress(long address)
private long
toJvmKlassAddress(long address)
private long
toJvmOopAddress(long address)
private long
toNativeAddress(long address)
private long
toNativeKlassAddress(long address)
private long
toNativeOopAddress(long address)
-
-
-
Field Detail
-
MAGIC_FIELD_OFFSET_OPTION
private static final java.lang.String MAGIC_FIELD_OFFSET_OPTION
- See Also:
- Constant Field Values
-
MAGIC_FIELD_OFFSET
private static final boolean MAGIC_FIELD_OFFSET
-
U
private final sun.misc.Unsafe U
-
instrumentation
private final java.lang.instrument.Instrumentation instrumentation
-
isAccurate
private final boolean isAccurate
-
addressSize
private final int addressSize
-
objectAlignment
private final int objectAlignment
-
oopSize
private final int oopSize
-
compressedOopsEnabled
private final boolean compressedOopsEnabled
-
narrowOopBase
private final long narrowOopBase
-
narrowOopShift
private final int narrowOopShift
-
compressedKlassOopsEnabled
private final boolean compressedKlassOopsEnabled
-
narrowKlassBase
private final long narrowKlassBase
-
narrowKlassShift
private final int narrowKlassShift
-
arrayHeaderSize
private final int arrayHeaderSize
-
objectHeaderSize
private final int objectHeaderSize
-
arrayObjectBase
private final long arrayObjectBase
-
sizes
private final HotspotUnsafe.Sizes sizes
-
lilliputVM
private final boolean lilliputVM
-
mfoInitialized
private volatile boolean mfoInitialized
-
mfoUnsafe
private java.lang.Object mfoUnsafe
-
mfoMethod
private java.lang.reflect.Method mfoMethod
-
BUFFERS
private final java.lang.ThreadLocal<java.lang.Object[]> BUFFERS
-
-
Constructor Detail
-
HotspotUnsafe
HotspotUnsafe(sun.misc.Unsafe u, java.lang.instrument.Instrumentation inst, UniverseData saDetails)
-
HotspotUnsafe
HotspotUnsafe(sun.misc.Unsafe u, java.lang.instrument.Instrumentation inst)
-
-
Method Detail
-
guessLilliput
private boolean guessLilliput(int addressSize)
-
guessNarrowOopBase
private long guessNarrowOopBase()
-
guessOopSize
private int guessOopSize()
-
guessHeaderSize
private int guessHeaderSize()
-
sizeOf
public long sizeOf(java.lang.Object o)
Description copied from interface:VirtualMachine
Returns the shallow size of the given object.- Specified by:
sizeOf
in interfaceVirtualMachine
- Parameters:
o
- object- Returns:
- shallow size
-
sizeOfField
public long sizeOfField(java.lang.String klassName)
Description copied from interface:VirtualMachine
Returns the size of a field holding the type.- Specified by:
sizeOfField
in interfaceVirtualMachine
- Parameters:
klassName
- klass- Returns:
- slot size
-
objectAlignment
public int objectAlignment()
Description copied from interface:VirtualMachine
Returns the object alignment.- Specified by:
objectAlignment
in interfaceVirtualMachine
- Returns:
- object alignment
-
arrayHeaderSize
public int arrayHeaderSize()
Description copied from interface:VirtualMachine
Returns the array header size. This includes the array length pseudofield.- Specified by:
arrayHeaderSize
in interfaceVirtualMachine
- Returns:
- array header size
-
objectHeaderSize
public int objectHeaderSize()
Description copied from interface:VirtualMachine
Returns the object header size.- Specified by:
objectHeaderSize
in interfaceVirtualMachine
- Returns:
- header size
-
getMinDiff
private int getMinDiff(java.lang.Class<?> klass)
-
addressSize
public int addressSize()
Description copied from interface:VirtualMachine
Returns native address size.- Specified by:
addressSize
in interfaceVirtualMachine
- Returns:
- address size in bytes
-
classPointerSize
public int classPointerSize()
Description copied from interface:VirtualMachine
Returns class pointer size.- Specified by:
classPointerSize
in interfaceVirtualMachine
- Returns:
- class pointer size, in bytes
-
details
public java.lang.String details()
Description copied from interface:VirtualMachine
Returns the informational details about the current VM mode- Specified by:
details
in interfaceVirtualMachine
- Returns:
- String details
-
instantiateType
private static java.lang.Object instantiateType(int type)
-
guessAlignment
private int guessAlignment()
-
addressOf
public long addressOf(java.lang.Object o)
Description copied from interface:VirtualMachine
Returns the machine address of the given object. Note that in some VM modes, the addresses would be guesses, based on internal experiments which would try to figure out the reference encoding. Use this data with care. Doing the naked memory access on the result of this method may corrupt the memory.- Specified by:
addressOf
in interfaceVirtualMachine
- Parameters:
o
- object- Returns:
- address
-
arrayBaseOffset
public int arrayBaseOffset(java.lang.String arrayComponentKlass)
Description copied from interface:VirtualMachine
Returns the array base offset for an array of a given component type.- Specified by:
arrayBaseOffset
in interfaceVirtualMachine
- Parameters:
arrayComponentKlass
- component type- Returns:
- base offset
-
arrayIndexScale
public int arrayIndexScale(java.lang.String arrayComponentKlass)
Description copied from interface:VirtualMachine
Returns the array index scale for an array of a given component type.- Specified by:
arrayIndexScale
in interfaceVirtualMachine
- Parameters:
arrayComponentKlass
- component type- Returns:
- index scale
-
getBoolean
public boolean getBoolean(java.lang.Object obj, long offset)
Description copied from interface:VirtualMachine
Reads a boolean off the object at given offset.- Specified by:
getBoolean
in interfaceVirtualMachine
- Parameters:
obj
- instanceoffset
- offset- Returns:
- the boolean
-
getByte
public byte getByte(java.lang.Object obj, long offset)
Description copied from interface:VirtualMachine
Reads a byte off the object at given offset.- Specified by:
getByte
in interfaceVirtualMachine
- Parameters:
obj
- instanceoffset
- offset- Returns:
- the byte
-
getShort
public short getShort(java.lang.Object obj, long offset)
Description copied from interface:VirtualMachine
Reads a short off the object at given offset.- Specified by:
getShort
in interfaceVirtualMachine
- Parameters:
obj
- instanceoffset
- offset- Returns:
- the short
-
getChar
public char getChar(java.lang.Object obj, long offset)
Description copied from interface:VirtualMachine
Reads a char off the object at given offset.- Specified by:
getChar
in interfaceVirtualMachine
- Parameters:
obj
- instanceoffset
- offset- Returns:
- the char
-
getInt
public int getInt(java.lang.Object obj, long offset)
Description copied from interface:VirtualMachine
Reads an int off the object at given offset.- Specified by:
getInt
in interfaceVirtualMachine
- Parameters:
obj
- instanceoffset
- offset- Returns:
- the int
-
getFloat
public float getFloat(java.lang.Object obj, long offset)
Description copied from interface:VirtualMachine
Reads a float off the object at given offset.- Specified by:
getFloat
in interfaceVirtualMachine
- Parameters:
obj
- instanceoffset
- offset- Returns:
- the float
-
getLong
public long getLong(java.lang.Object obj, long offset)
Description copied from interface:VirtualMachine
Reads a long off the object at given offset.- Specified by:
getLong
in interfaceVirtualMachine
- Parameters:
obj
- instanceoffset
- offset- Returns:
- the long
-
getDouble
public double getDouble(java.lang.Object obj, long offset)
Description copied from interface:VirtualMachine
Reads a double off the object at given offset.- Specified by:
getDouble
in interfaceVirtualMachine
- Parameters:
obj
- instanceoffset
- offset- Returns:
- the double
-
getObject
public java.lang.Object getObject(java.lang.Object obj, long offset)
Description copied from interface:VirtualMachine
Reads an object off the object at given offset.- Specified by:
getObject
in interfaceVirtualMachine
- Parameters:
obj
- instanceoffset
- offset- Returns:
- the Object
-
fieldOffset
public long fieldOffset(java.lang.reflect.Field field)
Description copied from interface:VirtualMachine
Returns the field offset for a given field, starting from the object base.- Specified by:
fieldOffset
in interfaceVirtualMachine
- Parameters:
field
- field- Returns:
- offset
-
magicFieldOffset
private long magicFieldOffset(java.lang.reflect.Field field, java.lang.RuntimeException original)
-
toNativeAddress
private long toNativeAddress(long address)
-
toJvmAddress
private long toJvmAddress(long address)
-
toNativeOopAddress
private long toNativeOopAddress(long address)
-
toJvmOopAddress
private long toJvmOopAddress(long address)
-
toNativeKlassAddress
private long toNativeKlassAddress(long address)
-
toJvmKlassAddress
private long toJvmKlassAddress(long address)
-
formatAddressAsHexByAddressSize
private java.lang.String formatAddressAsHexByAddressSize(long address)
-
-