1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.hpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,222 @@ 1.4 +/* 1.5 + * Copyright 2001-2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +class AdjoiningGenerations; 1.29 +class GCTaskManager; 1.30 +class PSAdaptiveSizePolicy; 1.31 + 1.32 +class ParallelScavengeHeap : public CollectedHeap { 1.33 + friend class VMStructs; 1.34 + private: 1.35 + static PSYoungGen* _young_gen; 1.36 + static PSOldGen* _old_gen; 1.37 + static PSPermGen* _perm_gen; 1.38 + 1.39 + // Sizing policy for entire heap 1.40 + static PSAdaptiveSizePolicy* _size_policy; 1.41 + static PSGCAdaptivePolicyCounters* _gc_policy_counters; 1.42 + 1.43 + static ParallelScavengeHeap* _psh; 1.44 + 1.45 + size_t _perm_gen_alignment; 1.46 + size_t _young_gen_alignment; 1.47 + size_t _old_gen_alignment; 1.48 + 1.49 + inline size_t set_alignment(size_t& var, size_t val); 1.50 + 1.51 + // Collection of generations that are adjacent in the 1.52 + // space reserved for the heap. 1.53 + AdjoiningGenerations* _gens; 1.54 + 1.55 + static GCTaskManager* _gc_task_manager; // The task manager. 1.56 + 1.57 + protected: 1.58 + static inline size_t total_invocations(); 1.59 + HeapWord* allocate_new_tlab(size_t size); 1.60 + void fill_all_tlabs(bool retire); 1.61 + 1.62 + public: 1.63 + ParallelScavengeHeap() : CollectedHeap() { 1.64 + set_alignment(_perm_gen_alignment, intra_generation_alignment()); 1.65 + set_alignment(_young_gen_alignment, intra_generation_alignment()); 1.66 + set_alignment(_old_gen_alignment, intra_generation_alignment()); 1.67 + } 1.68 + 1.69 + // For use by VM operations 1.70 + enum CollectionType { 1.71 + Scavenge, 1.72 + MarkSweep 1.73 + }; 1.74 + 1.75 + ParallelScavengeHeap::Name kind() const { 1.76 + return CollectedHeap::ParallelScavengeHeap; 1.77 + } 1.78 + 1.79 + static PSYoungGen* young_gen() { return _young_gen; } 1.80 + static PSOldGen* old_gen() { return _old_gen; } 1.81 + static PSPermGen* perm_gen() { return _perm_gen; } 1.82 + 1.83 + virtual PSAdaptiveSizePolicy* size_policy() { return _size_policy; } 1.84 + 1.85 + static PSGCAdaptivePolicyCounters* gc_policy_counters() { return _gc_policy_counters; } 1.86 + 1.87 + static ParallelScavengeHeap* heap(); 1.88 + 1.89 + static GCTaskManager* const gc_task_manager() { return _gc_task_manager; } 1.90 + 1.91 + AdjoiningGenerations* gens() { return _gens; } 1.92 + 1.93 + // Returns JNI_OK on success 1.94 + virtual jint initialize(); 1.95 + 1.96 + void post_initialize(); 1.97 + void update_counters(); 1.98 + 1.99 + // The alignment used for the various generations. 1.100 + size_t perm_gen_alignment() const { return _perm_gen_alignment; } 1.101 + size_t young_gen_alignment() const { return _young_gen_alignment; } 1.102 + size_t old_gen_alignment() const { return _old_gen_alignment; } 1.103 + 1.104 + // The alignment used for eden and survivors within the young gen. 1.105 + size_t intra_generation_alignment() const { return 64 * K; } 1.106 + 1.107 + size_t capacity() const; 1.108 + size_t used() const; 1.109 + 1.110 + // Return "true" if all generations (but perm) have reached the 1.111 + // maximal committed limit that they can reach, without a garbage 1.112 + // collection. 1.113 + virtual bool is_maximal_no_gc() const; 1.114 + 1.115 + // Does this heap support heap inspection? (+PrintClassHistogram) 1.116 + bool supports_heap_inspection() const { return true; } 1.117 + 1.118 + size_t permanent_capacity() const; 1.119 + size_t permanent_used() const; 1.120 + 1.121 + size_t max_capacity() const; 1.122 + 1.123 + // Whether p is in the allocated part of the heap 1.124 + bool is_in(const void* p) const; 1.125 + 1.126 + bool is_in_reserved(const void* p) const; 1.127 + bool is_in_permanent(const void *p) const { // reserved part 1.128 + return perm_gen()->reserved().contains(p); 1.129 + } 1.130 + 1.131 + bool is_permanent(const void *p) const { // committed part 1.132 + return perm_gen()->is_in(p); 1.133 + } 1.134 + 1.135 + static bool is_in_young(oop *p); // reserved part 1.136 + static bool is_in_old_or_perm(oop *p); // reserved part 1.137 + 1.138 + // Memory allocation. "gc_time_limit_was_exceeded" will 1.139 + // be set to true if the adaptive size policy determine that 1.140 + // an excessive amount of time is being spent doing collections 1.141 + // and caused a NULL to be returned. If a NULL is not returned, 1.142 + // "gc_time_limit_was_exceeded" has an undefined meaning. 1.143 + 1.144 + HeapWord* mem_allocate(size_t size, 1.145 + bool is_noref, 1.146 + bool is_tlab, 1.147 + bool* gc_overhead_limit_was_exceeded); 1.148 + HeapWord* failed_mem_allocate(size_t size, bool is_tlab); 1.149 + 1.150 + HeapWord* permanent_mem_allocate(size_t size); 1.151 + HeapWord* failed_permanent_mem_allocate(size_t size); 1.152 + 1.153 + // Support for System.gc() 1.154 + void collect(GCCause::Cause cause); 1.155 + 1.156 + // This interface assumes that it's being called by the 1.157 + // vm thread. It collects the heap assuming that the 1.158 + // heap lock is already held and that we are executing in 1.159 + // the context of the vm thread. 1.160 + void collect_as_vm_thread(GCCause::Cause cause); 1.161 + 1.162 + // These also should be called by the vm thread at a safepoint (e.g., from a 1.163 + // VM operation). 1.164 + // 1.165 + // The first collects the young generation only, unless the scavenge fails; it 1.166 + // will then attempt a full gc. The second collects the entire heap; if 1.167 + // maximum_compaction is true, it will compact everything and clear all soft 1.168 + // references. 1.169 + inline void invoke_scavenge(); 1.170 + inline void invoke_full_gc(bool maximum_compaction); 1.171 + 1.172 + size_t large_typearray_limit() { return FastAllocateSizeLimit; } 1.173 + 1.174 + bool supports_inline_contig_alloc() const { return !UseNUMA; } 1.175 + HeapWord** top_addr() const { return !UseNUMA ? young_gen()->top_addr() : NULL; } 1.176 + HeapWord** end_addr() const { return !UseNUMA ? young_gen()->end_addr() : NULL; } 1.177 + 1.178 + void ensure_parsability(bool retire_tlabs); 1.179 + void accumulate_statistics_all_tlabs(); 1.180 + void resize_all_tlabs(); 1.181 + 1.182 + size_t unsafe_max_alloc(); 1.183 + 1.184 + bool supports_tlab_allocation() const { return true; } 1.185 + 1.186 + size_t tlab_capacity(Thread* thr) const; 1.187 + size_t unsafe_max_tlab_alloc(Thread* thr) const; 1.188 + 1.189 + void oop_iterate(OopClosure* cl); 1.190 + void object_iterate(ObjectClosure* cl); 1.191 + void permanent_oop_iterate(OopClosure* cl); 1.192 + void permanent_object_iterate(ObjectClosure* cl); 1.193 + 1.194 + HeapWord* block_start(const void* addr) const; 1.195 + size_t block_size(const HeapWord* addr) const; 1.196 + bool block_is_obj(const HeapWord* addr) const; 1.197 + 1.198 + jlong millis_since_last_gc(); 1.199 + 1.200 + void prepare_for_verify(); 1.201 + void print() const; 1.202 + void print_on(outputStream* st) const; 1.203 + virtual void print_gc_threads_on(outputStream* st) const; 1.204 + virtual void gc_threads_do(ThreadClosure* tc) const; 1.205 + virtual void print_tracing_info() const; 1.206 + 1.207 + void verify(bool allow_dirty, bool silent); 1.208 + 1.209 + void print_heap_change(size_t prev_used); 1.210 + 1.211 + // Resize the young generation. The reserved space for the 1.212 + // generation may be expanded in preparation for the resize. 1.213 + void resize_young_gen(size_t eden_size, size_t survivor_size); 1.214 + 1.215 + // Resize the old generation. The reserved space for the 1.216 + // generation may be expanded in preparation for the resize. 1.217 + void resize_old_gen(size_t desired_free_space); 1.218 +}; 1.219 + 1.220 +inline size_t ParallelScavengeHeap::set_alignment(size_t& var, size_t val) 1.221 +{ 1.222 + assert(is_power_of_2((intptr_t)val), "must be a power of 2"); 1.223 + var = round_to(val, intra_generation_alignment()); 1.224 + return var; 1.225 +}