[sgen] Remove dependency on `mono-gc.h`.
[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 <metadata/sgen-pointer-queue.h>
21
22 void sgen_client_init_early (void);
23 void sgen_client_init (void);
24
25 mword sgen_client_slow_object_get_size (GCVTable *vtable, GCObject* o);
26
27 /*
28  * Returns the vtable used for dummy objects to fill the nursery for ease and speed of
29  * walking.  Must be a valid vtable that is not used by any actual objects.  Must be
30  * idempotent.
31  */
32 GCVTable* sgen_client_get_array_fill_vtable (void);
33
34 /*
35  * Fill the given range with a dummy object.  Its vtable must be the one returned by
36  * `sgen_client_get_array_fill_vtable()`.  If the range is too short to be filled with an
37  * object, null it.  Return `TRUE` if the range was filled with an object, `FALSE` if it was
38  * nulled.
39  */
40 gboolean sgen_client_array_fill_range (char *start, size_t size);
41
42 /*
43  * This is called if the nursery clearing policy at `clear-at-gc`, which is usually only
44  * used for debugging.  If `size` is large enough for the memory to have been filled with a
45  * dummy, object, zero its header.  Note that there might not actually be a header there.
46  */
47 void sgen_client_zero_array_fill_header (void *p, size_t size);
48
49 gboolean sgen_client_object_is_array_fill (GCObject *o);
50
51 gboolean sgen_client_object_has_critical_finalizer (GCObject *obj);
52
53 /*
54  * Called after an object is enqueued for finalization.  This is a very low-level callback.
55  * It should almost certainly be a NOP.
56  *
57  * FIXME: Can we merge this with `sgen_client_object_has_critical_finalizer()`?
58  */
59 void sgen_client_object_queued_for_finalization (GCObject *obj);
60
61 void sgen_client_run_finalize (MonoObject *obj);
62
63 gboolean sgen_client_mark_ephemerons (ScanCopyContext ctx);
64
65 /*
66  * Clear ephemeron pairs with unreachable keys.
67  * We pass the copy func so we can figure out if an array was promoted or not.
68  */
69 void sgen_client_clear_unreachable_ephemerons (ScanCopyContext ctx);
70
71 /*
72  * This is called for objects that are larger than one card.  If it's possible to scan only
73  * parts of the object based on which cards are marked, do so and return TRUE.  Otherwise,
74  * return FALSE.
75  */
76 gboolean sgen_client_cardtable_scan_object (char *obj, mword block_obj_size, guint8 *cards, gboolean mod_union, ScanCopyContext ctx);
77
78 void sgen_client_nursery_objects_pinned (void **definitely_pinned, int count);
79
80 void sgen_client_collecting_minor (SgenPointerQueue *fin_ready_queue, SgenPointerQueue *critical_fin_queue);
81 void sgen_client_collecting_major_1 (void);
82 void sgen_client_pinned_los_object (char *obj);
83 void sgen_client_collecting_major_2 (void);
84 void sgen_client_collecting_major_3 (SgenPointerQueue *fin_ready_queue, SgenPointerQueue *critical_fin_queue);
85
86 void sgen_client_degraded_allocation (size_t size);
87
88 void sgen_client_total_allocated_heap (mword allocated_heap);
89
90 /*
91  * If the client has registered any internal memory types, this must return a string
92  * describing the given type.  Only used for debugging.
93  */
94 const char* sgen_client_description_for_internal_mem_type (int type);
95
96 /* FIXME: Use `sgen_client_vtable_get_name()` instead of this. */
97 const char* sgen_client_object_safe_name (GCObject *obj);
98
99 const char* sgen_client_vtable_get_namespace (GCVTable *vtable);
100 const char* sgen_client_vtable_get_name (GCVTable *vtable);
101
102 void sgen_client_pre_collection_checks (void);
103
104 void sgen_client_thread_register (SgenThreadInfo* info, void *stack_bottom_fallback);
105 void sgen_client_thread_unregister (SgenThreadInfo *p);
106 void sgen_client_thread_attach (SgenThreadInfo *info);
107
108 void sgen_client_scan_thread_data (void *start_nursery, void *end_nursery, gboolean precise, ScanCopyContext ctx);
109
110 int sgen_client_stop_world (int generation);
111 int sgen_client_restart_world (int generation, GGTimingInfo *timing);
112
113 void sgen_client_log_timing (GGTimingInfo *info, mword last_major_num_sections, mword last_los_memory_usage);
114
115 gboolean sgen_client_handle_gc_param (const char *opt);
116 void sgen_client_print_gc_params_usage (void);
117
118 gboolean sgen_client_handle_gc_debug (const char *opt);
119 void sgen_client_print_gc_debug_usage (void);
120
121 #define TYPE_INT int
122 #define TYPE_LONGLONG long long
123 #define TYPE_SIZE size_t
124 #define TYPE_POINTER gpointer
125 #define TYPE_BOOL gboolean
126
127 #define BEGIN_PROTOCOL_ENTRY0(method) \
128         void sgen_client_ ## method (void);
129 #define BEGIN_PROTOCOL_ENTRY_HEAVY0(method) \
130         void sgen_client_ ## method (void);
131 #define BEGIN_PROTOCOL_ENTRY1(method,t1,f1) \
132         void sgen_client_ ## method (t1 f1);
133 #define BEGIN_PROTOCOL_ENTRY_HEAVY1(method,t1,f1) \
134         void sgen_client_ ## method (t1 f1);
135 #define BEGIN_PROTOCOL_ENTRY2(method,t1,f1,t2,f2) \
136         void sgen_client_ ## method (t1 f1, t2 f2);
137 #define BEGIN_PROTOCOL_ENTRY_HEAVY2(method,t1,f1,t2,f2) \
138         void sgen_client_ ## method (t1 f1, t2 f2);
139 #define BEGIN_PROTOCOL_ENTRY3(method,t1,f1,t2,f2,t3,f3) \
140         void sgen_client_ ## method (t1 f1, t2 f2, t3 f3);
141 #define BEGIN_PROTOCOL_ENTRY_HEAVY3(method,t1,f1,t2,f2,t3,f3) \
142         void sgen_client_ ## method (t1 f1, t2 f2, t3 f3);
143 #define BEGIN_PROTOCOL_ENTRY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
144         void sgen_client_ ## method (t1 f1, t2 f2, t3 f3, t4 f4);
145 #define BEGIN_PROTOCOL_ENTRY_HEAVY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
146         void sgen_client_ ## method (t1 f1, t2 f2, t3 f3, t4 f4);
147 #define BEGIN_PROTOCOL_ENTRY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
148         void sgen_client_ ## method (t1 f1, t2 f2, t3 f3, t4 f4, t5 f5);
149 #define BEGIN_PROTOCOL_ENTRY_HEAVY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
150         void sgen_client_ ## method (t1 f1, t2 f2, t3 f3, t4 f4, t5 f5);
151 #define BEGIN_PROTOCOL_ENTRY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
152         void sgen_client_ ## method (t1 f1, t2 f2, t3 f3, t4 f4, t5 f5, t6 f6);
153 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
154         void sgen_client_ ## method (t1 f1, t2 f2, t3 f3, t4 f4, t5 f5, t6 f6);
155
156 #define FLUSH()
157
158 #define DEFAULT_PRINT()
159 #define CUSTOM_PRINT(_)
160
161 #define IS_ALWAYS_MATCH(_)
162 #define MATCH_INDEX(_)
163 #define IS_VTABLE_MATCH(_)
164
165 #define END_PROTOCOL_ENTRY
166 #define END_PROTOCOL_ENTRY_HEAVY
167
168 #include "sgen-protocol-def.h"
169
170 #undef TYPE_INT
171 #undef TYPE_LONGLONG
172 #undef TYPE_SIZE
173 #undef TYPE_POINTER
174 #undef TYPE_BOOL