[sgen] `GCObject*` instead of `char*` where appropriate.
[mono.git] / mono / sgen / sgen-scan-object.h
1 /*
2  * sgen-scan-object.h: Generic object scan.
3  *
4  * Copyright 2001-2003 Ximian, Inc
5  * Copyright 2003-2010 Novell, Inc.
6  * Copyright (C) 2013 Xamarin Inc
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License 2.0 as published by the Free Software Foundation;
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License 2.0 along with this library; if not, write to the Free
19  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  *
22  * Scans one object, using the OBJ_XXX macros.  The start of the
23  * object must be given in the variable "char* start".  Afterwards,
24  * "start" will point to the start of the next object, if the scanned
25  * object contained references.  If not, the value of "start" should
26  * be considered undefined after executing this code.  The object's
27  * GC descriptor must be in the variable "mword desc".
28  *
29  * The macro `HANDLE_PTR` will be invoked for every reference encountered while scanning the
30  * object.  It is called with two parameters: The pointer to the reference (not the
31  * reference itself!) as well as the pointer to the scanned object.
32  *
33  * Modifiers (automatically undefined):
34  *
35  * SCAN_OBJECT_NOSCAN - if defined, don't actually scan the object,
36  * i.e. don't invoke the OBJ_XXX macros.
37  *
38  * SCAN_OBJECT_NOVTABLE - desc is provided by the includer, instead of
39  * vt.  Complex arrays cannot not be scanned.
40  *
41  * SCAN_OBJECT_PROTOCOL - if defined, binary protocol the scan.
42  * Should only be used for scanning that's done for the actual
43  * collection, not for debugging scans.
44  */
45
46 {
47 #ifndef SCAN_OBJECT_NOVTABLE
48 #if defined(SGEN_HEAVY_BINARY_PROTOCOL) && defined(SCAN_OBJECT_PROTOCOL)
49         binary_protocol_scan_begin ((GCObject*)start, SGEN_LOAD_VTABLE ((GCObject*)start), sgen_safe_object_get_size ((GCObject*)start));
50 #endif
51 #else
52 #if defined(SGEN_HEAVY_BINARY_PROTOCOL) && defined(SCAN_OBJECT_PROTOCOL)
53         binary_protocol_scan_vtype_begin (start + SGEN_CLIENT_OBJECT_HEADER_SIZE, size);
54 #endif
55 #endif
56         switch (desc & DESC_TYPE_MASK) {
57         case DESC_TYPE_RUN_LENGTH:
58 #define SCAN OBJ_RUN_LEN_FOREACH_PTR (desc, ((GCObject*)start))
59 #ifndef SCAN_OBJECT_NOSCAN
60                 SCAN;
61 #endif
62 #undef SCAN
63                 break;
64         case DESC_TYPE_VECTOR:
65 #define SCAN OBJ_VECTOR_FOREACH_PTR (desc, ((GCObject*)start))
66 #ifndef SCAN_OBJECT_NOSCAN
67                 SCAN;
68 #endif
69 #undef SCAN
70                 break;
71         case DESC_TYPE_BITMAP:
72 #define SCAN OBJ_BITMAP_FOREACH_PTR (desc, ((GCObject*)start))
73 #ifndef SCAN_OBJECT_NOSCAN
74                 SCAN;
75 #endif
76 #undef SCAN
77                 break;
78         case DESC_TYPE_COMPLEX:
79                 /* this is a complex object */
80 #define SCAN OBJ_COMPLEX_FOREACH_PTR (desc, ((GCObject*)start))
81 #ifndef SCAN_OBJECT_NOSCAN
82                 SCAN;
83 #endif
84 #undef SCAN
85                 break;
86 #ifndef SCAN_OBJECT_NOVTABLE
87         case DESC_TYPE_COMPLEX_ARR:
88                 /* this is an array of complex structs */
89 #define SCAN OBJ_COMPLEX_ARR_FOREACH_PTR (desc, ((GCObject*)start))
90 #ifndef SCAN_OBJECT_NOSCAN
91                 SCAN;
92 #endif
93 #undef SCAN
94                 break;
95 #endif
96         case DESC_TYPE_SMALL_PTRFREE:
97         case DESC_TYPE_COMPLEX_PTRFREE:
98                 /*Nothing to do*/
99                 break;
100         default:
101                 g_assert_not_reached ();
102         }
103 }
104
105 #undef SCAN_OBJECT_NOSCAN
106 #undef SCAN_OBJECT_NOVTABLE
107 #undef SCAN_OBJECT_PROTOCOL