JSR 133 - The Java(tm) Memory Model and Thread Specification Revisionjava
Since 1997, several serious flaws have been discovered in the Java Memory Model as defined in Chapter 17 of the Java Language Specification. These flaws allowed for confusing behaviors (such as final fields being observed to change their value) and undermined the compiler's ability to perform common optimizations.程序员
1997年,Java语言规范中,第17章Threads and Locks,暴露了JMM的一些严重漏洞。这些漏洞引发混乱的行为,好比final字段的值会发生变化,同时也会破坏编译器的普通的优化能力。编程
The Java Memory Model was an ambitious undertaking; it was the first time that a programming language specification attempted to incorporate a memory model which could provide consistent semantics for concurrency across a variety of architectures. Unfortunately, defining a memory model which is both consistent and intuitive proved far more difficult than expected. JSR 133 defines a new memory model for the Java language which fixes the flaws of the earlier memory model. In order to do this, the semantics of final and volatile needed to change.安全
JMM是编程语言规范中的第一次,试图在不一样处理器架构下,经过加入语义一致的多线程内存模型,来支持并发的,JMM,是一个野心勃勃的事业。不幸的是,定义一个一致并直观的内存模型远比指望的要困难。JSR 133规范定义了一个新的内存规范来修复早先的漏洞,同时也改变了final和volatile的语义。多线程
The full semantics are available at http://www.cs.umd.edu/users/pugh/java/memoryModel, but the formal semantics are not for the timid. It is surprising, and sobering, to discover how complicated seemingly simple concepts like synchronization really are. Fortunately, you need not understand the details of the formal semantics -- the goal of JSR 133 was to create a set of formal semantics that provides an intuitive framework for how volatile, synchronized, and final work.架构
可在以上网址看到全部的语义,正式的语义是很清楚的。但使人吃惊的是,像synchronized这样看似简单的概念事实上却很复杂。。。幸运的是,你不须要理解这些正式语义的细节,JSR 133的目的,就是为了建立一组正式的语义,用直观的框架来解释volatile、synchronized、final是怎么工做的。并发
The goals of JSR 133 include:框架
JSR 133的目的在于:编程语言
Preserving existing safety guarantees, like type-safety, and strengthening others. For example, variable values may not be created "out of thin air": each value for a variable observed by some thread must be a value that can reasonably be placed there by some thread.ide
维护现有的安全保证,如类型安全,并强化其余组件。例如,变量的值不能凭空产生,一些线程若是能看到一个变量的值,那这个变量必须是由其它线程设置的。
The semantics of correctly synchronized programs should be as simple and intuitive as possible.
使程序言简意赅,正确同步的程序的语义应该尽量的简单和直观
The semantics of incompletely or incorrectly synchronized programs should be defined so that potential security hazards are minimized.
未完整或正确同步的程序,语义上应该使潜在的安全风险降到最低
Programmers should be able to reason confidently about how multithreaded programs interact with memory.
程序员能自信的分析本身的多线程程序是如何与内存交互的
It should be possible to design correct, high performance JVM implementations across a wide range of popular hardware architectures.
能够在各类不一样的硬件架构上,设计出正确且高效的JVM实现
A new guarantee of initialization safety should be provided. If an object is properly constructed (which means that references to it do not escape during construction), then all threads which see a reference to that object will also see the values for its final fields that were set in the constructor, without the need for synchronization.
应该提供一种新的初始化安全保证,即一个对象应该被合适地构造。合适意味着在构造过程当中,它不会被别处引用,这样的话,等到其余线程获得这个对象引用的时候,就已经获得了对象中final字段的值,将final修饰的字段放在构造方法中设值,就不须要同步了。
There should be minimal impact on existing code.
应该对现有代码影响最小