wiki:Internals/MemoryAllocation

Version 1 (modified by lpolzer, 5 years ago) (diff)

Created.

Explanation by gb:

Memory allocation is per-thread; a thread conses within a private "chunk" of memory by decrementing a per-thread pointer that starts at the high end of its current chunk and comparing that pointer to the low end of the chunk; if the pointer's above the limit, we use the memory, otherwise we need a new chunk:

   [21]    (subl ($ 7) (@ (% fs) 132))  ; subtract the size of a cons - the tag of a
cons
                                        ; from the per-thread pointer
   [30]    (movl (@ (% fs) 132) (% temp0)) ; load the per-thread pointer into a temp
reg
   [38]    (cmpl (@ (% fs) 136) (% temp0)) ; compare to limit
   [46]    (ja L50)                        ; continue if above limit
   [48]    (uuo-alloc)                     ; trap, get a new chunk
L50
   [50]    (andb ($ 248) (@ (% fs) 132))   ; clear tag bits in thread-local storage
   [59]    (movl (% arg_y) (@ 3 (% temp0))) ; store car
   [62]    (movl (% arg_z) (@ -1 (% temp0))) ; store cdr
   [65]    (movl (% temp0) (% arg_z))      ; return cons cell