author | kvn |
Thu, 27 May 2010 18:01:56 -0700 | |
changeset 5694 | 1e0532a6abff |
parent 4574 | b2d5b0975515 |
child 5547 | f4b087cbb361 |
permissions | -rw-r--r-- |
1 | 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 |
|
4574
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
35 |
void CMSLockVerifier::assert_locked(const Mutex* lock, |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
36 |
const Mutex* p_lock1, |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
37 |
const Mutex* p_lock2) { |
1 | 38 |
if (!Universe::is_fully_initialized()) { |
39 |
return; |
|
40 |
} |
|
41 |
||
42 |
Thread* myThread = Thread::current(); |
|
43 |
||
44 |
if (lock == NULL) { // a "lock-free" structure, e.g. MUT, protected by CMS token |
|
4574
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
45 |
assert(p_lock1 == NULL && p_lock2 == NULL, "Unexpected caller error"); |
1 | 46 |
if (myThread->is_ConcurrentGC_thread()) { |
47 |
// This test might have to change in the future, if there can be |
|
48 |
// multiple peer CMS threads. But for now, if we're testing the CMS |
|
49 |
assert(myThread == ConcurrentMarkSweepThread::cmst(), |
|
50 |
"In CMS, CMS thread is the only Conc GC thread."); |
|
51 |
assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(), |
|
52 |
"CMS thread should have CMS token"); |
|
53 |
} else if (myThread->is_VM_thread()) { |
|
54 |
assert(ConcurrentMarkSweepThread::vm_thread_has_cms_token(), |
|
55 |
"VM thread should have CMS token"); |
|
56 |
} else { |
|
57 |
// Token should be held on our behalf by one of the other |
|
58 |
// of CMS or VM thread; not enough easily testable |
|
59 |
// state info to test which here. |
|
60 |
assert(myThread->is_GC_task_thread(), "Unexpected thread type"); |
|
61 |
} |
|
62 |
return; |
|
63 |
} |
|
64 |
||
4574
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
65 |
if (myThread->is_VM_thread() |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
66 |
|| myThread->is_ConcurrentGC_thread() |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
67 |
|| myThread->is_Java_thread()) { |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
68 |
// Make sure that we are holding the associated lock. |
1 | 69 |
assert_lock_strong(lock); |
4574
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
70 |
// The checking of p_lock is a spl case for CFLS' free list |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
71 |
// locks: we make sure that none of the parallel GC work gang |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
72 |
// threads are holding "sub-locks" of freeListLock(). We check only |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
73 |
// the parDictionaryAllocLock because the others are too numerous. |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
74 |
// This spl case code is somewhat ugly and any improvements |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
75 |
// are welcome. |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
76 |
assert(p_lock1 == NULL || !p_lock1->is_locked() || p_lock1->owned_by_self(), |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
77 |
"Possible race between this and parallel GC threads"); |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
78 |
assert(p_lock2 == NULL || !p_lock2->is_locked() || p_lock2->owned_by_self(), |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
79 |
"Possible race between this and parallel GC threads"); |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
80 |
} else if (myThread->is_GC_task_thread()) { |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
81 |
// Make sure that the VM or CMS thread holds lock on our behalf |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
82 |
// XXX If there were a concept of a gang_master for a (set of) |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
83 |
// gang_workers, we could have used the identity of that thread |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
84 |
// for checking ownership here; for now we just disjunct. |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
85 |
assert(lock->owner() == VMThread::vm_thread() || |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
86 |
lock->owner() == ConcurrentMarkSweepThread::cmst(), |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
87 |
"Should be locked by VM thread or CMS thread on my behalf"); |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
88 |
if (p_lock1 != NULL) { |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
89 |
assert_lock_strong(p_lock1); |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
90 |
} |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
91 |
if (p_lock2 != NULL) { |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
92 |
assert_lock_strong(p_lock2); |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
93 |
} |
1 | 94 |
} else { |
4574
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
95 |
// Make sure we didn't miss some other thread type calling into here; |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
96 |
// perhaps as a result of future VM evolution. |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1
diff
changeset
|
97 |
ShouldNotReachHere(); |
1 | 98 |
} |
99 |
} |
|
100 |
#endif |