Class ClassLayout


  • public class ClassLayout
    extends java.lang.Object
    Handles the class data *with* the layout information.
    • Field Detail

      • classData

        private final ClassData classData
      • isArray

        private final boolean isArray
      • fields

        private final java.util.SortedSet<FieldLayout> fields
      • size

        private final long size
      • lossesInternal

        private final int lossesInternal
      • lossesExternal

        private final int lossesExternal
      • lossesTotal

        private final int lossesTotal
      • ZERO_RUNS

        static final java.lang.String[] ZERO_RUNS
    • Constructor Detail

      • ClassLayout

        private ClassLayout​(ClassData classData,
                            java.util.SortedSet<FieldLayout> fields,
                            DataModel model,
                            long instanceSize,
                            int lossesInternal,
                            int lossesExternal,
                            int lossesTotal)
    • Method Detail

      • parseClass

        public static ClassLayout parseClass​(java.lang.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​(java.lang.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,
                                         java.util.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​(java.util.SortedSet<FieldLayout> fields,
                                            long instanceSize)
      • fields

        public java.util.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 java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toPrintable

        public java.lang.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 java.lang.String toPrintable​(java.lang.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 java.lang.String toHex​(int x)
      • toHex

        private static java.lang.String toHex​(long x)
      • parseMarkWord

        private static java.lang.String parseMarkWord​(int mark)
      • parseMarkWord

        private static java.lang.String parseMarkWord​(long mark)
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object