sizeOf() calculation from ClassLayout seems to be wrong
Enis Söztutar
enis.soz at gmail.com
Tue Jun 7 00:47:20 UTC 2016
Hi,
I was testing ClassLayout with small byte[]'s, and noticed something with a
byte[] size of 9:
[B object internals:
OFFSET SIZE TYPE DESCRIPTION VALUE
0 4 (object header) 01 00 00 00 (00000001
00000000 00000000 00000000) (1)
4 4 (object header) 00 00 00 00 (00000000
00000000 00000000 00000000) (0)
8 4 (object header) f5 00 00 f8 (11110101
00000000 00000000 11111000) (-134217483)
12 4 (object header) 11 00 00 00 (00010001
00000000 00000000 00000000) (17)
16 17 byte [B.<elements> N/A
33 7 (loss due to the next object alignment)
Instance size: 40 bytes
Space losses: 0 bytes internal + 7 bytes external = 7 bytes total
We seem to be calculating an extra 8 bytes in the byte[] layout after the
header. The instance size is calculated as 40, however,
VM.current().sizeOf() returns 32.
This little UT also fails with the latest source code base:
public class ArraySizeTest {
@Test
public void testByteArraySize() {
System.err.println(VM.current().details()); // debug
for (int i = 0; i < 100; i++) {
byte[] b = new byte[i];
long vmSize = VM.current().sizeOf(i);
long clSize = ClassLayout.parseInstance(b).instanceSize();
Assert.assertEquals("sizeOf() from VM and ClassLayout does not match,
VM.sizeOf()="
+ vmSize + ", ClassLayout.instanceSize()=" + clSize, vmSize, clSize
);
}
}
}
I was not able to open a JIRA issue for this, figured I can report here.
Thanks,
Enis
More information about the jol-dev
mailing list