Change immobile space free pointers to alien vars
[sbcl.git] / src / compiler / generic / parms.lisp
blob964b144ad14c980b95cda9ff104b5c78a33287ae
1 ;;;; This file contains some parameterizations of various VM
2 ;;;; attributes common to all architectures.
4 ;;;; This software is part of the SBCL system. See the README file for
5 ;;;; more information.
6 ;;;;
7 ;;;; This software is derived from the CMU CL system, which was
8 ;;;; written at Carnegie Mellon University and released into the
9 ;;;; public domain. The software is in the public domain and is
10 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
11 ;;;; files for more information.
13 (in-package "SB!VM")
15 ;;; When building the cross-compiler (and called by the host), read the
16 ;;; dynamic-space-size file.
17 ;;; When called by the cross-compiler (in the host), use the previously chosen value.
18 ;;; The target function is never called, but if omitted via #-sb-xc-host,
19 ;;; compilation of !GENCGC-SPACE-SETUP would issue an "undefined" warning.
20 (defun !read-dynamic-space-size ()
21 (unless (member :sb-xc-host *features*)
22 (return-from !read-dynamic-space-size (symbol-value 'default-dynamic-space-size)))
23 (with-open-file (f "output/dynamic-space-size.txt")
24 (let ((line (read-line f)))
25 (multiple-value-bind (number end)
26 (parse-integer line :junk-allowed t)
27 (when number
28 (let* ((ext (subseq line end))
29 (mult (cond ((or (zerop (length ext))
30 (member ext '("MB" "MIB") :test #'equalp))
31 (expt 2 20))
32 ((member ext '("GB" "GIB") :test #'equalp)
33 (expt 2 30))
35 (error "Invalid --dynamic-space-size=~A" line)))))
36 (* number mult)))))))
38 #!+gencgc
39 ;; Define START/END constants for GENCGC spaces.
40 ;; Assumptions:
41 ;; We only need very small read-only and static spaces, because
42 ;; gencgc does not purify any more. We can count on being able to
43 ;; allocate them with roughly the same size, and next to each other.
45 ;; There is one page of unmapped buffer between them for good measure.
47 ;; The linkage table (if enabled) can be treated the same way.
49 ;; Dynamic space traditionally sits elsewhere, so has its own
50 ;; parameter. But if not specified, it is allocated right after
51 ;; the other spaces (used on Windows/x86).
53 ;; The safepoint page (if enabled) is to be allocated immediately
54 ;; prior to static page. For x86(-64) this would not matter, because
55 ;; they can only reference it using an absolute fixup anyway, but
56 ;; for RISC platforms we can (and must) do better.
58 ;; The safepoint page needs to be small enough that the offset from
59 ;; static space is immediate, e.g. >= -2^12 for SPARC. #x1000 works
60 ;; for almost all platforms, but is too small to make VirtualProtect
61 ;; happy -- hence the need for an extra `alignment' configuration
62 ;; option below, which parms.lisp can set to #x10000 on Windows.
64 (defmacro !gencgc-space-setup
65 (small-spaces-start
66 &key ((:dynamic-space-start dynamic-space-start*))
67 ((:default-dynamic-space-size default-dynamic-space-size*))
68 #!+immobile-space (immobile-space-size (* 128 1024 1024))
69 #!+immobile-space (immobile-code-space-size (* 104 1024 1024))
70 ;; Smallest os_validate()able alignment; used as safepoint
71 ;; page size. Default suitable for POSIX platforms.
72 (alignment #x1000)
73 ;; traditional distance between spaces -- including the margin:
74 (small-space-spread #x100000)
75 ;; traditional margin between spaces
76 (margin-size #x1000))
77 (let* ((spaces '(read-only static
78 #!+linkage-table linkage-table
79 #!+immobile-space immobile))
80 (ptr small-spaces-start)
81 safepoint-address
82 (small-space-forms
83 (loop for (space next-space) on spaces appending
84 (let* ((next-start
85 (+ ptr (cond #!+immobile-space
86 ((eq space 'immobile)
87 ;; We subtract margin-size when
88 ;; computing FOO-SPACE-END,
89 ;; so add it in here to compensate.
90 (+ immobile-space-size margin-size))
92 small-space-spread))))
93 (end next-start))
94 (when (eq next-space 'static)
95 ;; margin becomes safepoint page; substract margin again.
96 (decf end alignment)
97 (setf safepoint-address end))
98 (prog1
99 `((defconstant ,(symbolicate space "-SPACE-START")
100 ,ptr)
101 (defconstant ,(symbolicate space "-SPACE-END")
102 ,(- end margin-size)))
103 (setf ptr next-start)))))
104 (safepoint-page-forms
105 (list #!+sb-safepoint
106 `(defconstant gc-safepoint-page-addr ,safepoint-address)))
108 #+ccl safepoint-address ; workaround for incorrect "Unused" warning
109 `(progn
110 ,@safepoint-page-forms
111 ,@small-space-forms
112 #!+immobile-space
113 (defconstant immobile-fixedobj-subspace-size
114 ,(- immobile-space-size immobile-code-space-size))
115 (defconstant default-dynamic-space-start ,(or dynamic-space-start* ptr))
116 #!-relocatable-heap (defconstant dynamic-space-start default-dynamic-space-start)
117 (defconstant default-dynamic-space-size
118 (or ,(!read-dynamic-space-size)
119 ,default-dynamic-space-size*
120 (ecase n-word-bits
121 (32 (expt 2 29))
122 (64 (expt 2 30))))))))
124 (defconstant-eqx +c-callable-fdefns+
125 '(sub-gc
126 sb!kernel::post-gc
127 internal-error
128 sb!kernel::control-stack-exhausted-error
129 sb!kernel::binding-stack-exhausted-error
130 sb!kernel::alien-stack-exhausted-error
131 sb!kernel::heap-exhausted-error
132 sb!kernel::undefined-alien-variable-error
133 sb!kernel::memory-fault-error
134 sb!kernel::unhandled-trap-error
135 ;; On these it's called through the internal errors mechanism
136 #!-(or arm arm64 x86-64) undefined-alien-fun-error
137 sb!di::handle-breakpoint
138 sb!di::handle-single-step-trap
139 #!+win32 sb!kernel::handle-win32-exception
140 #!+sb-thruption sb!thread::run-interruption
141 enter-alien-callback
142 #!+sb-thread sb!thread::enter-foreign-callback
143 #!+(and sb-safepoint-strictly (not win32))
144 sb!unix::signal-handler-callback)
145 #'equal)
147 (defconstant-eqx +common-static-symbols+
149 #!+immobile-space *immobile-freelist*
151 ;; things needed for non-local-exit
152 *current-catch-block*
153 *current-unwind-protect-block*
155 #!+hpux *c-lra*
157 ;; stack pointers
158 *binding-stack-start*
159 *control-stack-start*
160 *control-stack-end*
162 ;; interrupt handling
163 *alloc-signal*
164 *free-interrupt-context-index*
165 sb!unix::*allow-with-interrupts*
166 sb!unix::*interrupts-enabled*
167 sb!unix::*interrupt-pending*
168 #!+sb-thruption sb!unix::*thruption-pending*
169 #!+sb-thruption sb!impl::*restart-clusters*
170 *in-without-gcing*
171 *gc-inhibit*
172 *gc-pending*
173 #!-sb-thread
174 *stepping*
175 #!+sb-safepoint sb!impl::*gc-safe*
176 #!+sb-safepoint sb!impl::*in-safepoint*
178 ;; threading support
179 #!+sb-thread *stop-for-gc-pending*
180 #!+sb-thread *free-tls-index*
181 ;; Keep in sync with 'compiler/early-backend.lisp':
182 ;; "only PPC uses a separate symbol for the TLS index lock"
183 #!+(and sb-thread ppc) *tls-index-lock*
185 ;; dynamic runtime linking support
186 #!+sb-dynamic-core +required-runtime-c-symbols+
188 ;; non-x86oid gencgc object pinning
189 #!+(and gencgc (not (or x86 x86-64)))
190 *pinned-objects*
192 ;; for looking up assembler routine by name
193 ;; and patching them on runtime startup
194 sb!fasl::*assembler-routines*
196 ;;; The following symbols aren't strictly required to be static
197 ;;; - they are not accessed from C - but we make them static in order
198 ;;; to (perhaps) micro-optimize access in Lisp.
199 ;;; However there is no efficiency gain if we have #!+immobile-space.
200 #!-immobile-space ,@'(
201 ;; arbitrary object that changes after each GC
202 sb!kernel::*gc-epoch*
203 ;; Dispatch tables for generic array access
204 sb!impl::%%data-vector-reffers%%
205 sb!impl::%%data-vector-reffers/check-bounds%%
206 sb!impl::%%data-vector-setters%%
207 sb!impl::%%data-vector-setters/check-bounds%%))
208 #'equalp)
210 ;;; Number of entries in the thread local storage. Limits the number
211 ;;; of symbols with thread local bindings.
212 (defconstant tls-size 4096)
213 ;;; Refer to the lengthy comment in 'src/runtime/interrupt.h' about
214 ;;; the choice of this number. Rather than have to two copies
215 ;;; of the comment, please see that file before adjusting this.
216 (defconstant max-interrupts 1024)
218 #!+gencgc
219 (progn
220 (defconstant +highest-normal-generation+ 5)
221 (defconstant +pseudo-static-generation+ 6))
223 (defun !unintern-symbols ()
224 '("SB-VM"
225 +c-callable-fdefns+
226 +common-static-symbols+))