--- /dev/null 2019-10-08 16:01:21.069130487 +0800 +++ new/src/hotspot/share/gc/g1/g1ConcurrentHeapResizeThread.cpp 2020-01-03 17:56:50.339813048 +0800 @@ -0,0 +1,74 @@ +/* + * 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. + * + */ + +#include "precompiled.hpp" +#include "gc/g1/g1CollectedHeap.inline.hpp" +#include "gc/g1/g1ConcurrentHeapResizeThread.hpp" +#include "gc/g1/g1Policy.hpp" + +G1ConcurrentHeapResizeThread::G1ConcurrentHeapResizeThread(G1ConcurrentHeapResize* heap_resize) : + ConcurrentGCThread(), + _concurrent_heap_resize(heap_resize), + _state(Idle), + _start_monitor(NULL), + _done_monitor(NULL) { + + _start_monitor = new Monitor(Mutex::nonleaf, "Concurrent resize start monitor", true, + Monitor::_safepoint_check_never); + _done_monitor = new Monitor(Mutex::nonleaf, "Concurrent resize done monitor", true, + Monitor::_safepoint_check_never); + + set_name("G1 concurrent heap resizer"); + create_and_start(); +} + +void G1ConcurrentHeapResizeThread::run_service() { + + G1CollectedHeap* g1h = G1CollectedHeap::heap(); + G1Policy* policy = g1h->policy(); + + while (!should_terminate()) { + // wait until working is set. + sleep_before_next_cycle(); + if (should_terminate()) { + break; + } + concurrent_heap_resize()->do_work(); + concurrent_heap_resize()->notify_work_done(); + } +} + +void G1ConcurrentHeapResizeThread::stop_service() { + MutexLocker ml(_start_monitor, Mutex::_no_safepoint_check_flag); + _start_monitor->notify_all(); +} + +void G1ConcurrentHeapResizeThread::sleep_before_next_cycle() { + assert(!working(), "should have been cleared"); + + MonitorLocker ml(_start_monitor, Mutex::_no_safepoint_check_flag); + while (!working() && !should_terminate()) { + ml.wait(); + } +}