JOL object header information

Serkan ÖZAL serkanozal86 at hotmail.com
Wed Dec 17 10:25:55 UTC 2014


Aleksey Shipilev yazmış:
> On 12/16/2014 01:43 PM, Rafael Winterhalter wrote:
>   
>> If this is considered feasible: One could play similar tricks and
>> self-attach an agent via tools.jar and always print the correct instance
>> size via the Instrumentation API and only print the estimated size if this
>> is impossible? I would be more than happy to implement the feature, I just
>> did something similar for a test suite that required an agent. 
>>     
>
> Well, JOL can already be manually attached to as an agent, and it will
> use Instrumentation API then, see the "Instance size" below. It would be
> interesting to experiment with self-attachment though.
>
> $ java -jar jol-internals.jar java.lang.String
> Running 64-bit HotSpot VM.
> Using compressed references with 3-bit shift.
> Objects are 8 bytes aligned.
> Field sizes by type: 4, 1, 1, 2, 2, 4, 4, 8, 8 [bytes]
> Array element sizes: 4, 1, 1, 2, 2, 4, 4, 8, 8 [bytes]
>
> java.lang.String object internals:
>  OFFSET  SIZE   TYPE DESCRIPTION                    VALUE
>       0     4        (object header)                N/A
>       4     4        (object header)                N/A
>       8     4        (object header)                N/A
>      12     4 char[] String.value                   N/A
>      16     4    int String.hash                    N/A
>      20     4        (loss due to the next object alignment)
> Instance size: 24 bytes (estimated, add this JAR via -javaagent: to get
> accurate result)
> Space losses: 0 bytes internal + 4 bytes external = 4 bytes total
>
>
> $ java -javaagent:jol-internals.jar -jar jol-internals.jar java.lang.String
> Running 64-bit HotSpot VM.
> Using compressed references with 3-bit shift.
> Objects are 8 bytes aligned.
> Field sizes by type: 4, 1, 1, 2, 2, 4, 4, 8, 8 [bytes]
> Array element sizes: 4, 1, 1, 2, 2, 4, 4, 8, 8 [bytes]
>
> java.lang.String object internals:
>  OFFSET  SIZE   TYPE DESCRIPTION                    VALUE
>       0     4        (object header)                N/A
>       4     4        (object header)                N/A
>       8     4        (object header)                N/A
>      12     4 char[] String.value                   N/A
>      16     4    int String.hash                    N/A
>      20     4        (loss due to the next object alignment)
> Instance size: 24 bytes (reported by VM agent)
> Space losses: 0 bytes internal + 4 bytes external = 4 bytes total
>
>
> -Aleksey.
>
>
>
>
>   
Hi Aleksey,

If you want to use self attached Instrumentation agent,
I can send a patch similar like I did here: 
https://github.com/serkan-ozal/jillegal-agent/blob/master/src/main/java/tr/com/serkanozal/jillegal/agent/JillegalAgent.java#L174

BTW, I will also send another patch for Hotspot Servicability Agent 
support (not just for compressed-oops, for general use of it, 
compressed-oops will be only a feature of SA support patch) possibly in 
2 weeks. Sorry for latency :)

Regards.

--

Serkan ÖZAL


More information about the jol-dev mailing list