/* * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. * */ #ifndef SHARE_GC_G1_G1CONCURRENTHEAPRESIZETHREAD_HPP #define SHARE_GC_G1_G1CONCURRENTHEAPRESIZETHREAD_HPP #include "gc/shared/concurrentGCThread.hpp" class G1Policy; class G1ConcurrentHeapResize; // The concurrent heap resize thread helps to commit/uncommit heap region memory // to avoid the time spend in STW pause class G1ConcurrentHeapResizeThread : public ConcurrentGCThread { G1ConcurrentHeapResize* _concurrent_heap_resize; // The concurrent resizing thread has 3 states: // Idle: thread is waiting for start // Working: thread has started and is doing the work of memory commit/uncommit // Done: the work of memory commit/uncommit has finished but regions have not synchronized yet enum State { Idle, Working, Done, }; volatile State _state; Monitor* _start_monitor; // used notify the start of resize thread Monitor* _done_monitor; // used to notify concurrent resize is done void sleep_before_next_cycle(); void run_service(); void stop_service(); public: // Constructor G1ConcurrentHeapResizeThread(G1ConcurrentHeapResize* heap_resize); G1ConcurrentHeapResize* concurrent_heap_resize() { return _concurrent_heap_resize; } void set_idle() { assert(_state != Working, "must not be working"); _state = Idle; } bool idle() const { return _state == Idle; } void set_working() { assert(_state == Idle, "must be idle"); _state = Working; } bool working() const { return _state == Working; } void set_done() { assert(_state == Working, "must be working"); _state = Done; } bool done() const { return _state == Done; } // Returns true if a concurrent resizing cycle is in progress bool during_cycle() { return !idle(); } Monitor* start_monitor() { return _start_monitor; } Monitor* done_monitor() { return _done_monitor; } }; #endif // SHARE_GC_G1_G1CONCURRENTHEAPRESIZETHREAD_HPP