Class ClassLayout

java.lang.Object
org.openjdk.jol.info.ClassLayout

public class ClassLayout extends Object
Handles the class data *with* the layout information.
  • Field Details

    • classData

      private final ClassData classData
    • isArray

      private final boolean isArray
    • fields

      private final SortedSet<FieldLayout> fields
    • model

      private final DataModel model
    • size

      private final long size
    • lossesInternal

      private final int lossesInternal
    • lossesExternal

      private final int lossesExternal
    • lossesTotal

      private final int lossesTotal
    • ZERO_RUNS

      static final String[] ZERO_RUNS
  • Constructor Details

  • Method Details

    • parseClass

      public static ClassLayout parseClass(Class<?> klass)
      Produce the class layout for the given class. This is a shortcut for parseClass(Class,org.openjdk.jol.layouters.Layouter), but with a default layouter.
      Parameters:
      klass - class to work on
      Returns:
      class layout
    • parseClass

      public static ClassLayout parseClass(Class<?> klass, Layouter layouter)
      Produce the class layout for the given class, and given layouter. Note: this method is usable as the "caching" shortcut for parseInstance(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 on
      layouter - class layouter
      Returns:
      class layout
    • parseInstance

      public static ClassLayout parseInstance(Object instance)
      Produce the class layout for the given instance. This is a shortcut for parseInstance(java.lang.Object,org.openjdk.jol.layouters.Layouter), but with a default layouter.
      Parameters:
      instance - instance to work on
      Returns:
      class layout
    • parseInstance

      public static ClassLayout parseInstance(Object instance, Layouter layouter)
      Produce the class layout for the given instance, and given layouter. These methods, along with parseInstance(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 by parseClass(Class) properly, because their lengths are encoded in the instance objects, not in classes.
      Parameters:
      instance - instance to work on
      layouter - 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 data
      fields - field layouts
      model - data model to use
      instanceSize - instance size
      check - whether to check important invariants
      Returns:
      a new instance of the ClassLayout
    • checkInvariants

      private static void checkInvariants(SortedSet<FieldLayout> fields, long instanceSize)
    • fields

      public SortedSet<FieldLayout> 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

      public String toString()
      Overrides:
      toString in class Object
    • toPrintable

      public String toPrintable()
      Produce printable stringly representation of class layout. This method uses the instance originally provided to parseInstance(Object), if that instance is still available.
      Returns:
      human-readable layout info
    • toPrintable

      public String toPrintable(Object instance)
      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

      private static String toHex(int x)
    • toHex

      private static String toHex(long x)
    • parseMarkWord

      private static String parseMarkWord(int mark)
    • parseMarkWord

      private static String parseMarkWord(long mark)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object