Sanitize sgen's collection trigger internal API.
[mono.git] / mono / metadata / sgen-scan-object.h
1 /*
2  * Copyright 2001-2003 Ximian, Inc
3  * Copyright 2003-2010 Novell, Inc.
4  * 
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  * 
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  * 
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  *
25  * Scans one object, using the OBJ_XXX macros.  The start of the
26  * object must be given in the variable "char* start".  Afterwards,
27  * "start" will point to the start of the next object, if the scanned
28  * object contained references.  If not, the value of "start" should
29  * be considered undefined after executing this code.
30  *
31  * Modifiers (automatically undefined):
32  *
33  * SCAN_OBJECT_NOSCAN - if defined, don't actually scan the object,
34  * i.e. don't invoke the OBJ_XXX macros.
35  *
36  * SCAN_OBJECT_ACTION - is invoked after an object has been scanned.
37  * The object's start is "start", its length in bytes (including
38  * padding at the end) is "skip_size".  "desc" is the object's GC
39  * descriptor.  The action can use the macro
40  * "SCAN" to scan the object.
41  *
42  * SCAN_OBJECT_NOVTABLE - desc is provided by the includer, instead of
43  * vt.  Complex arrays cannot not be scanned.
44  */
45
46 #ifndef SCAN_OBJECT_ACTION
47 #define SCAN_OBJECT_ACTION
48 #endif
49
50 {
51 #ifndef SCAN_OBJECT_NOVTABLE
52         GCVTable *vt;
53         mword desc;
54
55         vt = (GCVTable*)SGEN_LOAD_VTABLE (start);
56         //type = vt->desc & 0x7;
57
58         /* gcc should be smart enough to remove the bounds check, but it isn't:( */
59         desc = vt->desc;
60 #endif
61         switch (desc & 0x7) {
62         case DESC_TYPE_RUN_LENGTH:
63 #define SCAN OBJ_RUN_LEN_FOREACH_PTR (desc, start)
64 #ifndef SCAN_OBJECT_NOSCAN
65                 SCAN;
66 #endif
67                 SCAN_OBJECT_ACTION;
68 #undef SCAN
69                 break;
70         case DESC_TYPE_SMALL_BITMAP:
71 #define SCAN OBJ_BITMAP_FOREACH_PTR (desc, start)
72 #ifndef SCAN_OBJECT_NOSCAN
73                 SCAN;
74 #endif
75                 SCAN_OBJECT_ACTION;
76 #undef SCAN
77                 break;
78         case DESC_TYPE_VECTOR:
79 #define SCAN OBJ_VECTOR_FOREACH_PTR (desc, start)
80 #ifndef SCAN_OBJECT_NOSCAN
81                 SCAN;
82 #endif
83                 SCAN_OBJECT_ACTION;
84 #undef SCAN
85                 break;
86         case DESC_TYPE_LARGE_BITMAP:
87 #define SCAN OBJ_LARGE_BITMAP_FOREACH_PTR (desc, start)
88 #ifndef SCAN_OBJECT_NOSCAN
89                 SCAN;
90 #endif
91                 SCAN_OBJECT_ACTION;
92 #undef SCAN
93                 break;
94         case DESC_TYPE_COMPLEX:
95                 /* this is a complex object */
96 #define SCAN OBJ_COMPLEX_FOREACH_PTR (desc, start)
97 #ifndef SCAN_OBJECT_NOSCAN
98                 SCAN;
99 #endif
100                 SCAN_OBJECT_ACTION;
101 #undef SCAN
102                 break;
103 #ifndef SCAN_OBJECT_NOVTABLE
104         case DESC_TYPE_COMPLEX_ARR:
105                 /* this is an array of complex structs */
106 #define SCAN OBJ_COMPLEX_ARR_FOREACH_PTR (vt, start)
107 #ifndef SCAN_OBJECT_NOSCAN
108                 SCAN;
109 #endif
110                 SCAN_OBJECT_ACTION;
111 #undef SCAN
112                 break;
113 #endif
114         case DESC_TYPE_COMPLEX_PTRFREE:
115                 /*Nothing to do*/
116                 SCAN_OBJECT_ACTION;
117                 break;
118         default:
119                 g_assert_not_reached ();
120         }
121 }
122
123 #undef SCAN_OBJECT_NOSCAN
124 #undef SCAN_OBJECT_ACTION
125 #undef SCAN_OBJECT_NOVTABLE