This post originated from an RSS feed registered with Agile Buzz
by James Robertson.
Original Post: Bootstrapping Smalltalk
Feed Title: David Buck - Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/buck-rss.xml
Feed Description: Smalltalk can do that
1) Is all the source for Moose in the parcel file on their download page (i.e. browseable from within visual works)?
2) Is all the source for Visual Works browseable from within Visual Works?
If 1 is true but 2 is false, it seems one doesn't have quite the extent of freedom one associates with source code. Also, if 2 is true, how does Visual Works bootstrap to the point where it can interpret smalltalk? I assume there is some small bootstrap portion that is distributed in binary form?
This leads to a third question: What is the first Smalltalk code to execute when it launches? For the purposes of this article, we'll talk about VisualWorks.
First, there are two pieces that make up a Smalltalk system - the virtual machine and the virtual image. You can think of the virtual machine as the interpreter, although these days, Smalltalk is dynamically compiled (JIT compiled) like Java and C#. The virtual image contains an exact snapshot of the objects in the system when the image was saved.
When Smalltalk starts running, the virtual machine begins by reading the image into memory and doing a bit of housecleaning to prepare to execute it. Remember that this image contains objects for:
All classes in the image
All methods in the image
All the bytecodes for the methods
All global variables
All Smalltalk processes
The context stacks of all Smalltalk processes
At this instant, the memory copy of the image looks just like it did when the snapshot was taken. It even knows which process was the active one and has a copy of the stack. There's only one thing left to do - pick up where you left off.
Where did you leave off? The image remembers - it had just taken a snapshot. The image starts by returning from the snapshot primitive. It's already nested several levels deep in a Smalltalk return stack, but that's ok. It just picks up exactly where it left off.
The snapshot primitive itself returns two different values. One indicates that it had just snapshotted an image and was just continuing. The other value indicates that the virtual machine is starting up a new image. In that latter case, the system performs various initializations that need to be done on startup. This process is called a "returnFromSnapshot".
I don't know if it exactly answers the question, but it's an interesting topic.