Path: blob/master/src/hotspot/share/gc/shared/concurrentGCThread.cpp
40957 views
/*1* Copyright (c) 2001, 2019, 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/concurrentGCThread.hpp"26#include "runtime/atomic.hpp"27#include "runtime/init.hpp"28#include "runtime/jniHandles.hpp"29#include "runtime/mutexLocker.hpp"30#include "runtime/os.hpp"3132ConcurrentGCThread::ConcurrentGCThread() :33_should_terminate(false),34_has_terminated(false) {}3536void ConcurrentGCThread::create_and_start(ThreadPriority prio) {37if (os::create_thread(this, os::cgc_thread)) {38os::set_priority(this, prio);39os::start_thread(this);40}41}4243void ConcurrentGCThread::run() {44// Setup handle area45set_active_handles(JNIHandleBlock::allocate_block());4647// Wait for initialization to complete48wait_init_completed();4950run_service();5152// Signal thread has terminated53MonitorLocker ml(Terminator_lock);54Atomic::release_store(&_has_terminated, true);55ml.notify_all();56}5758void ConcurrentGCThread::stop() {59assert(!should_terminate(), "Invalid state");60assert(!has_terminated(), "Invalid state");6162// Signal thread to terminate63Atomic::release_store_fence(&_should_terminate, true);6465stop_service();6667// Wait for thread to terminate68MonitorLocker ml(Terminator_lock);69while (!_has_terminated) {70ml.wait();71}72}7374bool ConcurrentGCThread::should_terminate() const {75return Atomic::load_acquire(&_should_terminate);76}7778bool ConcurrentGCThread::has_terminated() const {79return Atomic::load_acquire(&_has_terminated);80}818283