Java Memory Mannequin
페이지 정보

본문
The Java memory mannequin describes how threads in the Java programming language work together by memory. Along with the description of single-threaded execution of code, the memory mannequin offers the semantics of the Java programming language. The Java programming language and platform present thread capabilities. Synchronization between threads is notoriously tough for builders; this difficulty is compounded as a result of Java applications can run on a wide range of processors and working methods. To be able to attract conclusions a few program's conduct, Java's designers decided they needed to clearly outline possible behaviors of all Java packages. On trendy platforms, code is continuously not executed within the order it was written. It's reordered by the compiler, the processor and the memory subsystem to realize maximum efficiency. On multiprocessor architectures, individual processors may have their own local caches which can be out of sync with predominant memory. It is mostly undesirable to require threads to stay completely in sync with each other because this would be too pricey from a efficiency viewpoint.
In consequence, different threads may observe totally different values of the same shared information at any given time. In a single-threaded environment, it is easy to cause about code execution. The everyday method requires the system to implement as-if-serial semantics for individual threads in isolation. When an individual thread executes, Memory Wave Workshop it is going to seem as if all the actions taken by that thread occur in the order they seem in this system, even when the actions themselves happen out of order. If one thread executes its instructions out of order, then another thread would possibly see the truth that these instructions were executed out of order, even when that did not affect the semantics of the primary thread. If no reorderings are carried out, and the learn of y in Thread 2 returns the value 2, then the next learn of x should return the worth 1, as a result of the write to x was carried out earlier than the write to y. The Java Memory Mannequin (JMM) defines the allowable conduct of multithreaded programs, and due to this fact describes when such reorderings are potential.
It places execution-time constraints on the connection between threads and primary memory in order to achieve consistent and reliable Java applications. By doing this, it makes it doable to purpose about code execution in a multithreaded environment, even within the face of optimizations carried out by the dynamic compiler, the processor(s), and the caches. For the execution of a single thread, the rules are easy. The Java Language Specification requires a Java virtual machine to observe inside-thread as-if-serial semantics. The runtime (which, in this case, normally refers to the dynamic compiler, the processor and the memory subsystem) is free to introduce any useful execution optimizations so long as the results of the thread in isolation is guaranteed to be exactly the same as it will have been had all the statements been executed in the order the statements occurred in this system (also known as program order). The main caveat of that is that as-if-serial semantics do not stop completely different threads from having totally different views of the data.
The memory mannequin gives clear guidance about what values are allowed to be returned when the data is read. The essential guidelines suggest that particular person actions may be reordered, as lengthy as the as-if-serial semantics of the thread are usually not violated, and actions that indicate communication between threads, such as the acquisition or launch of a lock, be sure that actions that occur previous to them are seen by other threads that see their results. For example, everything that happens before the discharge of a lock can be seen to be ordered earlier than and visual to every little thing that happens after a subsequent acquisition of that very same lock. Mathematically, there's a partial order called the happens-earlier than order over all actions performed by the program. The occurs-before order subsumes this system order; if one motion happens earlier than another in the program order, it should happen before the opposite within the occurs-before order.
In addition, releases and subsequent acquisitions of locks type edges within the happens-before graph. A learn is allowed to return the worth of a write if that write is the last write to that variable before the learn along some path in the occurs-earlier than order, or if the write just isn't ordered with respect to that learn in the happens-before order. The Java memory mannequin was the primary attempt to provide a comprehensive memory model for a preferred programming language. It was justified by the growing prevalence of concurrent and parallel programs, and the need to supply instruments and technologies with clear semantics for such techniques. Pugh, William (2000). "The Java memory mannequin is fatally flawed" (PDF). Concurrency: Observe and Experience. Goetz, Brian (2004-02-24). "Fixing the Java Memory Model, Half 2" (PDF). Jeremy Manson and Brian Goetz (February 2004). "JSR 133 (Java Memory Model) FAQ". Retrieved 2010-10-18. The Java Memory Mannequin describes what behaviors are authorized in multithreaded code, and the way threads may interact by means of memory. It describes the relationship between variables in a program and the low-level details of storing and retrieving them to and from Memory Wave Workshop or registers in an actual computer system. It does this in a approach that can be carried out correctly utilizing a wide variety of hardware and a large number of compiler optimizations. Java Language Specification, Oracle. Manson, Jeremy. "JSR-133 FAQ". Goetz, Brian (2004-02-24). "Fixing the Java Memory Model, Part 1" (PDF). Java principle and follow: Fixing the Java Memory Model, half 1 - An article describing issues with the original Java memory mannequin. Java principle and practice: Fixing the Java Memory Mannequin, part 2 - Explains the changes JSR 133 made to the Java memory model.
- 이전글The 10 Most Scariest Things About Local Orangery Renovation 25.11.26
- 다음글Study Exactly How We Made Yellow Last Month 25.11.26
댓글목록
등록된 댓글이 없습니다.





