2 * allocation routines for C code. For allocation done by Lisp look
3 * instead at src/compiler/target/alloc.lisp and .../macros.lisp
7 * This software is part of the SBCL system. See the README file for
10 * This software is derived from the CMU CL system, which was
11 * written at Carnegie Mellon University and released into the
12 * public domain. The software is in the public domain and is
13 * provided with absolutely no warranty. See the COPYING and CREDITS
14 * files for more information.
20 #include "pseudo-atomic.h"
21 #include "genesis/code.h"
23 #ifdef LISP_FEATURE_GENCGC
24 lispobj
alloc_code_object (unsigned boxed
, unsigned unboxed
)
26 /* It used to be that even on gencgc builds the
27 * ALLOCATE-CODE-OBJECT VOP did all this initialization within
28 * pseudo atomic. Here, we rely on gc being inhibited. */
29 if (read_TLS(GC_INHIBIT
, arch_os_get_current_thread()) == NIL
)
30 lose("alloc_code_object called with GC enabled.");
33 struct thread
__attribute__((unused
)) *th
= arch_os_get_current_thread();
34 /* boxed is the number of constants; add other slots, align it to
35 * two words, so that the code start is aligned. */
36 int boxedwords
= ALIGN_UP(offsetof(struct code
, constants
)/sizeof(lispobj
)+boxed
, 2);
38 /* Unboxed is the size of instructions in bytes. It will be stored
39 * as is in the code_size slot, but it needs to be allocated with
40 * double-word alignment. */
41 unsigned unboxed_aligned
= ALIGN_UP(unboxed
, 2*N_WORD_BYTES
);
43 /* Since alloc_code_object is run under WITHOUT-GCING it doesn't
44 * actaully need to be pseudo-atomic, this is just to appease the
45 * assertions in general_alloc() */
46 set_pseudo_atomic_atomic(th
);
47 code
= (struct code
*)
48 general_alloc(boxedwords
*N_WORD_BYTES
+ unboxed_aligned
, CODE_PAGE_FLAG
);
49 clear_pseudo_atomic_atomic(th
);
51 code
->header
= (boxedwords
<< N_WIDETAG_BITS
) | CODE_HEADER_WIDETAG
;
52 code
->code_size
= make_fixnum(unboxed
);
53 code
->debug_info
= NIL
;
54 return make_lispobj(code
, OTHER_POINTER_LOWTAG
);