JavaMemoryModel: Semantics musings

From: Keith Randall (randall@src.dec.com)
Date: Mon Sep 24 2001 - 14:04:44 EDT


Jan wrote:
> That said, how big is the impact in practice? My impression is that
> most null pointer checks, etc. can be resolved using purely local
> information (and indeed that doing so was crucial to performance).
> It's a pain to insert the ordering constraints, sure, but what real
> performance impact does it have? For example, I suspect, but don't
> know, that the main benefit of related field analysis is in
> eliminating comparisons and conditional traps/branches, and the extra
> flexibility in instruction scheduling isn't a huge win. Does anyone
> have data either way? Keith?

   You are right, most of the win comes from just eliminating
instructions. For array bounds checks, you can eliminate not only the
compare and branch, but possibly also the array length load and index
calculation. On modern out-of-order processors, instruction
scheduling normally doesn't buy you much.

Jan wrote:
> 2) A write may be reordered across a control flow boundary iff it can
> be shown that the particular write will occur in any execution,
> regardless of the existence or behavior of other threads in the
> system.

   A clarifying question about this semantics - consider the following
program fragment:

r1 = x
r2 = x
if (r1 == r2)
   y = 42

Is "y = 42" allowed to be reordered across the control-flow boundary?
On first reading, I thought it couldn't, because r1 and r2 may contain
different values, depending on the behavior of other threads.
However, in an implementation I'm always allowed to choose a subset of
behaviors, and let me choose the subset that does both "r1 = x" and
"r2 = x" atomically (otherwise known as redundant load elimination).
This optimization requires no knowledge of the existence of other
threads or their behavior. Am I now allowed to reorder "y = 42"
across the control flow boundary?

More generally, do I need to show that the write will occur in any
execution, over ALL possible interleavings, or only the interleavings
that might actually occur?

                                   -Keith
-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel



This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:35 EDT