hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/cmsLockVerifier.cpp
author ehelin
Tue, 18 Mar 2014 09:03:28 +0100
changeset 23470 ff2a7ea4225d
parent 7397 5b173b4ca846
permissions -rw-r--r--
8036703: Add trace event with statistics for the metaspace chunk free lists Reviewed-by: stefank, mgerdin, coleenp, egahlin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
     2
 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4574
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4574
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4574
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "gc_implementation/concurrentMarkSweep/cmsLockVerifier.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "runtime/vmThread.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
///////////// Locking verification specific to CMS //////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// Much like "assert_lock_strong()", except that it relaxes the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// assertion somewhat for the parallel GC case, where VM thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// or the CMS thread might hold the lock on behalf of the parallel
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// threads. The second argument is in support of an extra locking
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// check for CFL spaces' free list locks.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
#ifndef PRODUCT
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    37
void CMSLockVerifier::assert_locked(const Mutex* lock,
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    38
                                    const Mutex* p_lock1,
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    39
                                    const Mutex* p_lock2) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  if (!Universe::is_fully_initialized()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  Thread* myThread = Thread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  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
    47
    assert(p_lock1 == NULL && p_lock2 == NULL, "Unexpected caller error");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    if (myThread->is_ConcurrentGC_thread()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
      // This test might have to change in the future, if there can be
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
      // multiple peer CMS threads.  But for now, if we're testing the CMS
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
      assert(myThread == ConcurrentMarkSweepThread::cmst(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
             "In CMS, CMS thread is the only Conc GC thread.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
      assert(ConcurrentMarkSweepThread::cms_thread_has_cms_token(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
             "CMS thread should have CMS token");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    } else if (myThread->is_VM_thread()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
      assert(ConcurrentMarkSweepThread::vm_thread_has_cms_token(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
             "VM thread should have CMS token");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
      // Token should be held on our behalf by one of the other
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
      // of CMS or VM thread; not enough easily testable
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
      // state info to test which here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
      assert(myThread->is_GC_task_thread(), "Unexpected thread type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    67
  if (myThread->is_VM_thread()
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    68
      || myThread->is_ConcurrentGC_thread()
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    69
      || myThread->is_Java_thread()) {
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    70
    // Make sure that we are holding the associated lock.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    assert_lock_strong(lock);
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    72
    // 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
    73
    // 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
    74
    // threads are holding "sub-locks" of freeListLock(). We check only
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    75
    // the parDictionaryAllocLock because the others are too numerous.
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    76
    // This spl case code is somewhat ugly and any improvements
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    77
    // are welcome.
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    78
    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
    79
           "Possible race between this and parallel GC threads");
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    80
    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
    81
           "Possible race between this and parallel GC threads");
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    82
  } else if (myThread->is_GC_task_thread()) {
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    83
    // 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
    84
    // 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
    85
    // gang_workers, we could have used the identity of that thread
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    86
    // for checking ownership here; for now we just disjunct.
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    87
    assert(lock->owner() == VMThread::vm_thread() ||
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    88
           lock->owner() == ConcurrentMarkSweepThread::cmst(),
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    89
           "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
    90
    if (p_lock1 != NULL) {
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    91
      assert_lock_strong(p_lock1);
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    92
    }
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    93
    if (p_lock2 != NULL) {
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    94
      assert_lock_strong(p_lock2);
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    95
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  } else {
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    97
    // 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
    98
    // perhaps as a result of future VM evolution.
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 1
diff changeset
    99
    ShouldNotReachHere();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
#endif