src/hotspot/share/gc/shared/gcOverheadChecker.hpp
author tschatzl
Wed, 13 Mar 2019 21:01:56 +0100
changeset 54110 f4f0dce5d0bb
parent 54085 ab87b06dfdc0
child 57875 427b38332f20
permissions -rw-r--r--
8220301: Remove jbyte use in CardTable Summary: Use CardTable::CardValue aliased to uint8_t instead. Reviewed-by: kbarrett, shade
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
54085
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
     1
/*
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
     3
 * Copyright (c) 2019, Google and/or its affiliates. All rights reserved.
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
     5
 *
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
     8
 * published by the Free Software Foundation.
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
     9
 *
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    14
 * accompanied this code).
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    15
 *
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    19
 *
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    22
 * questions.
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    23
 *
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    24
 */
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    25
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    26
#ifndef SHARE_GC_SHARED_GCOVERHEADCHECKER_HPP
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    27
#define SHARE_GC_SHARED_GCOVERHEADCHECKER_HPP
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    28
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    29
#include "memory/allocation.hpp"
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    30
#include "gc/shared/gcCause.hpp"
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    31
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    32
class SoftRefPolicy;
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    33
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    34
class GCOverheadTester: public StackObj {
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    35
public:
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    36
  virtual bool is_exceeded() = 0;
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    37
};
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    38
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    39
class GCOverheadChecker: public CHeapObj<mtGC> {
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    40
  // This is a hint for the heap:  we've detected that GC times
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    41
  // are taking longer than GCTimeLimit allows.
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    42
  bool _gc_overhead_limit_exceeded;
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    43
  // Use for diagnostics only.  If UseGCOverheadLimit is false,
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    44
  // this variable is still set.
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    45
  bool _print_gc_overhead_limit_would_be_exceeded;
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    46
  // Count of consecutive GC that have exceeded the
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    47
  // GC time limit criterion
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    48
  uint _gc_overhead_limit_count;
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    49
  // This flag signals that GCTimeLimit is being exceeded
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    50
  // but may not have done so for the required number of consecutive
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    51
  // collections
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    52
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    53
public:
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    54
  GCOverheadChecker();
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    55
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    56
  // This is a hint for the heap:  we've detected that gc times
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    57
  // are taking longer than GCTimeLimit allows.
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    58
  // Most heaps will choose to throw an OutOfMemoryError when
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    59
  // this occurs but it is up to the heap to request this information
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    60
  // of the policy
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    61
  bool gc_overhead_limit_exceeded() {
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    62
    return _gc_overhead_limit_exceeded;
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    63
  }
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    64
  void set_gc_overhead_limit_exceeded(bool v) {
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    65
    _gc_overhead_limit_exceeded = v;
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    66
  }
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    67
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    68
  // Tests conditions indicate the GC overhead limit is being approached.
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    69
  bool gc_overhead_limit_near() {
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    70
    return _gc_overhead_limit_count >= (GCOverheadLimitThreshold - 1);
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    71
  }
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    72
  void reset_gc_overhead_limit_count() {
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    73
    _gc_overhead_limit_count = 0;
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    74
  }
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    75
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    76
  // Check the conditions for an out-of-memory due to excessive GC time.
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    77
  // Set _gc_overhead_limit_exceeded if all the conditions have been met.
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    78
  void check_gc_overhead_limit(GCOverheadTester* time_overhead,
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    79
                               GCOverheadTester* space_overhead,
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    80
                               bool is_full_gc,
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    81
                               GCCause::Cause gc_cause,
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    82
                               SoftRefPolicy* soft_ref_policy);
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    83
};
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    84
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents:
diff changeset
    85
#endif // SHARE_GC_SHARED_GCOVERHEADCHECKER_HPP