src/share/vm/gc_implementation/parallelScavenge/asPSOldGen.cpp

Thu, 22 Sep 2011 10:57:37 -0700

author
johnc
date
Thu, 22 Sep 2011 10:57:37 -0700
changeset 3175
4dfb2df418f2
parent 2314
f95d63e2154a
child 5311
f99cd6e20ab1
permissions
-rw-r--r--

6484982: G1: process references during evacuation pauses
Summary: G1 now uses two reference processors - one is used by concurrent marking and the other is used by STW GCs (both full and incremental evacuation pauses). In an evacuation pause, the reference processor is embedded into the closures used to scan objects. Doing so causes causes reference objects to be 'discovered' by the reference processor. At the end of the evacuation pause, these discovered reference objects are processed - preserving (and copying) referent objects (and their reachable graphs) as appropriate.
Reviewed-by: ysr, jwilhelm, brutisso, stefank, tonyp

duke@435 1 /*
stefank@2314 2 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "gc_implementation/parallelScavenge/asPSOldGen.hpp"
stefank@2314 27 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
stefank@2314 28 #include "gc_implementation/parallelScavenge/psAdaptiveSizePolicy.hpp"
stefank@2314 29 #include "gc_implementation/parallelScavenge/psMarkSweepDecorator.hpp"
stefank@2314 30 #include "memory/cardTableModRefBS.hpp"
stefank@2314 31 #include "oops/oop.inline.hpp"
stefank@2314 32 #include "runtime/java.hpp"
duke@435 33
duke@435 34 // Whereas PSOldGen takes the maximum size of the generation
duke@435 35 // (which doesn't change in the case of PSOldGen) as a parameter,
duke@435 36 // ASPSOldGen takes the upper limit on the size of
duke@435 37 // the generation as a parameter. In ASPSOldGen the
duke@435 38 // maximum size of the generation can change as the boundary
duke@435 39 // moves. The "maximum size of the generation" is still a valid
duke@435 40 // concept since the generation can grow and shrink within that
duke@435 41 // maximum. There are lots of useful checks that use that
duke@435 42 // maximum. In PSOldGen the method max_gen_size() returns
duke@435 43 // _max_gen_size (as set by the PSOldGen constructor). This
duke@435 44 // is how it always worked. In ASPSOldGen max_gen_size()
duke@435 45 // returned the size of the reserved space for the generation.
duke@435 46 // That can change as the boundary moves. Below the limit of
duke@435 47 // the size of the generation is passed to the PSOldGen constructor
duke@435 48 // for "_max_gen_size" (have to pass something) but it is not used later.
duke@435 49 //
duke@435 50 ASPSOldGen::ASPSOldGen(size_t initial_size,
duke@435 51 size_t min_size,
duke@435 52 size_t size_limit,
duke@435 53 const char* gen_name,
duke@435 54 int level) :
duke@435 55 PSOldGen(initial_size, min_size, size_limit, gen_name, level),
duke@435 56 _gen_size_limit(size_limit)
duke@435 57
duke@435 58 {}
duke@435 59
duke@435 60 ASPSOldGen::ASPSOldGen(PSVirtualSpace* vs,
duke@435 61 size_t initial_size,
duke@435 62 size_t min_size,
duke@435 63 size_t size_limit,
duke@435 64 const char* gen_name,
duke@435 65 int level) :
duke@435 66 PSOldGen(initial_size, min_size, size_limit, gen_name, level),
duke@435 67 _gen_size_limit(size_limit)
duke@435 68
duke@435 69 {
duke@435 70 _virtual_space = vs;
duke@435 71 }
duke@435 72
duke@435 73 void ASPSOldGen::reset_after_change() {
duke@435 74 _reserved = MemRegion((HeapWord*)virtual_space()->low_boundary(),
duke@435 75 (HeapWord*)virtual_space()->high_boundary());
duke@435 76 post_resize();
duke@435 77 }
duke@435 78
duke@435 79
duke@435 80 size_t ASPSOldGen::available_for_expansion() {
duke@435 81 assert(virtual_space()->is_aligned(gen_size_limit()), "not aligned");
duke@435 82 assert(gen_size_limit() >= virtual_space()->committed_size(), "bad gen size");
duke@435 83
duke@435 84 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
duke@435 85 size_t result = gen_size_limit() - virtual_space()->committed_size();
duke@435 86 size_t result_aligned = align_size_down(result, heap->old_gen_alignment());
duke@435 87 return result_aligned;
duke@435 88 }
duke@435 89
duke@435 90 size_t ASPSOldGen::available_for_contraction() {
duke@435 91 size_t uncommitted_bytes = virtual_space()->uncommitted_size();
duke@435 92 if (uncommitted_bytes != 0) {
duke@435 93 return uncommitted_bytes;
duke@435 94 }
duke@435 95
duke@435 96 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
duke@435 97 const size_t gen_alignment = heap->old_gen_alignment();
duke@435 98 PSAdaptiveSizePolicy* policy = heap->size_policy();
duke@435 99 const size_t working_size =
duke@435 100 used_in_bytes() + (size_t) policy->avg_promoted()->padded_average();
duke@435 101 const size_t working_aligned = align_size_up(working_size, gen_alignment);
duke@435 102 const size_t working_or_min = MAX2(working_aligned, min_gen_size());
duke@435 103 if (working_or_min > reserved().byte_size()) {
duke@435 104 // If the used or minimum gen size (aligned up) is greater
duke@435 105 // than the total reserved size, then the space available
duke@435 106 // for contraction should (after proper alignment) be 0
duke@435 107 return 0;
duke@435 108 }
duke@435 109 const size_t max_contraction =
duke@435 110 reserved().byte_size() - working_or_min;
duke@435 111
duke@435 112 // Use the "increment" fraction instead of the "decrement" fraction
duke@435 113 // to allow the other gen to expand more aggressively. The
duke@435 114 // "decrement" fraction is conservative because its intent is to
duke@435 115 // only reduce the footprint.
duke@435 116
duke@435 117 size_t result = policy->promo_increment_aligned_down(max_contraction);
duke@435 118 // Also adjust for inter-generational alignment
duke@435 119 size_t result_aligned = align_size_down(result, gen_alignment);
duke@435 120 if (PrintAdaptiveSizePolicy && Verbose) {
duke@435 121 gclog_or_tty->print_cr("\nASPSOldGen::available_for_contraction:"
duke@435 122 " %d K / 0x%x", result_aligned/K, result_aligned);
duke@435 123 gclog_or_tty->print_cr(" reserved().byte_size() %d K / 0x%x ",
duke@435 124 reserved().byte_size()/K, reserved().byte_size());
duke@435 125 size_t working_promoted = (size_t) policy->avg_promoted()->padded_average();
duke@435 126 gclog_or_tty->print_cr(" padded promoted %d K / 0x%x",
duke@435 127 working_promoted/K, working_promoted);
duke@435 128 gclog_or_tty->print_cr(" used %d K / 0x%x",
duke@435 129 used_in_bytes()/K, used_in_bytes());
duke@435 130 gclog_or_tty->print_cr(" min_gen_size() %d K / 0x%x",
duke@435 131 min_gen_size()/K, min_gen_size());
duke@435 132 gclog_or_tty->print_cr(" max_contraction %d K / 0x%x",
duke@435 133 max_contraction/K, max_contraction);
duke@435 134 gclog_or_tty->print_cr(" without alignment %d K / 0x%x",
duke@435 135 policy->promo_increment(max_contraction)/K,
duke@435 136 policy->promo_increment(max_contraction));
duke@435 137 gclog_or_tty->print_cr(" alignment 0x%x", gen_alignment);
duke@435 138 }
duke@435 139 assert(result_aligned <= max_contraction, "arithmetic is wrong");
duke@435 140 return result_aligned;
duke@435 141 }

mercurial