TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Java Optimizations and the JMM

69 pointsby thedigitalengelover 10 years ago

2 comments

artagnonover 10 years ago
Let me try to break this down.<p>This is a wrong transformation:<p><pre><code> void writer(Tuple tuple) { tuple.nonVolatileF = 5; tuple.volatileF = 1; } void reader(Tuple tuple) { int regNV = 0; int cache = tuple.nonVolatileF; int regV = tuple.volatileF; if (regV == 1) { regNV = cache; } &#x2F;&#x2F; computation that uses both of the above } </code></pre> because `cache` might get assigned before `tuple.nonVolatileF` is set. (The same is true of regV, but I guess the untransformed program had that, so you don&#x27;t bother). But you said that the JMM guarantees that all reads in C_i - C_(i-1) will see writes in C_(i-1); this means that C_3 which reads `tuple.nonVolatileF` will see the write to that variable in C_2, no? Since you&#x27;re constructing an execution, why didn&#x27;t you interleave the execution to make this trivially true? Also, can&#x27;t you wrap the writer in an atomic block during transformation?
评论 #8288825 未加载
pkinskyover 10 years ago
Thanks for posting this, this looks really interesting.<p>one note: &gt;This blog post tries to show how some re-orderings (that may be done in as part of optimizing a Java program for performance) that intuitively seem <i>illegal</i> are, in fact, <i>illegal</i>, by deriving that <i>illegality</i> from directly the JMM spec.<p>Should the first &#x27;illegal&#x27; read legal?
评论 #8288581 未加载