• 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(uintptr_t slotAddr,Region * objectRegion,TaggedObject * value,Region * valueRegion)21 void Barriers::Update(uintptr_t slotAddr, Region *objectRegion, TaggedObject *value, Region *valueRegion)
22 {
23     JSThread* thread = valueRegion->GetJSThread();
24     auto heap = thread->GetEcmaVM()->GetHeap();
25     if (heap->IsFullMark()) {
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 (valueRegion->AtomicMark(heapValue)) {
39         heap->GetWorkManager()->Push(0, heapValue, valueRegion);
40     }
41 }
42 }  // namespace panda::ecmascript
43