1 /* Copyright (C) 1996, 1999, 2001 Aladdin Enterprises. All rights reserved. 2 3 This software is provided AS-IS with no warranty, either express or 4 implied. 5 6 This software is distributed under license and may not be copied, 7 modified or distributed except as expressly authorized under the terms 8 of the license contained in the file LICENSE in this distribution. 9 10 For more information about licensing, please refer to 11 http://www.ghostscript.com/licensing/. For information on 12 commercial licensing, go to http://www.artifex.com/licensing/ or 13 contact Artifex Software, Inc., 101 Lucas Valley Road #110, 14 San Rafael, CA 94903, U.S.A., +1(415)492-9861. 15 */ 16 17 /* $Id: gsgc.h,v 1.6 2002/06/16 08:45:42 lpd Exp $ */ 18 /* Library-level interface to garbage collector */ 19 20 /* 21 * This API is not strictly at the library level, since it references 22 * gs_ref_memory_t and the 4 PostScript memory spaces; however, the former 23 * concept already leaks into the library's standard allocator, and the 24 * latter is relatively small and harmless. 25 */ 26 27 #ifndef gsgc_INCLUDED 28 # define gsgc_INCLUDED 29 30 /* 31 * Define the VM space numbers, in increasing order of dynamism. Pointers 32 * from a higher-numbered space to the same or a lower-numbered space are 33 * always allowed, but not vice versa. Foreign space (the most static) is 34 * internal, the rest are visible to the programmer; the index of foreign 35 * space must be 0, so that we don't have to set any space bits in scalar 36 * refs (PostScript objects). 37 */ 38 typedef enum { 39 i_vm_foreign = 0, /* must be 0 */ 40 i_vm_system, 41 i_vm_global, 42 i_vm_local, 43 i_vm_max = i_vm_local 44 } i_vm_space; 45 46 /* 47 * Define an array of allocators indexed by space. Note that the first 48 * ("foreign") element of this array is always 0: foreign pointers, by 49 * definition, point to objects that are not managed by a Ghostscript 50 * allocator (typically, static const objects, or objects allocated with 51 * malloc by some piece of code other than Ghostscript). 52 */ 53 #ifndef gs_ref_memory_DEFINED 54 # define gs_ref_memory_DEFINED 55 typedef struct gs_ref_memory_s gs_ref_memory_t; 56 #endif 57 /* 58 * r_space_bits is only defined in PostScript interpreters, but if it is 59 * defined, we want to make sure it's 2. 60 */ 61 #ifdef r_space_bits 62 # if r_space_bits != 2 63 Error_r_space_bits_is_not_2; 64 # endif 65 #endif 66 typedef struct vm_spaces_s vm_spaces; 67 /* 68 * The garbage collection procedure is named vm_reclaim so as not to 69 * collide with the reclaim member of gs_dual_memory_t. 70 */ 71 #define vm_reclaim_proc(proc)\ 72 void proc(vm_spaces *pspaces, bool global) 73 struct vm_spaces_s { 74 vm_reclaim_proc((*vm_reclaim)); 75 union { 76 gs_ref_memory_t *indexed[4 /*1 << r_space_bits */ ]; 77 struct _ssn { 78 gs_ref_memory_t *foreign; 79 gs_ref_memory_t *system; 80 gs_ref_memory_t *global; 81 gs_ref_memory_t *local; 82 } named; 83 } memories; 84 }; 85 86 /* 87 * By convention, the vm_spaces member of structures, and local variables 88 * of type vm_spaces, are named spaces. 89 */ 90 #define space_foreign spaces.memories.named.foreign 91 #define space_system spaces.memories.named.system 92 #define space_global spaces.memories.named.global 93 #define space_local spaces.memories.named.local 94 #define spaces_indexed spaces.memories.indexed 95 96 /* 97 * Define the top-level entry to the garbage collectors. 98 */ 99 #define GS_RECLAIM(pspaces, global) ((pspaces)->vm_reclaim(pspaces, global)) 100 /* Backward compatibility */ 101 #define gs_reclaim(pspaces, global) GS_RECLAIM(pspaces, global) 102 103 #endif /* gsgc_INCLUDED */ 104