<?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>Wed, 28 Jul 2010 22:41:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<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>
	<item>
		<title>By: Brian Goetz</title>
		<link>http://tech.puredanger.com/2008/11/26/jmm-and-final-field-freeze/comment-page-1/#comment-112970</link>
		<dc:creator>Brian Goetz</dc:creator>
		<pubDate>Wed, 26 Nov 2008 23:37:47 +0000</pubDate>
		<guid isPermaLink="false">http://tech.puredanger.com/2008/11/26/jmm-and-final-field-freeze/#comment-112970</guid>
		<description>Alex is correct, but it is not surprising that this is confusing enough to get different answers -- this is deliberately exploring the boundaries of the memory model.  

One unstated assumption is that the keys and values in the map are individually thread-safe or effectively immutable.  

I don&#039;t buy Peter&#039;s argument, though.  While the elements of the map may eventually &quot;become visible&quot; without final, it may be seen to violate some obvious invariants in the absence of the final or other ordering guarantees.  For example, you could iterate the keys of the LHM but have containsKey() return false for one of those keys.  That would clearly be confusing.</description>
		<content:encoded><![CDATA[<p>Alex is correct, but it is not surprising that this is confusing enough to get different answers &#8212; this is deliberately exploring the boundaries of the memory model.  </p>
<p>One unstated assumption is that the keys and values in the map are individually thread-safe or effectively immutable.  </p>
<p>I don&#8217;t buy Peter&#8217;s argument, though.  While the elements of the map may eventually &#8220;become visible&#8221; without final, it may be seen to violate some obvious invariants in the absence of the final or other ordering guarantees.  For example, you could iterate the keys of the LHM but have containsKey() return false for one of those keys.  That would clearly be confusing.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.534 seconds -->
