2037N/A/*
2037N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
2037N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2037N/A *
2037N/A * This code is free software; you can redistribute it and/or modify it
2037N/A * under the terms of the GNU General Public License version 2 only, as
2037N/A * published by the Free Software Foundation.
2037N/A *
2037N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2037N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2037N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2037N/A * version 2 for more details (a copy is included in the LICENSE file that
2037N/A * accompanied this code).
2037N/A *
2037N/A * You should have received a copy of the GNU General Public License version
2037N/A * 2 along with this work; if not, write to the Free Software Foundation,
2037N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2037N/A *
2037N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2037N/A * or visit www.oracle.com if you need additional information or have any
2037N/A * questions.
2037N/A *
2037N/A */
2037N/A
2037N/A#include "precompiled.hpp"
2602N/A#include "gc_implementation/g1/heapRegionRemSet.hpp"
2037N/A#include "gc_implementation/g1/heapRegionSets.hpp"
2037N/A
2910N/A// Note on the check_mt_safety() methods below:
2910N/A//
2910N/A// Verification of the "master" heap region sets / lists that are
2910N/A// maintained by G1CollectedHeap is always done during a STW pause and
2910N/A// by the VM thread at the start / end of the pause. The standard
2910N/A// verification methods all assert check_mt_safety(). This is
2910N/A// important as it ensures that verification is done without
2910N/A// concurrent updates taking place at the same time. It follows, that,
2910N/A// for the "master" heap region sets / lists, the check_mt_safety()
2910N/A// method should include the VM thread / STW case.
2910N/A
2037N/A//////////////////// FreeRegionList ////////////////////
2037N/A
2037N/Aconst char* FreeRegionList::verify_region_extra(HeapRegion* hr) {
2037N/A if (hr->is_young()) {
2037N/A return "the region should not be young";
2037N/A }
2037N/A // The superclass will check that the region is empty and
2910N/A // not humongous.
2037N/A return HeapRegionLinkedList::verify_region_extra(hr);
2037N/A}
2037N/A
2037N/A//////////////////// MasterFreeRegionList ////////////////////
2037N/A
2602N/Aconst char* MasterFreeRegionList::verify_region_extra(HeapRegion* hr) {
2602N/A // We should reset the RSet for parallel iteration before we add it
2602N/A // to the master free list so that it is ready when the region is
2602N/A // re-allocated.
2602N/A if (!hr->rem_set()->verify_ready_for_par_iteration()) {
2602N/A return "the region's RSet should be ready for parallel iteration";
2602N/A }
2602N/A return FreeRegionList::verify_region_extra(hr);
2602N/A}
2602N/A
2037N/Abool MasterFreeRegionList::check_mt_safety() {
2037N/A // Master Free List MT safety protocol:
2037N/A // (a) If we're at a safepoint, operations on the master free list
2037N/A // should be invoked by either the VM thread (which will serialize
2037N/A // them) or by the GC workers while holding the
2037N/A // FreeList_lock.
2037N/A // (b) If we're not at a safepoint, operations on the master free
2037N/A // list should be invoked while holding the Heap_lock.
2037N/A
2910N/A if (SafepointSynchronize::is_at_safepoint()) {
2910N/A guarantee(Thread::current()->is_VM_thread() ||
2910N/A FreeList_lock->owned_by_self(),
2910N/A hrs_ext_msg(this, "master free list MT safety protocol "
2910N/A "at a safepoint"));
2910N/A } else {
2910N/A guarantee(Heap_lock->owned_by_self(),
2910N/A hrs_ext_msg(this, "master free list MT safety protocol "
2910N/A "outside a safepoint"));
2910N/A }
2037N/A
2037N/A return FreeRegionList::check_mt_safety();
2037N/A}
2037N/A
2037N/A//////////////////// SecondaryFreeRegionList ////////////////////
2037N/A
2037N/Abool SecondaryFreeRegionList::check_mt_safety() {
2037N/A // Secondary Free List MT safety protocol:
2037N/A // Operations on the secondary free list should always be invoked
2037N/A // while holding the SecondaryFreeList_lock.
2037N/A
2037N/A guarantee(SecondaryFreeList_lock->owned_by_self(),
2208N/A hrs_ext_msg(this, "secondary free list MT safety protocol"));
2037N/A
2037N/A return FreeRegionList::check_mt_safety();
2037N/A}
2037N/A
2910N/A//////////////////// OldRegionSet ////////////////////
2910N/A
2910N/Aconst char* OldRegionSet::verify_region_extra(HeapRegion* hr) {
2910N/A if (hr->is_young()) {
2910N/A return "the region should not be young";
2910N/A }
2910N/A // The superclass will check that the region is not empty and not
2910N/A // humongous.
2910N/A return HeapRegionSet::verify_region_extra(hr);
2910N/A}
2910N/A
2910N/A//////////////////// MasterOldRegionSet ////////////////////
2910N/A
2910N/Abool MasterOldRegionSet::check_mt_safety() {
2910N/A // Master Old Set MT safety protocol:
2910N/A // (a) If we're at a safepoint, operations on the master old set
2910N/A // should be invoked:
2910N/A // - by the VM thread (which will serialize them), or
2910N/A // - by the GC workers while holding the FreeList_lock, if we're
2910N/A // at a safepoint for an evacuation pause (this lock is taken
2910N/A // anyway when an GC alloc region is retired so that a new one
2910N/A // is allocated from the free list), or
2910N/A // - by the GC workers while holding the OldSets_lock, if we're at a
2910N/A // safepoint for a cleanup pause.
2910N/A // (b) If we're not at a safepoint, operations on the master old set
2910N/A // should be invoked while holding the Heap_lock.
2910N/A
2910N/A if (SafepointSynchronize::is_at_safepoint()) {
2910N/A guarantee(Thread::current()->is_VM_thread() ||
2910N/A _phase == HRSPhaseEvacuation && FreeList_lock->owned_by_self() ||
2910N/A _phase == HRSPhaseCleanup && OldSets_lock->owned_by_self(),
2910N/A hrs_ext_msg(this, "master old set MT safety protocol "
2910N/A "at a safepoint"));
2910N/A } else {
2910N/A guarantee(Heap_lock->owned_by_self(),
2910N/A hrs_ext_msg(this, "master old set MT safety protocol "
2910N/A "outside a safepoint"));
2910N/A }
2910N/A
2910N/A return OldRegionSet::check_mt_safety();
2910N/A}
2910N/A
2037N/A//////////////////// HumongousRegionSet ////////////////////
2037N/A
2037N/Aconst char* HumongousRegionSet::verify_region_extra(HeapRegion* hr) {
2037N/A if (hr->is_young()) {
2037N/A return "the region should not be young";
2037N/A }
2037N/A // The superclass will check that the region is not empty and
2037N/A // humongous.
2037N/A return HeapRegionSet::verify_region_extra(hr);
2037N/A}
2037N/A
2208N/A//////////////////// MasterHumongousRegionSet ////////////////////
2037N/A
2037N/Abool MasterHumongousRegionSet::check_mt_safety() {
2037N/A // Master Humongous Set MT safety protocol:
2037N/A // (a) If we're at a safepoint, operations on the master humongous
2037N/A // set should be invoked by either the VM thread (which will
2037N/A // serialize them) or by the GC workers while holding the
2037N/A // OldSets_lock.
2037N/A // (b) If we're not at a safepoint, operations on the master
2037N/A // humongous set should be invoked while holding the Heap_lock.
2037N/A
2910N/A if (SafepointSynchronize::is_at_safepoint()) {
2910N/A guarantee(Thread::current()->is_VM_thread() ||
2910N/A OldSets_lock->owned_by_self(),
2910N/A hrs_ext_msg(this, "master humongous set MT safety protocol "
2910N/A "at a safepoint"));
2910N/A } else {
2910N/A guarantee(Heap_lock->owned_by_self(),
2910N/A hrs_ext_msg(this, "master humongous set MT safety protocol "
2910N/A "outside a safepoint"));
2910N/A }
2910N/A
2037N/A return HumongousRegionSet::check_mt_safety();
2037N/A}