Path: blob/master/src/hotspot/share/gc/shared/concurrentGCBreakpoints.cpp
40957 views
/*1* Copyright (c) 2020, Oracle and/or its affiliates. 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#include "precompiled.hpp"25#include "gc/shared/collectedHeap.hpp"26#include "gc/shared/concurrentGCBreakpoints.hpp"27#include "logging/log.hpp"28#include "memory/universe.hpp"29#include "runtime/interfaceSupport.inline.hpp"30#include "runtime/mutexLocker.hpp"31#include "runtime/thread.hpp"32#include "utilities/debug.hpp"3334// States:35// _run_to _want_idle _is_stopped36// (1) No active request NULL false false37// (2) Active run_to() running non-NULL false false38// (3) Active run_to() in at() NULL false true39// (4) Active run_to_idle() NULL true false40const char* ConcurrentGCBreakpoints::_run_to = NULL;41bool ConcurrentGCBreakpoints::_want_idle = false;42bool ConcurrentGCBreakpoints::_is_stopped = false;4344// True if the collector is idle.45bool ConcurrentGCBreakpoints::_is_idle = true;4647void ConcurrentGCBreakpoints::reset_request_state() {48_run_to = NULL;49_want_idle = false;50_is_stopped = false;51}5253Monitor* ConcurrentGCBreakpoints::monitor() {54return ConcurrentGCBreakpoints_lock;55}5657bool ConcurrentGCBreakpoints::is_controlled() {58assert_locked_or_safepoint(monitor());59return _want_idle || _is_stopped || (_run_to != NULL);60}6162#define assert_Java_thread() \63assert(Thread::current()->is_Java_thread(), "precondition")6465void ConcurrentGCBreakpoints::run_to_idle_impl(bool acquiring_control) {66assert_Java_thread();67MonitorLocker ml(monitor());68if (acquiring_control) {69assert(!is_controlled(), "precondition");70log_trace(gc, breakpoint)("acquire_control");71} else {72assert(is_controlled(), "precondition");73log_trace(gc, breakpoint)("run_to_idle");74}75reset_request_state();76_want_idle = true;77ml.notify_all();78while (!_is_idle) {79ml.wait();80}81}8283void ConcurrentGCBreakpoints::acquire_control() {84run_to_idle_impl(true);85}8687void ConcurrentGCBreakpoints::release_control() {88assert_Java_thread();89MonitorLocker ml(monitor());90log_trace(gc, breakpoint)("release_control");91reset_request_state();92ml.notify_all();93}9495void ConcurrentGCBreakpoints::run_to_idle() {96run_to_idle_impl(false);97}9899bool ConcurrentGCBreakpoints::run_to(const char* breakpoint) {100assert_Java_thread();101assert(breakpoint != NULL, "precondition");102103MonitorLocker ml(monitor());104assert(is_controlled(), "precondition");105log_trace(gc, breakpoint)("run_to %s", breakpoint);106reset_request_state();107_run_to = breakpoint;108ml.notify_all();109110if (_is_idle) {111log_trace(gc, breakpoint)("run_to requesting collection %s", breakpoint);112MutexUnlocker mul(monitor());113Universe::heap()->collect(GCCause::_wb_breakpoint);114}115116// Wait for corresponding at() or a notify_idle().117while (true) {118if (_want_idle) {119// Completed cycle and resumed idle without hitting requested stop.120// That replaced our request with a run_to_idle() request.121log_trace(gc, breakpoint)("run_to missed %s", breakpoint);122return false; // Missed.123} else if (_is_stopped) {124log_trace(gc, breakpoint)("run_to stopped at %s", breakpoint);125return true; // Success.126} else {127ml.wait();128}129}130}131132void ConcurrentGCBreakpoints::at(const char* breakpoint) {133assert(Thread::current()->is_ConcurrentGC_thread(), "precondition");134assert(breakpoint != NULL, "precondition");135MonitorLocker ml(monitor(), Mutex::_no_safepoint_check_flag);136137// Ignore non-matching request state.138if ((_run_to == NULL) || (strcmp(_run_to, breakpoint) != 0)) {139log_trace(gc, breakpoint)("unmatched breakpoint %s", breakpoint);140return;141}142log_trace(gc, breakpoint)("matched breakpoint %s", breakpoint);143144// Notify request.145_run_to = NULL;146_is_stopped = true;147ml.notify_all(); // Wakeup waiting request.148// Wait for request to be cancelled.149while (_is_stopped) {150ml.wait();151}152log_trace(gc, breakpoint)("resumed from breakpoint");153}154155void ConcurrentGCBreakpoints::notify_active_to_idle() {156MonitorLocker ml(monitor(), Mutex::_no_safepoint_check_flag);157assert(!_is_stopped, "invariant");158// Notify pending run_to request of miss by replacing the run_to() request159// with a run_to_idle() request.160if (_run_to != NULL) {161log_debug(gc, breakpoint)162("Concurrent cycle completed without reaching breakpoint %s", _run_to);163_run_to = NULL;164_want_idle = true;165}166_is_idle = true;167monitor()->notify_all();168}169170void ConcurrentGCBreakpoints::notify_idle_to_active() {171assert_locked_or_safepoint(monitor());172_is_idle = false;173}174175176