1 | ;;;-*-Mode: LISP; Package: CCL -*- |
---|
2 | ;;; |
---|
3 | ;;; Copyright (C) 1994-2001 Digitool, Inc |
---|
4 | ;;; This file is part of OpenMCL. |
---|
5 | ;;; |
---|
6 | ;;; OpenMCL is licensed under the terms of the Lisp Lesser GNU Public |
---|
7 | ;;; License , known as the LLGPL and distributed with OpenMCL as the |
---|
8 | ;;; file "LICENSE". The LLGPL consists of a preamble and the LGPL, |
---|
9 | ;;; which is distributed with OpenMCL as the file "LGPL". Where these |
---|
10 | ;;; conflict, the preamble takes precedence. |
---|
11 | ;;; |
---|
12 | ;;; OpenMCL is referenced in the preamble as the "LIBRARY." |
---|
13 | ;;; |
---|
14 | ;;; The LLGPL is also available online at |
---|
15 | ;;; http://opensource.franz.com/preamble.html |
---|
16 | |
---|
17 | (in-package "CCL") |
---|
18 | |
---|
19 | (eval-when (eval compile) |
---|
20 | (require 'defstruct-macros)) |
---|
21 | |
---|
22 | (defun short-site-name () |
---|
23 | "Return a string with the abbreviated site name, or NIL if not known." |
---|
24 | (or *short-site-name* "unspecified")) |
---|
25 | |
---|
26 | (defun long-site-name () |
---|
27 | "Return a string with the long form of the site name, or NIL if not known." |
---|
28 | (or *long-site-name* "unspecified")) |
---|
29 | |
---|
30 | (defun machine-instance () |
---|
31 | "Return a string giving the name of the local machine." |
---|
32 | #-windows-target (%uname 1) |
---|
33 | #+windows-target |
---|
34 | (rlet ((nsize #>DWORD 0)) |
---|
35 | (if (eql 0 (#_GetComputerNameExW #$ComputerNameDnsFullyQualified |
---|
36 | (%null-ptr) |
---|
37 | nsize)) |
---|
38 | (%stack-block ((buf (* 2 (pref nsize #>DWORD)))) |
---|
39 | (#_GetComputerNameExW #$ComputerNameDnsFullyQualified |
---|
40 | buf |
---|
41 | nsize) |
---|
42 | (%get-native-utf-16-cstring buf)) |
---|
43 | "localhost")) |
---|
44 | ) |
---|
45 | |
---|
46 | |
---|
47 | (defun machine-type () |
---|
48 | "Returns a string describing the type of the local machine." |
---|
49 | #-windows-target (%uname 4) |
---|
50 | #+windows-target |
---|
51 | (rlet ((info #>SYSTEM_INFO)) |
---|
52 | (#_GetSystemInfo info) |
---|
53 | (case (pref info #>SYSTEM_INFO.nil.nil.wProcessorArchitecture) |
---|
54 | (#.#$PROCESSOR_ARCHITECTURE_AMD64 "x64") |
---|
55 | (#.#$PROCESSOR_ARCHITECTURE_INTEL "x86") |
---|
56 | (t "unknown"))) |
---|
57 | ) |
---|
58 | |
---|
59 | |
---|
60 | |
---|
61 | (defloadvar *machine-version* nil) |
---|
62 | |
---|
63 | (defun machine-version () |
---|
64 | "Return a string describing the version of the computer hardware we |
---|
65 | are running on, or NIL if we can't find any useful information." |
---|
66 | (or *machine-version* |
---|
67 | (setq *machine-version* |
---|
68 | #+darwin-target |
---|
69 | (block darwin-machine-version |
---|
70 | (%stack-block ((mib 8)) |
---|
71 | (setf (%get-long mib 0) #$CTL_HW |
---|
72 | (%get-long mib 4) #$HW_MODEL) |
---|
73 | (%stack-block ((res 256) |
---|
74 | (reslen target::node-size)) |
---|
75 | (setf (%get-byte res 0) 0 |
---|
76 | (%get-natural reslen 0) 256) |
---|
77 | (if (zerop (#_sysctl mib 2 res reslen (%null-ptr) 0)) |
---|
78 | (return-from darwin-machine-version (%get-cstring res)))))) |
---|
79 | #+linux-target |
---|
80 | (with-open-file (f "/proc/cpuinfo" :if-does-not-exist nil) |
---|
81 | (when f |
---|
82 | (flet ((cpu-info-match (target line) |
---|
83 | (let* ((targetlen (length target)) |
---|
84 | (linelen (length line))) |
---|
85 | (if (and (> linelen targetlen) |
---|
86 | (string= target line |
---|
87 | :end2 targetlen)) |
---|
88 | (let* ((colonpos (position #\: line))) |
---|
89 | (when colonpos |
---|
90 | (string-trim " " |
---|
91 | (subseq line (1+ colonpos))))))))) |
---|
92 | (do* ((line (read-line f nil nil) |
---|
93 | (read-line f nil nil)) |
---|
94 | (target #+ppc-target "machine" |
---|
95 | #+x86-target "model name")) |
---|
96 | ((null line)) |
---|
97 | (let* ((matched (cpu-info-match target line))) |
---|
98 | (when matched (return matched))))))) |
---|
99 | #+freebsd-target |
---|
100 | (%stack-block ((ret 512) |
---|
101 | (mib (* (record-length :uint)))) |
---|
102 | (setf (%get-unsigned-long mib 0) |
---|
103 | #$CTL_HW |
---|
104 | (%get-unsigned-long mib (record-length :uint)) |
---|
105 | #$HW_MODEL) |
---|
106 | (rlet ((oldsize :uint 512)) |
---|
107 | (if (eql 0 (#_sysctl mib 2 ret oldsize (%null-ptr) 0)) |
---|
108 | (%get-cstring ret) |
---|
109 | 1))) |
---|
110 | #+solaris-target |
---|
111 | (rlet ((info :processor_info_t)) |
---|
112 | (do* ((i 0 (1+ i))) |
---|
113 | ((and (= 0 (#_processor_info i info)) |
---|
114 | (= (pref info :processor_info_t.pi_state) |
---|
115 | #$P_ONLINE)) |
---|
116 | (%get-cstring (pref info :processor_info_t.pi_processor_type))))) |
---|
117 | #+windows-target |
---|
118 | (getenv "PROCESSOR_IDENTIFIER") |
---|
119 | ))) |
---|
120 | |
---|
121 | |
---|
122 | (defun software-type () |
---|
123 | "Return a string describing the supporting software." |
---|
124 | #-windows-target (%uname 0) |
---|
125 | #+windows-target "Microsoft Windows") |
---|
126 | |
---|
127 | |
---|
128 | (defun software-version () |
---|
129 | "Return a string describing version of the supporting software, or NIL |
---|
130 | if not available." |
---|
131 | #-windows-target (%uname 2) |
---|
132 | #+windows-target |
---|
133 | (rletZ ((info #>OSVERSIONINFOEX)) |
---|
134 | (setf (pref info #>OSVERSIONINFOEX.dwOSVersionInfoSize) |
---|
135 | (record-length #>OSVERSIONINFOEX)) |
---|
136 | (#_GetVersionExA info) |
---|
137 | (format nil "~d.~d Build ~d (~a)" |
---|
138 | (pref info #>OSVERSIONINFOEX.dwMajorVersion) |
---|
139 | (pref info #>OSVERSIONINFOEX.dwMinorVersion) |
---|
140 | (pref info #>OSVERSIONINFOEX.dwBuildNumber) |
---|
141 | (if (eql (pref info #>OSVERSIONINFOEX.wProductType) |
---|
142 | #$VER_NT_WORKSTATION) |
---|
143 | "Workstation" |
---|
144 | "Server"))) |
---|
145 | ) |
---|
146 | |
---|
147 | |
---|
148 | |
---|
149 | |
---|
150 | |
---|
151 | |
---|
152 | |
---|
153 | ;;; Yawn. |
---|
154 | |
---|
155 | |
---|
156 | |
---|
157 | (defmethod documentation (thing doc-id) |
---|
158 | (%get-documentation thing doc-id)) |
---|
159 | |
---|
160 | (defmethod (setf documentation) (new thing doc-id) |
---|
161 | (%put-documentation thing doc-id new)) |
---|
162 | |
---|
163 | |
---|
164 | (defmethod documentation ((symbol symbol) (doc-type (eql 'function))) |
---|
165 | (let* ((def (fboundp symbol))) ; FBOUNDP returns info about definition |
---|
166 | (when def |
---|
167 | (%get-documentation def t)))) |
---|
168 | |
---|
169 | (defmethod (setf documentation) ((new t) |
---|
170 | (symbol symbol) |
---|
171 | (doc-type (eql 'function))) |
---|
172 | (let* ((def (fboundp symbol))) ; FBOUNDP returns info about definition |
---|
173 | (when def |
---|
174 | (%put-documentation def |
---|
175 | t |
---|
176 | new)) |
---|
177 | new)) |
---|
178 | |
---|
179 | (defmethod documentation ((symbol symbol) (doc-type (eql 'setf))) |
---|
180 | (call-next-method)) |
---|
181 | |
---|
182 | (defmethod (setf documentation) ((new t) |
---|
183 | (symbol symbol) |
---|
184 | (doc-type (eql 'setf))) |
---|
185 | (call-next-method)) |
---|
186 | |
---|
187 | |
---|
188 | (defmethod documentation ((symbol symbol) (doc-type (eql 'variable))) |
---|
189 | (call-next-method)) |
---|
190 | |
---|
191 | (defmethod (setf documentation) ((new t) |
---|
192 | (symbol symbol) |
---|
193 | (doc-type (eql 'variable))) |
---|
194 | (call-next-method)) |
---|
195 | |
---|
196 | (defmethod documentation ((symbol symbol) (doc-type (eql 'compiler-macro))) |
---|
197 | (call-next-method)) |
---|
198 | |
---|
199 | (defmethod (setf documentation) ((new t) |
---|
200 | (symbol symbol) |
---|
201 | (doc-type (eql 'compiler-macro))) |
---|
202 | (call-next-method)) |
---|
203 | |
---|
204 | (defmethod documentation ((symbol symbol) (doc-type (eql 'type))) |
---|
205 | (let* ((class (find-class symbol nil))) |
---|
206 | (if class |
---|
207 | (documentation class doc-type) |
---|
208 | (call-next-method)))) |
---|
209 | |
---|
210 | (defmethod (setf documentation) (new (symbol symbol) (doc-type (eql 'type))) |
---|
211 | (let* ((class (find-class symbol nil))) |
---|
212 | (if class |
---|
213 | (setf (documentation class doc-type) new) |
---|
214 | (call-next-method)))) |
---|
215 | |
---|
216 | (defmethod documentation ((symbol symbol) (doc-type (eql 'method-combination))) |
---|
217 | (let* ((mci (method-combination-info symbol))) |
---|
218 | (if mci |
---|
219 | (documentation mci doc-type)))) |
---|
220 | |
---|
221 | (defmethod (setf documentation) ((new t) |
---|
222 | (symbol symbol) |
---|
223 | (doc-type (eql 'method-combination))) |
---|
224 | (let* ((mci (method-combination-info symbol))) |
---|
225 | (if mci |
---|
226 | (setf (documentation mci doc-type) new)))) |
---|
227 | |
---|
228 | |
---|
229 | (defmethod documentation ((symbol symbol) (doc-type (eql 'structure))) |
---|
230 | (let* ((class (find-class symbol nil))) |
---|
231 | (if (typep class 'structure-class) |
---|
232 | (documentation class 'type) |
---|
233 | (call-next-method)))) |
---|
234 | |
---|
235 | (defmethod (setf documentation) ((new t) |
---|
236 | (symbol symbol) |
---|
237 | (doc-type (eql 'structure))) |
---|
238 | (let* ((class (find-class symbol nil))) |
---|
239 | (if (typep class 'structure-class) |
---|
240 | (setf (documentation class 'type) new) |
---|
241 | (call-next-method)))) |
---|
242 | |
---|
243 | (defmethod documentation ((p package) (doc-type (eql 't))) |
---|
244 | (call-next-method)) |
---|
245 | |
---|
246 | (defmethod (setf documentation) ((new t) (p package) (doc-type (eql 't))) |
---|
247 | (call-next-method)) |
---|
248 | |
---|
249 | (defmethod documentation ((f function) (doc-type (eql 't))) |
---|
250 | (call-next-method)) |
---|
251 | |
---|
252 | (defmethod (setf documentation) ((new t) (f function) (doc-type (eql 't))) |
---|
253 | (call-next-method)) |
---|
254 | |
---|
255 | (defmethod documentation ((f function) (doc-type (eql 'function))) |
---|
256 | (documentation f t)) |
---|
257 | |
---|
258 | (defmethod (setf documentation) ((new t) |
---|
259 | (f function) |
---|
260 | (doc-type (eql 'function))) |
---|
261 | (setf (documentation f t) new)) |
---|
262 | |
---|
263 | (defmethod documentation ((l cons) (doc-type (eql 'function))) |
---|
264 | (let* ((name (setf-function-spec-name l))) |
---|
265 | (if name |
---|
266 | (documentation name doc-type) |
---|
267 | (%get-documentation l doc-type)))) |
---|
268 | |
---|
269 | (defmethod (setf documentation) ((new t) (l cons) (doc-type (eql 'function))) |
---|
270 | (let* ((name (setf-function-spec-name l))) |
---|
271 | (if name |
---|
272 | (setf (documentation name doc-type) new) |
---|
273 | (%put-documentation l doc-type new)))) |
---|
274 | |
---|
275 | |
---|
276 | (defmethod documentation ((l cons) (doc-type (eql 'compiler-macro))) |
---|
277 | (let* ((name (setf-function-spec-name l))) |
---|
278 | (if name |
---|
279 | (documentation name doc-type) |
---|
280 | (%get-documentation l doc-type)))) |
---|
281 | |
---|
282 | (defmethod (setf documentation) ((new t) (l cons) (doc-type (eql 'compiler-macr0))) |
---|
283 | (let* ((name (setf-function-spec-name l))) |
---|
284 | (if name |
---|
285 | (setf (documentation name doc-type) new) |
---|
286 | (%put-documentation l doc-type new)))) |
---|
287 | |
---|
288 | |
---|
289 | (defmethod documentation ((m method-combination) |
---|
290 | (doc-type (eql 'method-combination))) |
---|
291 | (call-next-method)) |
---|
292 | |
---|
293 | (defmethod (setf documentation) ((new t) |
---|
294 | (m method-combination) |
---|
295 | (doc-type (eql 'method-combination))) |
---|
296 | (call-next-method)) |
---|
297 | |
---|
298 | (defmethod documentation ((m method-combination) |
---|
299 | (doc-type (eql t))) |
---|
300 | (documentation m 'method-combination)) |
---|
301 | |
---|
302 | (defmethod (setf documentation) ((new t) |
---|
303 | (m method-combination) |
---|
304 | (doc-type (eql t))) |
---|
305 | (setf (documentation m 'method-combination) new)) |
---|
306 | |
---|
307 | (defmethod documentation ((m standard-method) |
---|
308 | (doc-type (eql t))) |
---|
309 | (call-next-method)) |
---|
310 | |
---|
311 | (defmethod (setf documentation) ((new t) |
---|
312 | (m standard-method) |
---|
313 | (doc-type (eql t))) |
---|
314 | (call-next-method)) |
---|
315 | |
---|
316 | (defmethod documentation ((c standard-class) (doc-type (eql 'type))) |
---|
317 | (call-next-method)) |
---|
318 | |
---|
319 | (defmethod (setf documentation) ((new t) |
---|
320 | (c standard-class) |
---|
321 | (doc-type (eql 'type))) |
---|
322 | (call-next-method)) |
---|
323 | |
---|
324 | (defmethod documentation ((c standard-class) (doc-type (eql 't))) |
---|
325 | (documentation c 'type)) |
---|
326 | |
---|
327 | (defmethod (setf documentation) ((new t) |
---|
328 | (c standard-class) |
---|
329 | (doc-type (eql 't))) |
---|
330 | (setf (documentation c 'type) new)) |
---|
331 | |
---|
332 | (defmethod documentation ((c structure-class) (doc-type (eql 'type))) |
---|
333 | (call-next-method)) |
---|
334 | |
---|
335 | (defmethod (setf documentation) ((new t) |
---|
336 | (c structure-class) |
---|
337 | (doc-type (eql 'type))) |
---|
338 | (call-next-method)) |
---|
339 | |
---|
340 | (defmethod documentation ((c structure-class) (doc-type (eql 't))) |
---|
341 | (documentation c 'type)) |
---|
342 | |
---|
343 | (defmethod (setf documentation) ((new t) |
---|
344 | (c structure-class) |
---|
345 | (doc-type (eql 't))) |
---|
346 | (setf (documentation c 'type) new)) |
---|
347 | |
---|
348 | ;;; This is now deprecated; things which call it should stop doing so. |
---|
349 | (defun set-documentation (symbol doc-type string) |
---|
350 | (setf (documentation symbol doc-type) string)) |
---|
351 | |
---|
352 | (defun set-function-info (symbol info) |
---|
353 | (let* ((doc-string (if (consp info) (car info) info))) |
---|
354 | (if (and *save-doc-strings* (stringp doc-string)) |
---|
355 | (set-documentation symbol 'function doc-string))) |
---|
356 | (let* ((cons (assq symbol *nx-globally-inline*)) |
---|
357 | (lambda-expression (if (consp info) (cdr info)))) |
---|
358 | (if (and (proclaimed-inline-p symbol) |
---|
359 | (not (compiler-special-form-p symbol)) |
---|
360 | (lambda-expression-p lambda-expression) |
---|
361 | (let* ((lambda-list (cadr lambda-expression))) |
---|
362 | (and (not (memq '&lap lambda-list)) |
---|
363 | (not (memq '&method lambda-list)) |
---|
364 | (not (memq '&lexpr lambda-list))))) |
---|
365 | (if cons |
---|
366 | (%rplacd cons lambda-expression) |
---|
367 | (push (cons symbol lambda-expression) *nx-globally-inline*)) |
---|
368 | (if cons (setq *nx-globally-inline* (delete cons *nx-globally-inline*))))) |
---|
369 | symbol) |
---|
370 | |
---|
371 | |
---|
372 | (setf (documentation 'if 'function) |
---|
373 | "If Predicate Then [Else] |
---|
374 | If Predicate evaluates to non-null, evaluate Then and returns its values, |
---|
375 | otherwise evaluate Else and return its values. Else defaults to NIL.") |
---|
376 | |
---|
377 | (setf (documentation 'progn 'function) |
---|
378 | "progn form* |
---|
379 | Evaluates each FORM and returns the value(s) of the last FORM.") |
---|
380 | |
---|
381 | (defmethod documentation ((thing character-encoding) (doc-type (eql t))) |
---|
382 | (character-encoding-documentation thing)) |
---|
383 | |
---|
384 | (defmethod (setf documentation) (new (thing character-encoding) (doc-type (eql t))) |
---|
385 | (check-type new (or null string)) |
---|
386 | (setf (character-encoding-documentation thing) new)) |
---|
387 | |
---|
388 | (defmethod documentation ((thing symbol) (doc-type (eql 'character-encoding))) |
---|
389 | (let* ((encoding (lookup-character-encoding (intern (string thing) :keyword)))) |
---|
390 | (when encoding |
---|
391 | (documentation encoding t)))) |
---|
392 | |
---|
393 | |
---|
394 | |
---|
395 | |
---|
396 | #| |
---|
397 | (setf (documentation 'car 'variable) "Preferred brand of automobile") |
---|
398 | (documentation 'car 'variable) |
---|
399 | (setf (documentation 'foo 'structure) "the structure is grand.") |
---|
400 | (documentation 'foo 'structure) |
---|
401 | (setf (documentation 'foo 'variable) "the metasyntactic remarker") |
---|
402 | (documentation 'foo 'variable) |
---|
403 | (setf (documentation 'foo 'obscure) "no one really knows what it means") |
---|
404 | (documentation 'foo 'obscure) |
---|
405 | (setf (documentation 'foo 'structure) "the structure is solid") |
---|
406 | (documentation 'foo 'function) |
---|
407 | ||# |
---|
408 | |
---|
409 | ;; |
---|
410 | |
---|
411 | |
---|
412 | (defun %page-fault-info () |
---|
413 | #-(or darwin-target windows-target) |
---|
414 | (rlet ((usage :rusage)) |
---|
415 | (%%rusage usage) |
---|
416 | (values (pref usage :rusage.ru_minflt) |
---|
417 | (pref usage :rusage.ru_majflt) |
---|
418 | (pref usage :rusage.ru_nswap))) |
---|
419 | #+darwin-target |
---|
420 | (rlet ((count #>mach_msg_type_number_t #$TASK_EVENTS_INFO_COUNT) |
---|
421 | (info #>task_events_info)) |
---|
422 | (#_task_info (#_mach_task_self) #$TASK_EVENTS_INFO info count) |
---|
423 | (values (pref info #>task_events_info.cow_faults) |
---|
424 | (pref info #>task_events_info.faults) |
---|
425 | (pref info #>task_events_info.pageins))) |
---|
426 | #+windows-target |
---|
427 | ;; Um, don't know how to determine this, or anything like it. |
---|
428 | (values 0 0 0)) |
---|
429 | |
---|
430 | |
---|
431 | |
---|
432 | (defparameter *report-time-function* nil |
---|
433 | "If non-NULL, should be a function which accepts the following |
---|
434 | keyword arguments: |
---|
435 | :FORM the form that was executed |
---|
436 | :RESULTS a list of all values returned by the execution of FORM |
---|
437 | :ELAPSED-TIME total elapsed (real) time, in internal-time-units-per-second |
---|
438 | :USER-TIME elapsed user time, in internal-time-units-per-second |
---|
439 | :SYSTEM-TIME elapsed system time, in internal-time-units-per-second |
---|
440 | :GC-TIME total real time spent in the GC, in internal-time-units-per-second |
---|
441 | :BYTES-ALLOCATED total bytes allocated |
---|
442 | :MINOR-PAGE-FAULTS minor page faults |
---|
443 | :MAJOR-PAGE-FAULTS major page faults |
---|
444 | :SWAPS swaps") |
---|
445 | |
---|
446 | |
---|
447 | (defun standard-report-time (&key form results elapsed-time user-time |
---|
448 | system-time gc-time bytes-allocated |
---|
449 | minor-page-faults major-page-faults |
---|
450 | swaps) |
---|
451 | (let* ((s *trace-output*) |
---|
452 | (units |
---|
453 | (ecase internal-time-units-per-second |
---|
454 | (1000000 "microseconds") |
---|
455 | (1000 "milliseconds"))) |
---|
456 | (width |
---|
457 | (ecase internal-time-units-per-second |
---|
458 | (1000000 6) |
---|
459 | (1000 3))) |
---|
460 | (cpu-count (cpu-count))) |
---|
461 | (format s "~&~S took ~:D ~a (~,vF seconds) to run ~%~20twith ~D available CPU core~P." |
---|
462 | form elapsed-time units width (/ elapsed-time internal-time-units-per-second) cpu-count cpu-count) |
---|
463 | (format s "~&During that period, ~:D ~a (~,vF seconds) were spent in user mode" user-time units width (/ user-time internal-time-units-per-second)) |
---|
464 | (format s "~& ~:D ~a (~,vF seconds) were spent in system mode" system-time units width(/ system-time internal-time-units-per-second)) |
---|
465 | (unless (eql gc-time 0) |
---|
466 | (format s |
---|
467 | "~%~:D ~a (~,vF seconds) was spent in GC." |
---|
468 | gc-time units width (/ gc-time internal-time-units-per-second))) |
---|
469 | (unless (eql 0 bytes-allocated) |
---|
470 | (format s "~% ~:D bytes of memory allocated." bytes-allocated)) |
---|
471 | (when (or (> minor-page-faults 0) |
---|
472 | (> major-page-faults 0) |
---|
473 | (> swaps 0)) |
---|
474 | (format s |
---|
475 | "~% ~:D minor page faults, ~:D major page faults, ~:D swaps." |
---|
476 | minor-page-faults major-page-faults swaps)) |
---|
477 | (format s "~&") |
---|
478 | (values-list results))) |
---|
479 | |
---|
480 | (defun report-time (form thunk) |
---|
481 | (flet ((integer-size-in-bytes (i) |
---|
482 | (if (typep i 'fixnum) |
---|
483 | 0 |
---|
484 | (* (logand (+ 2 (uvsize i)) (lognot 1)) 4)))) |
---|
485 | (multiple-value-bind (user-start system-start) |
---|
486 | (%internal-run-time) |
---|
487 | (multiple-value-bind (minor-start major-start swaps-start) |
---|
488 | (%page-fault-info) |
---|
489 | (let* ((initial-real-time (get-internal-real-time)) |
---|
490 | (initial-gc-time (gctime)) |
---|
491 | (initial-consed (total-bytes-allocated)) |
---|
492 | (initial-overhead (integer-size-in-bytes initial-consed))) |
---|
493 | (let* ((results (multiple-value-list (funcall thunk)))) |
---|
494 | (declare (dynamic-extent results)) |
---|
495 | (multiple-value-bind (user-end system-end) |
---|
496 | (%internal-run-time) |
---|
497 | (multiple-value-bind (minor-end major-end swaps-end) |
---|
498 | (%page-fault-info) |
---|
499 | (let* ((new-consed (total-bytes-allocated)) |
---|
500 | (bytes-consed |
---|
501 | (- new-consed (+ initial-overhead initial-consed))) |
---|
502 | (elapsed-real-time |
---|
503 | (- (get-internal-real-time) initial-real-time)) |
---|
504 | (elapsed-gc-time (- (gctime) initial-gc-time)) |
---|
505 | (elapsed-user-time |
---|
506 | (- user-end user-start)) |
---|
507 | (elapsed-system-time |
---|
508 | (- system-end system-start)) |
---|
509 | (elapsed-minor (- minor-end minor-start)) |
---|
510 | (elapsed-major (- major-end major-start)) |
---|
511 | (elapsed-swaps (- swaps-end swaps-start))) |
---|
512 | (funcall (or *report-time-function* |
---|
513 | #'standard-report-time) |
---|
514 | :form form |
---|
515 | :results results |
---|
516 | :elapsed-time elapsed-real-time |
---|
517 | :user-time elapsed-user-time |
---|
518 | :system-time elapsed-system-time |
---|
519 | :gc-time elapsed-gc-time |
---|
520 | :bytes-allocated bytes-consed |
---|
521 | :minor-page-faults elapsed-minor |
---|
522 | :major-page-faults elapsed-major |
---|
523 | :swaps elapsed-swaps)))))))))) |
---|
524 | |
---|
525 | |
---|
526 | |
---|
527 | |
---|
528 | ;;; site names and machine-instance is in the init file. |
---|
529 | |
---|
530 | (defun add-feature (symbol) |
---|
531 | "Not CL but should be." |
---|
532 | (if (symbolp symbol) |
---|
533 | (if (not (memq symbol *features*)) |
---|
534 | (setq *features* (cons symbol *features*))))) |
---|
535 | |
---|
536 | ;;; (dotimes (i 5000) (declare (fixnum i)) (add-feature 'junk)) |
---|
537 | |
---|
538 | |
---|
539 | |
---|
540 | |
---|
541 | ;;; Misc string functions |
---|
542 | |
---|
543 | |
---|
544 | (defun string-left-trim (char-bag string &aux end) |
---|
545 | "Given a set of characters (a list or string) and a string, returns |
---|
546 | a copy of the string with the characters in the set removed from the |
---|
547 | left end." |
---|
548 | (setq string (string string)) |
---|
549 | (setq end (length string)) |
---|
550 | (do ((index 0 (%i+ index 1))) |
---|
551 | ((or (eq index end) (not (find (aref string index) char-bag))) |
---|
552 | (subseq string index end)))) |
---|
553 | |
---|
554 | (defun string-right-trim (char-bag string &aux end) |
---|
555 | "Given a set of characters (a list or string) and a string, returns |
---|
556 | a copy of the string with the characters in the set removed from the |
---|
557 | right end." |
---|
558 | (setq string (string string)) |
---|
559 | (setq end (length string)) |
---|
560 | (do ((index (%i- end 1) (%i- index 1))) |
---|
561 | ((or (%i< index 0) (not (find (aref string index) char-bag))) |
---|
562 | (subseq string 0 (%i+ index 1))))) |
---|
563 | |
---|
564 | (defun string-trim (char-bag string &aux end) |
---|
565 | "Given a set of characters (a list or string) and a string, returns a |
---|
566 | copy of the string with the characters in the set removed from both |
---|
567 | ends." |
---|
568 | (setq string (string string)) |
---|
569 | (setq end (length string)) |
---|
570 | (let ((left-end) (right-end)) |
---|
571 | (do ((index 0 (%i+ index 1))) |
---|
572 | ((or (eq index end) (not (find (aref string index) char-bag))) |
---|
573 | (setq left-end index))) |
---|
574 | (do ((index (%i- end 1) (%i- index 1))) |
---|
575 | ((or (%i< index left-end) (not (find (aref string index) char-bag))) |
---|
576 | (setq right-end index))) |
---|
577 | (subseq string left-end (%i+ right-end 1)))) |
---|
578 | |
---|
579 | |
---|
580 | |
---|
581 | (defun copy-symbol (symbol &optional (copy-props nil) &aux new-symbol def) |
---|
582 | "Make and return a new uninterned symbol with the same print name |
---|
583 | as SYMBOL. If COPY-PROPS is false, the new symbol is neither bound |
---|
584 | nor fbound and has no properties, else it has a copy of SYMBOL's |
---|
585 | function, value and property list." |
---|
586 | (setq new-symbol (make-symbol (symbol-name symbol))) |
---|
587 | (when copy-props |
---|
588 | (when (boundp symbol) |
---|
589 | (set new-symbol (symbol-value symbol))) |
---|
590 | (when (setq def (fboundp symbol)) |
---|
591 | ;;;Shouldn't err out on macros/special forms. |
---|
592 | (%fhave new-symbol def)) |
---|
593 | (set-symbol-plist new-symbol (copy-list (symbol-plist symbol)))) |
---|
594 | new-symbol) |
---|
595 | |
---|
596 | |
---|
597 | (defvar %gentemp-counter 0 |
---|
598 | "Counter for generating unique GENTEMP symbols.") |
---|
599 | |
---|
600 | (defun gentemp (&optional (prefix "T") (package *package*)) |
---|
601 | "Creates a new symbol interned in package PACKAGE with the given PREFIX." |
---|
602 | (loop |
---|
603 | (let* ((new-pname (%str-cat (ensure-simple-string prefix) |
---|
604 | (%integer-to-string %gentemp-counter))) |
---|
605 | (sym (find-symbol new-pname package))) |
---|
606 | (if sym |
---|
607 | (setq %gentemp-counter (%i+ %gentemp-counter 1)) |
---|
608 | (return (values (intern new-pname package))))))) ; 1 value. |
---|
609 | |
---|
610 | |
---|
611 | |
---|
612 | |
---|
613 | (defun add-gc-hook (hook-function &optional (which-hook :pre-gc)) |
---|
614 | (ecase which-hook |
---|
615 | (:pre-gc |
---|
616 | (pushnew hook-function *pre-gc-hook-list*) |
---|
617 | (setq *pre-gc-hook* #'(lambda () |
---|
618 | (dolist (hook *pre-gc-hook-list*) |
---|
619 | (funcall hook))))) |
---|
620 | (:post-gc |
---|
621 | (pushnew hook-function *post-gc-hook-list*) |
---|
622 | (setq *post-gc-hook* #'(lambda () |
---|
623 | (dolist (hook *post-gc-hook-list*) |
---|
624 | (funcall hook)))))) |
---|
625 | hook-function) |
---|
626 | |
---|
627 | (defun remove-gc-hook (hook-function &optional (which-hook :pre-gc)) |
---|
628 | (ecase which-hook |
---|
629 | (:pre-gc |
---|
630 | (unless (setq *pre-gc-hook-list* (delq hook-function *pre-gc-hook-list*)) |
---|
631 | (setq *pre-gc-hook* nil))) |
---|
632 | (:post-gc |
---|
633 | (unless (setq *post-gc-hook-list* (delq hook-function *post-gc-hook-list*)) |
---|
634 | (setq *post-gc-hook* nil))))) |
---|
635 | |
---|
636 | |
---|
637 | |
---|
638 | |
---|
639 | |
---|
640 | |
---|
641 | (defun find-method-by-names (name qualifiers specializers) |
---|
642 | (let ((gf (fboundp name))) |
---|
643 | (when gf |
---|
644 | (if (not (standard-generic-function-p gf)) |
---|
645 | (error "~S is not a generic-function." gf) |
---|
646 | (let ((methods (%gf-methods gf))) |
---|
647 | (when methods |
---|
648 | (let* ((spec-len (length (%method-specializers (car methods)))) |
---|
649 | (new-specs (make-list spec-len :initial-element (find-class t)))) |
---|
650 | (declare (dynamic-extent new-specs)) |
---|
651 | (do ((specs specializers (cdr specs)) |
---|
652 | (nspecs new-specs (cdr nspecs))) |
---|
653 | ((or (null specs) (null nspecs))) |
---|
654 | (let ((s (car specs))) |
---|
655 | (rplaca nspecs (if (consp s) s (find-class s nil))))) |
---|
656 | (find-method gf qualifiers new-specs nil)))))))) |
---|
657 | |
---|
658 | |
---|
659 | |
---|
660 | (defun get-string-from-user (prompt) |
---|
661 | (with-terminal-input |
---|
662 | (format *query-io* "~&~a " prompt) |
---|
663 | (force-output *query-io*) |
---|
664 | (clear-input *query-io*) |
---|
665 | (values (read-line *query-io*)))) |
---|
666 | |
---|
667 | |
---|
668 | (defun select-item-from-list (list &key (window-title "Select one of the following") |
---|
669 | (table-print-function #'prin1) |
---|
670 | &allow-other-keys) |
---|
671 | (block get-answer |
---|
672 | (with-terminal-input |
---|
673 | (format *query-io* "~a:~%" window-title) |
---|
674 | (loop |
---|
675 | (catch :redisplay |
---|
676 | (do* ((l list (cdr l)) |
---|
677 | (i 0 (1+ i)) |
---|
678 | (item (car l) (car l))) |
---|
679 | ((null l)) |
---|
680 | (declare (fixnum i)) |
---|
681 | (format *query-io* "~& ~d: " i) |
---|
682 | (funcall table-print-function item *query-io*)) |
---|
683 | (loop |
---|
684 | (fresh-line *query-io*) |
---|
685 | (let* ((string (get-string-from-user "Selection [number,q,r,?]:")) |
---|
686 | (value (ignore-errors |
---|
687 | (let* ((*package* *keyword-package*)) |
---|
688 | (read-from-string string nil))))) |
---|
689 | (cond ((eq value :q) (throw :cancel t)) |
---|
690 | ((eq value :r) (throw :redisplay t)) |
---|
691 | ((eq value :?) |
---|
692 | (format *query-io* "~%Enter the number of the selection, ~% r to redisplay, ~% q to cancel or ~% ? to show this message again.")) |
---|
693 | ((and (typep value 'unsigned-byte) |
---|
694 | (< value (length list))) |
---|
695 | (return-from get-answer (list (nth value list)))))))))))) |
---|
696 | |
---|
697 | ;;; There should ideally be some way to override the UI (such as |
---|
698 | ;;; it is ...) here. |
---|
699 | ;;; More generally, this either |
---|
700 | ;;; a) shouldn't exist, or |
---|
701 | ;;; b) should do more sanity-checking |
---|
702 | (defun choose-file-dialog (&key file-types (prompt "File name:")) |
---|
703 | (%choose-file-dialog t prompt file-types)) |
---|
704 | |
---|
705 | (defun choose-new-file-dialog (&key prompt) |
---|
706 | (%choose-file-dialog nil prompt nil)) |
---|
707 | |
---|
708 | (defun %choose-file-dialog (must-exist prompt file-types) |
---|
709 | (loop |
---|
710 | (let* ((namestring (get-string-from-user prompt)) |
---|
711 | (pathname (ignore-errors (pathname namestring))) |
---|
712 | (exists (and pathname (probe-file pathname)))) |
---|
713 | (when (and (if must-exist exists) |
---|
714 | (or (null file-types) |
---|
715 | (member (pathname-type pathname) |
---|
716 | file-types :test #'equal))) |
---|
717 | (return pathname)) |
---|
718 | (if (not exists) |
---|
719 | (format *query-io* "~&~s does not exist." namestring) |
---|
720 | (format *query-io* "~&Type of ~s is not one of ~{~a~}" |
---|
721 | namestring file-types))))) |
---|
722 | |
---|
723 | (defparameter *overwrite-dialog-hook* nil) |
---|
724 | (defun overwrite-dialog (filename prompt) |
---|
725 | (if *overwrite-dialog-hook* |
---|
726 | (funcall *overwrite-dialog-hook* filename prompt) |
---|
727 | t)) |
---|
728 | |
---|
729 | ;;; Might want to have some other entry for, e.g., the inspector |
---|
730 | ;;; and to let it get its hands on the list header returned by |
---|
731 | ;;; disassemble-ppc-function. Maybe disassemble-ppc-function |
---|
732 | ;;; should take care of "normalizing" the code-vector ? |
---|
733 | (defun disassemble (thing) |
---|
734 | "Disassemble the compiled code associated with OBJECT, which can be a |
---|
735 | function, a lambda expression, or a symbol with a function definition. If |
---|
736 | it is not already compiled, the compiler is called to produce something to |
---|
737 | disassemble." |
---|
738 | (#+ppc-target ppc-xdisassemble |
---|
739 | #+x8632-target x8632-xdisassemble |
---|
740 | #+x8664-target x8664-xdisassemble |
---|
741 | (require-type (function-for-disassembly thing) 'compiled-function))) |
---|
742 | |
---|
743 | (defun function-for-disassembly (thing) |
---|
744 | (let* ((fun thing)) |
---|
745 | ;; CLHS says that DISASSEMBLE should signal a type error if its |
---|
746 | ;; argument isn't a function designator. Hard to imagine any |
---|
747 | ;; code depending on that ... |
---|
748 | ;;(when (typep fun 'standard-method) (setq fun (%method-function fun))) |
---|
749 | (when (or (symbolp fun) |
---|
750 | (and (consp fun) (neq (%car fun) 'lambda))) |
---|
751 | (setq fun (fboundp thing)) |
---|
752 | (when (and (symbolp thing) (not (functionp fun))) |
---|
753 | (setq fun (macro-function thing)))) |
---|
754 | (if (typep fun 'compiled-lexical-closure) |
---|
755 | (setq fun (closure-function fun))) |
---|
756 | (when (lambda-expression-p fun) |
---|
757 | (setq fun (compile-named-function fun))) |
---|
758 | fun)) |
---|
759 | |
---|
760 | (%fhave 'df #'disassemble) |
---|
761 | |
---|
762 | (defun string-sans-most-whitespace (string &optional (max-length (length string))) |
---|
763 | (with-output-to-string (sans-whitespace) |
---|
764 | (loop |
---|
765 | for count below max-length |
---|
766 | for char across string |
---|
767 | with just-saw-space = nil |
---|
768 | if (member char '(#\Space #\Tab #\Newline #\Return #\Formfeed)) |
---|
769 | do (if just-saw-space |
---|
770 | (decf count) |
---|
771 | (write-char #\Space sans-whitespace)) |
---|
772 | and do (setf just-saw-space t) |
---|
773 | else |
---|
774 | do (setf just-saw-space nil) |
---|
775 | and do (write-char char sans-whitespace)))) |
---|
776 | |
---|
777 | |
---|
778 | (defloadvar *use-cygwin-svn* |
---|
779 | #+windows-target (not (null (getenv "CYGWIN"))) |
---|
780 | #-windows-target nil) |
---|
781 | |
---|
782 | (defun svn-info-component (component) |
---|
783 | (let* ((component-length (length component))) |
---|
784 | (with-output-to-string (s) |
---|
785 | (multiple-value-bind (status exit-code) |
---|
786 | (external-process-status |
---|
787 | (run-program "svn" (list "info" (native-translated-namestring "ccl:")):output s)) |
---|
788 | (when (and (eq :exited status) (zerop exit-code)) |
---|
789 | (with-input-from-string (output (get-output-stream-string s)) |
---|
790 | (do* ((line (read-line output nil nil) (read-line output nil nil))) |
---|
791 | ((null line)) |
---|
792 | (when (and (>= (length line) component-length) |
---|
793 | (string= component line :end2 component-length)) |
---|
794 | (return-from svn-info-component |
---|
795 | (string-trim " " (subseq line component-length))))))))))) |
---|
796 | |
---|
797 | (defun svn-url () (svn-info-component "URL:")) |
---|
798 | (defun svn-repository () (svn-info-component "Repository Root:")) |
---|
799 | |
---|
800 | ;;; Try to say something about what tree (trunk, a branch, a release) |
---|
801 | ;;; we were built from. If the URL (relative to the repository) |
---|
802 | ;;; starts with "branches", return the second component of the |
---|
803 | ;;; relative URL, otherwise return the first component. |
---|
804 | (defun svn-tree () |
---|
805 | (let* ((repo (svn-repository)) |
---|
806 | (url (svn-url))) |
---|
807 | (or |
---|
808 | (if (and repo url) |
---|
809 | (let* ((repo-len (length repo))) |
---|
810 | (when (and (> (length url) repo-len) |
---|
811 | (string= repo url :end2 repo-len)) |
---|
812 | ;; Cheat: do pathname parsing here. |
---|
813 | (let* ((path (pathname (ensure-directory-namestring (subseq url repo-len)))) |
---|
814 | (dir (cdr (pathname-directory path)))) |
---|
815 | (when (string= "ccl" (car (last dir))) |
---|
816 | (let* ((base (car dir))) |
---|
817 | (unless (or (string= base "release") |
---|
818 | (string= base "releases")) |
---|
819 | (if (string= base "branches") |
---|
820 | (cadr dir) |
---|
821 | (car dir)))))))))))) |
---|
822 | |
---|
823 | |
---|
824 | |
---|
825 | |
---|
826 | |
---|
827 | (defun local-svn-revision () |
---|
828 | (or |
---|
829 | ;; svn2cvs uses a .svnrev file to sync CVS and SVN; if present, |
---|
830 | ;; it contains the svn revision in decimal. |
---|
831 | (with-open-file (f "ccl:\\.svnrev" :direction :input :if-does-not-exist nil) |
---|
832 | (when f (read f))) |
---|
833 | (with-output-to-string (s) |
---|
834 | (let* ((root (native-translated-namestring "ccl:"))) |
---|
835 | (when *use-cygwin-svn* |
---|
836 | (setq root (cygpath root))) |
---|
837 | (multiple-value-bind (status exit-code) |
---|
838 | (external-process-status |
---|
839 | (run-program "svnversion" (list (native-translated-namestring "ccl:") (or (svn-url) "")):output s)) |
---|
840 | (when (and (eq :exited status) (zerop exit-code)) |
---|
841 | (with-input-from-string (output (get-output-stream-string s)) |
---|
842 | (let* ((line (read-line output nil nil))) |
---|
843 | (when (and line (parse-integer line :junk-allowed t) ) |
---|
844 | (return-from local-svn-revision line)))))))))) |
---|
845 | |
---|
846 | |
---|
847 | ;;; Scan the heap, collecting infomation on the primitive object types |
---|
848 | ;;; found. Report that information. |
---|
849 | |
---|
850 | (defun heap-utilization (&key (stream *debug-io*) |
---|
851 | (gc-first t)) |
---|
852 | (let* ((nconses 0) |
---|
853 | (nvectors (make-array 256)) |
---|
854 | (vector-sizes (make-array 256)) |
---|
855 | (array-size-function (arch::target-array-data-size-function |
---|
856 | (backend-target-arch *host-backend*)))) |
---|
857 | (declare (type (simple-vector 256) nvectors vector-sizes) |
---|
858 | (dynamic-extent nvectors vector-sizes)) |
---|
859 | (when gc-first (gc)) |
---|
860 | (%map-areas (lambda (thing) |
---|
861 | (if (listp thing) |
---|
862 | (incf nconses) |
---|
863 | (let* ((typecode (typecode thing))) |
---|
864 | (incf (aref nvectors typecode)) |
---|
865 | (incf (aref vector-sizes typecode) |
---|
866 | (funcall array-size-function typecode (uvsize thing))))))) |
---|
867 | (report-heap-utilization stream nconses nvectors vector-sizes) |
---|
868 | (values))) |
---|
869 | |
---|
870 | (defvar *heap-utilization-vector-type-names* |
---|
871 | (let* ((a (make-array 256))) |
---|
872 | #+x8664-target |
---|
873 | (dotimes (i 256) |
---|
874 | (let* ((fulltag (logand i x8664::fulltagmask)) |
---|
875 | (names-vector |
---|
876 | (cond ((= fulltag x8664::fulltag-nodeheader-0) |
---|
877 | *nodeheader-0-types*) |
---|
878 | ((= fulltag x8664::fulltag-nodeheader-1) |
---|
879 | *nodeheader-1-types*) |
---|
880 | ((= fulltag x8664::fulltag-immheader-0) |
---|
881 | *immheader-0-types*) |
---|
882 | ((= fulltag x8664::fulltag-immheader-1) |
---|
883 | *immheader-1-types*) |
---|
884 | ((= fulltag x8664::fulltag-immheader-2) |
---|
885 | *immheader-2-types*))) |
---|
886 | (name (if names-vector |
---|
887 | (aref names-vector (ash i -4))))) |
---|
888 | ;; Special-case a few things ... |
---|
889 | (if (eq name 'symbol-vector) |
---|
890 | (setq name 'symbol) |
---|
891 | (if (eq name 'function-vector) |
---|
892 | (setq name 'function))) |
---|
893 | (setf (aref a i) name))) |
---|
894 | #+ppc64-target |
---|
895 | (dotimes (i 256) |
---|
896 | (let* ((lowtag (logand i ppc64::lowtagmask))) |
---|
897 | (setf (%svref a i) |
---|
898 | (cond ((= lowtag ppc64::lowtag-immheader) |
---|
899 | (%svref *immheader-types* (ash i -2))) |
---|
900 | ((= lowtag ppc64::lowtag-nodeheader) |
---|
901 | (%svref *nodeheader-types* (ash i -2))))))) |
---|
902 | #+(or ppc32-target x8632-target) |
---|
903 | (dotimes (i 256) |
---|
904 | (let* ((fulltag (logand i target::fulltagmask))) |
---|
905 | (setf (%svref a i) |
---|
906 | (cond ((= fulltag target::fulltag-immheader) |
---|
907 | (%svref *immheader-types* (ash i -3))) |
---|
908 | ((= fulltag target::fulltag-nodeheader) |
---|
909 | (%svref *nodeheader-types* (ash i -3))))))) |
---|
910 | a)) |
---|
911 | |
---|
912 | |
---|
913 | |
---|
914 | (defun report-heap-utilization (out nconses nvectors vector-sizes) |
---|
915 | (format out "~&Object type~42tCount~50tTotal Size in Bytes") |
---|
916 | (format out "~&CONS~36t~12d~48t~16d" nconses (* nconses target::cons.size)) |
---|
917 | (dotimes (i (length nvectors)) |
---|
918 | (let* ((count (aref nvectors i)) |
---|
919 | (sizes (aref vector-sizes i))) |
---|
920 | (unless (zerop count) |
---|
921 | (format out "~&~a~36t~12d~48t~16d" (aref *heap-utilization-vector-type-names* i) count sizes))))) |
---|
922 | |
---|
923 | ;; The number of words to allocate for static conses when the user requests |
---|
924 | ;; one and we don't have any left over |
---|
925 | (defparameter *static-cons-chunk* 1048576) |
---|
926 | |
---|
927 | (defun initialize-static-cons () |
---|
928 | "Activates collection of garbage conses in the static-conses |
---|
929 | list and allocates initial static conses." |
---|
930 | ; There might be a race here when multiple threads call this |
---|
931 | ; function. However, the discarded static conses will become |
---|
932 | ; garbage and be added right back to the list. No harm here |
---|
933 | ; except for additional garbage collections. |
---|
934 | (%set-kernel-global 'static-conses nil) |
---|
935 | (allocate-static-conses)) |
---|
936 | |
---|
937 | (defun allocate-static-conses () |
---|
938 | "Allocates some memory, freezes it and lets it become garbage. |
---|
939 | This will add the memory to the list of free static conses." |
---|
940 | (let* ((nfullgc (full-gccount))) |
---|
941 | (multiple-value-bind (head tail) |
---|
942 | (%allocate-list 0 *static-cons-chunk*) |
---|
943 | (if (eql (full-gccount) nfullgc) |
---|
944 | (freeze) |
---|
945 | (flash-freeze)) |
---|
946 | (%augment-static-conses head tail)))) |
---|
947 | |
---|
948 | (defun static-cons (car-value cdr-value) |
---|
949 | "Allocates a cons cell that doesn't move on garbage collection, |
---|
950 | and thus doesn't trigger re-hashing when used as a key in a hash |
---|
951 | table. Usage is equivalent to regular CONS." |
---|
952 | (when (eq (%get-kernel-global 'static-conses) 0) |
---|
953 | (initialize-static-cons)) |
---|
954 | (let ((cell (%atomic-pop-static-cons))) |
---|
955 | (if cell |
---|
956 | (progn |
---|
957 | (setf (car cell) car-value) |
---|
958 | (setf (cdr cell) cdr-value) |
---|
959 | cell) |
---|
960 | (progn |
---|
961 | (allocate-static-conses) |
---|
962 | (static-cons car-value cdr-value))))) |
---|
963 | |
---|
964 | |
---|
965 | (defparameter *weak-gc-method-names* |
---|
966 | '((:traditional . 0) |
---|
967 | (:non-circular . 1))) |
---|
968 | |
---|
969 | |
---|
970 | (defun weak-gc-method () |
---|
971 | (or (car (rassoc (%get-kernel-global 'weak-gc-method) |
---|
972 | *weak-gc-method-names*)) |
---|
973 | :traditional)) |
---|
974 | |
---|
975 | |
---|
976 | (defun (setf weak-gc-method) (name) |
---|
977 | (setf (%get-kernel-global 'weak-gc-method) |
---|
978 | (or (cdr (assoc name *weak-gc-method-names*)) |
---|
979 | 0)) |
---|
980 | name) |
---|
981 | |
---|
982 | (defun %lock-whostate-string (string lock) |
---|
983 | (with-standard-io-syntax |
---|
984 | (format nil "~a for ~a ~@[~a ~]@ #x~x" |
---|
985 | string |
---|
986 | (%svref lock target::lock.kind-cell) |
---|
987 | (lock-name lock) |
---|
988 | (%ptr-to-int (%svref lock target::lock._value-cell))))) |
---|