1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/cmsLockVerifier.cpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,95 @@ 1.4 +/* 1.5 + * Copyright 2002-2005 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +# include "incls/_precompiled.incl" 1.29 +# include "incls/_cmsLockVerifier.cpp.incl" 1.30 + 1.31 +///////////// Locking verification specific to CMS ////////////// 1.32 +// Much like "assert_lock_strong()", except that it relaxes the 1.33 +// assertion somewhat for the parallel GC case, where VM thread 1.34 +// or the CMS thread might hold the lock on behalf of the parallel 1.35 +// threads. The second argument is in support of an extra locking 1.36 +// check for CFL spaces' free list locks. 1.37 +#ifndef PRODUCT 1.38 +void CMSLockVerifier::assert_locked(const Mutex* lock, const Mutex* p_lock) { 1.39 + if (!Universe::is_fully_initialized()) { 1.40 + return; 1.41 + } 1.42 + 1.43 + Thread* myThread = Thread::current(); 1.44 + 1.45 + if (lock == NULL) { // a "lock-free" structure, e.g. MUT, protected by CMS token 1.46 + assert(p_lock == NULL, "Unexpected state"); 1.47 + if (myThread->is_ConcurrentGC_thread()) { 1.48 + // This test might have to change in the future, if there can be 1.49 + // multiple peer CMS threads. But for now, if we're testing the CMS 1.50 + assert(myThread == ConcurrentMarkSweepThread::cmst(), 1.51 + "In CMS, CMS thread is the only Conc GC thread."); 1.52 + assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), 1.53 + "CMS thread should have CMS token"); 1.54 + } else if (myThread->is_VM_thread()) { 1.55 + assert(ConcurrentMarkSweepThread::vm_thread_has_cms_token(), 1.56 + "VM thread should have CMS token"); 1.57 + } else { 1.58 + // Token should be held on our behalf by one of the other 1.59 + // of CMS or VM thread; not enough easily testable 1.60 + // state info to test which here. 1.61 + assert(myThread->is_GC_task_thread(), "Unexpected thread type"); 1.62 + } 1.63 + return; 1.64 + } 1.65 + 1.66 + if (ParallelGCThreads == 0) { 1.67 + assert_lock_strong(lock); 1.68 + } else { 1.69 + if (myThread->is_VM_thread() 1.70 + || myThread->is_ConcurrentGC_thread() 1.71 + || myThread->is_Java_thread()) { 1.72 + // Make sure that we are holding the associated lock. 1.73 + assert_lock_strong(lock); 1.74 + // The checking of p_lock is a spl case for CFLS' free list 1.75 + // locks: we make sure that none of the parallel GC work gang 1.76 + // threads are holding "sub-locks" of freeListLock(). We check only 1.77 + // the parDictionaryAllocLock because the others are too numerous. 1.78 + // This spl case code is somewhat ugly and any improvements 1.79 + // are welcome XXX FIX ME!! 1.80 + if (p_lock != NULL) { 1.81 + assert(!p_lock->is_locked() || p_lock->owned_by_self(), 1.82 + "Possible race between this and parallel GC threads"); 1.83 + } 1.84 + } else if (myThread->is_GC_task_thread()) { 1.85 + // Make sure that the VM or CMS thread holds lock on our behalf 1.86 + // XXX If there were a concept of a gang_master for a (set of) 1.87 + // gang_workers, we could have used the identity of that thread 1.88 + // for checking ownership here; for now we just disjunct. 1.89 + assert(lock->owner() == VMThread::vm_thread() || 1.90 + lock->owner() == ConcurrentMarkSweepThread::cmst(), 1.91 + "Should be locked by VM thread or CMS thread on my behalf"); 1.92 + } else { 1.93 + // Make sure we didn't miss some obscure corner case 1.94 + ShouldNotReachHere(); 1.95 + } 1.96 + } 1.97 +} 1.98 +#endif