hotspot/src/share/vm/gc_implementation/g1/concurrentG1RefineThread.cpp
author iveresov
Wed, 16 Dec 2009 15:12:51 -0800
changeset 4481 de92ec484f5e
parent 4022 2ec87d5043f7
child 5033 55f476a32544
permissions -rw-r--r--
6862387: tune concurrent refinement further Summary: Reworked the concurrent refinement: threads activation, feedback-based threshold adjustment, other miscellaneous fixes. Reviewed-by: apetrusenko, tonyp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     1
/*
3261
c7d5aae8d3f7 6862919: Update copyright year
xdono
parents: 2882
diff changeset
     2
 * Copyright 2001-2009 Sun Microsystems, Inc.  All Rights Reserved.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     4
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     8
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    13
 * accompanied this code).
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    14
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    18
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    21
 * have any questions.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    22
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    23
 */
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    24
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    25
#include "incls/_precompiled.incl"
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    26
#include "incls/_concurrentG1RefineThread.cpp.incl"
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    27
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    28
ConcurrentG1RefineThread::
2882
d508a8bac491 6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents: 2881
diff changeset
    29
ConcurrentG1RefineThread(ConcurrentG1Refine* cg1r, ConcurrentG1RefineThread *next,
d508a8bac491 6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents: 2881
diff changeset
    30
                         int worker_id_offset, int worker_id) :
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    31
  ConcurrentGCThread(),
2882
d508a8bac491 6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents: 2881
diff changeset
    32
  _worker_id_offset(worker_id_offset),
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
    33
  _worker_id(worker_id),
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
    34
  _active(false),
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
    35
  _next(next),
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    36
  _monitor(NULL),
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    37
  _cg1r(cg1r),
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    38
  _vtime_accum(0.0)
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    39
{
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    40
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    41
  // Each thread has its own monitor. The i-th thread is responsible for signalling
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    42
  // to thread i+1 if the number of buffers in the queue exceeds a threashold for this
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    43
  // thread. Monitors are also used to wake up the threads during termination.
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    44
  // The 0th worker in notified by mutator threads and has a special monitor.
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    45
  // The last worker is used for young gen rset size sampling.
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    46
  if (worker_id > 0) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    47
    _monitor = new Monitor(Mutex::nonleaf, "Refinement monitor", true);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    48
  } else {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    49
    _monitor = DirtyCardQ_CBL_mon;
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    50
  }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    51
  initialize();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    52
  create_and_start();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    53
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    54
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    55
void ConcurrentG1RefineThread::initialize() {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    56
  if (_worker_id < cg1r()->worker_thread_num()) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    57
    // Current thread activation threshold
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    58
    _threshold = MIN2<int>(cg1r()->thread_threshold_step() * (_worker_id + 1) + cg1r()->green_zone(),
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    59
                           cg1r()->yellow_zone());
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    60
    // A thread deactivates once the number of buffer reached a deactivation threshold
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    61
    _deactivation_threshold = MAX2<int>(_threshold - cg1r()->thread_threshold_step(), cg1r()->green_zone());
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    62
  } else {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    63
    set_active(true);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    64
  }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    65
}
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    66
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    67
void ConcurrentG1RefineThread::sample_young_list_rs_lengths() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    68
  G1CollectedHeap* g1h = G1CollectedHeap::heap();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    69
  G1CollectorPolicy* g1p = g1h->g1_policy();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    70
  if (g1p->adaptive_young_list_length()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    71
    int regions_visited = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    72
    g1h->young_list_rs_length_sampling_init();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    73
    while (g1h->young_list_rs_length_sampling_more()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    74
      g1h->young_list_rs_length_sampling_next();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    75
      ++regions_visited;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    76
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    77
      // we try to yield every time we visit 10 regions
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    78
      if (regions_visited == 10) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    79
        if (_sts.should_yield()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    80
          _sts.yield("G1 refine");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    81
          // we just abandon the iteration
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    82
          break;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    83
        }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    84
        regions_visited = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    85
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    86
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    87
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    88
    g1p->check_prediction_validity();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    89
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    90
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    91
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    92
void ConcurrentG1RefineThread::run_young_rs_sampling() {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    93
  DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    94
  _vtime_start = os::elapsedVTime();
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    95
  while(!_should_terminate) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    96
    _sts.join();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    97
    sample_young_list_rs_lengths();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    98
    _sts.leave();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    99
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   100
    if (os::supports_vtime()) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   101
      _vtime_accum = (os::elapsedVTime() - _vtime_start);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   102
    } else {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   103
      _vtime_accum = 0.0;
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
   104
    }
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
   105
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   106
    MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   107
    if (_should_terminate) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   108
      break;
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   109
    }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   110
    _monitor->wait(Mutex::_no_safepoint_check_flag, G1ConcRefineServiceInterval);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   111
  }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   112
}
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
   113
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   114
void ConcurrentG1RefineThread::wait_for_completed_buffers() {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   115
  DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   116
  MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   117
  while (!_should_terminate && !is_active()) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   118
    _monitor->wait(Mutex::_no_safepoint_check_flag);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   119
  }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   120
}
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   121
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   122
bool ConcurrentG1RefineThread::is_active() {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   123
  DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   124
  return _worker_id > 0 ? _active : dcqs.process_completed_buffers();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   125
}
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   126
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   127
void ConcurrentG1RefineThread::activate() {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   128
  MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   129
  if (_worker_id > 0) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   130
    if (G1TraceConcurrentRefinement) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   131
      DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   132
      gclog_or_tty->print_cr("G1-Refine-activated worker %d, on threshold %d, current %d",
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   133
                             _worker_id, _threshold, (int)dcqs.completed_buffers_num());
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   134
    }
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   135
    set_active(true);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   136
  } else {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   137
    DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   138
    dcqs.set_process_completed(true);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   139
  }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   140
  _monitor->notify();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   141
}
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
   142
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   143
void ConcurrentG1RefineThread::deactivate() {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   144
  MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   145
  if (_worker_id > 0) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   146
    if (G1TraceConcurrentRefinement) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   147
      DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   148
      gclog_or_tty->print_cr("G1-Refine-deactivated worker %d, off threshold %d, current %d",
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   149
                             _worker_id, _deactivation_threshold, (int)dcqs.completed_buffers_num());
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   150
    }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   151
    set_active(false);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   152
  } else {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   153
    DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   154
    dcqs.set_process_completed(false);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   155
  }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   156
}
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   157
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   158
void ConcurrentG1RefineThread::run() {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   159
  initialize_in_thread();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   160
  wait_for_universe_init();
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
   161
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   162
  if (_worker_id >= cg1r()->worker_thread_num()) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   163
    run_young_rs_sampling();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   164
    terminate();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   165
  }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   166
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   167
  _vtime_start = os::elapsedVTime();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   168
  while (!_should_terminate) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   169
    DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   170
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   171
    // Wait for work
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   172
    wait_for_completed_buffers();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   173
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   174
    if (_should_terminate) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   175
      break;
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   176
    }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   177
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   178
    _sts.join();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   179
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   180
    do {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   181
      int curr_buffer_num = (int)dcqs.completed_buffers_num();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   182
      // If the number of the buffers falls down into the yellow zone,
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   183
      // that means that the transition period after the evacuation pause has ended.
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   184
      if (dcqs.completed_queue_padding() > 0 && curr_buffer_num <= cg1r()->yellow_zone()) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   185
        dcqs.set_completed_queue_padding(0);
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
   186
      }
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   187
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   188
      if (_worker_id > 0 && curr_buffer_num <= _deactivation_threshold) {
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
   189
        // If the number of the buffer has fallen below our threshold
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
   190
        // we should deactivate. The predecessor will reactivate this
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
   191
        // thread should the number of the buffers cross the threshold again.
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
   192
        deactivate();
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
   193
        break;
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
   194
      }
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
   195
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
   196
      // Check if we need to activate the next thread.
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   197
      if (_next != NULL && !_next->is_active() && curr_buffer_num > _next->_threshold) {
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
   198
        _next->activate();
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
   199
      }
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   200
    } while (dcqs.apply_closure_to_completed_buffer(_worker_id + _worker_id_offset, cg1r()->green_zone()));
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
   201
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   202
    // We can exit the loop above while being active if there was a yield request.
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   203
    if (is_active()) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   204
      deactivate();
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
   205
    }
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   206
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   207
    _sts.leave();
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
   208
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   209
    if (os::supports_vtime()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   210
      _vtime_accum = (os::elapsedVTime() - _vtime_start);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   211
    } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   212
      _vtime_accum = 0.0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   213
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   214
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   215
  assert(_should_terminate, "just checking");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   216
  terminate();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   217
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   218
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   219
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   220
void ConcurrentG1RefineThread::yield() {
2741
34e2a243d69a 6490395: G1: Tidy up command line flags.
johnc
parents: 2142
diff changeset
   221
  if (G1TraceConcurrentRefinement) gclog_or_tty->print_cr("G1-Refine-yield");
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   222
  _sts.yield("G1 refine");
2741
34e2a243d69a 6490395: G1: Tidy up command line flags.
johnc
parents: 2142
diff changeset
   223
  if (G1TraceConcurrentRefinement) gclog_or_tty->print_cr("G1-Refine-yield-end");
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   224
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   225
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   226
void ConcurrentG1RefineThread::stop() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   227
  // it is ok to take late safepoints here, if needed
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   228
  {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   229
    MutexLockerEx mu(Terminator_lock);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   230
    _should_terminate = true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   231
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   232
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   233
  {
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   234
    MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   235
    _monitor->notify();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   236
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   237
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   238
  {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   239
    MutexLockerEx mu(Terminator_lock);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   240
    while (!_has_terminated) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   241
      Terminator_lock->wait();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   242
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   243
  }
2741
34e2a243d69a 6490395: G1: Tidy up command line flags.
johnc
parents: 2142
diff changeset
   244
  if (G1TraceConcurrentRefinement) gclog_or_tty->print_cr("G1-Refine-stop");
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   245
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   246
4022
2ec87d5043f7 6885041: G1: inconsistent thread dump
tonyp
parents: 3691
diff changeset
   247
void ConcurrentG1RefineThread::print() const {
2ec87d5043f7 6885041: G1: inconsistent thread dump
tonyp
parents: 3691
diff changeset
   248
  print_on(tty);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   249
}
4022
2ec87d5043f7 6885041: G1: inconsistent thread dump
tonyp
parents: 3691
diff changeset
   250
2ec87d5043f7 6885041: G1: inconsistent thread dump
tonyp
parents: 3691
diff changeset
   251
void ConcurrentG1RefineThread::print_on(outputStream* st) const {
2ec87d5043f7 6885041: G1: inconsistent thread dump
tonyp
parents: 3691
diff changeset
   252
  st->print("\"G1 Concurrent Refinement Thread#%d\" ", _worker_id);
2ec87d5043f7 6885041: G1: inconsistent thread dump
tonyp
parents: 3691
diff changeset
   253
  Thread::print_on(st);
2ec87d5043f7 6885041: G1: inconsistent thread dump
tonyp
parents: 3691
diff changeset
   254
  st->cr();
2ec87d5043f7 6885041: G1: inconsistent thread dump
tonyp
parents: 3691
diff changeset
   255
}