Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / sgen / sgen-scan-object.h
1 /**
2  * \file
3  * Generic object scan.
4  *
5  * Copyright 2001-2003 Ximian, Inc
6  * Copyright 2003-2010 Novell, Inc.
7  * Copyright (C) 2013 Xamarin Inc
8  *
9  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
10  *
11  *
12  * Scans one object, using the OBJ_XXX macros.  The start of the
13  * object must be given in the variable "char* start".  Afterwards,
14  * "start" will point to the start of the next object, if the scanned
15  * object contained references.  If not, the value of "start" should
16  * be considered undefined after executing this code.  The object's
17  * GC descriptor must be in the variable "mword desc".
18  *
19  * The macro `HANDLE_PTR` will be invoked for every reference encountered while scanning the
20  * object.  It is called with two parameters: The pointer to the reference (not the
21  * reference itself!) as well as the pointer to the scanned object.
22  *
23  * Modifiers (automatically undefined):
24  *
25  * SCAN_OBJECT_NOSCAN - if defined, don't actually scan the object,
26  * i.e. don't invoke the OBJ_XXX macros.
27  *
28  * SCAN_OBJECT_NOVTABLE - desc is provided by the includer, instead of
29  * vt.  Complex arrays cannot not be scanned.
30  *
31  * SCAN_OBJECT_PROTOCOL - if defined, binary protocol the scan.
32  * Should only be used for scanning that's done for the actual
33  * collection, not for debugging scans.
34  */
35
36 {
37 #ifndef SCAN_OBJECT_NOVTABLE
38 #if defined(SGEN_HEAVY_BINARY_PROTOCOL) && defined(SCAN_OBJECT_PROTOCOL)
39         binary_protocol_scan_begin ((GCObject*)start, SGEN_LOAD_VTABLE ((GCObject*)start), sgen_safe_object_get_size ((GCObject*)start));
40 #endif
41 #else
42 #if defined(SGEN_HEAVY_BINARY_PROTOCOL) && defined(SCAN_OBJECT_PROTOCOL)
43         binary_protocol_scan_vtype_begin (start + SGEN_CLIENT_OBJECT_HEADER_SIZE, size);
44 #endif
45 #endif
46         switch (desc & DESC_TYPE_MASK) {
47         case DESC_TYPE_RUN_LENGTH:
48 #define SCAN OBJ_RUN_LEN_FOREACH_PTR (desc, ((GCObject*)start))
49 #ifndef SCAN_OBJECT_NOSCAN
50                 SCAN;
51 #endif
52 #undef SCAN
53                 break;
54         case DESC_TYPE_VECTOR:
55 #define SCAN OBJ_VECTOR_FOREACH_PTR (desc, ((GCObject*)start))
56 #ifndef SCAN_OBJECT_NOSCAN
57                 SCAN;
58 #endif
59 #undef SCAN
60                 break;
61         case DESC_TYPE_BITMAP:
62 #define SCAN OBJ_BITMAP_FOREACH_PTR (desc, ((GCObject*)start))
63 #ifndef SCAN_OBJECT_NOSCAN
64                 SCAN;
65 #endif
66 #undef SCAN
67                 break;
68         case DESC_TYPE_COMPLEX:
69                 /* this is a complex object */
70 #define SCAN OBJ_COMPLEX_FOREACH_PTR (desc, ((GCObject*)start))
71 #ifndef SCAN_OBJECT_NOSCAN
72                 SCAN;
73 #endif
74 #undef SCAN
75                 break;
76 #ifndef SCAN_OBJECT_NOVTABLE
77         case DESC_TYPE_COMPLEX_ARR:
78                 /* this is an array of complex structs */
79 #define SCAN OBJ_COMPLEX_ARR_FOREACH_PTR (desc, ((GCObject*)start))
80 #ifndef SCAN_OBJECT_NOSCAN
81                 SCAN;
82 #endif
83 #undef SCAN
84                 break;
85 #endif
86         case DESC_TYPE_SMALL_PTRFREE:
87         case DESC_TYPE_COMPLEX_PTRFREE:
88                 /*Nothing to do*/
89                 break;
90         default:
91                 g_assert_not_reached ();
92         }
93 }
94
95 #undef SCAN_OBJECT_NOSCAN
96 #undef SCAN_OBJECT_NOVTABLE
97 #undef SCAN_OBJECT_PROTOCOL