< prev index next >

src/share/vm/gc/shared/adaptiveSizePolicy.cpp

Print this page
rev 10651 : 6858051: Create GC worker threads dynamically
Reviewed-by:
   1 /*
   2  * Copyright (c) 2004, 2015, 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  *


 113   uintx prev_active_workers = active_workers;
 114   uintx active_workers_by_JT = 0;
 115   uintx active_workers_by_heap_size = 0;
 116 
 117   // Always use at least min_workers but use up to
 118   // GCThreadsPerJavaThreads * application threads.
 119   active_workers_by_JT =
 120     MAX2((uintx) GCWorkersPerJavaThread * application_workers,
 121          min_workers);
 122 
 123   // Choose a number of GC threads based on the current size
 124   // of the heap.  This may be complicated because the size of
 125   // the heap depends on factors such as the throughput goal.
 126   // Still a large heap should be collected by more GC threads.
 127   active_workers_by_heap_size =
 128       MAX2((size_t) 2U, Universe::heap()->capacity() / HeapSizePerGCThread);
 129 
 130   uintx max_active_workers =
 131     MAX2(active_workers_by_JT, active_workers_by_heap_size);
 132 
 133   // Limit the number of workers to the the number created,
 134   // (workers()).
 135   new_active_workers = MIN2(max_active_workers,
 136                                 (uintx) total_workers);
 137 
 138   // Increase GC workers instantly but decrease them more
 139   // slowly.
 140   if (new_active_workers < prev_active_workers) {
 141     new_active_workers =
 142       MAX2(min_workers, (prev_active_workers + new_active_workers) / 2);
 143   }
 144 
 145   // Check once more that the number of workers is within the limits.
 146   assert(min_workers <= total_workers, "Minimum workers not consistent with total workers");
 147   assert(new_active_workers >= min_workers, "Minimum workers not observed");
 148   assert(new_active_workers <= total_workers, "Total workers not observed");
 149 
 150   if (ForceDynamicNumberOfGCThreads) {
 151     // Assume this is debugging and jiggle the number of GC threads.
 152     if (new_active_workers == prev_active_workers) {
 153       if (new_active_workers < total_workers) {
 154         new_active_workers++;
 155       } else if (new_active_workers > min_workers) {
 156         new_active_workers--;


   1 /*
   2  * Copyright (c) 2004, 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  *


 113   uintx prev_active_workers = active_workers;
 114   uintx active_workers_by_JT = 0;
 115   uintx active_workers_by_heap_size = 0;
 116 
 117   // Always use at least min_workers but use up to
 118   // GCThreadsPerJavaThreads * application threads.
 119   active_workers_by_JT =
 120     MAX2((uintx) GCWorkersPerJavaThread * application_workers,
 121          min_workers);
 122 
 123   // Choose a number of GC threads based on the current size
 124   // of the heap.  This may be complicated because the size of
 125   // the heap depends on factors such as the throughput goal.
 126   // Still a large heap should be collected by more GC threads.
 127   active_workers_by_heap_size =
 128       MAX2((size_t) 2U, Universe::heap()->capacity() / HeapSizePerGCThread);
 129 
 130   uintx max_active_workers =
 131     MAX2(active_workers_by_JT, active_workers_by_heap_size);
 132 
 133   new_active_workers = MIN2(max_active_workers, (uintx) total_workers);



 134 
 135   // Increase GC workers instantly but decrease them more
 136   // slowly.
 137   if (new_active_workers < prev_active_workers) {
 138     new_active_workers =
 139       MAX2(min_workers, (prev_active_workers + new_active_workers) / 2);
 140   }
 141 
 142   // Check once more that the number of workers is within the limits.
 143   assert(min_workers <= total_workers, "Minimum workers not consistent with total workers");
 144   assert(new_active_workers >= min_workers, "Minimum workers not observed");
 145   assert(new_active_workers <= total_workers, "Total workers not observed");
 146 
 147   if (ForceDynamicNumberOfGCThreads) {
 148     // Assume this is debugging and jiggle the number of GC threads.
 149     if (new_active_workers == prev_active_workers) {
 150       if (new_active_workers < total_workers) {
 151         new_active_workers++;
 152       } else if (new_active_workers > min_workers) {
 153         new_active_workers--;


< prev index next >