[BC][VI4] Forked Squeak version

Anthony Hannan ajh18 at cornell.edu
Thu Jun 13 20:45:00 UTC 2002


Avi Bryant <avi at beta4.com> wrote:
> On Wed, 12 Jun 2002, Anthony Hannan wrote:
> 
> > A context can change processes, or be taken out and put in another
> > later, it just can't be in more than one at the same time.
> 
> Ok.  Does this have to be managed explicitly, ie, do I have to tell a
> MethodContext that I'm moving it from one process to another?  Or is that
> taken care of by methods like #swapSender:?

The swapSender: method I sent you a while ago should work.  It swaps the
stack bottoms.  I will add the swapSender changeset to the list of
updates on the VI4 swiki page.

> What I think confused me when I last looked at it was that it was unclear
> how to have a context that wasn't currently associated with any Process.
> Do contexts have to be in exactly one process, or at most one?

At most one.
Let me describe the structure then you'll be able to add your own
methods if needed.
	Each Process2 has a CallStack.  A method activation record (frame) is a
sequence of slots that get added to the top of the callStack when a
method is called.  Refering to a frame from within the image (like with
thisContext or Process2>>topFrame) creates a MethodContext2 that refers
to its embedded frame in the callStack.  The callStack remembers which
methodContexts have been instantiated so duplicates can be avoided and
so they can be recognized as dead when their frames are popped.  Each
callStack has a fixed capacity decided at callStack creation time, like
every object.  When a callStack becomes full, new method activations
will be added to a new CallStack.  The new callStack will point to the
previous callStack, and the process will now point to the new callStack,
creating a linked structure of callStacks.  Eack callStack maintains a
back pointer to its owning process.  A callStack that is not part of a
process will have nil in its back pointer.
	You can manipulate a suspended process and its callStack in the image,
just be sure to maintain the following structure: 

	A process points to a callStack which points to its previous callStack
and so on.  Each callStack points back to its process.  Each callStack
holds the current ip and fp of its top frame.  Each frame, except the
bottom frame, holds the current ip and relative fp of its previous frame
(sender).  The bottom frame of each callStack holds 0 indicating its
sender is the topFrame of the previous callStack.  If the previous
callStack is nil then this bottom frame is the bottom frame of the
entire process.

	You can remove callStacks from the callStack link structure.  You can
insert new callStacks into this callStack link structure.  You can
divide a callStack into two (insert a callStack and move frames from one
to the other).  Dividing is useful when targeting specific frames to be
removed.  See methods in Process2 'private' that do these types of
manipulations, in particular: 
	insertStack: newStack under: existingContext
	removeFrame: context
	removeFramesBetween: upperContext and: lowerContext
	pvtSplitStackUnder: context

	These are all low level method, higher level methods allow you to
easily add new frames or pop frames.  See methods in Process2
'manipulating', in particular:
	activateMethod: compiledMethod
	return: result
	return: result from: context

I hope this helps,
Anthony



More information about the Squeak-dev mailing list