Merge pull request #717 from mono/client_websockets_impl
[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                 SGEN_OBJECT_LAYOUT_STATISTICS_MARK_BITMAP ((obj), (ptr)); \
45                 if (__old) {    \
46                         PARALLEL_COPY_OBJECT ((ptr), queue);    \
47                         __copy = *(ptr);        \
48                         SGEN_COND_LOG (9, __old != __copy, "Overwrote field at %p with %p (was: %p)", (ptr), *(ptr), __old);    \
49                         if (G_UNLIKELY (sgen_ptr_in_nursery (__copy) && !sgen_ptr_in_nursery ((ptr)))) \
50                                 sgen_add_to_global_remset ((ptr), __copy); \
51                 }       \
52         } while (0)
53
54 /*
55  * Scan the object pointed to by @start for references to
56  * other objects between @from_start and @from_end and copy
57  * them to the gray_objects area.
58  */
59 static void
60 PARALLEL_SCAN_OBJECT (char *start, SgenGrayQueue *queue)
61 {
62         SGEN_OBJECT_LAYOUT_STATISTICS_DECLARE_BITMAP;
63
64 #define SCAN_OBJECT_PROTOCOL
65 #include "sgen-scan-object.h"
66
67         SGEN_OBJECT_LAYOUT_STATISTICS_COMMIT_BITMAP;
68         HEAVY_STAT (++stat_scan_object_called_nursery);
69 }
70
71 /*
72  * scan_vtype:
73  *
74  * Scan the valuetype pointed to by START, described by DESC for references to
75  * other objects between @from_start and @from_end and copy them to the gray_objects area.
76  * Returns a pointer to the end of the object.
77  */
78 static void
79 PARALLEL_SCAN_VTYPE (char *start, mword desc, SgenGrayQueue *queue BINARY_PROTOCOL_ARG (size_t size))
80 {
81         SGEN_OBJECT_LAYOUT_STATISTICS_DECLARE_BITMAP;
82
83         /* The descriptors include info about the MonoObject header as well */
84         start -= sizeof (MonoObject);
85
86 #define SCAN_OBJECT_NOVTABLE
87 #define SCAN_OBJECT_PROTOCOL
88 #include "sgen-scan-object.h"
89 }
90
91 #undef HANDLE_PTR
92 /* Global remsets are handled in SERIAL_COPY_OBJECT_FROM_OBJ */
93 #define HANDLE_PTR(ptr,obj)     do {    \
94                 void *__old = *(ptr);   \
95                 SGEN_OBJECT_LAYOUT_STATISTICS_MARK_BITMAP ((obj), (ptr)); \
96                 if (__old) {    \
97                         SERIAL_COPY_OBJECT_FROM_OBJ ((ptr), queue);     \
98                         SGEN_COND_LOG (9, __old != *(ptr), "Overwrote field at %p with %p (was: %p)", (ptr), *(ptr), __old); \
99                 }       \
100         } while (0)
101
102 static void
103 SERIAL_SCAN_OBJECT (char *start, SgenGrayQueue *queue)
104 {
105         SGEN_OBJECT_LAYOUT_STATISTICS_DECLARE_BITMAP;
106
107 #define SCAN_OBJECT_PROTOCOL
108 #include "sgen-scan-object.h"
109
110         SGEN_OBJECT_LAYOUT_STATISTICS_COMMIT_BITMAP;
111         HEAVY_STAT (++stat_scan_object_called_nursery);
112 }
113
114 static void
115 SERIAL_SCAN_VTYPE (char *start, mword desc, SgenGrayQueue *queue BINARY_PROTOCOL_ARG (size_t size))
116 {
117         SGEN_OBJECT_LAYOUT_STATISTICS_DECLARE_BITMAP;
118
119         /* The descriptors include info about the MonoObject header as well */
120         start -= sizeof (MonoObject);
121
122 #define SCAN_OBJECT_NOVTABLE
123 #define SCAN_OBJECT_PROTOCOL
124 #include "sgen-scan-object.h"
125 }
126
127 #define FILL_MINOR_COLLECTOR_SCAN_OBJECT(collector)     do {                    \
128                 (collector)->parallel_ops.scan_object = PARALLEL_SCAN_OBJECT;   \
129                 (collector)->parallel_ops.scan_vtype = PARALLEL_SCAN_VTYPE;     \
130                 (collector)->serial_ops.scan_object = SERIAL_SCAN_OBJECT;       \
131                 (collector)->serial_ops.scan_vtype = SERIAL_SCAN_VTYPE; \
132         } while (0)