Java Memory Model and java model
This article is mainly based on "deep understanding of Java Virtual Machine: JVM advanced features and Best Practices". The JDK version is 1.6, and some content has changed after version 1.8.
The Java Virtual Machine divides the memory area managed during Java program execution into five parts:Method Area, heap, virtual machine stack, local method stack, program counter.
Based on whether the thread is shared or not,The method area and heap are shared by threads., Program counters, virtual machine stacks, and local method stacks are thread-proprietary.
Program countersIt is the row number indicator of the bytecode executed by the current thread.
Virtual Machine StackDescribes the Memory Model of Java method execution: each method creates a stack frame (storing the local variable table, operand stack, dynamic link, method exit, etc.) while executing ). The method call ends until the end, and the corresponding stack frame's inbound stack to the outbound stack.
Local method StackSimilar to the Virtual Machine stack. Provides Native services for virtual machines.
HeapUsed to store object instances. Main area of garbage collection.
Method AreaStores information about classes loaded by virtual machines, constants, static variables, and compiled code.