Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/shenandoah/shenandoahControlThread.hpp
38920 views
/*1* Copyright (c) 2013, 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_SHENANDOAHCONCURRENTTHREAD_HPP24#define SHARE_VM_GC_SHENANDOAH_SHENANDOAHCONCURRENTTHREAD_HPP2526#include "gc_interface/gcCause.hpp"27#include "gc_implementation/shared/concurrentGCThread.hpp"28#include "gc_implementation/shenandoah/shenandoahHeap.hpp"29#include "gc_implementation/shenandoah/shenandoahPadding.hpp"30#include "gc_implementation/shenandoah/shenandoahSharedVariables.hpp"31#include "runtime/task.hpp"32#include "utilities/ostream.hpp"3334class ShenandoahControlThread;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 flush SATB buffers periodically.49class ShenandoahPeriodicSATBFlushTask : public PeriodicTask {50public:51ShenandoahPeriodicSATBFlushTask() : PeriodicTask(ShenandoahSATBBufferFlushInterval) {}52virtual void task();53};5455// Periodic task to notify blocked paced waiters.56class ShenandoahPeriodicPacerNotify : public PeriodicTask {57public:58ShenandoahPeriodicPacerNotify() : PeriodicTask(PeriodicTask::min_interval) {}59virtual void task();60};6162class ShenandoahControlThread: public ConcurrentGCThread {63friend class VMStructs;6465private:66typedef enum {67none,68concurrent_normal,69stw_degenerated,70stw_full71} GCMode;7273// While we could have a single lock for these, it may risk unblocking74// GC waiters when alloc failure GC cycle finishes. We want instead75// to make complete explicit cycle for for demanding customers.76Monitor _alloc_failure_waiters_lock;77Monitor _gc_waiters_lock;78ShenandoahPeriodicTask _periodic_task;79ShenandoahPeriodicSATBFlushTask _periodic_satb_flush_task;80ShenandoahPeriodicPacerNotify _periodic_pacer_notify_task;8182private:83static SurrogateLockerThread* _slt;8485public:86void run();87void stop();8889private:90ShenandoahSharedFlag _gc_requested;91ShenandoahSharedFlag _alloc_failure_gc;92ShenandoahSharedFlag _graceful_shutdown;93ShenandoahSharedFlag _heap_changed;94ShenandoahSharedFlag _do_counters_update;95ShenandoahSharedFlag _force_counters_update;96GCCause::Cause _requested_gc_cause;97ShenandoahHeap::ShenandoahDegenPoint _degen_point;9899shenandoah_padding(0);100volatile intptr_t _allocs_seen;101shenandoah_padding(1);102volatile intptr_t _gc_id;103shenandoah_padding(2);104105bool check_cancellation_or_degen(ShenandoahHeap::ShenandoahDegenPoint point);106void service_concurrent_normal_cycle(GCCause::Cause cause);107void service_stw_full_cycle(GCCause::Cause cause);108void service_stw_degenerated_cycle(GCCause::Cause cause, ShenandoahHeap::ShenandoahDegenPoint point);109void service_uncommit(double shrink_before, size_t shrink_until);110111bool try_set_alloc_failure_gc();112void notify_alloc_failure_waiters();113bool is_alloc_failure_gc();114115void reset_gc_id();116void update_gc_id();117size_t get_gc_id();118119void notify_gc_waiters();120121// Handle GC request.122// Blocks until GC is over.123void handle_requested_gc(GCCause::Cause cause);124125bool is_explicit_gc(GCCause::Cause cause) const;126127bool check_soft_max_changed() const;128129public:130// Constructor131ShenandoahControlThread();132~ShenandoahControlThread();133134static void makeSurrogateLockerThread(TRAPS);135static SurrogateLockerThread* slt() { return _slt; }136137// Handle allocation failure from normal allocation.138// Blocks until memory is available.139void handle_alloc_failure(ShenandoahAllocRequest& req);140141// Handle allocation failure from evacuation path.142// Optionally blocks while collector is handling the failure.143void handle_alloc_failure_evac(size_t words);144145void request_gc(GCCause::Cause cause);146147void handle_counters_update();148void handle_force_counters_update();149void set_forced_counters_update(bool value);150151void notify_heap_changed();152153void pacing_notify_alloc(size_t words);154155void start();156void prepare_for_graceful_shutdown();157bool in_graceful_shutdown();158159char* name() const { return (char*)"ShenandoahConcurrentThread";}160161// Printing162void print_on(outputStream* st) const;163void print() const;164165};166167#endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAHCONCURRENTTHREAD_HPP168169170