Path: blob/master/src/hotspot/share/gc/parallel/psOldGen.hpp
41149 views
/*1* Copyright (c) 2001, 2021, 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#ifndef SHARE_GC_PARALLEL_PSOLDGEN_HPP25#define SHARE_GC_PARALLEL_PSOLDGEN_HPP2627#include "gc/parallel/mutableSpace.hpp"28#include "gc/parallel/objectStartArray.hpp"29#include "gc/parallel/psGenerationCounters.hpp"30#include "gc/parallel/psVirtualspace.hpp"31#include "gc/parallel/spaceCounters.hpp"32#include "runtime/safepoint.hpp"3334class PSOldGen : public CHeapObj<mtGC> {35friend class VMStructs;3637private:38MemRegion _reserved; // Used for simple containment tests39PSVirtualSpace* _virtual_space; // Controls mapping and unmapping of virtual mem40ObjectStartArray _start_array; // Keeps track of where objects start in a 512b block41MutableSpace* _object_space; // Where all the objects live4243// Performance Counters44PSGenerationCounters* _gen_counters;45SpaceCounters* _space_counters;4647// Sizing information, in bytes, set in constructor48const size_t _min_gen_size;49const size_t _max_gen_size;5051// Block size for parallel iteration52static const size_t IterateBlockSize = 1024 * 1024;5354#ifdef ASSERT55void assert_block_in_covered_region(MemRegion new_memregion) {56// Explictly capture current covered_region in a local57MemRegion covered_region = this->start_array()->covered_region();58assert(covered_region.contains(new_memregion),59"new region is not in covered_region [ " PTR_FORMAT ", " PTR_FORMAT " ], "60"new region [ " PTR_FORMAT ", " PTR_FORMAT " ], "61"object space [ " PTR_FORMAT ", " PTR_FORMAT " ]",62p2i(covered_region.start()),63p2i(covered_region.end()),64p2i(new_memregion.start()),65p2i(new_memregion.end()),66p2i(this->object_space()->used_region().start()),67p2i(this->object_space()->used_region().end()));68}69#endif7071HeapWord* cas_allocate_noexpand(size_t word_size) {72assert_locked_or_safepoint(Heap_lock);73HeapWord* res = object_space()->cas_allocate(word_size);74if (res != NULL) {75DEBUG_ONLY(assert_block_in_covered_region(MemRegion(res, word_size)));76_start_array.allocate_block(res);77}78return res;79}8081bool expand_for_allocate(size_t word_size);82bool expand(size_t bytes);83bool expand_by(size_t bytes);84bool expand_to_reserved();8586void shrink(size_t bytes);8788void post_resize();8990void initialize(ReservedSpace rs, size_t initial_size, size_t alignment,91const char* perf_data_name, int level);92void initialize_virtual_space(ReservedSpace rs, size_t initial_size, size_t alignment);93void initialize_work(const char* perf_data_name, int level);94void initialize_performance_counters(const char* perf_data_name, int level);9596public:97// Initialize the generation.98PSOldGen(ReservedSpace rs, size_t initial_size, size_t min_size,99size_t max_size, const char* perf_data_name, int level);100101MemRegion reserved() const { return _reserved; }102size_t max_gen_size() const { return _max_gen_size; }103size_t min_gen_size() const { return _min_gen_size; }104105bool is_in(const void* p) const {106return _virtual_space->contains((void *)p);107}108109bool is_in_reserved(const void* p) const {110return reserved().contains(p);111}112113MutableSpace* object_space() const { return _object_space; }114ObjectStartArray* start_array() { return &_start_array; }115PSVirtualSpace* virtual_space() const { return _virtual_space;}116117// Has the generation been successfully allocated?118bool is_allocated();119120// Size info121size_t capacity_in_bytes() const { return object_space()->capacity_in_bytes(); }122size_t used_in_bytes() const { return object_space()->used_in_bytes(); }123size_t free_in_bytes() const { return object_space()->free_in_bytes(); }124125size_t capacity_in_words() const { return object_space()->capacity_in_words(); }126size_t used_in_words() const { return object_space()->used_in_words(); }127size_t free_in_words() const { return object_space()->free_in_words(); }128129bool is_maximal_no_gc() const {130return virtual_space()->uncommitted_size() == 0;131}132133// Calculating new sizes134void resize(size_t desired_free_space);135136HeapWord* allocate(size_t word_size) {137HeapWord* res;138do {139res = cas_allocate_noexpand(word_size);140// Retry failed allocation if expand succeeds.141} while ((res == nullptr) && expand_for_allocate(word_size));142return res;143}144145// Iteration.146void oop_iterate(OopIterateClosure* cl) { object_space()->oop_iterate(cl); }147void object_iterate(ObjectClosure* cl) { object_space()->object_iterate(cl); }148149// Number of blocks to be iterated over in the used part of old gen.150size_t num_iterable_blocks() const;151// Iterate the objects starting in block block_index within [bottom, top) of the152// old gen. The object just reaching into this block is not iterated over.153// A block is an evenly sized non-overlapping part of the old gen of154// IterateBlockSize bytes.155void object_iterate_block(ObjectClosure* cl, size_t block_index);156157// Debugging - do not use for time critical operations158void print() const;159virtual void print_on(outputStream* st) const;160161void verify();162void verify_object_start_array();163164// Performance Counter support165void update_counters();166167// Printing support168const char* name() const { return "ParOldGen"; }169170// Debugging support171// Save the tops of all spaces for later use during mangling.172void record_spaces_top() PRODUCT_RETURN;173};174175#endif // SHARE_GC_PARALLEL_PSOLDGEN_HPP176177178