duke@435: /* sla@5237: * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSSCAVENGE_HPP stefank@2314: #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSSCAVENGE_HPP stefank@2314: stefank@2314: #include "gc_implementation/parallelScavenge/cardTableExtension.hpp" stefank@2314: #include "gc_implementation/parallelScavenge/psVirtualspace.hpp" stefank@2314: #include "gc_implementation/shared/collectorCounters.hpp" sla@5237: #include "gc_implementation/shared/gcTrace.hpp" stefank@2314: #include "memory/allocation.hpp" stefank@2314: #include "oops/oop.hpp" stefank@2314: #include "utilities/stack.hpp" stefank@2314: duke@435: class GCTaskManager; duke@435: class GCTaskQueue; duke@435: class OopStack; duke@435: class ReferenceProcessor; duke@435: class ParallelScavengeHeap; sla@5237: class ParallelScavengeTracer; duke@435: class PSIsAliveClosure; duke@435: class PSRefProcTaskExecutor; sla@5237: class STWGCTimer; duke@435: duke@435: class PSScavenge: AllStatic { duke@435: friend class PSIsAliveClosure; duke@435: friend class PSKeepAliveClosure; duke@435: friend class PSPromotionManager; duke@435: duke@435: enum ScavengeSkippedCause { duke@435: not_skipped = 0, duke@435: to_space_not_empty, duke@435: promoted_too_large, duke@435: full_follows_scavenge duke@435: }; duke@435: duke@435: // Saved value of to_space->top(), used to prevent objects in to_space from duke@435: // being rescanned. duke@435: static HeapWord* _to_space_top_before_gc; duke@435: duke@435: // Number of consecutive attempts to scavenge that were skipped duke@435: static int _consecutive_skipped_scavenges; duke@435: duke@435: duke@435: protected: duke@435: // Flags/counters stefank@5202: static ReferenceProcessor* _ref_processor; // Reference processor for scavenging. stefank@5202: static PSIsAliveClosure _is_alive_closure; // Closure used for reference processing stefank@5202: static CardTableExtension* _card_table; // We cache the card table for fast access. stefank@5202: static bool _survivor_overflow; // Overflow this collection stefank@5202: static uint _tenuring_threshold; // tenuring threshold for next scavenge stefank@5202: static elapsedTimer _accumulated_time; // total time spent on scavenge sla@5237: static STWGCTimer _gc_timer; // GC time book keeper sla@5237: static ParallelScavengeTracer _gc_tracer; // GC tracing stefank@5202: // The lowest address possible for the young_gen. stefank@5202: // This is used to decide if an oop should be scavenged, stefank@5202: // cards should be marked, etc. stefank@5202: static HeapWord* _young_generation_boundary; stefank@5202: // Used to optimize compressed oops young gen boundary checking. stefank@5202: static uintptr_t _young_generation_boundary_compressed; zgu@3900: static Stack _preserved_mark_stack; // List of marks to be restored after failed promotion zgu@3900: static Stack _preserved_oop_stack; // List of oops that need their mark restored. stefank@5202: static CollectorCounters* _counters; // collector performance counters duke@435: duke@435: static void clean_up_failed_promotion(); duke@435: duke@435: static bool should_attempt_scavenge(); duke@435: duke@435: static HeapWord* to_space_top_before_gc() { return _to_space_top_before_gc; } duke@435: static inline void save_to_space_top_before_gc(); duke@435: duke@435: // Private accessors duke@435: static CardTableExtension* const card_table() { assert(_card_table != NULL, "Sanity"); return _card_table; } duke@435: duke@435: public: duke@435: // Accessors jwilhelm@4129: static uint tenuring_threshold() { return _tenuring_threshold; } duke@435: static elapsedTimer* accumulated_time() { return &_accumulated_time; } duke@435: static int consecutive_skipped_scavenges() duke@435: { return _consecutive_skipped_scavenges; } duke@435: duke@435: // Performance Counters duke@435: static CollectorCounters* counters() { return _counters; } duke@435: duke@435: // Used by scavenge_contents && psMarkSweep duke@435: static ReferenceProcessor* const reference_processor() { duke@435: assert(_ref_processor != NULL, "Sanity"); duke@435: return _ref_processor; duke@435: } duke@435: // Used to add tasks duke@435: static GCTaskManager* const gc_task_manager(); duke@435: // The promotion managers tell us if they encountered overflow duke@435: static void set_survivor_overflow(bool state) { duke@435: _survivor_overflow = state; duke@435: } duke@435: // Adaptive size policy support. When the young generation/old generation duke@435: // boundary moves, _young_generation_boundary must be reset duke@435: static void set_young_generation_boundary(HeapWord* v) { duke@435: _young_generation_boundary = v; stefank@5202: if (UseCompressedOops) { stefank@5202: _young_generation_boundary_compressed = (uintptr_t)oopDesc::encode_heap_oop((oop)v); stefank@5202: } duke@435: } duke@435: duke@435: // Called by parallelScavengeHeap to init the tenuring threshold duke@435: static void initialize(); duke@435: jcoomes@3540: // Scavenge entry point. This may invoke a full gc; return true if so. jcoomes@3540: static bool invoke(); jcoomes@3540: // Return true if a collection was done; false otherwise. duke@435: static bool invoke_no_policy(); duke@435: duke@435: // If an attempt to promote fails, this method is invoked duke@435: static void oop_promotion_failed(oop obj, markOop obj_mark); duke@435: coleenp@548: template static inline bool should_scavenge(T* p); duke@435: duke@435: // These call should_scavenge() above and, if it returns true, also check that duke@435: // the object was not newly copied into to_space. The version with the bool duke@435: // argument is a convenience wrapper that fetches the to_space pointer from duke@435: // the heap and calls the other version (if the arg is true). coleenp@548: template static inline bool should_scavenge(T* p, MutableSpace* to_space); coleenp@548: template static inline bool should_scavenge(T* p, bool check_to_space); duke@435: iveresov@3536: template iveresov@3536: inline static void copy_and_push_safe_barrier(PSPromotionManager* pm, T* p); duke@435: coleenp@4037: static void copy_and_push_safe_barrier_from_klass(PSPromotionManager* pm, oop* p); coleenp@4037: duke@435: // Is an object in the young generation stefank@5202: // This assumes that the 'o' is in the heap, duke@435: // so it only checks one side of the complete predicate. stefank@5202: stefank@5202: inline static bool is_obj_in_young(oop o) { stefank@5202: return (HeapWord*)o >= _young_generation_boundary; stefank@5202: } stefank@5202: stefank@5202: inline static bool is_obj_in_young(narrowOop o) { stefank@5202: return (uintptr_t)o >= _young_generation_boundary_compressed; stefank@5202: } stefank@5202: duke@435: inline static bool is_obj_in_young(HeapWord* o) { stefank@5202: return o >= _young_generation_boundary; duke@435: } duke@435: }; stefank@2314: stefank@2314: #endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSSCAVENGE_HPP