Java Memory Model > 온라인상담

온라인상담

글로벌드림다문화연구소에 오신걸 환영합니다
온라인상담

Java Memory Model

페이지 정보

작성자 Regan Aleman 작성일25-11-19 07:11 조회54회 댓글0건

본문

The Java memory mannequin describes how threads in the Java programming language interact by Memory Wave Experience. Together with the description of single-threaded execution of code, the memory mannequin provides the semantics of the Java programming language. The Java programming language and platform present thread capabilities. Synchronization between threads is notoriously troublesome for builders; this issue is compounded because Java applications can run on a wide range of processors and operating systems. To be in a position to draw conclusions a couple of program's behavior, Java's designers determined they had to clearly define possible behaviors of all Java packages. On fashionable platforms, code is continuously not executed in the order it was written. It's reordered by the compiler, the processor and the memory subsystem to attain maximum performance. On multiprocessor architectures, particular person processors might have their own native caches which can be out of sync with main memory. It is usually undesirable to require threads to remain completely in sync with one another because this could be too costly from a efficiency viewpoint.



As a result, different threads might observe completely different values of the same shared information at any given time. In a single-threaded surroundings, it is easy to reason about code execution. The typical method requires the system to implement as-if-serial semantics for particular person threads in isolation. When an individual thread executes, it should seem as if all the actions taken by that thread occur in the order they appear in this system, even when the actions themselves occur out of order. If one thread executes its directions out of order, then another thread may see the truth that those instructions have been executed out of order, even when that didn't have an effect on the semantics of the first 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 ought to return the value 1, as a result of the write to x was carried out earlier than the write to y. The Java Memory Model (JMM) defines the allowable behavior of multithreaded applications, and therefore describes when such reorderings are potential.



It locations execution-time constraints on the relationship between threads and predominant memory in order to realize consistent and dependable Java applications. By doing this, it makes it possible to purpose about code execution in a multithreaded setting, even in the face of optimizations performed by the dynamic compiler, the processor(s), and the caches. For the execution of a single thread, the principles are simple. The Java Language Specification requires a Java virtual machine to observe within-thread as-if-serial semantics. The runtime (which, in this case, usually refers to the dynamic compiler, the processor and the memory subsystem) is free to introduce any useful execution optimizations as long as the result of the thread in isolation is assured to be exactly the identical as it would have been had all the statements been executed within the order the statements occurred in the program (also referred to as program order). The most important caveat of this is that as-if-serial semantics do not stop different threads from having different views of the info.



pexels-photo-198703.jpegThe memory model gives clear steerage about what values are allowed to be returned when the information is learn. The basic rules suggest that individual actions might be reordered, as long as the as-if-serial semantics of the thread are not violated, and actions that suggest communication between threads, such because the acquisition or release of a lock, be certain that actions that happen previous to them are seen by other threads that see their effects. For instance, every part that occurs earlier than the release of a lock will likely be seen to be ordered earlier than and visible to every part that happens after a subsequent acquisition of that 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 the program order; if one motion occurs earlier than another in the program order, it is going to occur earlier than the opposite in the happens-before order.



As well as, releases and subsequent acquisitions of locks type edges within the happens-earlier than graph. A read is allowed to return the value 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 will not be ordered with respect to that learn within the happens-before order. The Java memory model was the first try to provide a comprehensive memory model for a popular programming language. It was justified by the rising prevalence of concurrent and parallel techniques, and Memory Wave the necessity to provide tools and applied sciences with clear semantics for such systems. Pugh, William (2000). "The Java memory model is fatally flawed" (PDF). Concurrency: Practice and Expertise. Goetz, Brian (2004-02-24). "Fixing the Java Memory Model, Part 2" (PDF). Jeremy Manson and Brian Goetz (February 2004). "JSR 133 (Java Memory Mannequin) FAQ". Retrieved 2010-10-18. The Java Memory Model describes what behaviors are authorized in multithreaded code, and the way threads might work together through memory. It describes the relationship between variables in a program and the low-level details of storing and retrieving them to and from memory or registers in an actual pc system. It does this in a manner that may be implemented accurately utilizing a large number of hardware and a wide number of compiler optimizations. Java Language Specification, Oracle. Manson, Jeremy. "JSR-133 FAQ". Goetz, Brian (2004-02-24). "Fixing the Java Memory Model, Half 1" (PDF). Java concept and follow: Fixing the Java Memory Model, half 1 - An article describing problems with the unique Java memory model. Java theory and observe: Fixing the Java Memory Mannequin, Memory Wave part 2 - Explains the modifications JSR 133 made to the Java memory mannequin.

262649_in_1000x1000.jpg

댓글목록

등록된 댓글이 없습니다.