Path: blob/master/src/hotspot/share/gc/shenandoah/heuristics/shenandoahHeuristics.hpp
40975 views
/*1* Copyright (c) 2018, 2019, Red Hat, Inc. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_GC_SHENANDOAH_HEURISTICS_SHENANDOAHHEURISTICS_HPP25#define SHARE_GC_SHENANDOAH_HEURISTICS_SHENANDOAHHEURISTICS_HPP2627#include "gc/shenandoah/shenandoahHeap.hpp"28#include "gc/shenandoah/shenandoahPhaseTimings.hpp"29#include "gc/shenandoah/shenandoahSharedVariables.hpp"30#include "memory/allocation.hpp"31#include "runtime/globals_extension.hpp"3233#define SHENANDOAH_ERGO_DISABLE_FLAG(name) \34do { \35if (FLAG_IS_DEFAULT(name) && (name)) { \36log_info(gc)("Heuristics ergonomically sets -XX:-" #name); \37FLAG_SET_DEFAULT(name, false); \38} \39} while (0)4041#define SHENANDOAH_ERGO_ENABLE_FLAG(name) \42do { \43if (FLAG_IS_DEFAULT(name) && !(name)) { \44log_info(gc)("Heuristics ergonomically sets -XX:+" #name); \45FLAG_SET_DEFAULT(name, true); \46} \47} while (0)4849#define SHENANDOAH_ERGO_OVERRIDE_DEFAULT(name, value) \50do { \51if (FLAG_IS_DEFAULT(name)) { \52log_info(gc)("Heuristics ergonomically sets -XX:" #name "=" #value); \53FLAG_SET_DEFAULT(name, value); \54} \55} while (0)5657class ShenandoahCollectionSet;58class ShenandoahHeapRegion;5960class ShenandoahHeuristics : public CHeapObj<mtGC> {61static const intx Concurrent_Adjust = -1; // recover from penalties62static const intx Degenerated_Penalty = 10; // how much to penalize average GC duration history on Degenerated GC63static const intx Full_Penalty = 20; // how much to penalize average GC duration history on Full GC6465protected:66typedef struct {67ShenandoahHeapRegion* _region;68size_t _garbage;69} RegionData;7071RegionData* _region_data;7273uint _degenerated_cycles_in_a_row;74uint _successful_cycles_in_a_row;7576double _cycle_start;77double _last_cycle_end;7879size_t _gc_times_learned;80intx _gc_time_penalties;81TruncatedSeq* _gc_time_history;8283// There may be many threads that contend to set this flag84ShenandoahSharedFlag _metaspace_oom;8586static int compare_by_garbage(RegionData a, RegionData b);8788virtual void choose_collection_set_from_regiondata(ShenandoahCollectionSet* set,89RegionData* data, size_t data_size,90size_t free) = 0;9192void adjust_penalty(intx step);9394public:95ShenandoahHeuristics();96virtual ~ShenandoahHeuristics();9798void record_metaspace_oom() { _metaspace_oom.set(); }99void clear_metaspace_oom() { _metaspace_oom.unset(); }100bool has_metaspace_oom() const { return _metaspace_oom.is_set(); }101102virtual void record_cycle_start();103104virtual void record_cycle_end();105106virtual bool should_start_gc();107108virtual bool should_degenerate_cycle();109110virtual void record_success_concurrent();111112virtual void record_success_degenerated();113114virtual void record_success_full();115116virtual void record_allocation_failure_gc();117118virtual void record_requested_gc();119120virtual void choose_collection_set(ShenandoahCollectionSet* collection_set);121122virtual bool can_unload_classes();123virtual bool can_unload_classes_normal();124virtual bool should_unload_classes();125126virtual const char* name() = 0;127virtual bool is_diagnostic() = 0;128virtual bool is_experimental() = 0;129virtual void initialize();130131double time_since_last_gc() const;132};133134#endif // SHARE_GC_SHENANDOAH_HEURISTICS_SHENANDOAHHEURISTICS_HPP135136137