heapRegionSets.cpp 4.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 *
 */

#include "precompiled.hpp"
26
#include "gc_implementation/g1/heapRegionRemSet.hpp"
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
#include "gc_implementation/g1/heapRegionSets.hpp"

//////////////////// FreeRegionList ////////////////////

const char* FreeRegionList::verify_region_extra(HeapRegion* hr) {
  if (hr->is_young()) {
    return "the region should not be young";
  }
  // The superclass will check that the region is empty and
  // not-humongous.
  return HeapRegionLinkedList::verify_region_extra(hr);
}

//////////////////// MasterFreeRegionList ////////////////////

42 43 44 45 46 47 48 49 50 51
const char* MasterFreeRegionList::verify_region_extra(HeapRegion* hr) {
  // We should reset the RSet for parallel iteration before we add it
  // to the master free list so that it is ready when the region is
  // re-allocated.
  if (!hr->rem_set()->verify_ready_for_par_iteration()) {
    return "the region's RSet should be ready for parallel iteration";
  }
  return FreeRegionList::verify_region_extra(hr);
}

52 53 54 55 56 57 58 59 60 61 62 63 64 65
bool MasterFreeRegionList::check_mt_safety() {
  // Master Free List MT safety protocol:
  // (a) If we're at a safepoint, operations on the master free list
  // should be invoked by either the VM thread (which will serialize
  // them) or by the GC workers while holding the
  // FreeList_lock.
  // (b) If we're not at a safepoint, operations on the master free
  // list should be invoked while holding the Heap_lock.

  guarantee((SafepointSynchronize::is_at_safepoint() &&
               (Thread::current()->is_VM_thread() ||
                                            FreeList_lock->owned_by_self())) ||
            (!SafepointSynchronize::is_at_safepoint() &&
                                                Heap_lock->owned_by_self()),
T
tonyp 已提交
66
            hrs_ext_msg(this, "master free list MT safety protocol"));
67 68 69 70 71 72 73 74 75 76 77 78

  return FreeRegionList::check_mt_safety();
}

//////////////////// SecondaryFreeRegionList ////////////////////

bool SecondaryFreeRegionList::check_mt_safety() {
  // Secondary Free List MT safety protocol:
  // Operations on the secondary free list should always be invoked
  // while holding the SecondaryFreeList_lock.

  guarantee(SecondaryFreeList_lock->owned_by_self(),
T
tonyp 已提交
79
            hrs_ext_msg(this, "secondary free list MT safety protocol"));
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94

  return FreeRegionList::check_mt_safety();
}

//////////////////// HumongousRegionSet ////////////////////

const char* HumongousRegionSet::verify_region_extra(HeapRegion* hr) {
  if (hr->is_young()) {
    return "the region should not be young";
  }
  // The superclass will check that the region is not empty and
  // humongous.
  return HeapRegionSet::verify_region_extra(hr);
}

T
tonyp 已提交
95
//////////////////// MasterHumongousRegionSet ////////////////////
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110

bool MasterHumongousRegionSet::check_mt_safety() {
  // Master Humongous Set MT safety protocol:
  // (a) If we're at a safepoint, operations on the master humongous
  // set should be invoked by either the VM thread (which will
  // serialize them) or by the GC workers while holding the
  // OldSets_lock.
  // (b) If we're not at a safepoint, operations on the master
  // humongous set should be invoked while holding the Heap_lock.

  guarantee((SafepointSynchronize::is_at_safepoint() &&
               (Thread::current()->is_VM_thread() ||
                                             OldSets_lock->owned_by_self())) ||
            (!SafepointSynchronize::is_at_safepoint() &&
                                                 Heap_lock->owned_by_self()),
T
tonyp 已提交
111
            hrs_ext_msg(this, "master humongous set MT safety protocol"));
112 113
  return HumongousRegionSet::check_mt_safety();
}