Java memory model

Source: Internet
Author: User

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
    1. Lock: Locks the variable to allow only one thread to use it within a single time
    2. Unlock: Release variable lock
    3. READ: Thread reads variables from main memory to working memory
    4. Load: Load read memory into
    5. Use: Pass the variable to the execution engine
    6. Assgin: The execution engine uses variables to assign values to working memory
    7. Store: Working memory stores variables from working memory to main memory
    8. 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

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.