2 * Copyright 2001-2003 Ximian, Inc
3 * Copyright 2003-2010 Novell, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 #ifdef BINARY_PROTOCOL
26 #include "sgen-protocol.h"
28 /* If not null, dump binary protocol to this file */
29 static FILE *binary_protocol_file
= NULL
;
31 #define BINARY_PROTOCOL_BUFFER_SIZE 65536
33 static unsigned char binary_protocol_buffer
[BINARY_PROTOCOL_BUFFER_SIZE
];
34 static int binary_protocol_buffer_index
= 0;
37 flush_binary_protocol_buffer (void)
39 if (!binary_protocol_file
)
41 if (binary_protocol_buffer_index
== 0)
44 fwrite (binary_protocol_buffer
, 1, binary_protocol_buffer_index
, binary_protocol_file
);
45 fflush (binary_protocol_file
);
47 binary_protocol_buffer_index
= 0;
51 protocol_entry (unsigned char type
, gpointer data
, int size
)
53 if (!binary_protocol_file
)
55 if (binary_protocol_buffer_index
+ 1 + size
> BINARY_PROTOCOL_BUFFER_SIZE
)
56 flush_binary_protocol_buffer ();
58 binary_protocol_buffer
[binary_protocol_buffer_index
++] = type
;
59 memcpy (binary_protocol_buffer
+ binary_protocol_buffer_index
, data
, size
);
60 binary_protocol_buffer_index
+= size
;
62 g_assert (binary_protocol_buffer_index
<= BINARY_PROTOCOL_BUFFER_SIZE
);
66 binary_protocol_collection (int generation
)
68 SGenProtocolCollection entry
= { generation
};
69 flush_binary_protocol_buffer ();
70 protocol_entry (SGEN_PROTOCOL_COLLECTION
, &entry
, sizeof (SGenProtocolCollection
));
74 binary_protocol_alloc (gpointer obj
, gpointer vtable
, int size
)
76 SGenProtocolAlloc entry
= { obj
, vtable
, size
};
77 protocol_entry (SGEN_PROTOCOL_ALLOC
, &entry
, sizeof (SGenProtocolAlloc
));
81 binary_protocol_copy (gpointer from
, gpointer to
, gpointer vtable
, int size
)
83 SGenProtocolCopy entry
= { from
, to
, vtable
, size
};
84 protocol_entry (SGEN_PROTOCOL_COPY
, &entry
, sizeof (SGenProtocolCopy
));
88 binary_protocol_pin (gpointer obj
, gpointer vtable
, int size
)
90 SGenProtocolPin entry
= { obj
, vtable
, size
};
91 protocol_entry (SGEN_PROTOCOL_PIN
, &entry
, sizeof (SGenProtocolPin
));
95 binary_protocol_wbarrier (gpointer ptr
, gpointer value
, gpointer value_vtable
)
97 SGenProtocolWBarrier entry
= { ptr
, value
, value_vtable
};
98 protocol_entry (SGEN_PROTOCOL_WBARRIER
, &entry
, sizeof (SGenProtocolWBarrier
));
102 binary_protocol_global_remset (gpointer ptr
, gpointer value
, gpointer value_vtable
)
104 SGenProtocolGlobalRemset entry
= { ptr
, value
, value_vtable
};
105 protocol_entry (SGEN_PROTOCOL_GLOBAL_REMSET
, &entry
, sizeof (SGenProtocolGlobalRemset
));
109 binary_protocol_ptr_update (gpointer ptr
, gpointer old_value
, gpointer new_value
, gpointer vtable
, int size
)
111 SGenProtocolPtrUpdate entry
= { ptr
, old_value
, new_value
, vtable
, size
};
112 protocol_entry (SGEN_PROTOCOL_PTR_UPDATE
, &entry
, sizeof (SGenProtocolPtrUpdate
));
116 binary_protocol_cleanup (gpointer ptr
, gpointer vtable
, int size
)
118 SGenProtocolCleanup entry
= { ptr
, vtable
, size
};
119 protocol_entry (SGEN_PROTOCOL_CLEANUP
, &entry
, sizeof (SGenProtocolCleanup
));
123 binary_protocol_empty (gpointer start
, int size
)
125 SGenProtocolEmpty entry
= { start
, size
};
126 protocol_entry (SGEN_PROTOCOL_EMPTY
, &entry
, sizeof (SGenProtocolEmpty
));
130 binary_protocol_thread_restart (gpointer thread
)
132 SGenProtocolThreadRestart entry
= { thread
};
133 protocol_entry (SGEN_PROTOCOL_THREAD_RESTART
, &entry
, sizeof (SGenProtocolThreadRestart
));
138 binary_protocol_thread_register (gpointer thread
)
140 SGenProtocolThreadRegister entry
= { thread
};
141 protocol_entry (SGEN_PROTOCOL_THREAD_REGISTER
, &entry
, sizeof (SGenProtocolThreadRegister
));
146 binary_protocol_thread_unregister (gpointer thread
)
148 SGenProtocolThreadUnregister entry
= { thread
};
149 protocol_entry (SGEN_PROTOCOL_THREAD_UNREGISTER
, &entry
, sizeof (SGenProtocolThreadUnregister
));
154 binary_protocol_missing_remset (gpointer obj
, gpointer obj_vtable
, int offset
, gpointer value
, gpointer value_vtable
, int value_pinned
)
156 SGenProtocolMissingRemset entry
= { obj
, obj_vtable
, offset
, value
, value_vtable
, value_pinned
};
157 protocol_entry (SGEN_PROTOCOL_MISSING_REMSET
, &entry
, sizeof (SGenProtocolMissingRemset
));
163 #define binary_protocol_collection(generation)
164 #define binary_protocol_alloc(obj, vtable, size)
165 #define binary_protocol_copy(from, to, vtable, size)
166 #define binary_protocol_pin(obj, vtable, size)
167 #define binary_protocol_wbarrier(ptr, value, value_vtable)
168 #define binary_protocol_global_remset(ptr, value, value_vtable)
169 #define binary_protocol_ptr_update(ptr, old_value, new_value, vtable, size)
170 #define binary_protocol_cleanup(ptr, vtable, size)
171 #define binary_protocol_empty(start, size)
172 #define binary_protocol_thread_restart(thread)
173 #define binary_protocol_thread_register(thread)
174 #define binary_protocol_thread_unregister(thread)
175 #define binary_protocol_missing_remset(obj, obj_vtable, offset, value, value_vtable, value_pinned)