[sgen] Evacuation for concurrent mark (during forced collections).
[mono.git] / mono / metadata / sgen-major-scan-object.h
1 /*
2  * sgen-major-scan-object.h: Object scanning in the major 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_major;
23
24 #ifdef FIXED_HEAP
25 #define PREFETCH_DYNAMIC_HEAP(addr)
26 #else
27 #define PREFETCH_DYNAMIC_HEAP(addr)     PREFETCH ((addr))
28 #endif
29
30 #ifdef SCAN_FOR_CONCURRENT_MARK
31 #define FOLLOW_OBJECT(addr)     (!sgen_ptr_in_nursery ((addr)))
32 #define ALWAYS_ADD_TO_GLOBAL_REMSET     1
33 #define CONCURRENT_NAME(x)      x ## _concurrent
34 #else
35 #define FOLLOW_OBJECT(addr)     1
36 #define ALWAYS_ADD_TO_GLOBAL_REMSET     0
37 #define CONCURRENT_NAME(x)      x
38 #endif
39
40 #undef HANDLE_PTR
41 #define HANDLE_PTR(ptr,obj)     do {                                    \
42                 void *__old = *(ptr);                                   \
43                 void *__copy;                                           \
44                 if (__old && FOLLOW_OBJECT (__old)) {                   \
45                         PREFETCH_DYNAMIC_HEAP (__old);                  \
46                         CONCURRENT_NAME (major_copy_or_mark_object) ((ptr), __old, 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                 } else {                                                \
52                         if (ALWAYS_ADD_TO_GLOBAL_REMSET && G_UNLIKELY (sgen_ptr_in_nursery (__old) && !sgen_ptr_in_nursery ((ptr)))) \
53                                 sgen_add_to_global_remset ((ptr), __old); \
54                 }                                                       \
55         } while (0)
56
57 static void
58 CONCURRENT_NAME (major_scan_object) (char *start, SgenGrayQueue *queue)
59 {
60 #include "sgen-scan-object.h"
61
62         HEAVY_STAT (++stat_scan_object_called_major);
63 }
64
65 #ifdef SCAN_FOR_CONCURRENT_MARK
66 #ifdef SGEN_PARALLEL_MARK
67 #error concurrent and parallel mark not supported yet
68 #else
69 static void
70 CONCURRENT_NAME (major_scan_vtype) (char *start, mword desc, SgenGrayQueue *queue)
71 {
72         /* The descriptors include info about the MonoObject header as well */
73         start -= sizeof (MonoObject);
74
75 #define SCAN_OBJECT_NOVTABLE
76 #include "sgen-scan-object.h"
77 }
78 #endif
79 #endif
80
81 #undef PREFETCH_DYNAMIC_HEAP
82 #undef FOLLOW_OBJECT
83 #undef ALWAYS_ADD_TO_GLOBAL_REMSET
84 #undef CONCURRENT_NAME