1 /*
   2  * Copyright (c) 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  *
  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 G1Predictions;
  32 
  33 // Manages the decision about the threshold when concurrent marking should start.
  34 class G1IHOPControl : public CHeapObj<mtGC> {
  35  protected:
  36   double _ihop_percent;
  37   size_t _target_occupancy;
  38 
  39   // Initialize an instance with the initial IHOP value in percent and the target
  40   // occupancy. The target occupancy is the number of bytes when marking should
  41   // be finished and reclaim started.
  42   G1IHOPControl(double initial_ihop_percent, size_t target_occupancy);
  43  public:
  44   virtual ~G1IHOPControl() { }
  45 
  46   // Get the current marking threshold in bytes.
  47   virtual size_t get_conc_mark_start_threshold() = 0;
  48 
  49   // Update information about recent time during which allocations happened,
  50   // how many allocations happened and an additional safety buffer.
  51   virtual void update_allocation_info(double allocation_time_s, size_t allocated_bytes, size_t additional_buffer_size) = 0;
  52   // Update the time from the end of initial mark to the first mixed gc.
  53   virtual void update_time_to_mixed(double marking_length_s) = 0;
  54 
  55   virtual void print() = 0;
  56 };
  57 
  58 class G1StaticIHOPControl : public G1IHOPControl {
  59   double _last_allocation_time_s;
  60   size_t _last_allocated_bytes;
  61   double _last_marking_length_s;
  62  public:
  63   G1StaticIHOPControl(double ihop_percent, size_t target_occupancy) :
  64    G1IHOPControl(ihop_percent, target_occupancy),
  65    _last_allocation_time_s(0.0),
  66    _last_allocated_bytes(0),
  67    _last_marking_length_s(0.0) { }
  68 
  69   size_t get_conc_mark_start_threshold() { return (size_t) (_ihop_percent * _target_occupancy / 100.0); }
  70 
  71   virtual void update_allocation_info(double allocation_time_s, size_t allocated_bytes, size_t additional_buffer_size) {
  72     assert(allocation_time_s >= 0.0, "Allocation time must be positive but is %.3f", allocation_time_s);
  73     _last_allocation_time_s = allocation_time_s;
  74     _last_allocated_bytes = allocated_bytes;
  75   }
  76 
  77   virtual void update_time_to_mixed(double marking_length_s) {
  78    assert(marking_length_s > 0.0, "Marking length must be larger than zero but is %.3f", marking_length_s);
  79     _last_marking_length_s = marking_length_s;
  80   }
  81 
  82   virtual void print();
  83 #ifndef PRODUCT
  84   static void test();
  85 #endif
  86 };
  87 
  88 #endif // SHARE_VM_GC_G1_G1IHOPCONTROL_HPP