86 #include "replicode_defs.h"
94 #ifdef WITH_DETAIL_OID
96 static uint64 last_SysView_detail_oid = 1000;
99 #ifdef WITH_DETAIL_OID
100 detail_oid_ = ++last_SysView_detail_oid;
101 if (detail_oid_ == 0)
102 int set_breakpoint_here = 1;
106 SysView::SysView(_View *source) {
108 #ifdef WITH_DETAIL_OID
109 detail_oid_ = ++last_SysView_detail_oid;
110 if (detail_oid_ == 0)
111 int set_breakpoint_here = 1;
113 for (uint32 i = 0; i < VIEW_CODE_MAX_SIZE; ++i)
114 code_[i] = source->code(i);
116 for (uint32 i = 0; i < 2; ++i)
117 if (source->references_[i])
118 references_.push_back(0);
121 void SysView::write(word32 *data) {
123 data[0] = code_.size();
124 data[1] = references_.size();
126 for (; i < code_.size(); ++i)
127 data[2 + i] = code_[i].atom_;
128 for (uint32 j = 0; j < references_.size(); ++j)
129 data[2 + i + j] = references_[j];
132 void SysView::read(word32 *data) {
134 uint32 code_size = data[0];
135 uint32 reference_set_size = data[1];
138 for (i = 0; i < code_size; ++i)
139 code_.push_back(Atom(data[2 + i]));
140 for (j = 0; j < reference_set_size; ++j)
141 references_.push_back(data[2 + i + j]);
144 uint32 SysView::get_size()
const {
146 return 2 + code_.size() + references_.size();
149 void SysView::trace(std::ostream& out)
const {
151 out <<
" code size: " << code_.size() << std::endl;
152 out <<
" reference set size: " << references_.size() << std::endl;
153 out <<
"---code---" << std::endl;
154 Atom::TraceContext context;
155 for (uint32 i = 0; i < code_.size(); ++i) {
157 code_[i].trace(context, out);
160 out <<
"---reference set---" << std::endl;
161 for (uint32 i = 0; i < references_.size(); ++i)
162 out << references_[i] << std::endl;
167 uint32 SysObject::lastOID_ = 0;
169 SysObject::SysObject() : oid_(lastOID_++) {
170 #ifdef WITH_DETAIL_OID
175 SysObject::SysObject(Code *source) {
178 for (i = 0; i < source->code_size(); ++i)
179 code_[i] = source->code(i);
181 unordered_set<_View *, _View::Hash, _View::Equal>::const_iterator v;
183 for (i = 0, v = source->views_.begin(); v != source->views_.end(); ++i, ++v)
184 views_[i] =
new SysView(*v);
187 oid_ = source->get_oid();
188 #ifdef WITH_DETAIL_OID
189 detail_oid_ = source->get_detail_oid();
192 for (i = 0; i < source->references_size(); ++i)
193 references_.push_back(0);
196 SysObject::~SysObject() {
198 for (uint32 i = 0; i < views_.size(); ++i)
202 void SysObject::write(word32 *data) {
205 data[1] = code_.size();
206 data[2] = references_.size();
207 data[3] = markers_.size();
208 data[4] = views_.size();
213 for (i = 0; i < code_.size(); ++i)
214 data[5 + i] = code_[i].atom_;
215 for (j = 0; j < references_.size(); ++j)
216 data[5 + i + j] = references_[j];
217 for (k = 0; k < markers_.size(); ++k)
218 data[5 + i + j + k] = markers_[k];
220 for (l = 0; l < views_.size(); ++l) {
222 views_[l]->write(data + 5 + i + j + k + offset);
223 offset += views_[l]->get_size();
227 void SysObject::read(word32 *data) {
230 uint32 code_size = data[1];
231 uint32 reference_set_size = data[2];
232 uint32 marker_set_size = data[3];
233 uint32 view_set_size = data[4];
238 for (i = 0; i < code_size; ++i)
239 code_.push_back(Atom(data[5 + i]));
240 for (j = 0; j < reference_set_size; ++j)
241 references_.push_back(data[5 + i + j]);
242 for (k = 0; k < marker_set_size; ++k)
243 markers_.push_back(data[5 + i + j + k]);
245 for (l = 0; l < view_set_size; ++l) {
247 SysView *v =
new SysView();
248 v->read(data + 5 + i + j + k + offset);
250 offset += v->get_size();
254 uint32 SysObject::get_size() {
256 uint32 view_set_size = 0;
257 for (uint32 i = 0; i < views_.size(); ++i)
258 view_set_size += views_[i]->get_size();
259 return 5 + code_.size() + references_.size() + markers_.size() + view_set_size;
262 void SysObject::trace(std::ostream& out)
const {
264 out <<
"\n---object---\n";
265 out << oid_ << std::endl;
266 out <<
"code size: " << code_.size() << std::endl;
267 out <<
"reference set size: " << references_.size() << std::endl;
268 out <<
"marker set size: " << markers_.size() << std::endl;
269 out <<
"view set size: " << views_.size() << std::endl;
270 out <<
"\n---code---\n";
272 Atom::TraceContext context;
273 for (i = 0; i < code_.size(); ++i) {
276 code_[i].trace(context, out);
279 out <<
"\n---reference set---\n";
280 for (i = 0; i < references_.size(); ++i)
281 out << i <<
" " << references_[i] << std::endl;
282 out <<
"\n---marker set---\n";
283 for (i = 0; i < markers_.size(); ++i)
284 out << i <<
" " << markers_[i] << std::endl;
285 out <<
"\n---view set---\n";
286 for (uint32 k = 0; k < views_.size(); ++k) {
288 out <<
"view[" << k <<
"]" << std::endl;
289 out <<
"reference set size: " << views_[k]->references_.size() << std::endl;
290 out <<
"-code-" << std::endl;
292 for (j = 0; j < views_[k]->code_.size(); ++i, ++j) {
295 views_[k]->code_[j].trace(context, out);
298 out <<
"-reference set-" << std::endl;
299 for (j = 0; j < views_[k]->references_.size(); ++i, ++j)
300 out << j <<
" " << views_[k]->references_[j] << std::endl;
304 void SysObject::trace()
const { trace(std::cout); }
306 void Code::r_trace(ostream& out)
const {
309 if (references_size() < 1)
313 auto obj = get_reference(0);
314 if (obj->code_size() <= 2)
318 switch (obj->code(0).getDescriptor()) {
320 case Atom::COMPOSITE_STATE:
331 Mem *Mem::singleton_ = NULL;