1 /* 2 * Copyright (c) 2022, 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_INLINE_HPP 26 #define SHARE_GC_G1_G1FULLGCPREPARETASK_INLINE_HPP 27 28 #include "gc/g1/g1FullGCPrepareTask.hpp" 29 30 #include "gc/g1/g1CollectedHeap.inline.hpp" 31 #include "gc/g1/g1FullCollector.hpp" 32 #include "gc/g1/g1FullGCCompactionPoint.hpp" 33 #include "gc/g1/g1FullGCScope.hpp" 34 #include "gc/g1/heapRegion.inline.hpp" 35 36 template<bool is_humongous> 37 void G1DetermineCompactionQueueClosure::free_pinned_region(HeapRegion* hr) { 38 if (is_humongous) { 39 _g1h->free_humongous_region(hr, nullptr); 40 } else { 41 _g1h->free_region(hr, nullptr); 42 } 43 _collector->set_free(hr->hrm_index()); 44 add_to_compaction_queue(hr); 45 } 46 47 inline bool G1DetermineCompactionQueueClosure::should_compact(HeapRegion* hr) const { 48 // There is no need to iterate and forward objects in pinned regions ie. 49 // prepare them for compaction. 50 if (hr->is_pinned()) { 51 return false; 52 } 53 size_t live_words = _collector->live_words(hr->hrm_index()); 54 size_t live_words_threshold = _collector->scope()->region_compaction_threshold(); 55 // High live ratio region will not be compacted. 56 return live_words <= live_words_threshold; 57 } 58 59 inline uint G1DetermineCompactionQueueClosure::next_worker() { 60 uint result = _cur_worker; 61 _cur_worker = (_cur_worker + 1) % _collector->workers(); 62 return result; 63 } 64 65 inline G1FullGCCompactionPoint* G1DetermineCompactionQueueClosure::next_compaction_point() { 66 return _collector->compaction_point(next_worker()); 67 } 68 69 inline void G1DetermineCompactionQueueClosure::add_to_compaction_queue(HeapRegion* hr) { 70 hr->set_compaction_top(hr->bottom()); 71 G1FullGCCompactionPoint* cp = next_compaction_point(); 72 if (!cp->is_initialized()) { 73 cp->initialize(hr); 74 } 75 // Add region to the compaction queue. 76 cp->add(hr); 77 } 78 79 inline bool G1DetermineCompactionQueueClosure::do_heap_region(HeapRegion* hr) { 80 if (should_compact(hr)) { 81 assert(!hr->is_humongous(), "moving humongous objects not supported."); 82 add_to_compaction_queue(hr); 83 } else { 84 assert(hr->containing_set() == nullptr, "already cleared by PrepareRegionsClosure"); 85 if (hr->is_humongous()) { 86 oop obj = cast_to_oop(hr->humongous_start_region()->bottom()); 87 bool is_empty = !_collector->mark_bitmap()->is_marked(obj); 88 if (is_empty) { 89 free_pinned_region<true>(hr); 90 } 91 } else if (hr->is_open_archive()) { 92 bool is_empty = _collector->live_words(hr->hrm_index()) == 0; 93 if (is_empty) { 94 free_pinned_region<false>(hr); 95 } 96 } else if (hr->is_closed_archive()) { 97 // nothing to do with closed archive region 98 } else { 99 assert(MarkSweepDeadRatio > 0, 100 "only skip compaction for other regions when MarkSweepDeadRatio > 0"); 101 102 // Too many live objects in the region; skip compacting it. 103 _collector->update_from_compacting_to_skip_compacting(hr->hrm_index()); 104 log_trace(gc, phases)("Phase 2: skip compaction region index: %u, live words: " SIZE_FORMAT, 105 hr->hrm_index(), _collector->live_words(hr->hrm_index())); 106 } 107 } 108 109 return false; 110 } 111 112 //inline size_t G1SerialRePrepareClosure::apply(oop obj) { 113 // // We only re-prepare objects forwarded within the current region, so 114 // // skip objects that are already forwarded to another region. 115 // if (obj->is_forwarded() && !_current->is_in(obj->forwardee())) { 116 // return obj->size(); 117 // } 118 // 119 // // Get size and forward. 120 // size_t size = obj->size(); 121 // _cp->forward(obj, size); 122 // 123 // return size; 124 //} 125 126 #endif // SHARE_GC_G1_G1FULLGCPREPARETASK_INLINE_HPP