[Glass] About GsDeployer new doBulkMigrate

James Foster james.foster at gemtalksystems.com
Wed Apr 16 17:40:09 PDT 2014

> Ahhhh of course...the migrate stuff "just" changes the class pointer of the instances right? So if the slots for XXX instVars were there...they won't get lost. I guess it is similar to Pharo's #adoptInstance: and #primitiveChangeClassTo: 

I don’t think so. Migration creates a completely new object in a different location, and offers the new object the chance to get data from the old object. By default, instance variables that are the same are copied across (you can override this method to do something else). After the new object copies whatever it wants, the system does a two-way become on the objects to swap the identities. (Because GemStone uses an object table, swapping identities is very easy.)

So, it does not “just” change the class pointer, it creates an entirely new object with different instance variables and the old object is immediately eligible for garbage collection (because no one else has a reference to it). If the new class does not have an instance variable XXX, then the slot for XXX is not present in the new object; the data in that slot in the old object will get lost.

My understanding is that this is essentially what all Smalltalks (including Pharo) do when you change the definition of a class: there is actually a new class and a scan is made through object memory finding instances of the old class, creating new instances of the new class, copying across instance variables that are shared, and making the old instances eligible for garbage collection. The difference with GemStone is that the migration is optional and the data copying can be controlled, while in other Smalltalks the migration is automatic and there is no opportunity to salvage data in instance variables that do not carry across. Thus, GemStone can have the same semantics as Pharo (except it takes longer if the object space is larger), but it can be more flexible.

While the old object is eligible for garbage collection, it is unlikely to be lost right away and can probably be found. I have had occasion to list instances of the old class (they are likely still around), and salvage things from them.

Does that make sense (or did you already understand all of this and I just misinterpreted you comment above!)?


More information about the Glass mailing list