image.texi 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. @node Suspending and resuming heap images
  2. @section Suspending and resuming heap images
  3. @cindex dumping heap images
  4. @cindex heap image dumping
  5. @cindex image dumping
  6. @cindex writing heap images
  7. @cindex heap image writing
  8. @cindex image writing
  9. Scheme48's virtual machine operates by loading a heap image into memory
  10. and calling the initialization procedure specified in the image dump.
  11. Heap images can be produced in several different ways: programmatically
  12. with @code{write-image}, using the @embedref{Image-building commands,
  13. command processor's facilities}, or with the static linker. This
  14. section describes only @code{write-image} and the related system
  15. resumption & initialization.
  16. Heap image dumps begin with a sequence of characters terminated by an
  17. ASCII form-feed/page character (codepoint 12). This content may be
  18. anything; for example, it might be a Unix @code{#!} line that invokes
  19. @code{scheme48vm} on the file, or it might be a silly message to
  20. whomever reads the top of the heap image dump file. (The command
  21. processor's @code{,dump} & @code{,build} commands
  22. (@pxref{Image-building commands}) write a blank line at the top; the
  23. static linker
  24. @c @embedref{Static linker, static linker}
  25. puts a message stating that the
  26. image was built by the static linker.)
  27. @stindex write-images
  28. @code{Write-image} is exported by the @code{write-images} structure.
  29. @deffn procedure write-image filename startup-proc message @returns{} unspecified
  30. Writes a heap image whose startup procedure is @var{startup-proc} and
  31. that consists of every object accessible in some way from
  32. @var{startup-proc}. @var{Message} is put at the start of the heap
  33. image file before the ASCII form-feed/page character. When the image
  34. is resumed, @var{startup-proc} is passed a vector of program arguments,
  35. an input channel for standard input, an output channel for standard
  36. output, an output channel for standard error, and a vector of records
  37. to be resumed. This is typically simplified by @code{usual-resumer}
  38. (see below). On Unix, @var{startup-proc} must return an integer exit
  39. code; otherwise the program will crash and burn with a very low-level
  40. VM error message when @var{startup-proc} returns.
  41. @end deffn
  42. @subsection System initialization
  43. @cindex usual resumer
  44. @cindex heap image resumption
  45. @cindex resuming heap images
  46. @stindex usual-resumer
  47. When suspended heap images are resumed by the VM, the startup procedure
  48. specified in the heap image is applied to five arguments: a vector of
  49. command-line arguments (passed after the @code{-a} argument to the VM),
  50. an input channel for standard input, an output channel for standard
  51. output, an output channel for standard error, and a vector of records
  52. to be resumed. The startup procedure is responsible for performing any
  53. initialization necessary --- including initializing the Scheme48
  54. run-time system --- as well as simply running the program. Typically,
  55. this procedure is not written manually: resumers are ordinarily created
  56. using the @dfn{usual resumer} abstraction, exported from the structure
  57. @code{usual-resumer}.
  58. @deffn procedure usual-resumer startup-proc @returns{} resumer-proc
  59. This returns a procedure that is suitable as a heap image resumer
  60. procedure. When the heap image is resumed, it initializes the run-time
  61. system --- it resumes all the records, initializes the thread system,
  62. the dynamic state, the interrupt system, I/O system, @etc{} --- and
  63. applies @var{startup-proc} to a list (not a vector) of the command-line
  64. arguments.
  65. @end deffn
  66. Some records may contain machine-, OS-, or other session-specific data.
  67. When suspended in heap images and later resumed, this data may be
  68. invalidated, and it may be necessary to reinitialize this data upon
  69. resumption of suspended heap images. For this reason Scheme48 provides
  70. @dfn{record resumers}; see @code{define-record-resumer} from the
  71. @embedref{Records, @code{record-types} structure}.
  72. @subsection Manual system initialization
  73. If a programmer chooses not to use @code{usual-resumer} --- which is
  74. @emph{not} a very common thing to do ---, he is responsible for manual
  75. initialization of the run-time system, including the I/O system,
  76. resumption of records, the thread system and the root thread scheduler,
  77. the interrupt system, and the condition system.
  78. @strong{Warning:} Manual initialization of the run-time system is a
  79. @emph{very} delicate operation. Although one can potentially vastly
  80. decrease the size of dumped heap images by doing it manually,
  81. @footnote{For example, the author of this manual, merely out of
  82. curiosity, compared the sizes of two images: one that used the usual
  83. resumer and printed each of its command-line arguments, and one that
  84. performed @emph{no} run-time system initialization --- which eliminated
  85. the run-time system in the image, because it was untraceable from the
  86. resumer --- and wrote directly to the standard output channel. The
  87. difference was a factor of about twenty. However, also note that the
  88. difference is constant; the run-time system happened to account for
  89. nineteen twentieths of the larger image.} it is very error-prone and
  90. difficult to do without exercising great care, which is why the usual
  91. resumer facility exists. Unless you @emph{@strong{really}} know what
  92. you are doing, you should just use the usual resumer.
  93. At the present, documentation of manual system initialization is
  94. absent. However, if the reader knows enough about what he is doing
  95. that he desires to manually initialize the run-time system, he is
  96. probably sufficiently familiar with it already to be able to find the
  97. necessary information directly from Scheme48's source code and module
  98. descriptions.