1 /* 2 * Copyright (c) 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_GC_SHARED_GCOVERHEADCHECKER_HPP 26 #define SHARE_GC_SHARED_GCOVERHEADCHECKER_HPP 27 28 #include "memory/allocation.hpp" 29 #include "gc/shared/gcCause.hpp" 30 31 class SoftRefPolicy; 32 33 class GCOverheadTester: public StackObj { 34 public: 35 virtual bool is_exceeded() = 0; 36 }; 37 38 class GCOverheadChecker: public CHeapObj<mtGC> { 39 // This is a hint for the heap: we've detected that GC times 40 // are taking longer than GCTimeLimit allows. 41 bool _gc_overhead_limit_exceeded; 42 // Use for diagnostics only. If UseGCOverheadLimit is false, 43 // this variable is still set. 44 bool _print_gc_overhead_limit_would_be_exceeded; 45 // Count of consecutive GC that have exceeded the 46 // GC time limit criterion 47 uint _gc_overhead_limit_count; 48 // This flag signals that GCTimeLimit is being exceeded 49 // but may not have done so for the required number of consecutive 50 // collections 51 52 public: 53 GCOverheadChecker(); 54 55 // This is a hint for the heap: we've detected that gc times 56 // are taking longer than GCTimeLimit allows. 57 // Most heaps will choose to throw an OutOfMemoryError when 58 // this occurs but it is up to the heap to request this information 59 // of the policy 60 bool gc_overhead_limit_exceeded() { 61 return _gc_overhead_limit_exceeded; 62 } 63 void set_gc_overhead_limit_exceeded(bool v) { 64 _gc_overhead_limit_exceeded = v; 65 } 66 67 // Tests conditions indicate the GC overhead limit is being approached. 68 bool gc_overhead_limit_near() { 69 return _gc_overhead_limit_count >= (GCOverheadLimitThreshold - 1); 70 } 71 void reset_gc_overhead_limit_count() { 72 _gc_overhead_limit_count = 0; 73 } 74 75 // Check the conditions for an out-of-memory due to excessive GC time. 76 // Set _gc_overhead_limit_exceeded if all the conditions have been met. 77 void check_gc_overhead_limit(GCOverheadTester* time_overhead, 78 GCOverheadTester* space_overhead, 79 bool is_full_gc, 80 GCCause::Cause gc_cause, 81 SoftRefPolicy* soft_ref_policy); 82 }; 83 84 #endif // SHARE_GC_SHARED_GCOVERHEADCHECKER_HPP