Merge pull request #2800 from BrzVlad/feature-lazy-sweep
authorVlad Brezae <brezaevlad@gmail.com>
Wed, 13 Apr 2016 08:51:25 +0000 (16:51 +0800)
committerVlad Brezae <brezaevlad@gmail.com>
Wed, 13 Apr 2016 08:51:25 +0000 (16:51 +0800)
[sgen] Enable lazy sweep by default

1  2 
mono/metadata/sgen-client-mono.h
mono/sgen/sgen-marksweep.c

Simple merge
index 38e127b8cd541fe4b304adf4f3e91d19135265db,1509f06988b888be28db3f339ba26a1f9b2e2fd0..d2e3ccdd0093dcc9e68432ef1e8f20b9198651a2
@@@ -1641,9 -1675,9 +1666,11 @@@ sweep_finish (void
                }
        }
  
 +      sgen_memgov_major_post_sweep ();
 +
        set_sweep_state (SWEEP_STATE_SWEPT, SWEEP_STATE_COMPACTING);
+       if (concurrent_sweep)
+               binary_protocol_concurrent_sweep_end (sgen_timestamp ());
  }
  
  static void
@@@ -1859,29 -1832,31 +1886,38 @@@ major_start_major_collection (void
  
                binary_protocol_evacuating_blocks (block_obj_sizes [i]);
  
 -              free_block_lists [0][i] = NULL;
 -              free_block_lists [MS_BLOCK_FLAG_REFS][i] = NULL;
 +              sgen_evacuation_freelist_blocks (&free_block_lists [0][i], i);
 +              sgen_evacuation_freelist_blocks (&free_block_lists [MS_BLOCK_FLAG_REFS][i], i);
        }
  
-       if (lazy_sweep)
-               binary_protocol_sweep_begin (GENERATION_OLD, TRUE);
+       if (lazy_sweep && concurrent_sweep) {
+               /*
+                * sweep_blocks_job is created before sweep_finish, which we wait for above
+                * (major_finish_sweep_checking). After the end of sweep, if we don't have
+                * sweep_blocks_job set, it means that it has already been run.
+                */
+               SgenThreadPoolJob *job = sweep_blocks_job;
+               if (job)
+                       sgen_thread_pool_job_wait (job);
+       }
  
+       if (lazy_sweep && !concurrent_sweep)
+               binary_protocol_sweep_begin (GENERATION_OLD, TRUE);
        /* Sweep all unswept blocks and set them to MARKING */
        FOREACH_BLOCK_NO_LOCK (block) {
-               if (lazy_sweep)
+               if (lazy_sweep && !concurrent_sweep)
                        sweep_block (block);
                SGEN_ASSERT (0, block->state == BLOCK_STATE_SWEPT, "All blocks must be swept when we're pinning.");
                set_block_state (block, BLOCK_STATE_MARKING, BLOCK_STATE_SWEPT);
 +              /*
 +               * Swept blocks that have a null free_list are full. Evacuation is not
 +               * effective on these blocks since we expect them to have high usage anyway,
 +               * given that the survival rate for majors is relatively high.
 +               */
 +              if (evacuate_block_obj_sizes [block->obj_size_index] && !block->free_list)
 +                      block->is_to_space = TRUE;
        } END_FOREACH_BLOCK_NO_LOCK;
-       if (lazy_sweep)
+       if (lazy_sweep && !concurrent_sweep)
                binary_protocol_sweep_end (GENERATION_OLD, TRUE);
  
        set_sweep_state (SWEEP_STATE_NEED_SWEEPING, SWEEP_STATE_SWEPT);