Merge pull request #1870 from saper/langinfo_h
[mono.git] / mono / sgen / sgen-marksweep-scan-object-concurrent.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 guint64 stat_scan_object_called_major;
23
24 /*
25  * FIXME: We use the same scanning function in the concurrent collector whether we scan
26  * during the starting/finishing collection pause (with the world stopped) or from the
27  * concurrent worker thread.
28  *
29  * As long as the world is stopped, we should just follow pointers into the nursery and
30  * evict if possible.  In that case we also don't need the ALWAYS_ADD_TO_GLOBAL_REMSET case,
31  * which only seems to make sense for when the world is stopped, in which case we only need
32  * it because we don't follow into the nursery.
33  */
34
35 #undef HANDLE_PTR
36 #define HANDLE_PTR(ptr,obj)     do {                                    \
37                 GCObject *__old = *(ptr);                                       \
38                 SGEN_OBJECT_LAYOUT_STATISTICS_MARK_BITMAP ((obj), (ptr)); \
39                 binary_protocol_scan_process_reference ((obj), (ptr), __old); \
40                 if (__old && !sgen_ptr_in_nursery (__old)) {            \
41                         PREFETCH_READ (__old);                  \
42                         major_copy_or_mark_object_concurrent ((ptr), __old, queue); \
43                 } else {                                                \
44                         if (G_UNLIKELY (sgen_ptr_in_nursery (__old) && !sgen_ptr_in_nursery ((ptr)))) \
45                                 ADD_TO_GLOBAL_REMSET ((full_object), (ptr), __old); \
46                 }                                                       \
47         } while (0)
48
49 /* FIXME: Unify this with optimized code in sgen-marksweep.c. */
50
51 #undef ADD_TO_GLOBAL_REMSET
52 #define ADD_TO_GLOBAL_REMSET(object,ptr,target) mark_mod_union_card ((object), (void**)(ptr))
53
54 static void
55 major_scan_object_no_mark_concurrent_anywhere (GCObject *full_object, SgenDescriptor desc, SgenGrayQueue *queue)
56 {
57         char *start = (char*)full_object;
58
59         SGEN_OBJECT_LAYOUT_STATISTICS_DECLARE_BITMAP;
60
61 #ifdef HEAVY_STATISTICS
62         sgen_descriptor_count_scanned_object (desc);
63 #endif
64 #ifdef SGEN_HEAVY_BINARY_PROTOCOL
65         add_scanned_object (start);
66 #endif
67
68 #define SCAN_OBJECT_PROTOCOL
69 #include "sgen-scan-object.h"
70
71         SGEN_OBJECT_LAYOUT_STATISTICS_COMMIT_BITMAP;
72         HEAVY_STAT (++stat_scan_object_called_major);
73 }
74
75 static void
76 major_scan_object_no_mark_concurrent_start (GCObject *start, SgenDescriptor desc, SgenGrayQueue *queue)
77 {
78         major_scan_object_no_mark_concurrent_anywhere (start, desc, queue);
79 }
80
81 static void
82 major_scan_object_no_mark_concurrent (GCObject *start, SgenDescriptor desc, SgenGrayQueue *queue)
83 {
84         SGEN_ASSERT (0, !sgen_ptr_in_nursery (start), "Why are we scanning nursery objects in the concurrent collector?");
85         major_scan_object_no_mark_concurrent_anywhere (start, desc, queue);
86 }
87
88 #undef ADD_TO_GLOBAL_REMSET
89 #define ADD_TO_GLOBAL_REMSET(object,ptr,target) sgen_add_to_global_remset ((ptr), (target))
90
91 static void
92 major_scan_vtype_concurrent_finish (GCObject *full_object, char *start, SgenDescriptor desc, SgenGrayQueue *queue BINARY_PROTOCOL_ARG (size_t size))
93 {
94         SGEN_OBJECT_LAYOUT_STATISTICS_DECLARE_BITMAP;
95
96 #ifdef HEAVY_STATISTICS
97         /* FIXME: We're half scanning this object.  How do we account for that? */
98         //add_scanned_object (start);
99 #endif
100
101         /* The descriptors include info about the object header as well */
102         start -= SGEN_CLIENT_OBJECT_HEADER_SIZE;
103
104 #define SCAN_OBJECT_NOVTABLE
105 #define SCAN_OBJECT_PROTOCOL
106 #include "sgen-scan-object.h"
107
108         SGEN_OBJECT_LAYOUT_STATISTICS_COMMIT_BITMAP;
109 }