[concurrency-interest] Programming language-independent memory models
boehm at acm.org
Sat Aug 5 01:04:23 EDT 2017
The problem is that there are actually semi-rational reasons for the
differences between the C++ and Java memory models. And we tried to make
the two as similar as possible were such reasons didn't exist.
Java wanted to avoid undefined behavior (for the core language) at pretty
much all costs. The costs unfortunately include:
- Fences in object constructors
- New (for C++) optimization constraints, e.g. the inability to
rematerialize spilled registers from globals
- Serious definitional problems with out-of-thin-air results for basically
every program (as opposed to just memory_order_relaxed accesses in C++)
These were probably reasonable tradeoffs for Java, especially at the time.
But I don't think they would fly for C or C++.
I'm not sure that using memory_order_relaxed in a Java interpreter is that
much of an issue, given that JIT-compiled code would still benefit from the
weaker Java semantics. For the few cases for which this is seriously
suboptimal, e.g. long accesses on mips32, you could resort to assembly code.
On Fri, Aug 4, 2017 at 10:18 AM, Andrew Haley <aph at redhat.com> wrote:
> Do such things exist? Java and C++ have their own, which are mostly
> compatible but not quite. Any language implemented in C++ will
> necessarily implement the C++ memory model, which (perhaps)
> unfortunately implies that if it executes any data races the whole
> program becomes undefined. A programming language interpreter written
> in C++ could get around that by using atomic types for everything, but
> that's rather unpleasant. The Java memory model is somewhat more sane
> than that, and might provide a better base.
> Defining a memory model is a substantial task. It would be nice, from
> a blue sky point of view, to be able to pull a memory model off the
> shelf and say "Language X uses the Y memory model" and leave it at
> that, pausing only to describe Programming Languages X's mapping from
> its own operators to those of the Y memory model. I'll grant that
> this is difficult, because programming language semantics play a large
> part in the way a language uses memory. However, that's surely easier
> than starting with nothing.
> I'm wondering if, in the wonderful world of polyglot systems and
> applications, there has been any work in this area.
> Andrew Haley
> Java Platform Lead Engineer
> Red Hat UK Ltd. <https://www.redhat.com>
> EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Concurrency-interest