[comp.sources.amiga] REZ

ain@j.cc.purdue.edu (Patrick White) (06/05/88)

Submitted by:	kim@amdahl.uts.amdahl.com  (Kim DeVaughn)
Summary:	make programs resident in memory.
Poster Boy:	Patrick White	(ain@j.cc.purdue.edu)
Archive Name:	sources/amiga/volume5/rez03.d.sh.Z binaries/amiga/volume6/rez03.d.sh.Z
Tested.
 
NOTES:
   This was an arc that I separated.
   It was Submitted by Kim DeVaughn, but written by Jim Goodnow.
   The patch program is a patch to Manx 3.4b and 3.6 C compilers that allows
the C compiler to become resident (dosen't work otherwise).
   Rob ran into a version of Rez that needed to access the workbench disk
everytime it ran a program -- this version does *not* do that.
   rez will rez a name without stripping the path part of it off -- so one
can rez "c:cd" and "cd" -- rez thinks they are different, but "cd" is the
one that gets run in all cases.  So, if you use rez to load the programs,
cd into the directory first -- otherwise you load "c:cd" but run "cd".
 
 
-- Pat White   (co-moderator comp.sources/binaries.amiga)
ARPA/UUCP: j.cc.purdue.edu!ain  BITNET: PATWHITE@PURCCVM  PHONE: (317) 743-8421
U.S.  Mail:  320 Brown St. apt. 406,    West Lafayette, IN 47906
[How do you get to heaven?   Go to Pluto and hang a left.]
 
========================================
 
#	This is a shell archive.
#	Remove everything above and including the cut line.
#	Then run the rest of the file through sh.
#----cut here-----cut here-----cut here-----cut here----#
#!/bin/sh
# shar:	Shell Archiver
#	Run the following text with /bin/sh to create:
#	README
#	REZ.doc
# This archive created: Fri Jun  3 11:13:14 1988
# By:	Patrick White (PUCC Land, USA)
echo shar: extracting README '(2102 characters)'
cat << \SHAR_EOF > README
                       REZ  V0.3
                       ---  ----

**************************************************************************
***************************************************************************
*****                                                                 *****
*****  REZ is Copyright (C) 1988 by Jim Goodnow II and the binary     *****
*****  is freely redistributable except that it may not be included   *****
*****  as part of any commercial software package without my express  *****
*****  written permission.                                            *****
*****                                                                 *****
***************************************************************************
***************************************************************************


This is the BETA release version 0.3 of a new program and library called REZ.
This program allows almost any program to become resident and under the right
conditions, the code can be simultaneously shared among multiple invocations.

I am placing this program in the public domain subject to the above
restriction. Since this is a BETA version still, please don't give it
to Jerry Pournelle or others of his ilk till a released version is out
or there is a lot of confidence in this version.

With that out of the way, to find out how to use it simply rename
REZlib.lib to REZlib.library and copy it into your LIBS: directory
and say:

    REZ -?

For more detailed info, see the REZ.doc file.

Please let me know about any problems you have via email:

    bix:     jgoodnow
    usenet:  manx@well

or via phone at (415)339-2259.

             Thanks.

              Jim Goodnow II

              2/18/88

PS:

Features to be added in the final version:

- support for Overlays. I know how to do it, just have to write the code.
- smaller code (Once I'm sure it works I'll worry about efficiency)
- instead of a program and a library there will just be the program.
- maybe have the resident programs survive a warm boot ????
- support for running REZ from the workbench

SHAR_EOF
if test 2102 -ne "`wc -c README`"
then
echo shar: error transmitting README '(should have been 2102 characters)'
fi
echo shar: extracting REZ.doc '(10032 characters)'
cat << \SHAR_EOF > REZ.doc
**************************************************************************
***************************************************************************
*****                                                                 *****
*****  REZ is Copyright (C) 1988 by Jim Goodnow II and the binary     *****
*****  is freely redistributable except that it may not be included   *****
*****  as part of any commercial software package without my express  *****
*****  written permission.                                            *****
*****                                                                 *****
***************************************************************************
***************************************************************************


        REZ - a general purpose resident program command.
        ---

                   Version 0.3

                 Copyright 1988
                by Jim Goodnow II


                    BackGround
                    ----------

Normally when programs are run on the Amiga, a copy of the program is
read into memory from the appropriate file system. This is known as
loading the program. Then the CODE and DATA segments are adjusted to
reflect the actual location of the program in memory. This is known
as relocating the program. Finally, the relocated program is allowed
to execute.

This process is repeated each and every time a program is run, no matter
how many times it is run. In addition, if the same program is started
multiple times, like running several of the Boxes demos simultaneously,
a copy of the program is made for each one run.

However, there is another way of loading and running programs that is
much more efficient. It is called making programs resident. When a
program is made resident, it is loaded into memory just once. Some or
all of the relocation is performed at the initial load. Then, when
the program is needed, it is used directly from memory, and when the
program finishes, the program is left in memory for the next execution.

This explanation has been slightly oversimplified, and a more detailed
explanation can be found in the technical section at the end of this
document.


                    OverView
                    --------

The operation of REZ is very simple. A list is maintained in memory of
the names of those programs which are desired to be resident. When any
of the programs are first loaded into memory REZ automatically notices
that the program being loaded is to be resident and does the special
REZ load on it. Anytime after the first time, the resident version of
the program will be used.

What this means is that you can tell REZ that you want a whole slew of
programs to be in the resident list, but only those programs that you
actually run will actually get loaded into memory. The first time you
run each one it will load about as fast as it would without REZ, but
every time after it will be almost instantaneous.

So, the simplest way to use REZ is to just execute (maybe in your
s:startup-sequence file):

    REZ dir ls copy cd cc as ln make z

You can specify as many filenames as you want to since REZ maintains
a linked list of the names.

You can see the status of the resident name list by typing REZ with no
arguments. This will produce a display that looks like:

Name        Active  Status      Total  Pure  Share  Chk  Type
cc             0    Loaded         7   No    Yes     OK  Aztec C 3.4/3.6
as             0    Loaded        10   No    Yes     OK  Aztec C 3.4/3.6
ln             0    Loaded         2   No    Yes     OK  Aztec C 3.4/3.6
z              1    In Use         7   No    Yes     OK  Aztec C 3.4/3.6
delete         0    Loaded         1   Yes   Yes*   > 0  BCPL
copy           0    Not Loaded     0   ?     ?        ?  
cd             0    Not Loaded     0   ?     ?        ?  

The first column displays the name of the program. The next two columns are
related. The first shows the number of programs actively sharing the Code
part of this program. The second one shows the status of the program which
is either not loaded, loaded but not executing, or actually in use. The
next column labelled Total shows the number of times this program has been
executed since being made resident.

The next column indicates whether a program has any absolute references
to Data from Code. If it does not, then it is considered Pure. This is
important and is reflected in the next column called Share. Each program
must have it's own individual Data area. If the Code contains absolute
references to the Data area, it is not possible to use that Code with
multiple Data areas. There are other restrictions as well, but normally
if a program is Pure, it will also be Shareable.

Which brings us to the Share column. If a program is not Pure, then
it can't be shared except for some special cases. REZ automatically
detects these special cases and takes advantage of them and sets a
Yes in this column. More detailed information can be found in the
technical information section.

The other requirement for being Shareable is that the Code segment
can not be modified. When a program is made resident, REZ computes
a checksum for each Code segment in the program. When the list of
resident programs is displayed, REZ recomputes the checksum and
normally an OK is displayed.

However, if a segment has been modified,  then the number of the segment
will be displayed followin a '>'. In addition, if the program is Shareable,
REZ will automatically disable sharing which is indicated by an asterisk
following the "Yes" in the Share column. (See the "-c" option for automatic
checking.)

The final column makes an attempt to guess which language was used
to produce the program and is not guaranteed to be accurate, it just
seemed like useful information.

******************** DISCLAIMER ****************************

Despite rumors to the contrary, REZ does not slow down, add
bugs or in any way treat programs not produced with Aztec C
in any special manner.  ;-)

************************************************************


                    Options
                    -------

REZ has a number of options which can be referenced by using the "-?"
option which will produce the following display:

  REZ   Version 0.1   2-10-88    by Jim Goodnow II

  <no args>  display the list
  -a name    add name to list (default)
  -c         toggle auto checksum
  -f name    parse lines from file
  -k         unload all programs
  -l name    load name into memory
  -n name    add name as non-sharing
  -r name    remove name from list
  -u name    unload name from memory
  -?         display this message

REZ without any arguments shows the status display discussed in the
overview. Otherwise, the remaining arguments can be mixed together
and affect files until a different argument is detected. For example,
the line:

    REZ f1 f2 -r x1 x2

will add the files "f1" and "f2" since -a is the default, and will
remove files "x1" and "x2". We will now discuss each option in detail. 

The "-a" add option simply adds the name(s) to the in-memory list
if not already on the list. Names should not contain '/' or ':'
characters as they are not necessary and may prevent REZ from
detecting the program load.

The "-n" add with no share option is the same as the "-a" option
but it prevents the program from being marked as shareable.

The "-l" load option forces the program(s) named to be loaded but not
executed. This usually requires that the program be in the current
directory since REZ will not search the PATH. When a program is run,
it is automatically loaded, so this option is not normally needed.

The "-u" unload option forces the program(s) named to have the memory
associated with them freed up. However, the name will remain in the
resident list. If the program is currently executing, the unload will
be delayed until the last active copy is finished.

The "-r" remove option removes the named program(s) from the resident
list. If the program is loaded, it is unloaded first. If the program
is in use, unloading and removal are delayed until all active copies
have finished.

The "-k" kill option does a remove on all the programs currently in
the resident list.

The "-c" checksum option is a toggle which defaults to OFF. When
enabled, it forces REZ to perform a checksum on the Code segments
of each program when it finishes executing. This is important the
first few times you make some new programs resident if you plan
to run multiple copies of the programs simultaneously. It will
disable sharing if it discovers that the Code segment has been
corrupted.

The "-f" file option parses lines from the named file for options
and names as described above. Files may not be nested, however
multiple "-f" options may be given.


                    Limitations
                    -----------

There are only two limitations to REZ that I know of. First, programs
that use the AmigaDOS overlay facility are detected by REZ and are
not loaded. I now how to handle it, but it may wait till a later
version.

Second, programs that are started by LoadSeg(), but don't use
UnLoadSeg() to free their segments may cause trouble. This is
because REZ doesn't know that the memory has been freed and
will use the same memory for the next LoadSeg(). The most common
examples of this are programs which detach from the CLI. Since
these programs tend to be run once this is not a real problem.
DB is another example that can be more problematic.


                    Implementation
                    --------------

REZ is implemented by replacing the internal LoadSeg() and
UnLoadSeg() vectors of AmigaDOS. The replaced vectors point
to a Exec type library which contains a loader and routines
for managing the resident list. The REZ program performs most
of its functions by making calls to the REZ.LIBRARY.


                    Technical Information
                    ---------------------

This information will be supplied with the official release of
program.


SHAR_EOF
if test 10032 -ne "`wc -c REZ.doc`"
then
echo shar: error transmitting REZ.doc '(should have been 10032 characters)'
fi
#	End of shell archive
exit 0

ain@j.cc.purdue.edu (Patrick White) (06/06/88)

Submitted by:	kim@amdahl.uts.amdahl.com  (Kim DeVaughn)
Summary:	make programs resident in memory.
Poster Boy:	Patrick White	(ain@j.cc.purdue.edu)
Archive Name:	sources/amiga/volume5/rez.ccpatch.sh.Z
Tested.
 
NOTES:
   This was an arc that I separated.
   It was Submitted by Kim DeVaughn, but written by Jim Goodnow.
   The patch program is a patch to Manx 3.4b and 3.6 C compilers that allows
the C compiler to become resident (dosen't work otherwise).
   Rob ran into a version of Rez that needed to access the workbench disk
everytime it ran a program -- this version does *not* do that.
   rez will rez a name without stripping the path part of it off -- so one
can rez "c:cd" and "cd" -- rez thinks they are different, but "cd" is the
one that gets run in all cases.  So, if you use rez to load the programs,
cd into the directory first -- otherwise you load "c:cd" but run "cd".
 
 
-- Pat White   (co-moderator comp.sources/binaries.amiga)
ARPA/UUCP: j.cc.purdue.edu!ain  BITNET: PATWHITE@PURCCVM  PHONE: (317) 743-8421
U.S.  Mail:  320 Brown St. apt. 406,    West Lafayette, IN 47906
[How do you get to heaven?   Go to Pluto and hang a left.]
 
========================================
 
#	This is a shell archive.
#	Remove everything above and including the cut line.
#	Then run the rest of the file through sh.
#----cut here-----cut here-----cut here-----cut here----#
#!/bin/sh
# shar:	Shell Archiver
#	Run the following text with /bin/sh to create:
#	IF.AZTEC
#	patch.c
# This archive created: Fri Jun  3 11:10:50 1988
# By:	Patrick White (PUCC Land, USA)
echo shar: extracting IF.AZTEC '(1054 characters)'
cat << \SHAR_EOF > IF.AZTEC
Once REZ started working I discovered a number of programs that were not
shareable even though they were using the Aztec small model. In particular,
the compiler and make fall into these categories. The problem in the
compiler was that there was a section that went like:

	char *bra;

	bra = "bxx";
	strcpy(bra+1, branches[index]);

Unfortunately, this meant that the "bxx" was stored in the code segment
and modified by the program while executing. The new (3.6b?, 4.1a?) version
looks like:

	char bra[] = "bxx";

which is just fine. In the meantime, the included patch program will fix
this problem in either 3.6a or 3.4b. All it needs is for the compiler to
be in the current directory and to be called either "cc34b" or "cc36a".

The problem with make is more severe and invlolves my fexec() function which
needed to save the stack someplace while running the sub-process. It stored
it in the code segment making it non-shareable. For the time being, the
safest thing to do is to do "rez -n make" till I have a patch or a new
version of fexec().


SHAR_EOF
if test 1054 -ne "`wc -c IF.AZTEC`"
then
echo shar: error transmitting IF.AZTEC '(should have been 1054 characters)'
fi
echo shar: extracting patch.c '(334 characters)'
cat << \SHAR_EOF > patch.c
main()
{
	int i;

	if ((i = open("cc34b", 2)) >= 0) {
		lseek(i, 0x2e50L, 0);
		write(i, "bxx", 4);
		lseek(i, 0xc278L, 0);
		write (i, "\x47\xec\x87\x0e", 4);
		close(i);
	}
	if ((i = open("cc36a", 2)) >= 0) {
		lseek(i, 0x2f0cL, 0);
		write(i, "bxx", 4);
		lseek(i, 0xc68cL, 0);
		write (i, "\x47\xec\x87\x32", 4);
		close(i);
	}
}
SHAR_EOF
if test 334 -ne "`wc -c patch.c`"
then
echo shar: error transmitting patch.c '(should have been 334 characters)'
fi
#	End of shell archive
exit 0