14
14
#include < vector>
15
15
#include < stdint.h>
16
16
17
- #undef DPRINT
18
- #define DPRINT (fmt,...) fprintf(stderr, fmt, ##__VA_ARGS__)
19
-
20
17
// The number of allocations Rust code performs before performing cycle
21
18
// collection.
22
19
#define RUST_CC_FREQUENCY 5000
@@ -122,11 +119,16 @@ class irc : public shape::data<irc,shape::ptr> {
122
119
123
120
// Bump the internal reference count of the box.
124
121
if (ircs.find ((void *)ref_count_dp) == ircs.end ()) {
125
- // DPRINT("setting internal reference count for %p\n",
126
- // (void *)ref_count_dp);
122
+ LOG (task, gc,
123
+ " setting internal reference count for %p to 1" ,
124
+ (void *)ref_count_dp);
127
125
ircs[(void *)ref_count_dp] = 1 ;
128
126
} else {
129
- ++ircs[(void *)ref_count_dp];
127
+ uintptr_t newcount = ircs[(void *)ref_count_dp] + 1 ;
128
+ LOG (task, gc,
129
+ " bumping internal reference count for %p to %lu" ,
130
+ (void *)ref_count_dp, newcount);
131
+ ircs[(void *)ref_count_dp] = newcount;
130
132
}
131
133
132
134
// Do not traverse the contents of this box; it's in the allocation
@@ -176,8 +178,8 @@ irc::compute_ircs(rust_task *task, irc_map &ircs) {
176
178
177
179
const type_desc *tydesc = begin->second ;
178
180
179
- // DPRINT( "determining internal ref counts: %p, tydesc=%p\n ", p,
180
- // tydesc);
181
+ LOG (task, gc, " determining internal ref counts: %p, tydesc=%p" , p,
182
+ tydesc);
181
183
182
184
shape::arena arena;
183
185
shape::type_param *params =
@@ -223,11 +225,12 @@ find_roots(rust_task *task, irc_map &ircs, std::vector<void *> &roots) {
223
225
if (irc < ref_count) {
224
226
// This allocation must be a root, because the internal reference
225
227
// count is smaller than the total reference count.
226
- // DPRINT( "root found: %p, irc %lu, ref count %lu\n", alloc, irc ,
227
- // ref_count);
228
+ LOG (task, gc, " root found: %p, irc %lu, ref count %lu" ,
229
+ alloc, irc, ref_count);
228
230
roots.push_back (alloc);
229
231
} else {
230
- // DPRINT("nonroot found: %p, ref count %lu\n", alloc, ref_count);
232
+ LOG (task, gc, " nonroot found: %p, irc %lu, ref count %lu" ,
233
+ alloc, irc, ref_count);
231
234
/* assert(irc == ref_count && "Internal reference count must be "
232
235
"less than or equal to the total reference count!");*/
233
236
}
@@ -385,7 +388,7 @@ mark::do_mark(rust_task *task, const std::vector<void *> &roots,
385
388
386
389
const type_desc *tydesc = task->local_allocs [alloc];
387
390
388
- // DPRINT( "marking: %p, tydesc=%p\n ", p , tydesc);
391
+ LOG (task, gc, " marking: %p, tydesc=%p" , alloc , tydesc);
389
392
390
393
uint8_t *p = reinterpret_cast <uint8_t *>(alloc);
391
394
shape::arena arena;
@@ -398,7 +401,6 @@ mark::do_mark(rust_task *task, const std::vector<void *> &roots,
398
401
tydesc->shape_tables, p + sizeof(uintptr_t),
399
402
std::cerr);
400
403
log.walk();
401
- DPRINT("\n");
402
404
#endif
403
405
404
406
// We skip over the reference count here.
@@ -419,7 +421,7 @@ sweep(rust_task *task, const std::set<void *> &marked) {
419
421
while (begin != end) {
420
422
void *alloc = begin->first ;
421
423
if (marked.find (alloc) == marked.end ()) {
422
- // DPRINT( "object is part of a cycle: %p\n ", alloc);
424
+ LOG (task, gc, " object is part of a cycle: %p" , alloc);
423
425
424
426
// FIXME: Run the destructor, *if* it's a resource.
425
427
@@ -432,8 +434,8 @@ sweep(rust_task *task, const std::set<void *> &marked) {
432
434
433
435
void
434
436
do_cc (rust_task *task) {
435
- // DPRINT( "cc; n allocs = %lu\n ",
436
- // (long unsigned int)task->local_allocs.size());
437
+ LOG (task, gc, " cc; n allocs = %lu" ,
438
+ (long unsigned int )task->local_allocs .size ());
437
439
438
440
irc_map ircs;
439
441
irc::compute_ircs (task, ircs);
0 commit comments