hotspot/src/share/vm/gc_implementation/g1/heapRegionSets.cpp
author tonyp
Wed, 19 Jan 2011 19:30:42 -0500
changeset 7923 fc200fcd4e05
child 8680 f1c414e16a4c
permissions -rw-r--r--
6977804: G1: remove the zero-filling thread Summary: This changeset removes the zero-filling thread from G1 and collapses the two free region lists we had before (the "free" and "unclean" lists) into one. The new free list uses the new heap region sets / lists abstractions that we'll ultimately use it to keep track of all regions in the heap. A heap region set was also introduced for the humongous regions. Finally, this change increases the concurrency between the thread that completes freeing regions (after a cleanup pause) and the rest of the system (before we'd have to wait for said thread to complete before allocating a new region). The changest also includes a lot of refactoring and code simplification. Reviewed-by: jcoomes, johnc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
     1
/*
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
     2
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
     4
 *
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
     7
 * published by the Free Software Foundation.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
     8
 *
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    13
 * accompanied this code).
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    14
 *
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    18
 *
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    21
 * questions.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    22
 *
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    23
 */
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    24
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    25
#include "precompiled.hpp"
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    26
#include "gc_implementation/g1/heapRegionSets.hpp"
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    27
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    28
//////////////////// FreeRegionList ////////////////////
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    29
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    30
const char* FreeRegionList::verify_region_extra(HeapRegion* hr) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    31
  if (hr->is_young()) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    32
    return "the region should not be young";
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    33
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    34
  // The superclass will check that the region is empty and
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    35
  // not-humongous.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    36
  return HeapRegionLinkedList::verify_region_extra(hr);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    37
}
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    38
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    39
//////////////////// MasterFreeRegionList ////////////////////
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    40
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    41
bool MasterFreeRegionList::check_mt_safety() {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    42
  // Master Free List MT safety protocol:
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    43
  // (a) If we're at a safepoint, operations on the master free list
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    44
  // should be invoked by either the VM thread (which will serialize
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    45
  // them) or by the GC workers while holding the
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    46
  // FreeList_lock.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    47
  // (b) If we're not at a safepoint, operations on the master free
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    48
  // list should be invoked while holding the Heap_lock.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    49
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    50
  guarantee((SafepointSynchronize::is_at_safepoint() &&
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    51
               (Thread::current()->is_VM_thread() ||
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    52
                                            FreeList_lock->owned_by_self())) ||
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    53
            (!SafepointSynchronize::is_at_safepoint() &&
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    54
                                                Heap_lock->owned_by_self()),
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    55
            hrl_ext_msg(this, "master free list MT safety protocol"));
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    56
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    57
  return FreeRegionList::check_mt_safety();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    58
}
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    59
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    60
//////////////////// SecondaryFreeRegionList ////////////////////
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    61
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    62
bool SecondaryFreeRegionList::check_mt_safety() {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    63
  // Secondary Free List MT safety protocol:
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    64
  // Operations on the secondary free list should always be invoked
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    65
  // while holding the SecondaryFreeList_lock.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    66
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    67
  guarantee(SecondaryFreeList_lock->owned_by_self(),
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    68
            hrl_ext_msg(this, "secondary free list MT safety protocol"));
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    69
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    70
  return FreeRegionList::check_mt_safety();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    71
}
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    72
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    73
//////////////////// HumongousRegionSet ////////////////////
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    74
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    75
const char* HumongousRegionSet::verify_region_extra(HeapRegion* hr) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    76
  if (hr->is_young()) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    77
    return "the region should not be young";
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    78
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    79
  // The superclass will check that the region is not empty and
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    80
  // humongous.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    81
  return HeapRegionSet::verify_region_extra(hr);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    82
}
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    83
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    84
//////////////////// HumongousRegionSet ////////////////////
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    85
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    86
bool MasterHumongousRegionSet::check_mt_safety() {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    87
  // Master Humongous Set MT safety protocol:
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    88
  // (a) If we're at a safepoint, operations on the master humongous
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    89
  // set should be invoked by either the VM thread (which will
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    90
  // serialize them) or by the GC workers while holding the
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    91
  // OldSets_lock.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    92
  // (b) If we're not at a safepoint, operations on the master
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    93
  // humongous set should be invoked while holding the Heap_lock.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    94
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    95
  guarantee((SafepointSynchronize::is_at_safepoint() &&
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    96
               (Thread::current()->is_VM_thread() ||
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    97
                                             OldSets_lock->owned_by_self())) ||
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    98
            (!SafepointSynchronize::is_at_safepoint() &&
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    99
                                                 Heap_lock->owned_by_self()),
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   100
            hrl_ext_msg(this, "master humongous set MT safety protocol"));
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   101
  return HumongousRegionSet::check_mt_safety();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   102
}