Java memory model (to be perfected)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.