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 />

1 AgentDomain = Domain (<br />

2 | agent |<br />

3 " Use # agent : to set the agent that is protected by this domain "<br />

4 agent : anAgent = ( agent := self adopt : anAgent )<br />

5<br />

6 requestExecOf : selector on: obj with : args = unenforced (<br />

7 " Semantics are only enforced on the agent itself ,<br />

8 not on other objects created in its scope ."<br />

9 obj = agent ifFalse : [^ obj perform : selector with : args ].<br />

10<br />

11 " Only allow execution of white - listed selectors "<br />

12 (# read = selector or: [# send : = selector ]) ifTrue : [<br />

13 ^ agent perform : selector with : args ].<br />

14<br />

15 Error signal : ’Exec . of method ’ + selector + ’ is <strong>de</strong>nied .’ ))<br />

Listing 5.3: Domain <strong>de</strong>finition for an Agent, enforcing the expected guarantees.<br />

5.4. Semantics of the MOP<br />

Sec. 4.2 introduced the SOM language and the interpreter’s execution mo<strong>de</strong>l.<br />

Building on that foundation, this section <strong>de</strong>scribes the semantics of the OMOP<br />

by discussing its implementation in the SOM interpreter.<br />

Derived from Fig. 5.1, Lst. 5.4 shows how the basic elements of the OMOP<br />

map onto the SOM interpreter. Every SOMObject has a field to refer to the<br />

owner domain. The domain field is initialized in the #postAllocate method<br />

after allocation is completed. The initial value, i. e., the owner domain is <strong>de</strong>termined<br />

by the domain the thread is currently executing in. Since SOM is<br />

implemented as a stack-based interpreter, the current domain is <strong>de</strong>rived from<br />

the current stack frame. The enforcement flag is realized as part of the interpreter’s<br />

stack frames as well. Thus, every frame maintains an enforced flag<br />

and the current domain.<br />

SOMInvokable, the superclass for methods and primitives, maintains the<br />

attribute that indicates to the interpreter that execution has to continue unenforced.<br />

Methods are annotated with unenforced instead of enforced, because<br />

applications and libraries need to execute in the enforced mo<strong>de</strong> most of<br />

the time to benefit from the OMOP. Only the domain’s intercession handlers<br />

and methods implementing language behavior require unenforced execution.<br />

Thus, it is a pragmatic <strong>de</strong>cision to annotate the smaller set of methods that<br />

require unenforced execution.<br />

124

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

Saved successfully!

Ooh no, something went wrong!