Mercurial > hg > xemacs-beta
comparison lisp/utils/find-gc.el @ 0:376386a54a3c r19-14
Import from CVS: tag r19-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:45:50 +0200 |
parents | |
children | 0293115a14e9 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:376386a54a3c |
---|---|
1 ;;; find-gc.el --- detect functions that call the garbage collector | |
2 | |
3 ;; Copyright (C) 1992 Free Software Foundation, Inc. | |
4 | |
5 ;; Maintainer: FSF | |
6 ;; Keywords: maint | |
7 | |
8 ;; This file is part of XEmacs. | |
9 | |
10 ;; XEmacs is free software; you can redistribute it and/or modify it | |
11 ;; under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; XEmacs is distributed in the hope that it will be useful, but | |
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 ;; General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free | |
22 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | |
24 ;;; Synched up with: FSF 19.30. | |
25 | |
26 ;;; #### before this is really usable, it should be rewritten to call | |
27 ;;; Makefile to compile the files. | |
28 | |
29 ;;; Commentary: | |
30 | |
31 ;;; Produce in unsafe-list the set of all functions that may invoke GC. | |
32 ;;; This expects the Emacs sources to live in emacs-source-directory. | |
33 ;;; It creates a temporary working directory /tmp/esrc. | |
34 | |
35 ;;; Code: | |
36 | |
37 ;; Set this to point to your XEmacs source directory. | |
38 (setq emacs-source-directory "/net/prosper/opt/xemacs/editor/src") | |
39 | |
40 ;; Set this to the include directories neeed for compilation. | |
41 (setq include-directives "-I/net/prosper/opt/xemacs/editor/src -I/usr/dt/include -I/net/prosper/opt/SUNWmotif/include -I/net/prosper/opt/xemacs/editor/import/xpm/include -I/net/prosper/opt/xemacs/editor/import/include -I/usr/demo/SOUND/include -I/usr/openwin/include -I/usr/openwin/include/desktop -I/usr/openwin/include/desktop -I/net/prosper/opt/xemacs/editor/src/../lwlib -g -v -DNeedFunctionPrototypes -xildoff -I/usr/dt/include -I/net/prosper/opt/SUNWmotif/include -I/net/prosper/opt/xemacs/editor/import/xpm/include -I/net/prosper/opt/xemacs/editor/import/include -I/usr/demo/SOUND/include -I/usr/demo/SOUND/include") | |
42 | |
43 ;; Set this to the source files you want to check. | |
44 (setq source-files | |
45 '( | |
46 "EmacsFrame.c" "EmacsManager.c" "EmacsShell.c" "abbrev.c" "alloc.c" | |
47 "blocktype.c" "buffer.c" "bytecode.c" "callint.c" "callproc.c" "casefiddle.c" | |
48 "casetab.c" "cm.c" "cmds.c" "data.c" "debug.c" "device-stream.c" | |
49 "device-tty.c" "device-x.c" "device.c" "dired.c" "doc.c" "doprnt.c" | |
50 "dynarr.c""editfns.c" "elhash.c" "emacs.c" "eval.c" "event-Xt.c" | |
51 "event-stream.c" "event-tty.c" "events.c" "extents.c" "faces.c" "fileio.c" | |
52 "filelock.c" "filemode.c" "floatfns.c" "fns.c" "font-lock.c" "frame-tty.c" | |
53 "frame-x.c" "frame.c" "getloadavg.c" "glyphs.c" "gmalloc.c" "hash.c" | |
54 "indent.c" "insdel.c" "intl.c" "keyboard.c" "keymap.c" "lastfile.c" "lread.c" | |
55 "lstream.c" "macros.c" "marker.c" "md5.c" "menubar-x.c" "menubar.c" | |
56 "minibuf.c" "objects-x.c" "objects.c" "opaque.c" "print.c" "process.c" | |
57 "pure.c" "redisplay-output.c" "redisplay-tty.c" "redisplay-x.c" "redisplay.c" | |
58 "regex.c" "scrollbar.c" "search.c" "sound.c" "specifier.c" "sunplay.c" | |
59 "sunpro.c" "symbols.c" "syntax.c" "sysdep.c" "terminfo.c" "toolbar-x.c" | |
60 "toolbar.c" "tooltalk.c" "undo.c" "unexsol2.c" "vm-limit.c" "window.c" | |
61 "xgccache.c" "xselect.c")) | |
62 | |
63 ;;; | |
64 | |
65 (defun find-gc-unsafe () | |
66 (trace-call-tree nil) | |
67 (trace-use-tree) | |
68 (find-unsafe-funcs 'Fgarbage_collect) | |
69 (setq unsafe-list (sort unsafe-list | |
70 (function (lambda (x y) | |
71 (string-lessp (car x) (car y)))))) | |
72 (princ (format "%s\n" unsafe-list)) | |
73 (setq unsafe-list nil) | |
74 (find-unsafe-funcs 'Fgarbage_collect_1) | |
75 (setq unsafe-list (sort unsafe-list | |
76 (function (lambda (x y) | |
77 (string-lessp (car x) (car y)))))) | |
78 (princ (format "%s\n" unsafe-list))) | |
79 | |
80 | |
81 ;;; This does a depth-first search to find all functions that can | |
82 ;;; ultimately call the function "target". The result is an a-list | |
83 ;;; in unsafe-list; the cars are the unsafe functions, and the cdrs | |
84 ;;; are (one of) the unsafe functions that these functions directly | |
85 ;;; call. | |
86 | |
87 (defun find-unsafe-funcs (target) | |
88 (setq unsafe-list (list (list target))) | |
89 (trace-unsafe target)) | |
90 | |
91 (defun trace-unsafe (func) | |
92 (let ((used (assq func subrs-used))) | |
93 (or used | |
94 (error "No subrs-used for %s" (car unsafe-list))) | |
95 (while (setq used (cdr used)) | |
96 (or (assq (car used) unsafe-list) | |
97 (memq (car used) noreturn-list) | |
98 (progn | |
99 (setq unsafe-list (cons (cons (car used) func) unsafe-list)) | |
100 (trace-unsafe (car used))))))) | |
101 | |
102 | |
103 ;;; Functions on this list are safe, even if they appear to be able | |
104 ;;; to call the target. | |
105 | |
106 (setq noreturn-list '( signal_error error Fthrow wrong_type_argument )) | |
107 | |
108 | |
109 ;;; This produces an a-list of functions in subrs-called. The cdr of | |
110 ;;; each entry is a list of functions which the function in car calls. | |
111 | |
112 (defun trace-call-tree (&optional already-setup) | |
113 (or already-setup | |
114 (progn | |
115 (princ (format "Setting up directories...\n")) | |
116 ;; Gee, wouldn't a built-in "system" function be handy here. | |
117 (call-process "sh" nil nil nil "-c" "rm -rf /tmp/esrc") | |
118 (call-process "sh" nil nil nil "-c" "mkdir /tmp/esrc") | |
119 (call-process "sh" nil nil nil "-c" | |
120 (format "ln -s %s/*.[ch] /tmp/esrc" | |
121 emacs-source-directory)))) | |
122 (save-excursion | |
123 (set-buffer (get-buffer-create "*Trace Call Tree*")) | |
124 (setq subrs-called nil) | |
125 (let ((case-fold-search nil) | |
126 (files source-files) | |
127 name entry) | |
128 (while files | |
129 (princ (format "Compiling %s...\n" (car files))) | |
130 (call-process "sh" nil nil nil "-c" | |
131 (format "cd /tmp/esrc; gcc -dr -c %s /tmp/esrc/%s -o /dev/null" | |
132 include-directives (car files))) | |
133 (erase-buffer) | |
134 (insert-file-contents (concat "/tmp/esrc/" (car files) ".rtl")) | |
135 (while (re-search-forward ";; Function \\|(call_insn " nil t) | |
136 (if (= (char-after (- (point) 3)) ?o) | |
137 (progn | |
138 (looking-at "[a-zA-Z0-9_]+") | |
139 (setq name (intern (buffer-substring (match-beginning 0) | |
140 (match-end 0)))) | |
141 (princ (format "%s : %s\n" (car files) name)) | |
142 (setq entry (list name) | |
143 subrs-called (cons entry subrs-called))) | |
144 (if (looking-at ".*\n?.*\"\\([A-Za-z0-9_]+\\)\"") | |
145 (progn | |
146 (setq name (intern (buffer-substring (match-beginning 1) | |
147 (match-end 1)))) | |
148 (or (memq name (cdr entry)) | |
149 (setcdr entry (cons name (cdr entry)))))))) | |
150 ;;(delete-file (concat "/tmp/esrc/" (car files) ".rtl")) | |
151 (setq files (cdr files)))))) | |
152 | |
153 | |
154 ;;; This produces an inverted a-list in subrs-used. The cdr of each | |
155 ;;; entry is a list of functions that call the function in car. | |
156 | |
157 (defun trace-use-tree () | |
158 (setq subrs-used (mapcar 'list (mapcar 'car subrs-called))) | |
159 (let ((ptr subrs-called) | |
160 p2 found) | |
161 (while ptr | |
162 (setq p2 (car ptr)) | |
163 (while (setq p2 (cdr p2)) | |
164 (if (setq found (assq (car p2) subrs-used)) | |
165 (setcdr found (cons (car (car ptr)) (cdr found))))) | |
166 (setq ptr (cdr ptr))))) | |
167 | |
168 ;;; find-gc.el ends here |