您的位置:首页 > Web前端 > JavaScript

【翻译三】什么是JSR 133

2017-03-21 00:00 267 查看
摘要: 原文地址http://www.cs.umd.edu/~pugh/java/memoryModel/jsr-133-faq.html

JSR 133 - The Java(tm) Memory Model and Thread Specification Revision

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.

维护现有的安全保证,如类型安全,并强化其他组件。例如,变量的值不能凭空产生,一些线程如果能看到一个变量的值,那这个变量必须是由其它线程设置的。

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.

应该对现有代码影响最小
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: