source: trunk/src/gcc/boehm-gc/stubborn.c@ 1216

Last change on this file since 1216 was 2, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 8.8 KB
Line 
1/*
2 * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
3 * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
4 *
5 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
6 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
7 *
8 * Permission is hereby granted to use or copy this program
9 * for any purpose, provided the above notices are retained on all copies.
10 * Permission to modify the code and to distribute modified code is granted,
11 * provided the above notices are retained, and a notice that the code was
12 * modified is included with the above copyright notice.
13 */
14/* Boehm, July 31, 1995 5:02 pm PDT */
15
16
17#include "private/gc_priv.h"
18
19# ifdef STUBBORN_ALLOC
20/* Stubborn object (hard to change, nearly immutable) allocation. */
21
22extern ptr_t GC_clear_stack(); /* in misc.c, behaves like identity */
23
24#define GENERAL_MALLOC(lb,k) \
25 (GC_PTR)GC_clear_stack(GC_generic_malloc((word)lb, k))
26
27/* Data structure representing immutable objects that */
28/* are still being initialized. */
29/* This is a bit baroque in order to avoid acquiring */
30/* the lock twice for a typical allocation. */
31
32GC_PTR * GC_changing_list_start;
33
34void GC_push_stubborn_structures GC_PROTO((void))
35{
36 GC_push_all((ptr_t)(&GC_changing_list_start),
37 (ptr_t)(&GC_changing_list_start) + sizeof(GC_PTR *));
38}
39
40# ifdef THREADS
41 VOLATILE GC_PTR * VOLATILE GC_changing_list_current;
42# else
43 GC_PTR * GC_changing_list_current;
44# endif
45 /* Points at last added element. Also (ab)used for */
46 /* synchronization. Updates and reads are assumed atomic. */
47
48GC_PTR * GC_changing_list_limit;
49 /* Points at the last word of the buffer, which is always 0 */
50 /* All entries in (GC_changing_list_current, */
51 /* GC_changing_list_limit] are 0 */
52
53
54void GC_stubborn_init()
55{
56# define INIT_SIZE 10
57
58 GC_changing_list_start = (GC_PTR *)
59 GC_INTERNAL_MALLOC(
60 (word)(INIT_SIZE * sizeof(GC_PTR)),
61 PTRFREE);
62 BZERO(GC_changing_list_start,
63 INIT_SIZE * sizeof(GC_PTR));
64 if (GC_changing_list_start == 0) {
65 GC_err_printf0("Insufficient space to start up\n");
66 ABORT("GC_stubborn_init: put of space");
67 }
68 GC_changing_list_current = GC_changing_list_start;
69 GC_changing_list_limit = GC_changing_list_start + INIT_SIZE - 1;
70 * GC_changing_list_limit = 0;
71}
72
73/* Compact and possibly grow GC_uninit_list. The old copy is */
74/* left alone. Lock must be held. */
75/* When called GC_changing_list_current == GC_changing_list_limit */
76/* which is one past the current element. */
77/* When we finish GC_changing_list_current again points one past last */
78/* element. */
79/* Invariant while this is running: GC_changing_list_current */
80/* points at a word containing 0. */
81/* Returns FALSE on failure. */
82GC_bool GC_compact_changing_list()
83{
84 register GC_PTR *p, *q;
85 register word count = 0;
86 word old_size = (char **)GC_changing_list_limit
87 - (char **)GC_changing_list_start+1;
88 /* The casts are needed as a workaround for an Amiga bug */
89 register word new_size = old_size;
90 GC_PTR * new_list;
91
92 for (p = GC_changing_list_start; p < GC_changing_list_limit; p++) {
93 if (*p != 0) count++;
94 }
95 if (2 * count > old_size) new_size = 2 * count;
96 new_list = (GC_PTR *)
97 GC_INTERNAL_MALLOC(
98 new_size * sizeof(GC_PTR), PTRFREE);
99 /* PTRFREE is a lie. But we don't want the collector to */
100 /* consider these. We do want the list itself to be */
101 /* collectable. */
102 if (new_list == 0) return(FALSE);
103 BZERO(new_list, new_size * sizeof(GC_PTR));
104 q = new_list;
105 for (p = GC_changing_list_start; p < GC_changing_list_limit; p++) {
106 if (*p != 0) *q++ = *p;
107 }
108 GC_changing_list_start = new_list;
109 GC_changing_list_limit = new_list + new_size - 1;
110 GC_changing_list_current = q;
111 return(TRUE);
112}
113
114/* Add p to changing list. Clear p on failure. */
115# define ADD_CHANGING(p) \
116 { \
117 register struct hblk * h = HBLKPTR(p); \