• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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/ecma_vm.h"
17 #include "ecmascript/mem/barriers-inl.h"
18 #include "ecmascript/mem/heap.h"
19 
20 namespace panda::ecmascript {
Update(const JSThread * thread,uintptr_t slotAddr,Region * objectRegion,TaggedObject * value,Region * valueRegion,WriteBarrierType writeType)21 void Barriers::Update(const JSThread *thread, uintptr_t slotAddr, Region *objectRegion, TaggedObject *value,
22                       Region *valueRegion, WriteBarrierType writeType)
23 {
24     auto heap = thread->GetEcmaVM()->GetHeap();
25     if (heap->IsConcurrentFullMark()) {
26         if (valueRegion->InCollectSet() && !objectRegion->InYoungSpaceOrCSet()) {
27             objectRegion->AtomicInsertCrossRegionRSet(slotAddr);
28         }
29     } else {
30         if (!valueRegion->InYoungSpace()) {
31             return;
32         }
33     }
34 
35     // Weak ref record and concurrent mark record maybe conflict.
36     // This conflict is solved by keeping alive weak reference. A small amount of floating garbage may be added.
37     TaggedObject *heapValue = JSTaggedValue(value).GetHeapObject();
38     if (writeType != WriteBarrierType::DESERIALIZE && valueRegion->AtomicMark(heapValue)) {
39         heap->GetWorkManager()->Push(MAIN_THREAD_INDEX, heapValue, valueRegion);
40     }
41 }
42 
43 // For work deserialize, deserialize root object will be set to another object, however, this object may have been
44 // marked by concurrent mark, this may cause deserialize root object miss mark, this is to ensure the deserialize object
45 // will been marked
MarkAndPushForDeserialize(const JSThread * thread,TaggedObject * object)46 void Barriers::MarkAndPushForDeserialize(const JSThread *thread, TaggedObject *object)
47 {
48     auto heap = thread->GetEcmaVM()->GetHeap();
49     Region *valueRegion = Region::ObjectAddressToRange(object);
50     if ((heap->IsConcurrentFullMark() || valueRegion->InYoungSpace()) && valueRegion->AtomicMark(object)) {
51         heap->GetWorkManager()->Push(MAIN_THREAD_INDEX, object, valueRegion);
52     }
53 }
54 }  // namespace panda::ecmascript
55