Implement mono_gc_alloc_fixed on Boehm to be uncollectable. This matches SGen behavio...
[mono.git] / mono / sgen / sgen-protocol.h
1 /*
2  * sgen-protocol.h: Binary protocol of internal activity, to aid
3  * debugging.
4  *
5  * Copyright 2001-2003 Ximian, Inc
6  * Copyright 2003-2010 Novell, Inc.
7  * Copyright (C) 2012 Xamarin Inc
8  *
9  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
10  */
11
12 #ifndef __MONO_SGENPROTOCOL_H__
13 #define __MONO_SGENPROTOCOL_H__
14
15 #include "sgen-gc.h"
16
17 #define PROTOCOL_HEADER_CHECK 0xde7ec7ab1ec0de
18 #define PROTOCOL_HEADER_VERSION 1
19
20 /* Special indices returned by MATCH_INDEX. */
21 #define BINARY_PROTOCOL_NO_MATCH (-1)
22 #define BINARY_PROTOCOL_MATCH (-2)
23
24 #define PROTOCOL_ID(method) method ## _id
25 #define PROTOCOL_STRUCT(method) method ## _struct
26 #define CLIENT_PROTOCOL_NAME(method) sgen_client_ ## method
27
28 #ifndef TYPE_INT
29 #define TYPE_INT int
30 #endif
31 #ifndef TYPE_LONGLONG
32 #define TYPE_LONGLONG long long
33 #endif
34 #ifndef TYPE_SIZE
35 #define TYPE_SIZE size_t
36 #endif
37 #ifndef TYPE_POINTER
38 #define TYPE_POINTER gpointer
39 #endif
40 #ifndef TYPE_BOOL
41 #define TYPE_BOOL gboolean
42 #endif
43
44 enum {
45 #define BEGIN_PROTOCOL_ENTRY0(method) PROTOCOL_ID(method),
46 #define BEGIN_PROTOCOL_ENTRY1(method,t1,f1) PROTOCOL_ID(method),
47 #define BEGIN_PROTOCOL_ENTRY2(method,t1,f1,t2,f2) PROTOCOL_ID(method),
48 #define BEGIN_PROTOCOL_ENTRY3(method,t1,f1,t2,f2,t3,f3) PROTOCOL_ID(method),
49 #define BEGIN_PROTOCOL_ENTRY4(method,t1,f1,t2,f2,t3,f3,t4,f4) PROTOCOL_ID(method),
50 #define BEGIN_PROTOCOL_ENTRY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) PROTOCOL_ID(method),
51 #define BEGIN_PROTOCOL_ENTRY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) PROTOCOL_ID(method),
52 #define BEGIN_PROTOCOL_ENTRY_HEAVY0(method) PROTOCOL_ID(method),
53 #define BEGIN_PROTOCOL_ENTRY_HEAVY1(method,t1,f1) PROTOCOL_ID(method),
54 #define BEGIN_PROTOCOL_ENTRY_HEAVY2(method,t1,f1,t2,f2) PROTOCOL_ID(method),
55 #define BEGIN_PROTOCOL_ENTRY_HEAVY3(method,t1,f1,t2,f2,t3,f3) PROTOCOL_ID(method),
56 #define BEGIN_PROTOCOL_ENTRY_HEAVY4(method,t1,f1,t2,f2,t3,f3,t4,f4) PROTOCOL_ID(method),
57 #define BEGIN_PROTOCOL_ENTRY_HEAVY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) PROTOCOL_ID(method),
58 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) PROTOCOL_ID(method),
59
60 #define DEFAULT_PRINT()
61 #define CUSTOM_PRINT(_)
62
63 #define IS_ALWAYS_MATCH(_)
64 #define MATCH_INDEX(_)
65 #define IS_VTABLE_MATCH(_)
66
67 #define END_PROTOCOL_ENTRY
68 #define END_PROTOCOL_ENTRY_FLUSH
69 #define END_PROTOCOL_ENTRY_HEAVY
70
71 #include "sgen-protocol-def.h"
72 };
73
74 /* We pack all protocol structs by default unless specified otherwise */
75 #ifndef PROTOCOL_STRUCT_ATTR
76
77 #define PROTOCOL_PACK_STRUCTS
78
79 #if defined(__GNUC__)
80 #define PROTOCOL_STRUCT_ATTR __attribute__ ((packed))
81 #else
82 #define PROTOCOL_STRUCT_ATTR
83 #endif
84
85 #endif
86
87 #define BEGIN_PROTOCOL_ENTRY0(method)
88 #define BEGIN_PROTOCOL_ENTRY1(method,t1,f1) \
89         typedef struct PROTOCOL_STRUCT_ATTR { \
90                 t1 f1; \
91         } PROTOCOL_STRUCT(method);
92 #define BEGIN_PROTOCOL_ENTRY2(method,t1,f1,t2,f2) \
93         typedef struct PROTOCOL_STRUCT_ATTR { \
94                 t1 f1; \
95                 t2 f2; \
96         } PROTOCOL_STRUCT(method);
97 #define BEGIN_PROTOCOL_ENTRY3(method,t1,f1,t2,f2,t3,f3) \
98         typedef struct PROTOCOL_STRUCT_ATTR { \
99                 t1 f1; \
100                 t2 f2; \
101                 t3 f3; \
102         } PROTOCOL_STRUCT(method);
103 #define BEGIN_PROTOCOL_ENTRY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
104         typedef struct PROTOCOL_STRUCT_ATTR { \
105                 t1 f1; \
106                 t2 f2; \
107                 t3 f3; \
108                 t4 f4; \
109         } PROTOCOL_STRUCT(method);
110 #define BEGIN_PROTOCOL_ENTRY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
111         typedef struct PROTOCOL_STRUCT_ATTR { \
112                 t1 f1; \
113                 t2 f2; \
114                 t3 f3; \
115                 t4 f4; \
116                 t5 f5; \
117         } PROTOCOL_STRUCT(method);
118 #define BEGIN_PROTOCOL_ENTRY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
119         typedef struct PROTOCOL_STRUCT_ATTR { \
120                 t1 f1; \
121                 t2 f2; \
122                 t3 f3; \
123                 t4 f4; \
124                 t5 f5; \
125                 t6 f6; \
126         } PROTOCOL_STRUCT(method);
127
128 #define BEGIN_PROTOCOL_ENTRY_HEAVY0(method) \
129         BEGIN_PROTOCOL_ENTRY0 (method)
130 #define BEGIN_PROTOCOL_ENTRY_HEAVY1(method,t1,f1) \
131         BEGIN_PROTOCOL_ENTRY1 (method,t1,f1)
132 #define BEGIN_PROTOCOL_ENTRY_HEAVY2(method,t1,f1,t2,f2) \
133         BEGIN_PROTOCOL_ENTRY2 (method,t1,f1,t2,f2)
134 #define BEGIN_PROTOCOL_ENTRY_HEAVY3(method,t1,f1,t2,f2,t3,f3) \
135         BEGIN_PROTOCOL_ENTRY3 (method,t1,f1,t2,f2,t3,f3)
136 #define BEGIN_PROTOCOL_ENTRY_HEAVY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
137         BEGIN_PROTOCOL_ENTRY4 (method,t1,f1,t2,f2,t3,f3,t4,f4)
138 #define BEGIN_PROTOCOL_ENTRY_HEAVY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
139         BEGIN_PROTOCOL_ENTRY5 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5)
140 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
141         BEGIN_PROTOCOL_ENTRY6 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6)
142
143 #define DEFAULT_PRINT()
144 #define CUSTOM_PRINT(_)
145
146 #define IS_ALWAYS_MATCH(_)
147 #define MATCH_INDEX(_)
148 #define IS_VTABLE_MATCH(_)
149
150 #define END_PROTOCOL_ENTRY
151 #define END_PROTOCOL_ENTRY_FLUSH
152 #define END_PROTOCOL_ENTRY_HEAVY
153
154 #if defined(_MSC_VER) && defined(PROTOCOL_PACK_STRUCTS)
155 #pragma pack(push)
156 #pragma pack(1)
157 #endif
158 #include "sgen-protocol-def.h"
159 #if defined(_MSC_VER) && defined(PROTOCOL_PACK_STRUCTS)
160 #pragma pack(pop)
161 #undef PROTOCOL_PACK_STRUCTS
162 #endif
163
164 /* missing: finalizers, roots, non-store wbarriers */
165
166 void binary_protocol_init (const char *filename, long long limit);
167 gboolean binary_protocol_is_enabled (void);
168
169 gboolean binary_protocol_flush_buffers (gboolean force);
170
171 #define BEGIN_PROTOCOL_ENTRY0(method) \
172         void method (void);
173 #define BEGIN_PROTOCOL_ENTRY1(method,t1,f1) \
174         void method (t1 f1);
175 #define BEGIN_PROTOCOL_ENTRY2(method,t1,f1,t2,f2) \
176         void method (t1 f1, t2 f2);
177 #define BEGIN_PROTOCOL_ENTRY3(method,t1,f1,t2,f2,t3,f3) \
178         void method (t1 f1, t2 f2, t3 f3);
179 #define BEGIN_PROTOCOL_ENTRY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
180         void method (t1 f1, t2 f2, t3 f3, t4 f4);
181 #define BEGIN_PROTOCOL_ENTRY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
182         void method (t1 f1, t2 f2, t3 f3, t4 f4, t5 f5);
183 #define BEGIN_PROTOCOL_ENTRY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
184         void method (t1 f1, t2 f2, t3 f3, t4 f4, t5 f5, t6 f6);
185
186 #ifdef SGEN_HEAVY_BINARY_PROTOCOL
187 #define binary_protocol_is_heavy_enabled()      binary_protocol_is_enabled ()
188
189 #define BEGIN_PROTOCOL_ENTRY_HEAVY0(method) \
190         BEGIN_PROTOCOL_ENTRY0 (method)
191 #define BEGIN_PROTOCOL_ENTRY_HEAVY1(method,t1,f1) \
192         BEGIN_PROTOCOL_ENTRY1 (method,t1,f1)
193 #define BEGIN_PROTOCOL_ENTRY_HEAVY2(method,t1,f1,t2,f2) \
194         BEGIN_PROTOCOL_ENTRY2 (method,t1,f1,t2,f2)
195 #define BEGIN_PROTOCOL_ENTRY_HEAVY3(method,t1,f1,t2,f2,t3,f3) \
196         BEGIN_PROTOCOL_ENTRY3 (method,t1,f1,t2,f2,t3,f3)
197 #define BEGIN_PROTOCOL_ENTRY_HEAVY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
198         BEGIN_PROTOCOL_ENTRY4 (method,t1,f1,t2,f2,t3,f3,t4,f4)
199 #define BEGIN_PROTOCOL_ENTRY_HEAVY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
200         BEGIN_PROTOCOL_ENTRY5 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5)
201 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
202         BEGIN_PROTOCOL_ENTRY6 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6)
203 #else
204 #define binary_protocol_is_heavy_enabled()      FALSE
205
206 #define BEGIN_PROTOCOL_ENTRY_HEAVY0(method) \
207         static inline void method (void) {}
208 #define BEGIN_PROTOCOL_ENTRY_HEAVY1(method,t1,f1) \
209         static inline void method (t1 f1) {}
210 #define BEGIN_PROTOCOL_ENTRY_HEAVY2(method,t1,f1,t2,f2) \
211         static inline void method (t1 f1, t2 f2) {}
212 #define BEGIN_PROTOCOL_ENTRY_HEAVY3(method,t1,f1,t2,f2,t3,f3) \
213         static inline void method (t1 f1, t2 f2, t3 f3) {}
214 #define BEGIN_PROTOCOL_ENTRY_HEAVY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
215         static inline void method (t1 f1, t2 f2, t3 f3, t4 f4) {}
216 #define BEGIN_PROTOCOL_ENTRY_HEAVY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
217         static inline void method (t1 f1, t2 f2, t3 f3, t4 f4, t5 f5) {}
218 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
219         static inline void method (t1 f1, t2 f2, t3 f3, t4 f4, t5 f5, t6 f6) {}
220 #endif
221
222 #define DEFAULT_PRINT()
223 #define CUSTOM_PRINT(_)
224
225 #define IS_ALWAYS_MATCH(_)
226 #define MATCH_INDEX(_)
227 #define IS_VTABLE_MATCH(_)
228
229 #define END_PROTOCOL_ENTRY
230 #define END_PROTOCOL_ENTRY_FLUSH
231 #define END_PROTOCOL_ENTRY_HEAVY
232
233 #include "sgen-protocol-def.h"
234
235 #undef TYPE_INT
236 #undef TYPE_LONGLONG
237 #undef TYPE_SIZE
238 #undef TYPE_POINTER
239 #undef TYPE_BOOL
240
241 #endif