src/hotspot/share/gc/shared/workerPolicy.cpp
author phh
Sat, 30 Nov 2019 14:33:05 -0800
changeset 59330 5b96c12f909d
parent 52904 d2f118d3f8e7
permissions -rw-r--r--
8234541: C1 emits an empty message when it inlines successfully Summary: Use "inline" as the message when successfull Reviewed-by: thartmann, mdoerr Contributed-by: navy.xliu@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
52904
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
     1
/*
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
     4
 *
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
     8
 *
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    13
 * accompanied this code).
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    14
 *
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    18
 *
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    21
 * questions.
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    22
 *
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    23
 */
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    24
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    25
#include "precompiled.hpp"
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    26
#include "gc/shared/collectedHeap.hpp"
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    27
#include "gc/shared/workerPolicy.hpp"
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    28
#include "logging/log.hpp"
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    29
#include "memory/universe.hpp"
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    30
#include "runtime/os.inline.hpp"
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    31
#include "runtime/vm_version.hpp"
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    32
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    33
bool WorkerPolicy::_debug_perturbation = false;
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    34
uint WorkerPolicy::_parallel_worker_threads = 0;
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    35
bool WorkerPolicy::_parallel_worker_threads_initialized = false;
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    36
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    37
uint WorkerPolicy::nof_parallel_worker_threads(uint num,
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    38
                                               uint den,
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    39
                                               uint switch_pt) {
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    40
  if (FLAG_IS_DEFAULT(ParallelGCThreads)) {
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    41
    assert(ParallelGCThreads == 0, "Default ParallelGCThreads is not 0");
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    42
    uint threads;
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    43
    // For very large machines, there are diminishing returns
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    44
    // for large numbers of worker threads.  Instead of
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    45
    // hogging the whole system, use a fraction of the workers for every
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    46
    // processor after the first 8.  For example, on a 72 cpu machine
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    47
    // and a chosen fraction of 5/8
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    48
    // use 8 + (72 - 8) * (5/8) == 48 worker threads.
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    49
    uint ncpus = (uint) os::initial_active_processor_count();
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    50
    threads = (ncpus <= switch_pt) ?
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    51
              ncpus :
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    52
              (switch_pt + ((ncpus - switch_pt) * num) / den);
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    53
#ifndef _LP64
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    54
    // On 32-bit binaries the virtual address space available to the JVM
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    55
    // is usually limited to 2-3 GB (depends on the platform).
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    56
    // Do not use up address space with too many threads (stacks and per-thread
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    57
    // data). Note that x86 apps running on Win64 have 2 stacks per thread.
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    58
    // GC may more generally scale down threads by max heap size (etc), but the
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    59
    // consequences of over-provisioning threads are higher on 32-bit JVMS,
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    60
    // so add hard limit here:
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    61
    threads = MIN2(threads, (2 * switch_pt));
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    62
#endif
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    63
    return threads;
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    64
  } else {
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    65
    return ParallelGCThreads;
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    66
  }
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    67
}
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    68
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    69
uint WorkerPolicy::calc_parallel_worker_threads() {
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    70
  uint den = VM_Version::parallel_worker_threads_denominator();
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    71
  return nof_parallel_worker_threads(5, den, 8);
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    72
}
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    73
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    74
uint WorkerPolicy::parallel_worker_threads() {
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    75
  if (!_parallel_worker_threads_initialized) {
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    76
    if (FLAG_IS_DEFAULT(ParallelGCThreads)) {
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    77
      _parallel_worker_threads = WorkerPolicy::calc_parallel_worker_threads();
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    78
    } else {
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    79
      _parallel_worker_threads = ParallelGCThreads;
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    80
    }
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    81
    _parallel_worker_threads_initialized = true;
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    82
  }
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    83
  return _parallel_worker_threads;
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    84
}
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    85
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    86
//  If the number of GC threads was set on the command line, use it.
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    87
//  Else
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    88
//    Calculate the number of GC threads based on the number of Java threads.
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    89
//    Calculate the number of GC threads based on the size of the heap.
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    90
//    Use the larger.
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    91
uint WorkerPolicy::calc_default_active_workers(uintx total_workers,
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    92
                                               const uintx min_workers,
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    93
                                               uintx active_workers,
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    94
                                               uintx application_workers) {
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    95
  // If the user has specifically set the number of GC threads, use them.
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    96
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    97
  // If the user has turned off using a dynamic number of GC threads
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    98
  // or the users has requested a specific number, set the active
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
    99
  // number of workers to all the workers.
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   100
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   101
  uintx new_active_workers = total_workers;
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   102
  uintx prev_active_workers = active_workers;
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   103
  uintx active_workers_by_JT = 0;
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   104
  uintx active_workers_by_heap_size = 0;
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   105
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   106
  // Always use at least min_workers but use up to
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   107
  // GCThreadsPerJavaThreads * application threads.
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   108
  active_workers_by_JT =
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   109
    MAX2((uintx) GCWorkersPerJavaThread * application_workers,
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   110
         min_workers);
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   111
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   112
  // Choose a number of GC threads based on the current size
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   113
  // of the heap.  This may be complicated because the size of
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   114
  // the heap depends on factors such as the throughput goal.
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   115
  // Still a large heap should be collected by more GC threads.
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   116
  active_workers_by_heap_size =
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   117
    MAX2((size_t) 2U, Universe::heap()->capacity() / HeapSizePerGCThread);
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   118
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   119
  uintx max_active_workers =
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   120
    MAX2(active_workers_by_JT, active_workers_by_heap_size);
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   121
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   122
  new_active_workers = MIN2(max_active_workers, (uintx) total_workers);
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   123
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   124
  // Increase GC workers instantly but decrease them more
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   125
  // slowly.
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   126
  if (new_active_workers < prev_active_workers) {
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   127
    new_active_workers =
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   128
      MAX2(min_workers, (prev_active_workers + new_active_workers) / 2);
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   129
  }
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   130
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   131
  // Check once more that the number of workers is within the limits.
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   132
  assert(min_workers <= total_workers, "Minimum workers not consistent with total workers");
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   133
  assert(new_active_workers >= min_workers, "Minimum workers not observed");
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   134
  assert(new_active_workers <= total_workers, "Total workers not observed");
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   135
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   136
  if (ForceDynamicNumberOfGCThreads) {
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   137
    // Assume this is debugging and jiggle the number of GC threads.
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   138
    if (new_active_workers == prev_active_workers) {
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   139
      if (new_active_workers < total_workers) {
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   140
        new_active_workers++;
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   141
      } else if (new_active_workers > min_workers) {
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   142
        new_active_workers--;
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   143
      }
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   144
    }
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   145
    if (new_active_workers == total_workers) {
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   146
      if (_debug_perturbation) {
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   147
        new_active_workers =  min_workers;
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   148
      }
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   149
      _debug_perturbation = !_debug_perturbation;
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   150
    }
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   151
    assert((new_active_workers <= ParallelGCThreads) &&
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   152
           (new_active_workers >= min_workers),
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   153
           "Jiggled active workers too much");
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   154
  }
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   155
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   156
  log_trace(gc, task)("WorkerPolicy::calc_default_active_workers() : "
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   157
    "active_workers(): " UINTX_FORMAT "  new_active_workers: " UINTX_FORMAT "  "
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   158
    "prev_active_workers: " UINTX_FORMAT "\n"
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   159
    " active_workers_by_JT: " UINTX_FORMAT "  active_workers_by_heap_size: " UINTX_FORMAT,
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   160
    active_workers, new_active_workers, prev_active_workers,
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   161
    active_workers_by_JT, active_workers_by_heap_size);
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   162
  assert(new_active_workers > 0, "Always need at least 1");
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   163
  return new_active_workers;
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   164
}
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   165
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   166
uint WorkerPolicy::calc_active_workers(uintx total_workers,
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   167
                                       uintx active_workers,
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   168
                                       uintx application_workers) {
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   169
  // If the user has specifically set the number of GC threads, use them.
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   170
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   171
  // If the user has turned off using a dynamic number of GC threads
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   172
  // or the users has requested a specific number, set the active
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   173
  // number of workers to all the workers.
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   174
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   175
  uint new_active_workers;
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   176
  if (!UseDynamicNumberOfGCThreads ||
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   177
     (!FLAG_IS_DEFAULT(ParallelGCThreads) && !ForceDynamicNumberOfGCThreads)) {
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   178
    new_active_workers = total_workers;
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   179
  } else {
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   180
    uintx min_workers = (total_workers == 1) ? 1 : 2;
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   181
    new_active_workers = calc_default_active_workers(total_workers,
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   182
                                                     min_workers,
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   183
                                                     active_workers,
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   184
                                                     application_workers);
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   185
  }
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   186
  assert(new_active_workers > 0, "Always need at least 1");
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   187
  return new_active_workers;
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   188
}
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   189
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   190
uint WorkerPolicy::calc_active_conc_workers(uintx total_workers,
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   191
                                            uintx active_workers,
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   192
                                            uintx application_workers) {
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   193
  if (!UseDynamicNumberOfGCThreads ||
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   194
     (!FLAG_IS_DEFAULT(ConcGCThreads) && !ForceDynamicNumberOfGCThreads)) {
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   195
    return ConcGCThreads;
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   196
  } else {
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   197
    uint no_of_gc_threads = calc_default_active_workers(total_workers,
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   198
                                                        1, /* Minimum number of workers */
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   199
                                                        active_workers,
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   200
                                                        application_workers);
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   201
    return no_of_gc_threads;
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   202
  }
d2f118d3f8e7 8213224: Move code related to GC threads calculation out of AdaptiveSizePolicy
manc
parents:
diff changeset
   203
}