1 /*
2 * Copyright (c) 2010, 2024, Oracle and/or its affiliates. All rights reserved.
3 * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26 #ifndef SHARE_GC_PARALLEL_PSCOMPACTIONMANAGERNEW_INLINE_HPP
27 #define SHARE_GC_PARALLEL_PSCOMPACTIONMANAGERNEW_INLINE_HPP
28
29 #include "gc/parallel/psCompactionManagerNew.hpp"
30
31 #include "classfile/classLoaderData.hpp"
32 #include "classfile/javaClasses.inline.hpp"
33 #include "gc/parallel/parMarkBitMap.hpp"
34 #include "gc/parallel/psParallelCompactNew.inline.hpp"
35 #include "gc/parallel/psStringDedup.hpp"
36 #include "gc/shared/partialArrayState.hpp"
37 #include "gc/shared/partialArrayTaskStepper.inline.hpp"
38 #include "gc/shared/taskqueue.inline.hpp"
39 #include "oops/access.inline.hpp"
40 #include "oops/arrayOop.hpp"
41 #include "oops/compressedOops.inline.hpp"
42 #include "oops/objArrayOop.inline.hpp"
43 #include "oops/oop.inline.hpp"
44 #include "utilities/debug.hpp"
45 #include "utilities/globalDefinitions.hpp"
46
47 template <typename T>
48 inline void PCMarkAndPushClosureNew::do_oop_work(T* p) {
49 _compaction_manager->mark_and_push(p);
50 }
51
52 inline bool ParCompactionManagerNew::steal(uint queue_num, ScannerTask& t) {
53 return marking_stacks()->steal(queue_num, t);
54 }
55
56 inline void ParCompactionManagerNew::push(oop obj) {
57 marking_stack()->push(ScannerTask(obj));
58 }
59
60 inline void ParCompactionManagerNew::push(PartialArrayState* stat) {
61 marking_stack()->push(ScannerTask(stat));
62 }
63
64 template <typename T>
65 inline void ParCompactionManagerNew::mark_and_push(T* p) {
66 T heap_oop = RawAccess<>::oop_load(p);
67 if (!CompressedOops::is_null(heap_oop)) {
68 oop obj = CompressedOops::decode_not_null(heap_oop);
69 assert(ParallelScavengeHeap::heap()->is_in(obj), "should be in heap");
70
71 if (mark_bitmap()->mark_obj(obj)) {
72 if (StringDedup::is_enabled() &&
73 java_lang_String::is_instance(obj) &&
74 psStringDedup::is_candidate_from_mark(obj)) {
75 _string_dedup_requests.add(obj);
76 }
77
78 ContinuationGCSupport::transform_stack_chunk(obj);
79 push(obj);
80 }
81 }
82 }
83
84 inline void ParCompactionManagerNew::FollowStackClosure::do_void() {
85 _compaction_manager->follow_marking_stacks();
86 if (_terminator != nullptr) {
87 steal_marking_work_new(*_terminator, _worker_id);
88 }
89 }
90
91 template <typename T>
92 inline void follow_array_specialized(objArrayOop obj, size_t start, size_t end, ParCompactionManagerNew* cm) {
93 assert(start <= end, "invariant");
94 T* const base = (T*)obj->base();
95 T* const beg = base + start;
96 T* const chunk_end = base + end;
97
98 // Push the non-null elements of the next stride on the marking stack.
99 for (T* e = beg; e < chunk_end; e++) {
100 cm->mark_and_push<T>(e);
101 }
102 }
103
104 inline void ParCompactionManagerNew::follow_array(objArrayOop obj, size_t start, size_t end) {
105 if (UseCompressedOops) {
106 follow_array_specialized<narrowOop>(obj, start, end, this);
107 } else {
108 follow_array_specialized<oop>(obj, start, end, this);
109 }
110 }
111
112 inline void ParCompactionManagerNew::follow_contents(const ScannerTask& task, bool stolen) {
113 if (task.is_partial_array_state()) {
114 assert(PSParallelCompactNew::mark_bitmap()->is_marked(task.to_partial_array_state()->source()), "should be marked");
115 process_array_chunk(task.to_partial_array_state(), stolen);
116 } else {
117 oop obj = task.to_oop();
118 assert(PSParallelCompactNew::mark_bitmap()->is_marked(obj), "should be marked");
119 if (obj->is_objArray()) {
120 push_objArray(obj);
121 } else {
122 obj->oop_iterate(&_mark_and_push_closure);
123 }
124 }
125 }
126
127 #endif // SHARE_GC_PARALLEL_PSCOMPACTIONMANAGERNEW_INLINE_HPP