hotspot/src/share/vm/gc/g1/concurrentG1RefineThread.cpp
author goetz
Thu, 22 Oct 2015 13:07:10 -0400
changeset 33589 7cbd1b2c139b
parent 30770 5ba2d9f2084d
child 33608 7afc768e4d62
permissions -rw-r--r--
8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux. Reviewed-by: stuefe, coleenp, roland
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
/*
30613
a7815bb05ae2 8079579: Add SuspendibleThreadSetLeaver and make SuspendibleThreadSet::joint()/leave() private
pliden
parents: 29464
diff changeset
     2
 * Copyright (c) 2001, 2015, Oracle and/or its affiliates. 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
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5350
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5350
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5350
diff changeset
    21
 * questions.
1374
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
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30613
diff changeset
    26
#include "gc/g1/concurrentG1Refine.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30613
diff changeset
    27
#include "gc/g1/concurrentG1RefineThread.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30613
diff changeset
    28
#include "gc/g1/g1CollectedHeap.inline.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30613
diff changeset
    29
#include "gc/g1/g1CollectorPolicy.hpp"
30770
5ba2d9f2084d 8080585: concurrentGCThread.hpp should not include suspendibleThreadSet.hpp
pliden
parents: 30764
diff changeset
    30
#include "gc/g1/suspendibleThreadSet.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "memory/resourceArea.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "runtime/handles.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
#include "runtime/mutexLocker.hpp"
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    34
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    35
ConcurrentG1RefineThread::
2882
d508a8bac491 6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents: 2881
diff changeset
    36
ConcurrentG1RefineThread(ConcurrentG1Refine* cg1r, ConcurrentG1RefineThread *next,
24104
febf9363fb68 8019342: G1: High "Other" time most likely due to card redirtying
tschatzl
parents: 24094
diff changeset
    37
                         CardTableEntryClosure* refine_closure,
23855
c4574075402c 8016302: Change type of the number of GC workers to unsigned int (2)
vkempik
parents: 22551
diff changeset
    38
                         uint worker_id_offset, uint worker_id) :
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    39
  ConcurrentGCThread(),
24104
febf9363fb68 8019342: G1: High "Other" time most likely due to card redirtying
tschatzl
parents: 24094
diff changeset
    40
  _refine_closure(refine_closure),
2882
d508a8bac491 6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents: 2881
diff changeset
    41
  _worker_id_offset(worker_id_offset),
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
    42
  _worker_id(worker_id),
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
    43
  _active(false),
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
    44
  _next(next),
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    45
  _monitor(NULL),
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    46
  _cg1r(cg1r),
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    47
  _vtime_accum(0.0)
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    48
{
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    49
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 10528
diff changeset
    50
  // Each thread has its own monitor. The i-th thread is responsible for signaling
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 10528
diff changeset
    51
  // to thread i+1 if the number of buffers in the queue exceeds a threshold for this
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    52
  // thread. Monitors are also used to wake up the threads during termination.
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    53
  // The 0th worker in notified by mutator threads and has a special monitor.
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    54
  // The last worker is used for young gen rset size sampling.
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    55
  if (worker_id > 0) {
28163
322d55d167be 8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents: 24331
diff changeset
    56
    _monitor = new Monitor(Mutex::nonleaf, "Refinement monitor", true,
322d55d167be 8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents: 24331
diff changeset
    57
                           Monitor::_safepoint_check_never);
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    58
  } else {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    59
    _monitor = DirtyCardQ_CBL_mon;
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    60
  }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    61
  initialize();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    62
  create_and_start();
24331
c0bc7e5653fb 6885993: Named Thread: introduce print() and print_on(outputStream* st) methods
zgu
parents: 24104
diff changeset
    63
c0bc7e5653fb 6885993: Named Thread: introduce print() and print_on(outputStream* st) methods
zgu
parents: 24104
diff changeset
    64
  // set name
29464
02c245ad3ec9 8073545: Use shorter and more descriptive names for GC worker threads
david
parents: 28163
diff changeset
    65
  set_name("G1 Refine#%d", worker_id);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    66
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    67
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    68
void ConcurrentG1RefineThread::initialize() {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    69
  if (_worker_id < cg1r()->worker_thread_num()) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    70
    // Current thread activation threshold
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    71
    _threshold = MIN2<int>(cg1r()->thread_threshold_step() * (_worker_id + 1) + cg1r()->green_zone(),
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    72
                           cg1r()->yellow_zone());
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    73
    // A thread deactivates once the number of buffer reached a deactivation threshold
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    74
    _deactivation_threshold = MAX2<int>(_threshold - cg1r()->thread_threshold_step(), cg1r()->green_zone());
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    75
  } else {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    76
    set_active(true);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    77
  }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    78
}
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    79
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    80
void ConcurrentG1RefineThread::sample_young_list_rs_lengths() {
30613
a7815bb05ae2 8079579: Add SuspendibleThreadSetLeaver and make SuspendibleThreadSet::joint()/leave() private
pliden
parents: 29464
diff changeset
    81
  SuspendibleThreadSetJoiner sts_join;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    82
  G1CollectedHeap* g1h = G1CollectedHeap::heap();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    83
  G1CollectorPolicy* g1p = g1h->g1_policy();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    84
  if (g1p->adaptive_young_list_length()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    85
    int regions_visited = 0;
5350
cccf0925702e 6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents: 5033
diff changeset
    86
    g1h->young_list()->rs_length_sampling_init();
cccf0925702e 6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents: 5033
diff changeset
    87
    while (g1h->young_list()->rs_length_sampling_more()) {
cccf0925702e 6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents: 5033
diff changeset
    88
      g1h->young_list()->rs_length_sampling_next();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    89
      ++regions_visited;
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
      // we try to yield every time we visit 10 regions
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    92
      if (regions_visited == 10) {
30613
a7815bb05ae2 8079579: Add SuspendibleThreadSetLeaver and make SuspendibleThreadSet::joint()/leave() private
pliden
parents: 29464
diff changeset
    93
        if (sts_join.should_yield()) {
a7815bb05ae2 8079579: Add SuspendibleThreadSetLeaver and make SuspendibleThreadSet::joint()/leave() private
pliden
parents: 29464
diff changeset
    94
          sts_join.yield();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    95
          // we just abandon the iteration
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    96
          break;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    97
        }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    98
        regions_visited = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    99
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   100
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   101
10528
06fab03478df 7084509: G1: fix inconsistencies and mistakes in the young list target length calculations
tonyp
parents: 7397
diff changeset
   102
    g1p->revise_young_list_target_length_if_necessary();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   103
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   104
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   105
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   106
void ConcurrentG1RefineThread::run_young_rs_sampling() {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   107
  DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   108
  _vtime_start = os::elapsedVTime();
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   109
  while(!_should_terminate) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   110
    sample_young_list_rs_lengths();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   111
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   112
    if (os::supports_vtime()) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   113
      _vtime_accum = (os::elapsedVTime() - _vtime_start);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   114
    } else {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   115
      _vtime_accum = 0.0;
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
   116
    }
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
   117
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   118
    MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   119
    if (_should_terminate) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   120
      break;
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   121
    }
5033
55f476a32544 6928059: G1: command line parameter renaming
tonyp
parents: 4481
diff changeset
   122
    _monitor->wait(Mutex::_no_safepoint_check_flag, G1ConcRefinementServiceIntervalMillis);
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   123
  }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   124
}
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
   125
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   126
void ConcurrentG1RefineThread::wait_for_completed_buffers() {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   127
  DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
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
  while (!_should_terminate && !is_active()) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   130
    _monitor->wait(Mutex::_no_safepoint_check_flag);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   131
  }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   132
}
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   133
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   134
bool ConcurrentG1RefineThread::is_active() {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   135
  DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   136
  return _worker_id > 0 ? _active : dcqs.process_completed_buffers();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   137
}
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   138
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   139
void ConcurrentG1RefineThread::activate() {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   140
  MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   141
  if (_worker_id > 0) {
5033
55f476a32544 6928059: G1: command line parameter renaming
tonyp
parents: 4481
diff changeset
   142
    if (G1TraceConcRefinement) {
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   143
      DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   144
      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
   145
                             _worker_id, _threshold, (int)dcqs.completed_buffers_num());
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   146
    }
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   147
    set_active(true);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   148
  } else {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   149
    DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   150
    dcqs.set_process_completed(true);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   151
  }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   152
  _monitor->notify();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   153
}
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
   154
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   155
void ConcurrentG1RefineThread::deactivate() {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   156
  MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   157
  if (_worker_id > 0) {
5033
55f476a32544 6928059: G1: command line parameter renaming
tonyp
parents: 4481
diff changeset
   158
    if (G1TraceConcRefinement) {
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   159
      DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   160
      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
   161
                             _worker_id, _deactivation_threshold, (int)dcqs.completed_buffers_num());
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   162
    }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   163
    set_active(false);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   164
  } else {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   165
    DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   166
    dcqs.set_process_completed(false);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   167
  }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   168
}
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   169
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   170
void ConcurrentG1RefineThread::run() {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   171
  initialize_in_thread();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   172
  wait_for_universe_init();
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
   173
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   174
  if (_worker_id >= cg1r()->worker_thread_num()) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   175
    run_young_rs_sampling();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   176
    terminate();
5350
cccf0925702e 6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents: 5033
diff changeset
   177
    return;
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   178
  }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   179
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   180
  _vtime_start = os::elapsedVTime();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   181
  while (!_should_terminate) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   182
    DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   183
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   184
    // Wait for work
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   185
    wait_for_completed_buffers();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   186
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   187
    if (_should_terminate) {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   188
      break;
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   189
    }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   190
24094
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 23855
diff changeset
   191
    {
30613
a7815bb05ae2 8079579: Add SuspendibleThreadSetLeaver and make SuspendibleThreadSet::joint()/leave() private
pliden
parents: 29464
diff changeset
   192
      SuspendibleThreadSetJoiner sts_join;
24094
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 23855
diff changeset
   193
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 23855
diff changeset
   194
      do {
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 23855
diff changeset
   195
        int curr_buffer_num = (int)dcqs.completed_buffers_num();
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 23855
diff changeset
   196
        // If the number of the buffers falls down into the yellow zone,
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 23855
diff changeset
   197
        // that means that the transition period after the evacuation pause has ended.
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 23855
diff changeset
   198
        if (dcqs.completed_queue_padding() > 0 && curr_buffer_num <= cg1r()->yellow_zone()) {
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 23855
diff changeset
   199
          dcqs.set_completed_queue_padding(0);
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 23855
diff changeset
   200
        }
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   201
24094
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 23855
diff changeset
   202
        if (_worker_id > 0 && curr_buffer_num <= _deactivation_threshold) {
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 23855
diff changeset
   203
          // If the number of the buffer has fallen below our threshold
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 23855
diff changeset
   204
          // we should deactivate. The predecessor will reactivate this
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 23855
diff changeset
   205
          // thread should the number of the buffers cross the threshold again.
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 23855
diff changeset
   206
          deactivate();
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 23855
diff changeset
   207
          break;
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 23855
diff changeset
   208
        }
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   209
24094
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 23855
diff changeset
   210
        // Check if we need to activate the next thread.
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 23855
diff changeset
   211
        if (_next != NULL && !_next->is_active() && curr_buffer_num > _next->_threshold) {
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 23855
diff changeset
   212
          _next->activate();
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 23855
diff changeset
   213
        }
24104
febf9363fb68 8019342: G1: High "Other" time most likely due to card redirtying
tschatzl
parents: 24094
diff changeset
   214
      } while (dcqs.apply_closure_to_completed_buffer(_refine_closure, _worker_id + _worker_id_offset, cg1r()->green_zone()));
24094
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 23855
diff changeset
   215
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 23855
diff changeset
   216
      // We can exit the loop above while being active if there was a yield request.
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 23855
diff changeset
   217
      if (is_active()) {
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
   218
        deactivate();
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
   219
      }
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
   220
    }
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   221
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   222
    if (os::supports_vtime()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   223
      _vtime_accum = (os::elapsedVTime() - _vtime_start);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   224
    } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   225
      _vtime_accum = 0.0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   226
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   227
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   228
  assert(_should_terminate, "just checking");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   229
  terminate();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   230
}
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
void ConcurrentG1RefineThread::stop() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   233
  // it is ok to take late safepoints here, if needed
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   234
  {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   235
    MutexLockerEx mu(Terminator_lock);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   236
    _should_terminate = true;
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
  {
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   240
    MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   241
    _monitor->notify();
1374
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
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   244
  {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   245
    MutexLockerEx mu(Terminator_lock);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   246
    while (!_has_terminated) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   247
      Terminator_lock->wait();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   248
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   249
  }
5033
55f476a32544 6928059: G1: command line parameter renaming
tonyp
parents: 4481
diff changeset
   250
  if (G1TraceConcRefinement) {
55f476a32544 6928059: G1: command line parameter renaming
tonyp
parents: 4481
diff changeset
   251
    gclog_or_tty->print_cr("G1-Refine-stop");
55f476a32544 6928059: G1: command line parameter renaming
tonyp
parents: 4481
diff changeset
   252
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   253
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   254