The object structure that Java programmers must know from JVM zero foundation to advanced combat

The object structure that Java programmers must know from JVM zero foundation to advanced combat

The object structure that Java programmers must know from JVM zero foundation to advanced combat



foreword

The object structure that Java programmers must know from JVM zero foundation to advanced combat


JAVA object memory layout

insert image description here

  • The object header is used to store the metadata information of the object
    • The length of part of Mark Word data is 32bit and 64bit respectively in 32-bit and 64-bit virtual machines (compression pointers are not enabled), and stores the runtime data of the object itself, such as hash value. Mark Word is generally designed as a non-fixed data structure in order to store more data information and reuse its own storage space.
    • The type pointer points to its class metadata pointer, which is used to determine which class instance the object belongs to.
  • instance data
    • Instance data stores real effective data, such as the contents of various fields. The allocation strategy of each field is longs/doubles, ints, shorts/chars, bytes/boolean, oops (ordinary object pointers), and fields of the same width are always allocated Together, it is convenient to fetch data later. Variables defined by the parent class appear before variables defined by the subclass.
  • Align padding
    • The alignment padding is just a placeholder, not required

Summarize

This article introduces the entire content of the object structure that Java programmers must know from JVM zero foundation to advanced actual combat. I will continue to update it in the future. If you like it, please click to follow. The JVM series will continue to be updated.

Guess you like

Origin blog.csdn.net/weixin_42397937/article/details/131156364