Merge pull request #495 from nicolas-raoul/fix-for-issue2907-with-no-formatting-changes
[mono.git] / mono / metadata / sgen-minor-scan-object.h
1 /*
2  * sgen-minor-scan-object.h: Object scanning in the nursery collectors.
3  *
4  * Copyright 2001-2003 Ximian, Inc
5  * Copyright 2003-2010 Novell, Inc.
6  * Copyright (C) 2012 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 extern long long stat_scan_object_called_nursery;
23
24 #if defined(SGEN_SIMPLE_NURSERY)
25 #define SERIAL_SCAN_OBJECT simple_nursery_serial_scan_object
26 #define SERIAL_SCAN_VTYPE simple_nursery_serial_scan_vtype
27 #define PARALLEL_SCAN_OBJECT simple_nursery_parallel_scan_object
28 #define PARALLEL_SCAN_VTYPE simple_nursery_parallel_scan_vtype
29
30 #elif defined (SGEN_SPLIT_NURSERY)
31 #define SERIAL_SCAN_OBJECT split_nursery_serial_scan_object
32 #define SERIAL_SCAN_VTYPE split_nursery_serial_scan_vtype
33 #define PARALLEL_SCAN_OBJECT split_nursery_parallel_scan_object
34 #define PARALLEL_SCAN_VTYPE split_nursery_parallel_scan_vtype
35
36 #else
37 #error "Please define GC_CONF_NAME"
38 #endif
39
40 #undef HANDLE_PTR
41 #define HANDLE_PTR(ptr,obj)     do {    \
42                 void *__old = *(ptr);   \
43                 void *__copy;           \
44                 if (__old) {    \
45                         PARALLEL_COPY_OBJECT ((ptr), queue);    \
46                         __copy = *(ptr);        \
47                         SGEN_COND_LOG (9, __old != __copy, "Overwrote field at %p with %p (was: %p)", (ptr), *(ptr), __old);    \
48                         if (G_UNLIKELY (sgen_ptr_in_nursery (__copy) && !sgen_ptr_in_nursery ((ptr)))) \
49                                 sgen_add_to_global_remset ((ptr));      \
50                 }       \
51         } while (0)
52
53 /*
54  * Scan the object pointed to by @start for references to
55  * other objects between @from_start and @from_end and copy
56  * them to the gray_objects area.
57  */
58 static void
59 PARALLEL_SCAN_OBJECT (char *start, SgenGrayQueue *queue)
60 {
61 #include "sgen-scan-object.h"
62
63         HEAVY_STAT (++stat_scan_object_called_nursery);
64 }
65
66 /*
67  * scan_vtype:
68  *
69  * Scan the valuetype pointed to by START, described by DESC for references to
70  * other objects between @from_start and @from_end and copy them to the gray_objects area.
71  * Returns a pointer to the end of the object.
72  */
73 static void
74 PARALLEL_SCAN_VTYPE (char *start, mword desc, SgenGrayQueue *queue)
75 {
76         /* The descriptors include info about the MonoObject header as well */
77         start -= sizeof (MonoObject);
78
79 #define SCAN_OBJECT_NOVTABLE
80 #include "sgen-scan-object.h"
81 }
82
83 #undef HANDLE_PTR
84 /* Global remsets are handled in SERIAL_COPY_OBJECT_FROM_OBJ */
85 #define HANDLE_PTR(ptr,obj)     do {    \
86                 void *__old = *(ptr);   \
87                 if (__old) {    \
88                         SERIAL_COPY_OBJECT_FROM_OBJ ((ptr), queue);     \
89                         SGEN_COND_LOG (9, __old != *(ptr), "Overwrote field at %p with %p (was: %p)", (ptr), *(ptr), __old); \
90                 }       \
91         } while (0)
92
93 static void
94 SERIAL_SCAN_OBJECT (char *start, SgenGrayQueue *queue)
95 {
96 #include "sgen-scan-object.h"
97
98         HEAVY_STAT (++stat_scan_object_called_nursery);
99 }
100
101 static void
102 SERIAL_SCAN_VTYPE (char *start, mword desc, SgenGrayQueue *queue)
103 {
104         /* The descriptors include info about the MonoObject header as well */
105         start -= sizeof (MonoObject);
106
107 #define SCAN_OBJECT_NOVTABLE
108 #include "sgen-scan-object.h"
109 }
110
111 #define FILL_MINOR_COLLECTOR_SCAN_OBJECT(collector)     do {                    \
112                 (collector)->parallel_ops.scan_object = PARALLEL_SCAN_OBJECT;   \
113                 (collector)->parallel_ops.scan_vtype = PARALLEL_SCAN_VTYPE;     \
114                 (collector)->serial_ops.scan_object = SERIAL_SCAN_OBJECT;       \
115                 (collector)->serial_ops.scan_vtype = SERIAL_SCAN_VTYPE; \
116         } while (0)