Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/shenandoah/heuristics/shenandoahHeuristics.hpp
38922 views
/*1* Copyright (c) 2018, Red Hat, Inc. All rights reserved.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation.6*7* This code is distributed in the hope that it will be useful, but WITHOUT8* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or9* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License10* version 2 for more details (a copy is included in the LICENSE file that11* accompanied this code).12*13* You should have received a copy of the GNU General Public License version14* 2 along with this work; if not, write to the Free Software Foundation,15* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.16*17* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA18* or visit www.oracle.com if you need additional information or have any19* questions.20*21*/2223#ifndef SHARE_VM_GC_SHENANDOAH_HEURISTICS_SHENANDOAHHEURISTICS_HPP24#define SHARE_VM_GC_SHENANDOAH_HEURISTICS_SHENANDOAHHEURISTICS_HPP2526#include "gc_implementation/shenandoah/shenandoahHeap.hpp"27#include "gc_implementation/shenandoah/shenandoahPhaseTimings.hpp"28#include "gc_implementation/shenandoah/shenandoahSharedVariables.hpp"29#include "memory/allocation.hpp"30#include "runtime/globals_extension.hpp"31#include "runtime/java.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() const;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 start_choose_collection_set() {121}122virtual void end_choose_collection_set() {123}124125virtual void choose_collection_set(ShenandoahCollectionSet* collection_set);126127virtual bool can_process_references();128virtual bool should_process_references();129130virtual bool can_unload_classes();131virtual bool can_unload_classes_normal();132virtual bool should_unload_classes();133134virtual const char* name() = 0;135virtual bool is_diagnostic() = 0;136virtual bool is_experimental() = 0;137virtual void initialize();138139double time_since_last_gc() const;140};141142#endif // SHARE_VM_GC_SHENANDOAH_HEURISTICS_SHENANDOAHHEURISTICS_HPP143144145