hotspot/src/share/vm/gc_implementation/shared/adaptiveSizePolicy.cpp
changeset 11174 fccee5238e70
parent 7397 5b173b4ca846
child 13925 37f75ba502b1
equal deleted inserted replaced
11173:af2bc14f35f8 11174:fccee5238e70
    26 #include "gc_implementation/shared/adaptiveSizePolicy.hpp"
    26 #include "gc_implementation/shared/adaptiveSizePolicy.hpp"
    27 #include "gc_interface/gcCause.hpp"
    27 #include "gc_interface/gcCause.hpp"
    28 #include "memory/collectorPolicy.hpp"
    28 #include "memory/collectorPolicy.hpp"
    29 #include "runtime/timer.hpp"
    29 #include "runtime/timer.hpp"
    30 #include "utilities/ostream.hpp"
    30 #include "utilities/ostream.hpp"
       
    31 #include "utilities/workgroup.hpp"
    31 elapsedTimer AdaptiveSizePolicy::_minor_timer;
    32 elapsedTimer AdaptiveSizePolicy::_minor_timer;
    32 elapsedTimer AdaptiveSizePolicy::_major_timer;
    33 elapsedTimer AdaptiveSizePolicy::_major_timer;
       
    34 bool AdaptiveSizePolicy::_debug_perturbation = false;
    33 
    35 
    34 // The throughput goal is implemented as
    36 // The throughput goal is implemented as
    35 //      _throughput_goal = 1 - ( 1 / (1 + gc_cost_ratio))
    37 //      _throughput_goal = 1 - ( 1 / (1 + gc_cost_ratio))
    36 // gc_cost_ratio is the ratio
    38 // gc_cost_ratio is the ratio
    37 //      application cost / gc cost
    39 //      application cost / gc cost
    84 
    86 
    85   // Start the timers
    87   // Start the timers
    86   _minor_timer.start();
    88   _minor_timer.start();
    87 
    89 
    88   _young_gen_policy_is_ready = false;
    90   _young_gen_policy_is_ready = false;
       
    91 }
       
    92 
       
    93 //  If the number of GC threads was set on the command line,
       
    94 // use it.
       
    95 //  Else
       
    96 //    Calculate the number of GC threads based on the number of Java threads.
       
    97 //    Calculate the number of GC threads based on the size of the heap.
       
    98 //    Use the larger.
       
    99 
       
   100 int AdaptiveSizePolicy::calc_default_active_workers(uintx total_workers,
       
   101                                             const uintx min_workers,
       
   102                                             uintx active_workers,
       
   103                                             uintx application_workers) {
       
   104   // If the user has specifically set the number of
       
   105   // GC threads, use them.
       
   106 
       
   107   // If the user has turned off using a dynamic number of GC threads
       
   108   // or the users has requested a specific number, set the active
       
   109   // number of workers to all the workers.
       
   110 
       
   111   uintx new_active_workers = total_workers;
       
   112   uintx prev_active_workers = active_workers;
       
   113   uintx active_workers_by_JT = 0;
       
   114   uintx active_workers_by_heap_size = 0;
       
   115 
       
   116   // Always use at least min_workers but use up to
       
   117   // GCThreadsPerJavaThreads * application threads.
       
   118   active_workers_by_JT =
       
   119     MAX2((uintx) GCWorkersPerJavaThread * application_workers,
       
   120          min_workers);
       
   121 
       
   122   // Choose a number of GC threads based on the current size
       
   123   // of the heap.  This may be complicated because the size of
       
   124   // the heap depends on factors such as the thoughput goal.
       
   125   // Still a large heap should be collected by more GC threads.
       
   126   active_workers_by_heap_size =
       
   127       MAX2((size_t) 2U, Universe::heap()->capacity() / HeapSizePerGCThread);
       
   128 
       
   129   uintx max_active_workers =
       
   130     MAX2(active_workers_by_JT, active_workers_by_heap_size);
       
   131 
       
   132   // Limit the number of workers to the the number created,
       
   133   // (workers()).
       
   134   new_active_workers = MIN2(max_active_workers,
       
   135                                 (uintx) total_workers);
       
   136 
       
   137   // Increase GC workers instantly but decrease them more
       
   138   // slowly.
       
   139   if (new_active_workers < prev_active_workers) {
       
   140     new_active_workers =
       
   141       MAX2(min_workers, (prev_active_workers + new_active_workers) / 2);
       
   142   }
       
   143 
       
   144   // Check once more that the number of workers is within the limits.
       
   145   assert(min_workers <= total_workers, "Minimum workers not consistent with total workers");
       
   146   assert(new_active_workers >= min_workers, "Minimum workers not observed");
       
   147   assert(new_active_workers <= total_workers, "Total workers not observed");
       
   148 
       
   149   if (ForceDynamicNumberOfGCThreads) {
       
   150     // Assume this is debugging and jiggle the number of GC threads.
       
   151     if (new_active_workers == prev_active_workers) {
       
   152       if (new_active_workers < total_workers) {
       
   153         new_active_workers++;
       
   154       } else if (new_active_workers > min_workers) {
       
   155         new_active_workers--;
       
   156       }
       
   157     }
       
   158     if (new_active_workers == total_workers) {
       
   159       if (_debug_perturbation) {
       
   160         new_active_workers =  min_workers;
       
   161       }
       
   162       _debug_perturbation = !_debug_perturbation;
       
   163     }
       
   164     assert((new_active_workers <= (uintx) ParallelGCThreads) &&
       
   165            (new_active_workers >= min_workers),
       
   166       "Jiggled active workers too much");
       
   167   }
       
   168 
       
   169   if (TraceDynamicGCThreads) {
       
   170      gclog_or_tty->print_cr("GCTaskManager::calc_default_active_workers() : "
       
   171        "active_workers(): %d  new_acitve_workers: %d  "
       
   172        "prev_active_workers: %d\n"
       
   173        " active_workers_by_JT: %d  active_workers_by_heap_size: %d",
       
   174        active_workers, new_active_workers, prev_active_workers,
       
   175        active_workers_by_JT, active_workers_by_heap_size);
       
   176   }
       
   177   assert(new_active_workers > 0, "Always need at least 1");
       
   178   return new_active_workers;
       
   179 }
       
   180 
       
   181 int AdaptiveSizePolicy::calc_active_workers(uintx total_workers,
       
   182                                             uintx active_workers,
       
   183                                             uintx application_workers) {
       
   184   // If the user has specifically set the number of
       
   185   // GC threads, use them.
       
   186 
       
   187   // If the user has turned off using a dynamic number of GC threads
       
   188   // or the users has requested a specific number, set the active
       
   189   // number of workers to all the workers.
       
   190 
       
   191   int new_active_workers;
       
   192   if (!UseDynamicNumberOfGCThreads ||
       
   193      (!FLAG_IS_DEFAULT(ParallelGCThreads) && !ForceDynamicNumberOfGCThreads)) {
       
   194     new_active_workers = total_workers;
       
   195   } else {
       
   196     new_active_workers = calc_default_active_workers(total_workers,
       
   197                                                      2, /* Minimum number of workers */
       
   198                                                      active_workers,
       
   199                                                      application_workers);
       
   200   }
       
   201   assert(new_active_workers > 0, "Always need at least 1");
       
   202   return new_active_workers;
       
   203 }
       
   204 
       
   205 int AdaptiveSizePolicy::calc_active_conc_workers(uintx total_workers,
       
   206                                                  uintx active_workers,
       
   207                                                  uintx application_workers) {
       
   208   if (!UseDynamicNumberOfGCThreads ||
       
   209      (!FLAG_IS_DEFAULT(ConcGCThreads) && !ForceDynamicNumberOfGCThreads)) {
       
   210     return ConcGCThreads;
       
   211   } else {
       
   212     int no_of_gc_threads = calc_default_active_workers(
       
   213                              total_workers,
       
   214                              1, /* Minimum number of workers */
       
   215                              active_workers,
       
   216                              application_workers);
       
   217     return no_of_gc_threads;
       
   218   }
    89 }
   219 }
    90 
   220 
    91 bool AdaptiveSizePolicy::tenuring_threshold_change() const {
   221 bool AdaptiveSizePolicy::tenuring_threshold_change() const {
    92   return decrement_tenuring_threshold_for_gc_cost() ||
   222   return decrement_tenuring_threshold_for_gc_cost() ||
    93          increment_tenuring_threshold_for_gc_cost() ||
   223          increment_tenuring_threshold_for_gc_cost() ||