Bug in "loss due alignment" report?
Jaromir Hamala
jaromir.hamala at gmail.com
Tue Oct 13 08:27:02 UTC 2015
perhaps one more improvement could be done:
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) 0a 02 fc df (0000 1010
0000 0010 1111 1100 1101 1111)
12 4 int [I.length N/A
16 8 int [I.<elements> N/A
It would be nice to show the actual array length in the value column.
I believe you deliberately decided not to interpret HotSpot internal data,
but this one could be done safely. It's just a convenience thing anyway as
the length can be calculated from size even now.
Cheers,
Jaromir
On Tue, Oct 13, 2015 at 11:14 AM, Jaromir Hamala <jaromir.hamala at gmail.com>
wrote:
> Hi Aleksey,
>
> the `parseInstance()`works nicely, thanks! However the old code is now
> throwing NPE:
>
> public static void main(String[] args) {
> int size = 1;
> byte[] b = new byte[size];
>
> out.println(ClassLayout.parseClass(b.getClass()).toPrintable(b));
> }
>
>
> Exception in thread "main" java.lang.NullPointerException
> at org.openjdk.jol.info.ClassData.arrayLength(ClassData.java:68)
> at org.openjdk.jol.info.ClassData.parseArray(ClassData.java:89)
> at org.openjdk.jol.info.ClassData.parse(ClassData.java:95)
> at org.openjdk.jol.info.ClassData.parseClass(ClassData.java:64)
> at org.openjdk.jol.info.ClassLayout.parseClass(ClassLayout.java:66)
> at org.openjdk.jol.info.ClassLayout.parseClass(ClassLayout.java:50)
> at
> org.openjdk.jol.samples.JOLSample_01_Basic.main(JOLSample_01_Basic.java:58)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:606)
> at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
>
> Cheers,
> Jaromir
>
>
>
> On Mon, Oct 12, 2015 at 10:32 PM, Aleksey Shipilev <
> aleksey.shipilev at oracle.com> wrote:
>
>> Hi Jaromir,
>>
>> On 10/10/2015 08:12 PM, Jaromir Hamala wrote:
>> > 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.
>>
>> Yes, I agree.
>>
>> And the reason you provided is exactly what is happening. Without
>> changing the class parser to accept the instance itself, it would be
>> hard to accommodate any variable-length instance.
>>
>> Luckily, this is easy enough to fix. See:
>> https://bugs.openjdk.java.net/browse/CODETOOLS-7901530
>>
>> Notably, see a new sample:
>>
>> http://hg.openjdk.java.net/code-tools/jol/file/tip/jol-samples/src/main/java/org/openjdk/jol/samples/JOLSample_25_ArrayAlignment.java
>>
>> Please test!
>>
>> Thanks,
>> -Aleksey
>>
>>
>
>
> --
> “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
>
--
“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