src/hotspot/share/gc/g1/g1YoungRemSetSamplingThread.cpp
author tschatzl
Mon, 10 Dec 2018 10:25:27 +0100
changeset 52918 f94c7929a44b
parent 48969 7eb296a8ce2c
child 53034 de99beff5c0e
child 53090 759266b1c89b
permissions -rw-r--r--
8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1 Summary: Issue optional, default enabled, concurrent cycles when the VM is idle to reclaim unused internal and Java heap memory. Reviewed-by: sjohanss, sangheki Contributed-by: Rodrigo Bruno <rbruno@gsd.inesc-id.pt>, Ruslan Synytsky <rs@jelastic.com>, Thomas Schatzl <thomas.schatzl@oracle.com>
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.
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    64
  uintx time_since_last_gc;
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    65
  if ((G1PeriodicGCInterval == 0) ||
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    66
      ((time_since_last_gc = (uintx)Universe::heap()->millis_since_last_gc()) < G1PeriodicGCInterval)) {
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    67
    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
    68
                            time_since_last_gc, G1PeriodicGCInterval);
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    69
    return false;
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
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    72
  // 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
    73
  double recent_load;
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    74
  if ((G1PeriodicGCSystemLoadThreshold > 0) &&
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    75
      (os::loadavg(&recent_load, 1) == -1 || recent_load > G1PeriodicGCSystemLoadThreshold)) {
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    76
    log_debug(gc, periodic)("Load %1.2f is higher than threshold " UINTX_FORMAT ". Skipping.",
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    77
                            recent_load, G1PeriodicGCSystemLoadThreshold);
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    78
    return false;
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
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    81
  return true;
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
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    84
void G1YoungRemSetSamplingThread::check_for_periodic_gc(){
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    85
  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
    86
    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
    87
    if (should_start_periodic_gc()) {
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    88
      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
    89
    }
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
    90
    _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
    91
  }
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
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    94
void G1YoungRemSetSamplingThread::run_service() {
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    95
  double vtime_start = os::elapsedVTime();
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    96
37081
7656f5356a5d 8140257: Add support for "gc service threads" to ConcurrentGCThread
drwhite
parents: 37039
diff changeset
    97
  while (!should_terminate()) {
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    98
    sample_young_list_rs_lengths();
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    99
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   100
    if (os::supports_vtime()) {
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   101
      _vtime_accum = (os::elapsedVTime() - vtime_start);
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   102
    } else {
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   103
      _vtime_accum = 0.0;
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   104
    }
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   105
52918
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
   106
    check_for_periodic_gc();
f94c7929a44b 8212657: Implementation of JDK-8204089 Promptly Return Unused Committed Memory from G1
tschatzl
parents: 48969
diff changeset
   107
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   108
    sleep_before_next_cycle();
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
}
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   111
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   112
void G1YoungRemSetSamplingThread::stop_service() {
36378
d63bca5c1439 8140600: Convert unnecessarily malloc'd Monitors to value members
drwhite
parents: 36365
diff changeset
   113
  MutexLockerEx x(&_monitor, Mutex::_no_safepoint_check_flag);
d63bca5c1439 8140600: Convert unnecessarily malloc'd Monitors to value members
drwhite
parents: 36365
diff changeset
   114
  _monitor.notify();
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   115
}
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   116
39698
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   117
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
   118
  SuspendibleThreadSetJoiner* _sts;
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   119
  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
   120
  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
   121
public:
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   122
  G1YoungRemSetSamplingClosure(SuspendibleThreadSetJoiner* sts) :
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   123
    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
   124
48969
jwilhelm
parents: 48890
diff changeset
   125
  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
   126
    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
   127
    _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
   128
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   129
    // 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
   130
    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
   131
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   132
    _regions_visited++;
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   133
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   134
    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
   135
      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
   136
        _sts->yield();
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   137
        // 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
   138
        // 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
   139
        return true;
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   140
      }
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   141
      _regions_visited = 0;
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   142
    }
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   143
    return false;
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   144
  }
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   145
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   146
  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
   147
};
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   148
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   149
void G1YoungRemSetSamplingThread::sample_young_list_rs_lengths() {
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   150
  SuspendibleThreadSetJoiner sts;
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   151
  G1CollectedHeap* g1h = G1CollectedHeap::heap();
37985
539c597ee0fa 8154154: Separate G1 specific policy code from the CollectorPolicy class hierarchy
mgerdin
parents: 37081
diff changeset
   152
  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
   153
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   154
  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
   155
    G1YoungRemSetSamplingClosure cl(&sts);
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   156
39698
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   157
    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
   158
    g1cs->iterate(&cl);
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   159
48969
jwilhelm
parents: 48890
diff changeset
   160
    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
   161
      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
   162
    }
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   163
  }
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   164
}