1 /* 2 * Copyright (c) 2017, 2023, 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_GC_G1_G1FULLGCPREPARETASK_HPP 26 #define SHARE_GC_G1_G1FULLGCPREPARETASK_HPP 27 28 #include "gc/g1/g1FullGCTask.hpp" 29 #include "gc/g1/heapRegion.hpp" 30 #include "memory/allocation.hpp" 31 32 class G1CollectedHeap; 33 class G1CMBitMap; 34 class G1FullCollector; 35 class SlidingForwarding; 36 class G1FullGCCompactionPoint; 37 class HeapRegion; 38 39 // Determines the regions in the heap that should be part of the compaction and 40 // distributes them among the compaction queues in round-robin fashion. 41 class G1DetermineCompactionQueueClosure : public HeapRegionClosure { 42 G1CollectedHeap* _g1h; 43 G1FullCollector* _collector; 44 uint _cur_worker; 45 46 template<bool is_humongous> 47 inline void free_pinned_region(HeapRegion* hr); 48 49 inline bool should_compact(HeapRegion* hr) const; 50 51 // Returns the current worker id to assign a compaction point to, and selects 52 // the next one round-robin style. 53 inline uint next_worker(); 54 55 inline G1FullGCCompactionPoint* next_compaction_point(); 56 57 inline void add_to_compaction_queue(HeapRegion* hr); 58 59 public: 60 G1DetermineCompactionQueueClosure(G1FullCollector* collector); 61 62 inline bool do_heap_region(HeapRegion* hr) override; 63 }; 64 65 class G1FullGCPrepareTask : public G1FullGCTask { 66 volatile bool _has_free_compaction_targets; 67 HeapRegionClaimer _hrclaimer; 68 69 void set_has_free_compaction_targets(); 70 71 public: 72 G1FullGCPrepareTask(G1FullCollector* collector); 73 void work(uint worker_id); 74 // After the Prepare phase, are there any unused (empty) regions (compaction 75 // targets) at the end of any compaction queues? 76 bool has_free_compaction_targets(); 77 78 private: 79 class G1CalculatePointersClosure : public HeapRegionClosure { 80 G1CollectedHeap* _g1h; 81 G1FullCollector* _collector; 82 G1CMBitMap* _bitmap; 83 G1FullGCCompactionPoint* _cp; 84 85 void prepare_for_compaction(HeapRegion* hr); 86 87 public: 88 G1CalculatePointersClosure(G1FullCollector* collector, 89 G1FullGCCompactionPoint* cp); 90 91 bool do_heap_region(HeapRegion* hr); 92 }; 93 94 class G1PrepareCompactLiveClosure : public StackObj { 95 G1FullGCCompactionPoint* _cp; 96 SlidingForwarding* const _forwarding; 97 98 public: 99 G1PrepareCompactLiveClosure(G1FullGCCompactionPoint* cp); 100 size_t apply(oop object); 101 }; 102 }; 103 104 // Closure to re-prepare objects in the serial compaction point queue regions for 105 // serial compaction. 106 //class G1SerialRePrepareClosure : public StackObj { 107 // G1FullGCCompactionPoint* _cp; 108 // HeapWord* _dense_prefix_top; 109 // 110 //public: 111 // G1SerialRePrepareClosure(G1FullGCCompactionPoint* hrcp, HeapWord* dense_prefix_top) : 112 // _cp(hrcp), 113 // _dense_prefix_top(dense_prefix_top) { } 114 // 115 // inline size_t apply(oop obj); 116 //}; 117 118 #endif // SHARE_GC_G1_G1FULLGCPREPARETASK_HPP