Safepoint protocol upgrade
[sbcl.git] / src / compiler / generic / parms.lisp
1 ;;;; This file contains some parameterizations of various VM
2 ;;;; attributes common to all architectures.
3
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.
12
13 (in-package "SB!VM")
14
15 (def!macro !configure-dynamic-space-end (&optional default)
16   (with-open-file (f "output/dynamic-space-size.txt")
17     (let ((line (read-line f)))
18       (multiple-value-bind (number end)
19           (parse-integer line :junk-allowed t)
20         (if number
21             (let* ((ext (subseq line end))
22                    (mult (cond ((or (zerop (length ext))
23                                     (member ext '("MB MIB") :test #'equalp))
24                                 (expt 2 20))
25                                ((member ext '("GB" "GIB") :test #'equalp)
26                                 (expt 2 30))
27                                (t
28                                 (error "Invalid --dynamic-space-size=~A" line)))))
29               `(+ dynamic-space-start ,(* number mult)))
30             (or default
31                 `(+ dynamic-space-start
32                     (ecase n-word-bits
33                       (32 (expt 2 29))
34                       (64 (expt 2 30))))))))))
35
36 #!+gencgc
37 ;; Define START/END constants for GENCGC spaces.
38 ;; Assumptions:
39 ;;     We only need very small read-only and static spaces, because
40 ;;     gencgc does not purify any more.  We can count on being able to
41 ;;     allocate them with roughly the same size, and next to each other.
42 ;;
43 ;;     There is one page of unmapped buffer between them for good measure.
44 ;;
45 ;;     The linkage table (if enabled) can be treated the same way.
46 ;;
47 ;;     Dynamic space traditionally sits elsewhere, so has its own
48 ;;     parameter.  But if not specified, it is allocated right after
49 ;;     the other spaces (used on Windows/x86).
50 ;;
51 ;;     The safepoint page (if enabled) is to be allocated immediately
52 ;;     prior to static page.  For x86(-64) this would not matter, because
53 ;;     they can only reference it using an absolute fixup anyway, but
54 ;;     for RISC platforms we can (and must) do better.
55 ;;
56 ;;     The safepoint page needs to be small enough that the offset from
57 ;;     static space is immediate, e.g. >= -2^12 for SPARC.  #x1000 works
58 ;;     for almost all platforms, but is too small to make VirtualProtect
59 ;;     happy -- hence the need for an extra `alignment' configuration
60 ;;     option below, which parms.lisp can set to #x10000 on Windows.
61 ;;
62 ;; Cosmetic problem:
63 ;;
64 ;;     In the interest of readability, &KEY would be much nicer than
65 ;;     &OPTIONAL.  But is it possible to use keyword arguments to
66 ;;     DEF!MACRO?
67 ;;
68 (def!macro !gencgc-space-setup
69     (small-spaces-start
70      &optional dynamic-space-start*
71                default-dynamic-space-size
72                ;; Smallest os_validate()able alignment; used as safepoint
73                ;; page size.  Default suitable for POSIX platforms.
74                (alignment            #x1000)
75                ;; traditional distance between spaces -- including the margin:
76                (small-space-spread #x100000)
77                ;; traditional margin between spaces
78                (margin-size          #x1000))
79   (let* ((spaces '(read-only static #!+linkage-table linkage-table))
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 (+ ptr small-space-spread))
85                        (end next-start))
86                   (when (eq next-space 'static)
87                     ;; margin becomes safepoint page; substract margin again.
88                     (decf end alignment)
89                     (setf safepoint-address end))
90                   (prog1
91                       `((def!constant ,(symbolicate space "-SPACE-START")
92                             ,ptr)
93                         (def!constant ,(symbolicate space "-SPACE-END")
94                             ,(- end margin-size)))
95                     (setf ptr next-start)))))
96          (safepoint-page-forms
97           (list #!+sb-safepoint
98                 `(def!constant gc-safepoint-page-addr ,safepoint-address)))
99          (dynamic-space-start* (or dynamic-space-start* ptr))
100          (optional-dynamic-space-end
101           (when default-dynamic-space-size
102             (list (+ dynamic-space-start* default-dynamic-space-size)))))
103     `(progn
104        ,@safepoint-page-forms
105        ,@small-space-forms
106        (def!constant dynamic-space-start ,dynamic-space-start*)
107        (def!constant dynamic-space-end (!configure-dynamic-space-end
108                                         ,@optional-dynamic-space-end)))))
109
110 (defparameter *c-callable-static-symbols*
111   '(sub-gc
112     sb!kernel::post-gc
113     sb!kernel::internal-error
114     sb!kernel::control-stack-exhausted-error
115     sb!kernel::binding-stack-exhausted-error
116     sb!kernel::alien-stack-exhausted-error
117     sb!kernel::heap-exhausted-error
118     sb!kernel::undefined-alien-variable-error
119     sb!kernel::undefined-alien-function-error
120     sb!kernel::memory-fault-error
121     sb!kernel::unhandled-trap-error
122     sb!di::handle-breakpoint
123     sb!di::handle-single-step-trap
124     fdefinition-object
125     #!+win32 sb!kernel::handle-win32-exception
126     #!+sb-thruption sb!thread::run-interruption))
127
128 (defparameter *common-static-symbols*
129   '(t
130
131     ;; filled in by the C code to propagate to Lisp
132     *posix-argv* *core-string*
133
134     ;; free pointers.  Note that these are FIXNUM word counts, not (as
135     ;; one might expect) byte counts or SAPs. The reason seems to be
136     ;; that by representing them this way, we can avoid consing
137     ;; bignums.  -- WHN 2000-10-02
138     *read-only-space-free-pointer*
139     *static-space-free-pointer*
140
141     ;; things needed for non-local-exit
142     *current-catch-block*
143     *current-unwind-protect-block*
144
145     #!+hpux *c-lra*
146
147     ;; stack pointers
148     *binding-stack-start*
149     *control-stack-start*
150     *control-stack-end*
151
152     ;; interrupt handling
153     *alloc-signal*
154     *free-interrupt-context-index*
155     sb!unix::*allow-with-interrupts*
156     sb!unix::*interrupts-enabled*
157     sb!unix::*interrupt-pending*
158     #!+sb-thruption sb!unix::*thruption-pending*
159     #!+sb-thruption sb!impl::*restart-clusters*
160     sb!vm::*in-without-gcing*
161     *gc-inhibit*
162     *gc-pending*
163     #!-sb-thread
164     *stepping*
165     #!+sb-safepoint sb!impl::*gc-safe*
166     #!+sb-safepoint sb!impl::*in-safepoint*
167
168     ;; threading support
169     #!+sb-thread *stop-for-gc-pending*
170     #!+sb-thread *free-tls-index*
171     #!+sb-thread *tls-index-lock*
172
173     ;; dynamic runtime linking support
174     #!+sb-dynamic-core *required-runtime-c-symbols*
175     sb!kernel::*gc-epoch*
176
177     ;; Dispatch tables for generic array access
178     sb!impl::%%data-vector-reffers%%
179     sb!impl::%%data-vector-reffers/check-bounds%%
180     sb!impl::%%data-vector-setters%%
181     sb!impl::%%data-vector-setters/check-bounds%%
182
183     ;; non-x86oid gencgc object pinning
184     #!+(and gencgc (not (or x86 x86-64)))
185     *pinned-objects*
186
187     ;; hash table weaknesses
188     :key
189     :value
190     :key-and-value
191     :key-or-value))
192
193 ;;; Number of entries in the thread local storage. Limits the number
194 ;;; of symbols with thread local bindings.
195 (def!constant tls-size 4096)
196
197 #!+gencgc
198 (progn
199   (def!constant +highest-normal-generation+ 5)
200   (def!constant +pseudo-static-generation+ 6))
201
202 (defenum ()
203   trace-table-normal
204   trace-table-call-site
205   trace-table-fun-prologue
206   trace-table-fun-epilogue)