9b23ce4ab70e3cd2284d5babad52333158db0158
[mono.git] / mono / sgen / sgen-minor-scan-object.h
1 /*
2  * sgen-minor-scan-object.h: Object scanning in the nursery 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_nursery;
23
24 #if defined(SGEN_SIMPLE_NURSERY)
25 #define SERIAL_SCAN_OBJECT simple_nursery_serial_scan_object
26 #define SERIAL_SCAN_VTYPE simple_nursery_serial_scan_vtype
27
28 #elif defined (SGEN_SPLIT_NURSERY)
29 #define SERIAL_SCAN_OBJECT split_nursery_serial_scan_object
30 #define SERIAL_SCAN_VTYPE split_nursery_serial_scan_vtype
31
32 #else
33 #error "Please define GC_CONF_NAME"
34 #endif
35
36 #undef HANDLE_PTR
37 /* Global remsets are handled in SERIAL_COPY_OBJECT_FROM_OBJ */
38 #define HANDLE_PTR(ptr,obj)     do {    \
39                 void *__old = *(ptr);   \
40                 SGEN_OBJECT_LAYOUT_STATISTICS_MARK_BITMAP ((obj), (ptr)); \
41                 binary_protocol_scan_process_reference ((full_object), (ptr), __old); \
42                 if (__old) {    \
43                         SERIAL_COPY_OBJECT_FROM_OBJ ((ptr), queue);     \
44                         SGEN_COND_LOG (9, __old != *(ptr), "Overwrote field at %p with %p (was: %p)", (ptr), *(ptr), __old); \
45                 }       \
46         } while (0)
47
48 static void
49 SERIAL_SCAN_OBJECT (GCObject *full_object, SgenDescriptor desc, SgenGrayQueue *queue)
50 {
51         char *start = (char*)full_object;
52
53         SGEN_OBJECT_LAYOUT_STATISTICS_DECLARE_BITMAP;
54
55 #ifdef HEAVY_STATISTICS
56         sgen_descriptor_count_scanned_object (desc);
57 #endif
58
59         SGEN_ASSERT (9, sgen_get_current_collection_generation () == GENERATION_NURSERY, "Must not use minor scan during major collection.");
60
61 #define SCAN_OBJECT_PROTOCOL
62 #include "sgen-scan-object.h"
63
64         SGEN_OBJECT_LAYOUT_STATISTICS_COMMIT_BITMAP;
65         HEAVY_STAT (++stat_scan_object_called_nursery);
66 }
67
68 static void
69 SERIAL_SCAN_VTYPE (GCObject *full_object, char *start, SgenDescriptor desc, SgenGrayQueue *queue BINARY_PROTOCOL_ARG (size_t size))
70 {
71         SGEN_OBJECT_LAYOUT_STATISTICS_DECLARE_BITMAP;
72
73         SGEN_ASSERT (9, sgen_get_current_collection_generation () == GENERATION_NURSERY, "Must not use minor scan during major collection.");
74
75         /* The descriptors include info about the MonoObject header as well */
76         start -= SGEN_CLIENT_OBJECT_HEADER_SIZE;
77
78 #define SCAN_OBJECT_NOVTABLE
79 #define SCAN_OBJECT_PROTOCOL
80 #include "sgen-scan-object.h"
81 }
82
83 static void
84 SERIAL_SCAN_PTR_FIELD (GCObject *full_object, GCObject **ptr, SgenGrayQueue *queue)
85 {
86         HANDLE_PTR (ptr, NULL);
87 }
88
89 #define FILL_MINOR_COLLECTOR_SCAN_OBJECT(collector)     do {                    \
90                 (collector)->serial_ops.scan_object = SERIAL_SCAN_OBJECT;       \
91                 (collector)->serial_ops.scan_vtype = SERIAL_SCAN_VTYPE; \
92                 (collector)->serial_ops.scan_ptr_field = SERIAL_SCAN_PTR_FIELD; \
93         } while (0)