src/hotspot/share/gc/g1/g1YoungRemSetSamplingThread.cpp
author tschatzl
Wed, 16 Jan 2019 11:43:51 +0100
changeset 53354 528207d2e73e
parent 53090 759266b1c89b
child 53360 58e25974ede4
permissions -rw-r--r--
8216490: Spammy periodic GC log message contains random time stamp with periodic gc disabled Summary: Print periodic gc status at startup and only print regular messages if enabled. Reviewed-by: sangheki, kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
     1
/*
47647
64dba69fc528 8189276: Make SuspendibleThreadSet and related code available to other GCs
rkennke
parents: 47216
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
     4
 *
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
     7
 * published by the Free Software Foundation.
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
     8
 *
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    13
 * accompanied this code).
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    14
 *
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    18
 *
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    21
 * questions.
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    22
 *
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    23
 */
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    24
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    25
#include "precompiled.hpp"
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    26
#include "gc/g1/g1CollectedHeap.inline.hpp"
37039
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents: 36402
diff changeset
    27
#include "gc/g1/g1CollectionSet.hpp"
52918
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    28
#include "gc/g1/g1ConcurrentMark.inline.hpp"
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    29
#include "gc/g1/g1ConcurrentMarkThread.inline.hpp"
37985
539c597ee0fa 8154154: Separate G1 specific policy code from the CollectorPolicy class hierarchy
mgerdin
parents: 37081
diff changeset
    30
#include "gc/g1/g1Policy.hpp"
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    31
#include "gc/g1/g1YoungRemSetSamplingThread.hpp"
36365
bcc9c9afda49 8150390: Move rs length sampling data to the sampling thread
mgerdin
parents: 35916
diff changeset
    32
#include "gc/g1/heapRegion.inline.hpp"
bcc9c9afda49 8150390: Move rs length sampling data to the sampling thread
mgerdin
parents: 35916
diff changeset
    33
#include "gc/g1/heapRegionRemSet.hpp"
47647
64dba69fc528 8189276: Make SuspendibleThreadSet and related code available to other GCs
rkennke
parents: 47216
diff changeset
    34
#include "gc/shared/suspendibleThreadSet.hpp"
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    35
#include "runtime/mutexLocker.hpp"
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    36
36378
d63bca5c1439 8140600: Convert unnecessarily malloc'd Monitors to value members
drwhite
parents: 36365
diff changeset
    37
G1YoungRemSetSamplingThread::G1YoungRemSetSamplingThread() :
d63bca5c1439 8140600: Convert unnecessarily malloc'd Monitors to value members
drwhite
parents: 36365
diff changeset
    38
    ConcurrentGCThread(),
d63bca5c1439 8140600: Convert unnecessarily malloc'd Monitors to value members
drwhite
parents: 36365
diff changeset
    39
    _monitor(Mutex::nonleaf,
d63bca5c1439 8140600: Convert unnecessarily malloc'd Monitors to value members
drwhite
parents: 36365
diff changeset
    40
             "G1YoungRemSetSamplingThread monitor",
d63bca5c1439 8140600: Convert unnecessarily malloc'd Monitors to value members
drwhite
parents: 36365
diff changeset
    41
             true,
52918
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    42
             Monitor::_safepoint_check_never),
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    43
    _last_periodic_gc_attempt_s(os::elapsedTime()) {
35916
23189249c2c1 8147884: Names of GC threads should be set before the threads start
asmotrak
parents: 33608
diff changeset
    44
  set_name("G1 Young RemSet Sampling");
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    45
  create_and_start();
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    46
}
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    47
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    48
void G1YoungRemSetSamplingThread::sleep_before_next_cycle() {
36378
d63bca5c1439 8140600: Convert unnecessarily malloc'd Monitors to value members
drwhite
parents: 36365
diff changeset
    49
  MutexLockerEx x(&_monitor, Mutex::_no_safepoint_check_flag);
37081
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 37039
diff changeset
    50
  if (!should_terminate()) {
52918
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    51
    uintx waitms = G1ConcRefinementServiceIntervalMillis;
36378
d63bca5c1439 8140600: Convert unnecessarily malloc'd Monitors to value members
drwhite
parents: 36365
diff changeset
    52
    _monitor.wait(Mutex::_no_safepoint_check_flag, waitms);
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    53
  }
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    54
}
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    55
52918
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    56
bool G1YoungRemSetSamplingThread::should_start_periodic_gc() {
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    57
  // If we are currently in a concurrent mark we are going to uncommit memory soon.
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    58
  if (G1CollectedHeap::heap()->concurrent_mark()->cm_thread()->during_cycle()) {
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    59
    log_debug(gc, periodic)("Concurrent cycle in progress. Skipping.");
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    60
    return false;
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    61
  }
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    62
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    63
  // Check if enough time has passed since the last GC.
53354
528207d2e73e 8216490: Spammy periodic GC log message contains random time stamp with periodic gc disabled
tschatzl
parents: 53090
diff changeset
    64
  uintx time_since_last_gc = (uintx)Universe::heap()->millis_since_last_gc();
528207d2e73e 8216490: Spammy periodic GC log message contains random time stamp with periodic gc disabled
tschatzl
parents: 53090
diff changeset
    65
  if ((time_since_last_gc < G1PeriodicGCInterval)) {
52918
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    66
    log_debug(gc, periodic)("Last GC occurred " UINTX_FORMAT "ms before which is below threshold " UINTX_FORMAT "ms. Skipping.",
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    67
                            time_since_last_gc, G1PeriodicGCInterval);
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    68
    return false;
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    69
  }
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    70
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    71
  // Check if load is lower than max.
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    72
  double recent_load;
53090
759266b1c89b 8215548: G1PeriodicGCSystemLoadThreshold needs to be a double
tschatzl
parents: 52918
diff changeset
    73
  if ((G1PeriodicGCSystemLoadThreshold > 0.0f) &&
52918
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    74
      (os::loadavg(&recent_load, 1) == -1 || recent_load > G1PeriodicGCSystemLoadThreshold)) {
53090
759266b1c89b 8215548: G1PeriodicGCSystemLoadThreshold needs to be a double
tschatzl
parents: 52918
diff changeset
    75
    log_debug(gc, periodic)("Load %1.2f is higher than threshold %1.2f. Skipping.",
52918
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    76
                            recent_load, G1PeriodicGCSystemLoadThreshold);
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    77
    return false;
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    78
  }
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    79
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    80
  return true;
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    81
}
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    82
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    83
void G1YoungRemSetSamplingThread::check_for_periodic_gc(){
53354
528207d2e73e 8216490: Spammy periodic GC log message contains random time stamp with periodic gc disabled
tschatzl
parents: 53090
diff changeset
    84
  // If disabled, just return.
528207d2e73e 8216490: Spammy periodic GC log message contains random time stamp with periodic gc disabled
tschatzl
parents: 53090
diff changeset
    85
  if (G1PeriodicGCInterval == 0) {
528207d2e73e 8216490: Spammy periodic GC log message contains random time stamp with periodic gc disabled
tschatzl
parents: 53090
diff changeset
    86
    return;
528207d2e73e 8216490: Spammy periodic GC log message contains random time stamp with periodic gc disabled
tschatzl
parents: 53090
diff changeset
    87
  }
52918
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    88
  if ((os::elapsedTime() - _last_periodic_gc_attempt_s) > (G1PeriodicGCInterval / 1000.0)) {
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    89
    log_debug(gc, periodic)("Checking for periodic GC.");
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    90
    if (should_start_periodic_gc()) {
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    91
      Universe::heap()->collect(GCCause::_g1_periodic_collection);
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    92
    }
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    93
    _last_periodic_gc_attempt_s = os::elapsedTime();
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    94
  }
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    95
}
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    96
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    97
void G1YoungRemSetSamplingThread::run_service() {
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    98
  double vtime_start = os::elapsedVTime();
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    99
53354
528207d2e73e 8216490: Spammy periodic GC log message contains random time stamp with periodic gc disabled
tschatzl
parents: 53090
diff changeset
   100
  // Print a message about periodic GC configuration.
528207d2e73e 8216490: Spammy periodic GC log message contains random time stamp with periodic gc disabled
tschatzl
parents: 53090
diff changeset
   101
  if (G1PeriodicGCInterval != 0) {
528207d2e73e 8216490: Spammy periodic GC log message contains random time stamp with periodic gc disabled
tschatzl
parents: 53090
diff changeset
   102
    log_info(gc)("Periodic GC enabled with interval " UINTX_FORMAT "ms", G1PeriodicGCInterval);
528207d2e73e 8216490: Spammy periodic GC log message contains random time stamp with periodic gc disabled
tschatzl
parents: 53090
diff changeset
   103
  } else {
528207d2e73e 8216490: Spammy periodic GC log message contains random time stamp with periodic gc disabled
tschatzl
parents: 53090
diff changeset
   104
    log_info(gc)("Periodic GC disabled");
528207d2e73e 8216490: Spammy periodic GC log message contains random time stamp with periodic gc disabled
tschatzl
parents: 53090
diff changeset
   105
  }
528207d2e73e 8216490: Spammy periodic GC log message contains random time stamp with periodic gc disabled
tschatzl
parents: 53090
diff changeset
   106
37081
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 37039
diff changeset
   107
  while (!should_terminate()) {
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   108
    sample_young_list_rs_lengths();
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   109
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   110
    if (os::supports_vtime()) {
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   111
      _vtime_accum = (os::elapsedVTime() - vtime_start);
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   112
    } else {
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   113
      _vtime_accum = 0.0;
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   114
    }
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   115
52918
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
   116
    check_for_periodic_gc();
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
   117
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   118
    sleep_before_next_cycle();
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   119
  }
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   120
}
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   121
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   122
void G1YoungRemSetSamplingThread::stop_service() {
36378
d63bca5c1439 8140600: Convert unnecessarily malloc'd Monitors to value members
drwhite
parents: 36365
diff changeset
   123
  MutexLockerEx x(&_monitor, Mutex::_no_safepoint_check_flag);
d63bca5c1439 8140600: Convert unnecessarily malloc'd Monitors to value members
drwhite
parents: 36365
diff changeset
   124
  _monitor.notify();
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   125
}
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   126
39698
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   127
class G1YoungRemSetSamplingClosure : public HeapRegionClosure {
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   128
  SuspendibleThreadSetJoiner* _sts;
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   129
  size_t _regions_visited;
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   130
  size_t _sampled_rs_lengths;
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   131
public:
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   132
  G1YoungRemSetSamplingClosure(SuspendibleThreadSetJoiner* sts) :
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   133
    HeapRegionClosure(), _sts(sts), _regions_visited(0), _sampled_rs_lengths(0) { }
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   134
48969
jwilhelm
parents: 48890
diff changeset
   135
  virtual bool do_heap_region(HeapRegion* r) {
39698
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   136
    size_t rs_length = r->rem_set()->occupied();
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   137
    _sampled_rs_lengths += rs_length;
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   138
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   139
    // Update the collection set policy information for this region
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   140
    G1CollectedHeap::heap()->collection_set()->update_young_region_prediction(r, rs_length);
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   141
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   142
    _regions_visited++;
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   143
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   144
    if (_regions_visited == 10) {
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   145
      if (_sts->should_yield()) {
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   146
        _sts->yield();
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   147
        // A gc may have occurred and our sampling data is stale and further
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   148
        // traversal of the collection set is unsafe
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   149
        return true;
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   150
      }
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   151
      _regions_visited = 0;
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   152
    }
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   153
    return false;
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   154
  }
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   155
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   156
  size_t sampled_rs_lengths() const { return _sampled_rs_lengths; }
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   157
};
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   158
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   159
void G1YoungRemSetSamplingThread::sample_young_list_rs_lengths() {
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   160
  SuspendibleThreadSetJoiner sts;
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   161
  G1CollectedHeap* g1h = G1CollectedHeap::heap();
37985
539c597ee0fa 8154154: Separate G1 specific policy code from the CollectorPolicy class hierarchy
mgerdin
parents: 37081
diff changeset
   162
  G1Policy* g1p = g1h->g1_policy();
39698
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   163
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   164
  if (g1p->adaptive_young_list_length()) {
39698
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   165
    G1YoungRemSetSamplingClosure cl(&sts);
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   166
39698
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   167
    G1CollectionSet* g1cs = g1h->collection_set();
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   168
    g1cs->iterate(&cl);
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   169
48969
jwilhelm
parents: 48890
diff changeset
   170
    if (cl.is_complete()) {
39698
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   171
      g1p->revise_young_list_target_length_if_necessary(cl.sampled_rs_lengths());
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   172
    }
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   173
  }
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   174
}