Hi Aaron,
On Sun, May 4, 2014 at 8:40 AM, Aaron Rosenzweig <[hidden email]> wrote:
First, the concept isn't special to VisualWorks. The VisualAge VM had it before VW (AFAIA VA had it first) and I implemented it for VisualWorks in the early 2000's to allow the GemStone implementation on VisualWorks to be as simple as it is on VisualAge.
Second, I implemented immutability for the Newspeak Interpreter VM, a modified Squeak interpreter VM, in 2007 and you'll find that code in the VMMaker.oscog package in the NewspeakInterpreter class.
So no, it's not hard to add. It's simply hard to find the time to port the code from the NewspeakInterpreter VM to the Cog VM. Volunteers are encouraged to have a go and I'm very happy to give advice. Right now my priority is getting the 32-bit Spur port deployed (and having implemented a functional compaction algorithm this last week I can now do so).
It's pretty cheap, but not quite free. It's quite simple. When immutability is implemented, the system uses a bit in the object header as a per-object immutability flag, and checks the bit before every assignment. An attempt to assign an inst var in an immutable object causes a send-back of attemptToAssign: theValue withIndex: instVarIndex to the immutable object being assigned. An attempt to assign an immutable object in a primitive causes that primitive to fail with a PrimErrNoModification primitive failure code. IIRC the VW VM slowed by about 6% when immutability was implemented. I hope that on modern machines the slowdown would be even less, but the extra read of the object header during inst var assignment is a significant cost. The cost for primitives is much less because bounds checking implies a read of the object header to determine an object's size anyway.
HTH and pardon me for asking that in future you cc vm-dev for VM-related discussions. Thanks.
-- best,Eliot
|
Hi Alexandre,
On Sun, May 4, 2014 at 1:09 PM, Alexandre Bergel <[hidden email]> wrote:
It isn't.
The object representation needs to make room for the bit in the header, but the GC ignores it completely. However, the memory manager (of which the GC is a component) implements the core of e.g. the become primitive and that primitive can reasonably be expected to fail an attempt to become an immutable object.
best, Eliot
|
Free forum by Nabble | Edit this page |