• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_PARALLEL_EVACUATOR_VISITOR_INL_H
17 #define ECMASCRIPT_MEM_PARALLEL_EVACUATOR_VISITOR_INL_H
18 
19 #include "ecmascript/mem/parallel_evacuator_visitor.h"
20 
21 namespace panda::ecmascript {
22 
23 template<TriggerGCType gcType>
SlotUpdateRangeVisitor(ParallelEvacuator * evacuator)24 SlotUpdateRangeVisitor<gcType>::SlotUpdateRangeVisitor(ParallelEvacuator *evacuator) : evacuator_(evacuator) {}
25 
26 template<TriggerGCType gcType>
VisitObjectRangeImpl(TaggedObject * root,ObjectSlot start,ObjectSlot end,VisitObjectArea area)27 void SlotUpdateRangeVisitor<gcType>::VisitObjectRangeImpl(TaggedObject *root, ObjectSlot start, ObjectSlot end,
28                                                           VisitObjectArea area)
29 {
30     Region *rootRegion = Region::ObjectAddressToRange(root);
31     if (UNLIKELY(area == VisitObjectArea::IN_OBJECT)) {
32         JSHClass *hclass = root->SynchronizedGetClass();
33         ASSERT(!hclass->IsAllTaggedProp());
34         int index = 0;
35         LayoutInfo *layout = LayoutInfo::UncheckCast(hclass->GetLayout().GetTaggedObject());
36         ObjectSlot realEnd = start;
37         realEnd += layout->GetPropertiesCapacity();
38         end = end > realEnd ? realEnd : end;
39         for (ObjectSlot slot = start; slot < end; slot++) {
40             PropertyAttributes attr = layout->GetAttr(index++);
41             if (attr.IsTaggedRep()) {
42                 UpdateSlot(slot, rootRegion);
43             }
44         }
45         return;
46     }
47     for (ObjectSlot slot = start; slot < end; slot++) {
48         UpdateSlot(slot, rootRegion);
49     }
50 }
51 
52 template<TriggerGCType gcType>
UpdateSlot(ObjectSlot slot,Region * rootRegion)53 void SlotUpdateRangeVisitor<gcType>::UpdateSlot(ObjectSlot slot, Region *rootRegion)
54 {
55     evacuator_->UpdateNewObjectSlot<gcType, false>(slot);
56     JSTaggedValue value(slot.GetTaggedType());
57     if (!value.IsHeapObject()) {
58         return;
59     }
60     Region *valueRegion = Region::ObjectAddressToRange(slot.GetTaggedObject());
61     if (valueRegion->InYoungSpace()) {
62         rootRegion->InsertOldToNewRSet(slot.SlotAddress());
63     }
64 }
65 
66 template<TriggerGCType gcType>
NewToOldEvacuationVisitor(Heap * heap,std::unordered_set<JSTaggedType> * set,ParallelEvacuator * evacuator)67 NewToOldEvacuationVisitor<gcType>::NewToOldEvacuationVisitor(Heap *heap, std::unordered_set<JSTaggedType> *set,
68     ParallelEvacuator *evacuator) : pgoEnabled_(heap->GetJSThread()->IsPGOProfilerEnable()),
69     pgoProfiler_(heap->GetEcmaVM()->GetPGOProfiler()), trackSet_(set), slotUpdateRangeVisitor_(evacuator) {}
70 
71 template<TriggerGCType gcType>
operator()72 void NewToOldEvacuationVisitor<gcType>::operator()(void *mem)
73 {
74     auto object = reinterpret_cast<TaggedObject *>(mem);
75     JSHClass *klass = object->GetClass();
76     ObjectXRay::VisitObjectBody<VisitType::OLD_GC_VISIT>(object, klass, slotUpdateRangeVisitor_);
77     if (pgoEnabled_) {
78         UpdateTrackInfo(object, klass);
79     }
80 }
81 
82 template<TriggerGCType gcType>
UpdateTrackInfo(TaggedObject * header,JSHClass * klass)83 void NewToOldEvacuationVisitor<gcType>::UpdateTrackInfo(TaggedObject *header, JSHClass *klass)
84 {
85     if (klass->IsJSArray()) {
86         auto trackInfo = JSArray::Cast(header)->GetTrackInfo();
87         trackSet_->emplace(trackInfo.GetRawData());
88     }
89 }
90 }  // namespace panda::ecmascript
91 #endif  // ECMASCRIPT_MEM_PARALLEL_EVACUATOR_VISITOR_INL_H