Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/cmsLockVerifier.cpp
38920 views
/*1* Copyright (c) 2002, 2010, 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_implementation/concurrentMarkSweep/cmsLockVerifier.hpp"26#include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp"27#include "runtime/vmThread.hpp"2829///////////// Locking verification specific to CMS //////////////30// Much like "assert_lock_strong()", except that it relaxes the31// assertion somewhat for the parallel GC case, where VM thread32// or the CMS thread might hold the lock on behalf of the parallel33// threads. The second argument is in support of an extra locking34// check for CFL spaces' free list locks.35#ifndef PRODUCT36void CMSLockVerifier::assert_locked(const Mutex* lock,37const Mutex* p_lock1,38const Mutex* p_lock2) {39if (!Universe::is_fully_initialized()) {40return;41}4243Thread* myThread = Thread::current();4445if (lock == NULL) { // a "lock-free" structure, e.g. MUT, protected by CMS token46assert(p_lock1 == NULL && p_lock2 == NULL, "Unexpected caller error");47if (myThread->is_ConcurrentGC_thread()) {48// This test might have to change in the future, if there can be49// multiple peer CMS threads. But for now, if we're testing the CMS50assert(myThread == ConcurrentMarkSweepThread::cmst(),51"In CMS, CMS thread is the only Conc GC thread.");52assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(),53"CMS thread should have CMS token");54} else if (myThread->is_VM_thread()) {55assert(ConcurrentMarkSweepThread::vm_thread_has_cms_token(),56"VM thread should have CMS token");57} else {58// Token should be held on our behalf by one of the other59// of CMS or VM thread; not enough easily testable60// state info to test which here.61assert(myThread->is_GC_task_thread(), "Unexpected thread type");62}63return;64}6566if (myThread->is_VM_thread()67|| myThread->is_ConcurrentGC_thread()68|| myThread->is_Java_thread()) {69// Make sure that we are holding the associated lock.70assert_lock_strong(lock);71// The checking of p_lock is a spl case for CFLS' free list72// locks: we make sure that none of the parallel GC work gang73// threads are holding "sub-locks" of freeListLock(). We check only74// the parDictionaryAllocLock because the others are too numerous.75// This spl case code is somewhat ugly and any improvements76// are welcome.77assert(p_lock1 == NULL || !p_lock1->is_locked() || p_lock1->owned_by_self(),78"Possible race between this and parallel GC threads");79assert(p_lock2 == NULL || !p_lock2->is_locked() || p_lock2->owned_by_self(),80"Possible race between this and parallel GC threads");81} else if (myThread->is_GC_task_thread()) {82// Make sure that the VM or CMS thread holds lock on our behalf83// XXX If there were a concept of a gang_master for a (set of)84// gang_workers, we could have used the identity of that thread85// for checking ownership here; for now we just disjunct.86assert(lock->owner() == VMThread::vm_thread() ||87lock->owner() == ConcurrentMarkSweepThread::cmst(),88"Should be locked by VM thread or CMS thread on my behalf");89if (p_lock1 != NULL) {90assert_lock_strong(p_lock1);91}92if (p_lock2 != NULL) {93assert_lock_strong(p_lock2);94}95} else {96// Make sure we didn't miss some other thread type calling into here;97// perhaps as a result of future VM evolution.98ShouldNotReachHere();99}100}101#endif102103104