annotate src/gc.c @ 5334:b249c479f9e1

Replace some C++ comments with C89-style /* */ comments, mc-alloc.c 2011-01-10 Aidan Kehoe <kehoea@parhasard.net> * mc-alloc.c (get_used_list_index): Replace some C++ comments with C-style /* comments.
author Aidan Kehoe <kehoea@parhasard.net>
date Mon, 10 Jan 2011 20:00:57 +0000
parents 2cc24c69446c
children 308d34e9f07d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1 /* New incremental garbage collector for XEmacs.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2 Copyright (C) 2005 Marcus Crestani.
4934
714f7c9fabb1 make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents: 4502
diff changeset
3 Copyright (C) 2010 Ben Wing.
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
4
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
5 This file is part of XEmacs.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
6
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
10 later version.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
11
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
15 for more details.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
16
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
21
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
22 /* Synched up with: Not in FSF. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
23
5238
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
24 /*
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
25 Garbage Collectors in XEmacs
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
26
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
27 Currently, XEmacs comes with two garbage collectors:
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
28
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
29 - The "old garbage collector": a simple mark and sweep collector,
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
30 its implementation is mainly spread out over gc.c and alloc.c.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
31 It is used by the default configuration or if you configure
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
32 `--with-newgc=no'.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
33
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
34 - The "new garbage collector": an incremental mark and sweep collector,
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
35 its implementation is in gc.c. It is used if you configure
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
36 `--with-newgc'. It comes with a new allocator, see mc-alloc.c, and
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
37 with the KKCC mark algorith, see below.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
38
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
39 Additionally, the old garbage collectors comes with two mark algorithms:
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
40
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
41 - The "recursive mark algorithm" marks live objects by recursively
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
42 calling mark_* functions on live objects. It is the default mark
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
43 algorithm of the old garbage collector.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
44
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
45 - The "KKCC mark algorithm" uses an explicit stack that to keep
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
46 track of the current progress of traversal and uses memory layout
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
47 descriptions (that are also used by the portable dumper) instead
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
48 of the mark_* functions. The old garbage collector uses it if
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
49 you configure `--with-kkcc'. It is the default and only mark
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
50 algorithm of the new garbage collector.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
51
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
52
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
53 The New Incremental Garbage Collector
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
54
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
55 An incremental garbage collector keeps garbage collection pause
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
56 times short by interleaving small amounts of collection work with
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
57 program execution, it does that by instrumenting write barrier
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
58 algorithms that essentially allow interrupting the mark phase.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
59
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
60
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
61 Write Barrier
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
62
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
63 A write barrier is the most important prerequisite for fancy
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
64 garbage collection techniques. We implement a "Virtual Dirty Bit
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
65 (short: vdb) Write Barrier" that makes uses of the operating
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
66 system's memory-protection mechanisms: The write barrier
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
67 write-protects memory pages containing heap objects. If the
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
68 mutator tries to modify these objects by writing into the
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
69 write-protected page, the operating system generates a fault. The
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
70 write barrier catches this fault, reads out the error-causing
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
71 address and can thus identify the updated object and page.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
72
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
73 Not all environments and operating systems provide the mechanism to
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
74 write-protect memory, catch resulting write faults, and read out
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
75 the faulting address. But luckily, most of today's operating
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
76 systems provide the features needed for the write-barrier
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
77 implementation. Currently, XEmacs includes write-barrier
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
78 implementations for the following platforms:
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
79
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
80 - POSIX-compliant platforms like up-to-date UNIX, Linux, Solaris,
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
81 etc. use the system call `mprotect' for memory protection,
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
82 `sigaction' for signal handling and get the faulting address from
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
83 `struct siginfo'. See file vdb-posix.c.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
84
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
85 - Mach-based systems like Mac OS X use "Mach Exception Handlers".
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
86 See file vdb-mach.c.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
87
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
88 - Windows systems like native Windows and Cygwin use Microsoft's
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
89 so-called "Structured Exception Handling". See file vdb-win32.c.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
90
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
91 The configure script determines which write barrier implementation
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
92 to use for a system. If no write barrier implementation is working
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
93 on that system, a fall-back "fake" implementation is used: This
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
94 implementation simply turns of the incremental write barrier at
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
95 runtime and does not allow any incremental collection (see
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
96 vdb-fake.c). The garbage collector then acts like a traditional
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
97 mark-and-sweep garbage collector. Generally, the incremental
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
98 garbage collector can be turned of at runtime by the user or by
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
99 applications, see below.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
100
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
101
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
102 Memory Protection and Object Layout
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
103
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
104 Implementations of a memory-protection mechanism may restrict the
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
105 size and the alignment of the memory region to be on page-size
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
106 boundaries. All objects subject to be covered by the write barrier
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
107 have to be allocated on logical memory pages, so that they meet the
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
108 requirement to be write-protected. The new allocator mc-alloc is
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
109 aware of a system page size---it allocates all Lisp objects on
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
110 logical memory pages and is therefore defaulted to on when the new
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
111 garbage collector is enabled.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
112
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
113 Unfortunately, the Lisp object layout that works with the old
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
114 collector leads to holes in the write barrier: Not all data
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
115 structures containing pointers to Lisp objects are allocated on the
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
116 Lisp heap. Some Lisp objects do not carry all their information in
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
117 the object itself. External parts are kept in separately allocated
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
118 memory blocks that are not managed by the new Lisp allocator.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
119 Examples for these objects are hash tables and dynamic arrays, two
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
120 objects that can dynamically grow and shrink. The separate memory
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
121 blocks are not guaranteed to reside on page boundaries, and thus
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
122 cannot be watched by the write barrier.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
123
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
124 Moreover, the separate parts can contain live pointers to other Lisp
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
125 objects. These pointers are not covered by the write barrier and
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
126 modifications by the client during garbage collection do escape. In
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
127 this case, the client changes the connectivity of the reachability
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
128 graph behind the collector's back, which eventually leads to
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
129 erroneous collection of live objects. To solve this problem, I
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
130 transformed the separately allocated parts to fully qualified Lisp
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
131 objects that are managed by the allocator and thus are covered by
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
132 the write barrier. This also removes a lot of special allocation
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
133 and removal code for the out-sourced parts. Generally, allocating
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
134 all data structures that contain pointers to Lisp objects on one
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
135 heap makes the whole memory layout more consistent.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
136
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
137
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
138 Debugging
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
139
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
140 The virtual-dirty-bit write barrier provokes signals on purpose,
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
141 namely SIGSEGV and SIGBUS. When debugging XEmacs with this write
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
142 barrier running, the debugger always breaks whenever a signal
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
143 occurs. This behavior is generally desired: A debugger has to break
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
144 on signals, to allow the user to examine the cause of the
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
145 signal---especially for illegal memory access, which is a common
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
146 programming error. But the debugger should not break for signals
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
147 caused by the write barrier. Therefore, most debuggers provide the
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
148 ability to turn of their fault handling for specific signals. The
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
149 configure script generates the debugger's settings .gdbinit and
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
150 .dbxrc, adding code to turn of signal handling for SIGSEGV and
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
151 SIGBUS, if the new garbage collector is used.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
152
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
153 But what happens if a bug in XEmacs causes an illegal memory access?
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
154 To maintain basic debugging abilities, we use another signal: First,
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
155 the write-barrier signal handler has to determine if the current
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
156 error situation is caused by the write-barrier memory protection or
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
157 not. Therefore, the signal handler checks if the faulting address
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
158 has been write-protected before. If it has not, the fault is caused
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
159 by a bug; the debugger has to break in this situation. To achieve
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
160 this, the signal handler raises SIGABRT to abort the program. Since
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
161 SIGABRT is not masked out by the debugger, XEmacs aborts and allows
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
162 the user to examine the problem.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
163
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
164
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
165 Incremental Garbage Collection
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
166
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
167 The new garbage collector is still a mark-and-sweep collector, but
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
168 now the mark phase no longer runs in one atomic action, it is
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
169 interleaved with program execution. The incremental garbage
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
170 collector needs an explicit mark stack to store the state of the
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
171 incremental traversal: the KKCC mark algorithm is a prerequisite and
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
172 is enabled by default when the new garbage collector is on.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
173
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
174 Garbage collection is invoked as before: After `gc-cons-threshold'
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
175 bytes have been allocated since the last garbage collection (or
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
176 after `gc-cons-percentage' percentage of the total amount of memory
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
177 used for Lisp data has been allocated since the last garbage
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
178 collection) a collection starts. After some initialization, the
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
179 marking begins.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
180
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
181 The variable `gc-incremental-traversal-threshold' contains how many
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
182 steps of incremental work have to be executed in one incremental
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
183 traversal cycle. After that many steps have been made, the mark
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
184 phase is interrupted and the client resumes. Now, the Lisp memory
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
185 is write-protected and the write barrier records modified objects.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
186 Incremental traversal is resumed after
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
187 `gc-cons-incremental-threshold' bytes have been allocated since the
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
188 interruption of garbage collection. Then, the objects recorded by
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
189 the write-barrier have to be re-examined by the traversal, i.e. they
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
190 are re-pushed onto the mark stack and processed again. Once the
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
191 mark stack is empty, the traversal is done.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
192
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
193 A full incremental collection is slightly slower than a full garbage
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
194 collection before: There is an overhead for storing pointers into
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
195 objects when the write barrier is running, and an overhead for
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
196 repeated traversal of modified objects. However, the new
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
197 incremental garbage collector reduces client pause times to
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
198 one-third, so even when a garbage collection is running, XEmacs
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
199 stays reactive.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
200
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
201
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
202 Tricolor Marking: White, Black, and Grey Mark Bits
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
203
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
204 Garbage collection traverses the graph of reachable objects and
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
205 colors them. The objects subject to garbage collection are white at
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
206 the beginning. By the end of the collection, those that will be
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
207 retained are colored black. When there are no reachable objects left
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
208 to blacken, the traversal of live data structures is finished. In
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
209 traditional mark-and-sweep collectors, this black and white coloring
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
210 is sufficient.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
211
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
212 In an incremental collector, the intermediate state of the traversal
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
213 is im- portant because of ongoing mutator activity: the mutator
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
214 cannot be allowed to change things in such way that the collector
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
215 will fail to find all reachable objects. To understand and prevent
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
216 such interactions between the mutator and the collector, it is
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
217 useful to introduce a third color, grey.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
218
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
219 Grey objects have been reached by the traversal, but its descendants
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
220 may not have been. White objects are changed to grey when they are
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
221 reached by the traversal. Grey objects mark the current state of the
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
222 traversal: traversal pro- ceeds by processing the grey objects. The
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
223 KKCC mark stack holds all the currently grey-colored objects.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
224 Processing a grey object means following its outgoing pointers, and
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
225 coloring it black afterwards.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
226
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
227 Intuitively, the traversal proceeds in a wavefront of grey objects
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
228 that separates the unreached objects, which are colored white, from
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
229 the already processed black objects.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
230
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
231 The allocator takes care of storing the mark bits: The mark bits are
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
232 kept in a tree like structure, for details see mc-alloc.c.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
233
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
234
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
235 Internal States of the Incremental Garbage Collector
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
236
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
237 To keep track of its current state, the collector holds it's current
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
238 phase in the global `gc_state' variable. A collector phase is one
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
239 of the following:
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
240
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
241 NONE No incremental or full collection is currently running.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
242
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
243 INIT_GC The collector prepares for a new collection, e.g. sets some
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
244 global variables.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
245
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
246 PUSH_ROOT_SET The collector pushes the root set on the mark stack
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
247 to start the traversal of live objects.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
248
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
249 MARK The traversal of live objects colors the reachable objects
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
250 white, grey, or black, according to their lifeness. The mark
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
251 phase can be interrupted by the incremental collection algorithm:
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
252 Before the client (i.e. the non collector part of XEmacs) resumes,
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
253 the write barrier has to be installed so that the collector knows
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
254 what objects get modified during the collector's pause.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
255 Installing a write barrier means protecting pages that only
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
256 contain black objects and recording write access to these objects.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
257 Pages with white or grey objects do not need to be protected,
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
258 since these pages are due to marking anyways when the collector
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
259 resumes. Once the collector resumes, it has to re-scan all
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
260 objects that have been modified during the collector pause and
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
261 have been caught by the write barrier. The mark phase is done when
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
262 there are no more grey objects on the heap, i.e. the KKCC mark stack
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
263 is empty.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
264
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
265 REPUSH_ROOT_SET After the mark phase is done, the collector has to
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
266 traverse the root set pointers again, since modifications to the
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
267 objects in the root set can not all be covered by the write barrier
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
268 (e.g. root set objects that are on the call stack). Therefore, the
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
269 collector has to traverse the root set again without interruption.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
270
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
271 FINISH_MARK After the mark phase is finished, some objects with
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
272 special liveness semantics have to be treated separately, e.g.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
273 ephemerons and the various flavors of weak objects.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
274
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
275 FINALIZE The collector registers all objects that have finalizers
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
276 for finalization. Finalizations happens asynchronously sometimes
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
277 after the collection has finished.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
278
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
279 SWEEP The allocator scans the entire heap and frees all white marked
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
280 objects. The freed memory is recycled and can be re-used for future
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
281 allocations. The sweep phase is carried out atomically.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
282
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
283 FINISH_GC The collector cleans up after the garbage collection by
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
284 resetting some global variables.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
285
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
286
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
287 Lisp Interface
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
288
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
289 The new garbage collector can be accessed directly from Emacs Lisp.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
290 Basically, two functions invoke the garbage collector:
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
291
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
292 (gc-full) starts a full garbage collection. If an incremental
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
293 garbage collection is already running, it is finished without
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
294 further interruption. This function guarantees that unused
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
295 objects have been freed when it returns.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
296
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
297 (gc-incremental) starts an incremental garbage collection. If an
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
298 incremental garbage collection is already running, the next cycle
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
299 of incremental traversal is started. The garbage collection is
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
300 finished if the traversal completes. Note that this function does
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
301 not necessarily free any memory. It only guarantees that the
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
302 traversal of the heap makes progress.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
303
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
304 The old garbage collector uses the function (garbage-collect) to
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
305 invoke a garbage collection. This function is still in use by some
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
306 applications that explicitly want to invoke a garbage collection.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
307 Since these applications may expect that unused memory has really
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
308 been freed when (garbage-collect) returns, it maps to (gc-full).
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
309
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
310 The new garbage collector is highly customizable during runtime; it
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
311 can even be switched back to the traditional mark-and-sweep garbage
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
312 collector: The variable allow-incremental-gc controls whether
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
313 garbage collections may be interrupted or if they have to be carried
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
314 out in one atomic action. Setting allow-incremental-gc to nil
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
315 prevents incremental garbage collection, and the garbage collector
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
316 then only does full collects, even if (gc-incremental) is called.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
317 Non-nil allows incremental garbage collection.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
318
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
319 This way applications can freely decide what garbage collection
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
320 algorithm is best for the upcoming memory usage. How frequently a
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
321 garbage collection occurs and how much traversal work is done in one
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
322 incremental cycle can also be modified during runtime. See
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
323
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
324 M-x customize RET alloc RET
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
325
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
326 for an overview of all settings.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
327
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
328
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
329 More Information
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
330
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
331 More details can be found in
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
332 http://crestani.de/xemacs/pdf/thesis-newgc.pdf .
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
333
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
334 */
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
335
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
336 #include <config.h>
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
337 #include "lisp.h"
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
338
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
339 #include "backtrace.h"
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
340 #include "buffer.h"
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
341 #include "bytecode.h"
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
342 #include "chartab.h"
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
343 #include "console-stream.h"
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
344 #include "device.h"
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
345 #include "elhash.h"
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
346 #include "events.h"
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
347 #include "extents-impl.h"
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
348 #include "file-coding.h"
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
349 #include "frame-impl.h"
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
350 #include "gc.h"
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
351 #include "glyphs.h"
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
352 #include "opaque.h"
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
353 #include "lrecord.h"
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
354 #include "lstream.h"
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
355 #include "process.h"
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
356 #include "profile.h"
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
357 #include "redisplay.h"
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
358 #include "specifier.h"
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
359 #include "sysfile.h"
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
360 #include "sysdep.h"
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
361 #include "window.h"
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
362 #include "vdb.h"
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
363
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
364
5238
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
365 /* Number of bytes of consing since gc before a full gc should happen. */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
366 #define GC_CONS_THRESHOLD 2000000
5238
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
367
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
368 /* Number of bytes of consing since gc before another cycle of the gc
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
369 should happen in incremental mode. */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
370 #define GC_CONS_INCREMENTAL_THRESHOLD 200000
5238
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
371
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5191
diff changeset
372 /* Number of elements marked in one cycle of incremental GC. */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
373 #define GC_INCREMENTAL_TRAVERSAL_THRESHOLD 100000
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
374
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
375 /* Number of bytes of consing done since the last GC. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
376 EMACS_INT consing_since_gc;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
377
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
378 /* Number of bytes of consing done since startup. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
379 EMACS_UINT total_consing;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
380
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
381 /* Number of bytes of current allocated heap objects. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
382 EMACS_INT total_gc_usage;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
383
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
384 /* If the above is set. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
385 int total_gc_usage_set;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
386
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
387 /* Number of bytes of consing since gc before another gc should be done. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
388 EMACS_INT gc_cons_threshold;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
389
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
390 /* Nonzero during gc */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
391 int gc_in_progress;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
392
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
393 /* Percentage of consing of total data size before another GC. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
394 EMACS_INT gc_cons_percentage;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
395
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
396 #ifdef NEW_GC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
397 /* Number of bytes of consing since gc before another cycle of the gc
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
398 should be done in incremental mode. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
399 EMACS_INT gc_cons_incremental_threshold;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
400
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
401 /* Number of elements marked in one cycle of incremental GC. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
402 EMACS_INT gc_incremental_traversal_threshold;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
403
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
404 /* Nonzero during write barrier */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
405 int write_barrier_enabled;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
406 #endif /* NEW_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
407
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
408
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
409
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
410 #ifdef NEW_GC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
411 /************************************************************************/
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
412 /* Incremental State and Statistics */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
413 /************************************************************************/
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
414
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
415 enum gc_phase
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
416 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
417 NONE,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
418 INIT_GC,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
419 PUSH_ROOT_SET,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
420 MARK,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
421 REPUSH_ROOT_SET,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
422 FINISH_MARK,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
423 FINALIZE,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
424 SWEEP,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
425 FINISH_GC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
426 };
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
427
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
428 #ifndef ERROR_CHECK_GC
4124
9a633a00c3f2 [xemacs-hg @ 2007-08-17 08:08:05 by crestani]
crestani
parents: 4115
diff changeset
429 typedef struct gc_state_type
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
430 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
431 enum gc_phase phase;
4124
9a633a00c3f2 [xemacs-hg @ 2007-08-17 08:08:05 by crestani]
crestani
parents: 4115
diff changeset
432 } gc_state_type;
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
433 #else /* ERROR_CHECK_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
434 enum gc_stat_id
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
435 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
436 GC_STAT_TOTAL,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
437 GC_STAT_IN_LAST_GC,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
438 GC_STAT_IN_THIS_GC,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
439 GC_STAT_IN_LAST_CYCLE,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
440 GC_STAT_IN_THIS_CYCLE,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
441 GC_STAT_COUNT /* has to be last */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
442 };
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
443
4124
9a633a00c3f2 [xemacs-hg @ 2007-08-17 08:08:05 by crestani]
crestani
parents: 4115
diff changeset
444 typedef struct gc_state_type
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
445 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
446 enum gc_phase phase;
3313
509d2981ffea [xemacs-hg @ 2006-03-28 17:43:43 by crestani]
crestani
parents: 3267
diff changeset
447 double n_gc[GC_STAT_COUNT];
509d2981ffea [xemacs-hg @ 2006-03-28 17:43:43 by crestani]
crestani
parents: 3267
diff changeset
448 double n_cycles[GC_STAT_COUNT];
509d2981ffea [xemacs-hg @ 2006-03-28 17:43:43 by crestani]
crestani
parents: 3267
diff changeset
449 double enqueued[GC_STAT_COUNT];
509d2981ffea [xemacs-hg @ 2006-03-28 17:43:43 by crestani]
crestani
parents: 3267
diff changeset
450 double dequeued[GC_STAT_COUNT];
509d2981ffea [xemacs-hg @ 2006-03-28 17:43:43 by crestani]
crestani
parents: 3267
diff changeset
451 double repushed[GC_STAT_COUNT];
509d2981ffea [xemacs-hg @ 2006-03-28 17:43:43 by crestani]
crestani
parents: 3267
diff changeset
452 double enqueued2[GC_STAT_COUNT];
509d2981ffea [xemacs-hg @ 2006-03-28 17:43:43 by crestani]
crestani
parents: 3267
diff changeset
453 double dequeued2[GC_STAT_COUNT];
509d2981ffea [xemacs-hg @ 2006-03-28 17:43:43 by crestani]
crestani
parents: 3267
diff changeset
454 double finalized[GC_STAT_COUNT];
509d2981ffea [xemacs-hg @ 2006-03-28 17:43:43 by crestani]
crestani
parents: 3267
diff changeset
455 double freed[GC_STAT_COUNT];
4124
9a633a00c3f2 [xemacs-hg @ 2007-08-17 08:08:05 by crestani]
crestani
parents: 4115
diff changeset
456 } gc_state_type;
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
457 #endif /* ERROR_CHECK_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
458
4124
9a633a00c3f2 [xemacs-hg @ 2007-08-17 08:08:05 by crestani]
crestani
parents: 4115
diff changeset
459 gc_state_type gc_state;
9a633a00c3f2 [xemacs-hg @ 2007-08-17 08:08:05 by crestani]
crestani
parents: 4115
diff changeset
460
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
461 #define GC_PHASE gc_state.phase
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
462 #define GC_SET_PHASE(p) GC_PHASE = p
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
463
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
464 #ifdef ERROR_CHECK_GC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
465 # define GC_STAT_START_NEW_GC gc_stat_start_new_gc ()
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
466 # define GC_STAT_RESUME_GC gc_stat_resume_gc ()
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
467
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
468 #define GC_STAT_TICK(STAT) \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
469 gc_state.STAT[GC_STAT_TOTAL]++; \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
470 gc_state.STAT[GC_STAT_IN_THIS_GC]++; \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
471 gc_state.STAT[GC_STAT_IN_THIS_CYCLE]++
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
472
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
473 # define GC_STAT_ENQUEUED \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
474 if (GC_PHASE == REPUSH_ROOT_SET) \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
475 { \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
476 GC_STAT_TICK (enqueued2); \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
477 } \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
478 else \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
479 { \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
480 GC_STAT_TICK (enqueued); \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
481 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
482
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
483 # define GC_STAT_DEQUEUED \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
484 if (gc_state.phase == REPUSH_ROOT_SET) \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
485 { \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
486 GC_STAT_TICK (dequeued2); \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
487 } \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
488 else \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
489 { \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
490 GC_STAT_TICK (dequeued); \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
491 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
492 # define GC_STAT_REPUSHED GC_STAT_TICK (repushed)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
493
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
494 #define GC_STAT_RESUME(stat) \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
495 gc_state.stat[GC_STAT_IN_LAST_CYCLE] = \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
496 gc_state.stat[GC_STAT_IN_THIS_CYCLE]; \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
497 gc_state.stat[GC_STAT_IN_THIS_CYCLE] = 0
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
498
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
499 #define GC_STAT_RESTART(stat) \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
500 gc_state.stat[GC_STAT_IN_LAST_GC] = \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
501 gc_state.stat[GC_STAT_IN_THIS_GC]; \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
502 gc_state.stat[GC_STAT_IN_THIS_GC] = 0; \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
503 GC_STAT_RESUME (stat)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
504
5046
d4f666cda5e6 some random fixups
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
505 static void
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
506 gc_stat_start_new_gc (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
507 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
508 gc_state.n_gc[GC_STAT_TOTAL]++;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
509 gc_state.n_cycles[GC_STAT_TOTAL]++;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
510 gc_state.n_cycles[GC_STAT_IN_LAST_GC] = gc_state.n_cycles[GC_STAT_IN_THIS_GC];
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
511 gc_state.n_cycles[GC_STAT_IN_THIS_GC] = 1;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
512
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
513 GC_STAT_RESTART (enqueued);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
514 GC_STAT_RESTART (dequeued);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
515 GC_STAT_RESTART (repushed);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
516 GC_STAT_RESTART (finalized);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
517 GC_STAT_RESTART (enqueued2);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
518 GC_STAT_RESTART (dequeued2);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
519 GC_STAT_RESTART (freed);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
520 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
521
5046
d4f666cda5e6 some random fixups
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
522 static void
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
523 gc_stat_resume_gc (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
524 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
525 gc_state.n_cycles[GC_STAT_TOTAL]++;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
526 gc_state.n_cycles[GC_STAT_IN_THIS_GC]++;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
527 GC_STAT_RESUME (enqueued);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
528 GC_STAT_RESUME (dequeued);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
529 GC_STAT_RESUME (repushed);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
530 GC_STAT_RESUME (finalized);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
531 GC_STAT_RESUME (enqueued2);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
532 GC_STAT_RESUME (dequeued2);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
533 GC_STAT_RESUME (freed);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
534 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
535
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
536 void
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
537 gc_stat_finalized (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
538 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
539 GC_STAT_TICK (finalized);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
540 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
541
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
542 void
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
543 gc_stat_freed (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
544 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
545 GC_STAT_TICK (freed);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
546 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
547
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
548 DEFUN("gc-stats", Fgc_stats, 0, 0 ,"", /*
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
549 Return statistics about garbage collection cycles in a property list.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
550 */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
551 ())
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
552 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
553 Lisp_Object pl = Qnil;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
554 #define PL(name,value) \
3313
509d2981ffea [xemacs-hg @ 2006-03-28 17:43:43 by crestani]
crestani
parents: 3267
diff changeset
555 pl = cons3 (intern (name), make_float (gc_state.value), pl)
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
556
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
557 PL ("freed-in-this-cycle", freed[GC_STAT_IN_THIS_CYCLE]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
558 PL ("freed-in-this-gc", freed[GC_STAT_IN_THIS_GC]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
559 PL ("freed-in-last-cycle", freed[GC_STAT_IN_LAST_CYCLE]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
560 PL ("freed-in-last-gc", freed[GC_STAT_IN_LAST_GC]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
561 PL ("freed-total", freed[GC_STAT_TOTAL]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
562 PL ("finalized-in-this-cycle", finalized[GC_STAT_IN_THIS_CYCLE]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
563 PL ("finalized-in-this-gc", finalized[GC_STAT_IN_THIS_GC]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
564 PL ("finalized-in-last-cycle", finalized[GC_STAT_IN_LAST_CYCLE]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
565 PL ("finalized-in-last-gc", finalized[GC_STAT_IN_LAST_GC]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
566 PL ("finalized-total", finalized[GC_STAT_TOTAL]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
567 PL ("repushed-in-this-cycle", repushed[GC_STAT_IN_THIS_CYCLE]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
568 PL ("repushed-in-this-gc", repushed[GC_STAT_IN_THIS_GC]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
569 PL ("repushed-in-last-cycle", repushed[GC_STAT_IN_LAST_CYCLE]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
570 PL ("repushed-in-last-gc", repushed[GC_STAT_IN_LAST_GC]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
571 PL ("repushed-total", repushed[GC_STAT_TOTAL]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
572 PL ("dequeued2-in-this-cycle", dequeued2[GC_STAT_IN_THIS_CYCLE]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
573 PL ("dequeued2-in-this-gc", dequeued2[GC_STAT_IN_THIS_GC]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
574 PL ("dequeued2-in-last-cycle", dequeued2[GC_STAT_IN_LAST_CYCLE]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
575 PL ("dequeued2-in-last-gc", dequeued2[GC_STAT_IN_LAST_GC]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
576 PL ("dequeued2-total", dequeued2[GC_STAT_TOTAL]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
577 PL ("enqueued2-in-this-cycle", enqueued2[GC_STAT_IN_THIS_CYCLE]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
578 PL ("enqueued2-in-this-gc", enqueued2[GC_STAT_IN_THIS_GC]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
579 PL ("enqueued2-in-last-cycle", enqueued2[GC_STAT_IN_LAST_CYCLE]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
580 PL ("enqueued2-in-last-gc", enqueued2[GC_STAT_IN_LAST_GC]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
581 PL ("enqueued2-total", enqueued2[GC_STAT_TOTAL]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
582 PL ("dequeued-in-this-cycle", dequeued[GC_STAT_IN_THIS_CYCLE]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
583 PL ("dequeued-in-this-gc", dequeued[GC_STAT_IN_THIS_GC]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
584 PL ("dequeued-in-last-cycle", dequeued[GC_STAT_IN_LAST_CYCLE]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
585 PL ("dequeued-in-last-gc", dequeued[GC_STAT_IN_LAST_GC]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
586 PL ("dequeued-total", dequeued[GC_STAT_TOTAL]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
587 PL ("enqueued-in-this-cycle", enqueued[GC_STAT_IN_THIS_CYCLE]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
588 PL ("enqueued-in-this-gc", enqueued[GC_STAT_IN_THIS_GC]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
589 PL ("enqueued-in-last-cycle", enqueued[GC_STAT_IN_LAST_CYCLE]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
590 PL ("enqueued-in-last-gc", enqueued[GC_STAT_IN_LAST_GC]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
591 PL ("enqueued-total", enqueued[GC_STAT_TOTAL]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
592 PL ("n-cycles-in-this-gc", n_cycles[GC_STAT_IN_THIS_GC]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
593 PL ("n-cycles-in-last-gc", n_cycles[GC_STAT_IN_LAST_GC]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
594 PL ("n-cycles-total", n_cycles[GC_STAT_TOTAL]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
595 PL ("n-gc-total", n_gc[GC_STAT_TOTAL]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
596 PL ("phase", phase);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
597 return pl;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
598 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
599 #else /* not ERROR_CHECK_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
600 # define GC_STAT_START_NEW_GC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
601 # define GC_STAT_RESUME_GC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
602 # define GC_STAT_ENQUEUED
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
603 # define GC_STAT_DEQUEUED
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
604 # define GC_STAT_REPUSHED
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
605 # define GC_STAT_REMOVED
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
606 #endif /* not ERROR_CHECK_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
607 #endif /* NEW_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
608
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
609
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
610 /************************************************************************/
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
611 /* Recompute need to garbage collect */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
612 /************************************************************************/
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
613
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
614 int need_to_garbage_collect;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
615
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
616 #ifdef ERROR_CHECK_GC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
617 int always_gc = 0; /* Debugging hack; equivalent to
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
618 (setq gc-cons-thresold -1) */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
619 #else
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
620 #define always_gc 0
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
621 #endif
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
622
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
623 /* True if it's time to garbage collect now. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
624 void
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
625 recompute_need_to_garbage_collect (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
626 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
627 if (always_gc)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
628 need_to_garbage_collect = 1;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
629 else
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
630 need_to_garbage_collect =
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
631 #ifdef NEW_GC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
632 write_barrier_enabled ?
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
633 (consing_since_gc > gc_cons_incremental_threshold) :
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
634 #endif /* NEW_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
635 (consing_since_gc > gc_cons_threshold
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
636 &&
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
637 #if 0 /* #### implement this better */
4115
6595286b4bed [xemacs-hg @ 2007-08-14 18:58:13 by crestani]
crestani
parents: 3519
diff changeset
638 ((double)consing_since_gc) / total_data_usage()) >=
6595286b4bed [xemacs-hg @ 2007-08-14 18:58:13 by crestani]
crestani
parents: 3519
diff changeset
639 ((double)gc_cons_percentage / 100)
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
640 #else
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
641 (!total_gc_usage_set ||
4115
6595286b4bed [xemacs-hg @ 2007-08-14 18:58:13 by crestani]
crestani
parents: 3519
diff changeset
642 ((double)consing_since_gc / total_gc_usage) >=
6595286b4bed [xemacs-hg @ 2007-08-14 18:58:13 by crestani]
crestani
parents: 3519
diff changeset
643 ((double)gc_cons_percentage / 100))
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
644 #endif
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
645 );
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
646 recompute_funcall_allocation_flag ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
647 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
648
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
649
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
650
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
651 /************************************************************************/
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
652 /* Mark Phase */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
653 /************************************************************************/
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
654
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
655 static const struct memory_description lisp_object_description_1[] = {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
656 { XD_LISP_OBJECT, 0 },
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
657 { XD_END }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
658 };
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
659
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
660 const struct sized_memory_description lisp_object_description = {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
661 sizeof (Lisp_Object),
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
662 lisp_object_description_1
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
663 };
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
664
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
665 #if defined (USE_KKCC) || defined (PDUMP)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
666
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
667 /* This function extracts the value of a count variable described somewhere
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
668 else in the description. It is converted corresponding to the type */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
669 EMACS_INT
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
670 lispdesc_indirect_count_1 (EMACS_INT code,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
671 const struct memory_description *idesc,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
672 const void *idata)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
673 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
674 EMACS_INT count;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
675 const void *irdata;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
676
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
677 int line = XD_INDIRECT_VAL (code);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
678 int delta = XD_INDIRECT_DELTA (code);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
679
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
680 irdata = ((char *) idata) +
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
681 lispdesc_indirect_count (idesc[line].offset, idesc, idata);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
682 switch (idesc[line].type)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
683 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
684 case XD_BYTECOUNT:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
685 count = * (Bytecount *) irdata;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
686 break;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
687 case XD_ELEMCOUNT:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
688 count = * (Elemcount *) irdata;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
689 break;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
690 case XD_HASHCODE:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
691 count = * (Hashcode *) irdata;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
692 break;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
693 case XD_INT:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
694 count = * (int *) irdata;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
695 break;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
696 case XD_LONG:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
697 count = * (long *) irdata;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
698 break;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
699 default:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
700 stderr_out ("Unsupported count type : %d (line = %d, code = %ld)\n",
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
701 idesc[line].type, line, (long) code);
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
702 #if defined (USE_KKCC) && defined (DEBUG_XEMACS)
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
703 if (gc_in_progress)
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
704 kkcc_detailed_backtrace ();
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
705 #endif
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
706 #ifdef PDUMP
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
707 if (in_pdump)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
708 pdump_backtrace ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
709 #endif
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
710 count = 0; /* warning suppression */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
711 ABORT ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
712 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
713 count += delta;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
714 return count;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
715 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
716
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
717 /* SDESC is a "description map" (basically, a list of offsets used for
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
718 successive indirections) and OBJ is the first object to indirect off of.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
719 Return the description ultimately found. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
720
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
721 const struct sized_memory_description *
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
722 lispdesc_indirect_description_1 (const void *obj,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
723 const struct sized_memory_description *sdesc)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
724 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
725 int pos;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
726
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
727 for (pos = 0; sdesc[pos].size >= 0; pos++)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
728 obj = * (const void **) ((const char *) obj + sdesc[pos].size);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
729
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
730 return (const struct sized_memory_description *) obj;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
731 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
732
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
733 /* Compute the size of the data at RDATA, described by a single entry
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
734 DESC1 in a description array. OBJ and DESC are used for
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
735 XD_INDIRECT references. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
736
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
737 static Bytecount
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
738 lispdesc_one_description_line_size (void *rdata,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
739 const struct memory_description *desc1,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
740 const void *obj,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
741 const struct memory_description *desc)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
742 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
743 union_switcheroo:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
744 switch (desc1->type)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
745 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
746 case XD_LISP_OBJECT_ARRAY:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
747 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
748 EMACS_INT val = lispdesc_indirect_count (desc1->data1, desc, obj);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
749 return (val * sizeof (Lisp_Object));
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
750 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
751 case XD_LISP_OBJECT:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
752 case XD_LO_LINK:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
753 return sizeof (Lisp_Object);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
754 case XD_OPAQUE_PTR:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
755 return sizeof (void *);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
756 #ifdef NEW_GC
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
757 case XD_INLINE_LISP_OBJECT_BLOCK_PTR:
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
758 #endif /* NEW_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
759 case XD_BLOCK_PTR:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
760 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
761 EMACS_INT val = lispdesc_indirect_count (desc1->data1, desc, obj);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
762 return val * sizeof (void *);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
763 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
764 case XD_BLOCK_ARRAY:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
765 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
766 EMACS_INT val = lispdesc_indirect_count (desc1->data1, desc, obj);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
767
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
768 return (val *
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
769 lispdesc_block_size
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
770 (rdata,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
771 lispdesc_indirect_description (obj, desc1->data2.descr)));
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
772 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
773 case XD_OPAQUE_DATA_PTR:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
774 return sizeof (void *);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
775 case XD_UNION_DYNAMIC_SIZE:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
776 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
777 /* If an explicit size was given in the first-level structure
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
778 description, use it; else compute size based on current union
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
779 constant. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
780 const struct sized_memory_description *sdesc =
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
781 lispdesc_indirect_description (obj, desc1->data2.descr);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
782 if (sdesc->size)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
783 return sdesc->size;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
784 else
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
785 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
786 desc1 = lispdesc_process_xd_union (desc1, desc, obj);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
787 if (desc1)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
788 goto union_switcheroo;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
789 break;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
790 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
791 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
792 case XD_UNION:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
793 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
794 /* If an explicit size was given in the first-level structure
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
795 description, use it; else compute size based on maximum of all
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
796 possible structures. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
797 const struct sized_memory_description *sdesc =
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
798 lispdesc_indirect_description (obj, desc1->data2.descr);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
799 if (sdesc->size)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
800 return sdesc->size;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
801 else
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
802 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
803 int count;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
804 Bytecount max_size = -1, size;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
805
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
806 desc1 = sdesc->description;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
807
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
808 for (count = 0; desc1[count].type != XD_END; count++)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
809 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
810 size = lispdesc_one_description_line_size (rdata,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
811 &desc1[count],
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
812 obj, desc);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
813 if (size > max_size)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
814 max_size = size;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
815 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
816 return max_size;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
817 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
818 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
819 case XD_ASCII_STRING:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
820 return sizeof (void *);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
821 case XD_DOC_STRING:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
822 return sizeof (void *);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
823 case XD_INT_RESET:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
824 return sizeof (int);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
825 case XD_BYTECOUNT:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
826 return sizeof (Bytecount);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
827 case XD_ELEMCOUNT:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
828 return sizeof (Elemcount);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
829 case XD_HASHCODE:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
830 return sizeof (Hashcode);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
831 case XD_INT:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
832 return sizeof (int);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
833 case XD_LONG:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
834 return sizeof (long);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
835 default:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
836 stderr_out ("Unsupported dump type : %d\n", desc1->type);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
837 ABORT ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
838 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
839
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
840 return 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
841 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
842
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
843
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
844 /* Return the size of the memory block (NOT necessarily a structure!)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
845 described by SDESC and pointed to by OBJ. If SDESC records an
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
846 explicit size (i.e. non-zero), it is simply returned; otherwise,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
847 the size is calculated by the maximum offset and the size of the
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
848 object at that offset, rounded up to the maximum alignment. In
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
849 this case, we may need the object, for example when retrieving an
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
850 "indirect count" of an inlined array (the count is not constant,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
851 but is specified by one of the elements of the memory block). (It
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
852 is generally not a problem if we return an overly large size -- we
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
853 will simply end up reserving more space than necessary; but if the
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
854 size is too small we could be in serious trouble, in particular
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
855 with nested inlined structures, where there may be alignment
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
856 padding in the middle of a block. #### In fact there is an (at
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
857 least theoretical) problem with an overly large size -- we may
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
858 trigger a protection fault when reading from invalid memory. We
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
859 need to handle this -- perhaps in a stupid but dependable way,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
860 i.e. by trapping SIGSEGV and SIGBUS.) */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
861
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
862 Bytecount
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
863 lispdesc_block_size_1 (const void *obj, Bytecount size,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
864 const struct memory_description *desc)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
865 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
866 EMACS_INT max_offset = -1;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
867 int max_offset_pos = -1;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
868 int pos;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
869
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
870 if (size)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
871 return size;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
872
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
873 for (pos = 0; desc[pos].type != XD_END; pos++)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
874 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
875 EMACS_INT offset = lispdesc_indirect_count (desc[pos].offset, desc, obj);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
876 if (offset == max_offset)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
877 {
5168
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5158
diff changeset
878 #if 0
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5158
diff changeset
879 /* This can legitimately happen with gap arrays -- if there are
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5158
diff changeset
880 no elements in the array, and the gap size is 0, then both
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5158
diff changeset
881 parts of the array will be of size 0 and in the same place. */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
882 stderr_out ("Two relocatable elements at same offset?\n");
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
883 ABORT ();
5168
cf900a2f1fa3 extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents: 5158
diff changeset
884 #endif
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
885 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
886 else if (offset > max_offset)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
887 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
888 max_offset = offset;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
889 max_offset_pos = pos;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
890 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
891 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
892
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
893 if (max_offset_pos < 0)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
894 return 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
895
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
896 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
897 Bytecount size_at_max;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
898 size_at_max =
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
899 lispdesc_one_description_line_size ((char *) obj + max_offset,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
900 &desc[max_offset_pos], obj, desc);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
901
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
902 /* We have no way of knowing the required alignment for this structure,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
903 so just make it maximally aligned. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
904 return MAX_ALIGN_SIZE (max_offset + size_at_max);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
905 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
906 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
907 #endif /* defined (USE_KKCC) || defined (PDUMP) */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
908
3263
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
909 #ifdef NEW_GC
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
910 #define GC_CHECK_NOT_FREE(lheader) \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
911 gc_checking_assert (! LRECORD_FREE_P (lheader));
3263
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
912 #else /* not NEW_GC */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
913 #define GC_CHECK_NOT_FREE(lheader) \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
914 gc_checking_assert (! LRECORD_FREE_P (lheader)); \
5142
f965e31a35f0 reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents: 5127
diff changeset
915 gc_checking_assert (LHEADER_IMPLEMENTATION (lheader)->frob_block_p || \
f965e31a35f0 reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents: 5127
diff changeset
916 ! (lheader)->free)
3263
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
917 #endif /* not NEW_GC */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
918
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
919 #ifdef USE_KKCC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
920 /* The following functions implement the new mark algorithm.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
921 They mark objects according to their descriptions. They
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
922 are modeled on the corresponding pdumper procedures. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
923
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
924 #if 0
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
925 # define KKCC_STACK_AS_QUEUE 1
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
926 #endif
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
927
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
928 #ifdef DEBUG_XEMACS
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
929 /* The backtrace for the KKCC mark functions. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
930 #define KKCC_INIT_BT_STACK_SIZE 4096
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
931
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
932 typedef struct
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
933 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
934 void *obj;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
935 const struct memory_description *desc;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
936 int pos;
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
937 int is_lisp;
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
938 } kkcc_bt_stack_entry;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
939
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
940 static kkcc_bt_stack_entry *kkcc_bt;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
941 static int kkcc_bt_stack_size;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
942 static int kkcc_bt_depth = 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
943
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
944 static void
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
945 kkcc_bt_init (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
946 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
947 kkcc_bt_depth = 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
948 kkcc_bt_stack_size = KKCC_INIT_BT_STACK_SIZE;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
949 kkcc_bt = (kkcc_bt_stack_entry *)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
950 xmalloc_and_zero (kkcc_bt_stack_size * sizeof (kkcc_bt_stack_entry));
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
951 if (!kkcc_bt)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
952 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
953 stderr_out ("KKCC backtrace stack init failed for size %d\n",
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
954 kkcc_bt_stack_size);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
955 ABORT ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
956 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
957 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
958
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
959 /* Workhorse backtrace function. Not static because may potentially be
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
960 called from a debugger. */
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
961
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
962 void kkcc_backtrace_1 (int size, int detailed);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
963 void
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
964 kkcc_backtrace_1 (int size, int detailed)
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
965 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
966 int i;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
967 stderr_out ("KKCC mark stack backtrace :\n");
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
968 for (i = kkcc_bt_depth - 1; i >= kkcc_bt_depth - size && i >= 0; i--)
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
969 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
970 Lisp_Object obj = wrap_pointer_1 (kkcc_bt[i].obj);
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
971 stderr_out (" [%d] ", i);
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
972 if (!kkcc_bt[i].is_lisp)
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
973 stderr_out ("non Lisp Object");
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
974 else if (!LRECORDP (obj))
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
975 stderr_out ("Lisp Object, non-record");
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
976 else if (XRECORD_LHEADER (obj)->type >= lrecord_type_last_built_in_type
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
977 || (!XRECORD_LHEADER_IMPLEMENTATION (obj)))
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
978 stderr_out ("WARNING! Bad Lisp Object type %d",
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
979 XRECORD_LHEADER (obj)->type);
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
980 else
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
981 stderr_out ("%s", XRECORD_LHEADER_IMPLEMENTATION (obj)->name);
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
982 if (detailed && kkcc_bt[i].is_lisp)
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
983 {
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
984 stderr_out (" ");
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
985 debug_print (obj);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
986 }
3519
896a34d28b71 [xemacs-hg @ 2006-07-19 19:24:41 by crestani]
crestani
parents: 3486
diff changeset
987 stderr_out (" (addr: %p, desc: %p, ",
896a34d28b71 [xemacs-hg @ 2006-07-19 19:24:41 by crestani]
crestani
parents: 3486
diff changeset
988 (void *) kkcc_bt[i].obj,
896a34d28b71 [xemacs-hg @ 2006-07-19 19:24:41 by crestani]
crestani
parents: 3486
diff changeset
989 (void *) kkcc_bt[i].desc);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
990 if (kkcc_bt[i].pos >= 0)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
991 stderr_out ("pos: %d)\n", kkcc_bt[i].pos);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
992 else
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
993 if (kkcc_bt[i].pos == -1)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
994 stderr_out ("root set)\n");
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
995 else if (kkcc_bt[i].pos == -2)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
996 stderr_out ("dirty object)\n");
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
997 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
998 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
999
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1000 /* Various front ends onto kkcc_backtrace_1(), meant to be called from
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1001 a debugger.
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1002
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1003 The variants are:
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1004
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1005 normal vs _full(): Normal displays up to the topmost 100 items on the
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1006 stack, whereas full displays all items (even if there are thousands)
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1007
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1008 _detailed_() vs _short_(): Detailed here means print out the actual
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1009 Lisp objects on the stack using debug_print() in addition to their type,
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1010 whereas short means only show the type
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1011 */
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1012
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1013 void
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1014 kkcc_detailed_backtrace (void)
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1015 {
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1016 kkcc_backtrace_1 (100, 1);
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1017 }
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1018
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1019 void kkcc_short_backtrace (void);
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1020 void
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1021 kkcc_short_backtrace (void)
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1022 {
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1023 kkcc_backtrace_1 (100, 0);
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1024 }
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1025
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1026 void kkcc_detailed_backtrace_full (void);
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1027 void
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1028 kkcc_detailed_backtrace_full (void)
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1029 {
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1030 kkcc_backtrace_1 (kkcc_bt_depth, 1);
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1031 }
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1032
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1033 void kkcc_short_backtrace_full (void);
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1034 void
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1035 kkcc_short_backtrace_full (void)
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1036 {
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1037 kkcc_backtrace_1 (kkcc_bt_depth, 0);
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1038 }
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1039
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1040 /* Short versions for ease in calling from a debugger */
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1041
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1042 void kbt (void);
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1043 void
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1044 kbt (void)
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1045 {
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1046 kkcc_detailed_backtrace ();
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1047 }
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1048
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1049 void kbts (void);
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1050 void
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1051 kbts (void)
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1052 {
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1053 kkcc_short_backtrace ();
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1054 }
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1055
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1056 void kbtf (void);
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1057 void
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1058 kbtf (void)
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1059 {
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1060 kkcc_detailed_backtrace_full ();
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1061 }
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1062
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1063 void kbtsf (void);
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1064 void
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1065 kbtsf (void)
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1066 {
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1067 kkcc_short_backtrace_full ();
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1068 }
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1069
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1070 static void
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1071 kkcc_bt_stack_realloc (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1072 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1073 kkcc_bt_stack_size *= 2;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1074 kkcc_bt = (kkcc_bt_stack_entry *)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1075 xrealloc (kkcc_bt, kkcc_bt_stack_size * sizeof (kkcc_bt_stack_entry));
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1076 if (!kkcc_bt)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1077 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1078 stderr_out ("KKCC backtrace stack realloc failed for size %d\n",
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1079 kkcc_bt_stack_size);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1080 ABORT ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1081 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1082 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1083
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1084 static void
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1085 kkcc_bt_free (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1086 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1087 xfree_1 (kkcc_bt);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1088 kkcc_bt = 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1089 kkcc_bt_stack_size = 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1090 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1091
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1092 static void
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1093 kkcc_bt_push (void *obj, const struct memory_description *desc,
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1094 int is_lisp DECLARE_KKCC_DEBUG_ARGS)
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1095 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1096 kkcc_bt_depth = level;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1097 kkcc_bt[kkcc_bt_depth].obj = obj;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1098 kkcc_bt[kkcc_bt_depth].desc = desc;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1099 kkcc_bt[kkcc_bt_depth].pos = pos;
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1100 kkcc_bt[kkcc_bt_depth].is_lisp = is_lisp;
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1101 kkcc_bt_depth++;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1102 if (kkcc_bt_depth >= kkcc_bt_stack_size)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1103 kkcc_bt_stack_realloc ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1104 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1105
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1106 #else /* not DEBUG_XEMACS */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1107 #define kkcc_bt_init()
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1108 #define kkcc_bt_push(obj, desc)
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1109 #endif /* not DEBUG_XEMACS */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1110
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1111 /* Object memory descriptions are in the lrecord_implementation structure.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1112 But copying them to a parallel array is much more cache-friendly. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1113 const struct memory_description *lrecord_memory_descriptions[countof (lrecord_implementations_table)];
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1114
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1115 /* the initial stack size in kkcc_gc_stack_entries */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1116 #define KKCC_INIT_GC_STACK_SIZE 16384
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1117
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1118 typedef struct
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1119 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1120 void *data;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1121 const struct memory_description *desc;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1122 #ifdef DEBUG_XEMACS
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1123 int level;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1124 int pos;
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1125 int is_lisp;
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1126 #endif
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1127 } kkcc_gc_stack_entry;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1128
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1129
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1130 static kkcc_gc_stack_entry *kkcc_gc_stack_ptr;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1131 static int kkcc_gc_stack_front;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1132 static int kkcc_gc_stack_rear;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1133 static int kkcc_gc_stack_size;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1134
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1135 #define KKCC_INC(i) ((i + 1) % kkcc_gc_stack_size)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1136 #define KKCC_INC2(i) ((i + 2) % kkcc_gc_stack_size)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1137
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1138 #define KKCC_GC_STACK_FULL (KKCC_INC2 (kkcc_gc_stack_rear) == kkcc_gc_stack_front)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1139 #define KKCC_GC_STACK_EMPTY (KKCC_INC (kkcc_gc_stack_rear) == kkcc_gc_stack_front)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1140
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1141 static void
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1142 kkcc_gc_stack_init (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1143 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1144 kkcc_gc_stack_size = KKCC_INIT_GC_STACK_SIZE;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1145 kkcc_gc_stack_ptr = (kkcc_gc_stack_entry *)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1146 xmalloc_and_zero (kkcc_gc_stack_size * sizeof (kkcc_gc_stack_entry));
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1147 if (!kkcc_gc_stack_ptr)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1148 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1149 stderr_out ("stack init failed for size %d\n", kkcc_gc_stack_size);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1150 ABORT ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1151 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1152 kkcc_gc_stack_front = 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1153 kkcc_gc_stack_rear = kkcc_gc_stack_size - 1;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1154 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1155
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1156 static void
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1157 kkcc_gc_stack_free (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1158 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1159 xfree_1 (kkcc_gc_stack_ptr);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1160 kkcc_gc_stack_ptr = 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1161 kkcc_gc_stack_front = 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1162 kkcc_gc_stack_rear = 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1163 kkcc_gc_stack_size = 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1164 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1165
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1166 static void
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1167 kkcc_gc_stack_realloc (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1168 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1169 kkcc_gc_stack_entry *old_ptr = kkcc_gc_stack_ptr;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1170 int old_size = kkcc_gc_stack_size;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1171 kkcc_gc_stack_size *= 2;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1172 kkcc_gc_stack_ptr = (kkcc_gc_stack_entry *)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1173 xmalloc_and_zero (kkcc_gc_stack_size * sizeof (kkcc_gc_stack_entry));
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1174 if (!kkcc_gc_stack_ptr)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1175 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1176 stderr_out ("stack realloc failed for size %d\n", kkcc_gc_stack_size);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1177 ABORT ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1178 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1179 if (kkcc_gc_stack_rear >= kkcc_gc_stack_front)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1180 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1181 int number_elements = kkcc_gc_stack_rear - kkcc_gc_stack_front + 1;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1182 memcpy (kkcc_gc_stack_ptr, &old_ptr[kkcc_gc_stack_front],
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1183 number_elements * sizeof (kkcc_gc_stack_entry));
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1184 kkcc_gc_stack_front = 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1185 kkcc_gc_stack_rear = number_elements - 1;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1186 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1187 else
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1188 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1189 int number_elements = old_size - kkcc_gc_stack_front;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1190 memcpy (kkcc_gc_stack_ptr, &old_ptr[kkcc_gc_stack_front],
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1191 number_elements * sizeof (kkcc_gc_stack_entry));
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1192 memcpy (&kkcc_gc_stack_ptr[number_elements], &old_ptr[0],
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1193 (kkcc_gc_stack_rear + 1) * sizeof (kkcc_gc_stack_entry));
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1194 kkcc_gc_stack_front = 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1195 kkcc_gc_stack_rear = kkcc_gc_stack_rear + number_elements;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1196 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1197 xfree_1 (old_ptr);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1198 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1199
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1200 static void
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1201 kkcc_gc_stack_push (void *data, const struct memory_description *desc
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1202 DECLARE_KKCC_DEBUG_ARGS)
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1203 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1204 #ifdef NEW_GC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1205 GC_STAT_ENQUEUED;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1206 #endif /* NEW_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1207 if (KKCC_GC_STACK_FULL)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1208 kkcc_gc_stack_realloc();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1209 kkcc_gc_stack_rear = KKCC_INC (kkcc_gc_stack_rear);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1210 kkcc_gc_stack_ptr[kkcc_gc_stack_rear].data = data;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1211 kkcc_gc_stack_ptr[kkcc_gc_stack_rear].desc = desc;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1212 #ifdef DEBUG_XEMACS
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1213 kkcc_gc_stack_ptr[kkcc_gc_stack_rear].level = level;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1214 kkcc_gc_stack_ptr[kkcc_gc_stack_rear].pos = pos;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1215 #endif
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1216 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1217
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1218 #ifdef DEBUG_XEMACS
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1219
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1220 static inline void
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1221 kkcc_gc_stack_push_0 (void *data, const struct memory_description *desc,
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1222 int is_lisp DECLARE_KKCC_DEBUG_ARGS)
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1223 {
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1224 kkcc_gc_stack_push (data, desc KKCC_DEBUG_ARGS);
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1225 kkcc_gc_stack_ptr[kkcc_gc_stack_rear].is_lisp = is_lisp;
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1226 }
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1227
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1228 static inline void
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1229 kkcc_gc_stack_push_lisp (void *data, const struct memory_description *desc
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1230 DECLARE_KKCC_DEBUG_ARGS)
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1231 {
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1232 kkcc_gc_stack_push_0 (data, desc, 1 KKCC_DEBUG_ARGS);
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1233 }
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1234
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1235 static inline void
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1236 kkcc_gc_stack_push_nonlisp (void *data, const struct memory_description *desc
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1237 DECLARE_KKCC_DEBUG_ARGS)
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1238 {
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1239 kkcc_gc_stack_push_0 (data, desc, 0 KKCC_DEBUG_ARGS);
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1240 }
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1241
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1242 #else /* not DEBUG_XEMACS */
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1243
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1244 static inline void
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1245 kkcc_gc_stack_push_lisp (void *data, const struct memory_description *desc)
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1246 {
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1247 kkcc_gc_stack_push (data, desc);
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1248 }
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1249
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1250 static inline void
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1251 kkcc_gc_stack_push_nonlisp (void *data, const struct memory_description *desc)
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1252 {
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1253 kkcc_gc_stack_push (data, desc);
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1254 }
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1255
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1256 #endif /* (not) DEBUG_XEMACS */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1257
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1258 static kkcc_gc_stack_entry *
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1259 kkcc_gc_stack_pop (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1260 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1261 if (KKCC_GC_STACK_EMPTY)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1262 return 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1263 #ifdef NEW_GC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1264 GC_STAT_DEQUEUED;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1265 #endif /* NEW_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1266 #ifndef KKCC_STACK_AS_QUEUE
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1267 /* stack behaviour */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1268 return &kkcc_gc_stack_ptr[kkcc_gc_stack_rear--];
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1269 #else
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1270 /* queue behaviour */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1271 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1272 int old_front = kkcc_gc_stack_front;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1273 kkcc_gc_stack_front = KKCC_INC (kkcc_gc_stack_front);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1274 return &kkcc_gc_stack_ptr[old_front];
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1275 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1276 #endif
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1277 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1278
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1279 void
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1280 kkcc_gc_stack_push_lisp_object (Lisp_Object obj DECLARE_KKCC_DEBUG_ARGS)
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1281 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1282 if (XTYPE (obj) == Lisp_Type_Record)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1283 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1284 struct lrecord_header *lheader = XRECORD_LHEADER (obj);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1285 const struct memory_description *desc;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1286 GC_CHECK_LHEADER_INVARIANTS (lheader);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1287 desc = RECORD_DESCRIPTION (lheader);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1288 if (! MARKED_RECORD_HEADER_P (lheader))
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1289 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1290 #ifdef NEW_GC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1291 MARK_GREY (lheader);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1292 #else /* not NEW_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1293 MARK_RECORD_HEADER (lheader);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1294 #endif /* not NEW_GC */
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1295 kkcc_gc_stack_push_lisp ((void *) lheader, desc KKCC_DEBUG_ARGS);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1296 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1297 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1298 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1299
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1300 #ifdef NEW_GC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1301
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1302 void
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1303 kkcc_gc_stack_repush_dirty_object (Lisp_Object obj DECLARE_KKCC_DEBUG_ARGS)
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1304 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1305 if (XTYPE (obj) == Lisp_Type_Record)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1306 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1307 struct lrecord_header *lheader = XRECORD_LHEADER (obj);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1308 const struct memory_description *desc;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1309 GC_STAT_REPUSHED;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1310 GC_CHECK_LHEADER_INVARIANTS (lheader);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1311 desc = RECORD_DESCRIPTION (lheader);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1312 MARK_GREY (lheader);
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1313 kkcc_gc_stack_push_lisp ((void*) lheader, desc KKCC_DEBUG_ARGS);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1314 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1315 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1316 #endif /* NEW_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1317
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1318 #ifdef ERROR_CHECK_GC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1319 #define KKCC_DO_CHECK_FREE(obj, allow_free) \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1320 do \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1321 { \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1322 if (!allow_free && XTYPE (obj) == Lisp_Type_Record) \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1323 { \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1324 struct lrecord_header *lheader = XRECORD_LHEADER (obj); \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1325 GC_CHECK_NOT_FREE (lheader); \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1326 } \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1327 } while (0)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1328 #else
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1329 #define KKCC_DO_CHECK_FREE(obj, allow_free) DO_NOTHING
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1330 #endif
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1331
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1332 static inline void
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1333 mark_object_maybe_checking_free (Lisp_Object obj, int allow_free
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1334 DECLARE_KKCC_DEBUG_ARGS)
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1335 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1336 KKCC_DO_CHECK_FREE (obj, allow_free);
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1337 kkcc_gc_stack_push_lisp_object (obj KKCC_DEBUG_ARGS);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1338 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1339
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1340 /* This function loops all elements of a struct pointer and calls
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1341 mark_with_description with each element. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1342 static void
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1343 mark_struct_contents (const void *data,
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1344 const struct sized_memory_description *sdesc,
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1345 int count DECLARE_KKCC_DEBUG_ARGS)
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1346 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1347 int i;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1348 Bytecount elsize;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1349 elsize = lispdesc_block_size (data, sdesc);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1350
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1351 for (i = 0; i < count; i++)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1352 {
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1353 kkcc_gc_stack_push_nonlisp (((char *) data) + elsize * i,
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1354 sdesc->description
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1355 KKCC_DEBUG_ARGS);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1356 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1357 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1358
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1359 #ifdef NEW_GC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1360 /* This function loops all elements of a struct pointer and calls
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1361 mark_with_description with each element. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1362 static void
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1363 mark_lisp_object_block_contents (const void *data,
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1364 const struct sized_memory_description *sdesc,
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1365 int count DECLARE_KKCC_DEBUG_ARGS)
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1366 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1367 int i;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1368 Bytecount elsize;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1369 elsize = lispdesc_block_size (data, sdesc);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1370
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1371 for (i = 0; i < count; i++)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1372 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1373 const Lisp_Object obj = wrap_pointer_1 (((char *) data) + elsize * i);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1374 if (XTYPE (obj) == Lisp_Type_Record)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1375 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1376 struct lrecord_header *lheader = XRECORD_LHEADER (obj);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1377 const struct memory_description *desc;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1378 GC_CHECK_LHEADER_INVARIANTS (lheader);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1379 desc = sdesc->description;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1380 if (! MARKED_RECORD_HEADER_P (lheader))
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1381 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1382 MARK_GREY (lheader);
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1383 kkcc_gc_stack_push_lisp ((void *) lheader, desc KKCC_DEBUG_ARGS);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1384 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1385 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1386 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1387 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1388
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1389 #endif /* not NEW_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1390
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1391 /* This function implements the KKCC mark algorithm.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1392 Instead of calling mark_object, all the alive Lisp_Objects are pushed
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1393 on the kkcc_gc_stack. This function processes all elements on the stack
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1394 according to their descriptions. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1395 static void
5054
24372c7e0e8f fix build problem with pdump
Ben Wing <ben@xemacs.org>
parents: 5046
diff changeset
1396 kkcc_marking (int USED_IF_NEW_GC (cnt))
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1397 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1398 kkcc_gc_stack_entry *stack_entry = 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1399 void *data = 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1400 const struct memory_description *desc = 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1401 int pos;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1402 #ifdef NEW_GC
5046
d4f666cda5e6 some random fixups
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
1403 int obj_count = cnt;
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1404 #endif /* NEW_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1405 #ifdef DEBUG_XEMACS
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1406 int level = 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1407 #endif
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1408
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1409 while ((stack_entry = kkcc_gc_stack_pop ()) != 0)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1410 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1411 data = stack_entry->data;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1412 desc = stack_entry->desc;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1413 #ifdef DEBUG_XEMACS
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1414 level = stack_entry->level + 1;
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1415 kkcc_bt_push (data, desc, stack_entry->is_lisp, stack_entry->level,
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1416 stack_entry->pos);
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1417 #else
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1418 kkcc_bt_push (data, desc);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1419 #endif
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1420
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1421 #ifdef NEW_GC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1422 /* Mark black if object is currently grey. This first checks,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1423 if the object is really allocated on the mc-heap. If it is,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1424 it can be marked black; if it is not, it cannot be marked. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1425 maybe_mark_black (data);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1426 #endif /* NEW_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1427
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1428 if (!data) continue;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1429
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1430 gc_checking_assert (data);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1431 gc_checking_assert (desc);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1432
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1433 for (pos = 0; desc[pos].type != XD_END; pos++)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1434 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1435 const struct memory_description *desc1 = &desc[pos];
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1436 const void *rdata =
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1437 (const char *) data + lispdesc_indirect_count (desc1->offset,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1438 desc, data);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1439 union_switcheroo:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1440
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1441 /* If the flag says don't mark, then don't mark. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1442 if ((desc1->flags) & XD_FLAG_NO_KKCC)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1443 continue;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1444
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1445 switch (desc1->type)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1446 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1447 case XD_BYTECOUNT:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1448 case XD_ELEMCOUNT:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1449 case XD_HASHCODE:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1450 case XD_INT:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1451 case XD_LONG:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1452 case XD_INT_RESET:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1453 case XD_LO_LINK:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1454 case XD_OPAQUE_PTR:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1455 case XD_OPAQUE_DATA_PTR:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1456 case XD_ASCII_STRING:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1457 case XD_DOC_STRING:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1458 break;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1459 case XD_LISP_OBJECT:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1460 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1461 const Lisp_Object *stored_obj = (const Lisp_Object *) rdata;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1462
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1463 /* Because of the way that tagged objects work (pointers and
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1464 Lisp_Objects have the same representation), XD_LISP_OBJECT
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1465 can be used for untagged pointers. They might be NULL,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1466 though. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1467 if (EQ (*stored_obj, Qnull_pointer))
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1468 break;
3263
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1469 #ifdef NEW_GC
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1470 mark_object_maybe_checking_free (*stored_obj, 0
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1471 KKCC_DEBUG_ARGS);
3263
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1472 #else /* not NEW_GC */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1473 mark_object_maybe_checking_free
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1474 (*stored_obj, (desc1->flags) & XD_FLAG_FREE_LISP_OBJECT
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1475 KKCC_DEBUG_ARGS);
3263
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1476 #endif /* not NEW_GC */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1477 break;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1478 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1479 case XD_LISP_OBJECT_ARRAY:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1480 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1481 int i;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1482 EMACS_INT count =
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1483 lispdesc_indirect_count (desc1->data1, desc, data);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1484
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1485 for (i = 0; i < count; i++)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1486 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1487 const Lisp_Object *stored_obj =
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1488 (const Lisp_Object *) rdata + i;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1489
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1490 if (EQ (*stored_obj, Qnull_pointer))
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1491 break;
3263
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1492 #ifdef NEW_GC
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1493 mark_object_maybe_checking_free
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1494 (*stored_obj, 0 KKCC_DEBUG_ARGS);
3263
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1495 #else /* not NEW_GC */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1496 mark_object_maybe_checking_free
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1497 (*stored_obj, (desc1->flags) & XD_FLAG_FREE_LISP_OBJECT
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1498 KKCC_DEBUG_ARGS);
3263
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1499 #endif /* not NEW_GC */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1500 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1501 break;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1502 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1503 #ifdef NEW_GC
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1504 case XD_INLINE_LISP_OBJECT_BLOCK_PTR:
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1505 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1506 EMACS_INT count = lispdesc_indirect_count (desc1->data1, desc,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1507 data);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1508 const struct sized_memory_description *sdesc =
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1509 lispdesc_indirect_description (data, desc1->data2.descr);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1510 const char *dobj = * (const char **) rdata;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1511 if (dobj)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1512 mark_lisp_object_block_contents
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1513 (dobj, sdesc, count KKCC_DEBUG_ARGS);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1514 break;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1515 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1516 #endif /* NEW_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1517 case XD_BLOCK_PTR:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1518 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1519 EMACS_INT count = lispdesc_indirect_count (desc1->data1, desc,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1520 data);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1521 const struct sized_memory_description *sdesc =
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1522 lispdesc_indirect_description (data, desc1->data2.descr);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1523 const char *dobj = * (const char **) rdata;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1524 if (dobj)
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1525 mark_struct_contents (dobj, sdesc, count KKCC_DEBUG_ARGS);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1526 break;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1527 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1528 case XD_BLOCK_ARRAY:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1529 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1530 EMACS_INT count = lispdesc_indirect_count (desc1->data1, desc,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1531 data);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1532 const struct sized_memory_description *sdesc =
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1533 lispdesc_indirect_description (data, desc1->data2.descr);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1534
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1535 mark_struct_contents (rdata, sdesc, count KKCC_DEBUG_ARGS);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1536 break;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1537 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1538 case XD_UNION:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1539 case XD_UNION_DYNAMIC_SIZE:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1540 desc1 = lispdesc_process_xd_union (desc1, desc, data);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1541 if (desc1)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1542 goto union_switcheroo;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1543 break;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1544
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1545 default:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1546 stderr_out ("Unsupported description type : %d\n", desc1->type);
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1547 kkcc_detailed_backtrace ();
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1548 ABORT ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1549 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1550 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1551
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1552 #ifdef NEW_GC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1553 if (cnt)
5046
d4f666cda5e6 some random fixups
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
1554 if (!--obj_count)
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1555 break;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1556 #endif /* NEW_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1557 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1558 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1559 #endif /* USE_KKCC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1560
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1561 /* I hate duplicating all this crap! */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1562 int
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1563 marked_p (Lisp_Object obj)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1564 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1565 /* Checks we used to perform. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1566 /* if (EQ (obj, Qnull_pointer)) return 1; */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1567 /* if (!POINTER_TYPE_P (XGCTYPE (obj))) return 1; */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1568 /* if (PURIFIED (XPNTR (obj))) return 1; */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1569
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1570 if (XTYPE (obj) == Lisp_Type_Record)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1571 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1572 struct lrecord_header *lheader = XRECORD_LHEADER (obj);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1573
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1574 GC_CHECK_LHEADER_INVARIANTS (lheader);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1575
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1576 return MARKED_RECORD_HEADER_P (lheader);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1577 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1578 return 1;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1579 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1580
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1581
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1582 /* Mark reference to a Lisp_Object. If the object referred to has not been
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1583 seen yet, recursively mark all the references contained in it. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1584 void
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1585 mark_object (
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1586 #ifdef USE_KKCC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1587 Lisp_Object UNUSED (obj)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1588 #else
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1589 Lisp_Object obj
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1590 #endif
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1591 )
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1592 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1593 #ifdef USE_KKCC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1594 /* this code should never be reached when configured for KKCC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1595 stderr_out ("KKCC: Invalid mark_object call.\n");
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1596 stderr_out ("Replace mark_object with kkcc_gc_stack_push_lisp_object.\n");
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1597 ABORT ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1598 #else /* not USE_KKCC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1599
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1600 tail_recurse:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1601
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1602 /* Checks we used to perform */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1603 /* if (EQ (obj, Qnull_pointer)) return; */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1604 /* if (!POINTER_TYPE_P (XGCTYPE (obj))) return; */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1605 /* if (PURIFIED (XPNTR (obj))) return; */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1606
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1607 if (XTYPE (obj) == Lisp_Type_Record)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1608 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1609 struct lrecord_header *lheader = XRECORD_LHEADER (obj);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1610
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1611 GC_CHECK_LHEADER_INVARIANTS (lheader);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1612
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1613 /* We handle this separately, above, so we can mark free objects */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1614 GC_CHECK_NOT_FREE (lheader);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1615
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1616 /* All c_readonly objects have their mark bit set,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1617 so that we only need to check the mark bit here. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1618 if (! MARKED_RECORD_HEADER_P (lheader))
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1619 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1620 MARK_RECORD_HEADER (lheader);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1621
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1622 if (RECORD_MARKER (lheader))
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1623 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1624 obj = RECORD_MARKER (lheader) (obj);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1625 if (!NILP (obj)) goto tail_recurse;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1626 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1627 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1628 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1629 #endif /* not KKCC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1630 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1631
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1632
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1633 /************************************************************************/
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1634 /* Hooks */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1635 /************************************************************************/
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1636
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1637 /* Nonzero when calling certain hooks or doing other things where a GC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1638 would be bad. It prevents infinite recursive calls to gc. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1639 int gc_currently_forbidden;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1640
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1641 int
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1642 begin_gc_forbidden (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1643 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1644 return internal_bind_int (&gc_currently_forbidden, 1);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1645 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1646
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1647 void
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1648 end_gc_forbidden (int count)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1649 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1650 unbind_to (count);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1651 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1652
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1653 /* Hooks. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1654 Lisp_Object Vpre_gc_hook, Qpre_gc_hook;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1655 Lisp_Object Vpost_gc_hook, Qpost_gc_hook;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1656
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1657 /* Maybe we want to use this when doing a "panic" gc after memory_full()? */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1658 static int gc_hooks_inhibited;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1659
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1660 struct post_gc_action
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1661 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1662 void (*fun) (void *);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1663 void *arg;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1664 };
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1665
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1666 typedef struct post_gc_action post_gc_action;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1667
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1668 typedef struct
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1669 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1670 Dynarr_declare (post_gc_action);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1671 } post_gc_action_dynarr;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1672
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1673 static post_gc_action_dynarr *post_gc_actions;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1674
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1675 /* Register an action to be called at the end of GC.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1676 gc_in_progress is 0 when this is called.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1677 This is used when it is discovered that an action needs to be taken,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1678 but it's during GC, so it's not safe. (e.g. in a finalize method.)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1679
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1680 As a general rule, do not use Lisp objects here.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1681 And NEVER signal an error.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1682 */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1683
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1684 void
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1685 register_post_gc_action (void (*fun) (void *), void *arg)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1686 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1687 post_gc_action action;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1688
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1689 if (!post_gc_actions)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1690 post_gc_actions = Dynarr_new (post_gc_action);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1691
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1692 action.fun = fun;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1693 action.arg = arg;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1694
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1695 Dynarr_add (post_gc_actions, action);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1696 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1697
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1698 static void
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1699 run_post_gc_actions (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1700 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1701 int i;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1702
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1703 if (post_gc_actions)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1704 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1705 for (i = 0; i < Dynarr_length (post_gc_actions); i++)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1706 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1707 post_gc_action action = Dynarr_at (post_gc_actions, i);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1708 (action.fun) (action.arg);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1709 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1710
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1711 Dynarr_reset (post_gc_actions);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1712 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1713 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1714
3263
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1715 #ifdef NEW_GC
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1716 /* Asynchronous finalization. */
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1717 typedef struct finalize_elem
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1718 {
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1719 Lisp_Object obj;
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1720 struct finalize_elem *next;
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1721 } finalize_elem;
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1722
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1723 finalize_elem *Vall_finalizable_objs;
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1724 Lisp_Object Vfinalizers_to_run;
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1725
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1726 void
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1727 add_finalizable_obj (Lisp_Object obj)
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1728 {
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1729 finalize_elem *next = Vall_finalizable_objs;
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1730 Vall_finalizable_objs =
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1731 (finalize_elem *) xmalloc_and_zero (sizeof (finalize_elem));
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1732 Vall_finalizable_objs->obj = obj;
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1733 Vall_finalizable_objs->next = next;
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1734 }
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1735
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1736 void
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1737 register_for_finalization (void)
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1738 {
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1739 finalize_elem *rest = Vall_finalizable_objs;
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1740
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1741 if (!rest)
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1742 return;
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1743
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1744 while (!marked_p (rest->obj))
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1745 {
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1746 finalize_elem *temp = rest;
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1747 Vfinalizers_to_run = Fcons (rest->obj, Vfinalizers_to_run);
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1748 Vall_finalizable_objs = rest->next;
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4969
diff changeset
1749 xfree (temp);
3263
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1750 rest = Vall_finalizable_objs;
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1751 }
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1752
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1753 while (rest->next)
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1754 {
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1755 if (LRECORDP (rest->next->obj)
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1756 && !marked_p (rest->next->obj))
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1757 {
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1758 finalize_elem *temp = rest->next;
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1759 Vfinalizers_to_run = Fcons (rest->next->obj, Vfinalizers_to_run);
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1760 rest->next = rest->next->next;
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4969
diff changeset
1761 xfree (temp);
3263
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1762 }
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1763 else
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1764 {
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1765 rest = rest->next;
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1766 }
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1767 }
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1768 /* Keep objects alive that need to be finalized by marking
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1769 Vfinalizers_to_run transitively. */
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1770 kkcc_gc_stack_push_lisp_object_0 (Vfinalizers_to_run);
3263
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1771 kkcc_marking (0);
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1772 }
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1773
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1774 void
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1775 run_finalizers (void)
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1776 {
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1777 Lisp_Object rest;
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1778 for (rest = Vfinalizers_to_run; !NILP (rest); rest = XCDR (rest))
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1779 {
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1780 MC_ALLOC_CALL_FINALIZER (XPNTR (XCAR (rest)));
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1781 }
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1782 Vfinalizers_to_run = Qnil;
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1783 }
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1784 #endif /* not NEW_GC */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1785
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1786
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1787 /************************************************************************/
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1788 /* Garbage Collection */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1789 /************************************************************************/
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1790
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1791 /* Enable/disable incremental garbage collection during runtime. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1792 int allow_incremental_gc;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1793
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1794 /* For profiling. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1795 static Lisp_Object QSin_garbage_collection;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1796
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1797 /* Nonzero means display messages at beginning and end of GC. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1798 int garbage_collection_messages;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1799
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1800 /* "Garbage collecting" */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1801 Lisp_Object Vgc_message;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1802 Lisp_Object Vgc_pointer_glyph;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1803 static const Ascbyte gc_default_message[] = "Garbage collecting";
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1804 Lisp_Object Qgarbage_collecting;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1805
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1806 /* "Locals" during GC. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1807 struct frame *f;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1808 int speccount;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1809 int cursor_changed;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1810 Lisp_Object pre_gc_cursor;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1811
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1812 /* PROFILE_DECLARE */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1813 int do_backtrace;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1814 struct backtrace backtrace;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1815
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1816 /* Maximum amount of C stack to save when a GC happens. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1817 #ifndef MAX_SAVE_STACK
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1818 #define MAX_SAVE_STACK 0 /* 16000 */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1819 #endif
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1820
5016
2ade80e8c640 enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents: 5014
diff changeset
1821 static void
3267
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1822 show_gc_cursor_and_message (void)
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1823 {
3267
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1824 /* Now show the GC cursor/message. */
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1825 pre_gc_cursor = Qnil;
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1826 cursor_changed = 0;
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1827
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1828 /* We used to call selected_frame() here.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1829
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1830 The following functions cannot be called inside GC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1831 so we move to after the above tests. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1832 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1833 Lisp_Object frame;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1834 Lisp_Object device = Fselected_device (Qnil);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1835 if (NILP (device)) /* Could happen during startup, eg. if always_gc */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1836 return;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1837 frame = Fselected_frame (device);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1838 if (NILP (frame))
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1839 invalid_state ("No frames exist on device", device);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1840 f = XFRAME (frame);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1841 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1842
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1843 if (!noninteractive)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1844 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1845 if (FRAME_WIN_P (f))
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1846 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1847 Lisp_Object frame = wrap_frame (f);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1848 Lisp_Object cursor = glyph_image_instance (Vgc_pointer_glyph,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1849 FRAME_SELECTED_WINDOW (f),
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1850 ERROR_ME_NOT, 1);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1851 pre_gc_cursor = f->pointer;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1852 if (POINTER_IMAGE_INSTANCEP (cursor)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1853 /* don't change if we don't know how to change back. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1854 && POINTER_IMAGE_INSTANCEP (pre_gc_cursor))
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1855 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1856 cursor_changed = 1;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1857 Fset_frame_pointer (frame, cursor);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1858 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1859 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1860
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1861 /* Don't print messages to the stream device. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1862 if (!cursor_changed && !FRAME_STREAM_P (f))
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1863 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1864 if (garbage_collection_messages)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1865 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1866 Lisp_Object args[2], whole_msg;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1867 args[0] = (STRINGP (Vgc_message) ? Vgc_message :
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1868 build_msg_string (gc_default_message));
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4934
diff changeset
1869 args[1] = build_ascstring ("...");
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1870 whole_msg = Fconcat (2, args);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1871 echo_area_message (f, (Ibyte *) 0, whole_msg, 0, -1,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1872 Qgarbage_collecting);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1873 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1874 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1875 }
3267
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1876 }
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1877
5016
2ade80e8c640 enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents: 5014
diff changeset
1878 static void
3267
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1879 remove_gc_cursor_and_message (void)
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1880 {
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1881 /* Now remove the GC cursor/message */
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1882 if (!noninteractive)
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1883 {
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1884 if (cursor_changed)
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1885 Fset_frame_pointer (wrap_frame (f), pre_gc_cursor);
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1886 else if (!FRAME_STREAM_P (f))
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1887 {
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1888 /* Show "...done" only if the echo area would otherwise be empty. */
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1889 if (NILP (clear_echo_area (selected_frame (),
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1890 Qgarbage_collecting, 0)))
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1891 {
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1892 if (garbage_collection_messages)
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1893 {
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1894 Lisp_Object args[2], whole_msg;
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1895 args[0] = (STRINGP (Vgc_message) ? Vgc_message :
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1896 build_msg_string (gc_default_message));
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1897 args[1] = build_msg_string ("... done");
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1898 whole_msg = Fconcat (2, args);
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1899 echo_area_message (selected_frame (), (Ibyte *) 0,
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1900 whole_msg, 0, -1,
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1901 Qgarbage_collecting);
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1902 }
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1903 }
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1904 }
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1905 }
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1906 }
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1907
5016
2ade80e8c640 enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents: 5014
diff changeset
1908 static void
3267
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1909 gc_prepare (void)
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1910 {
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1911 #if MAX_SAVE_STACK > 0
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1912 char stack_top_variable;
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1913 extern char *stack_bottom;
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1914 #endif
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1915
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1916 #ifdef NEW_GC
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1917 GC_STAT_START_NEW_GC;
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1918 GC_SET_PHASE (INIT_GC);
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1919 #endif /* NEW_GC */
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1920
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1921 do_backtrace = profiling_active || backtrace_with_internal_sections;
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1922
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1923 assert (!gc_in_progress);
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1924 assert (!in_display || gc_currently_forbidden);
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1925
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1926 PROFILE_RECORD_ENTERING_SECTION (QSin_garbage_collection);
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1927
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1928 need_to_signal_post_gc = 0;
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1929 recompute_funcall_allocation_flag ();
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1930
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1931 if (!gc_hooks_inhibited)
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1932 run_hook_trapping_problems
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1933 (Qgarbage_collecting, Qpre_gc_hook,
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
1934 INHIBIT_EXISTING_PERMANENT_DISPLAY_OBJECT_DELETION);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1935
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1936 /***** Now we actually start the garbage collection. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1937
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1938 gc_in_progress = 1;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1939 #ifndef NEW_GC
5014
c2e0c3af5fe3 cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1940 inhibit_non_essential_conversion_operations++;
3263
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
1941 #endif /* not NEW_GC */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1942
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1943 #if MAX_SAVE_STACK > 0
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1944
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1945 /* Save a copy of the contents of the stack, for debugging. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1946 if (!purify_flag)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1947 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1948 /* Static buffer in which we save a copy of the C stack at each GC. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1949 static char *stack_copy;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1950 static Bytecount stack_copy_size;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1951
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1952 ptrdiff_t stack_diff = &stack_top_variable - stack_bottom;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1953 Bytecount stack_size = (stack_diff > 0 ? stack_diff : -stack_diff);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1954 if (stack_size < MAX_SAVE_STACK)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1955 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1956 if (stack_copy_size < stack_size)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1957 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1958 stack_copy = (char *) xrealloc (stack_copy, stack_size);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1959 stack_copy_size = stack_size;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1960 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1961
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1962 memcpy (stack_copy,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1963 stack_diff > 0 ? stack_bottom : &stack_top_variable,
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1964 stack_size);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1965 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1966 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1967 #endif /* MAX_SAVE_STACK > 0 */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1968
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1969 /* Do some totally ad-hoc resource clearing. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1970 /* #### generalize this? */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1971 clear_event_resource ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1972 cleanup_specifiers ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1973 cleanup_buffer_undo_lists ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1974 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1975
5016
2ade80e8c640 enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents: 5014
diff changeset
1976 static void
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1977 gc_mark_root_set (
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1978 #ifdef NEW_GC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1979 enum gc_phase phase
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1980 #else /* not NEW_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1981 void
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1982 #endif /* not NEW_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1983 )
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1984 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1985 #ifdef NEW_GC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1986 GC_SET_PHASE (phase);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1987 #endif /* NEW_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1988
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1989 /* Mark all the special slots that serve as the roots of accessibility. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1990
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1991 #ifdef USE_KKCC
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5168
diff changeset
1992 # define mark_object(obj) kkcc_gc_stack_push_lisp_object_0 (obj)
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1993 #endif /* USE_KKCC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1994
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1995 { /* staticpro() */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1996 Lisp_Object **p = Dynarr_begin (staticpros);
4921
17362f371cc2 add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents: 4502
diff changeset
1997 Elemcount len = Dynarr_length (staticpros);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
1998 Elemcount count;
4921
17362f371cc2 add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents: 4502
diff changeset
1999 for (count = 0; count < len; count++, p++)
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2000 /* Need to check if the pointer in the staticpro array is not
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2001 NULL. A gc can occur after variable is added to the staticpro
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2002 array and _before_ it is correctly initialized. In this case
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2003 its value is NULL, which we have to catch here. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2004 if (*p)
3486
4cc26ec3f0de [xemacs-hg @ 2006-07-02 07:32:19 by stephent]
stephent
parents: 3313
diff changeset
2005 mark_object (**p);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2006 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2007
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2008 { /* staticpro_nodump() */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2009 Lisp_Object **p = Dynarr_begin (staticpros_nodump);
4921
17362f371cc2 add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents: 4502
diff changeset
2010 Elemcount len = Dynarr_length (staticpros_nodump);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2011 Elemcount count;
4921
17362f371cc2 add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents: 4502
diff changeset
2012 for (count = 0; count < len; count++, p++)
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2013 /* Need to check if the pointer in the staticpro array is not
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2014 NULL. A gc can occur after variable is added to the staticpro
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2015 array and _before_ it is correctly initialized. In this case
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2016 its value is NULL, which we have to catch here. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2017 if (*p)
3486
4cc26ec3f0de [xemacs-hg @ 2006-07-02 07:32:19 by stephent]
stephent
parents: 3313
diff changeset
2018 mark_object (**p);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2019 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2020
3263
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
2021 #ifdef NEW_GC
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2022 { /* mcpro () */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2023 Lisp_Object *p = Dynarr_begin (mcpros);
4921
17362f371cc2 add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents: 4502
diff changeset
2024 Elemcount len = Dynarr_length (mcpros);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2025 Elemcount count;
4921
17362f371cc2 add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents: 4502
diff changeset
2026 for (count = 0; count < len; count++, p++)
17362f371cc2 add more byte-code assertions and better failure output
Ben Wing <ben@xemacs.org>
parents: 4502
diff changeset
2027 mark_object (*p);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2028 }
3263
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
2029 #endif /* NEW_GC */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2030
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2031 { /* GCPRO() */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2032 struct gcpro *tail;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2033 int i;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2034 for (tail = gcprolist; tail; tail = tail->next)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2035 for (i = 0; i < tail->nvars; i++)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2036 mark_object (tail->var[i]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2037 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2038
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2039 { /* specbind() */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2040 struct specbinding *bind;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2041 for (bind = specpdl; bind != specpdl_ptr; bind++)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2042 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2043 mark_object (bind->symbol);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2044 mark_object (bind->old_value);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2045 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2046 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2047
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2048 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2049 struct catchtag *c;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2050 for (c = catchlist; c; c = c->next)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2051 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2052 mark_object (c->tag);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2053 mark_object (c->val);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2054 mark_object (c->actual_tag);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2055 mark_object (c->backtrace);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2056 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2057 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2058
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2059 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2060 struct backtrace *backlist;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2061 for (backlist = backtrace_list; backlist; backlist = backlist->next)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2062 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2063 int nargs = backlist->nargs;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2064 int i;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2065
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2066 mark_object (*backlist->function);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2067 if (nargs < 0 /* nargs == UNEVALLED || nargs == MANY */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2068 /* might be fake (internal profiling entry) */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2069 && backlist->args)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2070 mark_object (backlist->args[0]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2071 else
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2072 for (i = 0; i < nargs; i++)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2073 mark_object (backlist->args[i]);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2074 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2075 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2076
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2077 mark_profiling_info ();
5191
71ee43b8a74d Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
2078
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2079 #ifdef USE_KKCC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2080 # undef mark_object
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2081 #endif
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2082 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2083
5016
2ade80e8c640 enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents: 5014
diff changeset
2084 static void
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2085 gc_finish_mark (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2086 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2087 #ifdef NEW_GC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2088 GC_SET_PHASE (FINISH_MARK);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2089 #endif /* NEW_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2090 init_marking_ephemerons ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2091
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2092 while (finish_marking_weak_hash_tables () > 0 ||
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2093 finish_marking_weak_lists () > 0 ||
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2094 continue_marking_ephemerons () > 0)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2095 #ifdef USE_KKCC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2096 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2097 kkcc_marking (0);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2098 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2099 #else /* not USE_KKCC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2100 ;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2101 #endif /* not USE_KKCC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2102
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2103 /* At this point, we know which objects need to be finalized: we
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2104 still need to resurrect them */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2105
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2106 while (finish_marking_ephemerons () > 0 ||
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2107 finish_marking_weak_lists () > 0 ||
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2108 finish_marking_weak_hash_tables () > 0)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2109 #ifdef USE_KKCC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2110 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2111 kkcc_marking (0);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2112 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2113 #else /* not USE_KKCC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2114 ;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2115 #endif /* not USE_KKCC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2116
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2117 /* And prune (this needs to be called after everything else has been
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2118 marked and before we do any sweeping). */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2119 /* #### this is somewhat ad-hoc and should probably be an object
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2120 method */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2121 prune_weak_hash_tables ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2122 prune_weak_lists ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2123 prune_specifiers ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2124 prune_syntax_tables ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2125
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2126 prune_ephemerons ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2127 prune_weak_boxes ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2128 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2129
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2130 #ifdef NEW_GC
5016
2ade80e8c640 enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents: 5014
diff changeset
2131 static void
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2132 gc_finalize (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2133 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2134 GC_SET_PHASE (FINALIZE);
3263
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
2135 register_for_finalization ();
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2136 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2137
5016
2ade80e8c640 enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents: 5014
diff changeset
2138 static void
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2139 gc_sweep (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2140 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2141 GC_SET_PHASE (SWEEP);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2142 mc_sweep ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2143 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2144 #endif /* NEW_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2145
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2146
5016
2ade80e8c640 enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents: 5014
diff changeset
2147 static void
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2148 gc_finish (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2149 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2150 #ifdef NEW_GC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2151 GC_SET_PHASE (FINISH_GC);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2152 #endif /* NEW_GC */
5158
9e0b43d3095c more cleanups to object-memory-usage stuff
Ben Wing <ben@xemacs.org>
parents: 5142
diff changeset
2153 finish_object_memory_usage_stats ();
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2154 consing_since_gc = 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2155 #ifndef DEBUG_XEMACS
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2156 /* Allow you to set it really fucking low if you really want ... */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2157 if (gc_cons_threshold < 10000)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2158 gc_cons_threshold = 10000;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2159 #endif
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2160 recompute_need_to_garbage_collect ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2161
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2162 #ifndef NEW_GC
5014
c2e0c3af5fe3 cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
2163 inhibit_non_essential_conversion_operations--;
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2164 #endif /* not NEW_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2165 gc_in_progress = 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2166
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2167 run_post_gc_actions ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2168
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2169 /******* End of garbage collection ********/
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2170
3263
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
2171 #ifndef NEW_GC
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2172 if (!breathing_space)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2173 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2174 breathing_space = malloc (4096 - MALLOC_OVERHEAD);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2175 }
3263
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
2176 #endif /* not NEW_GC */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2177
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2178 need_to_signal_post_gc = 1;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2179 funcall_allocation_flag = 1;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2180
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2181 PROFILE_RECORD_EXITING_SECTION (QSin_garbage_collection);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2182
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2183 #ifdef NEW_GC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2184 GC_SET_PHASE (NONE);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2185 #endif /* NEW_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2186 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2187
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2188 #ifdef NEW_GC
5016
2ade80e8c640 enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents: 5014
diff changeset
2189 static void
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2190 gc_suspend_mark_phase (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2191 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2192 PROFILE_RECORD_EXITING_SECTION (QSin_garbage_collection);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2193 write_barrier_enabled = 1;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2194 consing_since_gc = 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2195 vdb_start_dirty_bits_recording ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2196 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2197
5016
2ade80e8c640 enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents: 5014
diff changeset
2198 static int
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2199 gc_resume_mark_phase (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2200 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2201 PROFILE_RECORD_ENTERING_SECTION (QSin_garbage_collection);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2202 assert (write_barrier_enabled);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2203 vdb_stop_dirty_bits_recording ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2204 write_barrier_enabled = 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2205 return vdb_read_dirty_bits ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2206 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2207
5016
2ade80e8c640 enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents: 5014
diff changeset
2208 static int
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2209 gc_mark (int incremental)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2210 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2211 GC_SET_PHASE (MARK);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2212 if (!incremental)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2213 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2214 kkcc_marking (0);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2215 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2216 else
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2217 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2218 kkcc_marking (gc_incremental_traversal_threshold);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2219 if (!KKCC_GC_STACK_EMPTY)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2220 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2221 gc_suspend_mark_phase ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2222 return 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2223 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2224 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2225 return 1;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2226 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2227
5016
2ade80e8c640 enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents: 5014
diff changeset
2228 static int
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2229 gc_resume_mark (int incremental)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2230 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2231 if (!incremental)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2232 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2233 if (!KKCC_GC_STACK_EMPTY)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2234 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2235 GC_STAT_RESUME_GC;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2236 /* An incremental garbage collection is already running ---
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2237 now wrap it up and resume it atomically. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2238 gc_resume_mark_phase ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2239 gc_mark_root_set (REPUSH_ROOT_SET);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2240 kkcc_marking (0);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2241 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2242 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2243 else
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2244 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2245 int repushed_objects;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2246 int mark_work;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2247 GC_STAT_RESUME_GC;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2248 repushed_objects = gc_resume_mark_phase ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2249 mark_work = (gc_incremental_traversal_threshold > repushed_objects) ?
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2250 gc_incremental_traversal_threshold : repushed_objects;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2251 kkcc_marking (mark_work);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2252 if (KKCC_GC_STACK_EMPTY)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2253 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2254 /* Mark root set again and finish up marking. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2255 gc_mark_root_set (REPUSH_ROOT_SET);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2256 kkcc_marking (0);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2257 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2258 else
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2259 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2260 gc_suspend_mark_phase ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2261 return 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2262 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2263 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2264 return 1;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2265 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2266
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2267
5046
d4f666cda5e6 some random fixups
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
2268 static void
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2269 gc_1 (int incremental)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2270 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2271 switch (GC_PHASE)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2272 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2273 case NONE:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2274 gc_prepare ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2275 kkcc_gc_stack_init();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2276 #ifdef DEBUG_XEMACS
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2277 kkcc_bt_init ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2278 #endif
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2279 case INIT_GC:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2280 gc_mark_root_set (PUSH_ROOT_SET);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2281 case PUSH_ROOT_SET:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2282 if (!gc_mark (incremental))
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2283 return; /* suspend gc */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2284 case MARK:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2285 if (!KKCC_GC_STACK_EMPTY)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2286 if (!gc_resume_mark (incremental))
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2287 return; /* suspend gc */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2288 gc_finish_mark ();
3263
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
2289 case FINISH_MARK:
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
2290 gc_finalize ();
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2291 kkcc_gc_stack_free ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2292 #ifdef DEBUG_XEMACS
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2293 kkcc_bt_free ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2294 #endif
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2295 case FINALIZE:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2296 gc_sweep ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2297 case SWEEP:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2298 gc_finish ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2299 case FINISH_GC:
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2300 break;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2301 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2302 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2303
5046
d4f666cda5e6 some random fixups
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
2304 static void
d4f666cda5e6 some random fixups
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
2305 gc (int incremental)
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2306 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2307 if (gc_currently_forbidden
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2308 || in_display
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2309 || preparing_for_armageddon)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2310 return;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2311
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2312 /* Very important to prevent GC during any of the following
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2313 stuff that might run Lisp code; otherwise, we'll likely
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2314 have infinite GC recursion. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2315 speccount = begin_gc_forbidden ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2316
3267
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
2317 show_gc_cursor_and_message ();
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
2318
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2319 gc_1 (incremental);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2320
3267
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
2321 remove_gc_cursor_and_message ();
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
2322
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2323 /* now stop inhibiting GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2324 unbind_to (speccount);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2325 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2326
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2327 void
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2328 gc_full (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2329 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2330 gc (0);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2331 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2332
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2333 DEFUN ("gc-full", Fgc_full, 0, 0, "", /*
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2334 This function performs a full garbage collection. If an incremental
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2335 garbage collection is already running, it completes without any
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2336 further interruption. This function guarantees that unused objects
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2337 are freed when it returns. Garbage collection happens automatically if
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2338 the client allocates more than `gc-cons-threshold' bytes of Lisp data
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2339 since the previous garbage collection.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2340 */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2341 ())
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2342 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2343 gc_full ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2344 return Qt;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2345 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2346
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2347 void
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2348 gc_incremental (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2349 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2350 gc (allow_incremental_gc);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2351 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2352
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2353 DEFUN ("gc-incremental", Fgc_incremental, 0, 0, "", /*
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2354 This function starts an incremental garbage collection. If an
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2355 incremental garbage collection is already running, the next cycle
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2356 starts. Note that this function has not necessarily freed any memory
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2357 when it returns. This function only guarantees, that the traversal of
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2358 the heap makes progress. The next cycle of incremental garbage
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2359 collection happens automatically if the client allocates more than
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2360 `gc-incremental-cons-threshold' bytes of Lisp data since previous
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2361 garbage collection.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2362 */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2363 ())
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2364 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2365 gc_incremental ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2366 return Qt;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2367 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2368 #else /* not NEW_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2369 void garbage_collect_1 (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2370 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2371 if (gc_in_progress
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2372 || gc_currently_forbidden
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2373 || in_display
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2374 || preparing_for_armageddon)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2375 return;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2376
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2377 /* Very important to prevent GC during any of the following
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2378 stuff that might run Lisp code; otherwise, we'll likely
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2379 have infinite GC recursion. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2380 speccount = begin_gc_forbidden ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2381
3267
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
2382 show_gc_cursor_and_message ();
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
2383
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2384 gc_prepare ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2385 #ifdef USE_KKCC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2386 kkcc_gc_stack_init();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2387 #ifdef DEBUG_XEMACS
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2388 kkcc_bt_init ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2389 #endif
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2390 #endif /* USE_KKCC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2391 gc_mark_root_set ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2392 #ifdef USE_KKCC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2393 kkcc_marking (0);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2394 #endif /* USE_KKCC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2395 gc_finish_mark ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2396 #ifdef USE_KKCC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2397 kkcc_gc_stack_free ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2398 #ifdef DEBUG_XEMACS
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2399 kkcc_bt_free ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2400 #endif
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2401 #endif /* USE_KKCC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2402 gc_sweep_1 ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2403 gc_finish ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2404
3267
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
2405 remove_gc_cursor_and_message ();
a0de8be91f1b [xemacs-hg @ 2006-03-02 17:11:45 by crestani]
crestani
parents: 3263
diff changeset
2406
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2407 /* now stop inhibiting GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2408 unbind_to (speccount);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2409 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2410 #endif /* not NEW_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2411
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2412
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2413 /************************************************************************/
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2414 /* Initializations */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2415 /************************************************************************/
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2416
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2417 /* Initialization */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2418 static void
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2419 common_init_gc_early (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2420 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2421 Vgc_message = Qzero;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2422
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2423 gc_currently_forbidden = 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2424 gc_hooks_inhibited = 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2425
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2426 need_to_garbage_collect = always_gc;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2427
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2428 gc_cons_threshold = GC_CONS_THRESHOLD;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2429 gc_cons_percentage = 40; /* #### what is optimal? */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2430 total_gc_usage_set = 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2431 #ifdef NEW_GC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2432 gc_cons_incremental_threshold = GC_CONS_INCREMENTAL_THRESHOLD;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2433 gc_incremental_traversal_threshold = GC_INCREMENTAL_TRAVERSAL_THRESHOLD;
3263
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
2434 #endif /* NEW_GC */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2435 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2436
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2437 void
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2438 init_gc_early (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2439 {
3263
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
2440 #ifdef NEW_GC
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
2441 /* Reset the finalizers_to_run list after pdump_load. */
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
2442 Vfinalizers_to_run = Qnil;
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
2443 #endif /* NEW_GC */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2444 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2445
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2446 void
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2447 reinit_gc_early (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2448 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2449 common_init_gc_early ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2450 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2451
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2452 void
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2453 init_gc_once_early (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2454 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2455 common_init_gc_early ();
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2456 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2457
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2458 void
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2459 syms_of_gc (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2460 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2461 DEFSYMBOL (Qpre_gc_hook);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2462 DEFSYMBOL (Qpost_gc_hook);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2463 #ifdef NEW_GC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2464 DEFSUBR (Fgc_full);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2465 DEFSUBR (Fgc_incremental);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2466 #ifdef ERROR_CHECK_GC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2467 DEFSUBR (Fgc_stats);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2468 #endif /* not ERROR_CHECK_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2469 #endif /* NEW_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2470 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2471
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2472 void
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2473 vars_of_gc (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2474 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2475 staticpro_nodump (&pre_gc_cursor);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2476
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4934
diff changeset
2477 QSin_garbage_collection = build_defer_string ("(in garbage collection)");
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2478 staticpro (&QSin_garbage_collection);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2479
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2480 DEFVAR_INT ("gc-cons-threshold", &gc_cons_threshold /*
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2481 *Number of bytes of consing between full garbage collections.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2482 \"Consing\" is a misnomer in that this actually counts allocation
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2483 of all different kinds of objects, not just conses.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2484 Garbage collection can happen automatically once this many bytes have been
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2485 allocated since the last garbage collection. All data types count.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2486
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2487 Garbage collection happens automatically when `eval' or `funcall' are
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2488 called. (Note that `funcall' is called implicitly as part of evaluation.)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2489 By binding this temporarily to a large number, you can effectively
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2490 prevent garbage collection during a part of the program.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2491
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2492 Normally, you cannot set this value less than 10,000 (if you do, it is
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2493 automatically reset during the next garbage collection). However, if
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2494 XEmacs was compiled with DEBUG_XEMACS, this does not happen, allowing
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2495 you to set this value very low to track down problems with insufficient
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2496 GCPRO'ing. If you set this to a negative number, garbage collection will
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2497 happen at *EVERY* call to `eval' or `funcall'. This is an extremely
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2498 effective way to check GCPRO problems, but be warned that your XEmacs
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2499 will be unusable! You almost certainly won't have the patience to wait
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2500 long enough to be able to set it back.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2501
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2502 See also `consing-since-gc' and `gc-cons-percentage'.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2503 */ );
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2504
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2505 DEFVAR_INT ("gc-cons-percentage", &gc_cons_percentage /*
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2506 *Percentage of memory allocated between garbage collections.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2507
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2508 Garbage collection will happen if this percentage of the total amount of
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2509 memory used for data (see `lisp-object-memory-usage') has been allocated
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2510 since the last garbage collection. However, it will not happen if less
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2511 than `gc-cons-threshold' bytes have been allocated -- this sets an absolute
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2512 minimum in case very little data has been allocated or the percentage is
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2513 set very low. Set this to 0 to have garbage collection always happen after
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2514 `gc-cons-threshold' bytes have been allocated, regardless of current memory
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2515 usage.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2516
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2517 See also `consing-since-gc' and `gc-cons-threshold'.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2518 */ );
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2519
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2520 #ifdef NEW_GC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2521 DEFVAR_INT ("gc-cons-incremental-threshold",
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2522 &gc_cons_incremental_threshold /*
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2523 *Number of bytes of consing between cycles of incremental garbage
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2524 collections. \"Consing\" is a misnomer in that this actually counts
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2525 allocation of all different kinds of objects, not just conses. The
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2526 next garbage collection cycle can happen automatically once this many
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2527 bytes have been allocated since the last garbage collection cycle.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2528 All data types count.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2529
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2530 See also `gc-cons-threshold'.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2531 */ );
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2532
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2533 DEFVAR_INT ("gc-incremental-traversal-threshold",
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2534 &gc_incremental_traversal_threshold /*
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2535 *Number of elements processed in one cycle of incremental travesal.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2536 */ );
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2537 #endif /* NEW_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2538
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2539 DEFVAR_BOOL ("purify-flag", &purify_flag /*
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2540 Non-nil means loading Lisp code in order to dump an executable.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2541 This means that certain objects should be allocated in readonly space.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2542 */ );
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2543
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2544 DEFVAR_BOOL ("garbage-collection-messages", &garbage_collection_messages /*
4502
8748a3f7ceb4 Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4124
diff changeset
2545 *Non-nil means display messages at start and end of garbage collection.
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2546 */ );
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2547 garbage_collection_messages = 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2548
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2549 DEFVAR_LISP ("pre-gc-hook", &Vpre_gc_hook /*
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2550 Function or functions to be run just before each garbage collection.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2551 Interrupts, garbage collection, and errors are inhibited while this hook
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2552 runs, so be extremely careful in what you add here. In particular, avoid
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2553 consing, and do not interact with the user.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2554 */ );
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2555 Vpre_gc_hook = Qnil;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2556
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2557 DEFVAR_LISP ("post-gc-hook", &Vpost_gc_hook /*
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2558 Function or functions to be run just after each garbage collection.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2559 Interrupts, garbage collection, and errors are inhibited while this hook
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2560 runs. Each hook is called with one argument which is an alist with
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2561 finalization data.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2562 */ );
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2563 Vpost_gc_hook = Qnil;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2564
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2565 DEFVAR_LISP ("gc-message", &Vgc_message /*
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2566 String to print to indicate that a garbage collection is in progress.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2567 This is printed in the echo area. If the selected frame is on a
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2568 window system and `gc-pointer-glyph' specifies a value (i.e. a pointer
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2569 image instance) in the domain of the selected frame, the mouse pointer
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2570 will change instead of this message being printed.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2571 */ );
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4934
diff changeset
2572 Vgc_message = build_defer_string (gc_default_message);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2573
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2574 DEFVAR_LISP ("gc-pointer-glyph", &Vgc_pointer_glyph /*
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2575 Pointer glyph used to indicate that a garbage collection is in progress.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2576 If the selected window is on a window system and this glyph specifies a
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2577 value (i.e. a pointer image instance) in the domain of the selected
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2578 window, the pointer will be changed as specified during garbage collection.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2579 Otherwise, a message will be printed in the echo area, as controlled
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2580 by `gc-message'.
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2581 */ );
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2582
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2583 #ifdef NEW_GC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2584 DEFVAR_BOOL ("allow-incremental-gc", &allow_incremental_gc /*
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2585 *Non-nil means to allow incremental garbage collection. Nil prevents
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2586 *incremental garbage collection, the garbage collector then only does
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2587 *full collects (even if (gc-incremental) is called).
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2588 */ );
3263
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
2589
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
2590 Vfinalizers_to_run = Qnil;
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3092
diff changeset
2591 staticpro_nodump (&Vfinalizers_to_run);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2592 #endif /* NEW_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2593 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2594
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2595 void
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2596 complex_vars_of_gc (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2597 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2598 Vgc_pointer_glyph = Fmake_glyph_internal (Qpointer);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents:
diff changeset
2599 }