src/share/vm/gc_implementation/shared/suspendibleThreadSet.cpp

Wed, 31 Jul 2019 14:28:51 -0400

author
kbarrett
date
Wed, 31 Jul 2019 14:28:51 -0400
changeset 9787
9f28a4cac6d9
parent 6906
581e70386ec9
permissions
-rw-r--r--

8048556: Unnecessary GCLocker-initiated young GCs
Summary: Fixed recognition of unnecessary GCLocker collections.
Reviewed-by: pliden, tschatzl
Contributed-by: johnc@azul.com

pliden@6906 1 /*
pliden@6906 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
pliden@6906 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
pliden@6906 4 *
pliden@6906 5 * This code is free software; you can redistribute it and/or modify it
pliden@6906 6 * under the terms of the GNU General Public License version 2 only, as
pliden@6906 7 * published by the Free Software Foundation.
pliden@6906 8 *
pliden@6906 9 * This code is distributed in the hope that it will be useful, but WITHOUT
pliden@6906 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
pliden@6906 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
pliden@6906 12 * version 2 for more details (a copy is included in the LICENSE file that
pliden@6906 13 * accompanied this code).
pliden@6906 14 *
pliden@6906 15 * You should have received a copy of the GNU General Public License version
pliden@6906 16 * 2 along with this work; if not, write to the Free Software Foundation,
pliden@6906 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
pliden@6906 18 *
pliden@6906 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
pliden@6906 20 * or visit www.oracle.com if you need additional information or have any
pliden@6906 21 * questions.
pliden@6906 22 *
pliden@6906 23 */
pliden@6906 24
pliden@6906 25 #include "precompiled.hpp"
pliden@6906 26 #include "gc_implementation/shared/suspendibleThreadSet.hpp"
pliden@6906 27 #include "runtime/mutexLocker.hpp"
pliden@6906 28 #include "runtime/thread.inline.hpp"
pliden@6906 29
pliden@6906 30 uint SuspendibleThreadSet::_nthreads = 0;
pliden@6906 31 uint SuspendibleThreadSet::_nthreads_stopped = 0;
pliden@6906 32 bool SuspendibleThreadSet::_suspend_all = false;
pliden@6906 33 double SuspendibleThreadSet::_suspend_all_start = 0.0;
pliden@6906 34
pliden@6906 35 void SuspendibleThreadSet::join() {
pliden@6906 36 MonitorLockerEx ml(STS_lock, Mutex::_no_safepoint_check_flag);
pliden@6906 37 while (_suspend_all) {
pliden@6906 38 ml.wait(Mutex::_no_safepoint_check_flag);
pliden@6906 39 }
pliden@6906 40 _nthreads++;
pliden@6906 41 }
pliden@6906 42
pliden@6906 43 void SuspendibleThreadSet::leave() {
pliden@6906 44 MonitorLockerEx ml(STS_lock, Mutex::_no_safepoint_check_flag);
pliden@6906 45 assert(_nthreads > 0, "Invalid");
pliden@6906 46 _nthreads--;
pliden@6906 47 if (_suspend_all) {
pliden@6906 48 ml.notify_all();
pliden@6906 49 }
pliden@6906 50 }
pliden@6906 51
pliden@6906 52 void SuspendibleThreadSet::yield() {
pliden@6906 53 if (_suspend_all) {
pliden@6906 54 MonitorLockerEx ml(STS_lock, Mutex::_no_safepoint_check_flag);
pliden@6906 55 if (_suspend_all) {
pliden@6906 56 _nthreads_stopped++;
pliden@6906 57 if (_nthreads_stopped == _nthreads) {
pliden@6906 58 if (ConcGCYieldTimeout > 0) {
pliden@6906 59 double now = os::elapsedTime();
pliden@6906 60 guarantee((now - _suspend_all_start) * 1000.0 < (double)ConcGCYieldTimeout, "Long delay");
pliden@6906 61 }
pliden@6906 62 }
pliden@6906 63 ml.notify_all();
pliden@6906 64 while (_suspend_all) {
pliden@6906 65 ml.wait(Mutex::_no_safepoint_check_flag);
pliden@6906 66 }
pliden@6906 67 assert(_nthreads_stopped > 0, "Invalid");
pliden@6906 68 _nthreads_stopped--;
pliden@6906 69 ml.notify_all();
pliden@6906 70 }
pliden@6906 71 }
pliden@6906 72 }
pliden@6906 73
pliden@6906 74 void SuspendibleThreadSet::synchronize() {
pliden@6906 75 assert(Thread::current()->is_VM_thread(), "Must be the VM thread");
pliden@6906 76 if (ConcGCYieldTimeout > 0) {
pliden@6906 77 _suspend_all_start = os::elapsedTime();
pliden@6906 78 }
pliden@6906 79 MonitorLockerEx ml(STS_lock, Mutex::_no_safepoint_check_flag);
pliden@6906 80 assert(!_suspend_all, "Only one at a time");
pliden@6906 81 _suspend_all = true;
pliden@6906 82 while (_nthreads_stopped < _nthreads) {
pliden@6906 83 ml.wait(Mutex::_no_safepoint_check_flag);
pliden@6906 84 }
pliden@6906 85 }
pliden@6906 86
pliden@6906 87 void SuspendibleThreadSet::desynchronize() {
pliden@6906 88 assert(Thread::current()->is_VM_thread(), "Must be the VM thread");
pliden@6906 89 MonitorLockerEx ml(STS_lock, Mutex::_no_safepoint_check_flag);
pliden@6906 90 assert(_nthreads_stopped == _nthreads, "Invalid");
pliden@6906 91 _suspend_all = false;
pliden@6906 92 ml.notify_all();
pliden@6906 93 }

mercurial