Thu, 09 Apr 2015 15:59:26 +0200
8066771: Refactor VM GC operations caused by allocation failure
Reviewed-by: brutisso, jmasa
duke@435 | 1 | /* |
sla@5237 | 2 | * Copyright (c) 2001, 2013, Oracle and/or its affiliates. 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 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PARALLELSCAVENGEHEAP_HPP |
stefank@2314 | 26 | #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PARALLELSCAVENGEHEAP_HPP |
stefank@2314 | 27 | |
jwilhelm@6085 | 28 | #include "gc_implementation/parallelScavenge/generationSizer.hpp" |
stefank@2314 | 29 | #include "gc_implementation/parallelScavenge/objectStartArray.hpp" |
stefank@2314 | 30 | #include "gc_implementation/parallelScavenge/psGCAdaptivePolicyCounters.hpp" |
stefank@2314 | 31 | #include "gc_implementation/parallelScavenge/psOldGen.hpp" |
stefank@2314 | 32 | #include "gc_implementation/parallelScavenge/psYoungGen.hpp" |
stefank@2314 | 33 | #include "gc_implementation/shared/gcPolicyCounters.hpp" |
sla@5237 | 34 | #include "gc_implementation/shared/gcWhen.hpp" |
stefank@2314 | 35 | #include "gc_interface/collectedHeap.inline.hpp" |
jwilhelm@6085 | 36 | #include "memory/collectorPolicy.hpp" |
stefank@2314 | 37 | #include "utilities/ostream.hpp" |
stefank@2314 | 38 | |
duke@435 | 39 | class AdjoiningGenerations; |
sla@5237 | 40 | class GCHeapSummary; |
duke@435 | 41 | class GCTaskManager; |
sla@5237 | 42 | class PSAdaptiveSizePolicy; |
sla@5237 | 43 | class PSHeapSummary; |
duke@435 | 44 | |
duke@435 | 45 | class ParallelScavengeHeap : public CollectedHeap { |
duke@435 | 46 | friend class VMStructs; |
duke@435 | 47 | private: |
duke@435 | 48 | static PSYoungGen* _young_gen; |
duke@435 | 49 | static PSOldGen* _old_gen; |
duke@435 | 50 | |
duke@435 | 51 | // Sizing policy for entire heap |
jwilhelm@6084 | 52 | static PSAdaptiveSizePolicy* _size_policy; |
jwilhelm@6084 | 53 | static PSGCAdaptivePolicyCounters* _gc_policy_counters; |
duke@435 | 54 | |
duke@435 | 55 | static ParallelScavengeHeap* _psh; |
duke@435 | 56 | |
jmasa@1822 | 57 | GenerationSizer* _collector_policy; |
jmasa@1822 | 58 | |
duke@435 | 59 | // Collection of generations that are adjacent in the |
duke@435 | 60 | // space reserved for the heap. |
duke@435 | 61 | AdjoiningGenerations* _gens; |
jcoomes@3541 | 62 | unsigned int _death_march_count; |
duke@435 | 63 | |
jwilhelm@6084 | 64 | // The task manager |
jwilhelm@6084 | 65 | static GCTaskManager* _gc_task_manager; |
duke@435 | 66 | |
sla@5237 | 67 | void trace_heap(GCWhen::Type when, GCTracer* tracer); |
sla@5237 | 68 | |
duke@435 | 69 | protected: |
duke@435 | 70 | static inline size_t total_invocations(); |
duke@435 | 71 | HeapWord* allocate_new_tlab(size_t size); |
duke@435 | 72 | |
jcoomes@3541 | 73 | inline bool should_alloc_in_eden(size_t size) const; |
jcoomes@3541 | 74 | inline void death_march_check(HeapWord* const result, size_t size); |
jcoomes@3541 | 75 | HeapWord* mem_allocate_old_gen(size_t size); |
jcoomes@3541 | 76 | |
duke@435 | 77 | public: |
jwilhelm@6085 | 78 | ParallelScavengeHeap() : CollectedHeap(), _death_march_count(0) { } |
tschatzl@5701 | 79 | |
duke@435 | 80 | // For use by VM operations |
duke@435 | 81 | enum CollectionType { |
duke@435 | 82 | Scavenge, |
duke@435 | 83 | MarkSweep |
duke@435 | 84 | }; |
duke@435 | 85 | |
duke@435 | 86 | ParallelScavengeHeap::Name kind() const { |
duke@435 | 87 | return CollectedHeap::ParallelScavengeHeap; |
duke@435 | 88 | } |
duke@435 | 89 | |
coleenp@4037 | 90 | virtual CollectorPolicy* collector_policy() const { return (CollectorPolicy*) _collector_policy; } |
jmasa@1822 | 91 | |
jwilhelm@6084 | 92 | static PSYoungGen* young_gen() { return _young_gen; } |
jwilhelm@6084 | 93 | static PSOldGen* old_gen() { return _old_gen; } |
duke@435 | 94 | |
duke@435 | 95 | virtual PSAdaptiveSizePolicy* size_policy() { return _size_policy; } |
duke@435 | 96 | |
duke@435 | 97 | static PSGCAdaptivePolicyCounters* gc_policy_counters() { return _gc_policy_counters; } |
duke@435 | 98 | |
duke@435 | 99 | static ParallelScavengeHeap* heap(); |
duke@435 | 100 | |
duke@435 | 101 | static GCTaskManager* const gc_task_manager() { return _gc_task_manager; } |
duke@435 | 102 | |
duke@435 | 103 | AdjoiningGenerations* gens() { return _gens; } |
duke@435 | 104 | |
duke@435 | 105 | // Returns JNI_OK on success |
duke@435 | 106 | virtual jint initialize(); |
duke@435 | 107 | |
duke@435 | 108 | void post_initialize(); |
duke@435 | 109 | void update_counters(); |
duke@435 | 110 | |
jwilhelm@6085 | 111 | // The alignment used for the various areas |
jwilhelm@6085 | 112 | size_t space_alignment() { return _collector_policy->space_alignment(); } |
jwilhelm@6085 | 113 | size_t generation_alignment() { return _collector_policy->gen_alignment(); } |
jwilhelm@6085 | 114 | |
jwilhelm@6085 | 115 | // Return the (conservative) maximum heap alignment |
jwilhelm@6085 | 116 | static size_t conservative_max_heap_alignment() { |
jwilhelm@6085 | 117 | return CollectorPolicy::compute_heap_alignment(); |
jwilhelm@6085 | 118 | } |
duke@435 | 119 | |
duke@435 | 120 | size_t capacity() const; |
duke@435 | 121 | size_t used() const; |
duke@435 | 122 | |
coleenp@4037 | 123 | // Return "true" if all generations have reached the |
duke@435 | 124 | // maximal committed limit that they can reach, without a garbage |
duke@435 | 125 | // collection. |
duke@435 | 126 | virtual bool is_maximal_no_gc() const; |
duke@435 | 127 | |
jmasa@2909 | 128 | // Return true if the reference points to an object that |
jmasa@2909 | 129 | // can be moved in a partial collection. For currently implemented |
jmasa@2909 | 130 | // generational collectors that means during a collection of |
jmasa@2909 | 131 | // the young gen. |
jmasa@2909 | 132 | virtual bool is_scavengable(const void* addr); |
jmasa@2909 | 133 | |
duke@435 | 134 | // Does this heap support heap inspection? (+PrintClassHistogram) |
duke@435 | 135 | bool supports_heap_inspection() const { return true; } |
duke@435 | 136 | |
duke@435 | 137 | size_t max_capacity() const; |
duke@435 | 138 | |
duke@435 | 139 | // Whether p is in the allocated part of the heap |
duke@435 | 140 | bool is_in(const void* p) const; |
duke@435 | 141 | |
duke@435 | 142 | bool is_in_reserved(const void* p) const; |
duke@435 | 143 | |
jmasa@2909 | 144 | #ifdef ASSERT |
jmasa@2909 | 145 | virtual bool is_in_partial_collection(const void *p); |
jmasa@2909 | 146 | #endif |
jmasa@2909 | 147 | |
jwilhelm@6084 | 148 | bool is_in_young(oop p); // reserved part |
jwilhelm@6084 | 149 | bool is_in_old(oop p); // reserved part |
duke@435 | 150 | |
duke@435 | 151 | // Memory allocation. "gc_time_limit_was_exceeded" will |
duke@435 | 152 | // be set to true if the adaptive size policy determine that |
duke@435 | 153 | // an excessive amount of time is being spent doing collections |
duke@435 | 154 | // and caused a NULL to be returned. If a NULL is not returned, |
duke@435 | 155 | // "gc_time_limit_was_exceeded" has an undefined meaning. |
jwilhelm@6084 | 156 | HeapWord* mem_allocate(size_t size, bool* gc_overhead_limit_was_exceeded); |
duke@435 | 157 | |
tonyp@2971 | 158 | // Allocation attempt(s) during a safepoint. It should never be called |
tonyp@2971 | 159 | // to allocate a new TLAB as this allocation might be satisfied out |
tonyp@2971 | 160 | // of the old generation. |
tonyp@2971 | 161 | HeapWord* failed_mem_allocate(size_t size); |
duke@435 | 162 | |
duke@435 | 163 | // Support for System.gc() |
duke@435 | 164 | void collect(GCCause::Cause cause); |
duke@435 | 165 | |
duke@435 | 166 | // These also should be called by the vm thread at a safepoint (e.g., from a |
duke@435 | 167 | // VM operation). |
duke@435 | 168 | // |
duke@435 | 169 | // The first collects the young generation only, unless the scavenge fails; it |
duke@435 | 170 | // will then attempt a full gc. The second collects the entire heap; if |
duke@435 | 171 | // maximum_compaction is true, it will compact everything and clear all soft |
duke@435 | 172 | // references. |
duke@435 | 173 | inline void invoke_scavenge(); |
coleenp@4037 | 174 | |
coleenp@4037 | 175 | // Perform a full collection |
coleenp@4037 | 176 | virtual void do_full_collection(bool clear_all_soft_refs); |
duke@435 | 177 | |
duke@435 | 178 | bool supports_inline_contig_alloc() const { return !UseNUMA; } |
iveresov@576 | 179 | |
iveresov@576 | 180 | HeapWord** top_addr() const { return !UseNUMA ? young_gen()->top_addr() : (HeapWord**)-1; } |
iveresov@576 | 181 | HeapWord** end_addr() const { return !UseNUMA ? young_gen()->end_addr() : (HeapWord**)-1; } |
duke@435 | 182 | |
duke@435 | 183 | void ensure_parsability(bool retire_tlabs); |
duke@435 | 184 | void accumulate_statistics_all_tlabs(); |
duke@435 | 185 | void resize_all_tlabs(); |
duke@435 | 186 | |
duke@435 | 187 | bool supports_tlab_allocation() const { return true; } |
duke@435 | 188 | |
duke@435 | 189 | size_t tlab_capacity(Thread* thr) const; |
brutisso@6376 | 190 | size_t tlab_used(Thread* thr) const; |
duke@435 | 191 | size_t unsafe_max_tlab_alloc(Thread* thr) const; |
duke@435 | 192 | |
ysr@777 | 193 | // Can a compiler initialize a new object without store barriers? |
ysr@777 | 194 | // This permission only extends from the creation of a new object |
ysr@777 | 195 | // via a TLAB up to the first subsequent safepoint. |
ysr@777 | 196 | virtual bool can_elide_tlab_store_barriers() const { |
ysr@777 | 197 | return true; |
ysr@777 | 198 | } |
ysr@777 | 199 | |
ysr@1601 | 200 | virtual bool card_mark_must_follow_store() const { |
ysr@1601 | 201 | return false; |
ysr@1601 | 202 | } |
ysr@1601 | 203 | |
ysr@1462 | 204 | // Return true if we don't we need a store barrier for |
ysr@1462 | 205 | // initializing stores to an object at this address. |
ysr@1462 | 206 | virtual bool can_elide_initializing_store_barrier(oop new_obj); |
ysr@1462 | 207 | |
coleenp@4037 | 208 | void oop_iterate(ExtendedOopClosure* cl); |
duke@435 | 209 | void object_iterate(ObjectClosure* cl); |
jmasa@952 | 210 | void safe_object_iterate(ObjectClosure* cl) { object_iterate(cl); } |
duke@435 | 211 | |
duke@435 | 212 | HeapWord* block_start(const void* addr) const; |
duke@435 | 213 | size_t block_size(const HeapWord* addr) const; |
duke@435 | 214 | bool block_is_obj(const HeapWord* addr) const; |
duke@435 | 215 | |
duke@435 | 216 | jlong millis_since_last_gc(); |
duke@435 | 217 | |
duke@435 | 218 | void prepare_for_verify(); |
sla@5237 | 219 | PSHeapSummary create_ps_heap_summary(); |
tonyp@3269 | 220 | virtual void print_on(outputStream* st) const; |
stefank@4904 | 221 | virtual void print_on_error(outputStream* st) const; |
duke@435 | 222 | virtual void print_gc_threads_on(outputStream* st) const; |
duke@435 | 223 | virtual void gc_threads_do(ThreadClosure* tc) const; |
duke@435 | 224 | virtual void print_tracing_info() const; |
duke@435 | 225 | |
brutisso@3711 | 226 | void verify(bool silent, VerifyOption option /* ignored */); |
duke@435 | 227 | |
duke@435 | 228 | void print_heap_change(size_t prev_used); |
duke@435 | 229 | |
duke@435 | 230 | // Resize the young generation. The reserved space for the |
duke@435 | 231 | // generation may be expanded in preparation for the resize. |
duke@435 | 232 | void resize_young_gen(size_t eden_size, size_t survivor_size); |
duke@435 | 233 | |
duke@435 | 234 | // Resize the old generation. The reserved space for the |
duke@435 | 235 | // generation may be expanded in preparation for the resize. |
duke@435 | 236 | void resize_old_gen(size_t desired_free_space); |
jmasa@698 | 237 | |
jmasa@698 | 238 | // Save the tops of the spaces in all generations |
jmasa@698 | 239 | void record_gen_tops_before_GC() PRODUCT_RETURN; |
jmasa@698 | 240 | |
jmasa@698 | 241 | // Mangle the unused parts of all spaces in the heap |
jmasa@698 | 242 | void gen_mangle_unused_area() PRODUCT_RETURN; |
jrose@1424 | 243 | |
jrose@1424 | 244 | // Call these in sequential code around the processing of strong roots. |
jrose@1424 | 245 | class ParStrongRootsScope : public MarkingCodeBlobClosure::MarkScope { |
jwilhelm@6084 | 246 | public: |
jrose@1424 | 247 | ParStrongRootsScope(); |
jrose@1424 | 248 | ~ParStrongRootsScope(); |
jrose@1424 | 249 | }; |
duke@435 | 250 | }; |
duke@435 | 251 | |
stefank@2314 | 252 | #endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PARALLELSCAVENGEHEAP_HPP |