annotate src/share/vm/gc_implementation/concurrentMarkSweep/cmsLockVerifier.cpp @ 0:a61af66fc99e jdk7-b24

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