1 ;;;-----------------------------------------------------------------------------------
5 ;;; contact : me (Michael Trowe)
9 ;;;-----------------------------------------------------------------------------------
13 ((storage :reader storage
14 :initform
(make-hash-table)
16 (back-map :reader back-map
17 :initform
(make-hash-table)
19 (next-address :accessor next-address
21 :initarg
:next-address
)
22 (proxies :accessor proxies
23 :initform
(make-hash-table :test
#'equal
)
29 (defmessage send-notifier
(address destination
)
30 :receive-action
(store-destination (objstore *manager
*)
34 (defmessage reference-revoked
(address)
35 :receive-action
(let* ((store (objstore *manager
*))
36 (exports (when(cdr (gethash address
(storage store
)))
37 (setf (cdr (gethash address
(storage store
)))
39 (cdr (gethash address
(storage store
))))))))
41 (remhash (fetch-obj address
) (back-map store
))
42 (remhash address
(storage store
)))))
46 (defun ensure-exported (obj &optional
(destination *current-actor
*))
47 (with-slots (back-map storage next-address
) (objstore *manager
*)
48 (let ((address-and-packform (gethash obj back-map
)))
49 (if address-and-packform
50 (store-destination (objstore *manager
*) (car address-and-packform
) destination
)
51 (let ((address (setf next-address
(1+ next-address
))))
52 (setf (gethash address storage
) (list obj destination
))
53 (setf address-and-packform
54 (setf (gethash obj back-map
)
56 (format nil
"(np ~a '~a)"
59 (class-name (class-of obj
)))))))))
60 (values (car address-and-packform
)
61 (cdr address-and-packform
)))))
64 (defun fetch-obj (address)
65 (car (gethash address
(storage (objstore *manager
*)))))
67 (defun print-storage ()
68 (print-hash (storage (objstore *manager
*))))
70 (defun print-hash (hashtable)
71 (maphash #'(lambda (k v
) (print (list k v
)))
74 (defun notify-sending (proxy)
75 (kernel-send (remote-os proxy
)
76 (send-notifier-message
77 :address
(remote-address proxy
)
78 :destination
*current-actor
*)))
80 (defmethod notify-proxy ((proxy proxy
))
81 (or (get-proxy (objstore *manager
*) proxy
)
82 (store-proxy (objstore *manager
*) proxy
)))
84 (defmethod notify-proxy :after
((proxy proxy
))
85 (initialize-local-slots proxy
)
89 (defun notify-gc (proxy)
90 (let ((address (remote-address proxy
))
91 (os (remote-os proxy
)))
93 (remhash (cons address os
)
94 (proxies (objstore *manager
*)))
95 (let ((*current-actor
* ()))
97 (reference-revoked-message
98 :address address
))))))
103 (defmethod get-proxy ((store objstore
) proxy
)
104 (let ((pointer (gethash (cons (remote-address proxy
)
112 (defmethod store-proxy ((store objstore
) proxy
)
113 (setf (gethash (cons (remote-address proxy
) (remote-os proxy
))
115 (make-array 1 :weak t
:initial-element proxy
))
117 (excl:schedule-finalization proxy
#'notify-gc
)
119 (sb-ext:finalize proxy
#'notify-gc
)
123 (defmethod store-destination ((store objstore
) address
125 (pushnew destination
(cdr (gethash address
(storage store
)))))
128 (defmethod reset ((store objstore
))
129 (maphash #'(lambda (key proxy-pointer
)
130 (declare (ignore key
))
131 (kill (aref proxy-pointer
0)))
133 (reinitialize-instance store
134 :storage
(make-hash-table)
135 :back-map
(make-hash-table)
137 :proxies
(make-hash-table :test
#'equal
)))
139 (defmethod kill ((proxy proxy
))
140 (setf (remote-address proxy
) ()))