The details of the underlying steps of object creation that Java programmers must know from JVM zero foundation to advanced combat

The details of the underlying steps of object creation that Java programmers must know from JVM zero foundation to advanced combat

The details of the underlying steps of object creation that Java programmers must know from JVM zero foundation to advanced combat



foreword

The details of the underlying steps of object creation that Java programmers must know from JVM zero foundation to advanced combat


What are the process steps of Java object creation?

insert image description here

  • When the virtual machine encounters a new instruction, it first checks whether the corresponding class can locate a symbol reference of a class in the constant pool
  • Determine whether this class has been loaded, parsed and initialized
    • Allocate memory space in the Java heap for this newborn object. There are two main ways in which the Java heap allocates memory space:
    • pointer collision
      • Allocating memory space includes two steps of opening up a piece of memory and moving the pointer
      • Concurrency problems may occur in non-atomic steps. The Java virtual machine uses CAS with failed retries to ensure the atomicity of update operations.
    • free list
      • Allocating memory space includes two steps: opening up a piece of memory and modifying the free list
      • Concurrency problems may occur in non-atomic steps. The Java virtual machine uses CAS with failed retries to ensure the atomicity of update operations.
    • Initialize the allocated memory space to zero value
    • Set object header related data
      • GC generational age
      • object's hash code hashCode
      • metadata information
    • execute object method

Summarize

This article introduces all the details of the underlying steps of object creation 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/131156225