1 /*
 2  * Copyright (c) 2016, 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_PARALLEL_PSPARALLELCOMPACT_INLINE_HPP
26 #define SHARE_GC_PARALLEL_PSPARALLELCOMPACT_INLINE_HPP
27 
28 #include "gc/parallel/psParallelCompact.hpp"
29 
30 #include "gc/parallel/parallelScavengeHeap.hpp"
31 #include "gc/parallel/parMarkBitMap.inline.hpp"
32 #include "gc/shared/collectedHeap.hpp"
33 #include "gc/shared/continuationGCSupport.inline.hpp"
34 #include "gc/shared/slidingForwarding.inline.hpp"
35 #include "oops/access.inline.hpp"
36 #include "oops/compressedOops.inline.hpp"
37 #include "oops/klass.hpp"
38 #include "oops/oop.inline.hpp"
39 
40 inline bool PSParallelCompact::is_marked(oop obj) {
41   return mark_bitmap()->is_marked(obj);
42 }
43 
44 inline MutableSpace* PSParallelCompact::space(SpaceId id) {
45   assert(id < last_space_id, "id out of range");
46   return _space_info[id].space();
47 }
48 
49 inline HeapWord* PSParallelCompact::new_top(SpaceId id) {
50   assert(id < last_space_id, "id out of range");
51   return _space_info[id].new_top();
52 }
53 
54 inline HeapWord* PSParallelCompact::dense_prefix(SpaceId id) {
55   assert(id < last_space_id, "id out of range");
56   return _space_info[id].dense_prefix();
57 }
58 
59 inline ObjectStartArray* PSParallelCompact::start_array(SpaceId id) {
60   assert(id < last_space_id, "id out of range");
61   return _space_info[id].start_array();
62 }
63 
64 #ifdef ASSERT
65 inline void PSParallelCompact::check_new_location(HeapWord* old_addr, HeapWord* new_addr) {
66   assert(old_addr >= new_addr || space_id(old_addr) != space_id(new_addr),
67          "must move left or to a different space");
68   assert(is_object_aligned(old_addr) && is_object_aligned(new_addr),
69          "checking alignment");
70 }
71 #endif // ASSERT
72 
73 template <class T>
74 inline void PSParallelCompact::adjust_pointer(T* p) {
75   T heap_oop = RawAccess<>::oop_load(p);
76   if (!CompressedOops::is_null(heap_oop)) {
77     oop obj = CompressedOops::decode_not_null(heap_oop);
78     assert(ParallelScavengeHeap::heap()->is_in(obj), "should be in heap");
79 
80     if (!obj->is_forwarded()) {
81       return;
82     }
83     oop new_obj = SlidingForwarding::forwardee(obj);
84     assert(new_obj != nullptr, "non-null address for live objects");
85     assert(new_obj != obj, "inv");
86     assert(ParallelScavengeHeap::heap()->is_in_reserved(new_obj),
87            "should be in object space");
88     RawAccess<IS_NOT_NULL>::oop_store(p, new_obj);
89   }
90 }
91 
92 #endif // SHARE_GC_PARALLEL_PSPARALLELCOMPACT_INLINE_HPP