duke@435: /* trims@1907: * Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: duke@435: class PSMarkSweepDecorator; duke@435: duke@435: class PSYoungGen : public CHeapObj { duke@435: friend class VMStructs; duke@435: friend class ParallelScavengeHeap; duke@435: friend class AdjoiningGenerations; duke@435: duke@435: protected: duke@435: MemRegion _reserved; duke@435: PSVirtualSpace* _virtual_space; duke@435: duke@435: // Spaces duke@435: MutableSpace* _eden_space; duke@435: MutableSpace* _from_space; duke@435: MutableSpace* _to_space; duke@435: duke@435: duke@435: // MarkSweep Decorators duke@435: PSMarkSweepDecorator* _eden_mark_sweep; duke@435: PSMarkSweepDecorator* _from_mark_sweep; duke@435: PSMarkSweepDecorator* _to_mark_sweep; duke@435: duke@435: // Sizing information, in bytes, set in constructor duke@435: const size_t _init_gen_size; duke@435: const size_t _min_gen_size; duke@435: const size_t _max_gen_size; duke@435: duke@435: // Performance counters duke@435: PSGenerationCounters* _gen_counters; duke@435: SpaceCounters* _eden_counters; duke@435: SpaceCounters* _from_counters; duke@435: SpaceCounters* _to_counters; duke@435: duke@435: // Initialize the space boundaries duke@435: void compute_initial_space_boundaries(); duke@435: duke@435: // Space boundary helper duke@435: void set_space_boundaries(size_t eden_size, size_t survivor_size); duke@435: duke@435: virtual bool resize_generation(size_t eden_size, size_t survivor_size); duke@435: virtual void resize_spaces(size_t eden_size, size_t survivor_size); duke@435: duke@435: // Adjust the spaces to be consistent with the virtual space. duke@435: void post_resize(); duke@435: duke@435: // Return number of bytes that the generation can change. duke@435: // These should not be used by PSYoungGen duke@435: virtual size_t available_for_expansion(); duke@435: virtual size_t available_for_contraction(); duke@435: duke@435: // Given a desired shrinkage in the size of the young generation, duke@435: // return the actual size available for shrinkage. duke@435: virtual size_t limit_gen_shrink(size_t desired_change); duke@435: // returns the number of bytes available from the current size duke@435: // down to the minimum generation size. duke@435: size_t available_to_min_gen(); duke@435: // Return the number of bytes available for shrinkage considering duke@435: // the location the live data in the generation. duke@435: virtual size_t available_to_live(); duke@435: duke@435: public: duke@435: // Initialize the generation. duke@435: PSYoungGen(size_t initial_byte_size, duke@435: size_t minimum_byte_size, duke@435: size_t maximum_byte_size); duke@435: void initialize_work(); duke@435: virtual void initialize(ReservedSpace rs, size_t alignment); duke@435: virtual void initialize_virtual_space(ReservedSpace rs, size_t alignment); duke@435: duke@435: MemRegion reserved() const { return _reserved; } duke@435: duke@435: bool is_in(const void* p) const { duke@435: return _virtual_space->contains((void *)p); duke@435: } duke@435: duke@435: bool is_in_reserved(const void* p) const { duke@435: return reserved().contains((void *)p); duke@435: } duke@435: duke@435: MutableSpace* eden_space() const { return _eden_space; } duke@435: MutableSpace* from_space() const { return _from_space; } duke@435: MutableSpace* to_space() const { return _to_space; } duke@435: PSVirtualSpace* virtual_space() const { return _virtual_space; } duke@435: duke@435: // For Adaptive size policy duke@435: size_t min_gen_size() { return _min_gen_size; } duke@435: duke@435: // MarkSweep support duke@435: PSMarkSweepDecorator* eden_mark_sweep() const { return _eden_mark_sweep; } duke@435: PSMarkSweepDecorator* from_mark_sweep() const { return _from_mark_sweep; } duke@435: PSMarkSweepDecorator* to_mark_sweep() const { return _to_mark_sweep; } duke@435: duke@435: void precompact(); duke@435: void adjust_pointers(); duke@435: void compact(); duke@435: duke@435: // Parallel Old duke@435: void move_and_update(ParCompactionManager* cm); duke@435: duke@435: // Called during/after gc duke@435: void swap_spaces(); duke@435: duke@435: // Resize generation using suggested free space size and survivor size duke@435: // NOTE: "eden_size" and "survivor_size" are suggestions only. Current duke@435: // heap layout (particularly, live objects in from space) might duke@435: // not allow us to use these values. duke@435: void resize(size_t eden_size, size_t survivor_size); duke@435: duke@435: // Size info duke@435: size_t capacity_in_bytes() const; duke@435: size_t used_in_bytes() const; duke@435: size_t free_in_bytes() const; duke@435: duke@435: size_t capacity_in_words() const; duke@435: size_t used_in_words() const; duke@435: size_t free_in_words() const; duke@435: duke@435: // The max this generation can grow to duke@435: size_t max_size() const { return _reserved.byte_size(); } duke@435: duke@435: // The max this generation can grow to if the boundary between duke@435: // the generations are allowed to move. duke@435: size_t gen_size_limit() const { return _max_gen_size; } duke@435: duke@435: bool is_maximal_no_gc() const { duke@435: return true; // never expands except at a GC duke@435: } duke@435: duke@435: // Allocation duke@435: HeapWord* allocate(size_t word_size, bool is_tlab) { duke@435: HeapWord* result = eden_space()->cas_allocate(word_size); duke@435: return result; duke@435: } duke@435: duke@435: HeapWord** top_addr() const { return eden_space()->top_addr(); } duke@435: HeapWord** end_addr() const { return eden_space()->end_addr(); } duke@435: duke@435: // Iteration. duke@435: void oop_iterate(OopClosure* cl); duke@435: void object_iterate(ObjectClosure* cl); duke@435: duke@435: virtual void reset_after_change(); duke@435: virtual void reset_survivors_after_shrink(); duke@435: duke@435: // Performance Counter support duke@435: void update_counters(); duke@435: duke@435: // Debugging - do not use for time critical operations duke@435: void print() const; duke@435: void print_on(outputStream* st) const; duke@435: void print_used_change(size_t prev_used) const; duke@435: virtual const char* name() const { return "PSYoungGen"; } duke@435: duke@435: void verify(bool allow_dirty); duke@435: duke@435: // Space boundary invariant checker duke@435: void space_invariants() PRODUCT_RETURN; jmasa@698: jmasa@698: // Helper for mangling survivor spaces. jmasa@698: void mangle_survivors(MutableSpace* s1, jmasa@698: MemRegion s1MR, jmasa@698: MutableSpace* s2, jmasa@698: MemRegion s2MR) PRODUCT_RETURN; jmasa@698: jmasa@698: void record_spaces_top() PRODUCT_RETURN; duke@435: };