1 ;;;; Dump the current Lisp image into a core file. Also contains
2 ;;;; various high-level initialization stuff: loading init files and
3 ;;;; parsing environment variables.
5 ;;;; (All the real work is done by C.)
7 ;;;; This software is part of the SBCL system. See the README file for
10 ;;;; This software is derived from the CMU CL system, which was
11 ;;;; written at Carnegie Mellon University and released into the
12 ;;;; public domain. The software is in the public domain and is
13 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
14 ;;;; files for more information.
16 (in-package "SB!IMPL")
21 (defvar *before-save-initializations* nil
23 "This is a list of functions which are called before creating a saved core
24 image. These functions are executed in the child process which has no ports,
25 so they cannot do anything that tries to talk to the outside world.")
27 (defvar *after-save-initializations* nil
29 "This is a list of functions which are called when a saved core image starts
30 up. The system itself should be initialized at this point, but applications
33 ;;;; SAVE-LISP-AND-DIE itself
35 (sb!alien:def-alien-routine "save" (sb!alien:boolean)
36 (file sb!c-call:c-string)
37 (initial-function (sb!alien:unsigned #.sb!vm:word-bits)))
39 ;;; FIXME: When this is run without the PURIFY option,
40 ;;; it seems to save memory all the way up to the high-water mark,
41 ;;; not just what's currently used; and then after loading the
42 ;;; image to make a running Lisp, the memory never gets reclaimed.
43 ;;; (But with the PURIFY option it seems to work OK.)
44 (defun save-lisp-and-die (core-file-name &key
48 (environment-name "auxiliary"))
50 "Saves a CMU Common Lisp core image in the file of the specified name,
51 killing the current Lisp invocation in the process (unless it bails
52 out early because of some argument error or something).
54 The following keyword args are defined:
57 The function to run when the created core file is resumed.
58 The default function handles command line toplevel option
59 processing and runs the top level read-eval-print loop. This
60 function should not return.
63 If true (the default), do a purifying GC which moves all dynamically
64 allocated objects into static space so that they stay pure. This takes
65 somewhat longer than the normal GC which is otherwise done, but it's only
66 done once, and subsequent GC's will be done less often and will take less
67 time in the resulting core file. See PURIFY.
70 This should be a list of the main entry points in any newly loaded
71 systems. This need not be supplied, but locality and/or GC performance
72 may be better if they are. Meaningless if :PURIFY is NIL. See PURIFY.
75 This is also passed to PURIFY when :PURIFY is T. (rarely used)"
77 #!+mp (sb!mp::shutdown-multi-processing)
78 (when (fboundp 'sb!eval:flush-interpreted-function-cache)
79 (sb!eval:flush-interpreted-function-cache))
80 ;; FIXME: What is this for? Explain.
81 (when (fboundp 'cancel-finalization)
82 (cancel-finalization sb!sys:*tty*))
83 ;; FIXME: Would it be possible to unmix the PURIFY logic from this
84 ;; function, and just do a GC :FULL T here? (Then if the user wanted
85 ;; a PURIFYed image, he'd just run PURIFY immediately before calling
86 ;; SAVE-LISP-AND-DIE.)
88 (purify :root-structures root-structures
89 :environment-name environment-name)
90 #!-gencgc (gc) #!+gencgc (gc :full t))
91 ;; FIXME: Wouldn't it be more correct to go through this list backwards
92 ;; instead of forwards?
93 (dolist (f *before-save-initializations*)
95 (flet ((restart-lisp ()
97 (catch '%end-of-the-world
99 ;; FIXME: Wouldn't it be more correct to do this running
100 ;; backwards through the list, instead of forwards?
101 (dolist (f *after-save-initializations*)
103 (funcall toplevel)))))
104 ;; FIXME: Perhaps WITHOUT-GCING should be wrapped around the
105 ;; LET as well, to avoid the off chance of an interrupt triggering
106 ;; GC and making our saved RESTART-LISP address invalid?
108 (save (unix-namestring core-file-name nil)
109 (get-lisp-obj-address #'restart-lisp)))))
111 ;;;; functions used by worldload.lisp in CMU CL bootstrapping
113 ;;; If Name has been byte-compiled, and :RUNTIME is a feature, then load the
114 ;;; byte-compiled version, otherwise just do normal load.
115 #+nil ; no longer needed in SBCL.. I think.. -- WHN 19990814
116 (defun maybe-byte-load (name &optional (load-native t))
117 (let ((bname (make-pathname
119 :type #.(sb!c:backend-byte-fasl-file-type))))
120 (cond ((and (featurep :runtime)
126 ;;; Replace a cold-loaded native object file with a byte-compiled one, if it
128 #+nil ; no longer needed in SBCL.. I think.. -- WHN 19990814
129 (defun byte-load-over (name)
132 :type #.(sb!c:backend-byte-fasl-file-type))
133 :if-does-not-exist nil))