Re: [squeak-dev] Immutability, read-only objects

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Immutability, read-only objects

Eliot Miranda-2
 
Hi Janko,

2011/3/27 Janko Mivšek <[hidden email]>
Dear all,

What is current status of immutable/read-only support in VM? Or more
broader, object instvar change catching support (for which I mostly need
immutability anyway)?

My understanding is that this exists only in the Newspeak VM sources.  It is now reasonably easy to port to the standard and Cog VMs and the necessary primitive error code support is in the VMs and the image.  I'm currently working in Newspeak at Cadence expect that this summer I will have the opportunity to port the Cog VM under Newspeak.  At that point I'll be able to add the support to Cog and the standard VM.

There are now mechanisms in the VM which would allow one to include the immutability support conditionally, in which case the source could be included in the base VMs, and not have to live in a fork, which would be my preference.  e.g.

Interpreter methods for stack bytecodes
storeAndPopReceiverVariableBytecode
"Note: This code uses storePointerUnchecked:ofObject:withValue: and does the 
store check explicitly in order to help the translator produce better code."
| rcvr top |
<expandInCase: 'currentBytecode'>
"this bytecode will be expanded so that refs to currentBytecode below will be constant"
rcvr := receiver.
top := self internalStackTop.
self cppIf: Immutability
ifTrue:
[(self internalIsImmutable: rcvr) ifTrue:
[self internalPop: 1.
self internalCannotAssign: top to: receiver withIndex: (currentBytecode bitAnd: 7)].
"cannot fetch next bytecode until after immutability check so pc is correct (set to
following bytecode, not the bytecode after that) after attemptToAssign:withIndex:"].
self fetchNextBytecode.
rcvr < youngStart ifTrue:
[self possibleRootStoreInto: rcvr value: top].
self storePointerUnchecked: (currentBytecode bitAnd: 7) ofObject: rcvr withValue: top.
self internalPop: 1

best,
Eliot
 

Best regards
Janko

--
Janko Mivšek
Aida/Web
Smalltalk Web Application Server
http://www.aidaweb.si