File: smemory.h

package info (click to toggle)
rscheme 0.7.2-1.1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 10,672 kB
  • ctags: 12,430
  • sloc: lisp: 37,104; ansic: 29,763; cpp: 2,630; sh: 1,677; makefile: 568; yacc: 202; lex: 175; perl: 33
file content (226 lines) | stat: -rw-r--r-- 7,397 bytes parent folder | download | duplicates (4)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/*-----------------------------------------------------------------*-C-*---
 * File:    handc/runtime/smemory.h
 *
 *          Copyright (C)1997 Donovan Kolbly <d.kolbly@rscheme.org>
 *          as part of the RScheme project, licensed for free use.
 *          See <http://www.rscheme.org/> for the latest information.
 *
 * File version:     1.15
 * File mod date:    1997.11.29 23:10:49
 * System build:     v0.7.2, 97.12.21
 *
 * Purpose:          scheme heap interface
 *------------------------------------------------------------------------*/

#ifndef _H_RSCHEME_SMEMORY
#define _H_RSCHEME_SMEMORY

#include <rscheme/obj.h>
#include <rscheme/gcserver.h>

typedef struct _POBHeader {
    UINT_32	pob_size;
    obj		pob_class;
} POBHeader;

#define SLOT(i) ((i)*sizeof(obj))

/*  Low-level storage allocators.  Return uninitialized bits.  */

CIH_DECL obj alloc( UINT_32 bytes, obj obj_class );
CIH_DECL obj alloc1( obj obj_class );
CIH_DECL obj alloc2( obj obj_class );
CIH_DECL obj alloc3( obj obj_class );
CIH_DECL obj alloc4( obj obj_class );
CIH_DECL obj alloc5( obj obj_class );
CIH_DECL obj alloc6( obj obj_class );
CIH_DECL obj alloc7( obj obj_class );
CIH_DECL obj alloc8( obj obj_class );
CIH_DECL obj alloc9( obj obj_class );

/*  Allocate a gvec filled with FALSE_OBJ's  */

CIH_DECL obj gvec_alloc( UINT_32 num_slots, obj obj_class );
obj make_gvec( obj the_class, UINT_32 size, obj fill );

/*  Allocate a bvec, with last word set to zeros */

CIH_DECL obj bvec_alloc( UINT_32 num_bytes, obj bvec_class );


#define OBJ_ISA_PTR_OF_CLASS(x,c) ((OBJ_ISA_PTR(x) \
				    && EQ(CLASSOF_PTR(x),c)) \
				  ? YES : NO)
#define PTR_IN_CATEGORY_P(x,c) ((OBJ_ISA_PTR(x) \
				 && in_category_p(CLASSOF_PTR(x),c)) \
				  ? YES : NO)

#ifdef DEBUG_SMEMORY
CIH_DECL UINT_32 SIZEOF_PTR( obj ptr );
CIH_DECL obj CLASSOF_PTR( obj ptr );

CIH_DECL void *PTR_TO_DATAPTR( obj ptr );

CIH_DECL POBHeader *PTR_TO_HDRPTR( obj ptr );

CIH_DECL gc_obj_addr PTR_TO_GCPTR( obj x );
CIH_DECL obj GCPTR_TO_PTR( gc_obj_addr x );
CIH_DECL obj HDRPTR_TO_PTR( POBHeader *hdr );

#else

#define PTR_TO_HDRPTR(ptr)     ((POBHeader *)(VAL(ptr) - POINTER_TAG \
					      - sizeof(POBHeader)))
#define PTR_TO_GCPTR(ptr)     ((gc_obj_addr)PTR_TO_HDRPTR(ptr))
#define GCPTR_TO_PTR(gcp)      OBJ(((UINT_32)(gcp)) \
				   + sizeof(POBHeader) \
				   + POINTER_TAG )
#define HDRPTR_TO_PTR(p) GCPTR_TO_PTR(p)

#define SIZEOF_PTR(ptr) (PTR_TO_HDRPTR(ptr)->pob_size)
#define CLASSOF_PTR(ptr) (PTR_TO_HDRPTR(ptr)->pob_class)
#define PTR_TO_DATAPTR(ptr) ((void *)(VAL(ptr) - POINTER_TAG))

#endif

CIH_DECL void safe_point( UINT_32 headroom );


/******************** Memory Read Functions ********************/

#define bvec_read(b,o) bvec_read_uint8(b,o)

CIH_DECL UINT_8  bvec_read_uint8(  obj bvec, UINT_32 byte_offset );
          INT_8  bvec_read_int8(   obj bvec, UINT_32 byte_offset );
         UINT_16 bvec_read_uint16( obj bvec, UINT_32 byte_offset );
          INT_16 bvec_read_int16(  obj bvec, UINT_32 byte_offset );
          INT_32 bvec_read_int32(  obj bvec, UINT_32 byte_offset );
          INT_64 bvec_read_int64(  obj bvec, UINT_32 byte_offset );
         IEEE_32 bvec_read_ieee32( obj bvec, UINT_32 byte_offset );
         IEEE_64 bvec_read_ieee64( obj bvec, UINT_32 byte_offset );

#if INCLUDE_READ_BARRIER
CIH_DECL obj read_barrier( obj item );
#define READ_BARRIER(x)   read_barrier(x)
#else
#define READ_BARRIER(x)   (x)
#endif

#ifdef DEBUG_SMEMORY
CIH_DECL obj gvec_read( obj gvec, UINT_32 byte_offset );
#else
#define gvec_read(gvec,byte_offset) READ_BARRIER(*(obj *)(((char *)PTR_TO_DATAPTR(gvec))\
					     + (byte_offset)))

#endif

/******************** Memory Write Functions ********************/

void bvec_write_uint8(  obj bvec, UINT_32 byte_offset, UINT_8 v );
void bvec_write_int8(   obj bvec, UINT_32 byte_offset, INT_8 v );
void bvec_write_uint16( obj bvec, UINT_32 byte_offset, UINT_16 v );
void bvec_write_int16(  obj bvec, UINT_32 byte_offset, INT_16 v );

void bvec_write_int32(  obj bvec, UINT_32 byte_offset, INT_32 v );
void bvec_write_int64(  obj bvec, UINT_32 byte_offset, INT_64 v );
void bvec_write_ieee32(  obj bvec, UINT_32 byte_offset, IEEE_32 v );
void bvec_write_ieee64(  obj bvec, UINT_32 byte_offset, IEEE_64 v );

CIH_DECL void gvec_write( obj gvec, UINT_32 byte_offset, obj value );
CIH_DECL void gvec_write_ptr( obj gvec, UINT_32 byte_offset, obj value );
CIH_DECL void gvec_write_non_ptr( obj gvec, UINT_32 byte_offset, obj value );

/* an object is FRESH from the time it is allocated to
   the next GC_SAFE_POINT.  This is extraordinarily useful
   if you are allocating white, in which case the write
   barrier becomes a NOP
*/

CIH_DECL void gvec_write_fresh( obj gvec, UINT_32 byte_offset, obj value );
CIH_DECL void gvec_write_fresh_ptr( obj gvec, UINT_32 byte_offset, obj value );
CIH_DECL void gvec_write_fresh_non_ptr( obj gvec, UINT_32 byte_offset, obj value );

CIH_DECL void gvec_write_init( obj gvec, UINT_32 byte_offset, obj value );
CIH_DECL void gvec_write_init_ptr( obj gvec, UINT_32 byte_offset, obj value );
CIH_DECL void gvec_write_init_non_ptr( obj gvec, UINT_32 byte_offset, obj value );

/* lower-level allocation */

CIH_DECL void *malloc_aligned_32( UINT_32 bytes );
CIH_DECL void free_aligned_32( void *ptr );

/************************ weak pointers and finalization *******************/

void mark_as_finalizable( obj thing );
void found_weak_slot( obj in_thing, obj *slot ); 
rs_bool gc_cycle_finish_ok( void );
int rs_relocate_objects( obj tbl );

/********************** new names ***********************/

#define gvec_ref(g,i) gvec_read(g,i)
#define gvec_set(g,i,v) gvec_write(g,i,v)

#define make_bvec(class,size) bvec_alloc(size,class)

/********************** allocation areas ***********************/

struct _AllocArea;

typedef obj allocator_fn( struct _AllocArea *area, 
			  obj obj_class,
			  UINT_32 bytes );

typedef struct _AllocArea {
  obj                 entry;      /* each AllocArea get's its own entry */
  obj                 reserved;   /* a reserved object, for now */
  allocator_fn       *allocfn;    /* allocation implementation */
  void               *info;       /* guaranteed NULL for default impl */
} AllocArea;

/* 
 *   default allocation implementation  
 */
obj default_alloc_obj( AllocArea *area, obj obj_class, UINT_32 bytes );

/*
 *   wrapper functions
 */

#define AS_ALLOCAREA(p) ((AllocArea *)PTR_TO_DATAPTR(p))
#define ALLOCAREA_P(x) (OBJ_ISA_PTR(x) \
			&& EQ(CLASSOF_PTR(x),allocation_area_class))

obj alloc_in_area( AllocArea *in_area, obj the_class, UINT_32 size );
obj make_gvec_in_area( obj in_area, obj the_class, UINT_32 size, obj fill );
obj make_bvec_in_area( obj in_area, obj the_class, UINT_32 size, UINT_8 fill );

#ifdef INLINES

#if !(defined(_CI_GCCLIENT1) || defined(_CI_GCCLIENT2))
#ifndef FOREIGN

#ifdef gcserver_h  /* we're running RTGC */
#include <rtgc/gcserver1.ci>
#include <rtgc/objmgr.ci>
#include <rtgc/colorset1.ci>
#include <rtgc/gcserver2.ci>
#else
#include <rscheme/gcserver1.ci>
#include <rscheme/gcserver2.ci>
#endif
#endif
#endif

#include <rscheme/smemory.ci>
#include <rscheme/readwrit.ci>
#endif

/* recognize bvecs & gvecs */

#define GVEC_P(x) (OBJ_ISA_PTR(x) && \
		   EQ(gvec_read(CLASSOF_PTR(x),SLOT(1)),int2fx(0)))
#define BVEC_P(x) (OBJ_ISA_PTR(x) && \
		   EQ(gvec_read(CLASSOF_PTR(x),SLOT(1)),int2fx(1)))

#endif /* _H_SMEMORY */