1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef ECMASCRIPT_MEM_SHARED_HEAP_SHARED_FULL_GC_INL_H
17 #define ECMASCRIPT_MEM_SHARED_HEAP_SHARED_FULL_GC_INL_H
18
19 #include "ecmascript/mem/shared_heap/shared_full_gc.h"
20
21 namespace panda::ecmascript {
22
SharedFullGCMarkRootVisitor(SharedGCMovableMarker * marker,uint32_t threadId)23 SharedFullGCMarkRootVisitor::SharedFullGCMarkRootVisitor(SharedGCMovableMarker *marker, uint32_t threadId)
24 : marker_(marker), threadId_(threadId) {}
25
VisitRoot(Root type,ObjectSlot slot)26 void SharedFullGCMarkRootVisitor::VisitRoot([[maybe_unused]] Root type, ObjectSlot slot)
27 {
28 JSTaggedValue value(slot.GetTaggedType());
29 if (value.IsInSharedSweepableSpace()) {
30 ASSERT(!value.IsWeak());
31 marker_->MarkObject(threadId_, value.GetTaggedObject(), slot);
32 }
33 }
34
VisitRangeRoot(Root type,ObjectSlot start,ObjectSlot end)35 void SharedFullGCMarkRootVisitor::VisitRangeRoot([[maybe_unused]] Root type, ObjectSlot start, ObjectSlot end)
36 {
37 for (ObjectSlot slot = start; slot < end; slot++) {
38 JSTaggedValue value(slot.GetTaggedType());
39 if (value.IsInSharedSweepableSpace()) {
40 ASSERT(!value.IsWeak());
41 marker_->MarkObject(threadId_, value.GetTaggedObject(), slot);
42 }
43 }
44 }
45
VisitBaseAndDerivedRoot(Root type,ObjectSlot base,ObjectSlot derived,uintptr_t baseOldObject)46 void SharedFullGCMarkRootVisitor::VisitBaseAndDerivedRoot([[maybe_unused]] Root type, ObjectSlot base,
47 ObjectSlot derived, uintptr_t baseOldObject)
48 {
49 if (JSTaggedValue(base.GetTaggedType()).IsHeapObject()) {
50 derived.Update(base.GetTaggedType() + derived.GetTaggedType() - baseOldObject);
51 }
52 }
53
MarkObject(TaggedObject * object)54 void SharedFullGCMarkRootVisitor::MarkObject([[maybe_unused]] TaggedObject *object)
55 {
56 UNREACHABLE();
57 }
58
SharedFullGCMarkObjectVisitor(SharedGCMovableMarker * marker,uint32_t threadId)59 SharedFullGCMarkObjectVisitor::SharedFullGCMarkObjectVisitor(SharedGCMovableMarker *marker, uint32_t threadId)
60 : marker_(marker), threadId_(threadId) {}
61
VisitObjectRangeImpl(TaggedObject * root,ObjectSlot start,ObjectSlot end,VisitObjectArea area)62 void SharedFullGCMarkObjectVisitor::VisitObjectRangeImpl(TaggedObject *root, ObjectSlot start, ObjectSlot end,
63 VisitObjectArea area)
64 {
65 if (UNLIKELY(area == VisitObjectArea::IN_OBJECT)) {
66 JSHClass *hclass = root->SynchronizedGetClass();
67 ASSERT(!hclass->IsAllTaggedProp());
68 int index = 0;
69 LayoutInfo *layout = LayoutInfo::UncheckCast(hclass->GetLayout().GetTaggedObject());
70 ObjectSlot realEnd = start;
71 realEnd += layout->GetPropertiesCapacity();
72 end = end > realEnd ? realEnd : end;
73 for (ObjectSlot slot = start; slot < end; slot++) {
74 PropertyAttributes attr = layout->GetAttr(index++);
75 if (attr.IsTaggedRep()) {
76 marker_->MarkValue(threadId_, slot);
77 }
78 }
79 return;
80 }
81 for (ObjectSlot slot = start; slot < end; slot++) {
82 marker_->MarkValue(threadId_, slot);
83 }
84 }
85
VisitObjectHClassImpl(TaggedObject * hclass)86 void SharedFullGCMarkObjectVisitor::VisitObjectHClassImpl([[maybe_unused]] TaggedObject *hclass)
87 {
88 UNREACHABLE();
89 }
90
HandleSlot(ObjectSlot slot,Region * rootRegion,bool rootNeedEvacuate)91 void SharedFullGCMarkObjectVisitor::HandleSlot([[maybe_unused]] ObjectSlot slot, [[maybe_unused]] Region *rootRegion,
92 [[maybe_unused]] bool rootNeedEvacuate)
93 {
94 UNREACHABLE();
95 }
96
MarkAndPush(TaggedObject * object,Region * objectRegion)97 void SharedFullGCMarkObjectVisitor::MarkAndPush([[maybe_unused]] TaggedObject *object,
98 [[maybe_unused]] Region *objectRegion)
99 {
100 UNREACHABLE();
101 }
102 } // namespace panda::ecmascript
103 #endif // ECMASCRIPT_MEM_SHARED_HEAP_SHARED_FULL_GC_INL_H