Tue, 07 Oct 2008 11:01:35 -0700
Merge
duke@435 | 1 | /* |
xdono@772 | 2 | * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | class PSMarkSweepDecorator; |
duke@435 | 26 | |
duke@435 | 27 | class PSOldGen : public CHeapObj { |
duke@435 | 28 | friend class VMStructs; |
duke@435 | 29 | friend class PSPromotionManager; // Uses the cas_allocate methods |
duke@435 | 30 | friend class ParallelScavengeHeap; |
duke@435 | 31 | friend class AdjoiningGenerations; |
duke@435 | 32 | |
duke@435 | 33 | protected: |
duke@435 | 34 | MemRegion _reserved; // Used for simple containment tests |
duke@435 | 35 | PSVirtualSpace* _virtual_space; // Controls mapping and unmapping of virtual mem |
duke@435 | 36 | ObjectStartArray _start_array; // Keeps track of where objects start in a 512b block |
duke@435 | 37 | MutableSpace* _object_space; // Where all the objects live |
duke@435 | 38 | PSMarkSweepDecorator* _object_mark_sweep; // The mark sweep view of _object_space |
duke@435 | 39 | const char* const _name; // Name of this generation. |
duke@435 | 40 | |
duke@435 | 41 | // Performance Counters |
duke@435 | 42 | PSGenerationCounters* _gen_counters; |
duke@435 | 43 | SpaceCounters* _space_counters; |
duke@435 | 44 | |
duke@435 | 45 | // Sizing information, in bytes, set in constructor |
duke@435 | 46 | const size_t _init_gen_size; |
duke@435 | 47 | const size_t _min_gen_size; |
duke@435 | 48 | const size_t _max_gen_size; |
duke@435 | 49 | |
duke@435 | 50 | // Used when initializing the _name field. |
duke@435 | 51 | static inline const char* select_name(); |
duke@435 | 52 | |
duke@435 | 53 | HeapWord* allocate_noexpand(size_t word_size, bool is_tlab) { |
duke@435 | 54 | // We assume the heap lock is held here. |
duke@435 | 55 | assert(!is_tlab, "Does not support TLAB allocation"); |
duke@435 | 56 | assert_locked_or_safepoint(Heap_lock); |
duke@435 | 57 | HeapWord* res = object_space()->allocate(word_size); |
duke@435 | 58 | if (res != NULL) { |
duke@435 | 59 | _start_array.allocate_block(res); |
duke@435 | 60 | } |
duke@435 | 61 | return res; |
duke@435 | 62 | } |
duke@435 | 63 | |
duke@435 | 64 | // Support for MT garbage collection. CAS allocation is lower overhead than grabbing |
duke@435 | 65 | // and releasing the heap lock, which is held during gc's anyway. This method is not |
duke@435 | 66 | // safe for use at the same time as allocate_noexpand()! |
duke@435 | 67 | HeapWord* cas_allocate_noexpand(size_t word_size) { |
duke@435 | 68 | assert(SafepointSynchronize::is_at_safepoint(), "Must only be called at safepoint") |
duke@435 | 69 | HeapWord* res = object_space()->cas_allocate(word_size); |
duke@435 | 70 | if (res != NULL) { |
duke@435 | 71 | _start_array.allocate_block(res); |
duke@435 | 72 | } |
duke@435 | 73 | return res; |
duke@435 | 74 | } |
duke@435 | 75 | |
duke@435 | 76 | // Support for MT garbage collection. See above comment. |
duke@435 | 77 | HeapWord* cas_allocate(size_t word_size) { |
duke@435 | 78 | HeapWord* res = cas_allocate_noexpand(word_size); |
duke@435 | 79 | return (res == NULL) ? expand_and_cas_allocate(word_size) : res; |
duke@435 | 80 | } |
duke@435 | 81 | |
duke@435 | 82 | HeapWord* expand_and_allocate(size_t word_size, bool is_tlab); |
duke@435 | 83 | HeapWord* expand_and_cas_allocate(size_t word_size); |
duke@435 | 84 | void expand(size_t bytes); |
duke@435 | 85 | bool expand_by(size_t bytes); |
duke@435 | 86 | bool expand_to_reserved(); |
duke@435 | 87 | |
duke@435 | 88 | void shrink(size_t bytes); |
duke@435 | 89 | |
duke@435 | 90 | void post_resize(); |
duke@435 | 91 | |
duke@435 | 92 | public: |
duke@435 | 93 | // Initialize the generation. |
duke@435 | 94 | PSOldGen(ReservedSpace rs, size_t alignment, |
duke@435 | 95 | size_t initial_size, size_t min_size, size_t max_size, |
duke@435 | 96 | const char* perf_data_name, int level); |
duke@435 | 97 | |
duke@435 | 98 | PSOldGen(size_t initial_size, size_t min_size, size_t max_size, |
duke@435 | 99 | const char* perf_data_name, int level); |
duke@435 | 100 | |
duke@435 | 101 | void initialize(ReservedSpace rs, size_t alignment, |
duke@435 | 102 | const char* perf_data_name, int level); |
duke@435 | 103 | void initialize_virtual_space(ReservedSpace rs, size_t alignment); |
duke@435 | 104 | void initialize_work(const char* perf_data_name, int level); |
duke@435 | 105 | |
duke@435 | 106 | MemRegion reserved() const { return _reserved; } |
duke@435 | 107 | virtual size_t max_gen_size() { return _max_gen_size; } |
duke@435 | 108 | size_t min_gen_size() { return _min_gen_size; } |
duke@435 | 109 | |
duke@435 | 110 | // Returns limit on the maximum size of the generation. This |
duke@435 | 111 | // is the same as _max_gen_size for PSOldGen but need not be |
duke@435 | 112 | // for a derived class. |
duke@435 | 113 | virtual size_t gen_size_limit(); |
duke@435 | 114 | |
duke@435 | 115 | bool is_in(const void* p) const { |
duke@435 | 116 | return _virtual_space->contains((void *)p); |
duke@435 | 117 | } |
duke@435 | 118 | |
duke@435 | 119 | bool is_in_reserved(const void* p) const { |
duke@435 | 120 | return reserved().contains(p); |
duke@435 | 121 | } |
duke@435 | 122 | |
duke@435 | 123 | MutableSpace* object_space() const { return _object_space; } |
duke@435 | 124 | PSMarkSweepDecorator* object_mark_sweep() const { return _object_mark_sweep; } |
duke@435 | 125 | ObjectStartArray* start_array() { return &_start_array; } |
duke@435 | 126 | PSVirtualSpace* virtual_space() const { return _virtual_space;} |
duke@435 | 127 | |
duke@435 | 128 | // Has the generation been successfully allocated? |
duke@435 | 129 | bool is_allocated(); |
duke@435 | 130 | |
duke@435 | 131 | // MarkSweep methods |
duke@435 | 132 | virtual void precompact(); |
duke@435 | 133 | void adjust_pointers(); |
duke@435 | 134 | void compact(); |
duke@435 | 135 | |
duke@435 | 136 | // Parallel old |
duke@435 | 137 | virtual void move_and_update(ParCompactionManager* cm); |
duke@435 | 138 | |
duke@435 | 139 | // Size info |
duke@435 | 140 | size_t capacity_in_bytes() const { return object_space()->capacity_in_bytes(); } |
duke@435 | 141 | size_t used_in_bytes() const { return object_space()->used_in_bytes(); } |
duke@435 | 142 | size_t free_in_bytes() const { return object_space()->free_in_bytes(); } |
duke@435 | 143 | |
duke@435 | 144 | size_t capacity_in_words() const { return object_space()->capacity_in_words(); } |
duke@435 | 145 | size_t used_in_words() const { return object_space()->used_in_words(); } |
duke@435 | 146 | size_t free_in_words() const { return object_space()->free_in_words(); } |
duke@435 | 147 | |
duke@435 | 148 | // Includes uncommitted memory |
duke@435 | 149 | size_t contiguous_available() const; |
duke@435 | 150 | |
duke@435 | 151 | bool is_maximal_no_gc() const { |
duke@435 | 152 | return virtual_space()->uncommitted_size() == 0; |
duke@435 | 153 | } |
duke@435 | 154 | |
duke@435 | 155 | // Calculating new sizes |
duke@435 | 156 | void resize(size_t desired_free_space); |
duke@435 | 157 | |
duke@435 | 158 | // Allocation. We report all successful allocations to the size policy |
duke@435 | 159 | // Note that the perm gen does not use this method, and should not! |
duke@435 | 160 | HeapWord* allocate(size_t word_size, bool is_tlab); |
duke@435 | 161 | |
duke@435 | 162 | // Iteration. |
duke@435 | 163 | void oop_iterate(OopClosure* cl) { object_space()->oop_iterate(cl); } |
duke@435 | 164 | void object_iterate(ObjectClosure* cl) { object_space()->object_iterate(cl); } |
duke@435 | 165 | |
duke@435 | 166 | // Debugging - do not use for time critical operations |
duke@435 | 167 | virtual void print() const; |
duke@435 | 168 | virtual void print_on(outputStream* st) const; |
duke@435 | 169 | void print_used_change(size_t prev_used) const; |
duke@435 | 170 | |
duke@435 | 171 | void verify(bool allow_dirty); |
duke@435 | 172 | void verify_object_start_array(); |
duke@435 | 173 | |
duke@435 | 174 | // These should not used |
duke@435 | 175 | virtual void reset_after_change(); |
duke@435 | 176 | |
duke@435 | 177 | // These should not used |
duke@435 | 178 | virtual size_t available_for_expansion(); |
duke@435 | 179 | virtual size_t available_for_contraction(); |
duke@435 | 180 | |
duke@435 | 181 | void space_invariants() PRODUCT_RETURN; |
duke@435 | 182 | |
duke@435 | 183 | // Performace Counter support |
duke@435 | 184 | void update_counters(); |
duke@435 | 185 | |
duke@435 | 186 | // Printing support |
duke@435 | 187 | virtual const char* name() const { return _name; } |
jmasa@698 | 188 | |
jmasa@698 | 189 | // Debugging support |
jmasa@698 | 190 | // Save the tops of all spaces for later use during mangling. |
jmasa@698 | 191 | void record_spaces_top() PRODUCT_RETURN; |
duke@435 | 192 | }; |