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

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 #ifndef SHARE_VM_GC_IMPLEMENTATION_SHARED_SUSPENDIBLETHREADSET_HPP
pliden@6906 26 #define SHARE_VM_GC_IMPLEMENTATION_SHARED_SUSPENDIBLETHREADSET_HPP
pliden@6906 27
pliden@6906 28 #include "memory/allocation.hpp"
pliden@6906 29
pliden@6906 30 // A SuspendibleThreadSet is a set of threads that can be suspended.
pliden@6906 31 // A thread can join and later leave the set, and periodically yield.
pliden@6906 32 // If some thread (not in the set) requests, via synchronize(), that
pliden@6906 33 // the threads be suspended, then the requesting thread is blocked
pliden@6906 34 // until all the threads in the set have yielded or left the set. Threads
pliden@6906 35 // may not enter the set when an attempted suspension is in progress. The
pliden@6906 36 // suspending thread later calls desynchronize(), allowing the suspended
pliden@6906 37 // threads to continue.
pliden@6906 38 class SuspendibleThreadSet : public AllStatic {
pliden@6906 39 private:
pliden@6906 40 static uint _nthreads;
pliden@6906 41 static uint _nthreads_stopped;
pliden@6906 42 static bool _suspend_all;
pliden@6906 43 static double _suspend_all_start;
pliden@6906 44
pliden@6906 45 public:
pliden@6906 46 // Add the current thread to the set. May block if a suspension is in progress.
pliden@6906 47 static void join();
pliden@6906 48
pliden@6906 49 // Removes the current thread from the set.
pliden@6906 50 static void leave();
pliden@6906 51
pliden@6906 52 // Returns true if an suspension is in progress.
pliden@6906 53 static bool should_yield() { return _suspend_all; }
pliden@6906 54
pliden@6906 55 // Suspends the current thread if a suspension is in progress.
pliden@6906 56 static void yield();
pliden@6906 57
pliden@6906 58 // Returns when all threads in the set are suspended.
pliden@6906 59 static void synchronize();
pliden@6906 60
pliden@6906 61 // Resumes all suspended threads in the set.
pliden@6906 62 static void desynchronize();
pliden@6906 63 };
pliden@6906 64
pliden@6906 65 class SuspendibleThreadSetJoiner : public StackObj {
pliden@6906 66 public:
pliden@6906 67 SuspendibleThreadSetJoiner() {
pliden@6906 68 SuspendibleThreadSet::join();
pliden@6906 69 }
pliden@6906 70
pliden@6906 71 ~SuspendibleThreadSetJoiner() {
pliden@6906 72 SuspendibleThreadSet::leave();
pliden@6906 73 }
pliden@6906 74
pliden@6906 75 bool should_yield() {
pliden@6906 76 return SuspendibleThreadSet::should_yield();
pliden@6906 77 }
pliden@6906 78
pliden@6906 79 void yield() {
pliden@6906 80 SuspendibleThreadSet::yield();
pliden@6906 81 }
pliden@6906 82 };
pliden@6906 83
pliden@6906 84 #endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_SUSPENDIBLETHREADSET_HPP

mercurial