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 #include "precompiled.hpp"
  26 #include "gc/g1/g1CollectedHeap.inline.hpp"
  27 #include "gc/g1/g1ErgoVerbose.hpp"
  28 #include "gc/g1/g1IHOPControl.hpp"
  29 #include "gc/g1/g1Predictions.hpp"
  30 
  31 G1IHOPControl::G1IHOPControl(double initial_ihop_percent, size_t target_occupancy) :
  32   _ihop_percent(initial_ihop_percent),
  33   _target_occupancy(target_occupancy) {
  34   assert(_ihop_percent >= 0.0 && _ihop_percent <= 100.0, "Initial IHOP value must be between 0 and 100 but is %.3f", initial_ihop_percent);
  35 }
  36 
  37 void G1StaticIHOPControl::print() {
  38   ergo_verbose6(ErgoIHOP,
  39                 "basic information",
  40                 ergo_format_reason("value update")
  41                 ergo_format_byte_perc("threshold")
  42                 ergo_format_byte("target occupancy")
  43                 ergo_format_byte("current occupancy")
  44                 ergo_format_double("recent old gen allocation rate")
  45                 ergo_format_ms("recent marking phase length"),
  46                 get_conc_mark_start_threshold(),
  47                 (double) get_conc_mark_start_threshold() / G1CollectedHeap::heap()->capacity() * 100.0,
  48                 _target_occupancy,
  49                 G1CollectedHeap::heap()->used(),
  50                 _last_allocation_time_s > 0.0 ? _last_allocated_bytes / _last_allocation_time_s : 0.0,
  51                 _last_marking_length_s * 1000.0);
  52 }
  53 
  54 #ifndef PRODUCT
  55 static void test_update(G1IHOPControl* ctrl, double alloc_time, size_t alloc_amount, size_t young_size, double mark_time) {
  56   for (int i = 0; i < 100; i++) {
  57     ctrl->update_allocation_info(alloc_time, alloc_amount, young_size);
  58     ctrl->update_time_to_mixed(mark_time);
  59   }
  60 }
  61 
  62 void G1StaticIHOPControl::test() {
  63   size_t const initial_ihop = 45;
  64 
  65   G1StaticIHOPControl ctrl(initial_ihop, 100);
  66   size_t threshold;
  67   
  68   threshold = ctrl.get_conc_mark_start_threshold();
  69   assert(threshold == initial_ihop,
  70          "Expected IHOP threshold of " SIZE_FORMAT " but is " SIZE_FORMAT, initial_ihop, threshold);
  71 
  72   ctrl.update_allocation_info(100.0, 100, 100);
  73   threshold = ctrl.get_conc_mark_start_threshold();
  74   assert(threshold == initial_ihop,
  75          "Expected IHOP threshold of " SIZE_FORMAT " but is " SIZE_FORMAT, initial_ihop, threshold);
  76 
  77   ctrl.update_time_to_mixed(1000.0);
  78   threshold = ctrl.get_conc_mark_start_threshold();
  79   assert(threshold == initial_ihop,
  80          "Expected IHOP threshold of " SIZE_FORMAT " but is " SIZE_FORMAT, initial_ihop, threshold);
  81 
  82   // Whatever we pass, the IHOP value must stay the same.
  83   test_update(&ctrl, 2, 10, 10, 3);
  84   threshold = ctrl.get_conc_mark_start_threshold();
  85   assert(threshold == initial_ihop,
  86          "Expected IHOP threshold of " SIZE_FORMAT " but is " SIZE_FORMAT, initial_ihop, threshold);
  87 
  88   test_update(&ctrl, 12, 10, 10, 3);
  89   threshold = ctrl.get_conc_mark_start_threshold();
  90   assert(threshold == initial_ihop,
  91          "Expected IHOP threshold of " SIZE_FORMAT " but is " SIZE_FORMAT, initial_ihop, threshold);
  92 }
  93 #endif
  94 
  95 #ifndef PRODUCT
  96 void IHOP_test() {
  97   G1StaticIHOPControl::test();
  98 }
  99 #endif