Hardware Devices
The processor is very fast, but the processor and memory to deal with, read the operation data, the process of storing the results of the operation is very slow, the need for a cache, the operation of the data copied to the cache, the operation is completed after the results of synchronization memory, the processor does not have to wait for memory read and write speed. However, there is a cache consistency issue that relies on a certain protocol. The "Memory model" can be understood as the abstraction of read-write access to a particular memory or cache under a specific protocol.
Java memory Modelmain memory and working memory
All of the variables are stored in main memory (analogous to hardware master memory, thread sharing, which mainly corresponds to instance data in the Java heap). Each thread has its own working memory (as compared to the hardware cache analogy, the thread is not shared, mainly corresponds to some of the data in the virtual machine stack), and the working memory of the thread holds the copy of the main memory of the variable used by the thread, and the operation of the thread on the variable (read-write, assignment) is in working memory. Cannot directly manipulate the main memory variables, the different threads can not access each other in the working memory of the variable, only through the main memory to access.
interaction between main memory and working memory
Lock: A variable that acts on the main memory and flags a variable in main memory as a thread-exclusive state.
Unlock (Unlocked): A variable acting on the main memory, releasing a variable identified as a thread-exclusive state before being locked by another thread.
READ: A variable that acts on the main memory, transferring the value of a variable to the working memory for the load operation.
Load: A variable that acts on the working memory and puts the value of the variable obtained by the read operation into the variable copy.
Use: A variable that acts on the working memory, passing the value of the variable to the execution engine, the virtual opportunity to the bytecode instruction that uses the value of the variable, when the operation is performed.
Assign (Assignment): A variable that acts on the working memory, assigns the value obtained from the execution engine to the working memory variable, and the virtual opportunity to perform the operation when the byte-code instruction is assigned to the variable.
Store: A variable that acts on the working memory and transfers the variable to main memory for write operations.
Write: A variable that acts on the main memory and puts the value of the variable stored in the store operation into a variable in the main memory.
Java memory model