1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
/*
* Copyright (c) 1999 by Silicon Graphics. All rights reserved.
*
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
*
* Permission is hereby granted to use or copy this program
* for any purpose, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*/
/*
* THIS IMPLEMENTATION FOR THIS INTERFACE IS INCOMPLETE.
* NONE OF THIS HAS BEEN TESTED. DO NOT USE.
*
* Comments on the interface are appreciated, especially from
* potential users of the interface.
*
* This is a Bartlett style copying collector for young objects.
* We assume for now that all objects allocated through this
* mechanism have pointers only in the first BITMAP_BITS words.
* (On a 32-bit machine, BITMAP_BITS is 30.)
* Objects allocated in this manner should be rarely referenced
* by objects not allocated either through this interface, or through
* the typed allocation interface.
* If this interface is used, we assume that type information provided
* through either this or the typed allocation interface is valid
* in a stronger sense:
*
* 1) No pointers are stored in fields not marked as such.
* (Otherwise it is only necessary that objects referenced by
* fields marked as nonpointers are also reachable via another
* path.)
* 2) Values stored in pointer fields are either not addresses in
* the heap, or they really are pointers. In the latter case, it
* is acceptable to move the object they refer to, and to update
* the pointer.
*
* GC_free may not be invoked on objects allocated with GC_copying_malloc.
*
* No extra space is added to the end of objects allocated through this
* interface. If the client needs to maintain pointers past the
* end, the size should be explicitly padded.
*
* We assume that calls to this will usually be compiler generated.
* Hence the interface is allowed to be a bit ugly in return for speed.
*/
#include "gc_copy_descr.h"
/* GC_copy_descr.h must define */
/* GC_SIZE_FROM_DESCRIPTOR(descr) and */
/* GC_BIT_MAP_FROM_DESCRIPTOR(descr). */
/* It may either be the GC supplied version of the header file, or a */
/* client specific one that derives the information from a client- */
/* specific type descriptor. */
typedef GC_PTR GC_copy_alloc_state;
/* Current allocator state. */
/* Multiple allocation states */
/* may be used for concurrent */
/* allocation, or to enhance */
/* locality. */
/* Should be treated as opaque. */
/* Allocate a memory block of size given in the descriptor, and with */
/* pointer layout given by the descriptor. The resulting block may not */
/* be cleared, and should immediately be initialized by the client. */
/* (A concurrent GC may see an uninitialized pointer field. If it */
/* points outside the nursery, that's fine. If it points inside, it */
/* may retain an object, and be relocated. But that's also fine, since */
/* the new value will be immediately overwritten. */
/* This variant acquires the allocation lock, and uses a default */
/* global allocation state. */
GC_PTR GC_copying_malloc(GC_copy_descriptor);
/* A variant of the above that does no locking on the fast path, */
/* and passes an explicit pointer to an allocation state. */
/* The allocation state is updated. */
/* There will eventually need to be a macro or inline function version */
/* of this. */
GC_PTR GC_copying_malloc2(GC_copy_descriptor, GC_copy_alloc_state *);
/* Initialize an allocation state so that it can be used for */
/* allocation. This implicitly reserves a small section of the */
/* nursery for use with this allocator. */
void GC_init_copy_alloc_state(GC_copy_alloc_state *);
|