JOL object header information

Aleksey Shipilev aleksey.shipilev at oracle.com
Wed Dec 17 09:24:38 UTC 2014


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.




More information about the jol-dev mailing list