05.08.2014 Views

here - Stefan-Marr.de

here - Stefan-Marr.de

here - Stefan-Marr.de

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

3. Which Concepts for Concurrent and Parallel Progr. does a VM need to Support?<br />

for other purposes than optimization and strong guarantees for programmers.<br />

One use case for such weak immutability is provi<strong>de</strong>d by VisualWorks<br />

7 [Cincom Systems, Inc., 2002]. It allows marking objects as immutable and<br />

raises an exception when mutation is attempted. The exception handler is<br />

then free to mutate such an object. This behavior is used to map objects to<br />

persistent data storage and enable efficient consistency management. In this<br />

case the programmer does not consi<strong>de</strong>r the object to be immutable, instead<br />

this technique is a workaround for the missing capability of tracking mutation.<br />

However, the example also illustrates the relation between immutability<br />

and reflection. In sequential programs, such workarounds do not necessarily<br />

have a negative impact on the guarantees the programmer relies on. In a<br />

concurrent setting however, such workarounds can easily lead to uninten<strong>de</strong>d<br />

race conditions.<br />

Benefits of Immutability For a concurrency-aware VM, immutability can be<br />

used for performance optimization, either by avoiding copying of immutable<br />

objects, or replicating them to improve locality of access. In either case, immutability<br />

semantics have to be guaranteed to avoid semantic problems. Using<br />

it as sketched in the above example of VisualWorks is not an option.<br />

When immutability for a particular language is guaranteed by its compiler<br />

only, interactions across language boundaries become problematic, similarly<br />

to the use of reflection. JCoBox and Kilim use the knowledge of immutability<br />

to avoid copying objects in their implementation of safe messaging, but they<br />

rely on the absence of reflection for their semantics. Clojure’s approach to the<br />

problem is different. Its language mo<strong>de</strong>l of mostly si<strong>de</strong>-effect free concurrency<br />

on immutable data structures creates engineering benefits when direct access<br />

to the un<strong>de</strong>rlying Java ecosystem is avoi<strong>de</strong>d. However, it is not enforced. On<br />

the contrary, Clojure’s close integration with Java is an important aspect for<br />

its adoption.<br />

Conclusion Immutability is a basic property that needs to be preserved, especially<br />

in concurrent systems. Using it for other purposes such as the tracking<br />

of mutation in VisualWorks 7 should be avoi<strong>de</strong>d and the necessary facilities<br />

for such use cases should be provi<strong>de</strong>d directly. The main problem with<br />

immutability in a concurrent context is its relation to reflection. While t<strong>here</strong><br />

are use cases such as <strong>de</strong>serialization that can require the use of reflection and<br />

setting of final fields, in the context of concurrency, immutability requires<br />

strict guarantees.<br />

78

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!