src/share/vm/gc_implementation/g1/heapRegionSets.cpp

Fri, 14 Mar 2014 10:15:46 +0100

author
brutisso
date
Fri, 14 Mar 2014 10:15:46 +0100
changeset 6385
58fc1b1523dc
parent 3268
8aae2050e83e
permissions
-rw-r--r--

8034079: G1: Refactor the HeapRegionSet hierarchy
Reviewed-by: tschatzl, pliden

tonyp@2472 1 /*
tonyp@2472 2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
tonyp@2472 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
tonyp@2472 4 *
tonyp@2472 5 * This code is free software; you can redistribute it and/or modify it
tonyp@2472 6 * under the terms of the GNU General Public License version 2 only, as
tonyp@2472 7 * published by the Free Software Foundation.
tonyp@2472 8 *
tonyp@2472 9 * This code is distributed in the hope that it will be useful, but WITHOUT
tonyp@2472 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
tonyp@2472 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
tonyp@2472 12 * version 2 for more details (a copy is included in the LICENSE file that
tonyp@2472 13 * accompanied this code).
tonyp@2472 14 *
tonyp@2472 15 * You should have received a copy of the GNU General Public License version
tonyp@2472 16 * 2 along with this work; if not, write to the Free Software Foundation,
tonyp@2472 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
tonyp@2472 18 *
tonyp@2472 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
tonyp@2472 20 * or visit www.oracle.com if you need additional information or have any
tonyp@2472 21 * questions.
tonyp@2472 22 *
tonyp@2472 23 */
tonyp@2472 24
tonyp@2472 25 #include "precompiled.hpp"
tonyp@2974 26 #include "gc_implementation/g1/heapRegionRemSet.hpp"
brutisso@6385 27 #include "gc_implementation/g1/heapRegionSet.hpp"
tonyp@2472 28
tonyp@3268 29 // Note on the check_mt_safety() methods below:
tonyp@3268 30 //
tonyp@3268 31 // Verification of the "master" heap region sets / lists that are
tonyp@3268 32 // maintained by G1CollectedHeap is always done during a STW pause and
tonyp@3268 33 // by the VM thread at the start / end of the pause. The standard
tonyp@3268 34 // verification methods all assert check_mt_safety(). This is
tonyp@3268 35 // important as it ensures that verification is done without
tonyp@3268 36 // concurrent updates taking place at the same time. It follows, that,
tonyp@3268 37 // for the "master" heap region sets / lists, the check_mt_safety()
tonyp@3268 38 // method should include the VM thread / STW case.
tonyp@3268 39
brutisso@6385 40 void FreeRegionList::verify_list() {
brutisso@6385 41 HeapRegion* curr = head();
brutisso@6385 42 HeapRegion* prev1 = NULL;
brutisso@6385 43 HeapRegion* prev0 = NULL;
brutisso@6385 44 uint count = 0;
brutisso@6385 45 size_t capacity = 0;
brutisso@6385 46 while (curr != NULL) {
brutisso@6385 47 verify_region(curr);
tonyp@2472 48
brutisso@6385 49 count++;
brutisso@6385 50 guarantee(count < _unrealistically_long_length,
brutisso@6385 51 hrs_err_msg("[%s] the calculated length: %u seems very long, is there maybe a cycle? curr: "PTR_FORMAT" prev0: "PTR_FORMAT" " "prev1: "PTR_FORMAT" length: %u", name(), count, curr, prev0, prev1, length()));
brutisso@6385 52
brutisso@6385 53 capacity += curr->capacity();
brutisso@6385 54
brutisso@6385 55 prev1 = prev0;
brutisso@6385 56 prev0 = curr;
brutisso@6385 57 curr = curr->next();
tonyp@2472 58 }
brutisso@6385 59
brutisso@6385 60 guarantee(tail() == prev0, err_msg("Expected %s to end with %u but it ended with %u.", name(), tail()->hrs_index(), prev0->hrs_index()));
brutisso@6385 61
brutisso@6385 62 guarantee(length() == count, err_msg("%s count mismatch. Expected %u, actual %u.", name(), length(), count));
brutisso@6385 63 guarantee(total_capacity_bytes() == capacity, err_msg("%s capacity mismatch. Expected " SIZE_FORMAT ", actual " SIZE_FORMAT,
brutisso@6385 64 name(), total_capacity_bytes(), capacity));
tonyp@2472 65 }
tonyp@2472 66
brutisso@6385 67 void MasterFreeRegionListMtSafeChecker::check() {
tonyp@2472 68 // Master Free List MT safety protocol:
tonyp@2472 69 // (a) If we're at a safepoint, operations on the master free list
tonyp@2472 70 // should be invoked by either the VM thread (which will serialize
tonyp@2472 71 // them) or by the GC workers while holding the
tonyp@2472 72 // FreeList_lock.
tonyp@2472 73 // (b) If we're not at a safepoint, operations on the master free
tonyp@2472 74 // list should be invoked while holding the Heap_lock.
tonyp@2472 75
tonyp@3268 76 if (SafepointSynchronize::is_at_safepoint()) {
tonyp@3268 77 guarantee(Thread::current()->is_VM_thread() ||
brutisso@6385 78 FreeList_lock->owned_by_self(), "master free list MT safety protocol at a safepoint");
tonyp@3268 79 } else {
brutisso@6385 80 guarantee(Heap_lock->owned_by_self(), "master free list MT safety protocol outside a safepoint");
tonyp@3268 81 }
tonyp@2472 82 }
tonyp@2472 83
brutisso@6385 84 void SecondaryFreeRegionListMtSafeChecker::check() {
tonyp@2472 85 // Secondary Free List MT safety protocol:
tonyp@2472 86 // Operations on the secondary free list should always be invoked
tonyp@2472 87 // while holding the SecondaryFreeList_lock.
tonyp@2472 88
brutisso@6385 89 guarantee(SecondaryFreeList_lock->owned_by_self(), "secondary free list MT safety protocol");
tonyp@2472 90 }
tonyp@2472 91
brutisso@6385 92 void OldRegionSetMtSafeChecker::check() {
tonyp@3268 93 // Master Old Set MT safety protocol:
tonyp@3268 94 // (a) If we're at a safepoint, operations on the master old set
tonyp@3268 95 // should be invoked:
tonyp@3268 96 // - by the VM thread (which will serialize them), or
tonyp@3268 97 // - by the GC workers while holding the FreeList_lock, if we're
tonyp@3268 98 // at a safepoint for an evacuation pause (this lock is taken
tonyp@3268 99 // anyway when an GC alloc region is retired so that a new one
tonyp@3268 100 // is allocated from the free list), or
tonyp@3268 101 // - by the GC workers while holding the OldSets_lock, if we're at a
tonyp@3268 102 // safepoint for a cleanup pause.
tonyp@3268 103 // (b) If we're not at a safepoint, operations on the master old set
tonyp@3268 104 // should be invoked while holding the Heap_lock.
tonyp@3268 105
tonyp@3268 106 if (SafepointSynchronize::is_at_safepoint()) {
brutisso@6385 107 guarantee(Thread::current()->is_VM_thread()
brutisso@6385 108 || FreeList_lock->owned_by_self() || OldSets_lock->owned_by_self(),
brutisso@6385 109 "master old set MT safety protocol at a safepoint");
tonyp@3268 110 } else {
brutisso@6385 111 guarantee(Heap_lock->owned_by_self(), "master old set MT safety protocol outside a safepoint");
tonyp@3268 112 }
tonyp@3268 113 }
tonyp@3268 114
brutisso@6385 115 void HumongousRegionSetMtSafeChecker::check() {
brutisso@6385 116 // Humongous Set MT safety protocol:
tonyp@2472 117 // (a) If we're at a safepoint, operations on the master humongous
tonyp@2472 118 // set should be invoked by either the VM thread (which will
tonyp@2472 119 // serialize them) or by the GC workers while holding the
tonyp@2472 120 // OldSets_lock.
tonyp@2472 121 // (b) If we're not at a safepoint, operations on the master
tonyp@2472 122 // humongous set should be invoked while holding the Heap_lock.
tonyp@2472 123
tonyp@3268 124 if (SafepointSynchronize::is_at_safepoint()) {
tonyp@3268 125 guarantee(Thread::current()->is_VM_thread() ||
tonyp@3268 126 OldSets_lock->owned_by_self(),
brutisso@6385 127 "master humongous set MT safety protocol at a safepoint");
tonyp@3268 128 } else {
tonyp@3268 129 guarantee(Heap_lock->owned_by_self(),
brutisso@6385 130 "master humongous set MT safety protocol outside a safepoint");
tonyp@3268 131 }
tonyp@2472 132 }

mercurial