39d08abcf16027b60b884376a02acbc9a2517ea3
[mono.git] / mono / sgen / sgen-simple-nursery.c
1 /**
2  * \file
3  * Simple always promote nursery.
4  *
5  * Copyright 2001-2003 Ximian, Inc
6  * Copyright 2003-2010 Novell, Inc.
7  * Copyright 2011 Xamarin Inc (http://www.xamarin.com)
8  * Copyright (C) 2012 Xamarin Inc
9  *
10  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
11  */
12
13 #include "config.h"
14 #ifdef HAVE_SGEN_GC
15
16 #include <string.h>
17
18 #include "mono/sgen/sgen-gc.h"
19 #include "mono/sgen/sgen-protocol.h"
20 #include "mono/sgen/sgen-layout-stats.h"
21 #include "mono/sgen/sgen-client.h"
22 #include "mono/utils/mono-memory-model.h"
23
24 static inline GCObject*
25 alloc_for_promotion (GCVTable vtable, GCObject *obj, size_t objsize, gboolean has_references)
26 {
27         total_promoted_size += objsize;
28         return major_collector.alloc_object (vtable, objsize, has_references);
29 }
30
31 static inline GCObject*
32 alloc_for_promotion_par (GCVTable vtable, GCObject *obj, size_t objsize, gboolean has_references)
33 {
34         /*
35          * FIXME
36          * Note that the stat is not precise. total_promoted_size incrementing is not atomic and
37          * even in that case, the same object might be promoted simultaneously by different workers
38          * leading to one of the allocated major object to be discarded.
39          */
40         total_promoted_size += objsize;
41         return major_collector.alloc_object_par (vtable, objsize, has_references);
42 }
43
44 static SgenFragment*
45 build_fragments_get_exclude_head (void)
46 {
47         return NULL;
48 }
49
50 static void
51 build_fragments_release_exclude_head (void)
52 {
53 }
54
55 static void
56 build_fragments_finish (SgenFragmentAllocator *allocator)
57 {
58 }
59
60 static void
61 prepare_to_space (char *to_space_bitmap, size_t space_bitmap_size)
62 {
63 }
64
65 static void
66 clear_fragments (void)
67 {       
68 }
69
70 static void
71 init_nursery (SgenFragmentAllocator *allocator, char *start, char *end)
72 {
73         char *nursery_limit = sgen_nursery_start + sgen_nursery_size;
74
75         if (start < nursery_limit && end > nursery_limit) {
76                 sgen_fragment_allocator_add (allocator, start, nursery_limit);
77                 sgen_fragment_allocator_add (allocator, nursery_limit, end);
78         } else {
79                 sgen_fragment_allocator_add (allocator, start, end);
80         }
81 }
82
83
84 /******************************************Copy/Scan functins ************************************************/
85
86 #define collector_pin_object(obj, queue) sgen_pin_object (obj, queue);
87 #define COLLECTOR_SERIAL_ALLOC_FOR_PROMOTION alloc_for_promotion
88 #define COLLECTOR_PARALLEL_ALLOC_FOR_PROMOTION alloc_for_promotion_par
89
90 #define COPY_OR_MARK_PARALLEL
91 #include "sgen-copy-object.h"
92
93 #define SGEN_SIMPLE_NURSERY
94
95 #include "sgen-minor-copy-object.h"
96 #include "sgen-minor-scan-object.h"
97
98 static void
99 fill_serial_ops (SgenObjectOperations *ops)
100 {
101         ops->copy_or_mark_object = SERIAL_COPY_OBJECT;
102         FILL_MINOR_COLLECTOR_SCAN_OBJECT (ops);
103 }
104
105 #define SGEN_SIMPLE_PAR_NURSERY
106
107 #include "sgen-minor-copy-object.h"
108 #include "sgen-minor-scan-object.h"
109
110 static void
111 fill_parallel_ops (SgenObjectOperations *ops)
112 {
113         ops->copy_or_mark_object = SERIAL_COPY_OBJECT;
114         FILL_MINOR_COLLECTOR_SCAN_OBJECT (ops);
115 }
116
117 #undef SGEN_SIMPLE_PAR_NURSERY
118 #define SGEN_CONCURRENT_MAJOR
119
120 #include "sgen-minor-copy-object.h"
121 #include "sgen-minor-scan-object.h"
122
123 static void
124 fill_serial_with_concurrent_major_ops (SgenObjectOperations *ops)
125 {
126         ops->copy_or_mark_object = SERIAL_COPY_OBJECT;
127         FILL_MINOR_COLLECTOR_SCAN_OBJECT (ops);
128 }
129
130 void
131 sgen_simple_nursery_init (SgenMinorCollector *collector, gboolean parallel)
132 {
133         collector->is_split = FALSE;
134         collector->is_parallel = parallel;
135
136         collector->alloc_for_promotion = alloc_for_promotion;
137         collector->alloc_for_promotion_par = alloc_for_promotion_par;
138
139         collector->prepare_to_space = prepare_to_space;
140         collector->clear_fragments = clear_fragments;
141         collector->build_fragments_get_exclude_head = build_fragments_get_exclude_head;
142         collector->build_fragments_release_exclude_head = build_fragments_release_exclude_head;
143         collector->build_fragments_finish = build_fragments_finish;
144         collector->init_nursery = init_nursery;
145
146         fill_serial_ops (&collector->serial_ops);
147         fill_serial_with_concurrent_major_ops (&collector->serial_ops_with_concurrent_major);
148         fill_parallel_ops (&collector->parallel_ops);
149 }
150
151
152 #endif