hotspot/src/share/vm/gc/g1/g1YoungRemSetSamplingThread.cpp
author jprovino
Thu, 03 Mar 2016 12:20:22 -0500
changeset 36402 7c20aae43c41
parent 36378 d63bca5c1439
child 37039 79f62b89a7a6
permissions -rw-r--r--
8150984: Invalid VM argument causes crash -XX:G1ConcRefinementServiceIntervalMillis=2147483648 Summary: Change maximum range so it can't be negative Reviewed-by: kbarrett, sangheki
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
     1
/*
35916
23189249c2c1 8147884: Names of GC threads should be set before the threads start
asmotrak
parents: 33608
diff changeset
     2
 * Copyright (c) 2015, 2016, 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"
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    27
#include "gc/g1/g1CollectorPolicy.hpp"
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    28
#include "gc/g1/g1YoungRemSetSamplingThread.hpp"
36365
bcc9c9afda49 8150390: Move rs length sampling data to the sampling thread
mgerdin
parents: 35916
diff changeset
    29
#include "gc/g1/heapRegion.inline.hpp"
bcc9c9afda49 8150390: Move rs length sampling data to the sampling thread
mgerdin
parents: 35916
diff changeset
    30
#include "gc/g1/heapRegionRemSet.hpp"
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    31
#include "gc/g1/suspendibleThreadSet.hpp"
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    32
#include "runtime/mutexLocker.hpp"
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    33
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    34
void G1YoungRemSetSamplingThread::run() {
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    35
  initialize_in_thread();
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    36
  wait_for_universe_init();
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    37
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    38
  run_service();
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    39
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    40
  terminate();
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    41
}
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    42
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    43
void G1YoungRemSetSamplingThread::stop() {
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    44
  // it is ok to take late safepoints here, if needed
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    45
  {
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    46
    MutexLockerEx mu(Terminator_lock);
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    47
    _should_terminate = true;
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    48
  }
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    49
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    50
  stop_service();
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    51
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    52
  {
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    53
    MutexLockerEx mu(Terminator_lock);
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    54
    while (!_has_terminated) {
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    55
      Terminator_lock->wait();
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    56
    }
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    57
  }
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    58
}
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    59
36378
d63bca5c1439 8140600: Convert unnecessarily malloc'd Monitors to value members
drwhite
parents: 36365
diff changeset
    60
G1YoungRemSetSamplingThread::G1YoungRemSetSamplingThread() :
d63bca5c1439 8140600: Convert unnecessarily malloc'd Monitors to value members
drwhite
parents: 36365
diff changeset
    61
    ConcurrentGCThread(),
d63bca5c1439 8140600: Convert unnecessarily malloc'd Monitors to value members
drwhite
parents: 36365
diff changeset
    62
    _monitor(Mutex::nonleaf,
d63bca5c1439 8140600: Convert unnecessarily malloc'd Monitors to value members
drwhite
parents: 36365
diff changeset
    63
             "G1YoungRemSetSamplingThread monitor",
d63bca5c1439 8140600: Convert unnecessarily malloc'd Monitors to value members
drwhite
parents: 36365
diff changeset
    64
             true,
d63bca5c1439 8140600: Convert unnecessarily malloc'd Monitors to value members
drwhite
parents: 36365
diff changeset
    65
             Monitor::_safepoint_check_never) {
35916
23189249c2c1 8147884: Names of GC threads should be set before the threads start
asmotrak
parents: 33608
diff changeset
    66
  set_name("G1 Young RemSet Sampling");
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    67
  create_and_start();
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    68
}
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    69
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    70
void G1YoungRemSetSamplingThread::sleep_before_next_cycle() {
36378
d63bca5c1439 8140600: Convert unnecessarily malloc'd Monitors to value members
drwhite
parents: 36365
diff changeset
    71
  MutexLockerEx x(&_monitor, Mutex::_no_safepoint_check_flag);
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    72
  if (!_should_terminate) {
36402
7c20aae43c41 8150984: Invalid VM argument causes crash -XX:G1ConcRefinementServiceIntervalMillis=2147483648
jprovino
parents: 36378
diff changeset
    73
    uintx waitms = G1ConcRefinementServiceIntervalMillis; // 300, really should be?
36378
d63bca5c1439 8140600: Convert unnecessarily malloc'd Monitors to value members
drwhite
parents: 36365
diff changeset
    74
    _monitor.wait(Mutex::_no_safepoint_check_flag, waitms);
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    75
  }
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    76
}
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    77
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    78
void G1YoungRemSetSamplingThread::run_service() {
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    79
  double vtime_start = os::elapsedVTime();
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    80
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    81
  while (!_should_terminate) {
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    82
    sample_young_list_rs_lengths();
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    83
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    84
    if (os::supports_vtime()) {
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    85
      _vtime_accum = (os::elapsedVTime() - vtime_start);
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    86
    } else {
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    87
      _vtime_accum = 0.0;
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    88
    }
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    89
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    90
    sleep_before_next_cycle();
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    91
  }
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    92
}
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    93
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    94
void G1YoungRemSetSamplingThread::stop_service() {
36378
d63bca5c1439 8140600: Convert unnecessarily malloc'd Monitors to value members
drwhite
parents: 36365
diff changeset
    95
  MutexLockerEx x(&_monitor, Mutex::_no_safepoint_check_flag);
d63bca5c1439 8140600: Convert unnecessarily malloc'd Monitors to value members
drwhite
parents: 36365
diff changeset
    96
  _monitor.notify();
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    97
}
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    98
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
    99
void G1YoungRemSetSamplingThread::sample_young_list_rs_lengths() {
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   100
  SuspendibleThreadSetJoiner sts;
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   101
  G1CollectedHeap* g1h = G1CollectedHeap::heap();
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   102
  G1CollectorPolicy* g1p = g1h->g1_policy();
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   103
  if (g1p->adaptive_young_list_length()) {
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   104
    int regions_visited = 0;
36365
bcc9c9afda49 8150390: Move rs length sampling data to the sampling thread
mgerdin
parents: 35916
diff changeset
   105
    HeapRegion* hr = g1h->young_list()->first_region();
bcc9c9afda49 8150390: Move rs length sampling data to the sampling thread
mgerdin
parents: 35916
diff changeset
   106
    size_t sampled_rs_lengths = 0;
bcc9c9afda49 8150390: Move rs length sampling data to the sampling thread
mgerdin
parents: 35916
diff changeset
   107
bcc9c9afda49 8150390: Move rs length sampling data to the sampling thread
mgerdin
parents: 35916
diff changeset
   108
    while (hr != NULL) {
bcc9c9afda49 8150390: Move rs length sampling data to the sampling thread
mgerdin
parents: 35916
diff changeset
   109
      size_t rs_length = hr->rem_set()->occupied();
bcc9c9afda49 8150390: Move rs length sampling data to the sampling thread
mgerdin
parents: 35916
diff changeset
   110
      sampled_rs_lengths += rs_length;
bcc9c9afda49 8150390: Move rs length sampling data to the sampling thread
mgerdin
parents: 35916
diff changeset
   111
bcc9c9afda49 8150390: Move rs length sampling data to the sampling thread
mgerdin
parents: 35916
diff changeset
   112
      // The current region may not yet have been added to the
bcc9c9afda49 8150390: Move rs length sampling data to the sampling thread
mgerdin
parents: 35916
diff changeset
   113
      // incremental collection set (it gets added when it is
bcc9c9afda49 8150390: Move rs length sampling data to the sampling thread
mgerdin
parents: 35916
diff changeset
   114
      // retired as the current allocation region).
bcc9c9afda49 8150390: Move rs length sampling data to the sampling thread
mgerdin
parents: 35916
diff changeset
   115
      if (hr->in_collection_set()) {
bcc9c9afda49 8150390: Move rs length sampling data to the sampling thread
mgerdin
parents: 35916
diff changeset
   116
        // Update the collection set policy information for this region
bcc9c9afda49 8150390: Move rs length sampling data to the sampling thread
mgerdin
parents: 35916
diff changeset
   117
        g1p->update_incremental_cset_info(hr, rs_length);
bcc9c9afda49 8150390: Move rs length sampling data to the sampling thread
mgerdin
parents: 35916
diff changeset
   118
      }
bcc9c9afda49 8150390: Move rs length sampling data to the sampling thread
mgerdin
parents: 35916
diff changeset
   119
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   120
      ++regions_visited;
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
      // we try to yield every time we visit 10 regions
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   123
      if (regions_visited == 10) {
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   124
        if (sts.should_yield()) {
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   125
          sts.yield();
36365
bcc9c9afda49 8150390: Move rs length sampling data to the sampling thread
mgerdin
parents: 35916
diff changeset
   126
          // A gc may have occurred and our sampling data is stale and further
bcc9c9afda49 8150390: Move rs length sampling data to the sampling thread
mgerdin
parents: 35916
diff changeset
   127
          // traversal of the young list is unsafe
bcc9c9afda49 8150390: Move rs length sampling data to the sampling thread
mgerdin
parents: 35916
diff changeset
   128
          return;
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   129
        }
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   130
        regions_visited = 0;
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   131
      }
36365
bcc9c9afda49 8150390: Move rs length sampling data to the sampling thread
mgerdin
parents: 35916
diff changeset
   132
      hr = hr->get_next_young_region();
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   133
    }
36365
bcc9c9afda49 8150390: Move rs length sampling data to the sampling thread
mgerdin
parents: 35916
diff changeset
   134
    g1p->revise_young_list_target_length_if_necessary(sampled_rs_lengths);
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   135
  }
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents:
diff changeset
   136
}