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