Merge pull request #205 from m3rlinez/master
[mono.git] / mono / metadata / sgen-major-scan-object.h
1 /*
2  * Copyright 2001-2003 Ximian, Inc
3  * Copyright 2003-2010 Novell, Inc.
4  * 
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  * 
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  * 
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 extern long long stat_scan_object_called_nursery;
25 extern long long stat_scan_object_called_major;
26
27 #undef HANDLE_PTR
28 #define HANDLE_PTR(ptr,obj)     do {    \
29                 void *__old = *(ptr);   \
30                 void *__copy;           \
31                 if (__old) {    \
32                         copy_object ((ptr), queue);     \
33                         __copy = *(ptr);        \
34                         DEBUG (9, if (__old != __copy) fprintf (gc_debug_file, "Overwrote field at %p with %p (was: %p)\n", (ptr), *(ptr), __old));     \
35                         if (G_UNLIKELY (mono_sgen_ptr_in_nursery (__copy) && !mono_sgen_ptr_in_nursery ((ptr)))) \
36                                 mono_sgen_add_to_global_remset ((ptr)); \
37                 }       \
38         } while (0)
39
40 /*
41  * Scan the object pointed to by @start for references to
42  * other objects between @from_start and @from_end and copy
43  * them to the gray_objects area.
44  */
45 static void
46 minor_scan_object (char *start, SgenGrayQueue *queue)
47 {
48 #include "sgen-scan-object.h"
49
50         HEAVY_STAT (++stat_scan_object_called_nursery);
51 }
52
53 /*
54  * scan_vtype:
55  *
56  * Scan the valuetype pointed to by START, described by DESC for references to
57  * other objects between @from_start and @from_end and copy them to the gray_objects area.
58  * Returns a pointer to the end of the object.
59  */
60 static void
61 minor_scan_vtype (char *start, mword desc, SgenGrayQueue *queue)
62 {
63         /* The descriptors include info about the MonoObject header as well */
64         start -= sizeof (MonoObject);
65
66 #define SCAN_OBJECT_NOVTABLE
67 #include "sgen-scan-object.h"
68 }
69
70 #undef HANDLE_PTR
71 #define HANDLE_PTR(ptr,obj)     do {    \
72                 void *__old = *(ptr);   \
73                 void *__copy;           \
74                 if (__old) {    \
75                         nopar_copy_object ((ptr), queue);       \
76                         __copy = *(ptr);        \
77                         DEBUG (9, if (__old != __copy) fprintf (gc_debug_file, "Overwrote field at %p with %p (was: %p)\n", (ptr), *(ptr), __old));     \
78                         if (G_UNLIKELY (mono_sgen_ptr_in_nursery (__copy) && !mono_sgen_ptr_in_nursery ((ptr)))) \
79                                 mono_sgen_add_to_global_remset ((ptr)); \
80                 }       \
81         } while (0)
82
83 static void
84 nopar_minor_scan_object (char *start, SgenGrayQueue *queue)
85 {
86 #include "sgen-scan-object.h"
87
88         HEAVY_STAT (++stat_scan_object_called_nursery);
89 }
90
91 static void
92 nopar_minor_scan_vtype (char *start, mword desc, SgenGrayQueue *queue)
93 {
94         /* The descriptors include info about the MonoObject header as well */
95         start -= sizeof (MonoObject);
96
97 #define SCAN_OBJECT_NOVTABLE
98 #include "sgen-scan-object.h"
99 }
100
101 #ifdef FIXED_HEAP
102 #define PREFETCH_DYNAMIC_HEAP(addr)
103 #else
104 #define PREFETCH_DYNAMIC_HEAP(addr)     PREFETCH ((addr))
105 #endif
106
107 #undef HANDLE_PTR
108 #define HANDLE_PTR(ptr,obj)     do {                                    \
109                 void *__old = *(ptr);                                   \
110                 void *__copy;                                           \
111                 if (__old) {                                            \
112                         PREFETCH_DYNAMIC_HEAP (__old);                  \
113                         major_copy_or_mark_object ((ptr), queue);       \
114                         __copy = *(ptr);                                \
115                         DEBUG (9, if (__old != __copy) mono_sgen_debug_printf (9, "Overwrote field at %p with %p (was: %p)\n", (ptr), *(ptr), __old)); \
116                         if (G_UNLIKELY (mono_sgen_ptr_in_nursery (__copy) && !mono_sgen_ptr_in_nursery ((ptr)))) \
117                                 mono_sgen_add_to_global_remset ((ptr)); \
118                 }                                                       \
119         } while (0)
120
121 static void
122 major_scan_object (char *start, SgenGrayQueue *queue)
123 {
124 #include "sgen-scan-object.h"
125
126         HEAVY_STAT (++stat_scan_object_called_major);
127 }
128
129 #define FILL_COLLECTOR_SCAN_OBJECT(collector)   do {                    \
130                 (collector)->major_scan_object = major_scan_object;     \
131                 (collector)->minor_scan_object = minor_scan_object;     \
132                 (collector)->nopar_minor_scan_object = nopar_minor_scan_object; \
133                 (collector)->minor_scan_vtype = minor_scan_vtype;       \
134                 (collector)->nopar_minor_scan_vtype = nopar_minor_scan_vtype; \
135         } while (0)