1 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; This software is derived from the CMU CL system, which was
5 ;;;; written at Carnegie Mellon University and released into the
6 ;;;; public domain. The software is in the public domain and is
7 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
8 ;;;; files for more information.
10 (in-package "SB-COLD")
12 #+#.
(cl:if
(cl:find-package
"SB-POSIX") '(and) '(or))
13 (defun parallel-make-host-1 (max-jobs)
14 (let ((subprocess-count 0)
15 (subprocess-list nil
))
17 (multiple-value-bind (pid status
) (sb-posix:wait
)
18 (format t
"~&; Subprocess ~D exit status ~D~%" pid status
)
19 (setq subprocess-list
(delete pid subprocess-list
)))
20 (decf subprocess-count
)))
21 (do-stems-and-flags (stem flags
)
22 (unless (position :not-host flags
)
23 (when (>= subprocess-count max-jobs
)
25 (let ((pid (sb-posix:fork
)))
27 (in-host-compilation-mode
28 (lambda () (compile-stem stem flags
:host-compile
)))
29 ;; FIXME: convey exit code based on COMPILE result.
30 (sb-cold::exit-process
0))
31 (push pid subprocess-list
)
32 (incf subprocess-count
)
33 ;; Do not wait for the compile to finish. Just load as source.
34 (let ((source (merge-pathnames (stem-remap-target stem
)
35 (make-pathname :type
"lisp"))))
36 (let ((sb-ext:*evaluator-mode
* :interpret
))
37 (in-host-compilation-mode
39 (load source
:verbose t
:print nil
))))))))
40 (loop (if (plusp subprocess-count
) (wait) (return)))))
42 ;; We want to load compiled files, because that's what this function promises.
43 ;; Reloading is tricky because constructors for interned ctypes will construct
44 ;; new objects via their LOAD-TIME-VALUE forms, but globaldb already stored
45 ;; some objects from the interpreted pre-load.
46 ;; So wipe everything out that causes problems down the line.
47 ;; (Or perhaps we could make their effects idempotent)
48 (format t
"~&; Parallel build: Clearing globaldb~%")
50 (when (get s
:sb-xc-globaldb-info
)
51 (remf (symbol-plist s
) :sb-xc-globaldb-info
)))
52 (fill (symbol-value 'sb
!impl
::*info-types
*) nil
)
53 (clrhash (symbol-value 'sb
!kernel
::*forward-referenced-layouts
*))
54 (setf (symbol-value 'sb
!kernel
:*type-system-initialized
*) nil
)
55 (makunbound 'sb
!c
::*backend-primitive-type-names
*)
56 (makunbound 'sb
!c
::*backend-primitive-type-aliases
*)
58 (format t
"~&; Parallel build: Reloading compilation artifacts~%")
59 ;; Now it works to load fasls.
60 (in-host-compilation-mode
62 (handler-bind ((sb-kernel:redefinition-warning
#'muffle-warning
))
63 (do-stems-and-flags (stem flags
)
64 (unless (position :not-host flags
)
65 (load (stem-object-path stem flags
:host-compile
)
66 :verbose t
:print nil
))))))
67 (format t
"~&; Parallel build: Fasl loading complete~%"))
69 ;;; Either load or compile-then-load the cross-compiler into the
70 ;;; cross-compilation host Common Lisp.
71 (defun load-or-cload-xcompiler (load-or-cload-stem)
72 (declare (type function load-or-cload-stem
))
73 ;; Build a version of Python to run in the host Common Lisp, to be
74 ;; used only in cross-compilation.
76 ;; Note that files which are marked :ASSEM, to cause them to be
77 ;; processed with SB!C:ASSEMBLE-FILE when we're running under the
78 ;; cross-compiler or the target lisp, are still processed here, just
79 ;; with the ordinary Lisp compiler, and this is intentional, in
80 ;; order to make the compiler aware of the definitions of assembly
82 (if (and (make-host-1-parallelism)
83 (eq load-or-cload-stem
#'host-cload-stem
))
84 (funcall (intern "PARALLEL-MAKE-HOST-1" 'sb-cold
)
85 (make-host-1-parallelism))
86 (do-stems-and-flags (stem flags
)
87 (unless (find :not-host flags
)
88 (funcall load-or-cload-stem stem flags
)
89 #!+sb-show
(warn-when-cl-snapshot-diff *cl-snapshot
*))))
91 ;; If the cross-compilation host is SBCL itself, we can use the
92 ;; PURIFY extension to freeze everything in place, reducing the
93 ;; amount of work done on future GCs. In machines with limited
94 ;; memory, this could help, by reducing the amount of memory which
95 ;; needs to be juggled in a full GC. And it can hardly hurt, since
96 ;; (in the ordinary build procedure anyway) essentially everything
97 ;; which is reachable at this point will remain reachable for the
100 ;; (Except that purifying actually slows down GENCGC). -- JES, 2006-05-30
101 #+(and sbcl
(not gencgc
))