eliot.miranda at gmail.com
Tue Feb 20 20:51:16 UTC 2018
On Tue, Feb 20, 2018 at 6:56 AM, Denis Kudriashov <dionisiydk at gmail.com>
> It is just a question from the space :)
> I imagine that JS prototypes can be easily supported by anonymous classes.
> What is missing?
in 2005 is. One can do a very good job. There are three strong ideas one
can use. The first two are Vassili's, the last is Claus Gittinger's.
Vassili's ideas were to
a) analyse constructors and map the accessors in constructors to inst var
offsets. If one does inst var access by property lookup (an object is a
dictionary from field name to field) performance will be very poor. If one
can analyze a constructor and map each field to an inst var offset
performance can be much better.
b) the first field of any object is the prototype slot which points to the
prototype or nil. An inst var holding nil means "unbound". Therefore a
object's field Vassili minted special accessors, one for each offset. They
can't be written directly in Smalltalk but can be expressed using Smalltalk
bytecodes. They look like this, where instVarAt: is actually a bytecode
that fetches that inst var from the receiver
| current value |
current := self.
[current isNil ifTrue: [self error: 'field not found'].
value := current instVarAt: N. "N is the offset of the inst var this
accessor should return"
value ~~ nil ifTrue: [^value].
current := current instVarAt: 0] repeat
or in bytecode:
popIntoTemp: 0 "set current to be the receiver"
pushTemp: N inVectorAt: 0. "fetch Nth field of current"
pushConstant: nil "if Nth field is non-nil (is bound) answer it"
pop "discard nil"
pushTemp: 0 inVectorAt: 0. "fetch prototype field of current"
pushTemp: 0 "if prototype is nil, slot is not found"
popIntoTemp: 0 "set current to be the current's prototype"
We used a class per constructor, and were able to get performance about 4x
of Netscape's VM at the time.
Claus' idea is to create a circular instance, an object whose class is the
object itself. The idea follows from the fact that if one has the
changeClass/adoptInstance primitive one can create a prototype by creating
an Array whose first three fields are laid out like a Behavior's fields,
superclass/prototype, methodDictionsry, format, and whose subsequent fields
are the inst vars of the object. One then uses adoptInstance/change class
primitive to change the class of the Array to itself, so that it is an
instance of itself; it has its own methods in its methodDictionary, its
superclass field is now the prototype. The format field must specify a
pointer object with N inst vars. If using this scheme to implement
sot for dynamically added properties. And of course one would implement
prototype creation in a special primitive rather than using the standard
Using tricks like these one can get reasonably high performance. In fact,
Vassili's two ideas. The implementation is in Newspeak running above the
64-bit Spur VM.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Vm-dev