ee72408b76f273ace13978c6ea126cc1af7fe032
[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 SgenFragment*
32 build_fragments_get_exclude_head (void)
33 {
34         return NULL;
35 }
36
37 static void
38 build_fragments_release_exclude_head (void)
39 {
40 }
41
42 static void
43 build_fragments_finish (SgenFragmentAllocator *allocator)
44 {
45 }
46
47 static void
48 prepare_to_space (char *to_space_bitmap, size_t space_bitmap_size)
49 {
50 }
51
52 static void
53 clear_fragments (void)
54 {       
55 }
56
57 static void
58 init_nursery (SgenFragmentAllocator *allocator, char *start, char *end)
59 {
60         char *nursery_limit = sgen_nursery_start + sgen_nursery_size;
61
62         if (start < nursery_limit && end > nursery_limit) {
63                 sgen_fragment_allocator_add (allocator, start, nursery_limit);
64                 sgen_fragment_allocator_add (allocator, nursery_limit, end);
65         } else {
66                 sgen_fragment_allocator_add (allocator, start, end);
67         }
68 }
69
70
71 /******************************************Copy/Scan functins ************************************************/
72
73 #define collector_pin_object(obj, queue) sgen_pin_object (obj, queue);
74 #define COLLECTOR_SERIAL_ALLOC_FOR_PROMOTION alloc_for_promotion
75
76 #define COPY_OR_MARK_PARALLEL
77 #include "sgen-copy-object.h"
78
79 #define SGEN_SIMPLE_NURSERY
80
81 #include "sgen-minor-copy-object.h"
82 #include "sgen-minor-scan-object.h"
83
84 static void
85 fill_serial_ops (SgenObjectOperations *ops)
86 {
87         ops->copy_or_mark_object = SERIAL_COPY_OBJECT;
88         FILL_MINOR_COLLECTOR_SCAN_OBJECT (ops);
89 }
90
91 #define SGEN_SIMPLE_PAR_NURSERY
92
93 #include "sgen-minor-copy-object.h"
94 #include "sgen-minor-scan-object.h"
95
96 static void
97 fill_parallel_ops (SgenObjectOperations *ops)
98 {
99         ops->copy_or_mark_object = SERIAL_COPY_OBJECT;
100         FILL_MINOR_COLLECTOR_SCAN_OBJECT (ops);
101 }
102
103 #undef SGEN_SIMPLE_PAR_NURSERY
104 #define SGEN_CONCURRENT_MAJOR
105
106 #include "sgen-minor-copy-object.h"
107 #include "sgen-minor-scan-object.h"
108
109 static void
110 fill_serial_with_concurrent_major_ops (SgenObjectOperations *ops)
111 {
112         ops->copy_or_mark_object = SERIAL_COPY_OBJECT;
113         FILL_MINOR_COLLECTOR_SCAN_OBJECT (ops);
114 }
115
116 void
117 sgen_simple_nursery_init (SgenMinorCollector *collector, gboolean parallel)
118 {
119         collector->is_split = FALSE;
120         collector->is_parallel = parallel;
121
122         collector->alloc_for_promotion = alloc_for_promotion;
123
124         collector->prepare_to_space = prepare_to_space;
125         collector->clear_fragments = clear_fragments;
126         collector->build_fragments_get_exclude_head = build_fragments_get_exclude_head;
127         collector->build_fragments_release_exclude_head = build_fragments_release_exclude_head;
128         collector->build_fragments_finish = build_fragments_finish;
129         collector->init_nursery = init_nursery;
130
131         fill_serial_ops (&collector->serial_ops);
132         fill_serial_with_concurrent_major_ops (&collector->serial_ops_with_concurrent_major);
133         fill_parallel_ops (&collector->parallel_ops);
134 }
135
136
137 #endif