void ConcurrentG1RefineThread::sample_young_list_rs_lengths() {
  SuspendibleThreadSetJoiner sts;
  G1CollectedHeap* g1h = G1CollectedHeap::heap();
  G1CollectorPolicy* g1p = g1h->g1_policy();
  if (g1p->adaptive_young_list_length()) {
    int regions_visited = 0;
    g1h->young_list()->rs_length_sampling_init();
    while (g1h->young_list()->rs_length_sampling_more()) {
      g1h->young_list()->rs_length_sampling_next();
      ++regions_visited;

      // we try to yield every time we visit 10 regions
      if (regions_visited == 10) {
        if (sts.should_yield()) {
          sts.yield();
          // we just abandon the iteration
          break;
        }
        regions_visited = 0;
      }
    }

    g1p->revise_young_list_target_length_if_necessary();
  }
}
示例#2
0
void G1StringDedupThread::run() {
  G1StringDedupStat total_stat;

  initialize_in_thread();
  wait_for_universe_init();

  // Main loop
  for (;;) {
    G1StringDedupStat stat;

    stat.mark_idle();

    // Wait for the queue to become non-empty
    G1StringDedupQueue::wait();
    if (_should_terminate) {
      break;
    }

    {
      // Include thread in safepoints
      SuspendibleThreadSetJoiner sts;

      stat.mark_exec();

      // Process the queue
      for (;;) {
        oop java_string = G1StringDedupQueue::pop();
        if (java_string == NULL) {
          break;
        }

        G1StringDedupTable::deduplicate(java_string, stat);

        // Safepoint this thread if needed
        if (sts.should_yield()) {
          stat.mark_block();
          sts.yield();
          stat.mark_unblock();
        }
      }

      stat.mark_done();

      // Print statistics
      total_stat.add(stat);
      print(gclog_or_tty, stat, total_stat);
    }

    G1StringDedupTable::clean_entry_cache();
  }

  terminate();
}