Path: blob/master/src/hotspot/share/gc/shenandoah/heuristics/shenandoahAdaptiveHeuristics.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_SHENANDOAHADAPTIVEHEURISTICS_HPP25#define SHARE_GC_SHENANDOAH_HEURISTICS_SHENANDOAHADAPTIVEHEURISTICS_HPP2627#include "gc/shenandoah/heuristics/shenandoahHeuristics.hpp"28#include "gc/shenandoah/shenandoahPhaseTimings.hpp"29#include "utilities/numberSeq.hpp"3031class ShenandoahAllocationRate : public CHeapObj<mtGC> {32public:33explicit ShenandoahAllocationRate();34void allocation_counter_reset();3536double sample(size_t allocated);3738double instantaneous_rate(size_t allocated) const;39double upper_bound(double sds) const;40bool is_spiking(double rate, double threshold) const;4142private:4344double instantaneous_rate(double time, size_t allocated) const;4546double _last_sample_time;47size_t _last_sample_value;48double _interval_sec;49TruncatedSeq _rate;50TruncatedSeq _rate_avg;51};5253class ShenandoahAdaptiveHeuristics : public ShenandoahHeuristics {54public:55ShenandoahAdaptiveHeuristics();5657virtual ~ShenandoahAdaptiveHeuristics();5859virtual void choose_collection_set_from_regiondata(ShenandoahCollectionSet* cset,60RegionData* data, size_t size,61size_t actual_free);6263void record_cycle_start();64void record_success_concurrent();65void record_success_degenerated();66void record_success_full();6768virtual bool should_start_gc();6970virtual const char* name() { return "Adaptive"; }71virtual bool is_diagnostic() { return false; }72virtual bool is_experimental() { return false; }7374private:75// These are used to adjust the margin of error and the spike threshold76// in response to GC cycle outcomes. These values are shared, but the77// margin of error and spike threshold trend in opposite directions.78const static double FULL_PENALTY_SD;79const static double DEGENERATE_PENALTY_SD;8081const static double MINIMUM_CONFIDENCE;82const static double MAXIMUM_CONFIDENCE;8384const static double LOWEST_EXPECTED_AVAILABLE_AT_END;85const static double HIGHEST_EXPECTED_AVAILABLE_AT_END;8687friend class ShenandoahAllocationRate;8889// Used to record the last trigger that signaled to start a GC.90// This itself is used to decide whether or not to adjust the margin of91// error for the average cycle time and allocation rate or the allocation92// spike detection threshold.93enum Trigger {94SPIKE, RATE, OTHER95};9697void adjust_last_trigger_parameters(double amount);98void adjust_margin_of_error(double amount);99void adjust_spike_threshold(double amount);100101ShenandoahAllocationRate _allocation_rate;102103// The margin of error expressed in standard deviations to add to our104// average cycle time and allocation rate. As this value increases we105// tend to over estimate the rate at which mutators will deplete the106// heap. In other words, erring on the side of caution will trigger more107// concurrent GCs.108double _margin_of_error_sd;109110// The allocation spike threshold is expressed in standard deviations.111// If the standard deviation of the most recent sample of the allocation112// rate exceeds this threshold, a GC cycle is started. As this value113// decreases the sensitivity to allocation spikes increases. In other114// words, lowering the spike threshold will tend to increase the number115// of concurrent GCs.116double _spike_threshold_sd;117118// Remember which trigger is responsible for the last GC cycle. When the119// outcome of the cycle is evaluated we will adjust the parameters for the120// corresponding triggers. Note that successful outcomes will raise121// the spike threshold and lower the margin of error.122Trigger _last_trigger;123124// Keep track of the available memory at the end of a GC cycle. This125// establishes what is 'normal' for the application and is used as a126// source of feedback to adjust trigger parameters.127TruncatedSeq _available;128};129130#endif // SHARE_GC_SHENANDOAH_HEURISTICS_SHENANDOAHADAPTIVEHEURISTICS_HPP131132133