1 ;;;; stuff that knows about dumping FASL files
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
14 ;;; FIXME: Double colons are bad, and there are lots of them in this
15 ;;; file, because both dump logic in SB!C and load logic in SB!IMPL
16 ;;; need to know about fops. Perhaps all the load/dump logic should be
17 ;;; moved into a single package, perhaps called SB-LD.
19 ;;;; fasl dumper state
21 ;;; The FASL-FILE structure represents everything we need to know
22 ;;; about dumping to a fasl file. We need to objectify the state,
23 ;;; since the fasdumper must be reentrant.
25 #-no-ansi-print-object
26 (:print-object (lambda (x s)
27 (print-unreadable-object (x s :type t)
28 (prin1 (namestring (fasl-file-stream x)) s))))
30 ;; the stream we dump to
31 (stream (required-argument) :type stream)
32 ;; hashtables we use to keep track of dumped constants so that we
33 ;; can get them from the table rather than dumping them again. The
34 ;; EQUAL-TABLE is used for lists and strings, and the EQ-TABLE is
35 ;; used for everything else. We use a separate EQ table to avoid
36 ;; performance patholigies with objects for which EQUAL degnerates
37 ;; to EQL. Everything entered in the EQUAL table is also entered in
39 (equal-table (make-hash-table :test 'equal) :type hash-table)
40 (eq-table (make-hash-table :test 'eq) :type hash-table)
41 ;; the table's current free pointer: the next offset to be used
42 (table-free 0 :type index)
43 ;; an alist (PACKAGE . OFFSET) of the table offsets for each package
44 ;; we have currently located.
45 (packages () :type list)
46 ;; a table mapping from the Entry-Info structures for dumped XEPs to
47 ;; the table offsets of the corresponding code pointers
48 (entry-table (make-hash-table :test 'eq) :type hash-table)
49 ;; a table holding back-patching info for forward references to XEPs.
50 ;; The key is the Entry-Info structure for the XEP, and the value is
51 ;; a list of conses (<code-handle> . <offset>), where <code-handle>
52 ;; is the offset in the table of the code object needing to be
53 ;; patched, and <offset> is the offset that must be patched.
54 (patch-table (make-hash-table :test 'eq) :type hash-table)
55 ;; a list of the table handles for all of the DEBUG-INFO structures
56 ;; dumped in this file. These structures must be back-patched with
57 ;; source location information when the compilation is complete.
58 (debug-info () :type list)
59 ;; This is used to keep track of objects that we are in the process
60 ;; of dumping so that circularities can be preserved. The key is the
61 ;; object that we have previously seen, and the value is the object
62 ;; that we reference in the table to find this previously seen
63 ;; object. (The value is never NIL.)
65 ;; Except with list objects, the key and the value are always the
66 ;; same. In a list, the key will be some tail of the value.
67 (circularity-table (make-hash-table :test 'eq) :type hash-table)
68 ;; a hash table of structures that are allowed to be dumped. If we
69 ;; try to dump a structure that isn't in this hash table, we lose.
70 (valid-structures (make-hash-table :test 'eq) :type hash-table))
72 ;;; This structure holds information about a circularity.
73 (defstruct (circularity (:copier nil))
74 ;; the kind of modification to make to create circularity
75 (type (required-argument) :type (member :rplaca :rplacd :svset :struct-set))
76 ;; the object containing circularity
78 ;; index in object for circularity
79 (index (required-argument) :type index)
80 ;; the object to be stored at INDEX in OBJECT. This is that the key
81 ;; that we were using when we discovered the circularity.
83 ;; the value that was associated with VALUE in the
84 ;; CIRCULARITY-TABLE. This is the object that we look up in the
85 ;; EQ-TABLE to locate VALUE.
88 ;;; a list of the CIRCULARITY structures for all of the circularities
89 ;;; detected in the current top-level call to DUMP-OBJECT. Setting
90 ;;; this lobotomizes circularity detection as well, since circular
91 ;;; dumping uses the table.
92 (defvar *circularities-detected*)
94 ;;; used to inhibit table access when dumping forms to be read by the
96 (defvar *cold-load-dump* nil)
98 ;;; used to turn off the structure validation during dumping of source
100 (defvar *dump-only-valid-structures* t)
103 ;;; Write the byte B to the specified fasl-file stream.
104 (defun dump-byte (b fasl-file)
105 (declare (type (unsigned-byte 8) b) (type fasl-file fasl-file))
106 (write-byte b (fasl-file-stream fasl-file)))
108 ;;; Dump a 4 byte unsigned integer.
109 (defun dump-unsigned-32 (num fasl-file)
110 (declare (type (unsigned-byte 32) num) (type fasl-file fasl-file))
111 (let ((stream (fasl-file-stream fasl-file)))
113 (write-byte (ldb (byte 8 (* 8 i)) num) stream))))
115 ;;; Dump NUM to the fasl stream, represented by N bytes. This works
116 ;;; for either signed or unsigned integers. There's no range checking
117 ;;; -- if you don't specify enough bytes for the number to fit, this
118 ;;; function cheerfully outputs the low bytes.
119 (defun dump-integer-as-n-bytes (num bytes file)
120 (declare (integer num) (type index bytes) (type fasl-file file))
121 (do ((n num (ash n -8))
124 (declare (type index i))
125 (dump-byte (logand n #xff) file))
128 ;;; Setting this variable to an (UNSIGNED-BYTE 32) value causes
129 ;;; DUMP-FOP to use it as a counter and emit a FOP-NOP4 with the
130 ;;; counter value before every ordinary fop. This can make it easier
131 ;;; to follow the progress of LOAD-AS-FASL when
132 ;;; debugging/testing/experimenting.
133 #!+sb-show (defvar *fop-nop4-count* nil)
134 #!+sb-show (declaim (type (or (unsigned-byte 32) null) *fop-nop4-count*))
136 ;;; Dump the FOP code for the named FOP to the specified fasl-file.
138 ;;; FIXME: This should be a function, with a compiler macro expansion
139 ;;; for the common constant-FS case. (Among other things, that'll stop
140 ;;; it from EVALing ,FILE multiple times.)
142 ;;; FIXME: Compiler macros, frozen classes, inlining, and similar
143 ;;; optimizations should be conditional on #!+SB-FROZEN.
144 (defmacro dump-fop (fs file)
145 (let* ((fs (eval fs))
146 (val (get fs 'sb!impl::fop-code)))
150 (when *fop-nop4-count*
151 (dump-byte ,(get 'sb!impl::fop-nop4 'sb!impl::fop-code) ,file)
152 (dump-unsigned-32 (mod (incf *fop-nop4-count*) (expt 2 32)) ,file))
153 (dump-byte ',val ,file))
154 (error "compiler bug: ~S is not a legal fasload operator." fs))))
156 ;;; Dump a FOP-Code along with an integer argument, choosing the FOP
157 ;;; based on whether the argument will fit in a single byte.
159 ;;; FIXME: This, like DUMP-FOP, should be a function with a
160 ;;; compiler-macro expansion.
161 (defmacro dump-fop* (n byte-fop word-fop file)
165 (dump-fop ',byte-fop ,n-file)
166 (dump-byte ,n-n ,n-file))
168 (dump-fop ',word-fop ,n-file)
169 (dump-unsigned-32 ,n-n ,n-file)))))
171 ;;; Push the object at table offset Handle on the fasl stack.
172 (defun dump-push (handle file)
173 (declare (type index handle) (type fasl-file file))
174 (dump-fop* handle sb!impl::fop-byte-push sb!impl::fop-push file)
177 ;;; Pop the object currently on the fasl stack top into the table, and
178 ;;; return the table index, incrementing the free pointer.
179 (defun dump-pop (file)
181 (fasl-file-table-free file)
182 (dump-fop 'sb!impl::fop-pop file)
183 (incf (fasl-file-table-free file))))
185 ;;; If X is in File's EQUAL-TABLE, then push the object and return T,
186 ;;; otherwise NIL. If *COLD-LOAD-DUMP* is true, then do nothing and
188 (defun equal-check-table (x file)
189 (declare (type fasl-file file))
190 (unless *cold-load-dump*
191 (let ((handle (gethash x (fasl-file-equal-table file))))
193 (dump-push handle file)
198 ;;; These functions are called after dumping an object to save the
199 ;;; object in the table. The object (also passed in as X) must already
200 ;;; be on the top of the FOP stack. If *COLD-LOAD-DUMP* is true, then
201 ;;; we don't do anything.
202 (defun eq-save-object (x file)
203 (declare (type fasl-file file))
204 (unless *cold-load-dump*
205 (let ((handle (dump-pop file)))
206 (setf (gethash x (fasl-file-eq-table file)) handle)
207 (dump-push handle file)))
209 (defun equal-save-object (x file)
210 (declare (type fasl-file file))
211 (unless *cold-load-dump*
212 (let ((handle (dump-pop file)))
213 (setf (gethash x (fasl-file-equal-table file)) handle)
214 (setf (gethash x (fasl-file-eq-table file)) handle)
215 (dump-push handle file)))
218 ;;; Record X in File's CIRCULARITY-TABLE unless *COLD-LOAD-DUMP* is
219 ;;; true. This is called on objects that we are about to dump might
220 ;;; have a circular path through them.
222 ;;; The object must not currently be in this table, since the dumper
223 ;;; should never be recursively called on a circular reference.
224 ;;; Instead, the dumping function must detect the circularity and
225 ;;; arrange for the dumped object to be patched.
226 (defun note-potential-circularity (x file)
227 (unless *cold-load-dump*
228 (let ((circ (fasl-file-circularity-table file)))
229 (aver (not (gethash x circ)))
230 (setf (gethash x circ) x)))
233 ;;; Dump FORM to a fasl file so that it evaluated at load time in normal
234 ;;; load and at cold-load time in cold load. This is used to dump package
236 (defun fasl-dump-cold-load-form (form file)
237 (declare (type fasl-file file))
238 (dump-fop 'sb!impl::fop-normal-load file)
239 (let ((*cold-load-dump* t))
240 (dump-object form file))
241 (dump-fop 'sb!impl::fop-eval-for-effect file)
242 (dump-fop 'sb!impl::fop-maybe-cold-load file)
245 ;;;; opening and closing fasl files
247 ;;; Open a fasl file, write its header, and return a FASL-FILE object
248 ;;; for dumping to it. Some human-readable information about the
249 ;;; source code is given by the string WHERE. If BYTE-P is true, this
250 ;;; file will contain no native code, and is thus largely
251 ;;; implementation independent.
252 (defun open-fasl-file (name where &optional byte-p)
253 (declare (type pathname name))
254 (let* ((stream (open name
256 :if-exists :new-version
257 :element-type 'sb!assem:assembly-unit))
258 (res (make-fasl-file :stream stream)))
260 ;; Begin the header with the constant machine-readable (and
261 ;; semi-human-readable) string which is used to identify fasl files.
262 (write-string sb!c:*fasl-header-string-start-string* stream)
264 ;; The constant string which begins the header is followed by
265 ;; arbitrary human-readable text, terminated by a special
267 (with-standard-io-syntax
273 using ~A version ~A~%"
275 (format-universal-time nil (get-universal-time))
277 (sb!xc:lisp-implementation-type)
278 (sb!xc:lisp-implementation-version)))
279 (dump-byte sb!c:*fasl-header-string-stop-char-code* res)
281 ;; Finish the header by outputting fasl file implementation and
282 ;; version in machine-readable form.
283 (multiple-value-bind (implementation version)
285 (values *backend-byte-order*
286 byte-fasl-file-version)
287 (values *backend-fasl-file-implementation*
288 *backend-fasl-file-version*))
289 (dump-unsigned-32 (length (symbol-name implementation)) res)
290 (dotimes (i (length (symbol-name implementation)))
291 (dump-byte (char-code (aref (symbol-name implementation) i)) res))
292 (dump-unsigned-32 version res))
296 ;;; Close the specified FASL-FILE, aborting the write if ABORT-P.
297 ;;; We do various sanity checks, then end the group.
298 (defun close-fasl-file (file abort-p)
299 (declare (type fasl-file file))
300 (aver (zerop (hash-table-count (fasl-file-patch-table file))))
301 (dump-fop 'sb!impl::fop-verify-empty-stack file)
302 (dump-fop 'sb!impl::fop-verify-table-size file)
303 (dump-unsigned-32 (fasl-file-table-free file) file)
304 (dump-fop 'sb!impl::fop-end-group file)
305 (close (fasl-file-stream file) :abort abort-p)
308 ;;;; main entries to object dumping
310 ;;; This function deals with dumping objects that are complex enough
311 ;;; so that we want to cache them in the table, rather than repeatedly
312 ;;; dumping them. If the object is in the EQ-TABLE, then we push it,
313 ;;; otherwise, we do a type dispatch to a type specific dumping
314 ;;; function. The type specific branches do any appropriate
315 ;;; EQUAL-TABLE check and table entry.
317 ;;; When we go to dump the object, we enter it in the CIRCULARITY-TABLE.
318 (defun dump-non-immediate-object (x file)
319 (let ((index (gethash x (fasl-file-eq-table file))))
320 (cond ((and index (not *cold-load-dump*))
321 (dump-push index file))
324 (symbol (dump-symbol x file))
326 ;; KLUDGE: The code in this case has been hacked
327 ;; to match Douglas Crosher's quick fix to CMU CL
328 ;; (on cmucl-imp 1999-12-27), applied in sbcl-0.6.8.11
329 ;; with help from Martin Atzmueller. This is not an
330 ;; ideal solution; to quote DTC,
331 ;; The compiler locks up trying to coalesce the
332 ;; constant lists. The hack below will disable the
333 ;; coalescing of lists while dumping and allows
334 ;; the code to compile. The real fix would be to
335 ;; take a little more care while dumping these.
336 ;; So if better list coalescing is needed, start here.
338 (if (circular-list-p x)
341 (eq-save-object x file))
342 (unless (equal-check-table x file)
344 (equal-save-object x file))))
347 (eq-save-object x file))
349 (dump-structure x file)
350 (eq-save-object x file))
352 ;; FIXME: The comment at the head of
353 ;; DUMP-NON-IMMEDIATE-OBJECT says it's for objects which
354 ;; we want to save, instead of repeatedly dumping them.
355 ;; But then we dump arrays here without doing anything
356 ;; like EQUAL-SAVE-OBJECT. What gives?
359 (unless (equal-check-table x file)
361 (ratio (dump-ratio x file))
362 (complex (dump-complex x file))
363 (float (dump-float x file))
364 (integer (dump-integer x file)))
365 (equal-save-object x file)))
367 ;; This probably never happens, since bad things tend to
368 ;; be detected during IR1 conversion.
369 (error "This object cannot be dumped into a fasl file:~% ~S"
373 ;;; Dump an object of any type by dispatching to the correct
374 ;;; type-specific dumping function. We pick off immediate objects,
375 ;;; symbols and and magic lists here. Other objects are handled by
376 ;;; DUMP-NON-IMMEDIATE-OBJECT.
378 ;;; This is the function used for recursive calls to the fasl dumper.
379 ;;; We don't worry about creating circularities here, since it is
380 ;;; assumed that there is a top-level call to DUMP-OBJECT.
381 (defun sub-dump-object (x file)
384 (dump-non-immediate-object x file)
385 (dump-fop 'sb!impl::fop-empty-list file)))
388 (dump-fop 'sb!impl::fop-truth file)
389 (dump-non-immediate-object x file)))
390 ((fixnump x) (dump-integer x file))
391 ((characterp x) (dump-character x file))
393 (dump-non-immediate-object x file))))
395 ;;; Dump stuff to backpatch already dumped objects. INFOS is the list
396 ;;; of CIRCULARITY structures describing what to do. The patching FOPs
397 ;;; take the value to store on the stack. We compute this value by
398 ;;; fetching the enclosing object from the table, and then CDR'ing it
400 (defun dump-circularities (infos file)
401 (let ((table (fasl-file-eq-table file)))
403 (let* ((value (circularity-value info))
404 (enclosing (circularity-enclosing-object info)))
405 (dump-push (gethash enclosing table) file)
406 (unless (eq enclosing value)
407 (do ((current enclosing (cdr current))
410 (dump-fop 'sb!impl::fop-nthcdr file)
411 (dump-unsigned-32 i file))
412 (declare (type index i)))))
414 (ecase (circularity-type info)
415 (:rplaca (dump-fop 'sb!impl::fop-rplaca file))
416 (:rplacd (dump-fop 'sb!impl::fop-rplacd file))
417 (:svset (dump-fop 'sb!impl::fop-svset file))
418 (:struct-set (dump-fop 'sb!impl::fop-structset file)))
419 (dump-unsigned-32 (gethash (circularity-object info) table) file)
420 (dump-unsigned-32 (circularity-index info) file))))
422 ;;; Set up stuff for circularity detection, then dump an object. All
423 ;;; shared and circular structure will be exactly preserved within a
424 ;;; single call to Dump-Object. Sharing between objects dumped by
425 ;;; separate calls is only preserved when convenient.
427 ;;; We peek at the object type so that we only pay the circular
428 ;;; detection overhead on types of objects that might be circular.
429 (defun dump-object (x file)
430 (if (or (array-header-p x)
434 (let ((*circularities-detected* ())
435 (circ (fasl-file-circularity-table file)))
437 (sub-dump-object x file)
438 (when *circularities-detected*
439 (dump-circularities *circularities-detected* file)
441 (sub-dump-object x file)))
443 ;;;; LOAD-TIME-VALUE and MAKE-LOAD-FORM support
445 ;;; Emit a funcall of the function and return the handle for the
447 (defun fasl-dump-load-time-value-lambda (fun file)
448 (declare (type clambda fun) (type fasl-file file))
449 (let ((handle (gethash (leaf-info fun) (fasl-file-entry-table file))))
451 (dump-push handle file)
452 (dump-fop 'sb!impl::fop-funcall file)
456 ;;; Return T iff CONSTANT has not already been dumped. It's been
457 ;;; dumped if it's in the EQ table.
458 (defun fasl-constant-already-dumped (constant file)
459 (if (or (gethash constant (fasl-file-eq-table file))
460 (gethash constant (fasl-file-valid-structures file)))
464 ;;; Use HANDLE whenever we try to dump CONSTANT. HANDLE should have been
465 ;;; returned earlier by FASL-DUMP-LOAD-TIME-VALUE-LAMBDA.
466 (defun fasl-note-handle-for-constant (constant handle file)
467 (let ((table (fasl-file-eq-table file)))
468 (when (gethash constant table)
469 (error "~S already dumped?" constant))
470 (setf (gethash constant table) handle))
473 ;;; Note that the specified structure can just be dumped by
474 ;;; enumerating the slots.
475 (defun fasl-validate-structure (structure file)
476 (setf (gethash structure (fasl-file-valid-structures file)) t)
482 (defun dump-ratio (x file)
483 (sub-dump-object (numerator x) file)
484 (sub-dump-object (denominator x) file)
485 (dump-fop 'sb!impl::fop-ratio file))
488 (defun dump-integer (n file)
491 (dump-fop 'sb!impl::fop-byte-integer file)
492 (dump-byte (logand #xFF n) file))
494 (dump-fop 'sb!impl::fop-word-integer file)
495 (dump-unsigned-32 n file))
497 (dump-fop 'sb!impl::fop-word-integer file)
498 (dump-integer-as-n-bytes n 4 file))
500 (let ((bytes (ceiling (1+ (integer-length n)) 8)))
502 sb!impl::fop-small-integer
505 (dump-integer-as-n-bytes n bytes file)))))
507 (defun dump-float (x file)
510 (dump-fop 'sb!impl::fop-single-float file)
511 (dump-integer-as-n-bytes (single-float-bits x) 4 file))
513 (dump-fop 'sb!impl::fop-double-float file)
515 (declare (double-float x))
516 ;; FIXME: Why sometimes DUMP-UNSIGNED-32 and sometimes
517 ;; DUMP-INTEGER-AS-N-BYTES .. 4?
518 (dump-unsigned-32 (double-float-low-bits x) file)
519 (dump-integer-as-n-bytes (double-float-high-bits x) 4 file)))
522 (dump-fop 'sb!impl::fop-long-float file)
523 (dump-long-float x file))))
525 (defun dump-complex (x file)
528 ((complex single-float)
529 (dump-fop 'sb!impl::fop-complex-single-float file)
530 (dump-integer-as-n-bytes (single-float-bits (realpart x)) 4 file)
531 (dump-integer-as-n-bytes (single-float-bits (imagpart x)) 4 file))
533 ((complex double-float)
534 (dump-fop 'sb!impl::fop-complex-double-float file)
535 (let ((re (realpart x)))
536 (declare (double-float re))
537 (dump-unsigned-32 (double-float-low-bits re) file)
538 (dump-integer-as-n-bytes (double-float-high-bits re) 4 file))
539 (let ((im (imagpart x)))
540 (declare (double-float im))
541 (dump-unsigned-32 (double-float-low-bits im) file)
542 (dump-integer-as-n-bytes (double-float-high-bits im) 4 file)))
543 #!+(and long-float (not sb-xc))
544 ((complex long-float)
545 (dump-fop 'sb!impl::fop-complex-long-float file)
546 (dump-long-float (realpart x) file)
547 (dump-long-float (imagpart x) file))
549 (sub-dump-object (realpart x) file)
550 (sub-dump-object (imagpart x) file)
551 (dump-fop 'sb!impl::fop-complex file))))
555 ;;; Return the table index of PKG, adding the package to the table if
556 ;;; necessary. During cold load, we read the string as a normal string
557 ;;; so that we can do the package lookup at cold load time.
559 ;;; FIXME: Despite the parallelism in names, the functionality of
560 ;;; this function is not parallel to other functions DUMP-FOO, e.g.
561 ;;; DUMP-SYMBOL and DUMP-LIST. The mapping between names and behavior
562 ;;; should be made more consistent.
563 (defun dump-package (pkg file)
564 (declare (type package pkg) (type fasl-file file) (values index)
566 (cond ((cdr (assoc pkg (fasl-file-packages file) :test #'eq)))
568 (unless *cold-load-dump*
569 (dump-fop 'sb!impl::fop-normal-load file))
570 (dump-simple-string (package-name pkg) file)
571 (dump-fop 'sb!impl::fop-package file)
572 (unless *cold-load-dump*
573 (dump-fop 'sb!impl::fop-maybe-cold-load file))
574 (let ((entry (dump-pop file)))
575 (push (cons pkg entry) (fasl-file-packages file))
580 ;;; Dump a list, setting up patching information when there are
581 ;;; circularities. We scan down the list, checking for CDR and CAR
584 ;;; If there is a CDR circularity, we terminate the list with NIL and
585 ;;; make a CIRCULARITY notation for the CDR of the previous cons.
587 ;;; If there is no CDR circularity, then we mark the current cons and
588 ;;; check for a CAR circularity. When there is a CAR circularity, we
589 ;;; make the CAR NIL initially, arranging for the current cons to be
592 ;;; Otherwise, we recursively call the dumper to dump the current
595 ;;; Marking of the conses is inhibited when *COLD-LOAD-DUMP* is true.
596 ;;; This inhibits all circularity detection.
597 (defun dump-list (list file)
599 (not (gethash list (fasl-file-circularity-table file)))))
600 (do* ((l list (cdr l))
602 (circ (fasl-file-circularity-table file)))
605 (terminate-undotted-list n file))
607 (sub-dump-object l file)
608 (terminate-dotted-list n file))))
609 (declare (type index n))
610 (let ((ref (gethash l circ)))
612 (push (make-circularity :type :rplacd
616 :enclosing-object ref)
617 *circularities-detected*)
618 (terminate-undotted-list n file)
621 (unless *cold-load-dump*
622 (setf (gethash l circ) list))
625 (ref (gethash obj circ)))
627 (push (make-circularity :type :rplaca
631 :enclosing-object ref)
632 *circularities-detected*)
633 (sub-dump-object nil file))
635 (sub-dump-object obj file))))))
637 (defun terminate-dotted-list (n file)
638 (declare (type index n) (type fasl-file file))
640 (1 (dump-fop 'sb!impl::fop-list*-1 file))
641 (2 (dump-fop 'sb!impl::fop-list*-2 file))
642 (3 (dump-fop 'sb!impl::fop-list*-3 file))
643 (4 (dump-fop 'sb!impl::fop-list*-4 file))
644 (5 (dump-fop 'sb!impl::fop-list*-5 file))
645 (6 (dump-fop 'sb!impl::fop-list*-6 file))
646 (7 (dump-fop 'sb!impl::fop-list*-7 file))
647 (8 (dump-fop 'sb!impl::fop-list*-8 file))
648 (T (do ((nn n (- nn 255)))
650 (dump-fop 'sb!impl::fop-list* file)
652 (declare (type index nn))
653 (dump-fop 'sb!impl::fop-list* file)
654 (dump-byte 255 file)))))
656 ;;; If N > 255, must build list with one LIST operator, then LIST*
659 (defun terminate-undotted-list (n file)
660 (declare (type index n) (type fasl-file file))
662 (1 (dump-fop 'sb!impl::fop-list-1 file))
663 (2 (dump-fop 'sb!impl::fop-list-2 file))
664 (3 (dump-fop 'sb!impl::fop-list-3 file))
665 (4 (dump-fop 'sb!impl::fop-list-4 file))
666 (5 (dump-fop 'sb!impl::fop-list-5 file))
667 (6 (dump-fop 'sb!impl::fop-list-6 file))
668 (7 (dump-fop 'sb!impl::fop-list-7 file))
669 (8 (dump-fop 'sb!impl::fop-list-8 file))
671 (dump-fop 'sb!impl::fop-list file)
673 (t (dump-fop 'sb!impl::fop-list file)
675 (do ((nn (- n 255) (- nn 255)))
677 (dump-fop 'sb!impl::fop-list* file)
679 (declare (type index nn))
680 (dump-fop 'sb!impl::fop-list* file)
681 (dump-byte 255 file)))))))
685 ;;; Dump the array thing.
686 (defun dump-array (x file)
689 (dump-multi-dim-array x file)))
691 ;;; Dump the vector object. If it's not simple, then actually dump a
692 ;;; simple version of it. But we enter the original in the EQ or EQUAL
694 (defun dump-vector (x file)
695 (let ((simple-version (if (array-header-p x)
696 (coerce x 'simple-array)
698 (typecase simple-version
700 (unless (equal-check-table x file)
701 (dump-simple-string simple-version file)
702 (equal-save-object x file)))
704 (dump-simple-vector simple-version file)
705 (eq-save-object x file))
706 ((simple-array single-float (*))
707 (dump-single-float-vector simple-version file)
708 (eq-save-object x file))
709 ((simple-array double-float (*))
710 (dump-double-float-vector simple-version file)
711 (eq-save-object x file))
713 ((simple-array long-float (*))
714 (dump-long-float-vector simple-version file)
715 (eq-save-object x file))
716 ((simple-array (complex single-float) (*))
717 (dump-complex-single-float-vector simple-version file)
718 (eq-save-object x file))
719 ((simple-array (complex double-float) (*))
720 (dump-complex-double-float-vector simple-version file)
721 (eq-save-object x file))
723 ((simple-array (complex long-float) (*))
724 (dump-complex-long-float-vector simple-version file)
725 (eq-save-object x file))
727 (dump-i-vector simple-version file)
728 (eq-save-object x file)))))
730 ;;; Dump a SIMPLE-VECTOR, handling any circularities.
731 (defun dump-simple-vector (v file)
732 (declare (type simple-vector v) (type fasl-file file))
733 (note-potential-circularity v file)
734 (do ((index 0 (1+ index))
736 (circ (fasl-file-circularity-table file)))
739 sb!impl::fop-small-vector
742 (let* ((obj (aref v index))
743 (ref (gethash obj circ)))
745 (push (make-circularity :type :svset
749 :enclosing-object ref)
750 *circularities-detected*)
751 (sub-dump-object nil file))
753 (sub-dump-object obj file))))))
755 (defun dump-i-vector (vec file &key data-only)
756 (declare (type (simple-array * (*)) vec))
757 (let ((len (length vec)))
758 (labels ((dump-unsigned-vector (size bytes)
760 (dump-fop 'sb!impl::fop-int-vector file)
761 (dump-unsigned-32 len file)
762 (dump-byte size file))
763 ;; The case which is easy to handle in a portable way is when
764 ;; the element size is a multiple of the output byte size, and
765 ;; happily that's the only case we need to be portable. (The
766 ;; cross-compiler has to output debug information (including
767 ;; (SIMPLE-ARRAY (UNSIGNED-BYTE 8) *).) The other cases are only
768 ;; needed in the target SBCL, so we let them be handled with
769 ;; unportable bit bashing.
770 (cond ((>= size 8) ; easy cases
771 (multiple-value-bind (floor rem) (floor size 8)
774 (dump-integer-as-n-bytes i floor file))))
775 (t ; harder cases, not supported in cross-compiler
776 (dump-raw-bytes vec bytes file))))
777 (dump-signed-vector (size bytes)
778 ;; Note: Dumping specialized signed vectors isn't
779 ;; supported in the cross-compiler. (All cases here end
780 ;; up trying to call DUMP-RAW-BYTES, which isn't
781 ;; provided in the cross-compilation host, only on the
784 (dump-fop 'sb!impl::fop-signed-int-vector file)
785 (dump-unsigned-32 len file)
786 (dump-byte size file))
787 (dump-raw-bytes vec bytes file)))
789 ;; KLUDGE: What exactly does the (ASH .. -3) stuff do? -- WHN 19990902
791 (dump-unsigned-vector 1 (ash (+ (the index len) 7) -3)))
792 ((simple-array (unsigned-byte 2) (*))
793 (dump-unsigned-vector 2 (ash (+ (the index (ash len 1)) 7) -3)))
794 ((simple-array (unsigned-byte 4) (*))
795 (dump-unsigned-vector 4 (ash (+ (the index (ash len 2)) 7) -3)))
796 ((simple-array (unsigned-byte 8) (*))
797 (dump-unsigned-vector 8 len))
798 ((simple-array (unsigned-byte 16) (*))
799 (dump-unsigned-vector 16 (* 2 len)))
800 ((simple-array (unsigned-byte 32) (*))
801 (dump-unsigned-vector 32 (* 4 len)))
802 ((simple-array (signed-byte 8) (*))
803 (dump-signed-vector 8 len))
804 ((simple-array (signed-byte 16) (*))
805 (dump-signed-vector 16 (* 2 len)))
806 ((simple-array (signed-byte 30) (*))
807 (dump-signed-vector 30 (* 4 len)))
808 ((simple-array (signed-byte 32) (*))
809 (dump-signed-vector 32 (* 4 len)))))))
811 ;;; Dump characters and string-ish things.
813 (defun dump-character (ch file)
814 (dump-fop 'sb!impl::fop-short-character file)
815 (dump-byte (char-code ch) file))
817 ;;; a helper function shared by DUMP-SIMPLE-STRING and DUMP-SYMBOL
818 (defun dump-characters-of-string (s fasl-file)
819 (declare (type string s) (type fasl-file fasl-file))
821 (dump-byte (char-code c) fasl-file))
824 ;;; Dump a SIMPLE-BASE-STRING.
825 ;;; FIXME: should be called DUMP-SIMPLE-BASE-STRING then
826 (defun dump-simple-string (s file)
827 (declare (type simple-base-string s))
828 (dump-fop* (length s)
829 sb!impl::fop-small-string
832 (dump-characters-of-string s file)
835 ;;; If we get here, it is assumed that the symbol isn't in the table,
836 ;;; but we are responsible for putting it there when appropriate. To
837 ;;; avoid too much special-casing, we always push the symbol in the
838 ;;; table, but don't record that we have done so if *COLD-LOAD-DUMP*
840 (defun dump-symbol (s file)
841 (let* ((pname (symbol-name s))
842 (pname-length (length pname))
843 (pkg (symbol-package s)))
846 (dump-fop* pname-length
847 sb!impl::fop-uninterned-small-symbol-save
848 sb!impl::fop-uninterned-symbol-save
850 ;; CMU CL had FOP-SYMBOL-SAVE/FOP-SMALL-SYMBOL-SAVE fops which
851 ;; used the current value of *PACKAGE*. Unfortunately that's
852 ;; broken w.r.t. ANSI Common Lisp semantics, so those are gone
854 ;;((eq pkg *package*)
855 ;; (dump-fop* pname-length
856 ;; sb!impl::fop-small-symbol-save
857 ;; sb!impl::fop-symbol-save file))
858 ((eq pkg sb!int:*cl-package*)
859 (dump-fop* pname-length
860 sb!impl::fop-lisp-small-symbol-save
861 sb!impl::fop-lisp-symbol-save
863 ((eq pkg sb!int:*keyword-package*)
864 (dump-fop* pname-length
865 sb!impl::fop-keyword-small-symbol-save
866 sb!impl::fop-keyword-symbol-save
868 ((< pname-length 256)
869 (dump-fop* (dump-package pkg file)
870 sb!impl::fop-small-symbol-in-byte-package-save
871 sb!impl::fop-small-symbol-in-package-save
873 (dump-byte pname-length file))
875 (dump-fop* (dump-package pkg file)
876 sb!impl::fop-symbol-in-byte-package-save
877 sb!impl::fop-symbol-in-package-save
879 (dump-unsigned-32 pname-length file)))
881 (dump-characters-of-string pname file)
883 (unless *cold-load-dump*
884 (setf (gethash s (fasl-file-eq-table file))
885 (fasl-file-table-free file)))
887 (incf (fasl-file-table-free file)))
891 ;;;; component (function) dumping
893 (defun dump-segment (segment code-length fasl-file)
894 (declare (type sb!assem:segment segment)
895 (type fasl-file fasl-file))
896 (let* ((stream (fasl-file-stream fasl-file))
897 (nwritten (write-segment-contents segment stream)))
898 ;; In CMU CL there was no enforced connection between the CODE-LENGTH
899 ;; argument and the number of bytes actually written. I added this
900 ;; assertion while trying to debug portable genesis. -- WHN 19990902
901 (unless (= code-length nwritten)
902 (error "internal error, code-length=~D, nwritten=~D"
905 ;; KLUDGE: It's not clear what this is trying to do, but it looks as
906 ;; though it's an implicit undocumented dependence on a 4-byte
907 ;; wordsize which could be painful in porting. Note also that there
908 ;; are other undocumented modulo-4 things scattered throughout the
909 ;; code and conditionalized with GENGC, and I don't know what those
910 ;; do either. -- WHN 19990323
911 #!+gengc (unless (zerop (logand code-length 3))
912 (dotimes (i (- 4 (logand code-length 3)))
913 (dump-byte 0 fasl-file)))
916 ;;; Dump all the fixups. Currently there are three flavors of fixup:
917 ;;; - assembly routines: named by a symbol
918 ;;; - foreign (C) symbols: named by a string
919 ;;; - code object references: don't need a name.
920 (defun dump-fixups (fixups fasl-file)
921 (declare (list fixups) (type fasl-file fasl-file))
922 (dolist (info fixups)
923 ;; FIXME: Packing data with LIST in NOTE-FIXUP and unpacking them
924 ;; with FIRST, SECOND, and THIRD here is hard to follow and
925 ;; maintain. Perhaps we could define a FIXUP-INFO structure to use
926 ;; instead, and rename *FIXUPS* to *FIXUP-INFO-LIST*?
927 (let* ((kind (first info))
928 (fixup (second info))
929 (name (fixup-name fixup))
930 (flavor (fixup-flavor fixup))
931 (offset (third info)))
932 ;; FIXME: This OFFSET is not what's called OFFSET in the FIXUP
933 ;; structure, it's what's called POSN in NOTE-FIXUP. (As far as
934 ;; I can tell, FIXUP-OFFSET is not actually an offset, it's an
935 ;; internal label used instead of NAME for :CODE-OBJECT fixups.
936 ;; Notice that in the :CODE-OBJECT case, NAME is ignored.)
937 (dump-fop 'sb!impl::fop-normal-load fasl-file)
938 (let ((*cold-load-dump* t))
939 (dump-object kind fasl-file))
940 (dump-fop 'sb!impl::fop-maybe-cold-load fasl-file)
941 ;; Depending on the flavor, we may have various kinds of
942 ;; noise before the offset.
945 (aver (symbolp name))
946 (dump-fop 'sb!impl::fop-normal-load fasl-file)
947 (let ((*cold-load-dump* t))
948 (dump-object name fasl-file))
949 (dump-fop 'sb!impl::fop-maybe-cold-load fasl-file)
950 (dump-fop 'sb!impl::fop-assembler-fixup fasl-file))
952 (aver (stringp name))
953 (dump-fop 'sb!impl::fop-foreign-fixup fasl-file)
954 (let ((len (length name)))
955 (aver (< len 256)) ; (limit imposed by fop definition)
956 (dump-byte len fasl-file)
958 (dump-byte (char-code (schar name i)) fasl-file))))
961 (dump-fop 'sb!impl::fop-code-object-fixup fasl-file)))
962 ;; No matter what the flavor, we'll always dump the offset.
963 (dump-unsigned-32 offset fasl-file)))
966 ;;; Dump out the constant pool and code-vector for component, push the
967 ;;; result in the table, and return the offset.
969 ;;; The only tricky thing is handling constant-pool references to
970 ;;; functions. If we have already dumped the function, then we just
971 ;;; push the code pointer. Otherwise, we must create back-patching
972 ;;; information so that the constant will be set when the function is
973 ;;; eventually dumped. This is a bit awkward, since we don't have the
974 ;;; handle for the code object being dumped while we are dumping its
977 ;;; We dump trap objects in any unused slots or forward referenced slots.
978 (defun dump-code-object (component
985 (declare (type component component)
986 (list trace-table-as-list)
987 (type index code-length)
988 (type fasl-file fasl-file))
990 (let* ((2comp (component-info component))
991 (constants (ir2-component-constants 2comp))
992 (header-length (length constants))
993 (packed-trace-table (pack-trace-table trace-table-as-list))
994 (total-length (+ code-length
995 (* (length packed-trace-table) tt-bytes-per-entry))))
999 ;; Dump the debug info.
1001 (let ((info (debug-info-for-component component))
1002 (*dump-only-valid-structures* nil))
1003 (dump-object info fasl-file)
1004 (let ((info-handle (dump-pop fasl-file)))
1005 (dump-push info-handle fasl-file)
1006 (push info-handle (fasl-file-debug-info fasl-file))))
1008 ;; Dump the offset of the trace table.
1009 (dump-object code-length fasl-file)
1010 ;; FIXME: As long as we don't have GENGC, the trace table is
1011 ;; hardwired to be empty. So we might be able to get rid of
1012 ;; trace tables? However, we should probably wait for the first
1013 ;; port to a system where CMU CL uses GENGC to see whether GENGC
1014 ;; is really gone. (I.e. maybe other non-X86 ports will want to
1015 ;; use it, just as in CMU CL.)
1017 ;; Dump the constants, noting any :entries that have to be fixed up.
1018 (do ((i sb!vm:code-constants-offset (1+ i)))
1019 ((>= i header-length))
1020 (let ((entry (aref constants i)))
1023 (dump-object (constant-value entry) fasl-file))
1027 (let* ((info (leaf-info (cdr entry)))
1028 (handle (gethash info
1029 (fasl-file-entry-table fasl-file))))
1032 (dump-push handle fasl-file))
1034 (patches (cons info i))
1035 (dump-fop 'sb!impl::fop-misc-trap fasl-file)))))
1037 (dump-push (cdr entry) fasl-file))
1039 (dump-object (cdr entry) fasl-file)
1040 (dump-fop 'sb!impl::fop-fdefinition fasl-file))))
1042 (dump-fop 'sb!impl::fop-misc-trap fasl-file)))))
1044 ;; Dump the debug info.
1046 (let ((info (debug-info-for-component component))
1047 (*dump-only-valid-structures* nil))
1048 (dump-object info fasl-file)
1049 (let ((info-handle (dump-pop fasl-file)))
1050 (dump-push info-handle fasl-file)
1051 (push info-handle (fasl-file-debug-info fasl-file))))
1053 (let ((num-consts #!+gengc (- header-length
1054 sb!vm:code-debug-info-slot)
1055 #!-gengc (- header-length
1056 sb!vm:code-trace-table-offset-slot))
1057 (total-length #!+gengc (ceiling total-length 4)
1058 #!-gengc total-length))
1059 (cond ((and (< num-consts #x100) (< total-length #x10000))
1060 (dump-fop 'sb!impl::fop-small-code fasl-file)
1061 (dump-byte num-consts fasl-file)
1062 (dump-integer-as-n-bytes total-length 2 fasl-file))
1064 (dump-fop 'sb!impl::fop-code fasl-file)
1065 (dump-unsigned-32 num-consts fasl-file)
1066 (dump-unsigned-32 total-length fasl-file))))
1068 ;; These two dumps are only ones which contribute to our
1069 ;; TOTAL-LENGTH value.
1070 (dump-segment code-segment code-length fasl-file)
1071 (dump-i-vector packed-trace-table fasl-file :data-only t)
1073 ;; DUMP-FIXUPS does its own internal DUMP-FOPs: the bytes it
1074 ;; dumps aren't included in the TOTAL-LENGTH passed to our
1075 ;; FOP-CODE/FOP-SMALL-CODE fop.
1076 (dump-fixups fixups fasl-file)
1078 (dump-fop 'sb!impl::fop-sanctify-for-execution fasl-file)
1079 (let ((handle (dump-pop fasl-file)))
1080 (dolist (patch (patches))
1081 (push (cons handle (cdr patch))
1082 (gethash (car patch) (fasl-file-patch-table fasl-file))))
1085 (defun dump-assembler-routines (code-segment length fixups routines file)
1086 (dump-fop 'sb!impl::fop-assembler-code file)
1087 (dump-unsigned-32 #!+gengc (ceiling length 4)
1090 (write-segment-contents code-segment (fasl-file-stream file))
1091 (dolist (routine routines)
1092 (dump-fop 'sb!impl::fop-normal-load file)
1093 (let ((*cold-load-dump* t))
1094 (dump-object (car routine) file))
1095 (dump-fop 'sb!impl::fop-maybe-cold-load file)
1096 (dump-fop 'sb!impl::fop-assembler-routine file)
1097 (dump-unsigned-32 (label-position (cdr routine)) file))
1098 (dump-fixups fixups file)
1099 (dump-fop 'sb!impl::fop-sanctify-for-execution file)
1102 ;;; Dump a function-entry data structure corresponding to ENTRY to
1103 ;;; FILE. CODE-HANDLE is the table offset of the code object for the
1106 ;;; If the entry is a DEFUN, then we also dump a FOP-FSET so that the
1107 ;;; cold loader can instantiate the definition at cold-load time,
1108 ;;; allowing forward references to functions in top-level forms.
1109 (defun dump-one-entry (entry code-handle file)
1110 (declare (type entry-info entry) (type index code-handle)
1111 (type fasl-file file))
1112 (let ((name (entry-info-name entry)))
1113 (dump-push code-handle file)
1114 (dump-object name file)
1115 (dump-object (entry-info-arguments entry) file)
1116 (dump-object (entry-info-type entry) file)
1117 (dump-fop 'sb!impl::fop-function-entry file)
1118 (dump-unsigned-32 (label-position (entry-info-offset entry)) file)
1119 (let ((handle (dump-pop file)))
1120 (when (and name (or (symbolp name) (listp name)))
1121 (dump-object name file)
1122 (dump-push handle file)
1123 (dump-fop 'sb!impl::fop-fset file))
1126 ;;; Alter the code object referenced by CODE-HANDLE at the specified
1127 ;;; OFFSET, storing the object referenced by ENTRY-HANDLE.
1128 (defun dump-alter-code-object (code-handle offset entry-handle file)
1129 (declare (type index code-handle entry-handle offset) (type fasl-file file))
1130 (dump-push code-handle file)
1131 (dump-push entry-handle file)
1133 sb!impl::fop-byte-alter-code
1134 sb!impl::fop-alter-code
1138 ;;; Dump the code, constants, etc. for component. We pass in the
1139 ;;; assembler fixups, code vector and node info.
1140 (defun fasl-dump-component (component
1146 (declare (type component component) (list trace-table) (type fasl-file file))
1148 (dump-fop 'sb!impl::fop-verify-empty-stack file)
1149 (dump-fop 'sb!impl::fop-verify-table-size file)
1150 (dump-unsigned-32 (fasl-file-table-free file) file)
1153 (let ((info (ir2-component-dyncount-info (component-info component))))
1155 (fasl-validate-structure info file)))
1157 (let ((code-handle (dump-code-object component
1163 (2comp (component-info component)))
1164 (dump-fop 'sb!impl::fop-verify-empty-stack file)
1166 (dolist (entry (ir2-component-entries 2comp))
1167 (let ((entry-handle (dump-one-entry entry code-handle file)))
1168 (setf (gethash entry (fasl-file-entry-table file)) entry-handle)
1170 (let ((old (gethash entry (fasl-file-patch-table file))))
1171 ;; FIXME: All this code is shared with
1172 ;; FASL-DUMP-BYTE-COMPONENT, and should probably be gathered
1173 ;; up into a named function (DUMP-PATCHES?) called from both
1177 (dump-alter-code-object (car patch)
1181 (remhash entry (fasl-file-patch-table file)))))))
1184 (defun dump-byte-code-object (segment code-length constants file)
1185 (declare (type sb!assem:segment segment)
1186 (type index code-length)
1187 (type vector constants)
1188 (type fasl-file file))
1189 (collect ((entry-patches))
1191 ;; Dump the debug info.
1193 (let ((info (make-debug-info
1194 :name (component-name *component-being-compiled*)))
1195 (*dump-only-valid-structures* nil))
1196 (dump-object info file)
1197 (let ((info-handle (dump-pop file)))
1198 (dump-push info-handle file)
1199 (push info-handle (fasl-file-debug-info file))))
1201 ;; The "trace table" is initialized by loader to hold a list of
1202 ;; all byte functions in this code object (for debug info.)
1203 (dump-object nil file)
1205 ;; Dump the constants.
1206 (dotimes (i (length constants))
1207 (let ((entry (aref constants i)))
1210 (dump-object (constant-value entry) file))
1212 (dump-fop 'sb!impl::fop-misc-trap file))
1216 (let* ((info (leaf-info (cdr entry)))
1217 (handle (gethash info (fasl-file-entry-table file))))
1220 (dump-push handle file))
1222 (entry-patches (cons info
1223 (+ i sb!vm:code-constants-offset)))
1224 (dump-fop 'sb!impl::fop-misc-trap file)))))
1226 (dump-push (cdr entry) file))
1228 (dump-object (cdr entry) file)
1229 (dump-fop 'sb!impl::fop-fdefinition file))
1231 (dump-object 'load-type-predicate file)
1232 (let ((*unparse-function-type-simplify* t))
1233 (dump-object (type-specifier (cdr entry)) file))
1234 (dump-fop 'sb!impl::fop-funcall file)
1235 (dump-byte 1 file)))))))
1237 ;; Dump the debug info.
1239 (let ((info (make-debug-info :name
1240 (component-name *component-being-compiled*)))
1241 (*dump-only-valid-structures* nil))
1242 (dump-object info file)
1243 (let ((info-handle (dump-pop file)))
1244 (dump-push info-handle file)
1245 (push info-handle (fasl-file-debug-info file))))
1247 (let ((num-consts #!+gengc (+ (length constants) 2)
1248 #!-gengc (1+ (length constants)))
1249 (code-length #!+gengc (ceiling code-length 4)
1250 #!-gengc code-length))
1251 (cond ((and (< num-consts #x100) (< code-length #x10000))
1252 (dump-fop 'sb!impl::fop-small-code file)
1253 (dump-byte num-consts file)
1254 (dump-integer-as-n-bytes code-length 2 file))
1256 (dump-fop 'sb!impl::fop-code file)
1257 (dump-unsigned-32 num-consts file)
1258 (dump-unsigned-32 code-length file))))
1259 (dump-segment segment code-length file)
1260 (let ((code-handle (dump-pop file))
1261 (patch-table (fasl-file-patch-table file)))
1262 (dolist (patch (entry-patches))
1263 (push (cons code-handle (cdr patch))
1264 (gethash (car patch) patch-table)))
1267 ;;; Dump a BYTE-FUNCTION object. We dump the layout and
1268 ;;; funcallable-instance info, but rely on the loader setting up the
1269 ;;; correct funcallable-instance-function.
1270 (defun dump-byte-function (xep code-handle file)
1271 (let ((nslots (- (get-closure-length xep)
1273 (1- sb!vm:funcallable-instance-info-offset))))
1276 (dump-push code-handle file)
1277 (dump-object (%funcallable-instance-info xep i) file)))
1278 (dump-object (%funcallable-instance-layout xep) file)
1279 (dump-fop 'sb!impl::fop-make-byte-compiled-function file)
1280 (dump-byte nslots file))
1283 ;;; Dump a byte-component. This is similar to FASL-DUMP-COMPONENT, but
1285 (defun fasl-dump-byte-component (segment length constants xeps file)
1286 (declare (type sb!assem:segment segment)
1288 (type vector constants)
1290 (type fasl-file file))
1292 (let ((code-handle (dump-byte-code-object segment length constants file)))
1293 (dolist (noise xeps)
1294 (let* ((lambda (car noise))
1295 (info (lambda-info lambda))
1297 (dump-byte-function xep code-handle file)
1298 (let* ((entry-handle (dump-pop file))
1299 (patch-table (fasl-file-patch-table file))
1300 (old (gethash info patch-table)))
1301 (setf (gethash info (fasl-file-entry-table file)) entry-handle)
1304 (dump-alter-code-object (car patch)
1308 (remhash info patch-table))))))
1311 ;;; Dump a FOP-FUNCALL to call an already dumped top-level lambda at
1313 (defun fasl-dump-top-level-lambda-call (fun file)
1314 (declare (type clambda fun) (type fasl-file file))
1315 (let ((handle (gethash (leaf-info fun) (fasl-file-entry-table file))))
1317 (dump-push handle file)
1318 (dump-fop 'sb!impl::fop-funcall-for-effect file)
1322 ;;; Compute the correct list of DEBUG-SOURCE structures and backpatch
1323 ;;; all of the dumped DEBUG-INFO structures. We clear the
1324 ;;; FASL-FILE-DEBUG-INFO, so that subsequent components with different
1325 ;;; source info may be dumped.
1326 (defun fasl-dump-source-info (info file)
1327 (declare (type source-info info) (type fasl-file file))
1328 (let ((res (debug-source-for-info info))
1329 (*dump-only-valid-structures* nil))
1330 (dump-object res file)
1331 (let ((res-handle (dump-pop file)))
1332 (dolist (info-handle (fasl-file-debug-info file))
1333 (dump-push res-handle file)
1334 (dump-fop 'sb!impl::fop-structset file)
1335 (dump-unsigned-32 info-handle file)
1336 (dump-unsigned-32 2 file))))
1338 (setf (fasl-file-debug-info file) ())
1341 ;;;; dumping structures
1343 (defun dump-structure (struct file)
1344 (when *dump-only-valid-structures*
1345 (unless (gethash struct (fasl-file-valid-structures file))
1346 (error "attempt to dump invalid structure:~% ~S~%How did this happen?"
1348 (note-potential-circularity struct file)
1349 (do ((index 0 (1+ index))
1350 (length (%instance-length struct))
1351 (circ (fasl-file-circularity-table file)))
1354 sb!impl::fop-small-struct
1357 (let* ((obj (%instance-ref struct index))
1358 (ref (gethash obj circ)))
1360 (push (make-circularity :type :struct-set
1364 :enclosing-object ref)
1365 *circularities-detected*)
1366 (sub-dump-object nil file))
1368 (sub-dump-object obj file))))))
1370 (defun dump-layout (obj file)
1371 (when (layout-invalid obj)
1372 (compiler-error "attempt to dump reference to obsolete class: ~S"
1373 (layout-class obj)))
1374 (let ((name (sb!xc:class-name (layout-class obj))))
1376 (compiler-error "dumping anonymous layout: ~S" obj))
1377 (dump-fop 'sb!impl::fop-normal-load file)
1378 (let ((*cold-load-dump* t))
1379 (dump-object name file))
1380 (dump-fop 'sb!impl::fop-maybe-cold-load file))
1381 (sub-dump-object (layout-inherits obj) file)
1382 (sub-dump-object (layout-depthoid obj) file)
1383 (sub-dump-object (layout-length obj) file)
1384 (dump-fop 'sb!impl::fop-layout file))