1 /*
   2  * Copyright (c) 2018, 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_WORKERPOLICY_HPP
  26 #define SHARE_VM_GC_SHARED_WORKERPOLICY_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "utilities/globalDefinitions.hpp"
  30 
  31 class WorkerPolicy : public AllStatic {
  32   static const uint GCWorkersPerJavaThread = 2;
  33 
  34   static bool _debug_perturbation;
  35   static uint _parallel_worker_threads;
  36   static bool _parallel_worker_threads_initialized;
  37 
  38   static uint nof_parallel_worker_threads(uint num,
  39                                           uint den,
  40                                           uint switch_pt);
  41 
  42   // Calculates and returns the number of parallel GC threads. May
  43   // be CPU-architecture-specific.
  44   static uint calc_parallel_worker_threads();
  45 
  46 public:
  47   // Returns the number of parallel threads to be used as default value of
  48   // ParallelGCThreads. If that number has not been calculated, do so and
  49   // save it.  Returns ParallelGCThreads if it is set on the
  50   // command line.
  51   static uint parallel_worker_threads();
  52 
  53   // Return number default GC threads to use in the next GC.
  54   static uint calc_default_active_workers(uintx total_workers,
  55                                           const uintx min_workers,
  56                                           uintx active_workers,
  57                                           uintx application_workers);
  58 
  59   // Return number of GC threads to use in the next GC.
  60   // This is called sparingly so as not to change the
  61   // number of GC workers gratuitously.
  62   //   For ParNew collections
  63   //   For PS scavenge and ParOld collections
  64   //   For G1 evacuation pauses (subject to update)
  65   //   For G1 Full GCs (subject to update)
  66   // Other collection phases inherit the number of
  67   // GC workers from the calls above.  For example,
  68   // a CMS parallel remark uses the same number of GC
  69   // workers as the most recent ParNew collection.
  70   static uint calc_active_workers(uintx total_workers,
  71                                   uintx active_workers,
  72                                   uintx application_workers);
  73 
  74   // Return number of GC threads to use in the next concurrent GC phase.
  75   static uint calc_active_conc_workers(uintx total_workers,
  76                                        uintx active_workers,
  77                                        uintx application_workers);
  78 
  79 };
  80 
  81 #endif // SHARE_VM_GC_SHARED_WORKERPOLICY_HPP