Merge branch 'master' of github.com:mono/mono
[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 (ptr_in_nursery (__copy) && !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 char*
61 minor_scan_vtype (char *start, mword desc, char* from_start, char* from_end, SgenGrayQueue *queue)
62 {
63         size_t skip_size;
64
65         /* The descriptors include info about the MonoObject header as well */
66         start -= sizeof (MonoObject);
67
68         switch (desc & 0x7) {
69         case DESC_TYPE_RUN_LENGTH:
70                 OBJ_RUN_LEN_FOREACH_PTR (desc,start);
71                 OBJ_RUN_LEN_SIZE (skip_size, desc, start);
72                 g_assert (skip_size);
73                 return start + skip_size;
74         case DESC_TYPE_SMALL_BITMAP:
75                 OBJ_BITMAP_FOREACH_PTR (desc,start);
76                 OBJ_BITMAP_SIZE (skip_size, desc, start);
77                 return start + skip_size;
78         case DESC_TYPE_LARGE_BITMAP:
79         case DESC_TYPE_COMPLEX:
80                 // FIXME:
81                 g_assert_not_reached ();
82                 break;
83         default:
84                 // The other descriptors can't happen with vtypes
85                 g_assert_not_reached ();
86                 break;
87         }
88         return NULL;
89 }
90
91 #undef HANDLE_PTR
92 #define HANDLE_PTR(ptr,obj)     do {                                    \
93                 void *__old = *(ptr);                                   \
94                 void *__copy;                                           \
95                 if (__old) {                                            \
96                         major_copy_or_mark_object ((ptr), queue);       \
97                         __copy = *(ptr);                                \
98                         DEBUG (9, if (__old != __copy) mono_sgen_debug_printf (9, "Overwrote field at %p with %p (was: %p)\n", (ptr), *(ptr), __old)); \
99                         if (G_UNLIKELY (ptr_in_nursery (__copy) && !ptr_in_nursery ((ptr)))) \
100                                 mono_sgen_add_to_global_remset ((ptr)); \
101                 }                                                       \
102         } while (0)
103
104 static void
105 major_scan_object (char *start, SgenGrayQueue *queue)
106 {
107 #include "sgen-scan-object.h"
108
109         HEAVY_STAT (++stat_scan_object_called_major);
110 }
111
112 #define FILL_COLLECTOR_SCAN_OBJECT(collector)   do {                    \
113                 (collector)->major_scan_object = major_scan_object;     \
114                 (collector)->minor_scan_object = minor_scan_object;     \
115                 (collector)->minor_scan_vtype = minor_scan_vtype;       \
116         } while (0)