• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "src/heap/heap-write-barrier.h"
6 
7 #include "src/heap/heap-write-barrier-inl.h"
8 #include "src/heap/marking-barrier.h"
9 #include "src/objects/descriptor-array.h"
10 #include "src/objects/maybe-object.h"
11 #include "src/objects/slots-inl.h"
12 #include "src/objects/slots.h"
13 
14 namespace v8 {
15 namespace internal {
16 
17 namespace {
18 thread_local MarkingBarrier* current_marking_barrier = nullptr;
19 }  // namespace
20 
SetForThread(MarkingBarrier * marking_barrier)21 void WriteBarrier::SetForThread(MarkingBarrier* marking_barrier) {
22   DCHECK_NULL(current_marking_barrier);
23   current_marking_barrier = marking_barrier;
24 }
25 
ClearForThread(MarkingBarrier * marking_barrier)26 void WriteBarrier::ClearForThread(MarkingBarrier* marking_barrier) {
27   DCHECK_EQ(current_marking_barrier, marking_barrier);
28   current_marking_barrier = nullptr;
29 }
30 
MarkingSlow(Heap * heap,HeapObject host,HeapObjectSlot slot,HeapObject value)31 void WriteBarrier::MarkingSlow(Heap* heap, HeapObject host, HeapObjectSlot slot,
32                                HeapObject value) {
33   MarkingBarrier* marking_barrier = current_marking_barrier
34                                         ? current_marking_barrier
35                                         : heap->marking_barrier();
36   marking_barrier->Write(host, slot, value);
37 }
38 
MarkingSlow(Heap * heap,Code host,RelocInfo * reloc_info,HeapObject value)39 void WriteBarrier::MarkingSlow(Heap* heap, Code host, RelocInfo* reloc_info,
40                                HeapObject value) {
41   MarkingBarrier* marking_barrier = current_marking_barrier
42                                         ? current_marking_barrier
43                                         : heap->marking_barrier();
44   marking_barrier->Write(host, reloc_info, value);
45 }
46 
MarkingSlow(Heap * heap,JSArrayBuffer host,ArrayBufferExtension * extension)47 void WriteBarrier::MarkingSlow(Heap* heap, JSArrayBuffer host,
48                                ArrayBufferExtension* extension) {
49   MarkingBarrier* marking_barrier = current_marking_barrier
50                                         ? current_marking_barrier
51                                         : heap->marking_barrier();
52   marking_barrier->Write(host, extension);
53 }
54 
MarkingSlow(Heap * heap,DescriptorArray descriptor_array,int number_of_own_descriptors)55 void WriteBarrier::MarkingSlow(Heap* heap, DescriptorArray descriptor_array,
56                                int number_of_own_descriptors) {
57   MarkingBarrier* marking_barrier = current_marking_barrier
58                                         ? current_marking_barrier
59                                         : heap->marking_barrier();
60   marking_barrier->Write(descriptor_array, number_of_own_descriptors);
61 }
62 
MarkingFromCode(Address raw_host,Address raw_slot)63 int WriteBarrier::MarkingFromCode(Address raw_host, Address raw_slot) {
64   HeapObject host = HeapObject::cast(Object(raw_host));
65   MaybeObjectSlot slot(raw_slot);
66   WriteBarrier::Marking(host, slot, *slot);
67   // Called by RecordWriteCodeStubAssembler, which doesnt accept void type
68   return 0;
69 }
70 
71 }  // namespace internal
72 }  // namespace v8
73