1 /*
  2  * Copyright (c) 2017, 2026, 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_G1FULLGCMARKER_INLINE_HPP
 26 #define SHARE_GC_G1_G1FULLGCMARKER_INLINE_HPP
 27 
 28 #include "gc/g1/g1FullGCMarker.hpp"
 29 
 30 #include "classfile/classLoaderData.hpp"
 31 #include "classfile/javaClasses.inline.hpp"
 32 #include "gc/g1/g1Allocator.inline.hpp"
 33 #include "gc/g1/g1ConcurrentMarkBitMap.inline.hpp"
 34 #include "gc/g1/g1FullCollector.inline.hpp"
 35 #include "gc/g1/g1FullGCOopClosures.inline.hpp"
 36 #include "gc/g1/g1OopClosures.inline.hpp"
 37 #include "gc/g1/g1RegionMarkStatsCache.hpp"
 38 #include "gc/g1/g1StringDedup.hpp"
 39 #include "gc/shared/continuationGCSupport.inline.hpp"
 40 #include "gc/shared/preservedMarks.inline.hpp"
 41 #include "gc/shared/stringdedup/stringDedup.hpp"
 42 #include "oops/access.inline.hpp"
 43 #include "oops/compressedOops.inline.hpp"
 44 #include "oops/oop.inline.hpp"
 45 #include "utilities/checkedCast.hpp"
 46 #include "utilities/debug.hpp"
 47 
 48 inline bool G1FullGCMarker::mark_object(oop obj) {
 49   // Try to mark.
 50   if (!_bitmap->par_mark(obj)) {
 51     // Lost mark race.
 52     return false;
 53   }
 54 
 55   // Check if deduplicatable string.
 56   if (StringDedup::is_enabled() &&
 57       java_lang_String::is_instance(obj) &&
 58       G1StringDedup::is_candidate_from_mark(obj)) {
 59     _string_dedup_requests.add(obj);
 60   }
 61 
 62   ContinuationGCSupport::transform_stack_chunk(obj);
 63 
 64   // Collect live words.
 65   _mark_stats_cache.add_live_words(obj);
 66 
 67   return true;
 68 }
 69 
 70 template <class T> inline void G1FullGCMarker::mark_and_push(T* p) {
 71   T heap_oop = RawAccess<>::oop_load(p);
 72   if (!CompressedOops::is_null(heap_oop)) {
 73     oop obj = CompressedOops::decode_not_null(heap_oop);
 74     if (mark_object(obj)) {
 75       _task_queue.push(ScannerTask(obj));
 76     }
 77     assert(_bitmap->is_marked(obj), "Must be marked");
 78   }
 79 }
 80 
 81 inline bool G1FullGCMarker::is_task_queue_empty() {
 82   return _task_queue.is_empty();
 83 }
 84 
 85 inline void G1FullGCMarker::process_array_chunk(objArrayOop obj, size_t start, size_t end) {
 86   obj->oop_iterate_elements_range(mark_closure(),
 87                                   checked_cast<int>(start),
 88                                   checked_cast<int>(end));
 89 }
 90 
 91 inline void G1FullGCMarker::dispatch_task(const ScannerTask& task, bool stolen) {
 92   if (task.is_partial_array_state()) {
 93     assert(_bitmap->is_marked(task.to_partial_array_state()->source()), "should be marked");
 94     process_partial_array(task.to_partial_array_state(), stolen);
 95   } else {
 96     oop obj = task.to_oop();
 97     assert(_bitmap->is_marked(obj), "should be marked");
 98     if (obj->is_objArray()) {
 99       // Handle object arrays explicitly to allow them to
100       // be split into chunks if needed.
101       start_partial_array_processing((objArrayOop)obj);
102     } else {
103       obj->oop_iterate(mark_closure());
104     }
105   }
106 }
107 
108 inline void G1FullGCMarker::publish_and_drain_oop_tasks() {
109   ScannerTask task;
110   while (_task_queue.pop_overflow(task)) {
111     if (!_task_queue.try_push_to_taskqueue(task)) {
112       dispatch_task(task, false);
113     }
114   }
115   while (_task_queue.pop_local(task)) {
116     dispatch_task(task, false);
117   }
118 }
119 
120 void G1FullGCMarker::process_marking_stacks() {
121   do {
122     publish_and_drain_oop_tasks();
123   } while (!is_task_queue_empty());
124 }
125 
126 #endif // SHARE_GC_G1_G1FULLGCMARKER_INLINE_HPP