1 ;;;; machine-independent aspects of the object representation
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 ;;;; KLUDGE: The primitive objects here may look like self-contained
15 ;;;; definitions, but in general they're not. In particular, if you
16 ;;;; try to add a slot to them, beware of the following:
17 ;;;; * (mysterious crashes which occur after changing the length
18 ;;;; of SIMPLE-FUN, just adding a new slot not even doing anything
19 ;;;; with it, still dunno why)
20 ;;;; * The GC scavenging code (and for all I know other GC code too)
21 ;;;; is not automatically generated from these layouts, but instead
22 ;;;; was hand-written to correspond to them. The offsets are
23 ;;;; automatically propagated into the GC scavenging code, but the
24 ;;;; existence of slots, and whether they should be scavenged, is
25 ;;;; not automatically propagated. Thus e.g. if you add a
26 ;;;; SIMPLE-FUN-DEBUG-INFO slot holding a tagged object which needs
27 ;;;; to be GCed, you need to tweak scav_code_header() and
28 ;;;; verify_space() in gencgc.c, and the corresponding code in gc.c.
29 ;;;; * The src/runtime/print.c code (used by LDB) is implemented
30 ;;;; using hand-written lists of slot names, which aren't automatically
31 ;;;; generated from the code in this file.
32 ;;;; * Various code (e.g. STATIC-FSET in genesis.lisp) is hard-wired
33 ;;;; to know the name of the last slot of the object the code works
34 ;;;; with, and implicitly to know that the last slot is special (being
35 ;;;; the beginning of an arbitrary-length sequence of bytes following
36 ;;;; the fixed-layout slots).
37 ;;;; -- WHN 2001-12-29
39 ;;;; the primitive objects themselves
41 (define-primitive-object (cons :lowtag list-pointer-lowtag
43 (car :ref-trans car :set-trans sb!c::%rplaca :init :arg
44 :cas-trans %compare-and-swap-car)
45 (cdr :ref-trans cdr :set-trans sb!c::%rplacd :init :arg
46 :cas-trans %compare-and-swap-cdr))
48 (define-primitive-object (instance :lowtag instance-pointer-lowtag
49 :widetag instance-header-widetag
50 :alloc-trans %make-instance)
53 (define-primitive-object (bignum :lowtag other-pointer-lowtag
54 :widetag bignum-widetag
55 :alloc-trans sb!bignum::%allocate-bignum)
56 (digits :rest-p t :c-type #!-alpha "long" #!+alpha "u32"))
58 (define-primitive-object (ratio :type ratio
59 :lowtag other-pointer-lowtag
60 :widetag ratio-widetag
61 :alloc-trans %make-ratio)
62 (numerator :type integer
63 :ref-known (flushable movable)
66 (denominator :type integer
67 :ref-known (flushable movable)
68 :ref-trans %denominator
71 #!+#.(cl:if (cl:= sb!vm:n-word-bits 32) '(and) '(or))
72 (define-primitive-object (single-float :lowtag other-pointer-lowtag
73 :widetag single-float-widetag)
74 (value :c-type "float"))
76 (define-primitive-object (double-float :lowtag other-pointer-lowtag
77 :widetag double-float-widetag)
79 (value :c-type "double" :length #!-x86-64 2 #!+x86-64 1))
82 (define-primitive-object (long-float :lowtag other-pointer-lowtag
83 :widetag long-float-widetag)
85 (value :c-type "long double" :length #!+x86 3 #!+sparc 4))
87 (define-primitive-object (complex :type complex
88 :lowtag other-pointer-lowtag
89 :widetag complex-widetag
90 :alloc-trans %make-complex)
92 :ref-known (flushable movable)
96 :ref-known (flushable movable)
100 (define-primitive-object (array :lowtag other-pointer-lowtag
102 ;; FILL-POINTER of an ARRAY is in the same place as LENGTH of a
103 ;; VECTOR -- see SHRINK-VECTOR.
104 (fill-pointer :type index
105 :ref-trans %array-fill-pointer
106 :ref-known (flushable foldable)
107 :set-trans (setf %array-fill-pointer)
109 (fill-pointer-p :type (member t nil)
110 :ref-trans %array-fill-pointer-p
111 :ref-known (flushable foldable)
112 :set-trans (setf %array-fill-pointer-p)
114 (elements :type index
115 :ref-trans %array-available-elements
116 :ref-known (flushable foldable)
117 :set-trans (setf %array-available-elements)
120 :ref-trans %array-data-vector
121 :ref-known (flushable foldable)
122 :set-trans (setf %array-data-vector)
124 (displacement :type (or index null)
125 :ref-trans %array-displacement
126 :ref-known (flushable foldable)
127 :set-trans (setf %array-displacement)
130 :ref-trans %array-displaced-p
131 :ref-known (flushable foldable)
132 :set-trans (setf %array-displaced-p)
134 (displaced-from :type list
135 :ref-trans %array-displaced-from
136 :ref-known (flushable)
137 :set-trans (setf %array-displaced-from)
139 (dimensions :rest-p t))
141 (define-primitive-object (vector :type vector
142 :lowtag other-pointer-lowtag
144 ;; FILL-POINTER of an ARRAY is in the same place as LENGTH of a
145 ;; VECTOR -- see SHRINK-VECTOR.
146 (length :ref-trans sb!c::vector-length
148 (data :rest-p t :c-type #!-alpha "unsigned long" #!+alpha "u32"))
150 (define-primitive-object (code :type code-component
151 :lowtag other-pointer-lowtag
153 (code-size :type index
154 :ref-known (flushable movable)
155 :ref-trans %code-code-size)
156 (entry-points :type (or function null)
157 :ref-known (flushable)
158 :ref-trans %code-entry-points
160 :set-trans (setf %code-entry-points))
162 :ref-known (flushable)
163 :ref-trans %code-debug-info
165 :set-trans (setf %code-debug-info))
167 (constants :rest-p t))
169 (define-primitive-object (fdefn :type fdefn
170 :lowtag other-pointer-lowtag
171 :widetag fdefn-widetag)
172 (name :ref-trans fdefn-name)
173 (fun :type (or function null) :ref-trans fdefn-fun)
174 (raw-addr :c-type #!-alpha "char *" #!+alpha "u32"))
176 ;;; a simple function (as opposed to hairier things like closures
177 ;;; which are also subtypes of Common Lisp's FUNCTION type)
178 (define-primitive-object (simple-fun :type function
179 :lowtag fun-pointer-lowtag
180 :widetag simple-fun-header-widetag)
181 #!-(or x86 x86-64) (self :ref-trans %simple-fun-self
182 :set-trans (setf %simple-fun-self))
183 #!+(or x86 x86-64) (self
184 ;; KLUDGE: There's no :SET-KNOWN, :SET-TRANS, :REF-KNOWN, or
185 ;; :REF-TRANS here in this case. Instead, there's separate
186 ;; DEFKNOWN/DEFINE-VOP/DEFTRANSFORM stuff in
187 ;; compiler/x86/system.lisp to define and declare them by
188 ;; hand. I don't know why this is, but that's (basically)
189 ;; the way it was done in CMU CL, and it works. (It's not
190 ;; exactly the same way it was done in CMU CL in that CMU
191 ;; CL's allows duplicate DEFKNOWNs, blithely overwriting any
192 ;; previous data associated with the previous DEFKNOWN, and
193 ;; that property was used to mask the definitions here. In
194 ;; SBCL as of 0.6.12.64 that's not allowed -- too confusing!
195 ;; -- so we have to explicitly suppress the DEFKNOWNish
196 ;; stuff here in order to allow this old hack to work in the
197 ;; new world. -- WHN 2001-08-82
199 (next :type (or function null)
200 :ref-known (flushable)
201 :ref-trans %simple-fun-next
203 :set-trans (setf %simple-fun-next))
204 (name :ref-known (flushable)
205 :ref-trans %simple-fun-name
207 :set-trans (setf %simple-fun-name))
209 :ref-known (flushable)
210 :ref-trans %simple-fun-arglist
212 :set-trans (setf %simple-fun-arglist))
213 (type :ref-known (flushable)
214 :ref-trans %simple-fun-type
216 :set-trans (setf %simple-fun-type))
218 :ref-trans %simple-fun-xrefs
219 :ref-known (flushable)
220 :set-trans (setf %simple-fun-xrefs)
222 ;; the SB!C::DEBUG-FUN object corresponding to this object, or NIL for none
223 #+nil ; FIXME: doesn't work (gotcha, lowly maintenoid!) See notes on bug 137.
224 (debug-fun :ref-known (flushable)
225 :ref-trans %simple-fun-debug-fun
227 :set-trans (setf %simple-fun-debug-fun))
228 (code :rest-p t :c-type "unsigned char"))
230 (define-primitive-object (return-pc :lowtag other-pointer-lowtag :widetag t)
231 (return-point :c-type "unsigned char" :rest-p t))
233 (define-primitive-object (closure :lowtag fun-pointer-lowtag
234 :widetag closure-header-widetag)
235 (fun :init :arg :ref-trans %closure-fun)
238 (define-primitive-object (funcallable-instance
239 :lowtag fun-pointer-lowtag
240 :widetag funcallable-instance-header-widetag
241 :alloc-trans %make-funcallable-instance)
242 (trampoline :init :funcallable-instance-tramp)
243 (function :ref-known (flushable) :ref-trans %funcallable-instance-function
244 :set-known (unsafe) :set-trans (setf %funcallable-instance-function))
247 (define-primitive-object (value-cell :lowtag other-pointer-lowtag
248 :widetag value-cell-header-widetag
249 ;; FIXME: We also have an explicit VOP
250 ;; for this. Is this needed as well?
251 :alloc-trans make-value-cell)
252 (value :set-trans value-cell-set
254 :ref-trans value-cell-ref
255 :ref-known (flushable)
259 (define-primitive-object (sap :lowtag other-pointer-lowtag
260 :widetag sap-widetag)
262 (pointer :c-type "char *" :length 2))
265 (define-primitive-object (sap :lowtag other-pointer-lowtag
266 :widetag sap-widetag)
267 (pointer :c-type "char *"))
270 (define-primitive-object (weak-pointer :type weak-pointer
271 :lowtag other-pointer-lowtag
272 :widetag weak-pointer-widetag
273 :alloc-trans make-weak-pointer)
274 (value :ref-trans sb!c::%weak-pointer-value :ref-known (flushable)
276 (broken :type (member t nil)
277 :ref-trans sb!c::%weak-pointer-broken :ref-known (flushable)
279 (next :c-type #!-alpha "struct weak_pointer *" #!+alpha "u32"))
281 ;;;; other non-heap data blocks
283 (define-primitive-object (binding)
287 (define-primitive-object (unwind-block)
288 (current-uwp :c-type #!-alpha "struct unwind_block *" #!+alpha "u32")
289 (current-cont :c-type #!-alpha "lispobj *" #!+alpha "u32")
290 #!-(or x86 x86-64) current-code
292 #!+win32 next-seh-frame
293 #!+win32 seh-frame-handler)
295 (define-primitive-object (catch-block)
296 (current-uwp :c-type #!-alpha "struct unwind_block *" #!+alpha "u32")
297 (current-cont :c-type #!-alpha "lispobj *" #!+alpha "u32")
298 #!-(or x86 x86-64) current-code
300 #!+win32 next-seh-frame
301 #!+win32 seh-frame-handler
303 (previous-catch :c-type #!-alpha "struct catch_block *" #!+alpha "u32"))
305 ;;; (For an explanation of this, see the comments at the definition of
306 ;;; KLUDGE-NONDETERMINISTIC-CATCH-BLOCK-SIZE.)
307 (aver (= kludge-nondeterministic-catch-block-size catch-block-size))
311 (define-primitive-object (symbol :lowtag other-pointer-lowtag
312 :widetag symbol-header-widetag
313 :alloc-trans %make-symbol)
315 ;; Beware when changing this definition. NIL-the-symbol is defined
316 ;; using this layout, and NIL-the-end-of-list-marker is the cons
317 ;; ( NIL . NIL ), living in the first two slots of NIL-the-symbol
318 ;; (conses have no header). Careful selection of lowtags ensures
319 ;; that the same pointer can be used for both purposes:
320 ;; OTHER-POINTER-LOWTAG is 7, LIST-POINTER-LOWTAG is 3, so if you
321 ;; subtract 3 from (SB-KERNEL:GET-LISP-OBJ-ADDRESS 'NIL) you get the
322 ;; first data slot, and if you subtract 7 you get a symbol header.
324 ;; also the CAR of NIL-as-end-of-list
325 (value :init :unbound
326 :set-trans %set-symbol-global-value
328 ;; also the CDR of NIL-as-end-of-list. Its reffer needs special
329 ;; care for this reason, as hash values must be fixnums.
330 (hash :set-trans %set-symbol-hash)
332 (plist :ref-trans symbol-plist
333 :set-trans %set-symbol-plist
334 :cas-trans %compare-and-swap-symbol-plist
337 (name :ref-trans symbol-name :init :arg)
338 (package :ref-trans symbol-package
339 :set-trans %set-symbol-package
341 #!+sb-thread (tls-index :ref-known (flushable) :ref-trans symbol-tls-index))
343 (define-primitive-object (complex-single-float
344 :lowtag other-pointer-lowtag
345 :widetag complex-single-float-widetag)
346 (real :c-type "float")
347 (imag :c-type "float"))
349 (define-primitive-object (complex-double-float
350 :lowtag other-pointer-lowtag
351 :widetag complex-double-float-widetag)
353 (real :c-type "double" :length #!-x86-64 2 #!+x86-64 1)
354 (imag :c-type "double" :length #!-x86-64 2 #!+x86-64 1))
356 #!+(and sb-lutex sb-thread)
357 (define-primitive-object (lutex
358 :lowtag other-pointer-lowtag
359 :widetag lutex-widetag
360 :alloc-trans %make-lutex)
361 (gen :c-type "long" :length 1)
362 (live :c-type "long" :length 1)
363 (next :c-type "struct lutex *" :length 1)
364 (prev :c-type "struct lutex *" :length 1)
365 (mutex :c-type "pthread_mutex_t *"
367 (mutexattr :c-type "pthread_mutexattr_t *"
369 (condition-variable :c-type "pthread_cond_t *"
372 ;;; this isn't actually a lisp object at all, it's a c structure that lives
373 ;;; in c-land. However, we need sight of so many parts of it from Lisp that
374 ;;; it makes sense to define it here anyway, so that the GENESIS machinery
375 ;;; can take care of maintaining Lisp and C versions.
376 ;;; Hence the even-fixnum lowtag just so we don't get odd(sic) numbers
377 ;;; added to the slot offsets
378 (define-primitive-object (thread :lowtag even-fixnum-lowtag)
379 ;; no_tls_value_marker is borrowed very briefly at thread startup to
380 ;; pass the address of initial-function into new_thread_trampoline.
381 ;; tls[0] = NO_TLS_VALUE_MARKER_WIDETAG because a the tls index slot
382 ;; of a symbol is initialized to zero
383 (no-tls-value-marker)
384 (os-thread :c-type "os_thread_t")
385 ;; This is the original address at which the memory was allocated,
386 ;; which may have different alignment then what we prefer to use.
387 ;; Kept here so that when the thread dies we can release the whole
388 ;; memory we reserved.
389 (os-address :c-type "void *" :length #!+alpha 2 #!-alpha 1)
391 (os-attr :c-type "pthread_attr_t *" :length #!+alpha 2 #!-alpha 1)
393 (state-lock :c-type "pthread_mutex_t *" :length #!+alpha 2 #!-alpha 1)
395 (state-cond :c-type "pthread_cond_t *" :length #!+alpha 2 #!-alpha 1)
396 (binding-stack-start :c-type "lispobj *" :length #!+alpha 2 #!-alpha 1)
397 (binding-stack-pointer :c-type "lispobj *" :length #!+alpha 2 #!-alpha 1)
398 (control-stack-start :c-type "lispobj *" :length #!+alpha 2 #!-alpha 1)
399 (control-stack-end :c-type "lispobj *" :length #!+alpha 2 #!-alpha 1)
400 (alien-stack-start :c-type "lispobj *" :length #!+alpha 2 #!-alpha 1)
401 (alien-stack-pointer :c-type "lispobj *" :length #!+alpha 2 #!-alpha 1)
402 #!+gencgc (alloc-region :c-type "struct alloc_region" :length 5)
403 (this :c-type "struct thread *" :length #!+alpha 2 #!-alpha 1)
404 (prev :c-type "struct thread *" :length #!+alpha 2 #!-alpha 1)
405 (next :c-type "struct thread *" :length #!+alpha 2 #!-alpha 1)
406 ;; starting, running, suspended, dead
407 (state :c-type "lispobj")
408 (tls-cookie) ; on x86, the LDT index
409 #!+(or x86 x86-64) (pseudo-atomic-bits)
410 (interrupt-data :c-type "struct interrupt_data *"
411 :length #!+alpha 2 #!-alpha 1)
413 ;; KLUDGE: On alpha, until STEPPING we have been lucky and the 32
414 ;; bit slots came in pairs. However the C compiler will align
415 ;; interrupt_contexts on a double word boundary. This logic should
416 ;; be handled by DEFINE-PRIMITIVE-OBJECT.
419 (interrupt-contexts :c-type "os_context_t *" :rest-p t))