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
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.
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" :if-does-not-exist nil
)
25 (return-from !read-dynamic-space-size nil
))
26 (let ((line (read-line f
)))
27 (multiple-value-bind (number end
)
28 (parse-integer line
:junk-allowed t
)
30 (let* ((ext (subseq line end
))
31 (mult (cond ((or (zerop (length ext
))
32 (member ext
'("MB" "MIB") :test
#'equalp
))
34 ((member ext
'("GB" "GIB") :test
#'equalp
)
37 (error "Invalid --dynamic-space-size=~A" line
)))))
41 ;; Define START/END constants for GENCGC spaces.
43 ;; We only need very small read-only and static spaces, because
44 ;; gencgc does not purify any more. We can count on being able to
45 ;; allocate them with roughly the same size, and next to each other.
47 ;; There is one page of unmapped buffer between them for good measure.
49 ;; The linkage table (if enabled) can be treated the same way.
51 ;; Dynamic space traditionally sits elsewhere, so has its own
52 ;; parameter. But if not specified, it is allocated right after
53 ;; the other spaces (used on Windows/x86).
55 ;; The safepoint page (if enabled) is to be allocated immediately
56 ;; prior to static page. For x86(-64) this would not matter, because
57 ;; they can only reference it using an absolute fixup anyway, but
58 ;; for RISC platforms we can (and must) do better.
60 ;; The safepoint page needs to be small enough that the offset from
61 ;; static space is immediate, e.g. >= -2^12 for SPARC. #x1000 works
62 ;; for almost all platforms, but is too small to make VirtualProtect
63 ;; happy -- hence the need for an extra `alignment' configuration
64 ;; option below, which parms.lisp can set to #x10000 on Windows.
65 ;; To clarify: there is a gap at the end of read-only space to
66 ;; the safepoint page, but no gap at the end of the latter
67 ;; to the start of static space. (What do these gaps achieve?)
69 (defmacro !gencgc-space-setup
71 &key
((:dynamic-space-start dynamic-space-start
*))
72 ((:dynamic-space-size dynamic-space-size
*))
73 ;; The immobile-space START parameters should not be used
74 ;; except in forcing discontiguous addresses for testing.
75 ;; And of course, don't use them if unsupported.
76 ((:fixedobj-space-start fixedobj-space-start
*))
77 ((:fixedobj-space-size fixedobj-space-size
*) (* 24 1024 1024))
78 ((:varyobj-space-start varyobj-space-start
*))
79 ((:varyobj-space-size varyobj-space-size
*) (* 104 1024 1024))
80 ;; Smallest os_validate()able alignment; used as safepoint
81 ;; page size. Default suitable for POSIX platforms.
83 ;; traditional distance between spaces -- including the margin:
84 (small-space-spread #x100000
)
85 ;; traditional margin between spaces
87 (declare (ignorable dynamic-space-start
*)) ; might be unused in make-host-2
88 (flet ((defconstantish (relocatable symbol value
)
89 (if (not relocatable
) ; easy case
90 `(defconstant ,symbol
,value
)
91 ;; Genesis needs to know the gspace start, but it's not constant.
92 ;; This value will not be exposed to C code.
93 #+sb-xc-host
`(defparameter ,symbol
,value
)
94 ;; Ideally the #-sb-xc-host code be a DEFINE-ALIEN-VARIABLE,
95 ;; but can't be due to dependency order problem.
98 ((spaces (append `((read-only .
,small-space-spread
)
99 (static .
,small-space-spread
))
101 `((linkage-table .
,small-space-spread
))
103 `((fixedobj .
,fixedobj-space-size
*)
104 (varyobj .
,varyobj-space-size
*))))
105 (ptr small-spaces-start
)
108 (loop for
(space . size
) in spaces appending
110 ;; TODO: linkage-table could move with code, if the CPU
111 ;; prefers PC-relative jumps, and we emit better code
112 ;; (which we don't- for x86 we jmp via RBX always)
113 #!+relocatable-heap
(member space
'(fixedobj varyobj
)))
117 (when (eq space
'read-only
)
118 ;; margin becomes safepoint page; substract margin again.
120 (setf safepoint-address end
))
121 (let ((start-sym (symbolicate space
"-SPACE-START")))
122 ;; Allow expressly given addresses / sizes for immobile space.
123 ;; The addresses are for testing only - you should not need them.
125 (varyobj (setq start
(or varyobj-space-start
* start
)
126 end
(+ start varyobj-space-size
*)))
127 (fixedobj (setq start
(or fixedobj-space-start
* start
)
128 end
(+ start fixedobj-space-size
*)))
129 (t (setq end
(- end margin-size
))))
130 `(,(defconstantish relocatable start-sym start
)
132 `(defconstant ,(symbolicate space
"-SPACE-SIZE") ,(- end start
))
133 `(defconstant ,(symbolicate space
"-SPACE-END") ,end
)))))))
134 (safepoint-page-forms
135 (list #!+sb-safepoint
136 `(defconstant gc-safepoint-page-addr
,safepoint-address
)))
138 ;; CCL warns about a variable that is assigned but never read.
139 ;; That's actually reasonable. We consider it used, as do others.
140 safepoint-address
; "use" it here just to be sure it's used
142 ,@safepoint-page-forms
144 ,(defconstantish (or #!+relocatable-heap t
) 'dynamic-space-start
145 (or dynamic-space-start
* ptr
))
146 (defconstant default-dynamic-space-size
147 ;; Build-time make-config.sh option "--dynamic-space-size" overrides
148 ;; keyword argument :dynamic-space-size which overrides general default.
149 ;; All are overridden by runtime --dynamic-space-size command-line arg.
150 (or ,(or (!read-dynamic-space-size
) dynamic-space-size
*)
153 (64 (expt 2 30)))))))))
155 (defconstant-eqx +c-callable-fdefns
+
159 sb
!kernel
::control-stack-exhausted-error
160 sb
!kernel
::binding-stack-exhausted-error
161 sb
!kernel
::alien-stack-exhausted-error
162 sb
!kernel
::heap-exhausted-error
163 sb
!kernel
::undefined-alien-variable-error
164 sb
!kernel
::memory-fault-error
165 sb
!kernel
::unhandled-trap-error
166 ;; On these it's called through the internal errors mechanism
167 #!-
(or arm arm64 x86-64
) undefined-alien-fun-error
168 sb
!di
::handle-breakpoint
169 sb
!di
::handle-single-step-trap
170 #!+win32 sb
!kernel
::handle-win32-exception
171 #!+sb-thruption sb
!thread
::run-interruption
173 #!+sb-thread sb
!thread
::enter-foreign-callback
174 #!+(and sb-safepoint-strictly
(not win32
))
175 sb
!unix
::signal-handler-callback
)
178 ;;; Static symbols that C code must be able to assign to,
179 ;;; as contrasted with static for other reasons such as:
180 ;;; - garbage collections roots (namely NIL)
181 ;;; - other symbols that Lisp codegen must hardwire (T)
182 ;;; - static for efficiency of access but need not be
183 (defconstant-eqx !per-thread-c-interface-symbols
184 `((*free-interrupt-context-index
* 0)
185 (sb!sys
:*allow-with-interrupts
* t
)
186 (sb!sys
:*interrupts-enabled
* t
)
188 sb
!sys
:*interrupt-pending
*
189 #!+sb-thruption sb
!sys
:*thruption-pending
*
190 #!+sb-thruption sb
!kernel
:*restart-clusters
*
194 #!+sb-safepoint sb
!impl
::*gc-safe
*
195 #!+sb-safepoint sb
!impl
::*in-safepoint
*
196 #!+sb-thread
*stop-for-gc-pending
*
197 ;; non-x86oid gencgc object pinning
198 #!+(and gencgc
(not (or x86 x86-64
))) *pinned-objects
*
199 ;; things needed for non-local-exit
200 (*current-catch-block
* 0)
201 (*current-unwind-protect-block
* 0)
205 (defconstant-eqx +common-static-symbols
+
207 ;; These symbols are accessed from C only through TLS,
208 ;; never the symbol-value slot
209 #!-sb-thread
,@(mapcar (lambda (x) (car (ensure-list x
)))
210 !per-thread-c-interface-symbols
)
211 ;; NLX variables are thread slots on x86-64. A static sym is needed
212 ;; for arm64, ppc, and x86 because we haven't implemented TLS index fixups,
213 ;; so must lookup the TLS index given the symbol.
214 #!+(and sb-thread
(not x86-64
)) ,@'(*current-catch-block
*
215 *current-unwind-protect-block
*)
217 ;; sb-safepoint in addition to accessing this symbol via TLS,
218 ;; uses the symbol itself as a value. Kinda weird.
219 #!+sb-safepoint
*in-without-gcing
*
221 #!+immobile-space
*immobile-freelist
* ; not per-thread (yet...)
226 #!-sb-thread
*binding-stack-start
* ; a thread slot if #!+sb-thread
227 #!-sb-thread
*control-stack-start
* ; ditto
228 #!-sb-thread
*control-stack-end
* ; ditto
230 #!-sb-thread
*stepping
*
233 #!+sb-thread
*free-tls-index
*
234 ;; Keep in sync with 'compiler/early-backend.lisp':
235 ;; "only PPC uses a separate symbol for the TLS index lock"
236 #!+(and sb-thread ppc
) *tls-index-lock
*
237 ;; memory sanitizer argument-passing shadow bytes
240 ;; dynamic runtime linking support
241 #!+sb-dynamic-core
+required-foreign-symbols
+
243 ;; for looking up assembler routine by name
244 ;; and patching them on runtime startup
245 sb
!fasl
::*assembler-routines
*
247 ;; List of Lisp specials bindings made by create_thread_struct()
248 ;; other than the per-thread-c-interface-symbols.
249 sb
!thread
::*thread-initial-bindings
*
251 ;;; The following symbols aren't strictly required to be static
252 ;;; - they are not accessed from C - but we make them static in order
253 ;;; to (perhaps) micro-optimize access in Lisp.
254 ;;; However there is no efficiency gain if we have #!+immobile-space.
255 #!-immobile-space
,@'(
256 ;; arbitrary object that changes after each GC
257 sb
!kernel
::*gc-epoch
*
258 ;; Dispatch tables for generic array access
259 sb
!impl
::%%data-vector-reffers%%
260 sb
!impl
::%%data-vector-reffers
/check-bounds%%
261 sb
!impl
::%%data-vector-setters%%
262 sb
!impl
::%%data-vector-setters
/check-bounds%%
))
265 ;;; Number of entries in the thread local storage. Limits the number
266 ;;; of symbols with thread local bindings.
267 (defconstant tls-size
4096)
268 ;;; Refer to the lengthy comment in 'src/runtime/interrupt.h' about
269 ;;; the choice of this number. Rather than have to two copies
270 ;;; of the comment, please see that file before adjusting this.
271 (defconstant max-interrupts
1024)
275 (defconstant +highest-normal-generation
+ 5)
276 (defconstant +pseudo-static-generation
+ 6))
278 (defun !unintern-symbols
()
281 +common-static-symbols
+))