Path: blob/master/src/hotspot/share/gc/shenandoah/shenandoahControlThread.hpp
40957 views
/*1* Copyright (c) 2013, 2021, 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_SHENANDOAHCONTROLTHREAD_HPP25#define SHARE_GC_SHENANDOAH_SHENANDOAHCONTROLTHREAD_HPP2627#include "gc/shared/gcCause.hpp"28#include "gc/shared/concurrentGCThread.hpp"29#include "gc/shenandoah/shenandoahGC.hpp"30#include "gc/shenandoah/shenandoahHeap.hpp"31#include "gc/shenandoah/shenandoahPadding.hpp"32#include "gc/shenandoah/shenandoahSharedVariables.hpp"33#include "runtime/task.hpp"34#include "utilities/ostream.hpp"3536// Periodic task is useful for doing asynchronous things that do not require (heap) locks,37// or synchronization with other parts of collector. These could run even when ShenandoahConcurrentThread38// is busy driving the GC cycle.39class ShenandoahPeriodicTask : public PeriodicTask {40private:41ShenandoahControlThread* _thread;42public:43ShenandoahPeriodicTask(ShenandoahControlThread* thread) :44PeriodicTask(100), _thread(thread) {}45virtual void task();46};4748// Periodic task to notify blocked paced waiters.49class ShenandoahPeriodicPacerNotify : public PeriodicTask {50public:51ShenandoahPeriodicPacerNotify() : PeriodicTask(PeriodicTask::min_interval) {}52virtual void task();53};5455class ShenandoahControlThread: public ConcurrentGCThread {56friend class VMStructs;5758private:59typedef enum {60none,61concurrent_normal,62stw_degenerated,63stw_full64} GCMode;6566// While we could have a single lock for these, it may risk unblocking67// GC waiters when alloc failure GC cycle finishes. We want instead68// to make complete explicit cycle for for demanding customers.69Monitor _alloc_failure_waiters_lock;70Monitor _gc_waiters_lock;71ShenandoahPeriodicTask _periodic_task;72ShenandoahPeriodicPacerNotify _periodic_pacer_notify_task;7374public:75void run_service();76void stop_service();7778private:79ShenandoahSharedFlag _gc_requested;80ShenandoahSharedFlag _alloc_failure_gc;81ShenandoahSharedFlag _graceful_shutdown;82ShenandoahSharedFlag _heap_changed;83ShenandoahSharedFlag _do_counters_update;84ShenandoahSharedFlag _force_counters_update;85GCCause::Cause _requested_gc_cause;86ShenandoahGC::ShenandoahDegenPoint _degen_point;8788shenandoah_padding(0);89volatile size_t _allocs_seen;90shenandoah_padding(1);91volatile size_t _gc_id;92shenandoah_padding(2);9394bool check_cancellation_or_degen(ShenandoahGC::ShenandoahDegenPoint point);95void service_concurrent_normal_cycle(GCCause::Cause cause);96void service_stw_full_cycle(GCCause::Cause cause);97void service_stw_degenerated_cycle(GCCause::Cause cause, ShenandoahGC::ShenandoahDegenPoint point);98void service_uncommit(double shrink_before, size_t shrink_until);99100bool try_set_alloc_failure_gc();101void notify_alloc_failure_waiters();102bool is_alloc_failure_gc();103104void reset_gc_id();105void update_gc_id();106size_t get_gc_id();107108void notify_gc_waiters();109110// Handle GC request.111// Blocks until GC is over.112void handle_requested_gc(GCCause::Cause cause);113114bool is_explicit_gc(GCCause::Cause cause) const;115116bool check_soft_max_changed() const;117118public:119// Constructor120ShenandoahControlThread();121~ShenandoahControlThread();122123// Handle allocation failure from normal allocation.124// Blocks until memory is available.125void handle_alloc_failure(ShenandoahAllocRequest& req);126127// Handle allocation failure from evacuation path.128// Optionally blocks while collector is handling the failure.129void handle_alloc_failure_evac(size_t words);130131void request_gc(GCCause::Cause cause);132133void handle_counters_update();134void handle_force_counters_update();135void set_forced_counters_update(bool value);136137void notify_heap_changed();138139void pacing_notify_alloc(size_t words);140141void start();142void prepare_for_graceful_shutdown();143bool in_graceful_shutdown();144145char* name() const { return (char*)"ShenandoahControlThread";}146147// Printing148void print_on(outputStream* st) const;149void print() const;150};151152#endif // SHARE_GC_SHENANDOAH_SHENANDOAHCONTROLTHREAD_HPP153154155