Merge pull request #1132 from mattleibow/bugfix-20925
[mono.git] / mono / metadata / 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.
27  *
28  * Modifiers (automatically undefined):
29  *
30  * SCAN_OBJECT_NOSCAN - if defined, don't actually scan the object,
31  * i.e. don't invoke the OBJ_XXX macros.
32  *
33  * SCAN_OBJECT_NOVTABLE - desc is provided by the includer, instead of
34  * vt.  Complex arrays cannot not be scanned.
35  *
36  * SCAN_OBJECT_PROTOCOL - if defined, binary protocol the scan.
37  * Should only be used for scanning that's done for the actual
38  * collection, not for debugging scans.
39  */
40
41 {
42 #ifndef SCAN_OBJECT_NOVTABLE
43         GCVTable *vt;
44         mword desc;
45
46         vt = (GCVTable*)SGEN_LOAD_VTABLE (start);
47         //type = vt->desc & 0x7;
48
49         /* gcc should be smart enough to remove the bounds check, but it isn't:( */
50         desc = vt->desc;
51
52 #if defined(SGEN_HEAVY_BINARY_PROTOCOL) && defined(SCAN_OBJECT_PROTOCOL)
53         binary_protocol_scan_begin (start, vt, sgen_safe_object_get_size ((MonoObject*)start));
54 #endif
55 #else
56 #if defined(SGEN_HEAVY_BINARY_PROTOCOL) && defined(SCAN_OBJECT_PROTOCOL)
57         binary_protocol_scan_vtype_begin (start + sizeof (MonoObject), size);
58 #endif
59 #endif
60         switch (desc & 0x7) {
61         case DESC_TYPE_RUN_LENGTH:
62 #define SCAN OBJ_RUN_LEN_FOREACH_PTR (desc, start)
63 #ifndef SCAN_OBJECT_NOSCAN
64                 SCAN;
65 #endif
66 #undef SCAN
67                 break;
68         case DESC_TYPE_SMALL_BITMAP:
69 #define SCAN OBJ_BITMAP_FOREACH_PTR (desc, start)
70 #ifndef SCAN_OBJECT_NOSCAN
71                 SCAN;
72 #endif
73 #undef SCAN
74                 break;
75         case DESC_TYPE_VECTOR:
76 #define SCAN OBJ_VECTOR_FOREACH_PTR (desc, start)
77 #ifndef SCAN_OBJECT_NOSCAN
78                 SCAN;
79 #endif
80 #undef SCAN
81                 break;
82         case DESC_TYPE_LARGE_BITMAP:
83 #define SCAN OBJ_LARGE_BITMAP_FOREACH_PTR (desc, start)
84 #ifndef SCAN_OBJECT_NOSCAN
85                 SCAN;
86 #endif
87 #undef SCAN
88                 break;
89         case DESC_TYPE_COMPLEX:
90                 /* this is a complex object */
91 #define SCAN OBJ_COMPLEX_FOREACH_PTR (desc, start)
92 #ifndef SCAN_OBJECT_NOSCAN
93                 SCAN;
94 #endif
95 #undef SCAN
96                 break;
97 #ifndef SCAN_OBJECT_NOVTABLE
98         case DESC_TYPE_COMPLEX_ARR:
99                 /* this is an array of complex structs */
100 #define SCAN OBJ_COMPLEX_ARR_FOREACH_PTR (vt, start)
101 #ifndef SCAN_OBJECT_NOSCAN
102                 SCAN;
103 #endif
104 #undef SCAN
105                 break;
106 #endif
107         case DESC_TYPE_COMPLEX_PTRFREE:
108                 /*Nothing to do*/
109                 break;
110         default:
111                 g_assert_not_reached ();
112         }
113 }
114
115 #undef SCAN_OBJECT_NOSCAN
116 #undef SCAN_OBJECT_NOVTABLE
117 #undef SCAN_OBJECT_PROTOCOL