[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: memory allocation primitives?



At 17:13 2/11/93 -0500, Bob Hall wrote:
>Is there one or a small number of routines through which
>everyone who wants to cons a cell must pass?  That is, in order to
>profile consing, I'd like to advise CONS to do some stuff, but
>that may not get all the consing done by, e.g. the list functions
>such as append, remove, sublis, etc., because there is no guarantee
>that they call CONS to get their cells.  What I'd like is an advisable
>function like "CCL::%cons" or something that really does it for everybody.
>(An alternative is to advise every language primitive that could
>possibly allocate memory, but that is extremely ugly and may not even
>get everything (you can't advise special forms and macros, can you? also,
>macros may expand into mcl-specific internal function calls, such as
>backquote).)
>If there are a small number of such internal functions, that would be okay,
>too.  (e.g. In the C world, the functions malloc, realloc, etc. cover 99+% of
>all dynamic space allocation in programs.)
>

There are a fairly small number of routines, but they're all in subprims
in MCL's kernel, very difficult for you to patch. Since many of MCL's
consing primitives compile into direct calls to the subprims, much
of the consing never goes through any Lisp function at all, so advising
won't work, either. The only way I can think of that would work would be
for me to add some sort of consing hook that would be called with the
number of bytes consed whenever one of the consing subprimitives does its
thing. I hesitate to add this overhead.

Example.  In the code below, $sp-allocgv does the MAKE-ARRAY, $sp-consyz
does the CONS, and $sp-conslist does the LIST.

? (defun foo ()
    (list (make-array 12) (cons 1 2)))
FOO
? (disassemble *)
0 (JSR_SUBPRIM $SP-NOARGS)
4 (MOVEQ (FIXNUM 6) D0)
6 (JSR_SUBPRIM $SP-ALLOCGV)
10 (VPUSH ATEMP0)
12 (MOVEQ (FIXNUM 1) D1)
14 (MOVEQ (FIXNUM 2) D0)
16 (JSR_SUBPRIM $SP-CONSYZ)
20 (VPUSH D0)
22 (SET_NARGS 2)
24 (JSR_SUBPRIM $SP-CONSLIST)
28 (ADDQ.W 4 SP)
30 (RTS)
?