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.

6.2. Case Studies<br />

ing actor. Upon creation, #initialize is invoked, which starts the actor’s<br />

thread, i. e., Smalltalk process, to execute insi<strong>de</strong> itself by using #spawnHere.<br />

The implementation realizes safe messaging by adapting the semantics of<br />

method executions. All requests from outsi<strong>de</strong> the domain, i. e., from outsi<strong>de</strong><br />

the actor, are served asynchronously (line 32). The result of such asynchronous<br />

sends is represented by a Promise (line 23). In this simple implementation,<br />

the sending actor blocks on the promise if it requires the result of<br />

the message, and continues once the promise is resolved, i. e., once the result<br />

is <strong>de</strong>livered when the event-loop processes the message (line 7).<br />

All requests insi<strong>de</strong> the actor are performed directly (line 29). Note that<br />

this listing does not inclu<strong>de</strong> <strong>de</strong>finitions for field accesses, because Smalltalk<br />

offers object-based encapsulation (cf. Sec. 4.2.1). This object-based encapsulation<br />

guarantees that object fields can be accessed synchronously from within<br />

an actor only. In languages like Java, we would also need to take care of fields,<br />

since Java’s encapsulation is class-based. Thus, we would need to customize<br />

#readField:of: and #write:toField:of as well.<br />

Wrapping of the objects sent via messages is unnecessary, because the ownership<br />

notion and the corresponding domain of an object guarantee the actor<br />

properties implicitly. The OMOP’s #adopt: method can also be used to<br />

change the owner of an object as part of the message send, if <strong>de</strong>sired. By<br />

changing the owner, it becomes unnecessary to scan the full heap to ensure<br />

that other references to the object are no longer valid, because isolation is<br />

ensured by the new owner domain, i. e., actor. For the moment, ownership<br />

transfer needs to be used manually by asking the receiver domain to #adopt:<br />

the received object, and t<strong>here</strong>fore it is in the application co<strong>de</strong> but not part of<br />

the <strong>de</strong>finition in Lst. 6.7.<br />

Note that Lst. 6.7 contains only a sketch and does not take care of state<br />

encapsulation in terms of global state, however, the ATActor domain can customize<br />

#readGlobal: and #write:toGlobal: to make sure that full isolation<br />

is guaranteed between actors. Thus, global state of classes could be replaced<br />

with domain local copies by customizing these two intercession handlers. This<br />

would be very similar to the working copies used in the STM implementation<br />

(cf. Sec. 6.2.2).<br />

While Sec. 3.3.3 discussed the issue of scheduling guarantees, Lst. 6.7 does<br />

not inclu<strong>de</strong> a corresponding solution. As summarized in Tab. 6.1, the main<br />

issue is the missing control over the execution of co<strong>de</strong>. Specifically, custom<br />

schedulers built on top of a VM typically do not have the ability to reschedule<br />

an actor when it is executing computationally expensive co<strong>de</strong> or primitives.<br />

With the OMOP, the reification of method invocations and primitives pro-<br />

155

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

Saved successfully!

Ooh no, something went wrong!