src/hotspot/share/gc/g1/g1ConcurrentRefineThread.cpp
author pliden
Thu, 12 Apr 2018 08:25:30 +0200
changeset 49751 c3a10df652c0
parent 48103 26dbe08d1c17
child 51332 c25572739e7c
permissions -rw-r--r--
8201316: Move G1-related static members from JavaThread to G1BarrierSet Reviewed-by: stefank, shade
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
/*
49751
c3a10df652c0 8201316: Move G1-related static members from JavaThread to G1BarrierSet
pliden
parents: 48103
diff changeset
     2
 * Copyright (c) 2001, 2018, 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"
49751
c3a10df652c0 8201316: Move G1-related static members from JavaThread to G1BarrierSet
pliden
parents: 48103
diff changeset
    26
#include "gc/g1/g1BarrierSet.hpp"
47789
a77a7d3bc4f6 8149127: Rename g1/concurrentMarkThread.* to g1/g1ConcurrentMarkThread.*
tschatzl
parents: 47647
diff changeset
    27
#include "gc/g1/g1ConcurrentRefine.hpp"
a77a7d3bc4f6 8149127: Rename g1/concurrentMarkThread.* to g1/g1ConcurrentMarkThread.*
tschatzl
parents: 47647
diff changeset
    28
#include "gc/g1/g1ConcurrentRefineThread.hpp"
47647
64dba69fc528 8189276: Make SuspendibleThreadSet and related code available to other GCs
rkennke
parents: 47216
diff changeset
    29
#include "gc/shared/suspendibleThreadSet.hpp"
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33608
diff changeset
    30
#include "logging/log.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
48103
26dbe08d1c17 8190426: Lazily initialize refinement threads with UseDynamicNumberOfGCThreads
tschatzl
parents: 47789
diff changeset
    35
G1ConcurrentRefineThread::G1ConcurrentRefineThread(G1ConcurrentRefine* cr, uint worker_id) :
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    36
  ConcurrentGCThread(),
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
    37
  _worker_id(worker_id),
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
    38
  _active(false),
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    39
  _monitor(NULL),
47789
a77a7d3bc4f6 8149127: Rename g1/concurrentMarkThread.* to g1/g1ConcurrentMarkThread.*
tschatzl
parents: 47647
diff changeset
    40
  _cr(cr),
48103
26dbe08d1c17 8190426: Lazily initialize refinement threads with UseDynamicNumberOfGCThreads
tschatzl
parents: 47789
diff changeset
    41
  _vtime_accum(0.0)
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    42
{
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 10528
diff changeset
    43
  // 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
    44
  // 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
    45
  // thread. Monitors are also used to wake up the threads during termination.
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 30770
diff changeset
    46
  // The 0th (primary) worker is notified by mutator threads and has a special monitor.
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 30770
diff changeset
    47
  if (!is_primary()) {
28163
322d55d167be 8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents: 24331
diff changeset
    48
    _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
    49
                           Monitor::_safepoint_check_never);
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    50
  } else {
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    51
    _monitor = DirtyCardQ_CBL_mon;
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    52
  }
24331
c0bc7e5653fb 6885993: Named Thread: introduce print() and print_on(outputStream* st) methods
zgu
parents: 24104
diff changeset
    53
c0bc7e5653fb 6885993: Named Thread: introduce print() and print_on(outputStream* st) methods
zgu
parents: 24104
diff changeset
    54
  // set name
29464
02c245ad3ec9 8073545: Use shorter and more descriptive names for GC worker threads
david
parents: 28163
diff changeset
    55
  set_name("G1 Refine#%d", worker_id);
35916
23189249c2c1 8147884: Names of GC threads should be set before the threads start
asmotrak
parents: 35061
diff changeset
    56
  create_and_start();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    57
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    58
47789
a77a7d3bc4f6 8149127: Rename g1/concurrentMarkThread.* to g1/g1ConcurrentMarkThread.*
tschatzl
parents: 47647
diff changeset
    59
void G1ConcurrentRefineThread::wait_for_completed_buffers() {
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    60
  MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
37081
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36402
diff changeset
    61
  while (!should_terminate() && !is_active()) {
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    62
    _monitor->wait(Mutex::_no_safepoint_check_flag);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    63
  }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    64
}
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    65
47789
a77a7d3bc4f6 8149127: Rename g1/concurrentMarkThread.* to g1/g1ConcurrentMarkThread.*
tschatzl
parents: 47647
diff changeset
    66
bool G1ConcurrentRefineThread::is_active() {
49751
c3a10df652c0 8201316: Move G1-related static members from JavaThread to G1BarrierSet
pliden
parents: 48103
diff changeset
    67
  DirtyCardQueueSet& dcqs = G1BarrierSet::dirty_card_queue_set();
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 30770
diff changeset
    68
  return is_primary() ? dcqs.process_completed_buffers() : _active;
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    69
}
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    70
47789
a77a7d3bc4f6 8149127: Rename g1/concurrentMarkThread.* to g1/g1ConcurrentMarkThread.*
tschatzl
parents: 47647
diff changeset
    71
void G1ConcurrentRefineThread::activate() {
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    72
  MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 30770
diff changeset
    73
  if (!is_primary()) {
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    74
    set_active(true);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    75
  } else {
49751
c3a10df652c0 8201316: Move G1-related static members from JavaThread to G1BarrierSet
pliden
parents: 48103
diff changeset
    76
    DirtyCardQueueSet& dcqs = G1BarrierSet::dirty_card_queue_set();
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    77
    dcqs.set_process_completed(true);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    78
  }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    79
  _monitor->notify();
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    80
}
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
    81
47789
a77a7d3bc4f6 8149127: Rename g1/concurrentMarkThread.* to g1/g1ConcurrentMarkThread.*
tschatzl
parents: 47647
diff changeset
    82
void G1ConcurrentRefineThread::deactivate() {
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    83
  MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 30770
diff changeset
    84
  if (!is_primary()) {
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    85
    set_active(false);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    86
  } else {
49751
c3a10df652c0 8201316: Move G1-related static members from JavaThread to G1BarrierSet
pliden
parents: 48103
diff changeset
    87
    DirtyCardQueueSet& dcqs = G1BarrierSet::dirty_card_queue_set();
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    88
    dcqs.set_process_completed(false);
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    89
  }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    90
}
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    91
47789
a77a7d3bc4f6 8149127: Rename g1/concurrentMarkThread.* to g1/g1ConcurrentMarkThread.*
tschatzl
parents: 47647
diff changeset
    92
void G1ConcurrentRefineThread::run_service() {
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    93
  _vtime_start = os::elapsedVTime();
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 30770
diff changeset
    94
37081
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36402
diff changeset
    95
  while (!should_terminate()) {
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    96
    // Wait for work
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    97
    wait_for_completed_buffers();
37081
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 36402
diff changeset
    98
    if (should_terminate()) {
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
    99
      break;
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   100
    }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   101
37510
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37197
diff changeset
   102
    size_t buffers_processed = 0;
48103
26dbe08d1c17 8190426: Lazily initialize refinement threads with UseDynamicNumberOfGCThreads
tschatzl
parents: 47789
diff changeset
   103
    log_debug(gc, refine)("Activated worker %d, on threshold: " SIZE_FORMAT ", current: " SIZE_FORMAT,
26dbe08d1c17 8190426: Lazily initialize refinement threads with UseDynamicNumberOfGCThreads
tschatzl
parents: 47789
diff changeset
   104
                          _worker_id, _cr->activation_threshold(_worker_id),
49751
c3a10df652c0 8201316: Move G1-related static members from JavaThread to G1BarrierSet
pliden
parents: 48103
diff changeset
   105
                           G1BarrierSet::dirty_card_queue_set().completed_buffers_num());
36196
5128f617b0c6 8150134: Simplify concurrent refinement thread deactivation
kbarrett
parents: 36179
diff changeset
   106
24094
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 23855
diff changeset
   107
    {
30613
a7815bb05ae2 8079579: Add SuspendibleThreadSetLeaver and make SuspendibleThreadSet::joint()/leave() private
pliden
parents: 29464
diff changeset
   108
      SuspendibleThreadSetJoiner sts_join;
24094
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 23855
diff changeset
   109
37197
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37081
diff changeset
   110
      while (!should_terminate()) {
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37081
diff changeset
   111
        if (sts_join.should_yield()) {
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37081
diff changeset
   112
          sts_join.yield();
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37081
diff changeset
   113
          continue;             // Re-check for termination after yield delay.
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37081
diff changeset
   114
        }
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37081
diff changeset
   115
48103
26dbe08d1c17 8190426: Lazily initialize refinement threads with UseDynamicNumberOfGCThreads
tschatzl
parents: 47789
diff changeset
   116
        if (!_cr->do_refinement_step(_worker_id)) {
26dbe08d1c17 8190426: Lazily initialize refinement threads with UseDynamicNumberOfGCThreads
tschatzl
parents: 47789
diff changeset
   117
          break;
37197
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37081
diff changeset
   118
        }
37510
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37197
diff changeset
   119
        ++buffers_processed;
37197
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37081
diff changeset
   120
      }
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2741
diff changeset
   121
    }
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   122
37197
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37081
diff changeset
   123
    deactivate();
48103
26dbe08d1c17 8190426: Lazily initialize refinement threads with UseDynamicNumberOfGCThreads
tschatzl
parents: 47789
diff changeset
   124
    log_debug(gc, refine)("Deactivated worker %d, off threshold: " SIZE_FORMAT
37510
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37197
diff changeset
   125
                          ", current: " SIZE_FORMAT ", processed: " SIZE_FORMAT,
48103
26dbe08d1c17 8190426: Lazily initialize refinement threads with UseDynamicNumberOfGCThreads
tschatzl
parents: 47789
diff changeset
   126
                          _worker_id, _cr->deactivation_threshold(_worker_id),
49751
c3a10df652c0 8201316: Move G1-related static members from JavaThread to G1BarrierSet
pliden
parents: 48103
diff changeset
   127
                          G1BarrierSet::dirty_card_queue_set().completed_buffers_num(),
37510
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37197
diff changeset
   128
                          buffers_processed);
37197
282fa21230c3 8151670: Unexpected concurrent refinement deactivation and reactivation
kbarrett
parents: 37081
diff changeset
   129
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   130
    if (os::supports_vtime()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   131
      _vtime_accum = (os::elapsedVTime() - _vtime_start);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   132
    } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   133
      _vtime_accum = 0.0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   134
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   135
  }
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 30770
diff changeset
   136
36196
5128f617b0c6 8150134: Simplify concurrent refinement thread deactivation
kbarrett
parents: 36179
diff changeset
   137
  log_debug(gc, refine)("Stopping %d", _worker_id);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   138
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   139
47789
a77a7d3bc4f6 8149127: Rename g1/concurrentMarkThread.* to g1/g1ConcurrentMarkThread.*
tschatzl
parents: 47647
diff changeset
   140
void G1ConcurrentRefineThread::stop_service() {
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 30770
diff changeset
   141
  MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 30770
diff changeset
   142
  _monitor->notify();
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33608
diff changeset
   143
}