Package org.openjdk.jol.info
Class ClassLayout
java.lang.Object
org.openjdk.jol.info.ClassLayout
Handles the class data *with* the layout information.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ClassData
private final SortedSet
<FieldLayout> private final boolean
private final int
private final int
private final int
private final DataModel
private final long
(package private) static final String[]
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
ClassLayout
(ClassData classData, SortedSet<FieldLayout> fields, DataModel model, long instanceSize, int lossesInternal, int lossesExternal, int lossesTotal) -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
checkInvariants
(SortedSet<FieldLayout> fields, long instanceSize) static ClassLayout
create
(ClassData classData, SortedSet<FieldLayout> fields, DataModel model, long instanceSize, boolean check) Builds the class layout.boolean
fields()
Answer the set of fields, including those in superclasseslong
Loosed bytes due to next object alignmentlong
Loosed bytes from padding between fieldslong
Total loosed bytes i.e.int
hashCode()
int
Answer header sizelong
Answer instance sizestatic ClassLayout
parseClass
(Class<?> klass) Produce the class layout for the given class.static ClassLayout
parseClass
(Class<?> klass, Layouter layouter) Produce the class layout for the given class, and given layouter.static ClassLayout
parseInstance
(Object instance) Produce the class layout for the given instance.static ClassLayout
parseInstance
(Object instance, Layouter layouter) Produce the class layout for the given instance, and given layouter.private static String
parseMarkWord
(int mark) private static String
parseMarkWord
(long mark) private static String
toHex
(int x) private static String
toHex
(long x) Produce printable stringly representation of class layout.toPrintable
(Object instance) Produce printable stringly representation of class layout.toString()
-
Field Details
-
classData
-
isArray
private final boolean isArray -
fields
-
model
-
size
private final long size -
lossesInternal
private final int lossesInternal -
lossesExternal
private final int lossesExternal -
lossesTotal
private final int lossesTotal -
ZERO_RUNS
-
-
Constructor Details
-
ClassLayout
private ClassLayout(ClassData classData, SortedSet<FieldLayout> fields, DataModel model, long instanceSize, int lossesInternal, int lossesExternal, int lossesTotal)
-
-
Method Details
-
parseClass
Produce the class layout for the given class. This is a shortcut forparseClass(Class,org.openjdk.jol.layouters.Layouter)
, but with a default layouter.- Parameters:
klass
- class to work on- Returns:
- class layout
-
parseClass
Produce the class layout for the given class, and given layouter. Note: this method is usable as the "caching" shortcut forparseInstance(Object)
. You can use it to cache the introspection results for a constant-sized objects, e.g. plain Java objects. It is not recommended to use this method on arrays, since their lengths differ from instance to instance.- Parameters:
klass
- class to work onlayouter
- class layouter- Returns:
- class layout
-
parseInstance
Produce the class layout for the given instance. This is a shortcut forparseInstance(java.lang.Object,org.openjdk.jol.layouters.Layouter)
, but with a default layouter.- Parameters:
instance
- instance to work on- Returns:
- class layout
-
parseInstance
Produce the class layout for the given instance, and given layouter. These methods, along withparseInstance(Object)
are recommended for use when the shape of the object is not known in advance. For example, variable-sized instances (e.g. Java arrays) would not be parsed byparseClass(Class)
properly, because their lengths are encoded in the instance objects, not in classes.- Parameters:
instance
- instance to work onlayouter
- class layouter- Returns:
- class layout
-
create
public static ClassLayout create(ClassData classData, SortedSet<FieldLayout> fields, DataModel model, long instanceSize, boolean check) Builds the class layout.- Parameters:
classData
- class datafields
- field layoutsmodel
- data model to useinstanceSize
- instance sizecheck
- whether to check important invariants- Returns:
- a new instance of the ClassLayout
-
checkInvariants
-
fields
Answer the set of fields, including those in superclasses- Returns:
- sorted set of fields
-
instanceSize
public long instanceSize()Answer instance size- Returns:
- instance size
-
headerSize
public int headerSize()Answer header size- Returns:
- header size
-
getLossesInternal
public long getLossesInternal()Loosed bytes from padding between fields- Returns:
- Internally loosed bytes
-
getLossesExternal
public long getLossesExternal()Loosed bytes due to next object alignment- Returns:
- Externally loosed bytes
-
getLossesTotal
public long getLossesTotal()Total loosed bytes i.e. lossesInternal + lossesExternal- Returns:
- Total loosed bytes
-
toString
-
toPrintable
Produce printable stringly representation of class layout. This method uses the instance originally provided toparseInstance(Object)
, if that instance is still available.- Returns:
- human-readable layout info
-
toPrintable
Produce printable stringly representation of class layout. This method accepts instance to read the actual data from.- Parameters:
instance
- instance to work on- Returns:
- human-readable layout info
-
toHex
-
toHex
-
parseMarkWord
-
parseMarkWord
-
equals
-
hashCode
public int hashCode()
-