Class ClassLayout
java.lang.Object
org.openjdk.jol.info.ClassLayout
Handles the class data *with* the layout information.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ClassDataprivate final SortedSet<FieldLayout> private final booleanprivate final intprivate final intprivate final intprivate final DataModelprivate final long(package private) static final String[] -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateClassLayout(ClassData classData, SortedSet<FieldLayout> fields, DataModel model, long instanceSize, int lossesInternal, int lossesExternal, int lossesTotal) -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidcheckInvariants(SortedSet<FieldLayout> fields, long instanceSize) static ClassLayoutcreate(ClassData classData, SortedSet<FieldLayout> fields, DataModel model, long instanceSize, boolean check) Builds the class layout.booleanfields()Answer the set of fields, including those in superclasseslongLoosed bytes due to next object alignmentlongLoosed bytes from padding between fieldslongTotal loosed bytes i.e.inthashCode()intAnswer header sizelongAnswer instance sizestatic ClassLayoutparseClass(Class<?> klass) Produce the class layout for the given class.static ClassLayoutparseClass(Class<?> klass, Layouter layouter) Produce the class layout for the given class, and given layouter.static ClassLayoutparseInstance(Object instance) Produce the class layout for the given instance.static ClassLayoutparseInstance(Object instance, Layouter layouter) Produce the class layout for the given instance, and given layouter.private static StringparseMarkWord(int mark) private static StringparseMarkWord(long mark) private static StringtoHex(int x) private static StringtoHex(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
-
toHex
-
toHex
-
parseMarkWord
-
parseMarkWord
-
equals
-
hashCode
-