VM Startup
Before any smalltalk activity takes place, some virtual machine (VM)
startup actions are performed:
'symbols.stc'
-file
'modules.stx'
and load all DLL's as listed there
'symbols.stc'
and 'modules.stx'
are searched along the following path:
- .
- ./include
- $SMALLTALK_LIBDIR/include
- $STX_LIBDIR/include
- /usr/local/lib/smalltalk/include
- /usr/lib/smalltalk/include
- /opt/smalltalk/include
- .
- .\include
- $SMALLTALK_LIBDIR\include
- $STX_LIBDIR\include
#initialize
message at the end of the source file) or manually by the user from within
the browser or a workspace.
Since traditional smalltalks always use an image, this will contain the initialized classes with all of their class variables and class instance variables (if any).
In Smalltalk/X no snapshot image is required: it can be
started both with and without a snapshot.
If started with a snapshot, the behavior is as described above: all
objects are read from the image and the classes found there have already
executed their #initialize
method in the previous live.
If started without an image, all classes' #initialize
methods
are called at early startup time, sorted by class inheritance.
These methods are responsible to create and
setup any local objects required for proper operation of the class.
Inside a subclass inheritance level, the order by which those methods are invoked
is not defined (i.e. in a classes #initialize
method,
you may depend on all superclasses being already initialized,
but you may NOT depend on any other classes being initialized.
This means:
"class initialize"
methods in a way that
all required setup is performed.
(Doing so may give you a working setup while running the current image, but lead to trouble (i.e. uninitialized objects) when you ever compile your classes to machine code and start ST/X without an image.)
#initialize
method is invoked.
#initialize
method,
#initialize
to the other class from your
classes initialize method
ObjectMemory
and handling the #restarted
or
#returnFromSnapshot
notification in an #update:
method.
#initialize
methods should be prepared being
invoked multiple times, without getting confused. This is due to the above
reason; another class may invoke #initialize
since it does
not know whether the other class was already initialized.
Typically, an initialize method checks for any of its initialized
class variables being already non-nil.
#initialize
is invoked.
#initialize
method;
the view and display handling classes are usually not initialized at that time.
ObjectMemory
(in the #initialize
method) and
open the views in the classes #update:
method.
main()
" C-function in "librun/main.c"
is called.
The followup actions depend on whether this is a clean startup
(i.e. without an image)
or a startup from a snapshot image.
Clean Startup
A clean startup is performed if
no snapshot image is present (or the "-I"
command line option was given)
or if the image file is not readable.
stxPreInit()
" C-function is called.
Init()
"
function, which installs the class(es).
"Smalltalk initializeSystem"
.
"Object initialize"
.
"ExternalStream initialize"
.
Stdin
, Stdout
and Stderr
.
#initialize
to all other classes in the system
(*).
Notice, that at this time, the externalStreams Stdin
,
Stdout
and Stderr
are already initialized and
I/O on those objects is possible
(thats the reason for ExternalStream
being initialized manually, before all other classes).
However, also notice that the graphical classes have not yet been initialized - it is not possible to open any views or boxes during this phase.
ObjectMemory changed:#initialized
".
#initialize
method, and perform these second stage initialization
actions in their #update:
method.
stxPostInit()
" C-function is called.
main.c
".
"main.c"
file was compiled with -DDIRECT_START
,
the above startup message is immediately sent to start execution.
#start
is sent to the Smalltalk
class,
and startSelector and startClass are passed
in classVariables. The startup-message will then be sent there, after the
processScheduler has been initialized and scheduling is enabled.
I.e. if "main.c"
is compiled without -DDIRECT_START
,
the processor scheduler (and therefore thread-management) is already setup and
running at the time of the startSelector-methods invocation,
and all timer handling and interrupt processing is done as usual.
With this compiler flag, these facilities are not setup, and the code
runs bar-bones as a single thread.
This may be useful for single threaded low-level code (which does not require any
threading) or if you want to install your own scheduler.
By compiling a different "main.c"
,
you can arrange for any other method to be called instead (either immediately
or after process setup).
(BTW: this is how stand alone applications are built)
The "Smalltalk start
method in turn:
"patches"
file
"abbrev.stc
" file,
and install Autoload-stub classes for all entries found there.
".rc"
file (either "smalltalk.rc"
or an application specific file)
Have a
look
at the implementation of
Smalltalk start
for more details.
Very specialized applications, which do not need process scheduling or
which want to implement their own scheduling mechanisms, may
use the DIRECT_START
feature, to get their own code
called, without any standard (ST/X) setups being performed.
However, it is then their responsibility to correctly initialize the system.
stxPostInit()
" C-function is called.
stxPostReInit()
" C-function is called.
"main.c"
and default to
"Smalltalk"
and "restart"
respectively.
"Smalltalk restart"
to see the followup actions.
"patches"
and "smalltalk.rc"
.
The "patches"
script first checks for some required classes
to be present in the system, and then looks for a subdirectory called
"stxPatches"
and (if present) loads all files found there.
The "smalltalk.rc"
script sets up various common settings,
installs autoloaded classes (see below), consults the scripts
"host.rc"
and "display.rc"
,
and finally invokes "private.rc"
.
These other scripts are responsible for host-specific setup (printer setting),
display-specific setup (screen/keyboard configuration) and the start
of an initial application (the Launcher).
All of those scripts are searched along a common searchPath, and
the default scripts as provided with the delivery can be overwritten,
by providing a corresponding file in your current directory.
Installation of Autoloaded Classes
Within "smalltalk.rc"
, you will find the expression:
if a "--autoload" command line argument is present.
This will search for all files called
Smalltalk installAutoloadedClasses
"abbrev.stc"
under all
directories found along the packagePath,
and ensures that all of your packages are automatically installed into the system.
Because, this might take a long time (10 or more seconds), depending on the
number of directories found and the speed of you disk/network drives,
this is no longer done by default (as it used to be).
Shortcut Start with an Image
On UNIX systems, an image can be started directly by entering its name,
if the image file has execute permission.
Thus, if you saved your image as (say) "myApp"
,
you can make it executable with "chmod +x myApp"
and then start it via the simple command "myApp"
.
On VMS, you can start an image with the DCL command: "@myApp"
.
Copyright © 1995 Claus Gittinger, all rights reserved
<cg at exept.de>