Keeping oops across primitives

Andreas Raab andreas.raab at gmx.de
Tue Jun 6 00:46:13 UTC 2006


Hi Folks -

After having dodged the problem multiple times, I now really need a 
solution that allows one to keep references to Squeak objects from 
external (plugin) code across primitive calls.

What I've been thinking here is that the simplest possible solution 
would consist of an interface that merely allows a plugin to add an 
array of OOPs to the interpreter roots. This would mean that such an 
array is traversed and remapped just like the other interpreter oops but 
that the plugin can now refer to those oops throughout its lifetime and 
keep strong references to any objects it needs (such as well-known 
classes etc).

Interface:
The plan would be to extend the interpreter proxy by the following function:

sqInt addToVmRoots(sqInt *newArray, sqInt newCount, sqInt *oldArray);
   newArray: Pointer to an array of oops traversed by the collector
   newCount: Size of newArray
   oldArray: The oop array we're trying to replace in this call

Following the above we have the following operations:
   - add to the roots:
     vm->addToVmRoots(newArray, newCount, NULL); /* replace nothing */

   - resize/change an existing array:
     vm->addToVmRoots(newArray, newCount, oldArray);

   - delete/remove an existing array:
     vm->addToVmRoots(NULL, 0, oldArray); /* replace with NULL */

Tradeoffs:
Pro: Really simple to implement in the VM. Basically everything we need 
is a list of pointers to traceable arrays which get hooked into 
mapAndTraceInterpreterOops.
Pro: Really simple to maintain from the plugin side. The plugin can 
decide how many entries it needs (to keep overhead small) and if it 
wants to preserve an oop it just sticks it into that array and 
everything is fine.
Pro: The plugin keeps full control over the life-time of the object. The 
image can't pull out the rugs under the plugin if the plugin thinks that 
this oop may still be needed.
Con: Adding to the roots increases the overhead of the collector but 
that's something I'm willing to live with since if that ever gets an 
issue another indirection (through a Squeak array for example) can help 
to mitigate this problem.

Question: Does anyone see a serious problem with the above proposal? I'm 
about to implement this right away so if you see an issue with it, 
please let me know.

Cheers,
   - Andreas



More information about the Vm-dev mailing list