1 /* 2 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSSCAVENGE_HPP 26 #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSSCAVENGE_HPP 27 28 #include "gc_implementation/parallelScavenge/cardTableExtension.hpp" 29 #include "gc_implementation/parallelScavenge/psVirtualspace.hpp" 30 #include "gc_implementation/shared/collectorCounters.hpp" 31 #include "memory/allocation.hpp" 32 #include "oops/oop.hpp" 33 34 class GCTaskManager; 35 class GCTaskQueue; 36 class OopStack; 37 class ReferenceProcessor; 38 class ParallelScavengeHeap; 39 class PSIsAliveClosure; 40 class PSRefProcTaskExecutor; 41 42 class PSScavenge: AllStatic { 43 friend class PSIsAliveClosure; 44 friend class PSKeepAliveClosure; 45 friend class PSPromotionManager; 46 47 enum ScavengeSkippedCause { 48 not_skipped = 0, 49 to_space_not_empty, 50 promoted_too_large, 51 full_follows_scavenge 52 }; 53 54 // Saved value of to_space->top(), used to prevent objects in to_space from 55 // being rescanned. 56 static HeapWord* _to_space_top_before_gc; 57 58 // Number of consecutive attempts to scavenge that were skipped 59 static int _consecutive_skipped_scavenges; 60 61 62 protected: 63 // Flags/counters 64 static ReferenceProcessor* _ref_processor; // Reference processor for scavenging. 65 static PSIsAliveClosure _is_alive_closure; // Closure used for reference processing 66 static CardTableExtension* _card_table; // We cache the card table for fast access. 67 static bool _survivor_overflow; // Overflow this collection 68 static int _tenuring_threshold; // tenuring threshold for next scavenge 69 static elapsedTimer _accumulated_time; // total time spent on scavenge 70 static HeapWord* _young_generation_boundary; // The lowest address possible for the young_gen. 71 // This is used to decide if an oop should be scavenged, 72 // cards should be marked, etc. 73 static GrowableArray<markOop>* _preserved_mark_stack; // List of marks to be restored after failed promotion 74 static GrowableArray<oop>* _preserved_oop_stack; // List of oops that need their mark restored. 75 static CollectorCounters* _counters; // collector performance counters 76 77 static void clean_up_failed_promotion(); 78 79 static bool should_attempt_scavenge(); 80 81 static HeapWord* to_space_top_before_gc() { return _to_space_top_before_gc; } 82 static inline void save_to_space_top_before_gc(); 83 84 // Private accessors 85 static CardTableExtension* const card_table() { assert(_card_table != NULL, "Sanity"); return _card_table; } 86 87 public: 88 // Accessors 89 static int tenuring_threshold() { return _tenuring_threshold; } 90 static elapsedTimer* accumulated_time() { return &_accumulated_time; } 91 static bool promotion_failed() 92 { return _preserved_mark_stack != NULL; } 93 static int consecutive_skipped_scavenges() 94 { return _consecutive_skipped_scavenges; } 95 96 // Performance Counters 97 static CollectorCounters* counters() { return _counters; } 98 99 // Used by scavenge_contents && psMarkSweep 100 static ReferenceProcessor* const reference_processor() { 101 assert(_ref_processor != NULL, "Sanity"); 102 return _ref_processor; 103 } 104 // Used to add tasks 105 static GCTaskManager* const gc_task_manager(); 106 // The promotion managers tell us if they encountered overflow 107 static void set_survivor_overflow(bool state) { 108 _survivor_overflow = state; 109 } 110 // Adaptive size policy support. When the young generation/old generation 111 // boundary moves, _young_generation_boundary must be reset 112 static void set_young_generation_boundary(HeapWord* v) { 113 _young_generation_boundary = v; 114 } 115 116 // Called by parallelScavengeHeap to init the tenuring threshold 117 static void initialize(); 118 119 // Scavenge entry point 120 static void invoke(); 121 // Return true is a collection was done. Return 122 // false if the collection was skipped. 123 static bool invoke_no_policy(); 124 125 // If an attempt to promote fails, this method is invoked 126 static void oop_promotion_failed(oop obj, markOop obj_mark); 127 128 template <class T> static inline bool should_scavenge(T* p); 129 130 // These call should_scavenge() above and, if it returns true, also check that 131 // the object was not newly copied into to_space. The version with the bool 132 // argument is a convenience wrapper that fetches the to_space pointer from 133 // the heap and calls the other version (if the arg is true). 134 template <class T> static inline bool should_scavenge(T* p, MutableSpace* to_space); 135 template <class T> static inline bool should_scavenge(T* p, bool check_to_space); 136 137 template <class T> inline static void copy_and_push_safe_barrier(PSPromotionManager* pm, T* p); 138 139 // Is an object in the young generation 140 // This assumes that the HeapWord argument is in the heap, 141 // so it only checks one side of the complete predicate. 142 inline static bool is_obj_in_young(HeapWord* o) { 143 const bool result = (o >= _young_generation_boundary); 144 return result; 145 } 146 }; 147 148 #endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSSCAVENGE_HPP