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.

5. An Ownership-based MOP for Expressing Concurrency Abstractions<br />

The main() procedure of the program executes in the context of the current<br />

domain, which can be assumed to be a <strong>de</strong>fault that does not enforce any<br />

specific semantics. Furthermore, note that main() starts executing without<br />

enforcement enabled.<br />

The first action of the program is the creation of a new cell object. To <strong>de</strong>termine<br />

the initial owner of the new object, the VM queries the current domain<br />

via a call to #initialDomainForNewObject. Thus, the owner of a newly<br />

created object is <strong>de</strong>termined by the domain in which the current thread is executing.<br />

Afterwards, still in the unenforced execution mo<strong>de</strong>, the cell is set to<br />

the value #foo and then adopted by the immutable domain. After adopting<br />

the cell object, the intercession handlers of the domain <strong>de</strong>fine the semantics<br />

for all operations on the cell. They will be triggered during the enforced execution<br />

mo<strong>de</strong>, which is enabled by requesting the domain to evaluate a block:<br />

current evaluateEnforced: [cell set: #bar].<br />

When the VM reaches the point of executing cell set: #bar during enforced<br />

execution, it will not apply the method directly, but it will request<br />

the execution of the method by using the OMOP. The owner of the cell<br />

is i<strong>de</strong>ntified and the intercession handler #requestExecOf:on:with: is triggered<br />

on it. The intercession handler itself executes in unenforced mo<strong>de</strong> to<br />

avoid meta recursion. In this example, #requestExecOf:on:with: implements<br />

standard semantics of method execution, since immutability does not require<br />

any changes to it. Hence, the method #set: is executed with the enforcement<br />

enabled. At some point, the implementation of #set: tries to perform<br />

a write to the object field of the cell. Here, the VM triggers the OMOP’s<br />

#write:toField:of: intercession handler of the owner of the cell, instead of<br />

performing the write directly. T<strong>here</strong>by, the immutable domain is able to signal<br />

a violation of the requested immutability by throwing the corresponding<br />

exception.<br />

To cover other reflective capabilities properly as well, an implementation<br />

of the OMOP requires that for instance reflective writes to fields obey the<br />

enforcement flag. For example, in case the setter would have used Java’s<br />

reflect.Field.set() to write the value, the implementation of Field.set()<br />

would be required to <strong>de</strong>termine the owner domain of the cell, and use the<br />

MOP to request the actual memory write.<br />

After <strong>de</strong>monstrating how a program would execute in the presence of<br />

enforcement, Lst. 5.1 sketches of how such an immutability enforcing domain<br />

can be implemented. Note that the example uses the SOM syntax (cf.<br />

Sec. 4.2.1). The given ImmutableDomain overri<strong>de</strong>s all intercession handlers that<br />

are related to state mutation. These are the intercession handlers for han-<br />

120

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

Saved successfully!

Ooh no, something went wrong!