Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/parallelScavenge/adjoiningGenerations.cpp
38920 views
/*1* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "gc_implementation/parallelScavenge/adjoiningGenerations.hpp"26#include "gc_implementation/parallelScavenge/adjoiningVirtualSpaces.hpp"27#include "gc_implementation/parallelScavenge/generationSizer.hpp"28#include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"2930// If boundary moving is being used, create the young gen and old31// gen with ASPSYoungGen and ASPSOldGen, respectively. Revert to32// the old behavior otherwise (with PSYoungGen and PSOldGen).3334AdjoiningGenerations::AdjoiningGenerations(ReservedSpace old_young_rs,35GenerationSizer* policy,36size_t alignment) :37_virtual_spaces(old_young_rs, policy->min_gen1_size(),38policy->min_gen0_size(), alignment) {39size_t init_low_byte_size = policy->initial_gen1_size();40size_t min_low_byte_size = policy->min_gen1_size();41size_t max_low_byte_size = policy->max_gen1_size();42size_t init_high_byte_size = policy->initial_gen0_size();43size_t min_high_byte_size = policy->min_gen0_size();44size_t max_high_byte_size = policy->max_gen0_size();4546assert(min_low_byte_size <= init_low_byte_size &&47init_low_byte_size <= max_low_byte_size, "Parameter check");48assert(min_high_byte_size <= init_high_byte_size &&49init_high_byte_size <= max_high_byte_size, "Parameter check");50// Create the generations differently based on the option to51// move the boundary.52if (UseAdaptiveGCBoundary) {53// Initialize the adjoining virtual spaces. Then pass the54// a virtual to each generation for initialization of the55// generation.5657// Does the actual creation of the virtual spaces58_virtual_spaces.initialize(max_low_byte_size,59init_low_byte_size,60init_high_byte_size);6162// Place the young gen at the high end. Passes in the virtual space.63_young_gen = new ASPSYoungGen(_virtual_spaces.high(),64_virtual_spaces.high()->committed_size(),65min_high_byte_size,66_virtual_spaces.high_byte_size_limit());6768// Place the old gen at the low end. Passes in the virtual space.69_old_gen = new ASPSOldGen(_virtual_spaces.low(),70_virtual_spaces.low()->committed_size(),71min_low_byte_size,72_virtual_spaces.low_byte_size_limit(),73"old", 1);7475young_gen()->initialize_work();76assert(young_gen()->reserved().byte_size() <= young_gen()->gen_size_limit(),77"Consistency check");78assert(old_young_rs.size() >= young_gen()->gen_size_limit(),79"Consistency check");8081old_gen()->initialize_work("old", 1);82assert(old_gen()->reserved().byte_size() <= old_gen()->gen_size_limit(),83"Consistency check");84assert(old_young_rs.size() >= old_gen()->gen_size_limit(),85"Consistency check");86} else {8788// Layout the reserved space for the generations.89ReservedSpace old_rs =90virtual_spaces()->reserved_space().first_part(max_low_byte_size);91ReservedSpace heap_rs =92virtual_spaces()->reserved_space().last_part(max_low_byte_size);93ReservedSpace young_rs = heap_rs.first_part(max_high_byte_size);94assert(young_rs.size() == heap_rs.size(), "Didn't reserve all of the heap");9596// Create the generations. Virtual spaces are not passed in.97_young_gen = new PSYoungGen(init_high_byte_size,98min_high_byte_size,99max_high_byte_size);100_old_gen = new PSOldGen(init_low_byte_size,101min_low_byte_size,102max_low_byte_size,103"old", 1);104105// The virtual spaces are created by the initialization of the gens.106_young_gen->initialize(young_rs, alignment);107assert(young_gen()->gen_size_limit() == young_rs.size(),108"Consistency check");109_old_gen->initialize(old_rs, alignment, "old", 1);110assert(old_gen()->gen_size_limit() == old_rs.size(), "Consistency check");111}112}113114size_t AdjoiningGenerations::reserved_byte_size() {115return virtual_spaces()->reserved_space().size();116}117118119// Make checks on the current sizes of the generations and120// the contraints on the sizes of the generations. Push121// up the boundary within the contraints. A partial122// push can occur.123void AdjoiningGenerations::request_old_gen_expansion(size_t expand_in_bytes) {124assert(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary, "runtime check");125126assert_lock_strong(ExpandHeap_lock);127assert_locked_or_safepoint(Heap_lock);128129// These sizes limit the amount the boundaries can move. Effectively,130// the generation says how much it is willing to yield to the other131// generation.132const size_t young_gen_available = young_gen()->available_for_contraction();133const size_t old_gen_available = old_gen()->available_for_expansion();134const size_t alignment = virtual_spaces()->alignment();135size_t change_in_bytes = MIN3(young_gen_available,136old_gen_available,137align_size_up_(expand_in_bytes, alignment));138139if (change_in_bytes == 0) {140return;141}142143if (TraceAdaptiveGCBoundary) {144gclog_or_tty->print_cr("Before expansion of old gen with boundary move");145gclog_or_tty->print_cr(" Requested change: " SIZE_FORMAT_HEX " Attempted change: " SIZE_FORMAT_HEX,146expand_in_bytes, change_in_bytes);147if (!PrintHeapAtGC) {148Universe::print_on(gclog_or_tty);149}150gclog_or_tty->print_cr(" PSOldGen max size: " SIZE_FORMAT "K",151old_gen()->max_gen_size()/K);152}153154// Move the boundary between the generations up (smaller young gen).155if (virtual_spaces()->adjust_boundary_up(change_in_bytes)) {156young_gen()->reset_after_change();157old_gen()->reset_after_change();158}159160// The total reserved for the generations should match the sum161// of the two even if the boundary is moving.162assert(reserved_byte_size() ==163old_gen()->max_gen_size() + young_gen()->max_size(),164"Space is missing");165young_gen()->space_invariants();166old_gen()->space_invariants();167168if (TraceAdaptiveGCBoundary) {169gclog_or_tty->print_cr("After expansion of old gen with boundary move");170if (!PrintHeapAtGC) {171Universe::print_on(gclog_or_tty);172}173gclog_or_tty->print_cr(" PSOldGen max size: " SIZE_FORMAT "K",174old_gen()->max_gen_size()/K);175}176}177178// See comments on request_old_gen_expansion()179bool AdjoiningGenerations::request_young_gen_expansion(size_t expand_in_bytes) {180assert(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary, "runtime check");181182// If eden is not empty, the boundary can be moved but no advantage183// can be made of the move since eden cannot be moved.184if (!young_gen()->eden_space()->is_empty()) {185return false;186}187188189bool result = false;190const size_t young_gen_available = young_gen()->available_for_expansion();191const size_t old_gen_available = old_gen()->available_for_contraction();192const size_t alignment = virtual_spaces()->alignment();193size_t change_in_bytes = MIN3(young_gen_available,194old_gen_available,195align_size_up_(expand_in_bytes, alignment));196197if (change_in_bytes == 0) {198return false;199}200201if (TraceAdaptiveGCBoundary) {202gclog_or_tty->print_cr("Before expansion of young gen with boundary move");203gclog_or_tty->print_cr(" Requested change: " SIZE_FORMAT_HEX " Attempted change: " SIZE_FORMAT_HEX,204expand_in_bytes, change_in_bytes);205if (!PrintHeapAtGC) {206Universe::print_on(gclog_or_tty);207}208gclog_or_tty->print_cr(" PSYoungGen max size: " SIZE_FORMAT "K",209young_gen()->max_size()/K);210}211212// Move the boundary between the generations down (smaller old gen).213MutexLocker x(ExpandHeap_lock);214if (virtual_spaces()->adjust_boundary_down(change_in_bytes)) {215young_gen()->reset_after_change();216old_gen()->reset_after_change();217result = true;218}219220// The total reserved for the generations should match the sum221// of the two even if the boundary is moving.222assert(reserved_byte_size() ==223old_gen()->max_gen_size() + young_gen()->max_size(),224"Space is missing");225young_gen()->space_invariants();226old_gen()->space_invariants();227228if (TraceAdaptiveGCBoundary) {229gclog_or_tty->print_cr("After expansion of young gen with boundary move");230if (!PrintHeapAtGC) {231Universe::print_on(gclog_or_tty);232}233gclog_or_tty->print_cr(" PSYoungGen max size: " SIZE_FORMAT "K",234young_gen()->max_size()/K);235}236237return result;238}239240// Additional space is needed in the old generation. Try to move the boundary241// up to meet the need. Moves boundary up only242void AdjoiningGenerations::adjust_boundary_for_old_gen_needs(243size_t desired_free_space) {244assert(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary, "runtime check");245246// Stress testing.247if (PSAdaptiveSizePolicyResizeVirtualSpaceAlot == 1) {248MutexLocker x(ExpandHeap_lock);249request_old_gen_expansion(virtual_spaces()->alignment() * 3 / 2);250}251252// Expand only if the entire generation is already committed.253if (old_gen()->virtual_space()->uncommitted_size() == 0) {254if (old_gen()->free_in_bytes() < desired_free_space) {255MutexLocker x(ExpandHeap_lock);256request_old_gen_expansion(desired_free_space);257}258}259}260261// See comment on adjust_boundary_for_old_gen_needss().262// Adjust boundary down only.263void AdjoiningGenerations::adjust_boundary_for_young_gen_needs(size_t eden_size,264size_t survivor_size) {265266assert(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary, "runtime check");267268// Stress testing.269if (PSAdaptiveSizePolicyResizeVirtualSpaceAlot == 0) {270request_young_gen_expansion(virtual_spaces()->alignment() * 3 / 2);271eden_size = young_gen()->eden_space()->capacity_in_bytes();272}273274// Expand only if the entire generation is already committed.275if (young_gen()->virtual_space()->uncommitted_size() == 0) {276size_t desired_size = eden_size + 2 * survivor_size;277const size_t committed = young_gen()->virtual_space()->committed_size();278if (desired_size > committed) {279request_young_gen_expansion(desired_size - committed);280}281}282}283284285