1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/cmsLockVerifier.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,102 @@ 1.4 +/* 1.5 + * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "precompiled.hpp" 1.29 +#include "gc_implementation/concurrentMarkSweep/cmsLockVerifier.hpp" 1.30 +#include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp" 1.31 +#include "runtime/vmThread.hpp" 1.32 + 1.33 +///////////// Locking verification specific to CMS ////////////// 1.34 +// Much like "assert_lock_strong()", except that it relaxes the 1.35 +// assertion somewhat for the parallel GC case, where VM thread 1.36 +// or the CMS thread might hold the lock on behalf of the parallel 1.37 +// threads. The second argument is in support of an extra locking 1.38 +// check for CFL spaces' free list locks. 1.39 +#ifndef PRODUCT 1.40 +void CMSLockVerifier::assert_locked(const Mutex* lock, 1.41 + const Mutex* p_lock1, 1.42 + const Mutex* p_lock2) { 1.43 + if (!Universe::is_fully_initialized()) { 1.44 + return; 1.45 + } 1.46 + 1.47 + Thread* myThread = Thread::current(); 1.48 + 1.49 + if (lock == NULL) { // a "lock-free" structure, e.g. MUT, protected by CMS token 1.50 + assert(p_lock1 == NULL && p_lock2 == NULL, "Unexpected caller error"); 1.51 + if (myThread->is_ConcurrentGC_thread()) { 1.52 + // This test might have to change in the future, if there can be 1.53 + // multiple peer CMS threads. But for now, if we're testing the CMS 1.54 + assert(myThread == ConcurrentMarkSweepThread::cmst(), 1.55 + "In CMS, CMS thread is the only Conc GC thread."); 1.56 + assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), 1.57 + "CMS thread should have CMS token"); 1.58 + } else if (myThread->is_VM_thread()) { 1.59 + assert(ConcurrentMarkSweepThread::vm_thread_has_cms_token(), 1.60 + "VM thread should have CMS token"); 1.61 + } else { 1.62 + // Token should be held on our behalf by one of the other 1.63 + // of CMS or VM thread; not enough easily testable 1.64 + // state info to test which here. 1.65 + assert(myThread->is_GC_task_thread(), "Unexpected thread type"); 1.66 + } 1.67 + return; 1.68 + } 1.69 + 1.70 + if (myThread->is_VM_thread() 1.71 + || myThread->is_ConcurrentGC_thread() 1.72 + || myThread->is_Java_thread()) { 1.73 + // Make sure that we are holding the associated lock. 1.74 + assert_lock_strong(lock); 1.75 + // The checking of p_lock is a spl case for CFLS' free list 1.76 + // locks: we make sure that none of the parallel GC work gang 1.77 + // threads are holding "sub-locks" of freeListLock(). We check only 1.78 + // the parDictionaryAllocLock because the others are too numerous. 1.79 + // This spl case code is somewhat ugly and any improvements 1.80 + // are welcome. 1.81 + assert(p_lock1 == NULL || !p_lock1->is_locked() || p_lock1->owned_by_self(), 1.82 + "Possible race between this and parallel GC threads"); 1.83 + assert(p_lock2 == NULL || !p_lock2->is_locked() || p_lock2->owned_by_self(), 1.84 + "Possible race between this and parallel GC threads"); 1.85 + } else if (myThread->is_GC_task_thread()) { 1.86 + // Make sure that the VM or CMS thread holds lock on our behalf 1.87 + // XXX If there were a concept of a gang_master for a (set of) 1.88 + // gang_workers, we could have used the identity of that thread 1.89 + // for checking ownership here; for now we just disjunct. 1.90 + assert(lock->owner() == VMThread::vm_thread() || 1.91 + lock->owner() == ConcurrentMarkSweepThread::cmst(), 1.92 + "Should be locked by VM thread or CMS thread on my behalf"); 1.93 + if (p_lock1 != NULL) { 1.94 + assert_lock_strong(p_lock1); 1.95 + } 1.96 + if (p_lock2 != NULL) { 1.97 + assert_lock_strong(p_lock2); 1.98 + } 1.99 + } else { 1.100 + // Make sure we didn't miss some other thread type calling into here; 1.101 + // perhaps as a result of future VM evolution. 1.102 + ShouldNotReachHere(); 1.103 + } 1.104 +} 1.105 +#endif