1 /*
   2  * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_GC_SHARED_ADAPTIVESIZEPOLICY_INLINE_HPP
  26 #define SHARE_VM_GC_SHARED_ADAPTIVESIZEPOLICY_INLINE_HPP
  27 
  28 #include "gc/shared/adaptiveSizePolicy.hpp"
  29 
  30 template <class WorkerType>
  31 bool AdaptiveSizePolicy::add_workers(WorkerType* holder,
  32                                         uint& active_workers,
  33                                         uint total_workers,
  34                                         uint& created_workers,
  35                                         os::ThreadType worker_type,
  36                                         bool initializing) {
  37   uint start = created_workers;
  38   uint end = MIN2(active_workers, total_workers);
  39   for (uint worker_id = start; worker_id < end; worker_id += 1) {
  40     WorkerThread* new_worker = holder->install_worker(worker_id);
  41     assert(new_worker != NULL, "Failed to allocate GangWorker");
  42     if (new_worker == NULL || !os::create_thread(new_worker, worker_type)) {
  43       if(initializing) {
  44         vm_exit_out_of_memory(0, OOM_MALLOC_ERROR,
  45                 "Cannot create worker GC thread. Out of system resources.");
  46       }
  47       return false;
  48     }
  49     created_workers++;
  50 
  51     if (!DisableStartThread || !initializing) {
  52       os::start_thread(new_worker);
  53     }
  54   }
  55 
  56   active_workers = MIN2(active_workers, created_workers);
  57   active_workers = MAX2(1U, active_workers);
  58 
  59   log_trace(gc, task)("AdaptiveSizePolicy::add_workers() : "
  60      "active_workers: %u created_workers: %u",
  61      active_workers, created_workers);
  62 
  63   return true;
  64 }
  65 #endif // SHARE_VM_GC_SHARED_ADAPTIVESIZEPOLICY_INLINE_HPP