1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/gc_implementation/parallelScavenge/psOldGen.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,201 @@ 1.4 +/* 1.5 + * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSOLDGEN_HPP 1.29 +#define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSOLDGEN_HPP 1.30 + 1.31 +#include "gc_implementation/parallelScavenge/objectStartArray.hpp" 1.32 +#include "gc_implementation/parallelScavenge/psGenerationCounters.hpp" 1.33 +#include "gc_implementation/parallelScavenge/psVirtualspace.hpp" 1.34 +#include "gc_implementation/shared/mutableSpace.hpp" 1.35 +#include "gc_implementation/shared/spaceCounters.hpp" 1.36 +#include "runtime/safepoint.hpp" 1.37 + 1.38 +class PSMarkSweepDecorator; 1.39 + 1.40 +class PSOldGen : public CHeapObj<mtGC> { 1.41 + friend class VMStructs; 1.42 + friend class PSPromotionManager; // Uses the cas_allocate methods 1.43 + friend class ParallelScavengeHeap; 1.44 + friend class AdjoiningGenerations; 1.45 + 1.46 + protected: 1.47 + MemRegion _reserved; // Used for simple containment tests 1.48 + PSVirtualSpace* _virtual_space; // Controls mapping and unmapping of virtual mem 1.49 + ObjectStartArray _start_array; // Keeps track of where objects start in a 512b block 1.50 + MutableSpace* _object_space; // Where all the objects live 1.51 + PSMarkSweepDecorator* _object_mark_sweep; // The mark sweep view of _object_space 1.52 + const char* const _name; // Name of this generation. 1.53 + 1.54 + // Performance Counters 1.55 + PSGenerationCounters* _gen_counters; 1.56 + SpaceCounters* _space_counters; 1.57 + 1.58 + // Sizing information, in bytes, set in constructor 1.59 + const size_t _init_gen_size; 1.60 + const size_t _min_gen_size; 1.61 + const size_t _max_gen_size; 1.62 + 1.63 + // Used when initializing the _name field. 1.64 + static inline const char* select_name(); 1.65 + 1.66 + HeapWord* allocate_noexpand(size_t word_size) { 1.67 + // We assume the heap lock is held here. 1.68 + assert_locked_or_safepoint(Heap_lock); 1.69 + HeapWord* res = object_space()->allocate(word_size); 1.70 + if (res != NULL) { 1.71 + _start_array.allocate_block(res); 1.72 + } 1.73 + return res; 1.74 + } 1.75 + 1.76 + // Support for MT garbage collection. CAS allocation is lower overhead than grabbing 1.77 + // and releasing the heap lock, which is held during gc's anyway. This method is not 1.78 + // safe for use at the same time as allocate_noexpand()! 1.79 + HeapWord* cas_allocate_noexpand(size_t word_size) { 1.80 + assert(SafepointSynchronize::is_at_safepoint(), "Must only be called at safepoint"); 1.81 + HeapWord* res = object_space()->cas_allocate(word_size); 1.82 + if (res != NULL) { 1.83 + _start_array.allocate_block(res); 1.84 + } 1.85 + return res; 1.86 + } 1.87 + 1.88 + // Support for MT garbage collection. See above comment. 1.89 + HeapWord* cas_allocate(size_t word_size) { 1.90 + HeapWord* res = cas_allocate_noexpand(word_size); 1.91 + return (res == NULL) ? expand_and_cas_allocate(word_size) : res; 1.92 + } 1.93 + 1.94 + HeapWord* expand_and_allocate(size_t word_size); 1.95 + HeapWord* expand_and_cas_allocate(size_t word_size); 1.96 + void expand(size_t bytes); 1.97 + bool expand_by(size_t bytes); 1.98 + bool expand_to_reserved(); 1.99 + 1.100 + void shrink(size_t bytes); 1.101 + 1.102 + void post_resize(); 1.103 + 1.104 + public: 1.105 + // Initialize the generation. 1.106 + PSOldGen(ReservedSpace rs, size_t alignment, 1.107 + size_t initial_size, size_t min_size, size_t max_size, 1.108 + const char* perf_data_name, int level); 1.109 + 1.110 + PSOldGen(size_t initial_size, size_t min_size, size_t max_size, 1.111 + const char* perf_data_name, int level); 1.112 + 1.113 + virtual void initialize(ReservedSpace rs, size_t alignment, 1.114 + const char* perf_data_name, int level); 1.115 + void initialize_virtual_space(ReservedSpace rs, size_t alignment); 1.116 + virtual void initialize_work(const char* perf_data_name, int level); 1.117 + virtual void initialize_performance_counters(const char* perf_data_name, int level); 1.118 + 1.119 + MemRegion reserved() const { return _reserved; } 1.120 + virtual size_t max_gen_size() { return _max_gen_size; } 1.121 + size_t min_gen_size() { return _min_gen_size; } 1.122 + 1.123 + // Returns limit on the maximum size of the generation. This 1.124 + // is the same as _max_gen_size for PSOldGen but need not be 1.125 + // for a derived class. 1.126 + virtual size_t gen_size_limit(); 1.127 + 1.128 + bool is_in(const void* p) const { 1.129 + return _virtual_space->contains((void *)p); 1.130 + } 1.131 + 1.132 + bool is_in_reserved(const void* p) const { 1.133 + return reserved().contains(p); 1.134 + } 1.135 + 1.136 + MutableSpace* object_space() const { return _object_space; } 1.137 + PSMarkSweepDecorator* object_mark_sweep() const { return _object_mark_sweep; } 1.138 + ObjectStartArray* start_array() { return &_start_array; } 1.139 + PSVirtualSpace* virtual_space() const { return _virtual_space;} 1.140 + 1.141 + // Has the generation been successfully allocated? 1.142 + bool is_allocated(); 1.143 + 1.144 + // MarkSweep methods 1.145 + virtual void precompact(); 1.146 + void adjust_pointers(); 1.147 + void compact(); 1.148 + 1.149 + // Size info 1.150 + size_t capacity_in_bytes() const { return object_space()->capacity_in_bytes(); } 1.151 + size_t used_in_bytes() const { return object_space()->used_in_bytes(); } 1.152 + size_t free_in_bytes() const { return object_space()->free_in_bytes(); } 1.153 + 1.154 + size_t capacity_in_words() const { return object_space()->capacity_in_words(); } 1.155 + size_t used_in_words() const { return object_space()->used_in_words(); } 1.156 + size_t free_in_words() const { return object_space()->free_in_words(); } 1.157 + 1.158 + // Includes uncommitted memory 1.159 + size_t contiguous_available() const; 1.160 + 1.161 + bool is_maximal_no_gc() const { 1.162 + return virtual_space()->uncommitted_size() == 0; 1.163 + } 1.164 + 1.165 + // Calculating new sizes 1.166 + void resize(size_t desired_free_space); 1.167 + 1.168 + // Allocation. We report all successful allocations to the size policy 1.169 + // Note that the perm gen does not use this method, and should not! 1.170 + HeapWord* allocate(size_t word_size); 1.171 + 1.172 + // Iteration. 1.173 + void oop_iterate_no_header(OopClosure* cl) { object_space()->oop_iterate_no_header(cl); } 1.174 + void object_iterate(ObjectClosure* cl) { object_space()->object_iterate(cl); } 1.175 + 1.176 + // Debugging - do not use for time critical operations 1.177 + virtual void print() const; 1.178 + virtual void print_on(outputStream* st) const; 1.179 + void print_used_change(size_t prev_used) const; 1.180 + 1.181 + void verify(); 1.182 + void verify_object_start_array(); 1.183 + 1.184 + // These should not used 1.185 + virtual void reset_after_change(); 1.186 + 1.187 + // These should not used 1.188 + virtual size_t available_for_expansion(); 1.189 + virtual size_t available_for_contraction(); 1.190 + 1.191 + void space_invariants() PRODUCT_RETURN; 1.192 + 1.193 + // Performace Counter support 1.194 + void update_counters(); 1.195 + 1.196 + // Printing support 1.197 + virtual const char* name() const { return _name; } 1.198 + 1.199 + // Debugging support 1.200 + // Save the tops of all spaces for later use during mangling. 1.201 + void record_spaces_top() PRODUCT_RETURN; 1.202 +}; 1.203 + 1.204 +#endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSOLDGEN_HPP