/[cmucl]/src/code/scavhook.lisp
ViewVC logotype

Contents of /src/code/scavhook.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations)
Fri Mar 19 15:18:59 2010 UTC (4 years ago) by rtoy
Branch: MAIN
CVS Tags: sparc-tramp-assem-base, post-merge-intl-branch, release-20b-pre1, release-20b-pre2, sparc-tramp-assem-2010-07-19, GIT-CONVERSION, cross-sol-x86-merged, RELEASE_20b, cross-sol-x86-base, snapshot-2010-12, snapshot-2010-11, snapshot-2011-09, snapshot-2011-06, snapshot-2011-07, snapshot-2011-04, snapshot-2011-02, snapshot-2011-03, snapshot-2011-01, snapshot-2010-05, snapshot-2010-04, snapshot-2010-07, snapshot-2010-06, snapshot-2010-08, cross-sol-x86-2010-12-20, cross-sparc-branch-base, HEAD
Branch point for: cross-sparc-branch, RELEASE-20B-BRANCH, sparc-tramp-assem-branch, cross-sol-x86-branch
Changes since 1.4: +6 -5 lines
Merge intl-branch 2010-03-18 to HEAD.  To build, you need to use
boot-2010-02-1 as the bootstrap file.  You should probably also use
the new -P option for build.sh to generate and update the po files
while building.
1 ;;; -*- Package: EXT -*-
2 ;;;
3 ;;; **********************************************************************
4 ;;; This code was written as part of the CMU Common Lisp project at
5 ;;; Carnegie Mellon University, and has been placed in the public domain.
6 ;;;
7 (ext:file-comment
8 "$Header: /tiger/var/lib/cvsroots/cmucl/src/code/scavhook.lisp,v 1.5 2010/03/19 15:18:59 rtoy Rel $")
9 ;;;
10 ;;; **********************************************************************
11 ;;;
12 ;;; This file implements the ``Scavenger Hook'' extension.
13 ;;;
14 ;;; Written by William Lott
15 ;;;
16
17 (in-package "EXT")
18 (intl:textdomain "cmucl")
19
20 (export '(scavenger-hook scavenger-hook-p make-scavenger-hook
21 scavenger-hook-value scavenger-hook-function))
22
23 #+(or gengc gencgc)
24 (progn
25
26 (defun scavenger-hook-p (object)
27 _N"Returns T if OBJECT is a scavenger-hook, and NIL if not."
28 (scavenger-hook-p object))
29
30 (defun make-scavenger-hook (&key value (function (required-argument)))
31 _N"Create a new scavenger-hook with the specified VALUE and FUNCTION. For
32 as long as the scavenger-hook is alive, the scavenger in the garbage
33 collector will note whenever VALUE is moved, and arrange for FUNCTION
34 to be funcalled."
35 (declare (type function function))
36 (c::%make-scavenger-hook value function))
37
38 (defun scavenger-hook-value (scavhook)
39 _N"Returns the VALUE being monitored by SCAVHOOK. Can be setf."
40 (declare (type scavenger-hook scavhook))
41 (scavenger-hook-value scavhook))
42
43 (defun (setf scavenger-hook-value) (value scavhook)
44 (declare (type scavenger-hook scavhook))
45 (setf (scavenger-hook-value scavhook) value))
46
47 (defun scavenger-hook-function (scavhook)
48 _N"Returns the FUNCTION invoked when the monitored value is moved. Can be
49 setf."
50 (declare (type scavenger-hook scavhook))
51 (scavenger-hook-function scavhook))
52
53 (defun (setf scavenger-hook-function) (function scavhook)
54 (declare (type function function)
55 (type scavenger-hook scavhook))
56 (setf (scavenger-hook-function scavhook) function))
57
58 ); #+gengc progn
59
60 #-(or gengc gencgc)
61 (progn
62
63 (defstruct (scavhook
64 (:conc-name scavenger-hook-)
65 (:constructor %make-scavenger-hook (%value function last-addr))
66 (:print-function %print-scavenger-hook))
67 ;;
68 ;; The value we are monitoring.
69 (%value nil :type t)
70 ;;
71 ;; The function to invoke when the value gets scavenged (i.e. moved)
72 (function nil :type function)
73 ;;
74 ;; The address of where it was last time.
75 (last-addr 0 :type (unsigned-byte #.vm:word-bits)))
76
77 (defun %print-scavenger-hook (scavhook stream depth)
78 (declare (ignore depth))
79 (print-unreadable-object (scavhook stream :identity t :type t)))
80
81 (eval-when (compile eval)
82 (setf (info type kind 'scavenger-hook) :defined)
83 (setf (info type builtin 'scavenger-hook) nil))
84
85 (deftype scavenger-hook ()
86 'scavhook)
87
88 (defvar *scavenger-hooks* nil)
89
90 (defun make-scavenger-hook (&key value (function (required-argument)))
91 (without-gcing
92 (let ((scavhook
93 (%make-scavenger-hook value function
94 (kernel:get-lisp-obj-address value))))
95 (push (make-weak-pointer scavhook) *scavenger-hooks*)
96 scavhook)))
97
98 (declaim (inline scavenger-hook-p))
99 (defun scavenger-hook-p (thing)
100 (scavhook-p thing))
101
102 (declaim (inline scavenger-hook-value))
103 (defun scavenger-hook-value (scavhook)
104 (scavenger-hook-%value scavhook))
105
106 (defun (setf scavenger-hook-value) (value scavhook)
107 (without-gcing
108 (setf (scavenger-hook-%value scavhook) value)
109 (setf (scavenger-hook-last-addr scavhook)
110 (kernel:get-lisp-obj-address value)))
111 value)
112
113 (defun scavhook-after-gc-hook ()
114 (do ((prev nil)
115 (next *scavenger-hooks* (cdr next)))
116 ((null next))
117 (multiple-value-bind (scavhook valid) (weak-pointer-value (car next))
118 (cond (valid
119 (let* ((value (scavenger-hook-value scavhook))
120 (addr (kernel:get-lisp-obj-address value)))
121 (unless (= addr (scavenger-hook-last-addr scavhook))
122 (setf (scavenger-hook-last-addr scavhook) addr)
123 (funcall (scavenger-hook-function scavhook))))
124 (setf prev next))
125 (prev
126 (setf (cdr prev) (cdr next)))
127 (t
128 (setf *scavenger-hooks* (cdr next)))))))
129
130 (pushnew 'scavhook-after-gc-hook *after-gc-hooks*)
131
132 ); #-gengc progn

  ViewVC Help
Powered by ViewVC 1.1.5