1 /*
   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.
   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_G1_G1IHOPCONTROL_HPP
  26 #define SHARE_VM_GC_G1_G1IHOPCONTROL_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "utilities/numberSeq.hpp"
  30 
  31 class G1NewTracer;
  32 
  33 // Base class for algorithms that calculate the heap occupancy at which
  34 // concurrent marking should start. This heap usage threshold should be relative
  35 // to old gen size.
  36 class G1IHOPControl : public CHeapObj<mtGC> {
  37  protected:
  38   // The initial IHOP value relative to the target occupancy.
  39   double _initial_ihop_percent;
  40   // The target maximum occupancy of the heap. The target occupancy is the number
  41   // of bytes when marking should be finished and reclaim started.
  42   size_t _target_occupancy;
  43 
  44   // Most recent complete mutator allocation period in seconds.
  45   double _last_allocation_time_s;
  46   // Amount of bytes allocated during _last_allocation_time_s.
  47   size_t _last_allocated_bytes;
  48 
  49   // Initialize an instance with the initial IHOP value in percent. The target
  50   // occupancy will be updated at the first heap expansion.
  51   G1IHOPControl(double initial_ihop_percent);
  52 
  53   // Most recent time from the end of the initial mark to the start of the first
  54   // mixed gc.
  55   virtual double last_marking_length_s() const = 0;
  56  public:
  57   virtual ~G1IHOPControl() { }
  58 
  59   // Get the current non-young occupancy at which concurrent marking should start.
  60   virtual size_t get_conc_mark_start_threshold() = 0;
  61 
  62   // Adjust target occupancy.
  63   virtual void update_target_occupancy(size_t new_target_occupancy);
  64   // Update information about time during which allocations in the Java heap occurred,
  65   // how large these allocations were in bytes, and an additional buffer.
  66   // The allocations should contain any amount of space made unusable for further
  67   // allocation, e.g. any waste caused by TLAB allocation, space at the end of
  68   // humongous objects that can not be used for allocation, etc.
  69   // Together with the target occupancy, this additional buffer should contain the
  70   // difference between old gen size and total heap size at the start of reclamation,
  71   // and space required for that reclamation.
  72   virtual void update_allocation_info(double allocation_time_s, size_t allocated_bytes, size_t additional_buffer_size);
  73   // Update the time spent in the mutator beginning from the end of initial mark to
  74   // the first mixed gc.
  75   virtual void update_marking_length(double marking_length_s) = 0;
  76 
  77   virtual void print();
  78   virtual void send_trace_event(G1NewTracer* tracer);
  79 };
  80 
  81 // The returned concurrent mark starting occupancy threshold is a fixed value
  82 // relative to the maximum heap size.
  83 class G1StaticIHOPControl : public G1IHOPControl {
  84   // Most recent mutator time between the end of initial mark to the start of the
  85   // first mixed gc.
  86   double _last_marking_length_s;
  87  protected:
  88   double last_marking_length_s() const { return _last_marking_length_s; }
  89  public:
  90   G1StaticIHOPControl(double ihop_percent);
  91 
  92   size_t get_conc_mark_start_threshold() {
  93     guarantee(_target_occupancy > 0, "Target occupancy must have been initialized.");
  94     return (size_t) (_initial_ihop_percent * _target_occupancy / 100.0);
  95   }
  96 
  97   virtual void update_marking_length(double marking_length_s) {
  98    assert(marking_length_s > 0.0, "Marking length must be larger than zero.");
  99     _last_marking_length_s = marking_length_s;
 100   }
 101 };
 102 #endif // SHARE_VM_GC_G1_G1IHOPCONTROL_HPP