Changeset 8226


Ignore:
Timestamp:
Jan 19, 2008, 1:17:28 PM (12 years ago)
Author:
andreas
Message:

Initial implementation of STATIC-CONS. Uses locks on critical path, and
thus is slow.

Location:
trunk/source/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/lib/ccl-export-syms.lisp

    r8175 r8226  
    393393     *fasl-save-doc-strings*
    394394     *fasl-save-definitions*
     395     *static-cons-chunk*
     396     static-cons
    395397
    396398     compiler-let
  • trunk/source/lib/misc.lisp

    r7954 r8226  
    802802        (format out "~&~a~36t~12d~48t~16d" (aref *heap-utilization-vector-type-names* i)  count sizes)))))
    803803                           
    804 
    805 
     804;; The number of words to allocate for static conses when the user requests
     805;; one and we don't have any left over
     806(defparameter *static-cons-chunk* 1048576)
     807
     808(defun initialize-static-cons ()
     809  "Activates collection of garbage conses in the static-conses
     810   list and allocates initial static conses."
     811  (without-interrupts
     812   (%lock-gc-lock)
     813   ; Another thread might have called initialize already
     814   (when (eq (%get-kernel-global 'static-conses) 0)
     815     (%set-kernel-global 'static-conses nil))
     816   (%unlock-gc-lock))
     817  (allocate-static-conses))
     818
     819(defun allocate-static-conses ()
     820  "Allocates some memory, freezes it and lets it become garbage.
     821   This will add the memory to the list of free static conses."
     822  (let ((l (make-array *static-cons-chunk*)))
     823    (declare (ignore l))
     824    (freeze))
     825  (gc))
     826
     827(defmacro atomic-pop-kernel-global (place)
     828  "Pops an cons cell off a kernel global, in a way that's atomic w.r.t.
     829   garbage collection.  Uses gc-lock a.t.m., which is too
     830   expensive."
     831  `(without-interrupts
     832     (%lock-gc-lock)
     833     (let ((value (%get-kernel-global ,place)))
     834       (%set-kernel-global ,place (cdr value))
     835       (%unlock-gc-lock)
     836       value)))
     837
     838(defun static-cons (car-value cdr-value)
     839  "Allocates a cons cell that doesn't move on garbage collection,
     840   and thus doesn't trigger re-hashing when used as a key in a hash
     841   table.  Usage is equivalent to regular CONS."
     842  (when (eq (%get-kernel-global 'static-conses) 0)
     843    (initialize-static-cons))
     844  (let ((cell (atomic-pop-kernel-global 'static-conses)))
     845    (if cell
     846      (progn
     847        (setf (car cell) car-value)
     848        (setf (cdr cell) cdr-value)
     849        cell)
     850      (progn
     851        (allocate-static-conses)
     852        (static-cons car-value cdr-value)))))
     853       
     854
Note: See TracChangeset for help on using the changeset viewer.