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