1 /*
2 * Copyright (c) 2025 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 #include "ecmascript/cross_vm/js_tagged_value_hybrid-inl.h"
17 #include "ecmascript/mem/dynamic_object_operator.h"
18 #include "ecmascript/mem/object_xray.h"
19
20 namespace panda::ecmascript {
21
22 DynamicObjectOperator DynamicObjectOperator::dynOperator_;
23
Initialize()24 void DynamicObjectOperator::Initialize()
25 {
26 if (g_isEnableCMCGC) {
27 BaseObject::RegisterDynamic(&dynOperator_);
28 }
29 }
30
VisitObjectRangeImpl(BaseObject * root,uintptr_t startAddr,uintptr_t endAddr,VisitObjectArea area)31 void RefFieldObjectVisitor::VisitObjectRangeImpl(BaseObject *root, uintptr_t startAddr,
32 uintptr_t endAddr, VisitObjectArea area)
33 {
34 ObjectSlot start(startAddr);
35 ObjectSlot end(endAddr);
36 if (UNLIKELY(area == VisitObjectArea::IN_OBJECT)) {
37 VisitBodyInObj(TaggedObject::Cast(root), start, end, [this](ObjectSlot slot) {
38 visit(slot);
39 });
40 return;
41 }
42 for (ObjectSlot slot = start; slot < end; slot++) {
43 visit(slot);
44 }
45 }
46
VisitObjectHClassImpl(BaseObject * hclass)47 void RefFieldObjectVisitor::VisitObjectHClassImpl(BaseObject *hclass)
48 {
49 JSTaggedValue clz(reinterpret_cast<TaggedObject *>(hclass));
50 visitor_(reinterpret_cast<common::RefField<>&>(clz));
51 }
52
VisitAllRefFields(TaggedObject * obj)53 void RefFieldObjectVisitor::VisitAllRefFields(TaggedObject *obj)
54 {
55 // Note this will update the stack param, not the slot of object hclass
56 // But sinc hclass in non-movable, so current all visitor will not update hlass field, so it's ok
57 VisitObjectHClassImpl(obj->GetClass());
58 ObjectXRay::VisitObjectBody<VisitType::OLD_GC_VISIT>(obj, obj->GetClass(), *this);
59 }
60
visit(ObjectSlot slot)61 void RefFieldObjectVisitor::visit(ObjectSlot slot)
62 {
63 if (!slot.GetTaggedValue().IsHeapObject()) {
64 return;
65 }
66 visitor_(reinterpret_cast<common::RefField<>&>(*(slot.GetRefFieldAddr())));
67 }
68
69 } // namespace panda::ecmascript
70