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.

4.4. RoarVM<br />

that is performance critical and benefits from avoiding the interpretation overhead.<br />

The RoarVM and CogVM are <strong>de</strong>rived from the same original co<strong>de</strong> base and<br />

share the implementation of primitives. While the implementations diverged<br />

over time, the RoarVM supports the same primitives and collections of primitives<br />

in the form of plugins to be compatible with the CogVM. Thus, on the<br />

language level the provi<strong>de</strong>d mechanism are i<strong>de</strong>ntical.<br />

Smalltalk has access to primitives via an encoding in the method hea<strong>de</strong>r of<br />

a method object. If the primitive part of the method hea<strong>de</strong>r is set to a value<br />

different from zero, the VM is asked to execute the primitive referenced by<br />

this method instead of executing the byteco<strong>de</strong>s enco<strong>de</strong>d in the method. For<br />

the execution of a primitive the current context object is used, instead of creating<br />

a new one, as is done for standard message sends. This gives the primitive<br />

access to the current operand stack, the VM, and perhaps the un<strong>de</strong>rlying system.<br />

A number of primitive i<strong>de</strong>ntifiers is however reserved for so-called quick<br />

methods. Quick methods do not enco<strong>de</strong> byteco<strong>de</strong>s, but instead use the primitive<br />

i<strong>de</strong>ntifier to enco<strong>de</strong> presumably common short methods. This inclu<strong>de</strong>s<br />

return of self, true, false, and nil. Furthermore, quick methods enco<strong>de</strong><br />

accessors, i. e., methods that only return the object stored in a field.<br />

Tab. 4.1 shows the encoding of the method hea<strong>de</strong>r in the RoarVM. It uses<br />

the same encoding as the CogVM for compatibility. To avoid issues with the<br />

garbage collector, and because the method hea<strong>de</strong>r is a normal field in the<br />

method object, it is enco<strong>de</strong>d using a SmallInt, which is indicated by the<br />

least significant bit set to one. The hea<strong>de</strong>r enco<strong>de</strong>s the number of arguments<br />

(#args) the method expects, the number of slots the context object should provi<strong>de</strong><br />

for temporary variables (#temporaries), whether a small or large context<br />

object should be allocated for the operand stack (FS: frame size), and the number<br />

of literals enco<strong>de</strong>d in the method. For historical reasons, the primitive is<br />

enco<strong>de</strong>d with 10 non-consecutive bits. Bit 29 was presumably ad<strong>de</strong>d when<br />

the need arose. The 30th bit (F) is a flag bit that is reserved for custom use at<br />

the language si<strong>de</strong>, and bit 31 remains unused.<br />

Table 4.1.: RoarVM Method Hea<strong>de</strong>r<br />

F P. #args #temporaries FS #literals Primitive 1<br />

31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0<br />

103

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

Saved successfully!

Ooh no, something went wrong!