220418e8167deea8101378669fffc325ee38be66
[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  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License 2.0 as published by the Free Software Foundation;
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License 2.0 along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */
22
23 #ifndef __MONO_SGENPROTOCOL_H__
24 #define __MONO_SGENPROTOCOL_H__
25
26 #include "sgen-gc.h"
27
28 /* Special indices returned by MATCH_INDEX. */
29 #define BINARY_PROTOCOL_NO_MATCH (-1)
30 #define BINARY_PROTOCOL_MATCH (-2)
31
32 #define PROTOCOL_ID(method) method ## _id
33 #define PROTOCOL_STRUCT(method) method ## _struct
34 #define CLIENT_PROTOCOL_NAME(method) sgen_client_ ## method
35
36 #define TYPE_INT int
37 #define TYPE_LONGLONG long long
38 #define TYPE_SIZE size_t
39 #define TYPE_POINTER gpointer
40 #define TYPE_BOOL gboolean
41
42 enum {
43 #define BEGIN_PROTOCOL_ENTRY0(method) PROTOCOL_ID(method),
44 #define BEGIN_PROTOCOL_ENTRY1(method,t1,f1) PROTOCOL_ID(method),
45 #define BEGIN_PROTOCOL_ENTRY2(method,t1,f1,t2,f2) PROTOCOL_ID(method),
46 #define BEGIN_PROTOCOL_ENTRY3(method,t1,f1,t2,f2,t3,f3) PROTOCOL_ID(method),
47 #define BEGIN_PROTOCOL_ENTRY4(method,t1,f1,t2,f2,t3,f3,t4,f4) PROTOCOL_ID(method),
48 #define BEGIN_PROTOCOL_ENTRY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) PROTOCOL_ID(method),
49 #define BEGIN_PROTOCOL_ENTRY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) PROTOCOL_ID(method),
50 #define BEGIN_PROTOCOL_ENTRY_HEAVY0(method) PROTOCOL_ID(method),
51 #define BEGIN_PROTOCOL_ENTRY_HEAVY1(method,t1,f1) PROTOCOL_ID(method),
52 #define BEGIN_PROTOCOL_ENTRY_HEAVY2(method,t1,f1,t2,f2) PROTOCOL_ID(method),
53 #define BEGIN_PROTOCOL_ENTRY_HEAVY3(method,t1,f1,t2,f2,t3,f3) PROTOCOL_ID(method),
54 #define BEGIN_PROTOCOL_ENTRY_HEAVY4(method,t1,f1,t2,f2,t3,f3,t4,f4) PROTOCOL_ID(method),
55 #define BEGIN_PROTOCOL_ENTRY_HEAVY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) PROTOCOL_ID(method),
56 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) PROTOCOL_ID(method),
57
58 #define DEFAULT_PRINT()
59 #define CUSTOM_PRINT(_)
60
61 #define IS_ALWAYS_MATCH(_)
62 #define MATCH_INDEX(_)
63 #define IS_VTABLE_MATCH(_)
64
65 #define END_PROTOCOL_ENTRY
66 #define END_PROTOCOL_ENTRY_FLUSH
67 #define END_PROTOCOL_ENTRY_HEAVY
68
69 #include "sgen-protocol-def.h"
70 };
71
72 #define BEGIN_PROTOCOL_ENTRY0(method)
73 #define BEGIN_PROTOCOL_ENTRY1(method,t1,f1) \
74         typedef struct { \
75                 t1 f1; \
76         } PROTOCOL_STRUCT(method);
77 #define BEGIN_PROTOCOL_ENTRY2(method,t1,f1,t2,f2) \
78         typedef struct { \
79                 t1 f1; \
80                 t2 f2; \
81         } PROTOCOL_STRUCT(method);
82 #define BEGIN_PROTOCOL_ENTRY3(method,t1,f1,t2,f2,t3,f3) \
83         typedef struct { \
84                 t1 f1; \
85                 t2 f2; \
86                 t3 f3; \
87         } PROTOCOL_STRUCT(method);
88 #define BEGIN_PROTOCOL_ENTRY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
89         typedef struct { \
90                 t1 f1; \
91                 t2 f2; \
92                 t3 f3; \
93                 t4 f4; \
94         } PROTOCOL_STRUCT(method);
95 #define BEGIN_PROTOCOL_ENTRY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
96         typedef struct { \
97                 t1 f1; \
98                 t2 f2; \
99                 t3 f3; \
100                 t4 f4; \
101                 t5 f5; \
102         } PROTOCOL_STRUCT(method);
103 #define BEGIN_PROTOCOL_ENTRY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
104         typedef struct { \
105                 t1 f1; \
106                 t2 f2; \
107                 t3 f3; \
108                 t4 f4; \
109                 t5 f5; \
110                 t6 f6; \
111         } PROTOCOL_STRUCT(method);
112
113 #define BEGIN_PROTOCOL_ENTRY_HEAVY0(method) \
114         BEGIN_PROTOCOL_ENTRY0 (method)
115 #define BEGIN_PROTOCOL_ENTRY_HEAVY1(method,t1,f1) \
116         BEGIN_PROTOCOL_ENTRY1 (method,t1,f1)
117 #define BEGIN_PROTOCOL_ENTRY_HEAVY2(method,t1,f1,t2,f2) \
118         BEGIN_PROTOCOL_ENTRY2 (method,t1,f1,t2,f2)
119 #define BEGIN_PROTOCOL_ENTRY_HEAVY3(method,t1,f1,t2,f2,t3,f3) \
120         BEGIN_PROTOCOL_ENTRY3 (method,t1,f1,t2,f2,t3,f3)
121 #define BEGIN_PROTOCOL_ENTRY_HEAVY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
122         BEGIN_PROTOCOL_ENTRY4 (method,t1,f1,t2,f2,t3,f3,t4,f4)
123 #define BEGIN_PROTOCOL_ENTRY_HEAVY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
124         BEGIN_PROTOCOL_ENTRY5 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5)
125 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
126         BEGIN_PROTOCOL_ENTRY6 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6)
127
128 #define DEFAULT_PRINT()
129 #define CUSTOM_PRINT(_)
130
131 #define IS_ALWAYS_MATCH(_)
132 #define MATCH_INDEX(_)
133 #define IS_VTABLE_MATCH(_)
134
135 #define END_PROTOCOL_ENTRY
136 #define END_PROTOCOL_ENTRY_FLUSH
137 #define END_PROTOCOL_ENTRY_HEAVY
138
139 #include "sgen-protocol-def.h"
140
141 /* missing: finalizers, roots, non-store wbarriers */
142
143 void binary_protocol_init (const char *filename, long long limit);
144 gboolean binary_protocol_is_enabled (void);
145
146 void binary_protocol_flush_buffers (gboolean force);
147
148 #define BEGIN_PROTOCOL_ENTRY0(method) \
149         void method (void);
150 #define BEGIN_PROTOCOL_ENTRY1(method,t1,f1) \
151         void method (t1 f1);
152 #define BEGIN_PROTOCOL_ENTRY2(method,t1,f1,t2,f2) \
153         void method (t1 f1, t2 f2);
154 #define BEGIN_PROTOCOL_ENTRY3(method,t1,f1,t2,f2,t3,f3) \
155         void method (t1 f1, t2 f2, t3 f3);
156 #define BEGIN_PROTOCOL_ENTRY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
157         void method (t1 f1, t2 f2, t3 f3, t4 f4);
158 #define BEGIN_PROTOCOL_ENTRY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
159         void method (t1 f1, t2 f2, t3 f3, t4 f4, t5 f5);
160 #define BEGIN_PROTOCOL_ENTRY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
161         void method (t1 f1, t2 f2, t3 f3, t4 f4, t5 f5, t6 f6);
162
163 #ifdef SGEN_HEAVY_BINARY_PROTOCOL
164 #define binary_protocol_is_heavy_enabled()      binary_protocol_is_enabled ()
165
166 #define BEGIN_PROTOCOL_ENTRY_HEAVY0(method) \
167         BEGIN_PROTOCOL_ENTRY0 (method)
168 #define BEGIN_PROTOCOL_ENTRY_HEAVY1(method,t1,f1) \
169         BEGIN_PROTOCOL_ENTRY1 (method,t1,f1)
170 #define BEGIN_PROTOCOL_ENTRY_HEAVY2(method,t1,f1,t2,f2) \
171         BEGIN_PROTOCOL_ENTRY2 (method,t1,f1,t2,f2)
172 #define BEGIN_PROTOCOL_ENTRY_HEAVY3(method,t1,f1,t2,f2,t3,f3) \
173         BEGIN_PROTOCOL_ENTRY3 (method,t1,f1,t2,f2,t3,f3)
174 #define BEGIN_PROTOCOL_ENTRY_HEAVY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
175         BEGIN_PROTOCOL_ENTRY4 (method,t1,f1,t2,f2,t3,f3,t4,f4)
176 #define BEGIN_PROTOCOL_ENTRY_HEAVY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
177         BEGIN_PROTOCOL_ENTRY5 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5)
178 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
179         BEGIN_PROTOCOL_ENTRY6 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6)
180 #else
181 #define binary_protocol_is_heavy_enabled()      FALSE
182
183 #define BEGIN_PROTOCOL_ENTRY_HEAVY0(method) \
184         static inline void method (void) {}
185 #define BEGIN_PROTOCOL_ENTRY_HEAVY1(method,t1,f1) \
186         static inline void method (t1 f1) {}
187 #define BEGIN_PROTOCOL_ENTRY_HEAVY2(method,t1,f1,t2,f2) \
188         static inline void method (t1 f1, t2 f2) {}
189 #define BEGIN_PROTOCOL_ENTRY_HEAVY3(method,t1,f1,t2,f2,t3,f3) \
190         static inline void method (t1 f1, t2 f2, t3 f3) {}
191 #define BEGIN_PROTOCOL_ENTRY_HEAVY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
192         static inline void method (t1 f1, t2 f2, t3 f3, t4 f4) {}
193 #define BEGIN_PROTOCOL_ENTRY_HEAVY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
194         static inline void method (t1 f1, t2 f2, t3 f3, t4 f4, t5 f5) {}
195 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
196         static inline void method (t1 f1, t2 f2, t3 f3, t4 f4, t5 f5, t6 f6) {}
197 #endif
198
199 #define DEFAULT_PRINT()
200 #define CUSTOM_PRINT(_)
201
202 #define IS_ALWAYS_MATCH(_)
203 #define MATCH_INDEX(_)
204 #define IS_VTABLE_MATCH(_)
205
206 #define END_PROTOCOL_ENTRY
207 #define END_PROTOCOL_ENTRY_FLUSH
208 #define END_PROTOCOL_ENTRY_HEAVY
209
210 #include "sgen-protocol-def.h"
211
212 #undef TYPE_INT
213 #undef TYPE_LONGLONG
214 #undef TYPE_SIZE
215 #undef TYPE_POINTER
216 #undef TYPE_BOOL
217
218 #endif