1 #ifdef USE_PRAGMA_IDENT_HDR 2 #pragma ident "@(#)psYoungGen.hpp 1.48 07/05/05 17:05:31 JVM" 3 #endif 4 /* 5 * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved. 6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7 * 8 * This code is free software; you can redistribute it and/or modify it 9 * under the terms of the GNU General Public License version 2 only, as 10 * published by the Free Software Foundation. 11 * 12 * This code is distributed in the hope that it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * version 2 for more details (a copy is included in the LICENSE file that 16 * accompanied this code). 17 * 18 * You should have received a copy of the GNU General Public License version 19 * 2 along with this work; if not, write to the Free Software Foundation, 20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21 * 22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 23 * CA 95054 USA or visit www.sun.com if you need additional information or 24 * have any questions. 25 * 26 */ 27 28 class PSMarkSweepDecorator; 29 30 class PSYoungGen : public CHeapObj { 31 friend class VMStructs; 32 friend class ParallelScavengeHeap; 33 friend class AdjoiningGenerations; 34 35 protected: 36 MemRegion _reserved; 37 PSVirtualSpace* _virtual_space; 38 39 // Spaces 40 MutableSpace* _eden_space; 41 MutableSpace* _from_space; 42 MutableSpace* _to_space; 43 44 45 // MarkSweep Decorators 46 PSMarkSweepDecorator* _eden_mark_sweep; 47 PSMarkSweepDecorator* _from_mark_sweep; 48 PSMarkSweepDecorator* _to_mark_sweep; 49 50 // Sizing information, in bytes, set in constructor 51 const size_t _init_gen_size; 52 const size_t _min_gen_size; 53 const size_t _max_gen_size; 54 55 // Performance counters 56 PSGenerationCounters* _gen_counters; 57 SpaceCounters* _eden_counters; 58 SpaceCounters* _from_counters; 59 SpaceCounters* _to_counters; 60 61 // Initialize the space boundaries 62 void compute_initial_space_boundaries(); 63 64 // Space boundary helper 65 void set_space_boundaries(size_t eden_size, size_t survivor_size); 66 67 virtual bool resize_generation(size_t eden_size, size_t survivor_size); 68 virtual void resize_spaces(size_t eden_size, size_t survivor_size); 69 70 // Adjust the spaces to be consistent with the virtual space. 71 void post_resize(); 72 73 // Return number of bytes that the generation can change. 74 // These should not be used by PSYoungGen 75 virtual size_t available_for_expansion(); 76 virtual size_t available_for_contraction(); 77 78 // Given a desired shrinkage in the size of the young generation, 79 // return the actual size available for shrinkage. 80 virtual size_t limit_gen_shrink(size_t desired_change); 81 // returns the number of bytes available from the current size 82 // down to the minimum generation size. 83 size_t available_to_min_gen(); 84 // Return the number of bytes available for shrinkage considering 85 // the location the live data in the generation. 86 virtual size_t available_to_live(); 87 88 public: 89 // Initialize the generation. 90 PSYoungGen(size_t initial_byte_size, 91 size_t minimum_byte_size, 92 size_t maximum_byte_size); 93 void initialize_work(); 94 virtual void initialize(ReservedSpace rs, size_t alignment); 95 virtual void initialize_virtual_space(ReservedSpace rs, size_t alignment); 96 97 MemRegion reserved() const { return _reserved; } 98 99 bool is_in(const void* p) const { 100 return _virtual_space->contains((void *)p); 101 } 102 103 bool is_in_reserved(const void* p) const { 104 return reserved().contains((void *)p); 105 } 106 107 MutableSpace* eden_space() const { return _eden_space; } 108 MutableSpace* from_space() const { return _from_space; } 109 MutableSpace* to_space() const { return _to_space; } 110 PSVirtualSpace* virtual_space() const { return _virtual_space; } 111 112 // For Adaptive size policy 113 size_t min_gen_size() { return _min_gen_size; } 114 115 // MarkSweep support 116 PSMarkSweepDecorator* eden_mark_sweep() const { return _eden_mark_sweep; } 117 PSMarkSweepDecorator* from_mark_sweep() const { return _from_mark_sweep; } 118 PSMarkSweepDecorator* to_mark_sweep() const { return _to_mark_sweep; } 119 120 void precompact(); 121 void adjust_pointers(); 122 void compact(); 123 124 // Parallel Old 125 void move_and_update(ParCompactionManager* cm); 126 127 // Called during/after gc 128 void swap_spaces(); 129 130 // Resize generation using suggested free space size and survivor size 131 // NOTE: "eden_size" and "survivor_size" are suggestions only. Current 132 // heap layout (particularly, live objects in from space) might 133 // not allow us to use these values. 134 void resize(size_t eden_size, size_t survivor_size); 135 136 // Size info 137 size_t capacity_in_bytes() const; 138 size_t used_in_bytes() const; 139 size_t free_in_bytes() const; 140 141 size_t capacity_in_words() const; 142 size_t used_in_words() const; 143 size_t free_in_words() const; 144 145 // The max this generation can grow to 146 size_t max_size() const { return _reserved.byte_size(); } 147 148 // The max this generation can grow to if the boundary between 149 // the generations are allowed to move. 150 size_t gen_size_limit() const { return _max_gen_size; } 151 152 bool is_maximal_no_gc() const { 153 return true; // never expands except at a GC 154 } 155 156 // Allocation 157 HeapWord* allocate(size_t word_size, bool is_tlab) { 158 HeapWord* result = eden_space()->cas_allocate(word_size); 159 return result; 160 } 161 162 HeapWord** top_addr() const { return eden_space()->top_addr(); } 163 HeapWord** end_addr() const { return eden_space()->end_addr(); } 164 165 // Iteration. 166 void oop_iterate(OopClosure* cl); 167 void object_iterate(ObjectClosure* cl); 168 169 virtual void reset_after_change(); 170 virtual void reset_survivors_after_shrink(); 171 172 // Performance Counter support 173 void update_counters(); 174 175 // Debugging - do not use for time critical operations 176 void print() const; 177 void print_on(outputStream* st) const; 178 void print_used_change(size_t prev_used) const; 179 virtual const char* name() const { return "PSYoungGen"; } 180 181 void verify(bool allow_dirty); 182 183 // Space boundary invariant checker 184 void space_invariants() PRODUCT_RETURN; 185 186 // Helper for mangling survivor spaces. 187 void mangle_survivors(MutableSpace* s1, 188 MemRegion s1MR, 189 MutableSpace* s2, 190 MemRegion s2MR) PRODUCT_RETURN; 191 192 void record_spaces_top() PRODUCT_RETURN; 193 };