The whole process of Java object creation and recycling

Table of contents

1 Introduction

2 Java object creation

2.1 Class loading check

2.1.1 Who will load

2.1.2 How to load

2.2 Allocating memory

2.3 Initialize zero value

2.4 Setting the object header

2.5 Execute clinit

3 Object recycling

4 Supplement Tomcat to break the parental delegation mechanism


Before talking about the creation of java, let's first understand the memory composition of the Java virtual machine. When the Java virtual machine is started, the space allocated by the system to the JVM will be logically divided into heap, virtual machine stack, local method stack, method area, and program The counter has five parts, as shown in the figure below:

 

Heap : place new objects and arrays

Virtual machine stack : Before the thread runs, a thread stack space will be allocated to it. Each method execution in the thread will generate a stack frame and put it in the thread stack. The stack frame contains local variable tables, operand stacks, dynamic connections and methods. Export four parts.

        Local variable table: store local variables in methods

        Operand stack: data used for assignment or calculation

        Dynamic link: the entry address of the method execution

        Method exit: returns the address of the calling method

Local method stack : similar to the virtual machine stack, it is a stack for calling non-java methods

Method area : store class meta information, constant pool

Program Counter : Points to where the thread is running

Guess you like

Origin blog.csdn.net/s_nshine/article/details/132094627