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

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial