Improve a safety check when writing data into StatBuffer
[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 /*
23  * FIXME: We use the same scanning function in the concurrent collector whether we scan
24  * during the starting/finishing collection pause (with the world stopped) or from the
25  * concurrent worker thread.
26  *
27  * As long as the world is stopped, we should just follow pointers into the nursery and
28  * evict if possible.  In that case we also don't need the ALWAYS_ADD_TO_GLOBAL_REMSET case,
29  * which only seems to make sense for when the world is stopped, in which case we only need
30  * it because we don't follow into the nursery.
31  */
32
33 #undef HANDLE_PTR
34 #define HANDLE_PTR(ptr,obj)     do {                                    \
35                 GCObject *__old = *(ptr);                                   \
36                 binary_protocol_scan_process_reference ((full_object), (ptr), __old); \
37                 if (__old) {                                            \
38                         gboolean __still_in_nursery = major_copy_or_mark_object_with_evacuation ((ptr), __old, queue); \
39                         if (G_UNLIKELY (__still_in_nursery && !sgen_ptr_in_nursery ((ptr)) && !SGEN_OBJECT_IS_CEMENTED (*(ptr)))) { \
40                                 GCObject *__copy = *(ptr);                  \
41                                 sgen_add_to_global_remset ((ptr), __copy); \
42                         }                                               \
43                 }                                                       \
44         } while (0)
45
46
47 static void
48 major_scan_vtype_concurrent_finish (GCObject *full_object, char *start, SgenDescriptor desc, SgenGrayQueue *queue BINARY_PROTOCOL_ARG (size_t size))
49 {
50         SGEN_OBJECT_LAYOUT_STATISTICS_DECLARE_BITMAP;
51
52 #ifdef HEAVY_STATISTICS
53         /* FIXME: We're half scanning this object.  How do we account for that? */
54         //add_scanned_object (start);
55 #endif
56
57         /* The descriptors include info about the object header as well */
58         start -= SGEN_CLIENT_OBJECT_HEADER_SIZE;
59
60 #define SCAN_OBJECT_NOVTABLE
61 #define SCAN_OBJECT_PROTOCOL
62 #include "sgen-scan-object.h"
63
64         SGEN_OBJECT_LAYOUT_STATISTICS_COMMIT_BITMAP;
65 }