Why the maximum array size of ArrayList is Integer.MAX_VALUE - 8?

前端 未结 3 2039
一生所求
一生所求 2020-12-06 10:22

I am studying Java 8 documentation for ArrayList. I got that maximum array size is defined as Integer.MAX_VALUE - 8 means 2^31 – 8 = 2 147

3条回答
  •  没有蜡笔的小新
    2020-12-06 10:39

    The size of object header can not exceed 8 byte.

    For HotSpot:

    The object header consists of a mark word and a klass pointer.

    The mark word has word size (4 byte on 32 bit architectures, 8 byte on 64 bit architectures) and

    the klass pointer has word size on 32 bit architectures. On 64 bit architectures the klass pointer either has word size, but can also have 4 byte if the heap addresses can be encoded in these 4 bytes.

    This optimization is called "compressed oops" and you can also control it with the option UseCompressedOops.

    What is in java object header

提交回复
热议问题