20
20
21
21
using namespace std ;
22
22
23
+ void
24
+ annihilate_box (rust_task *task, rust_opaque_box *box);
25
+
23
26
namespace cc {
24
27
25
28
// Internal reference count computation
@@ -448,203 +451,17 @@ mark::do_mark(rust_task *task,
448
451
}
449
452
}
450
453
451
- class sweep : public shape ::data<sweep,shape::ptr> {
452
- friend class shape ::data<sweep,shape::ptr>;
453
-
454
- sweep (const sweep &other, const shape::ptr &in_dp)
455
- : shape::data<sweep,shape::ptr>(other.task, other.align,
456
- other.sp, other.params,
457
- other.tables, in_dp) {}
458
-
459
- sweep (const sweep &other,
460
- const uint8_t *in_sp,
461
- const shape::type_param *in_params,
462
- const rust_shape_tables *in_tables = NULL )
463
- : shape::data<sweep,shape::ptr>(other.task,
464
- other.align,
465
- in_sp,
466
- in_params,
467
- in_tables ? in_tables : other.tables,
468
- other.dp) {}
469
-
470
- sweep (const sweep &other,
471
- const uint8_t *in_sp,
472
- const shape::type_param *in_params,
473
- const rust_shape_tables *in_tables,
474
- shape::ptr in_dp)
475
- : shape::data<sweep,shape::ptr>(other.task,
476
- other.align,
477
- in_sp,
478
- in_params,
479
- in_tables,
480
- in_dp) {}
481
-
482
- sweep (rust_task *in_task,
483
- bool in_align,
484
- const uint8_t *in_sp,
485
- const shape::type_param *in_params,
486
- const rust_shape_tables *in_tables,
487
- uint8_t *in_data)
488
- : shape::data<sweep,shape::ptr>(in_task, in_align, in_sp,
489
- in_params, in_tables, in_data) {}
490
-
491
- void walk_vec2 (bool is_pod, uint16_t sp_size) {
492
- void *vec = shape::get_dp<void *>(dp);
493
- walk_vec2 (is_pod, get_vec_data_range (dp));
494
- task->kernel ->free (vec);
495
- }
496
-
497
- void walk_vec2 (bool is_pod,
498
- const std::pair<shape::ptr,shape::ptr> &data_range) {
499
- sweep sub (*this , data_range.first );
500
- shape::ptr data_end = sub.end_dp = data_range.second ;
501
- while (sub.dp < data_end) {
502
- sub.walk_reset ();
503
- sub.align = true ;
504
- }
505
- }
506
-
507
- void walk_tag2 (shape::tag_info &tinfo, uint32_t tag_variant) {
508
- shape::data<sweep,shape::ptr>::walk_variant1 (tinfo, tag_variant);
509
- }
510
-
511
- void walk_uniq2 () {
512
- void *x = *((void **)dp);
513
- // free contents first:
514
- shape::data<sweep,shape::ptr>::walk_uniq_contents1 ();
515
- // now free the ptr:
516
- task->kernel ->free (x);
517
- }
518
-
519
- void walk_box2 () {
520
- // In sweep phase, do not walk the box contents. There is an
521
- // outer loop walking all remaining boxes, and this box may well
522
- // have been freed already!
523
- }
524
-
525
- void walk_fn2 (char code) {
526
- switch (code) {
527
- case shape::SHAPE_UNIQ_FN: {
528
- fn_env_pair pair = *(fn_env_pair*)dp;
529
-
530
- if (pair.env ) {
531
- // free closed over data:
532
- shape::data<sweep,shape::ptr>::walk_fn_contents1 ();
533
-
534
- // now free the ptr:
535
- task->kernel ->free (pair.env );
536
- }
537
- break ;
538
- }
539
- case shape::SHAPE_BOX_FN: {
540
- // the box will be visited separately:
541
- shape::bump_dp<void *>(dp); // skip over the code ptr
542
- walk_box2 (); // walk over the environment ptr
543
- break ;
544
- }
545
- case shape::SHAPE_BARE_FN: // Does not close over data.
546
- case shape::SHAPE_STACK_FN: break ; // Not reachable from heap.
547
- default : abort ();
548
- }
549
- }
550
-
551
- void walk_obj2 () {
552
- return ;
553
- }
554
-
555
- void walk_iface2 () {
556
- walk_box2 ();
557
- }
558
-
559
- void walk_tydesc2 (char kind) {
560
- switch (kind) {
561
- case shape::SHAPE_TYDESC:
562
- case shape::SHAPE_SEND_TYDESC:
563
- break ;
564
- default : abort ();
565
- }
566
- }
567
-
568
- struct run_dtor_args {
569
- const shape::rust_fn *dtor;
570
- void *data;
571
- };
572
-
573
- typedef void (*dtor)(void **retptr, void *env, void *dptr);
574
-
575
- static void run_dtor (run_dtor_args *args) {
576
- dtor f = (dtor)args->dtor ;
577
- f (NULL , args->dtor ->env , args->data );
578
- }
579
-
580
- void walk_res2 (const shape::rust_fn *dtor, unsigned n_params,
581
- const shape::type_param *params, const uint8_t *end_sp,
582
- bool live) {
583
- void *data = (void *)(uintptr_t )dp;
584
- // Switch back to the Rust stack to run the destructor
585
- run_dtor_args args = {dtor, data};
586
- task->call_on_rust_stack ((void *)&args, (void *)run_dtor);
587
-
588
- while (this ->sp != end_sp) {
589
- this ->walk ();
590
- align = true ;
591
- }
592
- }
593
-
594
- void walk_subcontext2 (sweep &sub) { sub.walk (); }
595
-
596
- void walk_uniq_contents2 (sweep &sub) { sub.walk (); }
597
-
598
- void walk_struct2 (const uint8_t *end_sp) {
599
- while (this ->sp != end_sp) {
600
- this ->walk ();
601
- align = true ;
602
- }
603
- }
604
-
605
- void walk_variant2 (shape::tag_info &tinfo, uint32_t variant_id,
606
- const std::pair<const uint8_t *,const uint8_t *>
607
- variant_ptr_and_end) {
608
- sweep sub (*this , variant_ptr_and_end.first , tinfo.params );
609
-
610
- const uint8_t *variant_end = variant_ptr_and_end.second ;
611
- while (sub.sp < variant_end) {
612
- sub.walk ();
613
- align = true ;
614
- }
615
- }
616
-
617
- template <typename T>
618
- inline void walk_number2 () { /* no-op */ }
619
-
620
- public:
621
- static void do_sweep (rust_task *task,
622
- const std::set<rust_opaque_box*> &marked);
623
- };
624
-
625
454
void
626
- sweep:: do_sweep (rust_task *task,
627
- const std::set<rust_opaque_box*> &marked) {
455
+ do_sweep (rust_task *task,
456
+ const std::set<rust_opaque_box*> &marked) {
628
457
boxed_region *boxed = &task->boxed ;
629
458
rust_opaque_box *box = boxed->first_live_alloc ();
630
459
while (box != NULL ) {
631
460
// save next ptr as we may be freeing box
632
461
rust_opaque_box *box_next = box->next ;
633
462
if (marked.find (box) == marked.end ()) {
634
463
LOG (task, gc, " object is part of a cycle: %p" , box);
635
-
636
- const type_desc *tydesc = box->td ;
637
- uint8_t *p = (uint8_t *) box_body (box);
638
- shape::arena arena;
639
- shape::type_param *params =
640
- shape::type_param::from_tydesc_and_data (tydesc, p, arena);
641
-
642
- sweep sweep (task, true , tydesc->shape ,
643
- params, tydesc->shape_tables ,
644
- p);
645
- sweep.walk ();
646
-
647
- boxed->free (box);
464
+ annihilate_box (task, box);
648
465
}
649
466
box = box_next;
650
467
}
@@ -664,7 +481,7 @@ do_cc(rust_task *task) {
664
481
std::set<rust_opaque_box*> marked;
665
482
mark::do_mark (task, roots, marked);
666
483
667
- sweep:: do_sweep (task, marked);
484
+ do_sweep (task, marked);
668
485
}
669
486
670
487
void
0 commit comments