here - Stefan-Marr.de
here - Stefan-Marr.de
here - Stefan-Marr.de
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
7. Implementation Approaches<br />
The most important aspect <strong>here</strong> is that the intercession handlers that stand<br />
in for the original byteco<strong>de</strong> operations preserve the required stack semantics.<br />
Byteco<strong>de</strong>s that for instance push the value of a receiver’s field or a global<br />
literal will just result in a message send instead. The return value of the message<br />
send will then reflect the result of the read operation. Message sends and<br />
simple byteco<strong>de</strong>s that store into an object’s field are handled very similarly.<br />
The <strong>de</strong>legation of byteco<strong>de</strong>s with store and pop behavior requires an additional<br />
intercession handler. The store and pop byteco<strong>de</strong>s from the Smalltalk-<br />
80 byteco<strong>de</strong> set are problematic. These are more complex to handle because<br />
they require that the top element of the stack be removed after the operation.<br />
However, this <strong>de</strong>mands care, because all Smalltalk methods return<br />
a value, which gets pushed onto the stack after the method returns. The<br />
RoarVM+OMOP solved this problem by adding a special intercession handler<br />
#write:toField:of:return: in addition to the normal #write:toField:of:<br />
handler. It takes an additional parameter, the pre<strong>de</strong>termined return value for<br />
the handler.<br />
The co<strong>de</strong> implementing this adaptation is given in Lst. 7.3. It shows the C++<br />
co<strong>de</strong> of the RoarVM+OMOP for the store and pop byteco<strong>de</strong>. As line 6 shows,<br />
two values are popped from the stack, instead of only the value that is to<br />
be stored into the receiver. The second value, which corresponds to what the<br />
top value of the stack should be after the store and pop byteco<strong>de</strong>, is given to<br />
the intercession handler as a last parameter, and will be restored when the<br />
handler returns. The calling conventions and the current compiler in Squeak<br />
and Pharo guarantee that this approach is safe. Theoretically, it is problematic<br />
to assume that t<strong>here</strong> are always two elements on the stack that can be removed<br />
by the pop operation. However, in this situation it is guaranteed that t<strong>here</strong> is<br />
the original element to be popped and in addition, t<strong>here</strong> is at least the receiver<br />
object at the bottom of the stack, which is never subject to a store and pop<br />
byteco<strong>de</strong>. Thus, it is safe to pop the second element, which might be the<br />
receiver, and restore it when the message send returns.<br />
The send special message byteco<strong>de</strong>s and the quick methods require proper<br />
adaptation as well (cf. Sec. 4.4.1). For message byteco<strong>de</strong>s, the RoarVM+OMOP<br />
needs to force the intercession point for an actual message send when the<br />
domain customizes the request execution intercession points. While the quick<br />
methods need to force the intercession point for the reading of the receiver’s<br />
fields to be able to intercept them as any other field read with the intercession<br />
handler.<br />
192