Significance
The JVM defines the memory model to mask the memory access differences between various hardware and operating systems, enabling Java programs to achieve consistent access across all platforms
Dictionary table
- Variables: instance fields static fields and elements constituting array objects, etc., but excluding local variables and method parameters (thread-private)
- Main memory: Is the memory of the physical hardware
- Working memory: Each thread has a working memory that stores the copy of the primary memory used, the operation of the thread must be executed in the working memory and then returned to the main memory
Inter-memory operation
Operation explanation
- Lock: Locks the variable to allow only one thread to use it within a single time
- Unlock: Release variable lock
- READ: Thread reads variables from main memory to working memory
- Load: Load read memory into
- Use: Pass the variable to the execution engine
- Assgin: The execution engine uses variables to assign values to working memory
- Store: Working memory stores variables from working memory to main memory
- Write: Main memory writes the variables of the working memory requirement store
Usage rules
- Read with Load,store and write must appear in pairs
- Variables must be synchronized to main memory after changes in working memory
- Variables without assign cannot be written back to main memory
- Working memory cannot produce new variables, all variables must be fetched from main memory
- The value of the variable after the main memory executes lock on a variable will empty the working memory
- Before executing a unlock on a variable, you must first synchronize it to main memory
Refer to the in-depth understanding of Java virtual Machines--p365
Java memory model