Accessing variables through sending messages
Marcus Denker
denker at iam.unibe.ch
Tue Jun 21 16:45:36 UTC 2005
Am 21.06.2005 um 18:29 schrieb Bert Freudenberg:
>
> Am 21.06.2005 um 16:29 schrieb Alexandre Bergel:
>
>
>> Hello,
>>
>> I know there are some Self experts in this mailing list, that's
>> why I am asking a question related to it there. What would be the
>> best strategy to have variables not accessed by using their index,
>> but rather by sending messages correspondong to their accessors/
>> mutators.
>>
Do you really need the message send or just the "name" instead of
offset? These are two different things... the offset is needed for e.g.
Traits with state, but sends only for stuff like persistance.
>> I feel that an efficient implementation would require new
>> bytecode, therefore hardcoding this in the VM.
If you want message sends for instance access, you don't need new
bytecodes. you just need to change the compiler
to emit a send for instance var access. (For the new compiler, this
is quite trivial to do), or use Geppetto to reify
instance var access.
Of course, this is slow. So if you just want to late-bind the name to
the offset, then it would be faster to have bytecode for
accessing instVars by name. This would be slower than doing offsets,
but nevertheless much faster then sends, as no
lookup needs to be done, no method needs to be executed.
The third idea is that the offsets rarely change even when developing
and they are (mostly) constant at runtime. So with some
form of runtime-translator, you could have the smalltalk compiler
generate sends, and then have the "jit" to replace the sends
on first call with offsets. All offset changing opereations (those
that now force recompilation of the class hierarchy) would then
just invalidate the cache. This approach would cost mostly memory,
runtime would be as good as offsets, after the sytem "warms up".
Marcus
More information about the Squeak-dev
mailing list
|