JMM
1, the memory model abstraction.
Local memory is an abstraction of JMM and is not real, it covers caches, write buffers, registers, and other hardware and compiler optimizations.
2. Memory visibility issues?
?
3. Reorder
| Compiler optimized reordering |
If the compiler does not change the semantics of the single-threaded routines, the execution order of the statements can be rescheduled. |
| Instruction-level parallel reordering |
Modern processors employ instruction-parallel techniques to overlap multiple instructions, and if there is no data dependency, the processor can change the order in which the statements correspond to machine instructions. |
| Memory system reordering |
Because the processor uses the cache and read/write buffers, this makes the load and storage operations appear to be out of order. |
4, Memory barrier directive.
5, Happens-before
6. Sequential consistency
7. Volatile variables
volatile Variable
-
- Visibility: For the reading of volatile variables, you can always see (any thread) the last write to this volatile variable.
- Atomicity: The read/write of any single volatile variable is atomic, but a compound operation similar to volatile++ is not atomic in nature.
Volatile read-write memory semantics
-
- When a volatile variable is written, jmm flushes the shared variable value in the local memory corresponding to that thread to the main memory.
- When reading a volatile variable, JMM will invalidate the local memory for that thread, and the thread will then read the shared variable from main memory.
8, Locks (lock)
- Lock release has the same memory semantics as volatile writes.
- Lock acquisition has the same memory semantics as volatile reads.
9. Final domain
Still in the study, but also hope that you have a lot of guidance.
Java memory model (to be perfected)