Bug in "loss due alignment" report?

Jaromir Hamala jaromir.hamala at gmail.com
Sat Oct 10 17:12:16 UTC 2015


Hello,

I'm not sure if that's a bug or feature, but I have this code:

public static void main(String[] args) {
        int size = 1;
        byte[] b = new byte[size];

        out.println(ClassLayout.parseClass(b.getClass()).toPrintable(b));
    }

it yields following output:

[B object internals:
 OFFSET  SIZE  TYPE DESCRIPTION                    VALUE
      0     4       (object header)                01 00 00 00 (0000 0001
0000 0000 0000 0000 0000 0000)
      4     4       (object header)                00 00 00 00 (0000 0000
0000 0000 0000 0000 0000 0000)
      8     4       (object header)                84 01 fc df (1000 0100
0000 0001 1111 1100 1101 1111)
     12     4   int [B.length                      N/A
     16     0  byte [B.<elements>                  N/A
     16     8       (loss due to the next object alignment)
Instance size: 24 bytes (reported by Instrumentation API)
Space losses: 0 bytes internal + 8 bytes external = 8 bytes total

The alignment waste should be 7 and not 8 bytes and the element size should
be 1. I realize it can be tricky to fix as the class parser does not have
an access to the actual object instance, but the current report is rather
misleading.

Cheers,
Jaromir

-- 
“Perfection is achieved, not when there is nothing more to add, but when
there is nothing left to take away.”
Antoine de Saint Exupéry


More information about the jol-dev mailing list