1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/gc_implementation/parallelScavenge/psScavenge.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,168 @@ 1.4 +/* 1.5 + * Copyright (c) 2002, 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_PSSCAVENGE_HPP 1.29 +#define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSSCAVENGE_HPP 1.30 + 1.31 +#include "gc_implementation/parallelScavenge/cardTableExtension.hpp" 1.32 +#include "gc_implementation/parallelScavenge/psVirtualspace.hpp" 1.33 +#include "gc_implementation/shared/collectorCounters.hpp" 1.34 +#include "gc_implementation/shared/gcTrace.hpp" 1.35 +#include "memory/allocation.hpp" 1.36 +#include "oops/oop.hpp" 1.37 +#include "utilities/stack.hpp" 1.38 + 1.39 +class GCTaskManager; 1.40 +class GCTaskQueue; 1.41 +class OopStack; 1.42 +class ReferenceProcessor; 1.43 +class ParallelScavengeHeap; 1.44 +class ParallelScavengeTracer; 1.45 +class PSIsAliveClosure; 1.46 +class PSRefProcTaskExecutor; 1.47 +class STWGCTimer; 1.48 + 1.49 +class PSScavenge: AllStatic { 1.50 + friend class PSIsAliveClosure; 1.51 + friend class PSKeepAliveClosure; 1.52 + friend class PSPromotionManager; 1.53 + 1.54 + enum ScavengeSkippedCause { 1.55 + not_skipped = 0, 1.56 + to_space_not_empty, 1.57 + promoted_too_large, 1.58 + full_follows_scavenge 1.59 + }; 1.60 + 1.61 + // Saved value of to_space->top(), used to prevent objects in to_space from 1.62 + // being rescanned. 1.63 + static HeapWord* _to_space_top_before_gc; 1.64 + 1.65 + // Number of consecutive attempts to scavenge that were skipped 1.66 + static int _consecutive_skipped_scavenges; 1.67 + 1.68 + 1.69 + protected: 1.70 + // Flags/counters 1.71 + static ReferenceProcessor* _ref_processor; // Reference processor for scavenging. 1.72 + static PSIsAliveClosure _is_alive_closure; // Closure used for reference processing 1.73 + static CardTableExtension* _card_table; // We cache the card table for fast access. 1.74 + static bool _survivor_overflow; // Overflow this collection 1.75 + static uint _tenuring_threshold; // tenuring threshold for next scavenge 1.76 + static elapsedTimer _accumulated_time; // total time spent on scavenge 1.77 + static STWGCTimer _gc_timer; // GC time book keeper 1.78 + static ParallelScavengeTracer _gc_tracer; // GC tracing 1.79 + // The lowest address possible for the young_gen. 1.80 + // This is used to decide if an oop should be scavenged, 1.81 + // cards should be marked, etc. 1.82 + static HeapWord* _young_generation_boundary; 1.83 + // Used to optimize compressed oops young gen boundary checking. 1.84 + static uintptr_t _young_generation_boundary_compressed; 1.85 + static Stack<markOop, mtGC> _preserved_mark_stack; // List of marks to be restored after failed promotion 1.86 + static Stack<oop, mtGC> _preserved_oop_stack; // List of oops that need their mark restored. 1.87 + static CollectorCounters* _counters; // collector performance counters 1.88 + 1.89 + static void clean_up_failed_promotion(); 1.90 + 1.91 + static bool should_attempt_scavenge(); 1.92 + 1.93 + static HeapWord* to_space_top_before_gc() { return _to_space_top_before_gc; } 1.94 + static inline void save_to_space_top_before_gc(); 1.95 + 1.96 + // Private accessors 1.97 + static CardTableExtension* const card_table() { assert(_card_table != NULL, "Sanity"); return _card_table; } 1.98 + 1.99 + public: 1.100 + // Accessors 1.101 + static uint tenuring_threshold() { return _tenuring_threshold; } 1.102 + static elapsedTimer* accumulated_time() { return &_accumulated_time; } 1.103 + static int consecutive_skipped_scavenges() 1.104 + { return _consecutive_skipped_scavenges; } 1.105 + 1.106 + // Performance Counters 1.107 + static CollectorCounters* counters() { return _counters; } 1.108 + 1.109 + // Used by scavenge_contents && psMarkSweep 1.110 + static ReferenceProcessor* const reference_processor() { 1.111 + assert(_ref_processor != NULL, "Sanity"); 1.112 + return _ref_processor; 1.113 + } 1.114 + // Used to add tasks 1.115 + static GCTaskManager* const gc_task_manager(); 1.116 + // The promotion managers tell us if they encountered overflow 1.117 + static void set_survivor_overflow(bool state) { 1.118 + _survivor_overflow = state; 1.119 + } 1.120 + // Adaptive size policy support. When the young generation/old generation 1.121 + // boundary moves, _young_generation_boundary must be reset 1.122 + static void set_young_generation_boundary(HeapWord* v) { 1.123 + _young_generation_boundary = v; 1.124 + if (UseCompressedOops) { 1.125 + _young_generation_boundary_compressed = (uintptr_t)oopDesc::encode_heap_oop((oop)v); 1.126 + } 1.127 + } 1.128 + 1.129 + // Called by parallelScavengeHeap to init the tenuring threshold 1.130 + static void initialize(); 1.131 + 1.132 + // Scavenge entry point. This may invoke a full gc; return true if so. 1.133 + static bool invoke(); 1.134 + // Return true if a collection was done; false otherwise. 1.135 + static bool invoke_no_policy(); 1.136 + 1.137 + // If an attempt to promote fails, this method is invoked 1.138 + static void oop_promotion_failed(oop obj, markOop obj_mark); 1.139 + 1.140 + template <class T> static inline bool should_scavenge(T* p); 1.141 + 1.142 + // These call should_scavenge() above and, if it returns true, also check that 1.143 + // the object was not newly copied into to_space. The version with the bool 1.144 + // argument is a convenience wrapper that fetches the to_space pointer from 1.145 + // the heap and calls the other version (if the arg is true). 1.146 + template <class T> static inline bool should_scavenge(T* p, MutableSpace* to_space); 1.147 + template <class T> static inline bool should_scavenge(T* p, bool check_to_space); 1.148 + 1.149 + template <class T, bool promote_immediately> 1.150 + inline static void copy_and_push_safe_barrier(PSPromotionManager* pm, T* p); 1.151 + 1.152 + static void copy_and_push_safe_barrier_from_klass(PSPromotionManager* pm, oop* p); 1.153 + 1.154 + // Is an object in the young generation 1.155 + // This assumes that the 'o' is in the heap, 1.156 + // so it only checks one side of the complete predicate. 1.157 + 1.158 + inline static bool is_obj_in_young(oop o) { 1.159 + return (HeapWord*)o >= _young_generation_boundary; 1.160 + } 1.161 + 1.162 + inline static bool is_obj_in_young(narrowOop o) { 1.163 + return (uintptr_t)o >= _young_generation_boundary_compressed; 1.164 + } 1.165 + 1.166 + inline static bool is_obj_in_young(HeapWord* o) { 1.167 + return o >= _young_generation_boundary; 1.168 + } 1.169 +}; 1.170 + 1.171 +#endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSSCAVENGE_HPP