hotspot/src/share/vm/gc/shared/workerManager.hpp
author jmasa
Thu, 19 May 2016 13:59:50 -0700
changeset 39704 157f39705057
parent 38216 250794c6f95f
child 40096 246c62cd9180
permissions -rw-r--r--
8157240: GC task trace logging is incomprehensible Reviewed-by: tschatzl, redestad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38216
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
     1
/*
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
     2
 * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
     4
 *
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
     7
 * published by the Free Software Foundation.
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
     8
 *
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    13
 * accompanied this code).
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    14
 *
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    18
 *
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    21
 * questions.
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    22
 *
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    23
 */
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    24
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    25
#ifndef SHARE_VM_GC_SHARED_WORKERMANAGER_HPP
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    26
#define SHARE_VM_GC_SHARED_WORKERMANAGER_HPP
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    27
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    28
#include "gc/shared/adaptiveSizePolicy.hpp"
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    29
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    30
class WorkerManager : public AllStatic {
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    31
 public:
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    32
  // Create additional workers as needed.
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    33
  //   active_workers - number of workers being requested for an upcoming
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    34
  // parallel task.
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    35
  //   total_workers - total number of workers.  This is the maximum
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    36
  // number possible.
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    37
  //   created_workers - number of workers already created.  This maybe
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    38
  // less than, equal to, or greater than active workers.  If greater than
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    39
  // or equal to active_workers, nothing is done.
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    40
  //   worker_type - type of thread.
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    41
  //   initializing - true if this is called to get the initial number of
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    42
  // GC workers.
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    43
  // If initializing is true, do a vm exit if the workers cannot be created.
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    44
  // The initializing = true case is for JVM start up and failing to
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    45
  // create all the worker at start should considered a problem so exit.
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    46
  // If initializing = false, there are already some number of worker
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    47
  // threads and a failure would not be optimal but should not be fatal.
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    48
  template <class WorkerType>
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    49
  static uint add_workers (WorkerType* holder,
39704
157f39705057 8157240: GC task trace logging is incomprehensible
jmasa
parents: 38216
diff changeset
    50
                           uint active_workers,
157f39705057 8157240: GC task trace logging is incomprehensible
jmasa
parents: 38216
diff changeset
    51
                           uint total_workers,
157f39705057 8157240: GC task trace logging is incomprehensible
jmasa
parents: 38216
diff changeset
    52
                           uint created_workers,
157f39705057 8157240: GC task trace logging is incomprehensible
jmasa
parents: 38216
diff changeset
    53
                           os::ThreadType worker_type,
157f39705057 8157240: GC task trace logging is incomprehensible
jmasa
parents: 38216
diff changeset
    54
                           bool initializing) {
38216
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    55
    uint start = created_workers;
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    56
    uint end = MIN2(active_workers, total_workers);
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    57
    for (uint worker_id = start; worker_id < end; worker_id += 1) {
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    58
      WorkerThread* new_worker = holder->install_worker(worker_id);
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    59
      assert(new_worker != NULL, "Failed to allocate GangWorker");
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    60
      if (new_worker == NULL || !os::create_thread(new_worker, worker_type)) {
39704
157f39705057 8157240: GC task trace logging is incomprehensible
jmasa
parents: 38216
diff changeset
    61
        if (initializing) {
38216
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    62
          vm_exit_out_of_memory(0, OOM_MALLOC_ERROR,
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    63
                  "Cannot create worker GC thread. Out of system resources.");
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    64
        }
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    65
      }
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    66
      created_workers++;
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    67
      os::start_thread(new_worker);
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    68
    }
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    69
39704
157f39705057 8157240: GC task trace logging is incomprehensible
jmasa
parents: 38216
diff changeset
    70
    return created_workers;
157f39705057 8157240: GC task trace logging is incomprehensible
jmasa
parents: 38216
diff changeset
    71
  }
38216
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    72
39704
157f39705057 8157240: GC task trace logging is incomprehensible
jmasa
parents: 38216
diff changeset
    73
  // Log (at trace level) a change in the number of created workers.
157f39705057 8157240: GC task trace logging is incomprehensible
jmasa
parents: 38216
diff changeset
    74
  template <class WorkerType>
157f39705057 8157240: GC task trace logging is incomprehensible
jmasa
parents: 38216
diff changeset
    75
  static void log_worker_creation(WorkerType* holder,
157f39705057 8157240: GC task trace logging is incomprehensible
jmasa
parents: 38216
diff changeset
    76
                                  uint previous_created_workers,
157f39705057 8157240: GC task trace logging is incomprehensible
jmasa
parents: 38216
diff changeset
    77
                                  uint active_workers,
157f39705057 8157240: GC task trace logging is incomprehensible
jmasa
parents: 38216
diff changeset
    78
                                  uint created_workers,
157f39705057 8157240: GC task trace logging is incomprehensible
jmasa
parents: 38216
diff changeset
    79
                                  bool initializing) {
157f39705057 8157240: GC task trace logging is incomprehensible
jmasa
parents: 38216
diff changeset
    80
    if (previous_created_workers < created_workers) {
157f39705057 8157240: GC task trace logging is incomprehensible
jmasa
parents: 38216
diff changeset
    81
      const char* initializing_msg =  initializing ? "Adding initial" : "Creating additional";
157f39705057 8157240: GC task trace logging is incomprehensible
jmasa
parents: 38216
diff changeset
    82
      log_trace(gc, task)("%s %s(s) previously created workers %u active workers %u total created workers %u",
157f39705057 8157240: GC task trace logging is incomprehensible
jmasa
parents: 38216
diff changeset
    83
                          initializing_msg, holder->group_name(), previous_created_workers, active_workers, created_workers);
157f39705057 8157240: GC task trace logging is incomprehensible
jmasa
parents: 38216
diff changeset
    84
    }
38216
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    85
  }
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    86
};
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents:
diff changeset
    87
#endif // SHARE_VM_GC_SHARED_WORKERMANAGER_HPP