824db873ee73ed717f2ab50eedc88a8768870f84
[mono.git] / mono / metadata / sgen-client.h
1 /*
2  * sgen-client.h: SGen client interface.
3  *
4  * Copyright (C) 2014 Xamarin Inc
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License 2.0 as published by the Free Software Foundation;
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License 2.0 along with this library; if not, write to the Free
17  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19
20 #include "mono/metadata/sgen-pointer-queue.h"
21
22 void sgen_client_init (void);
23
24 mword sgen_client_slow_object_get_size (GCVTable *vtable, GCObject* o);
25
26 /*
27  * Fill the given range with a dummy object.  If the range is too short to be filled with an
28  * object, null it.  Return `TRUE` if the range was filled with an object, `FALSE` if it was
29  * nulled.
30  */
31 gboolean sgen_client_array_fill_range (char *start, size_t size);
32
33 /*
34  * This is called if the nursery clearing policy at `clear-at-gc`, which is usually only
35  * used for debugging.  If `size` is large enough for the memory to have been filled with a
36  * dummy, object, zero its header.  Note that there might not actually be a header there.
37  */
38 void sgen_client_zero_array_fill_header (void *p, size_t size);
39
40 gboolean sgen_client_object_is_array_fill (GCObject *o);
41
42 gboolean sgen_client_object_has_critical_finalizer (GCObject *obj);
43
44 /*
45  * Called after an object is enqueued for finalization.  This is a very low-level callback.
46  * It should almost certainly be a NOP.
47  *
48  * FIXME: Can we merge this with `sgen_client_object_has_critical_finalizer()`?
49  */
50 void sgen_client_object_queued_for_finalization (GCObject *obj);
51
52 void sgen_client_run_finalize (GCObject *obj);
53
54 void sgen_client_finalize_notify (void);
55
56 gboolean sgen_client_mark_ephemerons (ScanCopyContext ctx);
57
58 /*
59  * Clear ephemeron pairs with unreachable keys.
60  * We pass the copy func so we can figure out if an array was promoted or not.
61  */
62 void sgen_client_clear_unreachable_ephemerons (ScanCopyContext ctx);
63
64 /*
65  * This is called for objects that are larger than one card.  If it's possible to scan only
66  * parts of the object based on which cards are marked, do so and return TRUE.  Otherwise,
67  * return FALSE.
68  */
69 gboolean sgen_client_cardtable_scan_object (char *obj, mword block_obj_size, guint8 *cards, gboolean mod_union, ScanCopyContext ctx);
70
71 void sgen_client_nursery_objects_pinned (void **definitely_pinned, int count);
72
73 void sgen_client_collecting_minor (SgenPointerQueue *fin_ready_queue, SgenPointerQueue *critical_fin_queue);
74 void sgen_client_collecting_major_1 (void);
75 void sgen_client_pinned_los_object (char *obj);
76 void sgen_client_collecting_major_2 (void);
77 void sgen_client_collecting_major_3 (SgenPointerQueue *fin_ready_queue, SgenPointerQueue *critical_fin_queue);
78
79 void sgen_client_degraded_allocation (size_t size);
80
81 void sgen_client_total_allocated_heap_changed (size_t allocated_heap_size);
82
83 void sgen_client_out_of_memory (size_t size);
84
85 /*
86  * If the client has registered any internal memory types, this must return a string
87  * describing the given type.  Only used for debugging.
88  */
89 const char* sgen_client_description_for_internal_mem_type (int type);
90
91 const char* sgen_client_vtable_get_namespace (GCVTable *vtable);
92 const char* sgen_client_vtable_get_name (GCVTable *vtable);
93
94 void sgen_client_pre_collection_checks (void);
95
96 void sgen_client_thread_register (SgenThreadInfo* info, void *stack_bottom_fallback);
97 void sgen_client_thread_unregister (SgenThreadInfo *p);
98
99 void sgen_client_thread_register_worker (void);
100
101 void sgen_client_scan_thread_data (void *start_nursery, void *end_nursery, gboolean precise, ScanCopyContext ctx);
102
103 void sgen_client_stop_world (int generation);
104 void sgen_client_restart_world (int generation, GGTimingInfo *timing);
105
106 gboolean sgen_client_bridge_need_processing (void);
107 void sgen_client_bridge_reset_data (void);
108 void sgen_client_bridge_processing_stw_step (void);
109 void sgen_client_bridge_wait_for_processing (void);
110 void sgen_client_bridge_processing_finish (int generation);
111 gboolean sgen_client_bridge_is_bridge_object (GCObject *obj);
112 void sgen_client_bridge_register_finalized_object (GCObject *object);
113
114 void sgen_client_mark_togglerefs (char *start, char *end, ScanCopyContext ctx);
115 void sgen_client_clear_togglerefs (char *start, char *end, ScanCopyContext ctx);
116
117 void sgen_client_log_timing (GGTimingInfo *info, mword last_major_num_sections, mword last_los_memory_usage);
118
119 gboolean sgen_client_handle_gc_param (const char *opt);
120 void sgen_client_print_gc_params_usage (void);
121
122 gboolean sgen_client_handle_gc_debug (const char *opt);
123 void sgen_client_print_gc_debug_usage (void);
124
125 #define TYPE_INT int
126 #define TYPE_LONGLONG long long
127 #define TYPE_SIZE size_t
128 #define TYPE_POINTER gpointer
129 #define TYPE_BOOL gboolean
130
131 #define BEGIN_PROTOCOL_ENTRY0(method) \
132         void sgen_client_ ## method (void);
133 #define BEGIN_PROTOCOL_ENTRY_HEAVY0(method) \
134         void sgen_client_ ## method (void);
135 #define BEGIN_PROTOCOL_ENTRY1(method,t1,f1) \
136         void sgen_client_ ## method (t1 f1);
137 #define BEGIN_PROTOCOL_ENTRY_HEAVY1(method,t1,f1) \
138         void sgen_client_ ## method (t1 f1);
139 #define BEGIN_PROTOCOL_ENTRY2(method,t1,f1,t2,f2) \
140         void sgen_client_ ## method (t1 f1, t2 f2);
141 #define BEGIN_PROTOCOL_ENTRY_HEAVY2(method,t1,f1,t2,f2) \
142         void sgen_client_ ## method (t1 f1, t2 f2);
143 #define BEGIN_PROTOCOL_ENTRY3(method,t1,f1,t2,f2,t3,f3) \
144         void sgen_client_ ## method (t1 f1, t2 f2, t3 f3);
145 #define BEGIN_PROTOCOL_ENTRY_HEAVY3(method,t1,f1,t2,f2,t3,f3) \
146         void sgen_client_ ## method (t1 f1, t2 f2, t3 f3);
147 #define BEGIN_PROTOCOL_ENTRY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
148         void sgen_client_ ## method (t1 f1, t2 f2, t3 f3, t4 f4);
149 #define BEGIN_PROTOCOL_ENTRY_HEAVY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
150         void sgen_client_ ## method (t1 f1, t2 f2, t3 f3, t4 f4);
151 #define BEGIN_PROTOCOL_ENTRY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
152         void sgen_client_ ## method (t1 f1, t2 f2, t3 f3, t4 f4, t5 f5);
153 #define BEGIN_PROTOCOL_ENTRY_HEAVY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
154         void sgen_client_ ## method (t1 f1, t2 f2, t3 f3, t4 f4, t5 f5);
155 #define BEGIN_PROTOCOL_ENTRY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
156         void sgen_client_ ## method (t1 f1, t2 f2, t3 f3, t4 f4, t5 f5, t6 f6);
157 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
158         void sgen_client_ ## method (t1 f1, t2 f2, t3 f3, t4 f4, t5 f5, t6 f6);
159
160 #define FLUSH()
161
162 #define DEFAULT_PRINT()
163 #define CUSTOM_PRINT(_)
164
165 #define IS_ALWAYS_MATCH(_)
166 #define MATCH_INDEX(_)
167 #define IS_VTABLE_MATCH(_)
168
169 #define END_PROTOCOL_ENTRY
170 #define END_PROTOCOL_ENTRY_HEAVY
171
172 #include "sgen-protocol-def.h"
173
174 #undef TYPE_INT
175 #undef TYPE_LONGLONG
176 #undef TYPE_SIZE
177 #undef TYPE_POINTER
178 #undef TYPE_BOOL