duke@435: /* stefank@2314: * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #include "precompiled.hpp" stefank@2314: #include "gc_implementation/concurrentMarkSweep/cmsLockVerifier.hpp" stefank@2314: #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp" stefank@2314: #include "runtime/vmThread.hpp" duke@435: duke@435: ///////////// Locking verification specific to CMS ////////////// duke@435: // Much like "assert_lock_strong()", except that it relaxes the duke@435: // assertion somewhat for the parallel GC case, where VM thread duke@435: // or the CMS thread might hold the lock on behalf of the parallel duke@435: // threads. The second argument is in support of an extra locking duke@435: // check for CFL spaces' free list locks. duke@435: #ifndef PRODUCT ysr@1580: void CMSLockVerifier::assert_locked(const Mutex* lock, ysr@1580: const Mutex* p_lock1, ysr@1580: const Mutex* p_lock2) { duke@435: if (!Universe::is_fully_initialized()) { duke@435: return; duke@435: } duke@435: duke@435: Thread* myThread = Thread::current(); duke@435: duke@435: if (lock == NULL) { // a "lock-free" structure, e.g. MUT, protected by CMS token ysr@1580: assert(p_lock1 == NULL && p_lock2 == NULL, "Unexpected caller error"); duke@435: if (myThread->is_ConcurrentGC_thread()) { duke@435: // This test might have to change in the future, if there can be duke@435: // multiple peer CMS threads. But for now, if we're testing the CMS duke@435: assert(myThread == ConcurrentMarkSweepThread::cmst(), duke@435: "In CMS, CMS thread is the only Conc GC thread."); duke@435: assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), duke@435: "CMS thread should have CMS token"); duke@435: } else if (myThread->is_VM_thread()) { duke@435: assert(ConcurrentMarkSweepThread::vm_thread_has_cms_token(), duke@435: "VM thread should have CMS token"); duke@435: } else { duke@435: // Token should be held on our behalf by one of the other duke@435: // of CMS or VM thread; not enough easily testable duke@435: // state info to test which here. duke@435: assert(myThread->is_GC_task_thread(), "Unexpected thread type"); duke@435: } duke@435: return; duke@435: } duke@435: ysr@1580: if (myThread->is_VM_thread() ysr@1580: || myThread->is_ConcurrentGC_thread() ysr@1580: || myThread->is_Java_thread()) { ysr@1580: // Make sure that we are holding the associated lock. duke@435: assert_lock_strong(lock); ysr@1580: // The checking of p_lock is a spl case for CFLS' free list ysr@1580: // locks: we make sure that none of the parallel GC work gang ysr@1580: // threads are holding "sub-locks" of freeListLock(). We check only ysr@1580: // the parDictionaryAllocLock because the others are too numerous. ysr@1580: // This spl case code is somewhat ugly and any improvements ysr@1580: // are welcome. ysr@1580: assert(p_lock1 == NULL || !p_lock1->is_locked() || p_lock1->owned_by_self(), ysr@1580: "Possible race between this and parallel GC threads"); ysr@1580: assert(p_lock2 == NULL || !p_lock2->is_locked() || p_lock2->owned_by_self(), ysr@1580: "Possible race between this and parallel GC threads"); ysr@1580: } else if (myThread->is_GC_task_thread()) { ysr@1580: // Make sure that the VM or CMS thread holds lock on our behalf ysr@1580: // XXX If there were a concept of a gang_master for a (set of) ysr@1580: // gang_workers, we could have used the identity of that thread ysr@1580: // for checking ownership here; for now we just disjunct. ysr@1580: assert(lock->owner() == VMThread::vm_thread() || ysr@1580: lock->owner() == ConcurrentMarkSweepThread::cmst(), ysr@1580: "Should be locked by VM thread or CMS thread on my behalf"); ysr@1580: if (p_lock1 != NULL) { ysr@1580: assert_lock_strong(p_lock1); ysr@1580: } ysr@1580: if (p_lock2 != NULL) { ysr@1580: assert_lock_strong(p_lock2); ysr@1580: } duke@435: } else { ysr@1580: // Make sure we didn't miss some other thread type calling into here; ysr@1580: // perhaps as a result of future VM evolution. ysr@1580: ShouldNotReachHere(); duke@435: } duke@435: } duke@435: #endif