hotspot/src/share/vm/gc/g1/concurrentG1Refine.cpp
author kbarrett
Tue, 30 Aug 2016 23:48:16 -0400
changeset 40892 330a02d935ad
parent 38172 90f405aac699
child 46653 d72083d17b19
permissions -rw-r--r--
8156500: Move Reference pending list into VM to prevent deadlocks Summary: Move reference pending list and locking into VM Reviewed-by: coleenp, dholmes, dcubed, mchung, plevart Contributed-by: kim.barrett@oracle.com, per.liden@oracle.com
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
/*
36371
fd81a4f0ea00 8139651: ConcurrentG1Refine uses ints for many of its members that should be unsigned types
jprovino
parents: 33608
diff changeset
     2
 * Copyright (c) 2001, 2016, 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: 5033
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5033
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: 5033
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: 6247
diff changeset
    25
#include "precompiled.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 27880
diff changeset
    26
#include "gc/g1/concurrentG1Refine.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 27880
diff changeset
    27
#include "gc/g1/concurrentG1RefineThread.hpp"
38172
90f405aac699 8155524: HotCardCache shouldn't be part of ConcurrentG1Refine
kbarrett
parents: 37985
diff changeset
    28
#include "gc/g1/g1YoungRemSetSamplingThread.hpp"
90f405aac699 8155524: HotCardCache shouldn't be part of ConcurrentG1Refine
kbarrett
parents: 37985
diff changeset
    29
#include "logging/log.hpp"
22220
eb467dfb9585 8029326: G1 does not check if threads gets created
ehelin
parents: 17854
diff changeset
    30
#include "runtime/java.hpp"
38172
90f405aac699 8155524: HotCardCache shouldn't be part of ConcurrentG1Refine
kbarrett
parents: 37985
diff changeset
    31
#include "runtime/thread.hpp"
37510
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    32
#include "utilities/debug.hpp"
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    33
#include "utilities/globalDefinitions.hpp"
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    34
#include "utilities/pair.hpp"
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    35
#include <math.h>
8926
717a49db1743 7026932: G1: No need to abort VM when card count cache expansion fails
johnc
parents: 8683
diff changeset
    36
37510
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    37
// Arbitrary but large limits, to simplify some of the zone calculations.
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    38
// The general idea is to allow expressions like
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    39
//   MIN2(x OP y, max_XXX_zone)
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    40
// without needing to check for overflow in "x OP y", because the
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    41
// ranges for x and y have been restricted.
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    42
STATIC_ASSERT(sizeof(LP64_ONLY(jint) NOT_LP64(jshort)) <= (sizeof(size_t)/2));
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    43
const size_t max_yellow_zone = LP64_ONLY(max_jint) NOT_LP64(max_jshort);
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    44
const size_t max_green_zone = max_yellow_zone / 2;
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    45
const size_t max_red_zone = INT_MAX; // For dcqs.set_max_completed_queue.
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    46
STATIC_ASSERT(max_yellow_zone <= max_red_zone);
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    47
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    48
// Range check assertions for green zone values.
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    49
#define assert_zone_constraints_g(green)                        \
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    50
  do {                                                          \
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    51
    size_t azc_g_green = (green);                               \
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    52
    assert(azc_g_green <= max_green_zone,                       \
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    53
           "green exceeds max: " SIZE_FORMAT, azc_g_green);     \
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    54
  } while (0)
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    55
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    56
// Range check assertions for green and yellow zone values.
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    57
#define assert_zone_constraints_gy(green, yellow)                       \
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    58
  do {                                                                  \
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    59
    size_t azc_gy_green = (green);                                      \
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    60
    size_t azc_gy_yellow = (yellow);                                    \
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    61
    assert_zone_constraints_g(azc_gy_green);                            \
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    62
    assert(azc_gy_yellow <= max_yellow_zone,                            \
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    63
           "yellow exceeds max: " SIZE_FORMAT, azc_gy_yellow);          \
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    64
    assert(azc_gy_green <= azc_gy_yellow,                               \
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    65
           "green (" SIZE_FORMAT ") exceeds yellow (" SIZE_FORMAT ")",  \
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    66
           azc_gy_green, azc_gy_yellow);                                \
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    67
  } while (0)
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    68
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    69
// Range check assertions for green, yellow, and red zone values.
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    70
#define assert_zone_constraints_gyr(green, yellow, red)                 \
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    71
  do {                                                                  \
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    72
    size_t azc_gyr_green = (green);                                     \
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    73
    size_t azc_gyr_yellow = (yellow);                                   \
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    74
    size_t azc_gyr_red = (red);                                         \
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    75
    assert_zone_constraints_gy(azc_gyr_green, azc_gyr_yellow);          \
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    76
    assert(azc_gyr_red <= max_red_zone,                                 \
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    77
           "red exceeds max: " SIZE_FORMAT, azc_gyr_red);               \
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    78
    assert(azc_gyr_yellow <= azc_gyr_red,                               \
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    79
           "yellow (" SIZE_FORMAT ") exceeds red (" SIZE_FORMAT ")",    \
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    80
           azc_gyr_yellow, azc_gyr_red);                                \
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    81
  } while (0)
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    82
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    83
// Logging tag sequence for refinement control updates.
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    84
#define CTRL_TAGS gc, ergo, refine
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    85
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    86
// For logging zone values, ensuring consistency of level and tags.
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    87
#define LOG_ZONES(...) log_debug( CTRL_TAGS )(__VA_ARGS__)
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    88
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    89
// Package for pair of refinement thread activation and deactivation
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    90
// thresholds.  The activation and deactivation levels are resp. the first
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    91
// and second values of the pair.
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    92
typedef Pair<size_t, size_t> Thresholds;
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    93
inline size_t activation_level(const Thresholds& t) { return t.first; }
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    94
inline size_t deactivation_level(const Thresholds& t) { return t.second; }
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    95
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    96
static Thresholds calc_thresholds(size_t green_zone,
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    97
                                  size_t yellow_zone,
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    98
                                  uint worker_i) {
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
    99
  double yellow_size = yellow_zone - green_zone;
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   100
  double step = yellow_size / ConcurrentG1Refine::thread_num();
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   101
  if (worker_i == 0) {
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   102
    // Potentially activate worker 0 more aggressively, to keep
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   103
    // available buffers near green_zone value.  When yellow_size is
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   104
    // large we don't want to allow a full step to accumulate before
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   105
    // doing any processing, as that might lead to significantly more
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   106
    // than green_zone buffers to be processed by update_rs.
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   107
    step = MIN2(step, ParallelGCThreads / 2.0);
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   108
  }
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   109
  size_t activate_offset = static_cast<size_t>(ceil(step * (worker_i + 1)));
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   110
  size_t deactivate_offset = static_cast<size_t>(floor(step * worker_i));
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   111
  return Thresholds(green_zone + activate_offset,
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   112
                    green_zone + deactivate_offset);
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   113
}
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   114
38172
90f405aac699 8155524: HotCardCache shouldn't be part of ConcurrentG1Refine
kbarrett
parents: 37985
diff changeset
   115
ConcurrentG1Refine::ConcurrentG1Refine(size_t green_zone,
37510
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   116
                                       size_t yellow_zone,
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   117
                                       size_t red_zone,
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   118
                                       size_t min_yellow_zone_size) :
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 32738
diff changeset
   119
  _threads(NULL),
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 32738
diff changeset
   120
  _sample_thread(NULL),
37510
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   121
  _n_worker_threads(thread_num()),
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   122
  _green_zone(green_zone),
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   123
  _yellow_zone(yellow_zone),
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   124
  _red_zone(red_zone),
38172
90f405aac699 8155524: HotCardCache shouldn't be part of ConcurrentG1Refine
kbarrett
parents: 37985
diff changeset
   125
  _min_yellow_zone_size(min_yellow_zone_size)
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   126
{
37510
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   127
  assert_zone_constraints_gyr(green_zone, yellow_zone, red_zone);
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   128
}
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   129
37510
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   130
static size_t calc_min_yellow_zone_size() {
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   131
  size_t step = G1ConcRefinementThresholdStep;
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   132
  uint n_workers = ConcurrentG1Refine::thread_num();
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   133
  if ((max_yellow_zone / step) < n_workers) {
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   134
    return max_yellow_zone;
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   135
  } else {
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   136
    return step * n_workers;
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   137
  }
37510
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   138
}
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   139
37510
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   140
static size_t calc_init_green_zone() {
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   141
  size_t green = G1ConcRefinementGreenZone;
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   142
  if (FLAG_IS_DEFAULT(G1ConcRefinementGreenZone)) {
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   143
    green = ParallelGCThreads;
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   144
  }
37510
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   145
  return MIN2(green, max_green_zone);
32738
a1adf25202fd 8135025: Error message is repeated for large value at G1ConcRefinementThreads
sangheki
parents: 30876
diff changeset
   146
}
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents: 13289
diff changeset
   147
37510
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   148
static size_t calc_init_yellow_zone(size_t green, size_t min_size) {
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   149
  size_t config = G1ConcRefinementYellowZone;
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   150
  size_t size = 0;
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   151
  if (FLAG_IS_DEFAULT(G1ConcRefinementYellowZone)) {
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   152
    size = green * 2;
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   153
  } else if (green < config) {
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   154
    size = config - green;
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   155
  }
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   156
  size = MAX2(size, min_size);
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   157
  size = MIN2(size, max_yellow_zone);
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   158
  return MIN2(green + size, max_yellow_zone);
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   159
}
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   160
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   161
static size_t calc_init_red_zone(size_t green, size_t yellow) {
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   162
  size_t size = yellow - green;
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   163
  if (!FLAG_IS_DEFAULT(G1ConcRefinementRedZone)) {
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   164
    size_t config = G1ConcRefinementRedZone;
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   165
    if (yellow < config) {
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   166
      size = MAX2(size, config - yellow);
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   167
    }
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   168
  }
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   169
  return MIN2(yellow + size, max_red_zone);
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   170
}
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   171
38172
90f405aac699 8155524: HotCardCache shouldn't be part of ConcurrentG1Refine
kbarrett
parents: 37985
diff changeset
   172
ConcurrentG1Refine* ConcurrentG1Refine::create(CardTableEntryClosure* refine_closure,
37510
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   173
                                               jint* ecode) {
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   174
  size_t min_yellow_zone_size = calc_min_yellow_zone_size();
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   175
  size_t green_zone = calc_init_green_zone();
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   176
  size_t yellow_zone = calc_init_yellow_zone(green_zone, min_yellow_zone_size);
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   177
  size_t red_zone = calc_init_red_zone(green_zone, yellow_zone);
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   178
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   179
  LOG_ZONES("Initial Refinement Zones: "
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   180
            "green: " SIZE_FORMAT ", "
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   181
            "yellow: " SIZE_FORMAT ", "
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   182
            "red: " SIZE_FORMAT ", "
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   183
            "min yellow size: " SIZE_FORMAT,
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   184
            green_zone, yellow_zone, red_zone, min_yellow_zone_size);
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   185
38172
90f405aac699 8155524: HotCardCache shouldn't be part of ConcurrentG1Refine
kbarrett
parents: 37985
diff changeset
   186
  ConcurrentG1Refine* cg1r = new ConcurrentG1Refine(green_zone,
37510
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   187
                                                    yellow_zone,
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   188
                                                    red_zone,
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   189
                                                    min_yellow_zone_size);
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   190
32738
a1adf25202fd 8135025: Error message is repeated for large value at G1ConcRefinementThreads
sangheki
parents: 30876
diff changeset
   191
  if (cg1r == NULL) {
a1adf25202fd 8135025: Error message is repeated for large value at G1ConcRefinementThreads
sangheki
parents: 30876
diff changeset
   192
    *ecode = JNI_ENOMEM;
a1adf25202fd 8135025: Error message is repeated for large value at G1ConcRefinementThreads
sangheki
parents: 30876
diff changeset
   193
    vm_shutdown_during_initialization("Could not create ConcurrentG1Refine");
a1adf25202fd 8135025: Error message is repeated for large value at G1ConcRefinementThreads
sangheki
parents: 30876
diff changeset
   194
    return NULL;
a1adf25202fd 8135025: Error message is repeated for large value at G1ConcRefinementThreads
sangheki
parents: 30876
diff changeset
   195
  }
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents: 13289
diff changeset
   196
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 32738
diff changeset
   197
  cg1r->_threads = NEW_C_HEAP_ARRAY_RETURN_NULL(ConcurrentG1RefineThread*, cg1r->_n_worker_threads, mtGC);
32738
a1adf25202fd 8135025: Error message is repeated for large value at G1ConcRefinementThreads
sangheki
parents: 30876
diff changeset
   198
  if (cg1r->_threads == NULL) {
a1adf25202fd 8135025: Error message is repeated for large value at G1ConcRefinementThreads
sangheki
parents: 30876
diff changeset
   199
    *ecode = JNI_ENOMEM;
a1adf25202fd 8135025: Error message is repeated for large value at G1ConcRefinementThreads
sangheki
parents: 30876
diff changeset
   200
    vm_shutdown_during_initialization("Could not allocate an array for ConcurrentG1RefineThread");
a1adf25202fd 8135025: Error message is repeated for large value at G1ConcRefinementThreads
sangheki
parents: 30876
diff changeset
   201
    return NULL;
a1adf25202fd 8135025: Error message is repeated for large value at G1ConcRefinementThreads
sangheki
parents: 30876
diff changeset
   202
  }
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents: 13289
diff changeset
   203
23855
c4574075402c 8016302: Change type of the number of GC workers to unsigned int (2)
vkempik
parents: 22551
diff changeset
   204
  uint worker_id_offset = DirtyCardQueueSet::num_par_ids();
17327
4bd0581aa231 7176479: G1: JVM crashes on T5-8 system with 1.5 TB heap
johnc
parents: 13289
diff changeset
   205
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   206
  ConcurrentG1RefineThread *next = NULL;
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 32738
diff changeset
   207
  for (uint i = cg1r->_n_worker_threads - 1; i != UINT_MAX; i--) {
37510
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   208
    Thresholds thresholds = calc_thresholds(green_zone, yellow_zone, i);
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   209
    ConcurrentG1RefineThread* t =
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   210
      new ConcurrentG1RefineThread(cg1r,
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   211
                                   next,
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   212
                                   refine_closure,
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   213
                                   worker_id_offset,
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   214
                                   i,
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   215
                                   activation_level(thresholds),
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   216
                                   deactivation_level(thresholds));
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   217
    assert(t != NULL, "Conc refine should have been created");
22220
eb467dfb9585 8029326: G1 does not check if threads gets created
ehelin
parents: 17854
diff changeset
   218
    if (t->osthread() == NULL) {
32738
a1adf25202fd 8135025: Error message is repeated for large value at G1ConcRefinementThreads
sangheki
parents: 30876
diff changeset
   219
      *ecode = JNI_ENOMEM;
a1adf25202fd 8135025: Error message is repeated for large value at G1ConcRefinementThreads
sangheki
parents: 30876
diff changeset
   220
      vm_shutdown_during_initialization("Could not create ConcurrentG1RefineThread");
a1adf25202fd 8135025: Error message is repeated for large value at G1ConcRefinementThreads
sangheki
parents: 30876
diff changeset
   221
      return NULL;
22220
eb467dfb9585 8029326: G1 does not check if threads gets created
ehelin
parents: 17854
diff changeset
   222
    }
eb467dfb9585 8029326: G1 does not check if threads gets created
ehelin
parents: 17854
diff changeset
   223
32738
a1adf25202fd 8135025: Error message is repeated for large value at G1ConcRefinementThreads
sangheki
parents: 30876
diff changeset
   224
    assert(t->cg1r() == cg1r, "Conc refine thread should refer to this");
a1adf25202fd 8135025: Error message is repeated for large value at G1ConcRefinementThreads
sangheki
parents: 30876
diff changeset
   225
    cg1r->_threads[i] = t;
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   226
    next = t;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   227
  }
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 32738
diff changeset
   228
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 32738
diff changeset
   229
  cg1r->_sample_thread = new G1YoungRemSetSamplingThread();
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 32738
diff changeset
   230
  if (cg1r->_sample_thread->osthread() == NULL) {
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 32738
diff changeset
   231
    *ecode = JNI_ENOMEM;
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 32738
diff changeset
   232
    vm_shutdown_during_initialization("Could not create G1YoungRemSetSamplingThread");
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 32738
diff changeset
   233
    return NULL;
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 32738
diff changeset
   234
  }
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 32738
diff changeset
   235
32738
a1adf25202fd 8135025: Error message is repeated for large value at G1ConcRefinementThreads
sangheki
parents: 30876
diff changeset
   236
  *ecode = JNI_OK;
a1adf25202fd 8135025: Error message is repeated for large value at G1ConcRefinementThreads
sangheki
parents: 30876
diff changeset
   237
  return cg1r;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   238
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   239
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   240
void ConcurrentG1Refine::stop() {
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 32738
diff changeset
   241
  for (uint i = 0; i < _n_worker_threads; i++) {
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 32738
diff changeset
   242
    _threads[i]->stop();
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   243
  }
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 32738
diff changeset
   244
  _sample_thread->stop();
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   245
}
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   246
37510
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   247
void ConcurrentG1Refine::update_thread_thresholds() {
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 32738
diff changeset
   248
  for (uint i = 0; i < _n_worker_threads; i++) {
37510
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   249
    Thresholds thresholds = calc_thresholds(_green_zone, _yellow_zone, i);
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   250
    _threads[i]->update_thresholds(activation_level(thresholds),
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   251
                                   deactivation_level(thresholds));
4481
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   252
  }
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   253
}
de92ec484f5e 6862387: tune concurrent refinement further
iveresov
parents: 4022
diff changeset
   254
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   255
ConcurrentG1Refine::~ConcurrentG1Refine() {
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 32738
diff changeset
   256
  for (uint i = 0; i < _n_worker_threads; i++) {
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 32738
diff changeset
   257
    delete _threads[i];
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   258
  }
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 32738
diff changeset
   259
  FREE_C_HEAP_ARRAY(ConcurrentG1RefineThread*, _threads);
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 32738
diff changeset
   260
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 32738
diff changeset
   261
  delete _sample_thread;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   262
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   263
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 2249
diff changeset
   264
void ConcurrentG1Refine::threads_do(ThreadClosure *tc) {
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 32738
diff changeset
   265
  worker_threads_do(tc);
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 32738
diff changeset
   266
  tc->do_thread(_sample_thread);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   267
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   268
17854
d65bc1546091 8013895: G1: G1SummarizeRSetStats output on Linux needs improvemen
tschatzl
parents: 17327
diff changeset
   269
void ConcurrentG1Refine::worker_threads_do(ThreadClosure * tc) {
37510
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   270
  for (uint i = 0; i < _n_worker_threads; i++) {
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 32738
diff changeset
   271
    tc->do_thread(_threads[i]);
17854
d65bc1546091 8013895: G1: G1SummarizeRSetStats output on Linux needs improvemen
tschatzl
parents: 17327
diff changeset
   272
  }
d65bc1546091 8013895: G1: G1SummarizeRSetStats output on Linux needs improvemen
tschatzl
parents: 17327
diff changeset
   273
}
d65bc1546091 8013895: G1: G1SummarizeRSetStats output on Linux needs improvemen
tschatzl
parents: 17327
diff changeset
   274
23855
c4574075402c 8016302: Change type of the number of GC workers to unsigned int (2)
vkempik
parents: 22551
diff changeset
   275
uint ConcurrentG1Refine::thread_num() {
26932
33d6fa41d290 8047976: Ergonomics for GC thread counts should update the flags
jwilhelm
parents: 26160
diff changeset
   276
  return G1ConcRefinementThreads;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   277
}
4022
2ec87d5043f7 6885041: G1: inconsistent thread dump
tonyp
parents: 3590
diff changeset
   278
2ec87d5043f7 6885041: G1: inconsistent thread dump
tonyp
parents: 3590
diff changeset
   279
void ConcurrentG1Refine::print_worker_threads_on(outputStream* st) const {
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 32738
diff changeset
   280
  for (uint i = 0; i < _n_worker_threads; ++i) {
4022
2ec87d5043f7 6885041: G1: inconsistent thread dump
tonyp
parents: 3590
diff changeset
   281
    _threads[i]->print_on(st);
2ec87d5043f7 6885041: G1: inconsistent thread dump
tonyp
parents: 3590
diff changeset
   282
    st->cr();
2ec87d5043f7 6885041: G1: inconsistent thread dump
tonyp
parents: 3590
diff changeset
   283
  }
33608
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 32738
diff changeset
   284
  _sample_thread->print_on(st);
7afc768e4d62 8138920: Refactor the sampling thread from ConcurrentG1RefineThread
drwhite
parents: 32738
diff changeset
   285
  st->cr();
4022
2ec87d5043f7 6885041: G1: inconsistent thread dump
tonyp
parents: 3590
diff changeset
   286
}
37158
b882bbfa1af0 8152101: Move G1 concurrent refinement adjustment code out of G1CollectorPolicy
mgerdin
parents: 36371
diff changeset
   287
37510
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   288
static size_t calc_new_green_zone(size_t green,
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   289
                                  double update_rs_time,
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   290
                                  size_t update_rs_processed_buffers,
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   291
                                  double goal_ms) {
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   292
  // Adjust green zone based on whether we're meeting the time goal.
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   293
  // Limit to max_green_zone.
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   294
  const double inc_k = 1.1, dec_k = 0.9;
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   295
  if (update_rs_time > goal_ms) {
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   296
    if (green > 0) {
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   297
      green = static_cast<size_t>(green * dec_k);
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   298
    }
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   299
  } else if (update_rs_time < goal_ms &&
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   300
             update_rs_processed_buffers > green) {
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   301
    green = static_cast<size_t>(MAX2(green * inc_k, green + 1.0));
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   302
    green = MIN2(green, max_green_zone);
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   303
  }
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   304
  return green;
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   305
}
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   306
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   307
static size_t calc_new_yellow_zone(size_t green, size_t min_yellow_size) {
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   308
  size_t size = green * 2;
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   309
  size = MAX2(size, min_yellow_size);
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   310
  return MIN2(green + size, max_yellow_zone);
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   311
}
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   312
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   313
static size_t calc_new_red_zone(size_t green, size_t yellow) {
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   314
  return MIN2(yellow + (yellow - green), max_red_zone);
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   315
}
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   316
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   317
void ConcurrentG1Refine::update_zones(double update_rs_time,
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   318
                                      size_t update_rs_processed_buffers,
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   319
                                      double goal_ms) {
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   320
  log_trace( CTRL_TAGS )("Updating Refinement Zones: "
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   321
                         "update_rs time: %.3fms, "
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   322
                         "update_rs buffers: " SIZE_FORMAT ", "
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   323
                         "update_rs goal time: %.3fms",
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   324
                         update_rs_time,
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   325
                         update_rs_processed_buffers,
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   326
                         goal_ms);
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   327
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   328
  _green_zone = calc_new_green_zone(_green_zone,
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   329
                                    update_rs_time,
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   330
                                    update_rs_processed_buffers,
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   331
                                    goal_ms);
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   332
  _yellow_zone = calc_new_yellow_zone(_green_zone, _min_yellow_zone_size);
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   333
  _red_zone = calc_new_red_zone(_green_zone, _yellow_zone);
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   334
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   335
  assert_zone_constraints_gyr(_green_zone, _yellow_zone, _red_zone);
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   336
  LOG_ZONES("Updated Refinement Zones: "
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   337
            "green: " SIZE_FORMAT ", "
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   338
            "yellow: " SIZE_FORMAT ", "
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   339
            "red: " SIZE_FORMAT,
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   340
            _green_zone, _yellow_zone, _red_zone);
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   341
}
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   342
37158
b882bbfa1af0 8152101: Move G1 concurrent refinement adjustment code out of G1CollectorPolicy
mgerdin
parents: 36371
diff changeset
   343
void ConcurrentG1Refine::adjust(double update_rs_time,
37510
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   344
                                size_t update_rs_processed_buffers,
37158
b882bbfa1af0 8152101: Move G1 concurrent refinement adjustment code out of G1CollectorPolicy
mgerdin
parents: 36371
diff changeset
   345
                                double goal_ms) {
b882bbfa1af0 8152101: Move G1 concurrent refinement adjustment code out of G1CollectorPolicy
mgerdin
parents: 36371
diff changeset
   346
  DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
b882bbfa1af0 8152101: Move G1 concurrent refinement adjustment code out of G1CollectorPolicy
mgerdin
parents: 36371
diff changeset
   347
b882bbfa1af0 8152101: Move G1 concurrent refinement adjustment code out of G1CollectorPolicy
mgerdin
parents: 36371
diff changeset
   348
  if (G1UseAdaptiveConcRefinement) {
37510
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   349
    update_zones(update_rs_time, update_rs_processed_buffers, goal_ms);
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   350
    update_thread_thresholds();
37158
b882bbfa1af0 8152101: Move G1 concurrent refinement adjustment code out of G1CollectorPolicy
mgerdin
parents: 36371
diff changeset
   351
37510
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   352
    // Change the barrier params
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   353
    if (_n_worker_threads == 0) {
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   354
      // Disable dcqs notification when there are no threads to notify.
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   355
      dcqs.set_process_completed_threshold(INT_MAX);
37158
b882bbfa1af0 8152101: Move G1 concurrent refinement adjustment code out of G1CollectorPolicy
mgerdin
parents: 36371
diff changeset
   356
    } else {
37510
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   357
      // Worker 0 is the primary; wakeup is via dcqs notification.
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   358
      STATIC_ASSERT(max_yellow_zone <= INT_MAX);
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   359
      size_t activate = _threads[0]->activation_threshold();
cf066fe4531b 8133051: Concurrent refinement threads may be activated and deactivated at random
kbarrett
parents: 37158
diff changeset
   360
      dcqs.set_process_completed_threshold((int)activate);
37158
b882bbfa1af0 8152101: Move G1 concurrent refinement adjustment code out of G1CollectorPolicy
mgerdin
parents: 36371
diff changeset
   361
    }
b882bbfa1af0 8152101: Move G1 concurrent refinement adjustment code out of G1CollectorPolicy
mgerdin
parents: 36371
diff changeset
   362
    dcqs.set_max_completed_queue((int)red_zone());
b882bbfa1af0 8152101: Move G1 concurrent refinement adjustment code out of G1CollectorPolicy
mgerdin
parents: 36371
diff changeset
   363
  }
b882bbfa1af0 8152101: Move G1 concurrent refinement adjustment code out of G1CollectorPolicy
mgerdin
parents: 36371
diff changeset
   364
b882bbfa1af0 8152101: Move G1 concurrent refinement adjustment code out of G1CollectorPolicy
mgerdin
parents: 36371
diff changeset
   365
  size_t curr_queue_size = dcqs.completed_buffers_num();
b882bbfa1af0 8152101: Move G1 concurrent refinement adjustment code out of G1CollectorPolicy
mgerdin
parents: 36371
diff changeset
   366
  if (curr_queue_size >= yellow_zone()) {
b882bbfa1af0 8152101: Move G1 concurrent refinement adjustment code out of G1CollectorPolicy
mgerdin
parents: 36371
diff changeset
   367
    dcqs.set_completed_queue_padding(curr_queue_size);
b882bbfa1af0 8152101: Move G1 concurrent refinement adjustment code out of G1CollectorPolicy
mgerdin
parents: 36371
diff changeset
   368
  } else {
b882bbfa1af0 8152101: Move G1 concurrent refinement adjustment code out of G1CollectorPolicy
mgerdin
parents: 36371
diff changeset
   369
    dcqs.set_completed_queue_padding(0);
b882bbfa1af0 8152101: Move G1 concurrent refinement adjustment code out of G1CollectorPolicy
mgerdin
parents: 36371
diff changeset
   370
  }
b882bbfa1af0 8152101: Move G1 concurrent refinement adjustment code out of G1CollectorPolicy
mgerdin
parents: 36371
diff changeset
   371
  dcqs.notify_if_necessary();
b882bbfa1af0 8152101: Move G1 concurrent refinement adjustment code out of G1CollectorPolicy
mgerdin
parents: 36371
diff changeset
   372
}