Why compressed Oops gives 12 bytes for an object header

This is after the Java 6 memory model. In a 32-bit JVM, the size of the Shallow object

8 bytes (object header) + total of all instance variables + padding (optional) 

If the first 2 members are not added up to a multiple of 8, there will be an addition.

In 64 bit JVM, Shallow size

 16 bytes (object header) + total of all instance variables + padding (optional) 

I understand that this Object header is 2 words long (oracle hotspot VM)

  • class word
  • word tags

in a 32-bit JVM, object header = 2 * 32 bits = 64 bits = 8 bytes
on a 64-bit JVM, object header = 2 * 64 bits = 128 bits = 16 bytes

But with CompressedOops, the three least significant bits are reduced, so it should go back to 8 bytes on a 64-bit JVM for heaps of less than 32 gigs.

But when I tested the layout of the object using JOL (layout of Java objects), it displays 12 bytes for the Object header.

Test code

 public class App { public static void main( String[] args ) { System.out.println(System.getProperty("java.version")); System.out.println(VMSupport.vmDetails()); System.out.println(ClassLayout.parseClass(A.class).toPrintable()); } } class A { int a; } 

Exit

 1.8.0_05 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] com.layout.test.jolTesting.A object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0 12 (object header) N/A 12 4 int Aa N/A Instance size: 16 bytes (estimated, the sample instance is not available) Space losses: 0 bytes internal + 0 bytes external = 0 bytes total 

What am I missing here that adds these extra 4 bytes?

+5
source share
2 answers

As far as I know, this happens because, unlike the word klass, the tag word is not encoded using CompressedOops .

So, 4 bytes (64-bit class compressed word) + 8 bytes (tag) = 12 bytes (header)

+2
source

HotSpot has 8-byte, 12-byte, and 16-byte object headers. This is because the title contains two parts: markword (metainfo about the object) and classword (class reference). In 32/64-bit mode, a tag occupies 4 or 8 bytes. Classword is a β€œsimple” link and therefore can be compressed in 64-bit mode.

see: https://shipilev.net/blog/2014/heapdump-is-a-lie/

0
source

Source: https://habr.com/ru/post/1200442/


All Articles