src/share/vm/gc_implementation/concurrentMarkSweep/cmsLockVerifier.cpp

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 435
a61af66fc99e
child 1580
e018e6884bd8
permissions
-rw-r--r--

Initial load

duke@435 1 /*
duke@435 2 * Copyright 2002-2005 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 # include "incls/_precompiled.incl"
duke@435 26 # include "incls/_cmsLockVerifier.cpp.incl"
duke@435 27
duke@435 28 ///////////// Locking verification specific to CMS //////////////
duke@435 29 // Much like "assert_lock_strong()", except that it relaxes the
duke@435 30 // assertion somewhat for the parallel GC case, where VM thread
duke@435 31 // or the CMS thread might hold the lock on behalf of the parallel
duke@435 32 // threads. The second argument is in support of an extra locking
duke@435 33 // check for CFL spaces' free list locks.
duke@435 34 #ifndef PRODUCT
duke@435 35 void CMSLockVerifier::assert_locked(const Mutex* lock, const Mutex* p_lock) {
duke@435 36 if (!Universe::is_fully_initialized()) {
duke@435 37 return;
duke@435 38 }
duke@435 39
duke@435 40 Thread* myThread = Thread::current();
duke@435 41
duke@435 42 if (lock == NULL) { // a "lock-free" structure, e.g. MUT, protected by CMS token
duke@435 43 assert(p_lock == NULL, "Unexpected state");
duke@435 44 if (myThread->is_ConcurrentGC_thread()) {
duke@435 45 // This test might have to change in the future, if there can be
duke@435 46 // multiple peer CMS threads. But for now, if we're testing the CMS
duke@435 47 assert(myThread == ConcurrentMarkSweepThread::cmst(),
duke@435 48 "In CMS, CMS thread is the only Conc GC thread.");
duke@435 49 assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(),
duke@435 50 "CMS thread should have CMS token");
duke@435 51 } else if (myThread->is_VM_thread()) {
duke@435 52 assert(ConcurrentMarkSweepThread::vm_thread_has_cms_token(),
duke@435 53 "VM thread should have CMS token");
duke@435 54 } else {
duke@435 55 // Token should be held on our behalf by one of the other
duke@435 56 // of CMS or VM thread; not enough easily testable
duke@435 57 // state info to test which here.
duke@435 58 assert(myThread->is_GC_task_thread(), "Unexpected thread type");
duke@435 59 }
duke@435 60 return;
duke@435 61 }
duke@435 62
duke@435 63 if (ParallelGCThreads == 0) {
duke@435 64 assert_lock_strong(lock);
duke@435 65 } else {
duke@435 66 if (myThread->is_VM_thread()
duke@435 67 || myThread->is_ConcurrentGC_thread()
duke@435 68 || myThread->is_Java_thread()) {
duke@435 69 // Make sure that we are holding the associated lock.
duke@435 70 assert_lock_strong(lock);
duke@435 71 // The checking of p_lock is a spl case for CFLS' free list
duke@435 72 // locks: we make sure that none of the parallel GC work gang
duke@435 73 // threads are holding "sub-locks" of freeListLock(). We check only
duke@435 74 // the parDictionaryAllocLock because the others are too numerous.
duke@435 75 // This spl case code is somewhat ugly and any improvements
duke@435 76 // are welcome XXX FIX ME!!
duke@435 77 if (p_lock != NULL) {
duke@435 78 assert(!p_lock->is_locked() || p_lock->owned_by_self(),
duke@435 79 "Possible race between this and parallel GC threads");
duke@435 80 }
duke@435 81 } else if (myThread->is_GC_task_thread()) {
duke@435 82 // Make sure that the VM or CMS thread holds lock on our behalf
duke@435 83 // XXX If there were a concept of a gang_master for a (set of)
duke@435 84 // gang_workers, we could have used the identity of that thread
duke@435 85 // for checking ownership here; for now we just disjunct.
duke@435 86 assert(lock->owner() == VMThread::vm_thread() ||
duke@435 87 lock->owner() == ConcurrentMarkSweepThread::cmst(),
duke@435 88 "Should be locked by VM thread or CMS thread on my behalf");
duke@435 89 } else {
duke@435 90 // Make sure we didn't miss some obscure corner case
duke@435 91 ShouldNotReachHere();
duke@435 92 }
duke@435 93 }
duke@435 94 }
duke@435 95 #endif

mercurial