c6966412907f2618d0d97ba365af024dae0897a0
[mono.git] / mono / metadata / sgen-protocol.c
1 #ifdef BINARY_PROTOCOL
2
3 #include "sgen-protocol.h"
4
5 /* If not null, dump binary protocol to this file */
6 static FILE *binary_protocol_file = NULL;
7
8 #define BINARY_PROTOCOL_BUFFER_SIZE     65536
9
10 static unsigned char binary_protocol_buffer [BINARY_PROTOCOL_BUFFER_SIZE];
11 static int binary_protocol_buffer_index = 0;
12
13 static void
14 flush_binary_protocol_buffer (void)
15 {
16         if (!binary_protocol_file)
17                 return;
18         if (binary_protocol_buffer_index == 0)
19                 return;
20
21         fwrite (binary_protocol_buffer, 1, binary_protocol_buffer_index, binary_protocol_file);
22         fflush (binary_protocol_file);
23
24         binary_protocol_buffer_index = 0;
25 }
26
27 static void
28 protocol_entry (unsigned char type, gpointer data, int size)
29 {
30         if (!binary_protocol_file)
31                 return;
32         if (binary_protocol_buffer_index + 1 + size > BINARY_PROTOCOL_BUFFER_SIZE)
33                 flush_binary_protocol_buffer ();
34
35         binary_protocol_buffer [binary_protocol_buffer_index++] = type;
36         memcpy (binary_protocol_buffer + binary_protocol_buffer_index, data, size);
37         binary_protocol_buffer_index += size;
38
39         g_assert (binary_protocol_buffer_index <= BINARY_PROTOCOL_BUFFER_SIZE);
40 }
41
42 static void
43 binary_protocol_collection (int generation)
44 {
45         SGenProtocolCollection entry = { generation };
46         flush_binary_protocol_buffer ();
47         protocol_entry (SGEN_PROTOCOL_COLLECTION, &entry, sizeof (SGenProtocolCollection));
48 }
49
50 static void
51 binary_protocol_alloc (gpointer obj, gpointer vtable, int size)
52 {
53         SGenProtocolAlloc entry = { obj, vtable, size };
54         protocol_entry (SGEN_PROTOCOL_ALLOC, &entry, sizeof (SGenProtocolAlloc));
55 }
56
57 static void
58 binary_protocol_copy (gpointer from, gpointer to, gpointer vtable, int size)
59 {
60         SGenProtocolCopy entry = { from, to, vtable, size };
61         protocol_entry (SGEN_PROTOCOL_COPY, &entry, sizeof (SGenProtocolCopy));
62 }
63
64 static void
65 binary_protocol_pin (gpointer obj, gpointer vtable, int size)
66 {
67         SGenProtocolPin entry = { obj, vtable, size };
68         protocol_entry (SGEN_PROTOCOL_PIN, &entry, sizeof (SGenProtocolPin));
69 }
70
71 static void
72 binary_protocol_wbarrier (gpointer ptr, gpointer value, gpointer value_vtable)
73 {
74         SGenProtocolWBarrier entry = { ptr, value, value_vtable };
75         protocol_entry (SGEN_PROTOCOL_WBARRIER, &entry, sizeof (SGenProtocolWBarrier));
76 }
77
78 static void
79 binary_protocol_global_remset (gpointer ptr, gpointer value, gpointer value_vtable)
80 {
81         SGenProtocolGlobalRemset entry = { ptr, value, value_vtable };
82         protocol_entry (SGEN_PROTOCOL_GLOBAL_REMSET, &entry, sizeof (SGenProtocolGlobalRemset));
83 }
84
85 static void
86 binary_protocol_ptr_update (gpointer ptr, gpointer old_value, gpointer new_value, gpointer vtable, int size)
87 {
88         SGenProtocolPtrUpdate entry = { ptr, old_value, new_value, vtable, size };
89         protocol_entry (SGEN_PROTOCOL_PTR_UPDATE, &entry, sizeof (SGenProtocolPtrUpdate));
90 }
91
92 static void
93 binary_protocol_cleanup (gpointer ptr, gpointer vtable, int size)
94 {
95         SGenProtocolCleanup entry = { ptr, vtable, size };
96         protocol_entry (SGEN_PROTOCOL_CLEANUP, &entry, sizeof (SGenProtocolCleanup));
97 }
98
99 static void
100 binary_protocol_empty (gpointer start, int size)
101 {
102         SGenProtocolEmpty entry = { start, size };
103         protocol_entry (SGEN_PROTOCOL_EMPTY, &entry, sizeof (SGenProtocolEmpty));
104 }
105
106 static void
107 binary_protocol_thread_restart (gpointer thread)
108 {
109         SGenProtocolThreadRestart entry = { thread };
110         protocol_entry (SGEN_PROTOCOL_THREAD_RESTART, &entry, sizeof (SGenProtocolThreadRestart));
111
112 }
113
114 static void
115 binary_protocol_thread_register (gpointer thread)
116 {
117         SGenProtocolThreadRegister entry = { thread };
118         protocol_entry (SGEN_PROTOCOL_THREAD_REGISTER, &entry, sizeof (SGenProtocolThreadRegister));
119
120 }
121
122 static void
123 binary_protocol_thread_unregister (gpointer thread)
124 {
125         SGenProtocolThreadUnregister entry = { thread };
126         protocol_entry (SGEN_PROTOCOL_THREAD_UNREGISTER, &entry, sizeof (SGenProtocolThreadUnregister));
127
128 }
129
130 static void
131 binary_protocol_missing_remset (gpointer obj, gpointer obj_vtable, int offset, gpointer value, gpointer value_vtable, int value_pinned)
132 {
133         SGenProtocolMissingRemset entry = { obj, obj_vtable, offset, value, value_vtable, value_pinned };
134         protocol_entry (SGEN_PROTOCOL_MISSING_REMSET, &entry, sizeof (SGenProtocolMissingRemset));
135
136 }
137
138 #else
139
140 #define binary_protocol_collection(generation)
141 #define binary_protocol_alloc(obj, vtable, size)
142 #define binary_protocol_copy(from, to, vtable, size)
143 #define binary_protocol_pin(obj, vtable, size)
144 #define binary_protocol_wbarrier(ptr, value, value_vtable)
145 #define binary_protocol_global_remset(ptr, value, value_vtable)
146 #define binary_protocol_ptr_update(ptr, old_value, new_value, vtable, size)
147 #define binary_protocol_cleanup(ptr, vtable, size)
148 #define binary_protocol_empty(start, size)
149 #define binary_protocol_thread_restart(thread)
150 #define binary_protocol_thread_register(thread)
151 #define binary_protocol_thread_unregister(thread)
152 #define binary_protocol_missing_remset(obj, obj_vtable, offset, value, value_vtable, value_pinned)
153
154 #endif