annotate lisp/find-gc.el @ 506:5a33b571a57e

*** empty log message ***
author Jim Blandy <jimb@redhat.com>
date Thu, 16 Jan 1992 22:42:10 +0000
parents 1af8a4d8f39f
children 8a533acedb77
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
123
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 ;;;; find-gc.el
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4 ;;; Produce in unsafe-list the set of all functions that may invoke GC.
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5 ;;; This expects the Emacs sources to live in emacs-source-directory.
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6 ;;; It creates a temporary working directory /tmp/esrc.
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
8 (defun find-gc-unsafe ()
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 (trace-call-tree nil)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10 (trace-use-tree)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 (find-unsafe-funcs 'Fgarbage_collect)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 (setq unsafe-list (sort unsafe-list
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 (function (lambda (x y)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 (string-lessp (car x) (car y))))))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15 )
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 (setq emacs-source-directory "/usr/gnu/src/dist/src")
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20 ;;; This does a depth-first search to find all functions that can
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21 ;;; ultimately call the function "target". The result is an a-list
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22 ;;; in unsafe-list; the cars are the unsafe functions, and the cdrs
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23 ;;; are (one of) the unsafe functions that these functions directly
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24 ;;; call.
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26 (defun find-unsafe-funcs (target)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27 (setq unsafe-list (list (list target)))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28 (trace-unsafe target)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29 )
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31 (defun trace-unsafe (func)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 (let ((used (assq func subrs-used)))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33 (or used
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 (error "No subrs-used for %s" (car unsafe-list)))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 (while (setq used (cdr used))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 (or (assq (car used) unsafe-list)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 (memq (car used) noreturn-list)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38 (progn
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 (setq unsafe-list (cons (cons (car used) func) unsafe-list))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 (trace-unsafe (car used))))))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 )
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 ;;; Functions on this list are safe, even if they appear to be able
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 ;;; to call the target.
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 (setq noreturn-list '( Fsignal Fthrow wrong_type_argument ))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50 ;;; This produces an a-list of functions in subrs-called. The cdr of
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51 ;;; each entry is a list of functions which the function in car calls.
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53 (defun trace-call-tree (&optional already-setup)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54 (message "Setting up directories...")
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55 (or already-setup
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 (progn
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57 ;; Gee, wouldn't a built-in "system" function be handy here.
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 (call-process "csh" nil nil nil "-c" "rm -rf /tmp/esrc")
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59 (call-process "csh" nil nil nil "-c" "mkdir /tmp/esrc")
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60 (call-process "csh" nil nil nil "-c"
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61 (format "ln -s %s/*.[ch] /tmp/esrc"
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62 emacs-source-directory))))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 (save-excursion
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64 (set-buffer (get-buffer-create "*Trace Call Tree*"))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65 (setq subrs-called nil)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66 (let ((case-fold-search nil)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67 (files source-files)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68 name entry)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69 (while files
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70 (message "Compiling %s..." (car files))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71 (call-process "csh" nil nil nil "-c"
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 (format "gcc -dr -c /tmp/esrc/%s -o /dev/null"
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73 (car files)))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74 (erase-buffer)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 (insert-file-contents (concat "/tmp/esrc/" (car files) ".rtl"))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 (while (re-search-forward ";; Function \\|(call_insn " nil t)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77 (if (= (char-after (- (point) 3)) ?o)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78 (progn
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79 (looking-at "[a-zA-Z0-9_]+")
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80 (setq name (intern (buffer-substring (match-beginning 0)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 (match-end 0))))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82 (message "%s : %s" (car files) name)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83 (setq entry (list name)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84 subrs-called (cons entry subrs-called)))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 (if (looking-at ".*\n?.*\"\\([A-Za-z0-9_]+\\)\"")
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 (progn
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 (setq name (intern (buffer-substring (match-beginning 1)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 (match-end 1))))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 (or (memq name (cdr entry))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 (setcdr entry (cons name (cdr entry))))))))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 (delete-file (concat "/tmp/esrc/" (car files) ".rtl"))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92 (setq files (cdr files)))))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 )
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 ;;; This was originally generated directory-files, but there were
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 ;;; too many files there that were not actually compiled. The
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 ;;; list below was created for a HP-UX 7.0 system.
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100 (setq source-files '("dispnew.c" "scroll.c" "xdisp.c" "window.c"
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 "term.c" "cm.c" "emacs.c" "keyboard.c" "macros.c"
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 "keymap.c" "sysdep.c" "buffer.c" "filelock.c"
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103 "insdel.c" "marker.c" "minibuf.c" "fileio.c"
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 "dired.c" "filemode.c" "cmds.c" "casefiddle.c"
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 "indent.c" "search.c" "regex.c" "undo.c"
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 "alloc.c" "data.c" "doc.c" "editfns.c"
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 "callint.c" "eval.c" "fns.c" "print.c" "lread.c"
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108 "abbrev.c" "syntax.c" "unexec.c" "mocklisp.c"
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 "bytecode.c" "process.c" "callproc.c" "doprnt.c"
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 "x11term.c" "x11fns.c"))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113 ;;; This produces an inverted a-list in subrs-used. The cdr of each
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 ;;; entry is a list of functions that call the function in car.
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 (defun trace-use-tree ()
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117 (setq subrs-used (mapcar 'list (mapcar 'car subrs-called)))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118 (let ((ptr subrs-called)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119 p2 found)
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120 (while ptr
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 (setq p2 (car ptr))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122 (while (setq p2 (cdr p2))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123 (if (setq found (assq (car p2) subrs-used))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124 (setcdr found (cons (car (car ptr)) (cdr found)))))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125 (setq ptr (cdr ptr))))
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126 )
1af8a4d8f39f Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127