src/hotspot/share/gc/z/zDirector.cpp
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 55002 da9840e2f7da
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
     1 /*
     1 /*
     2  * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    64 
    64 
    65   // Perform GC if timer has expired.
    65   // Perform GC if timer has expired.
    66   const double time_since_last_gc = ZStatCycle::time_since_last();
    66   const double time_since_last_gc = ZStatCycle::time_since_last();
    67   const double time_until_gc = ZCollectionInterval - time_since_last_gc;
    67   const double time_until_gc = ZCollectionInterval - time_since_last_gc;
    68 
    68 
    69   log_debug(gc, director)("Rule: Timer, Interval: %us, TimeUntilGC: %.3lfs",
    69   log_debug(gc, director)("Rule: Timer, Interval: %us, TimeUntilGC: %.3fs",
    70                           ZCollectionInterval, time_until_gc);
    70                           ZCollectionInterval, time_until_gc);
    71 
    71 
    72   return time_until_gc <= 0;
    72   return time_until_gc <= 0;
    73 }
    73 }
    74 
    74 
    79   }
    79   }
    80 
    80 
    81   // Perform GC if heap usage passes 10/20/30% and no other GC has been
    81   // Perform GC if heap usage passes 10/20/30% and no other GC has been
    82   // performed yet. This allows us to get some early samples of the GC
    82   // performed yet. This allows us to get some early samples of the GC
    83   // duration, which is needed by the other rules.
    83   // duration, which is needed by the other rules.
    84   const size_t max_capacity = ZHeap::heap()->current_max_capacity();
    84   const size_t max_capacity = ZHeap::heap()->soft_max_capacity();
    85   const size_t used = ZHeap::heap()->used();
    85   const size_t used = ZHeap::heap()->used();
    86   const double used_threshold_percent = (ZStatCycle::ncycles() + 1) * 0.1;
    86   const double used_threshold_percent = (ZStatCycle::ncycles() + 1) * 0.1;
    87   const size_t used_threshold = max_capacity * used_threshold_percent;
    87   const size_t used_threshold = max_capacity * used_threshold_percent;
    88 
    88 
    89   log_debug(gc, director)("Rule: Warmup %.0f%%, Used: " SIZE_FORMAT "MB, UsedThreshold: " SIZE_FORMAT "MB",
    89   log_debug(gc, director)("Rule: Warmup %.0f%%, Used: " SIZE_FORMAT "MB, UsedThreshold: " SIZE_FORMAT "MB",
   105   // allocation spikes.
   105   // allocation spikes.
   106 
   106 
   107   // Calculate amount of free memory available to Java threads. Note that
   107   // Calculate amount of free memory available to Java threads. Note that
   108   // the heap reserve is not available to Java threads and is therefore not
   108   // the heap reserve is not available to Java threads and is therefore not
   109   // considered part of the free memory.
   109   // considered part of the free memory.
   110   const size_t max_capacity = ZHeap::heap()->current_max_capacity();
   110   const size_t max_capacity = ZHeap::heap()->soft_max_capacity();
   111   const size_t max_reserve = ZHeap::heap()->max_reserve();
   111   const size_t max_reserve = ZHeap::heap()->max_reserve();
   112   const size_t used = ZHeap::heap()->used();
   112   const size_t used = ZHeap::heap()->used();
   113   const size_t free_with_reserve = max_capacity - used;
   113   const size_t free_with_reserve = max_capacity - MIN2(max_capacity, used);
   114   const size_t free = free_with_reserve - MIN2(free_with_reserve, max_reserve);
   114   const size_t free = free_with_reserve - MIN2(free_with_reserve, max_reserve);
   115 
   115 
   116   // Calculate time until OOM given the max allocation rate and the amount
   116   // Calculate time until OOM given the max allocation rate and the amount
   117   // of free memory. The allocation rate is a moving average and we multiply
   117   // of free memory. The allocation rate is a moving average and we multiply
   118   // that with an allocation spike tolerance factor to guard against unforeseen
   118   // that with an allocation spike tolerance factor to guard against unforeseen
   131   // We also deduct the sample interval, so that we don't overshoot the target
   131   // We also deduct the sample interval, so that we don't overshoot the target
   132   // time and end up starting the GC too late in the next interval.
   132   // time and end up starting the GC too late in the next interval.
   133   const double sample_interval = 1.0 / ZStatAllocRate::sample_hz;
   133   const double sample_interval = 1.0 / ZStatAllocRate::sample_hz;
   134   const double time_until_gc = time_until_oom - max_duration_of_gc - sample_interval;
   134   const double time_until_gc = time_until_oom - max_duration_of_gc - sample_interval;
   135 
   135 
   136   log_debug(gc, director)("Rule: Allocation Rate, MaxAllocRate: %.3lfMB/s, Free: " SIZE_FORMAT "MB, MaxDurationOfGC: %.3lfs, TimeUntilGC: %.3lfs",
   136   log_debug(gc, director)("Rule: Allocation Rate, MaxAllocRate: %.3fMB/s, Free: " SIZE_FORMAT "MB, MaxDurationOfGC: %.3fs, TimeUntilGC: %.3fs",
   137                           max_alloc_rate / M, free / M, max_duration_of_gc, time_until_gc);
   137                           max_alloc_rate / M, free / M, max_duration_of_gc, time_until_gc);
   138 
   138 
   139   return time_until_gc <= 0;
   139   return time_until_gc <= 0;
   140 }
   140 }
   141 
   141 
   153   // Only consider doing a proactive GC if the heap usage has grown by at least
   153   // Only consider doing a proactive GC if the heap usage has grown by at least
   154   // 10% of the max capacity since the previous GC, or more than 5 minutes has
   154   // 10% of the max capacity since the previous GC, or more than 5 minutes has
   155   // passed since the previous GC. This helps avoid superfluous GCs when running
   155   // passed since the previous GC. This helps avoid superfluous GCs when running
   156   // applications with very low allocation rate.
   156   // applications with very low allocation rate.
   157   const size_t used_after_last_gc = ZStatHeap::used_at_relocate_end();
   157   const size_t used_after_last_gc = ZStatHeap::used_at_relocate_end();
   158   const size_t used_increase_threshold = ZHeap::heap()->current_max_capacity() * 0.10; // 10%
   158   const size_t used_increase_threshold = ZHeap::heap()->soft_max_capacity() * 0.10; // 10%
   159   const size_t used_threshold = used_after_last_gc + used_increase_threshold;
   159   const size_t used_threshold = used_after_last_gc + used_increase_threshold;
   160   const size_t used = ZHeap::heap()->used();
   160   const size_t used = ZHeap::heap()->used();
   161   const double time_since_last_gc = ZStatCycle::time_since_last();
   161   const double time_since_last_gc = ZStatCycle::time_since_last();
   162   const double time_since_last_gc_threshold = 5 * 60; // 5 minutes
   162   const double time_since_last_gc_threshold = 5 * 60; // 5 minutes
   163   if (used < used_threshold && time_since_last_gc < time_since_last_gc_threshold) {
   163   if (used < used_threshold && time_since_last_gc < time_since_last_gc_threshold) {
   164     // Don't even consider doing a proactive GC
   164     // Don't even consider doing a proactive GC
   165     log_debug(gc, director)("Rule: Proactive, UsedUntilEnabled: " SIZE_FORMAT "MB, TimeUntilEnabled: %.3lfs",
   165     log_debug(gc, director)("Rule: Proactive, UsedUntilEnabled: " SIZE_FORMAT "MB, TimeUntilEnabled: %.3fs",
   166                             (used_threshold - used) / M,
   166                             (used_threshold - used) / M,
   167                             time_since_last_gc_threshold - time_since_last_gc);
   167                             time_since_last_gc_threshold - time_since_last_gc);
   168     return false;
   168     return false;
   169   }
   169   }
   170 
   170 
   173   const AbsSeq& duration_of_gc = ZStatCycle::normalized_duration();
   173   const AbsSeq& duration_of_gc = ZStatCycle::normalized_duration();
   174   const double max_duration_of_gc = duration_of_gc.davg() + (duration_of_gc.dsd() * one_in_1000);
   174   const double max_duration_of_gc = duration_of_gc.davg() + (duration_of_gc.dsd() * one_in_1000);
   175   const double acceptable_gc_interval = max_duration_of_gc * ((assumed_throughput_drop_during_gc / acceptable_throughput_drop) - 1.0);
   175   const double acceptable_gc_interval = max_duration_of_gc * ((assumed_throughput_drop_during_gc / acceptable_throughput_drop) - 1.0);
   176   const double time_until_gc = acceptable_gc_interval - time_since_last_gc;
   176   const double time_until_gc = acceptable_gc_interval - time_since_last_gc;
   177 
   177 
   178   log_debug(gc, director)("Rule: Proactive, AcceptableGCInterval: %.3lfs, TimeSinceLastGC: %.3lfs, TimeUntilGC: %.3lfs",
   178   log_debug(gc, director)("Rule: Proactive, AcceptableGCInterval: %.3fs, TimeSinceLastGC: %.3fs, TimeUntilGC: %.3fs",
   179                           acceptable_gc_interval, time_since_last_gc, time_until_gc);
   179                           acceptable_gc_interval, time_since_last_gc, time_until_gc);
   180 
   180 
   181   return time_until_gc <= 0;
   181   return time_until_gc <= 0;
   182 }
   182 }
   183 
   183 
   189   // we start a GC cycle to avoid a potential allocation stall later.
   189   // we start a GC cycle to avoid a potential allocation stall later.
   190 
   190 
   191   // Calculate amount of free memory available to Java threads. Note that
   191   // Calculate amount of free memory available to Java threads. Note that
   192   // the heap reserve is not available to Java threads and is therefore not
   192   // the heap reserve is not available to Java threads and is therefore not
   193   // considered part of the free memory.
   193   // considered part of the free memory.
   194   const size_t max_capacity = ZHeap::heap()->current_max_capacity();
   194   const size_t max_capacity = ZHeap::heap()->soft_max_capacity();
   195   const size_t max_reserve = ZHeap::heap()->max_reserve();
   195   const size_t max_reserve = ZHeap::heap()->max_reserve();
   196   const size_t used = ZHeap::heap()->used();
   196   const size_t used = ZHeap::heap()->used();
   197   const size_t free_with_reserve = max_capacity - used;
   197   const size_t free_with_reserve = max_capacity - used;
   198   const size_t free = free_with_reserve - MIN2(free_with_reserve, max_reserve);
   198   const size_t free = free_with_reserve - MIN2(free_with_reserve, max_reserve);
   199 
   199   const double free_percent = percent_of(free, max_capacity);
   200   return percent_of(free, max_capacity) <= 5.0;
   200 
       
   201   log_debug(gc, director)("Rule: High Usage, Free: " SIZE_FORMAT "MB(%.1f%%)",
       
   202                           free / M, free_percent);
       
   203 
       
   204   return free_percent <= 5.0;
   201 }
   205 }
   202 
   206 
   203 GCCause::Cause ZDirector::make_gc_decision() const {
   207 GCCause::Cause ZDirector::make_gc_decision() const {
   204   // Rule 0: Timer
   208   // Rule 0: Timer
   205   if (rule_timer()) {
   209   if (rule_timer()) {