<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: JMM and final field freeze</title>
	<atom:link href="http://tech.puredanger.com/index.php/2008/11/26/jmm-and-final-field-freeze/feed/" rel="self" type="application/rss+xml" />
	<link>http://tech.puredanger.com/2008/11/26/jmm-and-final-field-freeze/</link>
	<description>Alex Miller&#039;s technical blog</description>
	<lastBuildDate>Mon, 06 Feb 2012 19:39:50 -0800</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
	<item>
		<title>By: miluch</title>
		<link>http://tech.puredanger.com/2008/11/26/jmm-and-final-field-freeze/comment-page-1/#comment-260438</link>
		<dc:creator>miluch</dc:creator>
		<pubDate>Wed, 03 Nov 2010 22:10:12 +0000</pubDate>
		<guid isPermaLink="false">http://tech.puredanger.com/2008/11/26/jmm-and-final-field-freeze/#comment-260438</guid>
		<description>@Brian 


If we assume that keys and values in map are individually effectively immutable/immutable  we can surely say that SomeClass is immutable. With regard to your answer to Peter Veentjer comment how come that immutable object is not published safely ? What i do understand from your book is that immutable objects are always safely published...

If an object is  immutable that it can be safely published through any mechanism (according to your book). By any mechanism i understand any approach to make an instance of SomeClass visible to other thread, e.g storing an instance of SomeClass in  some public field  of  other class instance.</description>
		<content:encoded><![CDATA[<p>@Brian </p>
<p>If we assume that keys and values in map are individually effectively immutable/immutable  we can surely say that SomeClass is immutable. With regard to your answer to Peter Veentjer comment how come that immutable object is not published safely ? What i do understand from your book is that immutable objects are always safely published&#8230;</p>
<p>If an object is  immutable that it can be safely published through any mechanism (according to your book). By any mechanism i understand any approach to make an instance of SomeClass visible to other thread, e.g storing an instance of SomeClass in  some public field  of  other class instance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yoav Zibin</title>
		<link>http://tech.puredanger.com/2008/11/26/jmm-and-final-field-freeze/comment-page-1/#comment-169083</link>
		<dc:creator>Yoav Zibin</dc:creator>
		<pubDate>Sat, 04 Jul 2009 16:40:22 +0000</pubDate>
		<guid isPermaLink="false">http://tech.puredanger.com/2008/11/26/jmm-and-final-field-freeze/#comment-169083</guid>
		<description>At first I agreed with Tim Jansen, that LinkedHashMap does not use a final field, and therefore is not thread-safe without using synchronization.
But after actually reading the original JSR133 spec, I saw 
Figure 22: Transitive guarantees from final fields
and it shows this exact example.
So I agree with Alex, and it is thread safe.</description>
		<content:encoded><![CDATA[<p>At first I agreed with Tim Jansen, that LinkedHashMap does not use a final field, and therefore is not thread-safe without using synchronization.<br />
But after actually reading the original JSR133 spec, I saw<br />
Figure 22: Transitive guarantees from final fields<br />
and it shows this exact example.<br />
So I agree with Alex, and it is thread safe.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian Goetz</title>
		<link>http://tech.puredanger.com/2008/11/26/jmm-and-final-field-freeze/comment-page-1/#comment-113671</link>
		<dc:creator>Brian Goetz</dc:creator>
		<pubDate>Fri, 28 Nov 2008 15:28:24 +0000</pubDate>
		<guid isPermaLink="false">http://tech.puredanger.com/2008/11/26/jmm-and-final-field-freeze/#comment-113671</guid>
		<description>Peter, are you assuming that the SomeClass object is itself safely published?  You didn&#039;t state that assumption.  If so, though, this is right, as the state of the SomeClass *is* the state of the Map.</description>
		<content:encoded><![CDATA[<p>Peter, are you assuming that the SomeClass object is itself safely published?  You didn&#8217;t state that assumption.  If so, though, this is right, as the state of the SomeClass *is* the state of the Map.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Jansen</title>
		<link>http://tech.puredanger.com/2008/11/26/jmm-and-final-field-freeze/comment-page-1/#comment-113176</link>
		<dc:creator>Tim Jansen</dc:creator>
		<pubDate>Thu, 27 Nov 2008 08:31:51 +0000</pubDate>
		<guid isPermaLink="false">http://tech.puredanger.com/2008/11/26/jmm-and-final-field-freeze/#comment-113176</guid>
		<description>You are right, the objects reachable by a final field have the same visibilty as the final field itself. I didnt know that.</description>
		<content:encoded><![CDATA[<p>You are right, the objects reachable by a final field have the same visibilty as the final field itself. I didnt know that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Veentjer</title>
		<link>http://tech.puredanger.com/2008/11/26/jmm-and-final-field-freeze/comment-page-1/#comment-113175</link>
		<dc:creator>Peter Veentjer</dc:creator>
		<pubDate>Thu, 27 Nov 2008 08:21:56 +0000</pubDate>
		<guid isPermaLink="false">http://tech.puredanger.com/2008/11/26/jmm-and-final-field-freeze/#comment-113175</guid>
		<description>Hi Brian,

I think you have overlooked a part of my argument or I didn&#039;t express myself clearly, because a safe publication need some kind of synchronization action like a volatile or a lock for example. 

If an object has publication problems (all fields are normal and not volatile/final/used in a synchronized context) the object can be safely used in a multithreaded environment if:
-in some point in time this object is published correctly by using volatile/final/synchronized context and not before
- the object is not changed after this publication

The ordering gurantees for the volatile write/synchronized  unlock are so strong that instruction before them can&#039;t jump over them, so constructor code for example is not allowed to be executed after this publication, The same goes for the ordering gurantees of the volatile read/synchroned lock: the ordering guarantees are so strong that instructions that come after them can&#039;t jump in front of them. 

In your book have written a small chapter about it: piggybacking on synchronization. And I think it is one of the most powerfull features of the new JMM (since objects with publication problems can be used safely, for example by using a blockingqueue or concurrentmap). 

Occording to the JMM in the case of the SomeClass (without final map): 
1) there is a happens before relation between the creation of the someclass and the publication (using a volatile variable for example) : program order rule
2) there is a happens before relation between the write and read of a volatile variable (volatile variable rule)
3) there is a happens before relation between the read of the volatile variable, and the usage of the internals

And since the happens before rules are transitive, there is a happens before relation between action1 and action3.
So the SomeClass can safely be used in a multithreaded environment if it is published safely (and not changed after construction).

If I got this wrong, it would mean that there is a serious holes in my understanding of the JMM and I would like to understand what I&#039;m missing.</description>
		<content:encoded><![CDATA[<p>Hi Brian,</p>
<p>I think you have overlooked a part of my argument or I didn&#8217;t express myself clearly, because a safe publication need some kind of synchronization action like a volatile or a lock for example. </p>
<p>If an object has publication problems (all fields are normal and not volatile/final/used in a synchronized context) the object can be safely used in a multithreaded environment if:<br />
-in some point in time this object is published correctly by using volatile/final/synchronized context and not before<br />
- the object is not changed after this publication</p>
<p>The ordering gurantees for the volatile write/synchronized  unlock are so strong that instruction before them can&#8217;t jump over them, so constructor code for example is not allowed to be executed after this publication, The same goes for the ordering gurantees of the volatile read/synchroned lock: the ordering guarantees are so strong that instructions that come after them can&#8217;t jump in front of them. </p>
<p>In your book have written a small chapter about it: piggybacking on synchronization. And I think it is one of the most powerfull features of the new JMM (since objects with publication problems can be used safely, for example by using a blockingqueue or concurrentmap). </p>
<p>Occording to the JMM in the case of the SomeClass (without final map):<br />
1) there is a happens before relation between the creation of the someclass and the publication (using a volatile variable for example) : program order rule<br />
2) there is a happens before relation between the write and read of a volatile variable (volatile variable rule)<br />
3) there is a happens before relation between the read of the volatile variable, and the usage of the internals</p>
<p>And since the happens before rules are transitive, there is a happens before relation between action1 and action3.<br />
So the SomeClass can safely be used in a multithreaded environment if it is published safely (and not changed after construction).</p>
<p>If I got this wrong, it would mean that there is a serious holes in my understanding of the JMM and I would like to understand what I&#8217;m missing.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

