annotate src/mc-alloc.c @ 5891:a0e751d6c3ad

Import the #'clear-string API from GNU, use it in tls.c src/ChangeLog addition: 2015-04-18 Aidan Kehoe <kehoea@parhasard.net> * sequence.c (Fclear_string): New, API from GNU. Zero a string's contents, making sure the text is not kept around even when the string's data is reallocated because of a changed character length. * sequence.c (syms_of_sequence): Make it available to Lisp. * lisp.h: Make it available to C code. * tls.c (nss_pk11_password): Use it. * tls.c (gnutls_pk11_password): Use it. * tls.c (openssl_password): Use it. tests/ChangeLog addition: 2015-04-18 Aidan Kehoe <kehoea@parhasard.net> * automated/lisp-tests.el: Test #'clear-string, just added. Unfortunately there's no way to be certain from Lisp that the old password data has been erased after realloc; it may be worth adding a test to tests.c, but *we'll be reading memory we shouldn't be*, so that gives me pause.
author Aidan Kehoe <kehoea@parhasard.net>
date Sat, 18 Apr 2015 23:00:14 +0100
parents 56144c8593a8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1 /* New size-based allocator for XEmacs.
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
2 Copyright (C) 2005 Marcus Crestani.
5042
f395ee7ad844 Fix some compile warnings, make vdb test code conditional on DEBUG_XEMACS
Ben Wing <ben@xemacs.org>
parents: 4125
diff changeset
3 Copyright (C) 2010 Ben Wing.
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
4
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
5 This file is part of XEmacs.
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
6
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5238
diff changeset
7 XEmacs is free software: you can redistribute it and/or modify it
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5238
diff changeset
9 Free Software Foundation, either version 3 of the License, or (at your
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5238
diff changeset
10 option) any later version.
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
11
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
15 for more details.
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
16
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5238
diff changeset
18 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
19
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
20 /* Synched up with: Not in FSF. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
21
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: 5216
diff changeset
22 /*
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
23 The New 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: 5216
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: 5216
diff changeset
25 The ideas and algorithms are based on the allocator 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: 5216
diff changeset
26 Boehm-Demers-Weiser conservative garbage collector. 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: 5216
diff changeset
27 http://www.hpl.hp.com/personal/Hans_ Boehm/gc/index.html.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
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: 5216
diff changeset
29 The new allocator is enabled when 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: 5216
diff changeset
30 is enabled (with `--with-newgc'). The implementation of
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
31 the new garbage collector is in gc.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: 5216
diff changeset
32
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
33 The new allocator takes care of:
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
34 - allocating objects in a write-barrier-friendly way
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
35 - manage object's 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: 5216
diff changeset
36
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
37 Three-Level 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: 5216
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: 5216
diff changeset
39 The new allocator efficiently manages the allocation of 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: 5216
diff changeset
40 objects by minimizing the number of times malloc() and free() 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: 5216
diff changeset
41 called. The allocation process has three layers of abstraction:
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
42
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
43 1. It allocates memory in very large chunks called heap sections.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
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: 5216
diff changeset
45 2. The heap sections are subdivided into pages. The page size 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: 5216
diff changeset
46 determined by the constant PAGE_SIZE. It holds the size of a 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: 5216
diff changeset
47 in bytes.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
48
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
49 3. One page consists of one or more cells. Each cell represents
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
50 a memory location for an object. The cells on one page all have
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
51 the same size, thus every page only contains equal-sized
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
52 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: 5216
diff changeset
53
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
54 If an object is bigger than page size, it is allocated on 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: 5216
diff changeset
55 multi-page. Then there is only one cell on a multi-page (the cell
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
56 covers the full multi-page). Is an object smaller than 1/2 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: 5216
diff changeset
57 a page contains several objects and several cells. There
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
58 is only one cell on a page for object sizes from 1/2 PAGE_SIZE 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: 5216
diff changeset
59 PAGE_SIZE (whereas multi-pages always contain 2 only 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: 5216
diff changeset
60 cell). Only in layer one malloc() and free() are 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: 5216
diff changeset
61
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
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: 5216
diff changeset
63 Size Classes and Page Lists
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
64
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
65 Meta-information about every page and multi-page is kept in a 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: 5216
diff changeset
66 header. The page header contains some bookkeeping information like
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
67 number of used and free cells, and pointers to other 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: 5216
diff changeset
68 headers. The page headers are linked in a page list.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
69
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
70 Every page list builds a size class. A size class contains 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: 5216
diff changeset
71 pages (linked via page headers) for objects of the same size. 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: 5216
diff changeset
72 new allocator does not group objects based on their type, it groups
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
73 objects based on their sizes.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
74
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
75 Here is an example: A cons contains a lrecord_header, a car and cdr
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
76 field. Altogether it uses 12 bytes of memory (on 32 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: 5216
diff changeset
77 machines). All conses are allocated on pages with a cell size of 12
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
78 bytes. All theses pages are kept together in a page list, which
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
79 represents the size class for 12 bytes objects. But this size class
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
80 is not exclusively for conses only. Other objects, which are also
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
81 12 bytes big (e.g. weak-boxes), are allocated in the same 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: 5216
diff changeset
82 class and on the same pages.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
83
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
84 The number of size classes is customizable, so is the size step
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
85 between successive size classes.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
86
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
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: 5216
diff changeset
88 Used and Unused Heap
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
89
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
90 The memory which is managed by the allocator can be divided in 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: 5216
diff changeset
91 logical parts:
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
92
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
93 The used heap contains pages, on which objects are allocated. These
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
94 pages are com- pletely or partially occupied. In the used heap, 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: 5216
diff changeset
95 is important to quickly find a free spot for a 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: 5216
diff changeset
96 object. Therefore the size classes of the used heap are defined 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: 5216
diff changeset
97 the size of the cells on the pages. The size classes should match
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
98 common object sizes, to avoid wasting 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: 5216
diff changeset
99
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
100 The unused heap only contains completely empty pages. They have
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
101 never been used or have been freed completely again. In the 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: 5216
diff changeset
102 heap, the size of consecutive memory tips the scales. A page is 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: 5216
diff changeset
103 smallest entity which is asked for. Therefore, the size classes of
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
104 the unused heap are defined by the number of consecutive pages.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
105
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
106 The parameters for the different size classes can be adjusted
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
107 independently, see `configurable values' 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: 5216
diff changeset
108
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
109
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
110 The Allocator's Data Structures
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
111
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
112 The struct `mc_allocator_globals holds' all the data structures
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
113 that the new allocator uses (lists of used and unused pages, 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: 5216
diff changeset
114 bits, etc.).
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
115
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
116
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
117 Mapping of Heap Pointers to Page Headers
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
118
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
119 For caching benefits, the page headers and mark bits are stored
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
120 separately from their associated page. During 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: 5216
diff changeset
121 (i.e. for marking and freeing objects) it is important to identify
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
122 the page header which is responsible for a given Lisp object.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
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: 5216
diff changeset
124 To do this task quickly, I added a two level search tree: the upper
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
125 10 bits of the heap pointer are the index of the first level. 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: 5216
diff changeset
126 entry of the first level links to the second level, where the next
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
127 10 bits of the heap pointer are used to identify the 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: 5216
diff changeset
128 header. The remaining bits point to the object relative 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: 5216
diff changeset
129 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: 5216
diff changeset
130
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
131 On architectures with more than 32 bits pointers, a hash value of
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
132 the upper bits is used to index into the first level.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
133
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
134
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
135 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: 5216
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: 5216
diff changeset
137 For caching purposes, the mark bits are no longer kept within 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: 5216
diff changeset
138 objects, they are kept in a separate bit field.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
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: 5216
diff changeset
140 Every page header has a field for the mark bits of the 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: 5216
diff changeset
141 the page. If there are less cells on the page than there fit 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: 5216
diff changeset
142 in the integral data type EMACS_INT, the mark bits are stored
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
143 directly in this EMACS_INT.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
144
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
145 Otherwise, the mark bits are written in a separate space, with 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: 5216
diff changeset
146 page header pointing to this space. This happens to pages 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: 5216
diff changeset
147 rather small objects: many cells fit on a page, thus many 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: 5216
diff changeset
148 are needed.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
149
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
150
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
151 Allocate 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: 5216
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: 5216
diff changeset
153 Use
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
154 void *mc_alloc (size_t 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: 5216
diff changeset
155 to request memory from the allocator. This returns a pointer to 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: 5216
diff changeset
156 newly allocated block of memory of given 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: 5216
diff changeset
157
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
158 This is how the new allocator allocates 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: 5216
diff changeset
159 1. Determine the size class of the object.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
160 2. Is there already a page in this size class and is there a free
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
161 cell on this 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: 5216
diff changeset
162 * YES
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
163 3. Unlink free cell from free list, return address of free cell.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
164 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: 5216
diff changeset
165 * 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: 5216
diff changeset
166 3. Is there a page in the unused heap?
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
167 * YES
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
168 4. Move unused page to used heap.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
169 5. Initialize page header, free list, and 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: 5216
diff changeset
170 6. Unlink first cell from free list, return address of cell.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
171 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: 5216
diff changeset
172 * 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: 5216
diff changeset
173 4. Expand the heap, add new memory to unused heap
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
174 [go back to 3. and proceed with the YES case].
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
175
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
176 The allocator puts partially filled pages to the front of the 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: 5216
diff changeset
177 list, completely filled ones to the end. That guarantees a fast
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
178 terminating search for free cells. Are there two successive 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: 5216
diff changeset
179 pages at the front of the page list, the complete size class 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: 5216
diff changeset
180 full, a new page has to be added.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
181
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
182
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
183 Expand Heap
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
184
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
185 To expand the heap, a big chunk of contiguous memory is 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: 5216
diff changeset
186 using malloc(). These pieces are called heap sections. How big a 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: 5216
diff changeset
187 heap section is (and thus the growth of the heap) is adjustable: 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: 5216
diff changeset
188 MIN_HEAP_INCREASE, MAX_HEAP_INCREASE, and HEAP_GROWTH_DIVISOR 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: 5216
diff changeset
189
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
190
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
191 Free 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: 5216
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: 5216
diff changeset
193 One optimization in XEmacs is that locally used Lisp objects 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: 5216
diff changeset
194 freed manually (the memory is not wasted till the next 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: 5216
diff changeset
195 collection). Therefore the new allocator provides this function:
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
196 void mc_free (void *ptr)
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
197 That frees the object pointed to by ptr.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
198
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
199 This function is also used internally during sweep phase 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: 5216
diff changeset
200 garbage collection. This is how it works in detail:
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
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: 5216
diff changeset
202 1. Use pointer to identify page header
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
203 (use lookup mechanism described above).
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
204 2. Mark cell as free and hook it into free list.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
205 3. Is the page completely 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: 5216
diff changeset
206 * YES
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
207 4. Unlink page from page list.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
208 5. Remove page header, free list, and 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: 5216
diff changeset
209 6. Move page to unused heap.
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
210 * 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: 5216
diff changeset
211 4. Move page to front of size class (to speed up 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: 5216
diff changeset
212 of 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: 5216
diff changeset
213
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
214 If the last object of a page is freed, the empty page is returned 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: 5216
diff changeset
215 the unused heap. The allocator tries to coalesce adjacent pages, 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: 5216
diff changeset
216 gain a big piece of contiguous memory. The resulting chunk is hooked
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
217 into the according size class of the unused heap. If this created 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: 5216
diff changeset
218 complete heap section, the heap section is returned to 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: 5216
diff changeset
219 system by using free().
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
220
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
221
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
222 Allocator and 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: 5216
diff changeset
223
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
224 The new allocator simplifies the interface to 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: 5216
diff changeset
225 * mark live objects: MARK_[WHITE|GREY|BLACK] (ptr)
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
226 * sweep heap: EMACS_INT mc_sweep (void)
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
227 * run finalizers: EMACS_INT mc_finalize (void)
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
228
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
229
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
230 Allocator and Dumper
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
231
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
232 The new allocator provides special finalization for the portable
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
233 dumper (to save disk space): EMACS_INT mc_finalize_for_disksave (void)
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
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: 5216
diff changeset
235
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
236 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: 5216
diff changeset
237
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
238 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: 5216
diff changeset
239 http://crestani.de/xemacs/pdf/mc-alloc.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: 5216
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: 5216
diff changeset
241 */
2cc24c69446c Document the new allocator and the new garbage collector in gc.c and mc-alloc.c.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5216
diff changeset
242
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
243 #include <config.h>
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
244
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
245 #include "lisp.h"
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
246 #include "mc-alloc.h"
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
247 #include "getpagesize.h"
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
248
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
249
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
250 #if 0
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
251 # define USE_MARK_BITS_FREE_LIST 1
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
252 #endif
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
253 #if 1
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
254 # define BLOCKTYPE_ALLOC_PAGE_HEADER 1
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
255 #endif
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
256
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
257 /* Memory protection needs the real system-dependent pagesize. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
258 #ifndef WIN32_NATIVE
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
259 #include <unistd.h> /* for getpagesize () */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
260 #endif
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
261 #if defined (HAVE_GETPAGESIZE)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
262 # define SYS_PAGE_SIZE getpagesize ()
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
263 #elif defined (_SC_PAGESIZE)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
264 # define SYS_PAGE_SIZE sysconf (_SC_PAGESIZE)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
265 #elif defined (_SC_PAGE_SIZE)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
266 # define SYS_PAGE_SIZE sysconf (_SC_PAGE_SIZE)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
267 #elif defined(get_page_size)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
268 # define SYS_PAGE_SIZE get_page_size ()
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
269 #elif defined(PAGESIZE)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
270 # define SYS_PAGE_SIZE PAGESIZE
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
271 #elif defined(PAGE_SIZE)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
272 # define SYS_PAGE_SIZE PAGE_SIZE
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
273 #else
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
274 /* Valid page sizes are powers of 2. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
275 # define SYS_PAGE_SIZE 4096
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
276 #endif
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
277
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
278
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
279 /*--- configurable values ----------------------------------------------*/
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
280
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
281 /* Definition of size classes */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
282
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
283 /* Heap used list constants: In the used heap, it is important to
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
284 quickly find a free spot for a new object. Therefore the size
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
285 classes of the used heap are defined by the size of the cells on
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
286 the pages. The size classes should match common object sizes, to
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
287 avoid wasting memory. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
288
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
289 /* Minimum object size in bytes. */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
290 #if BITS_PER_EMACS_INT > 32
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
291 # define USED_LIST_MIN_OBJECT_SIZE 16
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
292 #else
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
293 # define USED_LIST_MIN_OBJECT_SIZE 8
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
294 #endif
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
295
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
296 /* The step size by which the size classes increase (up to upper
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
297 threshold). This many bytes are mapped to a single used list: */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
298 #if BITS_PER_EMACS_INT > 32
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
299 # define USED_LIST_LIN_STEP 8
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
300 #else
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
301 # define USED_LIST_LIN_STEP 4
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
302 #endif
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
303
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
304 /* The upper threshold should always be set to PAGE_SIZE/2, because if
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
305 a object is larger than PAGE_SIZE/2 there is no room for any other
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
306 object on this page. Objects this big are kept in the page list of
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
307 the multiple pages, since a quick search for free spots is not
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
308 needed for this kind of pages (because there are no free spots).
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
309 PAGE_SIZES_DIV_2 defines maximum size of a used space list. */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
310 #define USED_LIST_UPPER_THRESHOLD PAGE_SIZE_DIV_2
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
311
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
312
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
313 /* Heap free list constants: In the unused heap, the size of
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
314 consecutive memory tips the scales. A page is smallest entity which
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
315 is asked for. Therefore, the size classes of the unused heap are
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
316 defined by the number of consecutive pages. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
317 /* Sizes up to this many pages each have their own free list. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
318 #define FREE_LIST_LOWER_THRESHOLD 32
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
319 /* The step size by which the size classes increase (up to upper
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
320 threshold). FREE_LIST_LIN_STEP number of sizes are mapped to a
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
321 single free list for sizes between FREE_LIST_LOWER_THRESHOLD and
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
322 FREE_LIST_UPPER_THRESHOLD. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
323 #define FREE_LIST_LIN_STEP 8
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
324 /* Sizes of at least this many pages are mapped to a single free
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
325 list. Blocks of memory larger than this number are all kept in a
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
326 single list, which makes searching this list slow. But objects that
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
327 big are really seldom. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
328 #define FREE_LIST_UPPER_THRESHOLD 256
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
329
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
330
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
331 /* used heap list count */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
332 #define N_USED_PAGE_LISTS (((USED_LIST_UPPER_THRESHOLD \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
333 - USED_LIST_MIN_OBJECT_SIZE) \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
334 / USED_LIST_LIN_STEP) + 1 ) + 1
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
335
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
336 /* free heap list count */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
337 #define N_FREE_PAGE_LISTS (((FREE_LIST_UPPER_THRESHOLD \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
338 - FREE_LIST_LOWER_THRESHOLD) \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
339 / FREE_LIST_LIN_STEP) \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
340 + FREE_LIST_LOWER_THRESHOLD)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
341
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
342
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
343 /* Maximum number of separately added heap sections. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
344 #if BITS_PER_EMACS_INT > 32
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
345 # define MAX_HEAP_SECTS 2048
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
346 #else
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
347 # define MAX_HEAP_SECTS 768
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
348 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
349
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
350
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
351 /* Heap growth constants. Heap increases by any number between the
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
352 boundaries (unit is PAGE_SIZE). */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
353 #define MIN_HEAP_INCREASE 256
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
354 #define MAX_HEAP_INCREASE 256 /* not used */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
355
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
356 /* Every heap growth is calculated like this:
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
357 needed_pages + ( HEAP_SIZE / ( PAGE_SIZE * HEAP_GROWTH_DIVISOR )).
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
358 So the growth of the heap is influenced by the current size of the
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
359 heap, but kept between MIN_HEAP_INCREASE and MAX_HEAP_INCREASE
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
360 boundaries.
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
361 This reduces the number of heap sectors, the larger the heap grows
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
362 the larger are the newly allocated chunks. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
363 #define HEAP_GROWTH_DIVISOR 3
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
364
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
365
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
366 /* Zero memory before putting on free lists. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
367 #define ZERO_MEM 1
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
368
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
369
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
370 #ifndef CHAR_BIT /* should be included by limits.h */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
371 # define CHAR_BIT BITS_PER_CHAR
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
372 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
373
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
374
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
375
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
376 /*--- values depending on PAGE_SIZE ------------------------------------*/
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
377
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
378 /* initialized in init_mc_allocator () */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
379 static EMACS_INT log_page_size;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
380 static EMACS_INT page_size_div_2;
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
381
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
382 #undef PAGE_SIZE
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
383 #define PAGE_SIZE SYS_PAGE_SIZE
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
384 #define LOG_PAGE_SIZE log_page_size
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
385 #define PAGE_SIZE_DIV_2 page_size_div_2
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
386
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
387
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
388 /* Constants for heap address to page header mapping. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
389 #define LOG_LEVEL2_SIZE 10
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
390 #define LEVEL2_SIZE (1 << LOG_LEVEL2_SIZE)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
391 #if BITS_PER_EMACS_INT > 32
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
392 # define USE_HASH_TABLE 1
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
393 # define LOG_LEVEL1_SIZE 11
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
394 #else
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
395 # define LOG_LEVEL1_SIZE \
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
396 (BITS_PER_EMACS_INT - LOG_LEVEL2_SIZE - LOG_PAGE_SIZE)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
397 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
398 #define LEVEL1_SIZE (1 << LOG_LEVEL1_SIZE)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
399
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
400 #ifdef USE_HASH_TABLE
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
401 # define HASH(hi) ((hi) & (LEVEL1_SIZE - 1))
4125
93bd75c45dca [xemacs-hg @ 2007-08-17 10:16:46 by crestani]
crestani
parents: 4117
diff changeset
402 # define L1_INDEX(p) HASH ((EMACS_UINT) p >> (LOG_LEVEL2_SIZE + LOG_PAGE_SIZE))
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
403 #else
4125
93bd75c45dca [xemacs-hg @ 2007-08-17 10:16:46 by crestani]
crestani
parents: 4117
diff changeset
404 # define L1_INDEX(p) ((EMACS_UINT) p >> (LOG_LEVEL2_SIZE + LOG_PAGE_SIZE))
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
405 #endif
4125
93bd75c45dca [xemacs-hg @ 2007-08-17 10:16:46 by crestani]
crestani
parents: 4117
diff changeset
406 #define L2_INDEX(p) (((EMACS_UINT) p >> LOG_PAGE_SIZE) & (LEVEL2_SIZE - 1))
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
407
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
408
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
409
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
410
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
411 /*--- structs and typedefs ---------------------------------------------*/
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
412
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
413 /* Links the free lists (mark_bit_free_list and cell free list). */
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
414 typedef struct free_link
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
415 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
416 struct lrecord_header lheader;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
417 struct free_link *next_free;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
418 } free_link;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
419
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
420
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
421 /* Header for pages. They are held in a doubly linked list. */
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
422 typedef struct page_header
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
423 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
424 struct page_header *next; /* next page_header */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
425 struct page_header *prev; /* previous page_header */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
426 /* Field plh holds pointer to the according header of the page list.*/
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
427 struct page_list_header *plh; /* page list header */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
428 free_link *free_list; /* links free cells on page */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
429 EMACS_INT n_pages; /* number of pages */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
430 EMACS_INT cell_size; /* size of cells on page */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
431 EMACS_INT cells_on_page; /* total number of cells on page */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
432 EMACS_INT cells_used; /* number of used cells on page */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
433 /* If the number of objects on page is bigger than BITS_PER_EMACS_INT,
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
434 the mark bits are put in an extra memory area. Then the field
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
435 mark_bits holds the pointer to this area. Is the number of
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
436 objects smaller than BITS_PER_EMACS_INT, the mark bits are held in the
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
437 mark_bit EMACS_INT directly, without an additional indirection. */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
438 unsigned int black_bit:1; /* objects on page are black */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
439 unsigned int dirty_bit:1; /* page is dirty */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
440 unsigned int protection_bit:1; /* page is write protected */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
441 unsigned int array_bit:1; /* page holds arrays */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
442 Rawbyte *mark_bits; /* pointer to mark bits */
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
443 void *heap_space; /* pointer to heap, where objects
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
444 are stored */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
445 } page_header;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
446
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
447
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
448 /* Different list types. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
449 enum list_type_enum {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
450 USED_LIST,
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
451 FREE_LIST
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
452 };
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
453
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
454
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
455 /* Header for page lists. Field list_type holds the type of the list. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
456 typedef struct page_list_header
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
457 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
458 enum list_type_enum list_type; /* the type of the list */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
459 /* Size holds the size of one cell (in bytes) in a used heap list, or the
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
460 size of the heap sector (in number of pages). */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
461 size_t size; /* size of one cell / heap sector */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
462 page_header *first; /* first of page_header list */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
463 page_header *last; /* last of page_header list */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
464 /* If the number of objects on page is bigger than
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
465 BITS_PER_EMACS_INT, the mark bits are put in an extra memory
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
466 area, which is linked in this free list, if not used. Is the
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
467 number of objects smaller than BITS_PER_EMACS_INT, the mark bits
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
468 are hold in the mark bit EMACS_INT directly, without an
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
469 additional indirection. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
470 free_link *mark_bit_free_list;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
471
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
472 #ifdef MEMORY_USAGE_STATS
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
473 EMACS_INT page_count; /* number if pages in list */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
474 EMACS_INT used_cells; /* number of objects in list */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
475 EMACS_INT used_space; /* used space */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
476 EMACS_INT total_cells; /* number of available cells */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
477 EMACS_INT total_space; /* available space */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
478 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
479 } page_list_header;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
480
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
481
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
482 /* The heap sectors are stored with their real start pointer and their
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
483 real size. Not aligned to PAGE_SIZE. Needed for freeing heap sectors. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
484 typedef struct heap_sect {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
485 void *real_start; /* real start pointer (NOT aligned) */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
486 size_t real_size; /* NOT multiple of PAGE_SIZE */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
487 void *start; /* aligned start pointer */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
488 EMACS_INT n_pages; /* multiple of PAGE_SIZE */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
489 } heap_sect;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
490
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
491
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
492 /* 2nd tree level for mapping of heap addresses to page headers. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
493 typedef struct level_2_lookup_tree {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
494 page_header *index[LEVEL2_SIZE]; /* link to page header */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
495 EMACS_INT key; /* high order address bits */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
496 #ifdef USE_HASH_TABLE
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
497 struct level_2_lookup_tree *hash_link; /* hash chain link */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
498 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
499 } level_2_lookup_tree;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
500
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
501
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
502
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
503 /*--- global variable definitions --------------------------------------*/
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
504
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
505 /* All global allocator variables are kept in this struct. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
506 typedef struct mc_allocator_globals_type {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
507
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
508 /* heap size */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
509 EMACS_INT heap_size;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
510
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
511 /* list of all separatly allocated chunks of heap */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
512 heap_sect heap_sections[MAX_HEAP_SECTS];
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
513 EMACS_INT n_heap_sections;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
514
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
515 /* Holds all allocated pages, each object size class in its separate list,
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
516 to guarantee fast allocation on partially filled pages. */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
517 page_list_header *used_heap_pages;
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
518
5216
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
519 /* Holds all allocated pages that contain array elements. */
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
520 page_list_header array_heap_pages;
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
521
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
522 /* Holds all free pages in the heap. N multiples of PAGE_SIZE are
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
523 kept on the Nth free list. Contiguos pages are coalesced. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
524 page_list_header free_heap_pages[N_FREE_PAGE_LISTS];
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
525
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
526 /* ptr lookup table */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
527 level_2_lookup_tree **ptr_lookup_table;
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
528
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
529 #ifndef BLOCKTYPE_ALLOC_PAGE_HEADER
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
530 /* page header free list */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
531 free_link *page_header_free_list;
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
532 #endif /* not BLOCKTYPE_ALLOC_PAGE_HEADER */
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
533
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
534 #ifdef MEMORY_USAGE_STATS
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
535 EMACS_INT malloced_bytes;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
536 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
537 } mc_allocator_globals_type;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
538
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
539 mc_allocator_globals_type mc_allocator_globals;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
540
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
541
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
542
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
543
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
544 /*--- macro accessors --------------------------------------------------*/
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
545
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
546 #define USED_HEAP_PAGES(i) \
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
547 ((page_list_header*) &mc_allocator_globals.used_heap_pages[i])
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
548
5216
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
549 #define ARRAY_HEAP_PAGES \
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
550 ((page_list_header*) &mc_allocator_globals.array_heap_pages)
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
551
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
552 #define FREE_HEAP_PAGES(i) \
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
553 ((page_list_header*) &mc_allocator_globals.free_heap_pages[i])
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
554
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
555 #define PLH(plh) plh
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
556 # define PLH_LIST_TYPE(plh) PLH (plh)->list_type
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
557 # define PLH_SIZE(plh) PLH (plh)->size
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
558 # define PLH_FIRST(plh) PLH (plh)->first
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
559 # define PLH_LAST(plh) PLH (plh)->last
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
560 # define PLH_MARK_BIT_FREE_LIST(plh) PLH (plh)->mark_bit_free_list
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
561 #ifdef MEMORY_USAGE_STATS
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
562 # define PLH_PAGE_COUNT(plh) PLH (plh)->page_count
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
563 # define PLH_USED_CELLS(plh) PLH (plh)->used_cells
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
564 # define PLH_USED_SPACE(plh) PLH (plh)->used_space
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
565 # define PLH_TOTAL_CELLS(plh) PLH (plh)->total_cells
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
566 # define PLH_TOTAL_SPACE(plh) PLH (plh)->total_space
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
567 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
568
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
569 #define PH(ph) ph
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
570 # define PH_NEXT(ph) PH (ph)->next
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
571 # define PH_PREV(ph) PH (ph)->prev
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
572 # define PH_PLH(ph) PH (ph)->plh
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
573 # define PH_FREE_LIST(ph) PH (ph)->free_list
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
574 # define PH_N_PAGES(ph) PH (ph)->n_pages
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
575 # define PH_CELL_SIZE(ph) PH (ph)->cell_size
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
576 # define PH_CELLS_ON_PAGE(ph) PH (ph)->cells_on_page
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
577 # define PH_CELLS_USED(ph) PH (ph)->cells_used
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
578 # define PH_BLACK_BIT(ph) PH (ph)->black_bit
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
579 # define PH_DIRTY_BIT(ph) PH (ph)->dirty_bit
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
580 # define PH_PROTECTION_BIT(ph) PH (ph)->protection_bit
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
581 # define PH_ARRAY_BIT(ph) PH (ph)->array_bit
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
582 # define PH_MARK_BITS(ph) PH (ph)->mark_bits
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
583 # define PH_HEAP_SPACE(ph) PH (ph)->heap_space
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
584 #define PH_LIST_TYPE(ph) PLH_LIST_TYPE (PH_PLH (ph))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
585 #define PH_MARK_BIT_FREE_LIST(ph) PLH_MARK_BIT_FREE_LIST (PH_PLH (ph))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
586
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
587 #define HEAP_SIZE mc_allocator_globals.heap_size
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
588
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
589 #ifdef MEMORY_USAGE_STATS
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
590 # define MC_MALLOCED_BYTES mc_allocator_globals.malloced_bytes
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
591 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
592
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
593 #define HEAP_SECTION(index) mc_allocator_globals.heap_sections[index]
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
594 #define N_HEAP_SECTIONS mc_allocator_globals.n_heap_sections
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
595
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
596 #ifndef BLOCKTYPE_ALLOC_PAGE_HEADER
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
597 #define PAGE_HEADER_FREE_LIST mc_allocator_globals.page_header_free_list
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
598 #endif /* not BLOCKTYPE_ALLOC_PAGE_HEADER */
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
599
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
600 #define NEXT_FREE(free_list) ((free_link*) free_list)->next_free
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
601 #define FREE_LIST(free_list) (free_link*) (free_list)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
602
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
603 #define PTR_LOOKUP_TABLE(i) mc_allocator_globals.ptr_lookup_table[i]
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
604 #define LEVEL2(l2, i) l2->index[i]
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
605 # define LEVEL2_KEY(l2) l2->key
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
606 #ifdef USE_HASH_TABLE
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
607 # define LEVEL2_HASH_LINK(l2) l2->hash_link
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
608 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
609
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
610 #if ZERO_MEM
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
611 # define ZERO_HEAP_SPACE(ph) \
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
612 memset (PH_HEAP_SPACE (ph), '\0', PH_N_PAGES (ph) * PAGE_SIZE)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
613 # define ZERO_PAGE_HEADER(ph) memset (ph, '\0', sizeof (page_header))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
614 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
615
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
616 #define div_PAGE_SIZE(x) (x >> LOG_PAGE_SIZE)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
617 #define mult_PAGE_SIZE(x) (x << LOG_PAGE_SIZE)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
618
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
619 #define BYTES_TO_PAGES(bytes) (div_PAGE_SIZE ((bytes + (PAGE_SIZE - 1))))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
620
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
621 #define PAGE_SIZE_ALIGNMENT(address) \
4125
93bd75c45dca [xemacs-hg @ 2007-08-17 10:16:46 by crestani]
crestani
parents: 4117
diff changeset
622 (void *) ((((EMACS_UINT) (address)) + PAGE_SIZE) & ~(PAGE_SIZE - 1))
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
623
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
624 #define PH_ON_FREE_LIST_P(ph) \
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
625 (ph && PH_PLH (ph) && (PLH_LIST_TYPE (PH_PLH (ph)) == FREE_LIST))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
626
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
627 #define PH_ON_USED_LIST_P(ph) \
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
628 (ph && PH_PLH (ph) && (PLH_LIST_TYPE (PH_PLH (ph)) == USED_LIST))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
629
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
630
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
631 /* Number of mark bits: minimum 1, maximum 8. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
632 #define N_MARK_BITS 2
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
633
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
634
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
635
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
636 /************************************************************************/
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
637 /* MC Allocator */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
638 /************************************************************************/
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
639
3305
1043bbfa24cf [xemacs-hg @ 2006-03-26 15:24:25 by crestani]
crestani
parents: 3303
diff changeset
640 /* Set to 1 if memory becomes short. */
1043bbfa24cf [xemacs-hg @ 2006-03-26 15:24:25 by crestani]
crestani
parents: 3303
diff changeset
641 EMACS_INT memory_shortage;
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
642
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
643 /*--- misc functions ---------------------------------------------------*/
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
644
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
645 /* Visits all pages (page_headers) hooked into the used heap pages
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
646 list and executes f with the current page header as
3303
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
647 argument. Needed for sweep. Returns number of processed pages. */
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
648 static EMACS_INT
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
649 visit_all_used_page_headers (EMACS_INT (*f) (page_header *ph))
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
650 {
3303
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
651 EMACS_INT number_of_pages_processed = 0;
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
652 EMACS_INT i;
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
653 for (i = 0; i < N_USED_PAGE_LISTS; i++)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
654 if (PLH_FIRST (USED_HEAP_PAGES (i)))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
655 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
656 page_header *ph = PLH_FIRST (USED_HEAP_PAGES (i));
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
657 while (PH_NEXT (ph))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
658 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
659 page_header *next = PH_NEXT (ph); /* in case f removes the page */
3303
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
660 number_of_pages_processed += f (ph);
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
661 ph = next;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
662 }
3303
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
663 number_of_pages_processed += f (ph);
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
664 }
5216
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
665
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
666 if (PLH_FIRST (ARRAY_HEAP_PAGES))
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
667 {
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
668 page_header *ph = PLH_FIRST (ARRAY_HEAP_PAGES);
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
669 while (PH_NEXT (ph))
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
670 {
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
671 page_header *next = PH_NEXT (ph); /* in case f removes the page */
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
672 number_of_pages_processed += f (ph);
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
673 ph = next;
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
674 }
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
675 number_of_pages_processed += f (ph);
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
676 }
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
677
3303
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
678 return number_of_pages_processed;
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
679 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
680
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
681
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
682
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
683
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
684 /*--- mapping of heap addresses to page headers and mark bits ----------*/
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
685
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
686 /* Sets a heap pointer and page header pair into the lookup table. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
687 static void
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
688 set_lookup_table (void *ptr, page_header *ph)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
689 {
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
690 EMACS_INT l1_index = L1_INDEX (ptr);
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
691 level_2_lookup_tree *l2 = PTR_LOOKUP_TABLE (l1_index);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
692 #ifdef USE_HASH_TABLE
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
693 while ((l2) && (LEVEL2_KEY (l2) != l1_index))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
694 l2 = LEVEL2_HASH_LINK (l2);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
695 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
696 if (!l2)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
697 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
698 l2 = (level_2_lookup_tree*)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
699 xmalloc_and_zero (sizeof (level_2_lookup_tree));
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
700 #ifdef MEMORY_USAGE_STATS
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
701 MC_MALLOCED_BYTES +=
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
702 malloced_storage_size (0, sizeof (level_2_lookup_tree), 0);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
703 #endif
2932
6c70efc2b5b1 [xemacs-hg @ 2005-09-14 14:24:28 by crestani]
crestani
parents: 2775
diff changeset
704 memset (l2, '\0', sizeof (level_2_lookup_tree));
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
705 #ifdef USE_HASH_TABLE
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
706 LEVEL2_HASH_LINK (l2) = PTR_LOOKUP_TABLE (l1_index);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
707 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
708 PTR_LOOKUP_TABLE (l1_index) = l2;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
709 LEVEL2_KEY (l2) = l1_index;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
710 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
711 LEVEL2 (l2, L2_INDEX (ptr)) = ph;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
712 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
713
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
714
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
715 #ifdef UNSET_LOOKUP_TABLE
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
716 /* Set the lookup table to 0 for given heap address. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
717 static void
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
718 unset_lookup_table (void *ptr)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
719 {
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
720 EMACS_INT l1_index = L1_INDEX (ptr);
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
721 level_2_lookup_tree *l2 = PTR_LOOKUP_TABLE (l1_index);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
722 #ifdef USE_HASH_TABLE
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
723 while ((l2) && (LEVEL2_KEY (l2) != l1_index))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
724 l2 = LEVEL2_HASH_LINK (l2);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
725 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
726 if (l2) {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
727 LEVEL2 (l2, L2_INDEX (ptr)) = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
728 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
729 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
730 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
731
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
732 /* Returns the page header of a given heap address, or 0 if not in table.
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
733 For internal use, no error checking. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
734 static page_header *
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
735 get_page_header_internal (void *ptr)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
736 {
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
737 EMACS_INT l1_index = L1_INDEX (ptr);
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
738 level_2_lookup_tree *l2 = PTR_LOOKUP_TABLE (l1_index);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
739 #ifdef USE_HASH_TABLE
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
740 while ((l2) && (LEVEL2_KEY (l2) != l1_index))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
741 l2 = LEVEL2_HASH_LINK (l2);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
742 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
743 if (!l2)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
744 return 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
745 return LEVEL2 (l2, L2_INDEX (ptr));
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
746 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
747
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
748 /* Returns the page header of a given heap address, or 0 if not in table. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
749 static page_header *
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
750 get_page_header (void *ptr)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
751 {
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
752 EMACS_INT l1_index = L1_INDEX (ptr);
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
753 level_2_lookup_tree *l2 = PTR_LOOKUP_TABLE (l1_index);
2723
c474585a3460 [xemacs-hg @ 2005-04-10 00:47:53 by crestani]
crestani
parents: 2720
diff changeset
754 assert (l2);
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
755 #ifdef USE_HASH_TABLE
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
756 while ((l2) && (LEVEL2_KEY (l2) != l1_index))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
757 l2 = LEVEL2_HASH_LINK (l2);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
758 #endif
2723
c474585a3460 [xemacs-hg @ 2005-04-10 00:47:53 by crestani]
crestani
parents: 2720
diff changeset
759 assert (LEVEL2 (l2, L2_INDEX (ptr)));
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
760 return LEVEL2 (l2, L2_INDEX (ptr));
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
761 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
762
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
763 /* Returns the mark bit index of a given heap address. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
764 static EMACS_INT
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
765 get_mark_bit_index (void *ptr, page_header *ph)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
766 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
767 EMACS_INT cell_size = PH_CELL_SIZE (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
768 if (cell_size)
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
769 return (((EMACS_INT) ptr - (EMACS_INT)(PH_HEAP_SPACE (ph))) / cell_size)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
770 * N_MARK_BITS;
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
771 else /* only one object on page */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
772 return 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
773 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
774
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
775
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
776 /* Adds addresses of pages to lookup table. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
777 static void
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
778 add_pages_to_lookup_table (page_header *ph, EMACS_INT n_pages)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
779 {
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
780 Rawbyte *p = (Rawbyte *) PH_HEAP_SPACE (ph);
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
781 EMACS_INT end_of_section = (EMACS_INT) p + (PAGE_SIZE * n_pages);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
782 for (p = (Rawbyte *) PH_HEAP_SPACE (ph);
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
783 (EMACS_INT) p < end_of_section; p += PAGE_SIZE)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
784 set_lookup_table (p, ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
785 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
786
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
787
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
788 /* Initializes lookup table. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
789 static void
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
790 init_lookup_table (void)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
791 {
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
792 EMACS_INT i;
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
793 for (i = 0; i < LEVEL1_SIZE; i++)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
794 PTR_LOOKUP_TABLE (i) = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
795 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
796
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
797
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
798
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
799
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
800 /*--- mark bits --------------------------------------------------------*/
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
801
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
802 /*--- bit operations --- */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
803
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
804 /* Allocates a bit array of length bits. */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
805 static Rawbyte *
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
806 alloc_bit_array(size_t bits)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
807 {
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
808 Rawbyte *bit_array;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
809 #ifdef USE_MARK_BITS_FREE_LIST
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
810 size_t size = ((bits + CHAR_BIT - 1) / CHAR_BIT) * sizeof (Rawbyte);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
811 #else /* not USE_MARK_BITS_FREE_LIST */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
812 size_t size =
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
813 ALIGN_FOR_TYPE (((bits + CHAR_BIT - 1) / CHAR_BIT) * sizeof (Rawbyte),
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
814 Rawbyte *);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
815 #endif /* not USE_MARK_BITS_FREE_LIST */
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
816 if (size < sizeof (free_link)) size = sizeof (free_link);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
817 #ifdef MEMORY_USAGE_STATS
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
818 MC_MALLOCED_BYTES += malloced_storage_size (0, size, 0);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
819 #endif
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
820 bit_array = (Rawbyte *) xmalloc_and_zero (size);
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
821 return bit_array;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
822 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
823
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
824
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
825 /* Returns the bit value at pos. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
826 static EMACS_INT
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
827 get_bit (Rawbyte *bit_array, EMACS_INT pos)
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
828 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
829 #if N_MARK_BITS > 1
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
830 EMACS_INT result = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
831 EMACS_INT i;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
832 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
833 bit_array += pos / CHAR_BIT;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
834 #if N_MARK_BITS > 1
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
835 for (i = 0; i < N_MARK_BITS; i++)
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
836 result |= ((*bit_array & (1 << ((pos + i) % CHAR_BIT))) != 0) << i;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
837 return result;
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
838 #else
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
839 return (*bit_array & (1 << (pos % CHAR_BIT))) != 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
840 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
841 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
842
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
843
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
844 /* Bit_Arrays bit at pos to val. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
845 static void
4125
93bd75c45dca [xemacs-hg @ 2007-08-17 10:16:46 by crestani]
crestani
parents: 4117
diff changeset
846 set_bit (Rawbyte *bit_array, EMACS_INT pos, EMACS_UINT val)
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
847 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
848 #if N_MARK_BITS > 1
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
849 EMACS_INT i;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
850 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
851 bit_array += pos / CHAR_BIT;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
852 #if N_MARK_BITS > 1
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
853 for (i = 0; i < N_MARK_BITS; i++)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
854 if ((val >> i) & 1)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
855 *bit_array |= 1 << ((pos + i) % CHAR_BIT);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
856 else
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
857 *bit_array &= ~(1 << ((pos + i) % CHAR_BIT));
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
858 #else
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
859 if (val)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
860 *bit_array |= 1 << (pos % CHAR_BIT);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
861 else
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
862 *bit_array &= ~(1 << (pos % CHAR_BIT));
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
863 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
864 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
865
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
866
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
867 /*--- mark bit functions ---*/
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
868 #define USE_PNTR_MARK_BITS(ph) \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
869 ((PH_CELLS_ON_PAGE (ph) * N_MARK_BITS) > BITS_PER_EMACS_INT)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
870 #define USE_WORD_MARK_BITS(ph) \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
871 ((PH_CELLS_ON_PAGE (ph) * N_MARK_BITS) <= BITS_PER_EMACS_INT)
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
872
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
873 #define GET_BIT_WORD(b, p) get_bit ((Rawbyte *) &b, p)
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
874 #define GET_BIT_PNTR(b, p) get_bit (b, p)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
875
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
876 #define SET_BIT_WORD(b, p, v) set_bit ((Rawbyte *) &b, p, v)
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
877 #define SET_BIT_PNTR(b, p, v) set_bit (b, p, v)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
878
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
879 #define ZERO_MARK_BITS_WORD(ph) PH_MARK_BITS (ph) = 0
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
880 #define ZERO_MARK_BITS_PNTR(ph) \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
881 do { \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
882 memset (PH_MARK_BITS (ph), '\0', \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
883 ((PH_CELLS_ON_PAGE (ph) * N_MARK_BITS) \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
884 + CHAR_BIT - 1) / CHAR_BIT * sizeof (Rawbyte)); \
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
885 } while (0)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
886
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
887 #define GET_BIT(bit, ph, p) \
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
888 do { \
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
889 if (USE_PNTR_MARK_BITS (ph)) \
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
890 bit = GET_BIT_PNTR (PH_MARK_BITS (ph), p); \
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
891 else \
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
892 bit = GET_BIT_WORD (PH_MARK_BITS (ph), p); \
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
893 } while (0)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
894
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
895 #define SET_BIT(ph, p, v) \
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
896 do { \
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
897 if (USE_PNTR_MARK_BITS (ph)) \
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
898 SET_BIT_PNTR (PH_MARK_BITS (ph), p, v); \
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
899 else \
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
900 SET_BIT_WORD (PH_MARK_BITS (ph), p, v); \
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
901 } while (0)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
902
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
903 #define ZERO_MARK_BITS(ph) \
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
904 do { \
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
905 if (USE_PNTR_MARK_BITS (ph)) \
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
906 ZERO_MARK_BITS_PNTR (ph); \
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
907 else \
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
908 ZERO_MARK_BITS_WORD (ph); \
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
909 } while (0)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
910
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
911
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
912 /* Allocates mark-bit space either from a free list or from the OS
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
913 for the given page header. */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
914 static Rawbyte *
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
915 alloc_mark_bits (page_header *ph)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
916 {
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
917 Rawbyte *result;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
918 #ifdef USE_MARK_BITS_FREE_LIST
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
919 if (PH_MARK_BIT_FREE_LIST (ph) == 0)
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
920 result = (Rawbyte *) alloc_bit_array (PH_CELLS_ON_PAGE (ph) * N_MARK_BITS);
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
921 else
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
922 {
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
923 result = (Rawbyte *) PH_MARK_BIT_FREE_LIST (ph);
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
924 PH_MARK_BIT_FREE_LIST (ph) = NEXT_FREE (result);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
925 }
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
926 #else /* not USE_MARK_BITS_FREE_LIST */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
927 result = (Rawbyte *) alloc_bit_array (PH_CELLS_ON_PAGE (ph) * N_MARK_BITS);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
928 #endif /* not USE_MARK_BITS_FREE_LIST */
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
929 return result;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
930 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
931
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
932
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
933 /* Frees by maintaining a free list. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
934 static void
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
935 free_mark_bits (page_header *ph)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
936 {
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
937 #ifdef USE_MARK_BITS_FREE_LIST
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
938 NEXT_FREE (PH_MARK_BITS (ph)) = PH_MARK_BIT_FREE_LIST (ph);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
939 PH_MARK_BIT_FREE_LIST (ph) = FREE_LIST (PH_MARK_BITS (ph));
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
940 #else /* not USE_MARK_BITS_FREE_LIST */
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
941 if (PH_MARK_BITS (ph))
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
942 free (PH_MARK_BITS (ph));
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
943 #endif /* not USE_MARK_BITS_FREE_LIST */
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
944 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
945
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
946
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
947 /* Installs mark bits and zeros bits. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
948 static void
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
949 install_mark_bits (page_header *ph)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
950 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
951 if (USE_PNTR_MARK_BITS (ph))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
952 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
953 PH_MARK_BITS (ph) = alloc_mark_bits (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
954 ZERO_MARK_BITS_PNTR (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
955 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
956 else
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
957 ZERO_MARK_BITS_WORD (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
958 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
959
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
960
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
961 /* Cleans and frees the mark bits of the given page_header. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
962 static void
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
963 remove_mark_bits (page_header *ph)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
964 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
965 if (USE_PNTR_MARK_BITS (ph))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
966 free_mark_bits (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
967 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
968
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
969
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
970 /* Zeros all mark bits in given header. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
971 static void
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
972 zero_mark_bits (page_header *ph)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
973 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
974 ZERO_MARK_BITS (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
975 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
976
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
977
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
978 /* Returns mark bit for given heap pointer. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
979 EMACS_INT
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
980 get_mark_bit (void *ptr)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
981 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
982 EMACS_INT bit = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
983 page_header *ph = get_page_header (ptr);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
984 gc_checking_assert (ph && PH_ON_USED_LIST_P (ph));
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
985 if (ph)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
986 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
987 GET_BIT (bit, ph, get_mark_bit_index (ptr, ph));
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
988 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
989 return bit;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
990 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
991
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
992
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
993 /* Sets mark bit for given heap pointer. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
994 void
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
995 set_mark_bit (void *ptr, EMACS_INT value)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
996 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
997 page_header *ph = get_page_header (ptr);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
998 assert (ph && PH_ON_USED_LIST_P (ph));
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
999 if (ph)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1000 {
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1001 if (value == BLACK)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1002 if (!PH_BLACK_BIT (ph))
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1003 PH_BLACK_BIT (ph) = 1;
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1004 SET_BIT (ph, get_mark_bit_index (ptr, ph), value);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1005 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1006 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1007
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1008
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1009
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1010
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1011 /*--- page header functions --------------------------------------------*/
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1012
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1013 #ifdef BLOCKTYPE_ALLOC_PAGE_HEADER
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1014 #include "blocktype.h"
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1015
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1016 struct page_header_blocktype
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1017 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1018 Blocktype_declare (page_header);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1019 } *the_page_header_blocktype;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1020 #endif /* BLOCKTYPE_ALLOC_PAGE_HEADER */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1021
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1022 /* Allocates a page header either from a free list or from the OS. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1023 static page_header *
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1024 alloc_page_header (void)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1025 {
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1026 #ifdef BLOCKTYPE_ALLOC_PAGE_HEADER
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1027 page_header *result;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1028 #ifdef MEMORY_USAGE_STATS
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1029 MC_MALLOCED_BYTES += malloced_storage_size (0, sizeof (page_header), 0);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1030 #endif
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1031 result = Blocktype_alloc (the_page_header_blocktype);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1032 ZERO_PAGE_HEADER (result);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1033 return result;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1034 #else /* not BLOCKTYPE_ALLOC_PAGE_HEADER */
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1035 page_header *result;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1036 if (PAGE_HEADER_FREE_LIST == 0)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1037 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1038 result =
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1039 (page_header *) xmalloc_and_zero ((EMACS_INT) (sizeof (page_header)));
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1040 #ifdef MEMORY_USAGE_STATS
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1041 MC_MALLOCED_BYTES += malloced_storage_size (0, sizeof (page_header), 0);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1042 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1043 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1044 else
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1045 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1046 result = (page_header*) PAGE_HEADER_FREE_LIST;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1047 PAGE_HEADER_FREE_LIST = NEXT_FREE (result);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1048 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1049 return result;
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1050 #endif /* not BLOCKTYPE_ALLOC_PAGE_HEADER */
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1051 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1052
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1053
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1054 /* Frees given page header by maintaining a free list. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1055 static void
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1056 free_page_header (page_header *ph)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1057 {
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1058 #ifdef BLOCKTYPE_ALLOC_PAGE_HEADER
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1059 Blocktype_free (the_page_header_blocktype, ph);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1060 #else /* not BLOCKTYPE_ALLOC_PAGE_HEADER */
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1061 #if ZERO_MEM
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1062 ZERO_PAGE_HEADER (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1063 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1064 NEXT_FREE (ph) = PAGE_HEADER_FREE_LIST;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1065 PAGE_HEADER_FREE_LIST = FREE_LIST (ph);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1066 #endif /* not BLOCKTYPE_ALLOC_PAGE_HEADER */
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1067 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1068
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1069
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1070 /* Adds given page header to given page list header's list. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1071 static void
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1072 add_page_header_to_plh (page_header *ph, page_list_header *plh)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1073 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1074 /* insert at the front of the list */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1075 PH_PREV (ph) = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1076 PH_NEXT (ph) = PLH_FIRST (plh);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1077 PH_PLH (ph) = plh;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1078 /* if list is not empty, set prev in the first element */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1079 if (PLH_FIRST (plh))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1080 PH_PREV (PLH_FIRST (plh)) = ph;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1081 /* one element in list is first and last at the same time */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1082 PLH_FIRST (plh) = ph;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1083 if (!PLH_LAST (plh))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1084 PLH_LAST (plh) = ph;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1085
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1086 #ifdef MEMORY_USAGE_STATS
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1087 /* bump page count */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1088 PLH_PAGE_COUNT (plh)++;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1089 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1090
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1091 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1092
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1093
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1094 /* Removes given page header from given page list header's list. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1095 static void
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1096 remove_page_header_from_plh (page_header *ph, page_list_header *plh)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1097 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1098 if (PLH_FIRST (plh) == ph)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1099 PLH_FIRST (plh) = PH_NEXT (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1100 if (PLH_LAST (plh) == ph)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1101 PLH_LAST (plh) = PH_PREV (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1102 if (PH_NEXT (ph))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1103 PH_PREV (PH_NEXT (ph)) = PH_PREV (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1104 if (PH_PREV (ph))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1105 PH_NEXT (PH_PREV (ph)) = PH_NEXT (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1106
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1107 #ifdef MEMORY_USAGE_STATS
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1108 /* decrease page count */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1109 PLH_PAGE_COUNT (plh)--;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1110 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1111 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1112
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1113
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1114 /* Moves a page header to the front of its the page header list.
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1115 This is used during sweep: Pages with some alive objects are moved to
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1116 the front. This makes allocation faster, all pages with free slots
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1117 can be found at the front of the list. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1118 static void
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1119 move_page_header_to_front (page_header *ph)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1120 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1121 page_list_header *plh = PH_PLH (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1122 /* is page already first? */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1123 if (ph == PLH_FIRST (plh)) return;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1124 /* remove from list */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1125 if (PLH_LAST (plh) == ph)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1126 PLH_LAST (plh) = PH_PREV (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1127 if (PH_NEXT (ph))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1128 PH_PREV (PH_NEXT (ph)) = PH_PREV (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1129 if (PH_PREV (ph))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1130 PH_NEXT (PH_PREV (ph)) = PH_NEXT (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1131 /* insert at the front */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1132 PH_NEXT (ph) = PLH_FIRST (plh);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1133 PH_PREV (ph) = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1134 PH_PREV (PH_NEXT (ph)) = ph;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1135 PLH_FIRST (plh) = ph;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1136 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1137
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1138
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1139
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1140
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1141 /*--- page list functions ----------------------------------------------*/
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1142
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1143 /* Returns the index of the used heap list according to given size. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1144 static int
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1145 get_used_list_index (size_t size)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1146 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1147 if (size <= USED_LIST_MIN_OBJECT_SIZE)
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1148 {
5334
b249c479f9e1 Replace some C++ comments with C89-style /* */ comments, mc-alloc.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5238
diff changeset
1149 /* printf ("size %d -> index %d\n", size, 0); */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1150 return 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1151 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1152 if (size <= (size_t) USED_LIST_UPPER_THRESHOLD)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1153 {
5334
b249c479f9e1 Replace some C++ comments with C89-style /* */ comments, mc-alloc.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5238
diff changeset
1154 /* printf ("size %d -> index %d\n", size, */
b249c479f9e1 Replace some C++ comments with C89-style /* */ comments, mc-alloc.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5238
diff changeset
1155 /* ((size - USED_LIST_MIN_OBJECT_SIZE - 1) */
b249c479f9e1 Replace some C++ comments with C89-style /* */ comments, mc-alloc.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5238
diff changeset
1156 /* / USED_LIST_LIN_STEP) + 1); */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1157 return ((size - USED_LIST_MIN_OBJECT_SIZE - 1)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1158 / USED_LIST_LIN_STEP) + 1;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1159 }
5334
b249c479f9e1 Replace some C++ comments with C89-style /* */ comments, mc-alloc.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5238
diff changeset
1160 /* printf ("size %d -> index %d\n", size, N_USED_PAGE_LISTS - 1); */
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1161 return N_USED_PAGE_LISTS - 1;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1162 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1163
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1164 /* Returns the size of the used heap list according to given index. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1165 static size_t
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1166 get_used_list_size_value (int used_index)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1167 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1168 if (used_index < N_USED_PAGE_LISTS - 1)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1169 return (used_index * USED_LIST_LIN_STEP) + USED_LIST_MIN_OBJECT_SIZE;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1170 return 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1171 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1172
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1173
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1174 /* Returns the index of the free heap list according to given size. */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1175 static EMACS_INT
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1176 get_free_list_index (EMACS_INT n_pages)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1177 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1178 if (n_pages == 0)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1179 return 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1180 if (n_pages <= FREE_LIST_LOWER_THRESHOLD)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1181 return n_pages - 1;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1182 if (n_pages >= FREE_LIST_UPPER_THRESHOLD - 1)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1183 return N_FREE_PAGE_LISTS - 1;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1184 return ((n_pages - FREE_LIST_LOWER_THRESHOLD - 1)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1185 / FREE_LIST_LIN_STEP) + FREE_LIST_LOWER_THRESHOLD;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1186
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1187 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1188
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1189
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1190 /* Returns the size in number of pages of the given free list at index. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1191 static size_t
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1192 get_free_list_size_value (EMACS_INT free_index)
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1193 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1194 if (free_index < FREE_LIST_LOWER_THRESHOLD)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1195 return free_index + 1;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1196 if (free_index >= N_FREE_PAGE_LISTS)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1197 return FREE_LIST_UPPER_THRESHOLD;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1198 return ((free_index + 1 - FREE_LIST_LOWER_THRESHOLD)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1199 * FREE_LIST_LIN_STEP) + FREE_LIST_LOWER_THRESHOLD;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1200 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1201
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1202
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1203 Bytecount
5157
1fae11d56ad2 redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents: 5146
diff changeset
1204 mc_alloced_storage_size (Bytecount claimed_size, struct usage_stats *stats)
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1205 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1206 size_t used_size =
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1207 get_used_list_size_value (get_used_list_index (claimed_size));
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1208 if (used_size == 0)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1209 used_size = mult_PAGE_SIZE (BYTES_TO_PAGES (claimed_size));
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1210
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1211 if (stats)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1212 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1213 stats->was_requested += claimed_size;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1214 stats->malloc_overhead += used_size - claimed_size;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1215 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1216
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1217 return used_size;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1218 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1219
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1220
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1221
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1222 /*--- free heap functions ----------------------------------------------*/
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1223
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1224 /* Frees a heap section, if the heap_section is completly free */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1225 static EMACS_INT
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1226 free_heap_section (page_header *ph)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1227 {
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1228 EMACS_INT i;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1229 EMACS_INT removed = 0;
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1230 for (i = 0; i < N_HEAP_SECTIONS; i++)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1231 if (!removed)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1232 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1233 if ((PH_HEAP_SPACE (ph) == HEAP_SECTION(i).start)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1234 && (PH_N_PAGES (ph) == HEAP_SECTION(i).n_pages))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1235 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1236 xfree_1 (HEAP_SECTION(i).real_start);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1237 #ifdef MEMORY_USAGE_STATS
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1238 MC_MALLOCED_BYTES
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1239 -= malloced_storage_size (0, HEAP_SECTION(i).real_size, 0);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1240 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1241
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1242 HEAP_SIZE -= PH_N_PAGES (ph) * PAGE_SIZE;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1243
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1244 removed = 1;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1245 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1246 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1247 else
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1248 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1249 HEAP_SECTION(i-1).real_start = HEAP_SECTION(i).real_start;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1250 HEAP_SECTION(i-1).real_size = HEAP_SECTION(i).real_size;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1251 HEAP_SECTION(i-1).start = HEAP_SECTION(i).start;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1252 HEAP_SECTION(i-1).n_pages = HEAP_SECTION(i).n_pages;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1253 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1254
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1255 N_HEAP_SECTIONS = N_HEAP_SECTIONS - removed;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1256
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1257 return removed;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1258 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1259
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1260 /* Removes page from free list. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1261 static void
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1262 remove_page_from_free_list (page_header *ph)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1263 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1264 remove_page_header_from_plh (ph, PH_PLH (ph));
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1265 PH_PLH (ph) = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1266 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1267
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1268
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1269 /* Adds page to according free list. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1270 static void
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1271 add_page_to_free_list (page_header *ph)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1272 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1273 PH_PLH (ph) = FREE_HEAP_PAGES (get_free_list_index (PH_N_PAGES (ph)));
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1274 add_page_header_to_plh (ph, PH_PLH (ph));
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1275 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1276
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1277
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1278 /* Merges two adjacent pages. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1279 static page_header *
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1280 merge_pages (page_header *first_ph, page_header *second_ph)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1281 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1282 /* merge */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1283 PH_N_PAGES (first_ph) += PH_N_PAGES (second_ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1284 /* clean up left over page header */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1285 free_page_header (second_ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1286 /* update lookup table */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1287 add_pages_to_lookup_table (first_ph, PH_N_PAGES (first_ph));
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1288
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1289 return first_ph;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1290 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1291
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1292
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1293 /* Checks if pages are adjacent, merges them, and adds merged page to
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1294 free list */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1295 static void
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1296 merge_into_free_list (page_header *ph)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1297 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1298 /* check if you can coalesce adjacent pages */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1299 page_header *prev_ph =
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1300 get_page_header_internal ((void*) (((EMACS_INT) PH_HEAP_SPACE (ph))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1301 - PAGE_SIZE));
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1302 page_header *succ_ph =
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1303 get_page_header_internal ((void*) (((EMACS_INT) PH_HEAP_SPACE (ph))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1304 + (PH_N_PAGES (ph) * PAGE_SIZE)));
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1305 if (PH_ON_FREE_LIST_P (prev_ph))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1306 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1307 remove_page_from_free_list (prev_ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1308 ph = merge_pages (prev_ph, ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1309 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1310 if (PH_ON_FREE_LIST_P (succ_ph))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1311 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1312 remove_page_from_free_list (succ_ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1313 ph = merge_pages (ph, succ_ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1314 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1315 /* try to free heap_section, if the section is complete */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1316 if (!free_heap_section (ph))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1317 /* else add merged page to free list */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1318 add_page_to_free_list (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1319 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1320
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1321
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1322 /* Cuts given page header after n_pages, returns the first (cut) part, and
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1323 puts the rest on the free list. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1324 static page_header *
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1325 split_page (page_header *ph, EMACS_INT n_pages)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1326 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1327 page_header *new_ph;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1328 EMACS_INT rem_pages = PH_N_PAGES (ph) - n_pages;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1329
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1330 /* remove the page from the free list if already hooked in */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1331 if (PH_PLH (ph))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1332 remove_page_from_free_list (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1333 /* set new number of pages */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1334 PH_N_PAGES (ph) = n_pages;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1335 /* add new page to lookup table */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1336 add_pages_to_lookup_table (ph, n_pages);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1337
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1338 if (rem_pages)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1339 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1340 /* build new page with reminder */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1341 new_ph = alloc_page_header ();
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1342 PH_N_PAGES (new_ph) = rem_pages;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1343 PH_HEAP_SPACE (new_ph) =
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1344 (void*) ((EMACS_INT) (PH_HEAP_SPACE (ph)) + (n_pages * PAGE_SIZE));
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1345 /* add new page to lookup table */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1346 add_pages_to_lookup_table (new_ph, rem_pages);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1347 /* hook the rest into free list */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1348 add_page_to_free_list (new_ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1349 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1350 return ph;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1351 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1352
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1353
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1354 /* Expands the heap by given number of pages. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1355 static page_header *
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1356 expand_heap (EMACS_INT needed_pages)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1357 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1358 page_header *ph;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1359 EMACS_INT n_pages;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1360 size_t real_size;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1361 void *real_start;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1362
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1363 /* determine number of pages the heap should grow */
3305
1043bbfa24cf [xemacs-hg @ 2006-03-26 15:24:25 by crestani]
crestani
parents: 3303
diff changeset
1364 if (memory_shortage)
1043bbfa24cf [xemacs-hg @ 2006-03-26 15:24:25 by crestani]
crestani
parents: 3303
diff changeset
1365 n_pages = needed_pages;
1043bbfa24cf [xemacs-hg @ 2006-03-26 15:24:25 by crestani]
crestani
parents: 3303
diff changeset
1366 else
1043bbfa24cf [xemacs-hg @ 2006-03-26 15:24:25 by crestani]
crestani
parents: 3303
diff changeset
1367 n_pages = max (MIN_HEAP_INCREASE,
1043bbfa24cf [xemacs-hg @ 2006-03-26 15:24:25 by crestani]
crestani
parents: 3303
diff changeset
1368 needed_pages
1043bbfa24cf [xemacs-hg @ 2006-03-26 15:24:25 by crestani]
crestani
parents: 3303
diff changeset
1369 + (HEAP_SIZE / (PAGE_SIZE * HEAP_GROWTH_DIVISOR)));
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1370
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1371 /* get the real values */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1372 real_size = (n_pages * PAGE_SIZE) + PAGE_SIZE;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1373 real_start = xmalloc_and_zero (real_size);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1374 #ifdef MEMORY_USAGE_STATS
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1375 MC_MALLOCED_BYTES += malloced_storage_size (0, real_size, 0);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1376 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1377
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1378 /* maintain heap section count */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1379 if (N_HEAP_SECTIONS >= MAX_HEAP_SECTS)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1380 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1381 stderr_out ("Increase number of MAX_HEAP_SECTS");
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1382 ABORT ();
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1383 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1384 HEAP_SECTION(N_HEAP_SECTIONS).real_start = real_start;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1385 HEAP_SECTION(N_HEAP_SECTIONS).real_size = real_size;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1386 HEAP_SECTION(N_HEAP_SECTIONS).start = PAGE_SIZE_ALIGNMENT (real_start);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1387 HEAP_SECTION(N_HEAP_SECTIONS).n_pages = n_pages;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1388 N_HEAP_SECTIONS ++;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1389
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1390 /* get page header */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1391 ph = alloc_page_header ();
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1392
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1393 /* setup page header */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1394 PH_N_PAGES (ph) = n_pages;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1395 PH_HEAP_SPACE (ph) = PAGE_SIZE_ALIGNMENT (real_start);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1396 assert (((EMACS_INT) (PH_HEAP_SPACE (ph)) % PAGE_SIZE) == 0);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1397 HEAP_SIZE += n_pages * PAGE_SIZE;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1398
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1399 /* this was also done by allocate_lisp_storage */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1400 if (need_to_check_c_alloca)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1401 xemacs_c_alloca (0);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1402
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1403 /* return needed size, put rest on free list */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1404 return split_page (ph, needed_pages);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1405 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1406
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1407
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1408
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1409
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1410 /*--- used heap functions ----------------------------------------------*/
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1411 /* Installs initial free list. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1412 static void
5216
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1413 install_cell_free_list (page_header *ph)
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1414 {
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1415 Rawbyte *p;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1416 EMACS_INT i;
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1417 EMACS_INT cell_size = PH_CELL_SIZE (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1418 /* write initial free list if cell_size is < PAGE_SIZE */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1419 p = (Rawbyte *) PH_HEAP_SPACE (ph);
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1420 for (i = 0; i < PH_CELLS_ON_PAGE (ph) - 1; i++)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1421 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1422 #ifdef ERROR_CHECK_GC
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1423 assert (!LRECORD_FREE_P (p));
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1424 MARK_LRECORD_AS_FREE (p);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1425 #endif
5216
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1426 if (!PH_ARRAY_BIT (ph))
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1427 NEXT_FREE (p) = FREE_LIST (p + cell_size);
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1428 set_lookup_table (p, ph);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1429 p += cell_size;
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1430 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1431 #ifdef ERROR_CHECK_GC
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1432 assert (!LRECORD_FREE_P (p));
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1433 MARK_LRECORD_AS_FREE (p);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1434 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1435 NEXT_FREE (p) = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1436 set_lookup_table (p, ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1437
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1438 /* hook free list into header */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1439 PH_FREE_LIST (ph) = FREE_LIST (PH_HEAP_SPACE (ph));
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1440 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1441
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1442
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1443 /* Cleans the object space of the given page_header. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1444 static void
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1445 remove_cell_free_list (page_header *ph)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1446 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1447 #if ZERO_MEM
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1448 ZERO_HEAP_SPACE (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1449 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1450 PH_FREE_LIST (ph) = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1451 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1452
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1453
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1454 /* Installs a new page and hooks it into given page_list_header. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1455 static page_header *
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1456 install_page_in_used_list (page_header *ph, page_list_header *plh,
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1457 size_t size, EMACS_INT elemcount)
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1458 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1459 /* add to list */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1460 add_page_header_to_plh (ph, plh);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1461
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1462 /* determine cell size */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1463 if (PLH_SIZE (plh))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1464 PH_CELL_SIZE (ph) = PLH_SIZE (plh);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1465 else
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1466 PH_CELL_SIZE (ph) = size;
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1467 if (elemcount == 1)
5216
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1468 {
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1469 PH_CELLS_ON_PAGE (ph) = (PAGE_SIZE * PH_N_PAGES (ph)) / PH_CELL_SIZE (ph);
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1470 PH_ARRAY_BIT (ph) = 0;
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1471 }
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1472 else
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1473 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1474 PH_CELLS_ON_PAGE (ph) = elemcount;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1475 PH_ARRAY_BIT (ph) = 1;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1476 }
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1477
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1478 /* init cell count */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1479 PH_CELLS_USED (ph) = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1480
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1481 /* install mark bits and initialize cell free list */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1482 install_mark_bits (ph);
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1483
5216
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1484 install_cell_free_list (ph);
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1485
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1486 #ifdef MEMORY_USAGE_STATS
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1487 PLH_TOTAL_CELLS (plh) += PH_CELLS_ON_PAGE (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1488 PLH_TOTAL_SPACE (plh) += PAGE_SIZE * PH_N_PAGES (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1489 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1490
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1491 return ph;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1492 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1493
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1494
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1495 /* Cleans and frees a page, identified by the given page_header. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1496 static void
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1497 remove_page_from_used_list (page_header *ph)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1498 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1499 page_list_header *plh = PH_PLH (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1500
5050
6f2158fa75ed Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents: 4125
diff changeset
1501 assert (!(gc_in_progress && PH_PROTECTION_BIT (ph)));
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1502 /* cleanup: remove memory protection, zero page_header bits. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1503
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1504 #ifdef MEMORY_USAGE_STATS
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1505 PLH_TOTAL_CELLS (plh) -= PH_CELLS_ON_PAGE (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1506 PLH_TOTAL_SPACE (plh) -= PAGE_SIZE * PH_N_PAGES (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1507 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1508
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1509 /* clean up mark bits and cell free list */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1510 remove_cell_free_list (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1511 if (PH_ON_USED_LIST_P (ph))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1512 remove_mark_bits (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1513
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1514 /* clean up page header */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1515 PH_CELL_SIZE (ph) = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1516 PH_CELLS_ON_PAGE (ph) = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1517 PH_CELLS_USED (ph) = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1518
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1519 /* remove from used list */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1520 remove_page_header_from_plh (ph, plh);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1521
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1522 /* move to free list */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1523 merge_into_free_list (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1524 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1525
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1526
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1527
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1528
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1529 /*--- allocation -------------------------------------------------------*/
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1530
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1531 /* Allocates from cell free list on already allocated pages. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1532 static page_header *
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1533 allocate_cell (page_list_header *plh)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1534 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1535 page_header *ph = PLH_FIRST (plh);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1536 if (ph)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1537 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1538 if (PH_FREE_LIST (ph))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1539 /* elements free on first page */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1540 return ph;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1541 else if ((PH_NEXT (ph))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1542 && (PH_FREE_LIST (PH_NEXT (ph))))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1543 /* elements free on second page */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1544 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1545 page_header *temp = PH_NEXT (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1546 /* move full page (first page) to end of list */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1547 PH_NEXT (PLH_LAST (plh)) = ph;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1548 PH_PREV (ph) = PLH_LAST (plh);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1549 PLH_LAST (plh) = ph;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1550 PH_NEXT (ph) = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1551 /* install second page as first page */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1552 ph = temp;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1553 PH_PREV (ph) = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1554 PLH_FIRST (plh) = ph;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1555 return ph;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1556 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1557 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1558 return 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1559 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1560
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1561
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1562 /* Finds a page which has at least the needed number of pages.
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1563 Algorithm: FIRST FIT. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1564 static page_header *
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1565 find_free_page_first_fit (EMACS_INT needed_pages, page_header *ph)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1566 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1567 while (ph)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1568 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1569 if (PH_N_PAGES (ph) >= needed_pages)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1570 return ph;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1571 ph = PH_NEXT (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1572 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1573 return 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1574 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1575
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1576
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1577 /* Allocates a page from the free list. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1578 static page_header *
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1579 allocate_page_from_free_list (EMACS_INT needed_pages)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1580 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1581 page_header *ph = 0;
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1582 EMACS_INT i;
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1583 for (i = get_free_list_index (needed_pages); i < N_FREE_PAGE_LISTS; i++)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1584 if ((ph = find_free_page_first_fit (needed_pages,
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1585 PLH_FIRST (FREE_HEAP_PAGES (i)))) != 0)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1586 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1587 if (PH_N_PAGES (ph) > needed_pages)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1588 return split_page (ph, needed_pages);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1589 else
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1590 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1591 remove_page_from_free_list (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1592 return ph;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1593 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1594 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1595 return 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1596 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1597
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1598
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1599 /* Allocates a new page, either from free list or by expanding the heap. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1600 static page_header *
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1601 allocate_new_page (page_list_header *plh, size_t size, EMACS_INT elemcount)
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1602 {
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1603 EMACS_INT needed_pages = BYTES_TO_PAGES (size * elemcount);
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1604 /* first check free list */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1605 page_header *result = allocate_page_from_free_list (needed_pages);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1606 if (!result)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1607 /* expand heap */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1608 result = expand_heap (needed_pages);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1609 install_page_in_used_list (result, plh, size, elemcount);
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1610 return result;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1611 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1612
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1613
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1614 /* Selects the correct size class, tries to allocate a cell of this size
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1615 from the free list, if this fails, a new page is allocated. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1616 static void *
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1617 mc_alloc_1 (size_t size, EMACS_INT elemcount)
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1618 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1619 page_list_header *plh = 0;
2723
c474585a3460 [xemacs-hg @ 2005-04-10 00:47:53 by crestani]
crestani
parents: 2720
diff changeset
1620 page_header *ph = 0;
c474585a3460 [xemacs-hg @ 2005-04-10 00:47:53 by crestani]
crestani
parents: 2720
diff changeset
1621 void *result = 0;
c474585a3460 [xemacs-hg @ 2005-04-10 00:47:53 by crestani]
crestani
parents: 2720
diff changeset
1622
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1623 if (size == 0)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1624 return 0;
5216
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1625
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1626 if (elemcount == 1)
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1627 {
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1628 plh = USED_HEAP_PAGES (get_used_list_index (size));
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1629 if (size < (size_t) USED_LIST_UPPER_THRESHOLD)
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1630 /* first check any free cells */
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1631 ph = allocate_cell (plh);
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1632 }
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1633 else
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1634 {
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1635 plh = ARRAY_HEAP_PAGES;
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1636 }
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1637
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1638 if (!ph)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1639 /* allocate a new page */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1640 ph = allocate_new_page (plh, size, elemcount);
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1641
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1642 /* return first element of free list and remove it from the list */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1643 result = (void*) PH_FREE_LIST (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1644 PH_FREE_LIST (ph) =
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1645 NEXT_FREE (PH_FREE_LIST (ph));
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1646
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1647 memset (result, '\0', (size * elemcount));
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1648 MARK_LRECORD_AS_FREE (result);
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1649
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1650 /* bump used cells counter */
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1651 PH_CELLS_USED (ph) += elemcount;
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1652
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1653 #ifdef MEMORY_USAGE_STATS
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1654 PLH_USED_CELLS (plh) += elemcount;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1655 PLH_USED_SPACE (plh) += size * elemcount;
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1656 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1657
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1658 return result;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1659 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1660
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1661 /* Array allocation. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1662 void *
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1663 mc_alloc_array (size_t size, EMACS_INT elemcount)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1664 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1665 return mc_alloc_1 (size, elemcount);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1666 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1667
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1668 void *
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1669 mc_alloc (size_t size)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1670 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1671 return mc_alloc_1 (size, 1);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1672 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1673
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1674
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1675
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1676 /*--- sweep & free & finalize-------------------------------------------*/
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1677
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1678 /* Frees a heap pointer. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1679 static void
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1680 remove_cell (void *ptr, page_header *ph)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1681 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1682 #ifdef MEMORY_USAGE_STATS
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1683 PLH_USED_CELLS (PH_PLH (ph))--;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1684 if (PH_ON_USED_LIST_P (ph))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1685 PLH_USED_SPACE (PH_PLH (ph)) -=
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1686 detagged_lisp_object_size ((const struct lrecord_header *) ptr);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1687 else
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1688 PLH_USED_SPACE (PH_PLH (ph)) -= PH_CELL_SIZE (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1689 #endif
2775
05d62157e048 [xemacs-hg @ 2005-05-15 16:37:52 by crestani]
crestani
parents: 2723
diff changeset
1690 if (PH_ON_USED_LIST_P (ph))
05d62157e048 [xemacs-hg @ 2005-05-15 16:37:52 by crestani]
crestani
parents: 2723
diff changeset
1691 {
2994
ec5f23ea6d2e [xemacs-hg @ 2005-10-14 01:21:57 by ben]
ben
parents: 2932
diff changeset
1692 #ifdef ALLOC_TYPE_STATS
2775
05d62157e048 [xemacs-hg @ 2005-05-15 16:37:52 by crestani]
crestani
parents: 2723
diff changeset
1693 dec_lrecord_stats (PH_CELL_SIZE (ph),
05d62157e048 [xemacs-hg @ 2005-05-15 16:37:52 by crestani]
crestani
parents: 2723
diff changeset
1694 (const struct lrecord_header *) ptr);
2994
ec5f23ea6d2e [xemacs-hg @ 2005-10-14 01:21:57 by ben]
ben
parents: 2932
diff changeset
1695 #endif /* ALLOC_TYPE_STATS */
2775
05d62157e048 [xemacs-hg @ 2005-05-15 16:37:52 by crestani]
crestani
parents: 2723
diff changeset
1696 #ifdef ERROR_CHECK_GC
05d62157e048 [xemacs-hg @ 2005-05-15 16:37:52 by crestani]
crestani
parents: 2723
diff changeset
1697 assert (!LRECORD_FREE_P (ptr));
05d62157e048 [xemacs-hg @ 2005-05-15 16:37:52 by crestani]
crestani
parents: 2723
diff changeset
1698 deadbeef_memory (ptr, PH_CELL_SIZE (ph));
05d62157e048 [xemacs-hg @ 2005-05-15 16:37:52 by crestani]
crestani
parents: 2723
diff changeset
1699 MARK_LRECORD_AS_FREE (ptr);
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1700 #endif
2775
05d62157e048 [xemacs-hg @ 2005-05-15 16:37:52 by crestani]
crestani
parents: 2723
diff changeset
1701 }
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1702
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1703 /* hooks cell into free list */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1704 NEXT_FREE (ptr) = PH_FREE_LIST (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1705 PH_FREE_LIST (ph) = FREE_LIST (ptr);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1706 /* decrease cells used */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1707 PH_CELLS_USED (ph)--;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1708 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1709
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1710
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1711 /* Mark free list marks all free list entries. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1712 static void
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1713 mark_free_list (page_header *ph)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1714 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1715 free_link *fl = PH_FREE_LIST (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1716 while (fl)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1717 {
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1718 SET_BIT (ph, get_mark_bit_index (fl, ph), BLACK);
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1719 fl = NEXT_FREE (fl);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1720 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1721 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1722
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1723
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1724 /* Finalize a page for disksave. XEmacs calls this routine before it
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1725 dumps the heap image. You have to tell mc-alloc how to call your
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1726 object's finalizer for disksave. Therefore, you have to define the
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1727 macro MC_ALLOC_CALL_FINALIZER_FOR_DISKSAVE(ptr). This macro should
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1728 do nothing else then test if there is a finalizer and call it on
3303
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
1729 the given argument, which is the heap address of the object.
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
1730 Returns number of processed pages. */
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
1731 static EMACS_INT
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1732 finalize_page_for_disksave (page_header *ph)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1733 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1734 EMACS_INT heap_space = (EMACS_INT) PH_HEAP_SPACE (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1735 EMACS_INT heap_space_step = PH_CELL_SIZE (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1736 EMACS_INT mark_bit = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1737 EMACS_INT mark_bit_max_index = PH_CELLS_ON_PAGE (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1738
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1739 for (mark_bit = 0; mark_bit < mark_bit_max_index; mark_bit++)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1740 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1741 EMACS_INT ptr = (heap_space + (heap_space_step * mark_bit));
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1742 MC_ALLOC_CALL_FINALIZER_FOR_DISKSAVE ((void *) ptr);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1743 }
3303
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
1744 return 1;
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1745 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1746
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1747
3303
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
1748 /* Finalizes the heap for disksave. Returns number of processed
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
1749 pages. */
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
1750 EMACS_INT
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1751 mc_finalize_for_disksave (void)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1752 {
3303
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
1753 return visit_all_used_page_headers (finalize_page_for_disksave);
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1754 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1755
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1756
3303
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
1757 /* Sweeps a page: all the non-marked cells are freed. If the page is
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
1758 empty in the end, it is removed. If some cells are free, it is
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
1759 moved to the front of its page header list. Full pages stay where
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
1760 they are. Returns number of processed pages.*/
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
1761 static EMACS_INT
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1762 sweep_page (page_header *ph)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1763 {
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1764 Rawbyte *heap_space = (Rawbyte *) PH_HEAP_SPACE (ph);
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1765 EMACS_INT heap_space_step = PH_CELL_SIZE (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1766 EMACS_INT mark_bit = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1767 EMACS_INT mark_bit_max_index = PH_CELLS_ON_PAGE (ph);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1768 unsigned int bit = 0;
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1769
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1770 mark_free_list (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1771
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1772 /* ARRAY_BIT_HACK */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1773 if (PH_ARRAY_BIT (ph))
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1774 for (mark_bit = 0; mark_bit < mark_bit_max_index; mark_bit++)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1775 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1776 GET_BIT (bit, ph, mark_bit * N_MARK_BITS);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1777 if (bit)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1778 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1779 zero_mark_bits (ph);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1780 PH_BLACK_BIT (ph) = 0;
3303
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
1781 return 1;
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1782 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1783 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1784
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1785 for (mark_bit = 0; mark_bit < mark_bit_max_index; mark_bit++)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1786 {
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1787 GET_BIT (bit, ph, mark_bit * N_MARK_BITS);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1788 if (bit == WHITE)
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1789 {
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1790 GC_STAT_FREED;
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1791 remove_cell (heap_space + (heap_space_step * mark_bit), ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1792 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1793 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1794 zero_mark_bits (ph);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1795 PH_BLACK_BIT (ph) = 0;
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1796 if (PH_CELLS_USED (ph) == 0)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1797 remove_page_from_used_list (ph);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1798 else if (PH_CELLS_USED (ph) < PH_CELLS_ON_PAGE (ph))
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1799 move_page_header_to_front (ph);
3303
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
1800
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
1801 return 1;
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1802 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1803
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1804
3303
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
1805 /* Sweeps the heap. Returns number of processed pages. */
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
1806 EMACS_INT
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1807 mc_sweep (void)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1808 {
3303
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
1809 return visit_all_used_page_headers (sweep_page);
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1810 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1811
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1812
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1813 /* Changes the size of the cell pointed to by ptr.
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1814 Returns the new address of the new cell with new size. */
5042
f395ee7ad844 Fix some compile warnings, make vdb test code conditional on DEBUG_XEMACS
Ben Wing <ben@xemacs.org>
parents: 4125
diff changeset
1815 static void *
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1816 mc_realloc_1 (void *ptr, size_t size, int elemcount)
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1817 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1818 if (ptr)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1819 {
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1820 if (size * elemcount)
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1821 {
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1822 void *result = mc_alloc_1 (size, elemcount);
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1823 size_t from_size = PH_CELL_SIZE (get_page_header (ptr));
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1824 size_t cpy_size = size * elemcount;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1825 if (cpy_size > from_size)
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1826 cpy_size = from_size;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1827 memcpy (result, ptr, cpy_size);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1828 #ifdef ALLOC_TYPE_STATS
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1829 inc_lrecord_stats (size, (struct lrecord_header *) result);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1830 #endif /* not ALLOC_TYPE_STATS */
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1831 return result;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1832 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1833 else
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1834 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1835 return 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1836 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1837 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1838 else
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1839 return mc_alloc_1 (size, elemcount);
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1840 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1841
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1842 void *
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1843 mc_realloc (void *ptr, size_t size)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1844 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1845 return mc_realloc_1 (ptr, size, 1);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1846 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1847
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1848 void *
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1849 mc_realloc_array (void *ptr, size_t size, EMACS_INT elemcount)
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1850 {
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1851 return mc_realloc_1 (ptr, size, elemcount);
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1852 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1853
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1854
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1855
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1856 /*--- initialization ---------------------------------------------------*/
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1857
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1858 /* Call once at the very beginning. */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1859 void
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1860 init_mc_allocator (void)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1861 {
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1862 EMACS_INT i;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1863
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1864 #ifdef MEMORY_USAGE_STATS
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1865 MC_MALLOCED_BYTES = 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1866 #endif
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1867
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1868 /* init of pagesize dependent values */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1869 switch (SYS_PAGE_SIZE)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1870 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1871 case 512: log_page_size = 9; break;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1872 case 1024: log_page_size = 10; break;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1873 case 2048: log_page_size = 11; break;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1874 case 4096: log_page_size = 12; break;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1875 case 8192: log_page_size = 13; break;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1876 case 16384: log_page_size = 14; break;
3212
26a547441418 [xemacs-hg @ 2006-01-21 13:34:20 by crestani]
crestani
parents: 3092
diff changeset
1877 case 32768: log_page_size = 15; break;
26a547441418 [xemacs-hg @ 2006-01-21 13:34:20 by crestani]
crestani
parents: 3092
diff changeset
1878 case 65536: log_page_size = 16; break;
26a547441418 [xemacs-hg @ 2006-01-21 13:34:20 by crestani]
crestani
parents: 3092
diff changeset
1879 default:
26a547441418 [xemacs-hg @ 2006-01-21 13:34:20 by crestani]
crestani
parents: 3092
diff changeset
1880 fprintf(stderr, "##### SYS_PAGE_SIZE=%d not supported #####\n",
26a547441418 [xemacs-hg @ 2006-01-21 13:34:20 by crestani]
crestani
parents: 3092
diff changeset
1881 SYS_PAGE_SIZE);
26a547441418 [xemacs-hg @ 2006-01-21 13:34:20 by crestani]
crestani
parents: 3092
diff changeset
1882 ABORT ();
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1883 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1884
4125
93bd75c45dca [xemacs-hg @ 2007-08-17 10:16:46 by crestani]
crestani
parents: 4117
diff changeset
1885 page_size_div_2 = (EMACS_UINT) SYS_PAGE_SIZE >> 1;
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1886
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1887 mc_allocator_globals.used_heap_pages =
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1888 (page_list_header *) xmalloc_and_zero ((N_USED_PAGE_LISTS + 1)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1889 * sizeof (page_list_header));
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1890 #ifdef MEMORY_USAGE_STATS
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1891 MC_MALLOCED_BYTES += (N_USED_PAGE_LISTS + 1) * sizeof (page_list_header);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1892 #endif
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1893
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1894 mc_allocator_globals.ptr_lookup_table =
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1895 (level_2_lookup_tree **)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1896 xmalloc_and_zero ((LEVEL1_SIZE + 1) * sizeof (level_2_lookup_tree *));
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1897 #ifdef MEMORY_USAGE_STATS
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1898 MC_MALLOCED_BYTES += (LEVEL1_SIZE + 1) * sizeof (level_2_lookup_tree *);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1899 #endif
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1900
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1901 #ifdef BLOCKTYPE_ALLOC_PAGE_HEADER
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1902 the_page_header_blocktype = Blocktype_new (struct page_header_blocktype);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1903 #endif /* BLOCKTYPE_ALLOC_PAGE_HEADER */
2932
6c70efc2b5b1 [xemacs-hg @ 2005-09-14 14:24:28 by crestani]
crestani
parents: 2775
diff changeset
1904
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1905 for (i = 0; i < N_USED_PAGE_LISTS; i++)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1906 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1907 page_list_header *plh = USED_HEAP_PAGES (i);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1908 PLH_LIST_TYPE (plh) = USED_LIST;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1909 PLH_SIZE (plh) = get_used_list_size_value (i);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1910 PLH_FIRST (plh) = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1911 PLH_LAST (plh) = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1912 PLH_MARK_BIT_FREE_LIST (plh) = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1913 #ifdef MEMORY_USAGE_STATS
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1914 PLH_PAGE_COUNT (plh) = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1915 PLH_USED_CELLS (plh) = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1916 PLH_USED_SPACE (plh) = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1917 PLH_TOTAL_CELLS (plh) = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1918 PLH_TOTAL_SPACE (plh) = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1919 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1920 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1921
5216
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1922 {
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1923 page_list_header *plh = ARRAY_HEAP_PAGES;
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1924 PLH_LIST_TYPE (plh) = USED_LIST;
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1925 PLH_SIZE (plh) = 0;
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1926 PLH_FIRST (plh) = 0;
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1927 PLH_LAST (plh) = 0;
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1928 PLH_MARK_BIT_FREE_LIST (plh) = 0;
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1929 #ifdef MEMORY_USAGE_STATS
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1930 PLH_PAGE_COUNT (plh) = 0;
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1931 PLH_USED_CELLS (plh) = 0;
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1932 PLH_USED_SPACE (plh) = 0;
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1933 PLH_TOTAL_CELLS (plh) = 0;
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1934 PLH_TOTAL_SPACE (plh) = 0;
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1935 #endif
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1936 }
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
1937
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1938 for (i = 0; i < N_FREE_PAGE_LISTS; i++)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1939 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1940 page_list_header *plh = FREE_HEAP_PAGES (i);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1941 PLH_LIST_TYPE (plh) = FREE_LIST;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1942 PLH_SIZE (plh) = get_free_list_size_value (i);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1943 PLH_FIRST (plh) = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1944 PLH_LAST (plh) = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1945 PLH_MARK_BIT_FREE_LIST (plh) = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1946 #ifdef MEMORY_USAGE_STATS
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1947 PLH_PAGE_COUNT (plh) = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1948 PLH_USED_CELLS (plh) = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1949 PLH_USED_SPACE (plh) = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1950 PLH_TOTAL_CELLS (plh) = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1951 PLH_TOTAL_SPACE (plh) = 0;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1952 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1953 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1954
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1955 #ifndef BLOCKTYPE_ALLOC_PAGE_HEADER
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1956 PAGE_HEADER_FREE_LIST = 0;
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1957 #endif /* not BLOCKTYPE_ALLOC_PAGE_HEADER */
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1958
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1959 #ifdef MEMORY_USAGE_STATS
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1960 MC_MALLOCED_BYTES += sizeof (mc_allocator_globals);
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1961 #endif
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1962
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1963 init_lookup_table ();
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1964 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1965
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1966
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1967
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1968
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1969 /*--- lisp function for statistics -------------------------------------*/
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1970
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1971 #ifdef MEMORY_USAGE_STATS
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1972 DEFUN ("mc-alloc-memory-usage", Fmc_alloc_memory_usage, 0, 0, 0, /*
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1973 Returns stats about the mc-alloc memory usage. See diagnose.el.
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1974 */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1975 ())
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1976 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1977 Lisp_Object free_plhs = Qnil;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1978 Lisp_Object used_plhs = Qnil;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1979 Lisp_Object heap_sects = Qnil;
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1980 EMACS_INT used_size = 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1981 EMACS_INT real_size = 0;
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1982
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
1983 EMACS_INT i;
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1984
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1985 for (i = 0; i < N_FREE_PAGE_LISTS; i++)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1986 if (PLH_PAGE_COUNT (FREE_HEAP_PAGES(i)) > 0)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1987 free_plhs =
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5471
diff changeset
1988 Facons (make_fixnum (PLH_SIZE (FREE_HEAP_PAGES(i))),
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5471
diff changeset
1989 list1 (make_fixnum (PLH_PAGE_COUNT (FREE_HEAP_PAGES(i)))),
5354
22c4e67a2e69 Remove #'acons from cl.el, make the version in alloc.c visible to Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5334
diff changeset
1990 free_plhs);
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1991
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1992 for (i = 0; i < N_USED_PAGE_LISTS; i++)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1993 if (PLH_PAGE_COUNT (USED_HEAP_PAGES(i)) > 0)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
1994 used_plhs =
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5471
diff changeset
1995 Facons (make_fixnum (PLH_SIZE (USED_HEAP_PAGES(i))),
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5471
diff changeset
1996 list5 (make_fixnum (PLH_PAGE_COUNT (USED_HEAP_PAGES(i))),
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5471
diff changeset
1997 make_fixnum (PLH_USED_CELLS (USED_HEAP_PAGES(i))),
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5471
diff changeset
1998 make_fixnum (PLH_USED_SPACE (USED_HEAP_PAGES(i))),
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5471
diff changeset
1999 make_fixnum (PLH_TOTAL_CELLS (USED_HEAP_PAGES(i))),
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5471
diff changeset
2000 make_fixnum (PLH_TOTAL_SPACE (USED_HEAP_PAGES(i)))),
5354
22c4e67a2e69 Remove #'acons from cl.el, make the version in alloc.c visible to Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5334
diff changeset
2001 used_plhs);
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
2002
5216
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
2003 used_plhs =
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5471
diff changeset
2004 Facons (make_fixnum (0),
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5471
diff changeset
2005 list5 (make_fixnum (PLH_PAGE_COUNT(ARRAY_HEAP_PAGES)),
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5471
diff changeset
2006 make_fixnum (PLH_USED_CELLS (ARRAY_HEAP_PAGES)),
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5471
diff changeset
2007 make_fixnum (PLH_USED_SPACE (ARRAY_HEAP_PAGES)),
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5471
diff changeset
2008 make_fixnum (PLH_TOTAL_CELLS (ARRAY_HEAP_PAGES)),
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5471
diff changeset
2009 make_fixnum (PLH_TOTAL_SPACE (ARRAY_HEAP_PAGES))),
5354
22c4e67a2e69 Remove #'acons from cl.el, make the version in alloc.c visible to Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5334
diff changeset
2010 used_plhs);
5216
9b8c2168d231 Allocate lrecord arrays in own size class.
Marcus Crestani <crestani@informatik.uni-tuebingen.de>
parents: 5167
diff changeset
2011
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
2012 for (i = 0; i < N_HEAP_SECTIONS; i++) {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
2013 used_size += HEAP_SECTION(i).n_pages * PAGE_SIZE;
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
2014 real_size +=
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
2015 malloced_storage_size (0, HEAP_SECTION(i).real_size, 0);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
2016 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
2017
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
2018 heap_sects =
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5471
diff changeset
2019 list3 (make_fixnum (N_HEAP_SECTIONS),
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5471
diff changeset
2020 make_fixnum (used_size),
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5471
diff changeset
2021 make_fixnum (real_size));
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
2022
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5471
diff changeset
2023 return Fcons (make_fixnum (PAGE_SIZE),
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2024 list5 (heap_sects,
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
2025 Fnreverse (used_plhs),
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
2026 Fnreverse (free_plhs),
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5471
diff changeset
2027 make_fixnum (sizeof (mc_allocator_globals)),
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5471
diff changeset
2028 make_fixnum (MC_MALLOCED_BYTES)));
2720
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
2029 }
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
2030 #endif /* MEMORY_USAGE_STATS */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
2031
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
2032 void
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
2033 syms_of_mc_alloc (void)
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
2034 {
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
2035 #ifdef MEMORY_USAGE_STATS
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
2036 DEFSUBR (Fmc_alloc_memory_usage);
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
2037 #endif /* MEMORY_USAGE_STATS */
6fa9919a9a0b [xemacs-hg @ 2005-04-08 23:10:01 by crestani]
crestani
parents:
diff changeset
2038 }
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2039
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2040
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2041 /*--- incremental garbage collector ----------------------------------*/
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2042
5054
24372c7e0e8f fix build problem with pdump
Ben Wing <ben@xemacs.org>
parents: 5052
diff changeset
2043 #if 0 /* currently unused */
24372c7e0e8f fix build problem with pdump
Ben Wing <ben@xemacs.org>
parents: 5052
diff changeset
2044
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2045 /* access dirty bit of page header */
5042
f395ee7ad844 Fix some compile warnings, make vdb test code conditional on DEBUG_XEMACS
Ben Wing <ben@xemacs.org>
parents: 4125
diff changeset
2046 static void
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2047 set_dirty_bit (page_header *ph, unsigned int value)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2048 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2049 PH_DIRTY_BIT (ph) = value;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2050 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2051
5042
f395ee7ad844 Fix some compile warnings, make vdb test code conditional on DEBUG_XEMACS
Ben Wing <ben@xemacs.org>
parents: 4125
diff changeset
2052 static void
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2053 set_dirty_bit_for_address (void *ptr, unsigned int value)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2054 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2055 set_dirty_bit (get_page_header (ptr), value);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2056 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2057
5042
f395ee7ad844 Fix some compile warnings, make vdb test code conditional on DEBUG_XEMACS
Ben Wing <ben@xemacs.org>
parents: 4125
diff changeset
2058 static unsigned int
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2059 get_dirty_bit (page_header *ph)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2060 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2061 return PH_DIRTY_BIT (ph);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2062 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2063
5042
f395ee7ad844 Fix some compile warnings, make vdb test code conditional on DEBUG_XEMACS
Ben Wing <ben@xemacs.org>
parents: 4125
diff changeset
2064 static unsigned int
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2065 get_dirty_bit_for_address (void *ptr)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2066 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2067 return get_dirty_bit (get_page_header (ptr));
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2068 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2069
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2070
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2071 /* access protection bit of page header */
5042
f395ee7ad844 Fix some compile warnings, make vdb test code conditional on DEBUG_XEMACS
Ben Wing <ben@xemacs.org>
parents: 4125
diff changeset
2072 static void
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2073 set_protection_bit (page_header *ph, unsigned int value)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2074 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2075 PH_PROTECTION_BIT (ph) = value;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2076 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2077
5042
f395ee7ad844 Fix some compile warnings, make vdb test code conditional on DEBUG_XEMACS
Ben Wing <ben@xemacs.org>
parents: 4125
diff changeset
2078 static void
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2079 set_protection_bit_for_address (void *ptr, unsigned int value)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2080 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2081 set_protection_bit (get_page_header (ptr), value);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2082 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2083
5042
f395ee7ad844 Fix some compile warnings, make vdb test code conditional on DEBUG_XEMACS
Ben Wing <ben@xemacs.org>
parents: 4125
diff changeset
2084 static unsigned int
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2085 get_protection_bit (page_header *ph)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2086 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2087 return PH_PROTECTION_BIT (ph);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2088 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2089
5042
f395ee7ad844 Fix some compile warnings, make vdb test code conditional on DEBUG_XEMACS
Ben Wing <ben@xemacs.org>
parents: 4125
diff changeset
2090 static unsigned int
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2091 get_protection_bit_for_address (void *ptr)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2092 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2093 return get_protection_bit (get_page_header (ptr));
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2094 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2095
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2096
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2097 /* Returns the start of the page of the object pointed to by ptr. */
5042
f395ee7ad844 Fix some compile warnings, make vdb test code conditional on DEBUG_XEMACS
Ben Wing <ben@xemacs.org>
parents: 4125
diff changeset
2098 static void *
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2099 get_page_start (void *ptr)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2100 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2101 return PH_HEAP_SPACE (get_page_header (ptr));
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2102 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2103
5054
24372c7e0e8f fix build problem with pdump
Ben Wing <ben@xemacs.org>
parents: 5052
diff changeset
2104 #endif /* 0 */
24372c7e0e8f fix build problem with pdump
Ben Wing <ben@xemacs.org>
parents: 5052
diff changeset
2105
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2106 /* Make PAGE_SIZE globally available. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2107 EMACS_INT
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2108 mc_get_page_size ()
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2109 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2110 return PAGE_SIZE;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2111 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2112
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2113 /* Is the fault at ptr on a protected page? */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2114 EMACS_INT
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2115 fault_on_protected_page (void *ptr)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2116 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2117 page_header *ph = get_page_header_internal (ptr);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2118 return (ph
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2119 && PH_HEAP_SPACE (ph)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2120 && (PH_HEAP_SPACE (ph) <= ptr)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2121 && ((void *) ((EMACS_INT) PH_HEAP_SPACE (ph)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2122 + PH_N_PAGES (ph) * PAGE_SIZE) > ptr)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2123 && (PH_PROTECTION_BIT (ph) == 1));
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2124 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2125
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2126
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2127 /* Protect the heap page of given page header ph if black objects are
3303
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
2128 on the page. Returns number of processed pages. */
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
2129 static EMACS_INT
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2130 protect_heap_page (page_header *ph)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2131 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2132 if (PH_BLACK_BIT (ph))
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2133 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2134 void *heap_space = PH_HEAP_SPACE (ph);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2135 EMACS_INT heap_space_size = PH_N_PAGES (ph) * PAGE_SIZE;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2136 vdb_protect ((void *) heap_space, heap_space_size);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2137 PH_PROTECTION_BIT (ph) = 1;
3303
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
2138 return 1;
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2139 }
3303
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
2140 return 0;
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2141 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2142
3303
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
2143 /* Protect all heap pages with black objects. Returns number of
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
2144 processed pages.*/
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
2145 EMACS_INT
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2146 protect_heap_pages (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2147 {
3303
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
2148 return visit_all_used_page_headers (protect_heap_page);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2149 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2150
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2151
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2152 /* Remove protection (if there) of heap page of given page header
3303
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
2153 ph. Returns number of processed pages. */
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
2154 static EMACS_INT
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2155 unprotect_heap_page (page_header *ph)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2156 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2157 if (PH_PROTECTION_BIT (ph))
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2158 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2159 void *heap_space = PH_HEAP_SPACE (ph);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2160 EMACS_INT heap_space_size = PH_N_PAGES (ph) * PAGE_SIZE;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2161 vdb_unprotect (heap_space, heap_space_size);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2162 PH_PROTECTION_BIT (ph) = 0;
3303
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
2163 return 1;
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2164 }
3303
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
2165 return 0;
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2166 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2167
3303
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
2168 /* Remove protection for all heap pages which are protected. Returns
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
2169 number of processed pages. */
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
2170 EMACS_INT
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2171 unprotect_heap_pages (void)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2172 {
3303
619edf713d55 [xemacs-hg @ 2006-03-26 14:05:29 by crestani]
crestani
parents: 3263
diff changeset
2173 return visit_all_used_page_headers (unprotect_heap_page);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2174 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2175
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2176 /* Remove protection and mark page dirty. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2177 void
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2178 unprotect_page_and_mark_dirty (void *ptr)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2179 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2180 page_header *ph = get_page_header (ptr);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2181 unprotect_heap_page (ph);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2182 PH_DIRTY_BIT (ph) = 1;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2183 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2184
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2185 /* Repush all objects on dirty pages onto the mark stack. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2186 int
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2187 repush_all_objects_on_page (void *ptr)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2188 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2189 int repushed_objects = 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2190 page_header *ph = get_page_header (ptr);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2191 Rawbyte *heap_space = (Rawbyte *) PH_HEAP_SPACE (ph);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2192 EMACS_INT heap_space_step = PH_CELL_SIZE (ph);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2193 EMACS_INT mark_bit = 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2194 EMACS_INT mark_bit_max_index = PH_CELLS_ON_PAGE (ph);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2195 unsigned int bit = 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2196 for (mark_bit = 0; mark_bit < mark_bit_max_index; mark_bit++)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2197 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2198 GET_BIT (bit, ph, mark_bit * N_MARK_BITS);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2199 if (bit == BLACK)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2200 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2201 repushed_objects++;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2202 gc_write_barrier
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2203 (wrap_pointer_1 ((heap_space + (heap_space_step * mark_bit))));
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2204 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2205 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2206 PH_BLACK_BIT (ph) = 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2207 PH_DIRTY_BIT (ph) = 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2208 return repushed_objects;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2209 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2210
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2211 /* Mark black if object is currently grey. This first checks, if the
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2212 object is really allocated on the mc-heap. If it is, it can be
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2213 marked black; if it is not, it cannot be marked. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2214 EMACS_INT
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2215 maybe_mark_black (void *ptr)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2216 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2217 page_header *ph = get_page_header_internal (ptr);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2218 unsigned int bit = 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2219
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2220 if (ph && PH_PLH (ph) && PH_ON_USED_LIST_P (ph))
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2221 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2222 GET_BIT (bit, ph, get_mark_bit_index (ptr, ph));
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2223 if (bit == GREY)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2224 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2225 if (!PH_BLACK_BIT (ph))
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2226 PH_BLACK_BIT (ph) = 1;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2227 SET_BIT (ph, get_mark_bit_index (ptr, ph), BLACK);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2228 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2229 return 1;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2230 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2231 return 0;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2232 }
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2233
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2234 /* Only for debugging --- not used anywhere in the sources. */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2235 EMACS_INT
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2236 object_on_heap_p (void *ptr)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2237 {
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2238 page_header *ph = get_page_header_internal (ptr);
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2239 return (ph && PH_ON_USED_LIST_P (ph));
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 2994
diff changeset
2240 }