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 classHotspotUnsafe.Sizes
-
Field Summary
Fields Modifier and Type Field Description private intaddressSizeprivate intarrayHeaderSizeprivate longarrayObjectBaseprivate java.lang.ThreadLocal<java.lang.Object[]>BUFFERSprivate booleancompressedKlassOopsEnabledprivate booleancompressedOopsEnabledprivate java.lang.instrument.Instrumentationinstrumentationprivate booleanisAccurateprivate booleanlilliputVMprivate static booleanMAGIC_FIELD_OFFSETprivate static java.lang.StringMAGIC_FIELD_OFFSET_OPTIONprivate booleanmfoInitializedprivate java.lang.reflect.MethodmfoMethodprivate java.lang.ObjectmfoUnsafeprivate longnarrowKlassBaseprivate intnarrowKlassShiftprivate longnarrowOopBaseprivate intnarrowOopShiftprivate intobjectAlignmentprivate intobjectHeaderSizeprivate intoopSizeprivate HotspotUnsafe.Sizessizesprivate sun.misc.UnsafeU
-
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 longaddressOf(java.lang.Object o)Returns the machine address of the given object.intaddressSize()Returns native address size.intarrayBaseOffset(java.lang.String arrayComponentKlass)Returns the array base offset for an array of a given component type.intarrayHeaderSize()Returns the array header size.intarrayIndexScale(java.lang.String arrayComponentKlass)Returns the array index scale for an array of a given component type.intclassPointerSize()Returns class pointer size.java.lang.Stringdetails()Returns the informational details about the current VM modelongfieldOffset(java.lang.reflect.Field field)Returns the field offset for a given field, starting from the object base.private java.lang.StringformatAddressAsHexByAddressSize(long address)booleangetBoolean(java.lang.Object obj, long offset)Reads a boolean off the object at given offset.bytegetByte(java.lang.Object obj, long offset)Reads a byte off the object at given offset.chargetChar(java.lang.Object obj, long offset)Reads a char off the object at given offset.doublegetDouble(java.lang.Object obj, long offset)Reads a double off the object at given offset.floatgetFloat(java.lang.Object obj, long offset)Reads a float off the object at given offset.intgetInt(java.lang.Object obj, long offset)Reads an int off the object at given offset.longgetLong(java.lang.Object obj, long offset)Reads a long off the object at given offset.private intgetMinDiff(java.lang.Class<?> klass)java.lang.ObjectgetObject(java.lang.Object obj, long offset)Reads an object off the object at given offset.shortgetShort(java.lang.Object obj, long offset)Reads a short off the object at given offset.private intguessAlignment()private intguessHeaderSize()private booleanguessLilliput(int addressSize)private longguessNarrowOopBase()private intguessOopSize()private static java.lang.ObjectinstantiateType(int type)private longmagicFieldOffset(java.lang.reflect.Field field, java.lang.RuntimeException original)intobjectAlignment()Returns the object alignment.intobjectHeaderSize()Returns the object header size.longsizeOf(java.lang.Object o)Returns the shallow size of the given object.longsizeOfField(java.lang.String klassName)Returns the size of a field holding the type.private longtoJvmAddress(long address)private longtoJvmKlassAddress(long address)private longtoJvmOopAddress(long address)private longtoNativeAddress(long address)private longtoNativeKlassAddress(long address)private longtoNativeOopAddress(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:VirtualMachineReturns the shallow size of the given object.- Specified by:
sizeOfin interfaceVirtualMachine- Parameters:
o- object- Returns:
- shallow size
-
sizeOfField
public long sizeOfField(java.lang.String klassName)
Description copied from interface:VirtualMachineReturns the size of a field holding the type.- Specified by:
sizeOfFieldin interfaceVirtualMachine- Parameters:
klassName- klass- Returns:
- slot size
-
objectAlignment
public int objectAlignment()
Description copied from interface:VirtualMachineReturns the object alignment.- Specified by:
objectAlignmentin interfaceVirtualMachine- Returns:
- object alignment
-
arrayHeaderSize
public int arrayHeaderSize()
Description copied from interface:VirtualMachineReturns the array header size. This includes the array length pseudofield.- Specified by:
arrayHeaderSizein interfaceVirtualMachine- Returns:
- array header size
-
objectHeaderSize
public int objectHeaderSize()
Description copied from interface:VirtualMachineReturns the object header size.- Specified by:
objectHeaderSizein interfaceVirtualMachine- Returns:
- header size
-
getMinDiff
private int getMinDiff(java.lang.Class<?> klass)
-
addressSize
public int addressSize()
Description copied from interface:VirtualMachineReturns native address size.- Specified by:
addressSizein interfaceVirtualMachine- Returns:
- address size in bytes
-
classPointerSize
public int classPointerSize()
Description copied from interface:VirtualMachineReturns class pointer size.- Specified by:
classPointerSizein interfaceVirtualMachine- Returns:
- class pointer size, in bytes
-
details
public java.lang.String details()
Description copied from interface:VirtualMachineReturns the informational details about the current VM mode- Specified by:
detailsin 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:VirtualMachineReturns 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:
addressOfin interfaceVirtualMachine- Parameters:
o- object- Returns:
- address
-
arrayBaseOffset
public int arrayBaseOffset(java.lang.String arrayComponentKlass)
Description copied from interface:VirtualMachineReturns the array base offset for an array of a given component type.- Specified by:
arrayBaseOffsetin interfaceVirtualMachine- Parameters:
arrayComponentKlass- component type- Returns:
- base offset
-
arrayIndexScale
public int arrayIndexScale(java.lang.String arrayComponentKlass)
Description copied from interface:VirtualMachineReturns the array index scale for an array of a given component type.- Specified by:
arrayIndexScalein interfaceVirtualMachine- Parameters:
arrayComponentKlass- component type- Returns:
- index scale
-
getBoolean
public boolean getBoolean(java.lang.Object obj, long offset)Description copied from interface:VirtualMachineReads a boolean off the object at given offset.- Specified by:
getBooleanin interfaceVirtualMachine- Parameters:
obj- instanceoffset- offset- Returns:
- the boolean
-
getByte
public byte getByte(java.lang.Object obj, long offset)Description copied from interface:VirtualMachineReads a byte off the object at given offset.- Specified by:
getBytein interfaceVirtualMachine- Parameters:
obj- instanceoffset- offset- Returns:
- the byte
-
getShort
public short getShort(java.lang.Object obj, long offset)Description copied from interface:VirtualMachineReads a short off the object at given offset.- Specified by:
getShortin interfaceVirtualMachine- Parameters:
obj- instanceoffset- offset- Returns:
- the short
-
getChar
public char getChar(java.lang.Object obj, long offset)Description copied from interface:VirtualMachineReads a char off the object at given offset.- Specified by:
getCharin interfaceVirtualMachine- Parameters:
obj- instanceoffset- offset- Returns:
- the char
-
getInt
public int getInt(java.lang.Object obj, long offset)Description copied from interface:VirtualMachineReads an int off the object at given offset.- Specified by:
getIntin interfaceVirtualMachine- Parameters:
obj- instanceoffset- offset- Returns:
- the int
-
getFloat
public float getFloat(java.lang.Object obj, long offset)Description copied from interface:VirtualMachineReads a float off the object at given offset.- Specified by:
getFloatin interfaceVirtualMachine- Parameters:
obj- instanceoffset- offset- Returns:
- the float
-
getLong
public long getLong(java.lang.Object obj, long offset)Description copied from interface:VirtualMachineReads a long off the object at given offset.- Specified by:
getLongin interfaceVirtualMachine- Parameters:
obj- instanceoffset- offset- Returns:
- the long
-
getDouble
public double getDouble(java.lang.Object obj, long offset)Description copied from interface:VirtualMachineReads a double off the object at given offset.- Specified by:
getDoublein interfaceVirtualMachine- Parameters:
obj- instanceoffset- offset- Returns:
- the double
-
getObject
public java.lang.Object getObject(java.lang.Object obj, long offset)Description copied from interface:VirtualMachineReads an object off the object at given offset.- Specified by:
getObjectin interfaceVirtualMachine- Parameters:
obj- instanceoffset- offset- Returns:
- the Object
-
fieldOffset
public long fieldOffset(java.lang.reflect.Field field)
Description copied from interface:VirtualMachineReturns the field offset for a given field, starting from the object base.- Specified by:
fieldOffsetin 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)
-
-