SCM

SCM Repository

[xemacs] View of /XEmacs/packages/xemacs-packages/xemacs-devel/find-gc.el
ViewVC logotype

View of /XEmacs/packages/xemacs-packages/xemacs-devel/find-gc.el

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (download) (annotate)
Sun Mar 8 16:22:39 1998 UTC (15 years, 2 months ago) by steveb
Branch: MAIN
CVS Tags: sumo-2000-07-06, xemacs-devel-1_40, xemacs-devel-1_41, xemacs-devel-1_42, sumo-2007-04-27, xemacs-devel-1_45, xemacs-devel-1_46, sumo-2002-07-20, xemacs-devel-1_48, xemacs-devel-1_49, sumo-2001-12-11, sumo-2009-02-17, sumo-2005-05-05, Sumo-Jan-10-2001, sumo-2003-06-29, xemacs-devel-1_35, xemacs-devel-1_37, xemacs-devel-1_36, xemacs-devel-1_31, xemacs-devel-1_30, xemacs-devel-1_33, xemacs-devel-1_32, xemacs-devel-1_39, xemacs-devel-1_38, sumo-2005-07-15, sumo-2005-03-07, sumo-2006-12-21, sumo-2000-01-15, xemacs-devel-1_44, xemacs-sumo-2000-24-10, xemacs-devel-1_47, pre-pkg-build-changes, xemacs-devel-1_26, xemacs-devel-1_27, xemacs-devel-1_24, xemacs-devel-1_25, pre-sumo, xemacs-devel-1_28, sumo-2001-03-15, xemacs-devel-1_56, sumo-2000-09-04, xemacs-devel-1_55, sumo-1999-12-09, sumo-2005-12-08, sumo-feb_2001, sumo-2003-10-03, sumo-2001-09-29, sumo-1999-12-15, sumo-1999-12-11, sumo-2002-03-12, sumo-2001-12-16, xemacs-devel-1_80, xemacs-devel-1_81, xemacs-devel-1_82, sumo-2004-02-02, package-release-20000710, sumo-2004-05-17, sumo-feb_2001a, sumo-2002-01-19, xemacs-devel-1_79, xemacs-devel-1_78, sumo-2000-05-24, xemacs-devel-1_71, xemacs-devel-1_70, xemacs-devel-1_73, xemacs-devel-1_72, xemacs-devel-1_75, xemacs-devel-1_74, xemacs-devel-1_77, xemacs-devel-1_76, pending-sumo-release, sumo-2003-11-13, sumo-2004-08-18, XEMACS_BEFORE_MOVE_TO_SUNSITE_DK, xemacs-devel-1_68, xemacs-devel-1_69, xemacs-devel-1_62, xemacs-devel-1_63, xemacs-devel-1_60, xemacs-devel-1_61, xemacs-devel-1_66, xemacs-devel-1_67, xemacs-devel-1_64, xemacs-devel-1_65, new-tree-start, sumo-2001-12-13, sumo-2002-05-22, sumo-current, sumo-2000-01-24, sumo-2001-01-15, sumo-2005-01-18, xemacs-devel-1_59, xemacs-devel-1_58, xemacs-devel-1_57, sumo-2010-07-27, sumo-2002-03-29, xemacs-devel-1_54, xemacs-devel-1_53, xemacs-devel-1_52, xemacs-devel-1_50, sumo-2003-08-31, sumo-2003-04-14, sumo-2003-04-12, sumo-2002-09-19, xemacs-sumo-2001-07-09, xemacs-sumo-2001-07-08, sumo-2003-02-05, sumo-2006-05-10, HEAD
Changes since 1.1: +64 -73 lines
Updates to find-func.el and fixes for find-gc.el.
;;; find-gc.el --- detect functions that call the garbage collector

;; Copyright (C) 1992 Free Software Foundation, Inc.

;; Maintainer: FSF
;; Keywords: maint

;; This file is part of XEmacs.

;; XEmacs is free software; you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; XEmacs is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with XEmacs; see the file COPYING.  If not, write to the 
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

;;; Synched up with: FSF 19.30.

;;; #### before this is really usable, it should be rewritten to call
;;; Makefile to compile the files.

;;; Commentary:

;;; Produce in unsafe-list the set of all functions that may invoke GC.
;;; This expects the Emacs sources to live in emacs-source-directory.
;;; It creates a temporary working directory /tmp/esrc.

;;; Code:

(defvar unsafe-list nil)
(defvar subrs-used nil)
(defvar subrs-called nil)

;; Set this to point to your XEmacs source directory.
(defvar emacs-source-directory "/usr/src/xemacs/xemacs-20/src")

;;; Functions on this list are safe, even if they appear to be able
;;; to call the target.

(defvar noreturn-list '(signal_error error Fthrow wrong_type_argument))

;;; Try to load generated source-files
(load-library (concat emacs-source-directory "/../lisp/source-files.el"))

(defvar source-files nil
  "Set this to the source files you want to check.")

;;;

(defun find-gc-unsafe ()
  (setq subrs-used nil)
  (trace-call-tree t nil)
  (trace-use-tree)
  (set-buffer (get-buffer-create "*gc-tmp*"))
  (erase-buffer)
  (find-unsafe-funcs 'Fgarbage_collect)
  (setq unsafe-list (sort unsafe-list 'find-gc-sort-p))
  (insert (format "%s\n" unsafe-list))
  (setq unsafe-list nil)
  (find-unsafe-funcs 'garbage_collect_1)
  (setq unsafe-list (sort unsafe-list 'find-gc-sort-p))
  (insert (format "%s\n" unsafe-list))
  (goto-char (point-min))
  (while (search-forward ") (" nil t)
    (replace-match ")
 (" nil t))
  )

(defun find-gc-sort-p (x y)
  (string-lessp (car x) (car y)))

;;; This does a depth-first search to find all functions that can
;;; ultimately call the function "target".  The result is an a-list
;;; in unsafe-list; the cars are the unsafe functions, and the cdrs
;;; are (one of) the unsafe functions that these functions directly
;;; call.

(defun find-unsafe-funcs (target)
  (setq unsafe-list (list (list target)))
  (trace-unsafe target))

(defun trace-unsafe (func)
  (let ((used (assq func subrs-used)))
    (or used
	(error "No subrs-used for %s" (car unsafe-list)))
    (while (setq used (cdr used))
      (or (assq (car used) unsafe-list)
	  (memq (car used) noreturn-list)
	  (progn
	    (setq unsafe-list (cons (cons (car used) func) unsafe-list))
	    (trace-unsafe (car used)))))))


;;; This produces an a-list of functions in subrs-called.  The cdr of
;;; each entry is a list of functions which the function in car calls.

(defun trace-call-tree (&optional make-all delete-after)
  (save-excursion
    (setq subrs-called nil)
    (let ((case-fold-search nil)
	  name entry file)
      ;; Stage one, make rtl files with make
      (if make-all
	  (call-process 
	   "sh" nil nil nil "-c" 
	   (format "cd %s; make dortl" emacs-source-directory file))
	(dolist (file source-files)
	  (princ (format "Compiling %s...\n" file))
	  (call-process 
	   "sh" nil nil nil "-c" 
	   (format "cd %s; make %s.rtl" emacs-source-directory file))))
      (set-buffer (get-buffer-create "*Trace Call Tree*"))
      ;; Stage two, process them
      (dolist (file source-files)
	(erase-buffer)
	(insert-file-contents (concat emacs-source-directory "/" file ".rtl"))
	(while (re-search-forward ";; Function \\|(call_insn " nil t)
          (if (= (char-after (- (point) 3)) ?o)
              (progn
                (looking-at "[a-zA-Z0-9_]+")
                (setq name (intern (buffer-substring (match-beginning 0)
                                                     (match-end 0))))
                (princ (format "%s : %s\n" file name))
                (setq entry (list name)
                      subrs-called (cons entry subrs-called)))
            (if (looking-at ".*\n?.*\"\\([A-Za-z0-9_]+\\)\"")
                (progn
                  (setq name (intern (buffer-substring (match-beginning 1)
                                                       (match-end 1))))
                  (or (memq name (cdr entry))
                      (setcdr entry (cons name (cdr entry)))))))))
      (when delete-after
	(dolist (file source-files)
	  (delete-file (concat emacs-source-directory "/" file ".rtl"))))
	    )))


;;; This produces an inverted a-list in subrs-used.  The cdr of each
;;; entry is a list of functions that call the function in car.

(defun trace-use-tree ()
  (setq subrs-used (mapcar 'list (mapcar 'car subrs-called)))
  (let ((ptr subrs-called)
	p2 found)
    (while ptr
      (setq p2 (car ptr))
      (while (setq p2 (cdr p2))
	(if (setq found (assq (car p2) subrs-used))
	    (setcdr found (cons (car (car ptr)) (cdr found)))))
      (setq ptr (cdr ptr)))))

;;; find-gc.el ends here

root@alioth.debian.org
ViewVC Help
Powered by ViewVC 1.0.0  
Powered By FusionForge
Show source