Garbage Collection catch-22 with blocks - Further complications

Alan Lovejoy sourcery at pacbell.net
Sun Jul 4 19:27:58 UTC 1999


Peter Smet wrote:

>  Alan - and anyone else with an interest in blocks.
>  About the weakMethodContext:
>
>  >>Briefly, the solution involves defining a new subclass of MethodContext,
>  >>called WeakMethodContext, that uses a WeakArray to hold on to the
>  >>receiver.  A MethodContext will answer a new WeakMethodContext
>  >>with the same state in response to the message #asWeakContext.
>  >>Sending the message #beWeak to a BlockContext causes it to
>  >>replace its "home" context with "homeContext asWeakContext."
>  >>
>  >>I tested this briefly, and it seems to work.
>
>  I did some further testing, and found some interesting consequences. One is
>  that messages can get sent to the WeakArray rather than the receiver
>  contained in the WeakArray. I went through your new methods with a fine
>  tooth comb, and it seems to me you have all bases covered. Any calls to
>  receiver should be caught by your new method that returns the first element
>  in the WeakArray. I end up with a bizarre situation in the debugger caused
>  by a WeakArray not understanding a message. When I look at the 'self' that
>  the message is directed to it is the object contained in the WeakArray. This
>  can't be right, or the error would not have occurred in the first place. I
>  can only guess that there must be some optimization where the home context
>  receiver VARIABLE is accessed directly for doing the message send.
>  Unfortunately, I cannot see where this is happening. Does anyone know if
>  this guess is correct? Does the method context always use the receiver
>  method, or is direct variable access invoked by the compiler somewhere. How
>  would I override this?
>
>  I can send code that demonstrates the problem if needed.
>
>  Thanks for any help
>
>  Peter

I feared at the time that the "receiver" variable was probably 
accessed directly
by the interpreter.  The most likely cases would be whenever the block accesses
an instance variable of the receiver, and also whenever there is a message send
to "self" in the block.  A quick fix would be to not use blocks that 
send messages
to "self,"' nor blocks that access instances variables from the outer 
context.  You
could pass "self" and any accessed instance variables in as block arguments,
or else assign the values thereof to temporary variables, and  only access the
temporary variables in the block. Otherwise, some VM hacking will be required.

--Alan


Content-Type: text/x-vcard; charset=us-ascii;
  name="sourcery.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Alan Lovejoy
Content-Disposition: attachment;
  filename="sourcery.vcf"

Attachment converted: Anon:sourcery.vcf 7 (TEXT/R*ch) (0000AD7B)





More information about the Squeak-dev mailing list