1 // Copyright 2016 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 #ifndef V8_HEAP_REMEMBERED_SET_INL_H_
6 #define V8_HEAP_REMEMBERED_SET_INL_H_
7
8 #include "src/common/ptr-compr-inl.h"
9 #include "src/heap/remembered-set.h"
10
11 namespace v8 {
12 namespace internal {
13
14 template <typename Callback>
UpdateTypedSlot(Heap * heap,SlotType slot_type,Address addr,Callback callback)15 SlotCallbackResult UpdateTypedSlotHelper::UpdateTypedSlot(Heap* heap,
16 SlotType slot_type,
17 Address addr,
18 Callback callback) {
19 switch (slot_type) {
20 case CODE_TARGET_SLOT: {
21 RelocInfo rinfo(addr, RelocInfo::CODE_TARGET, 0, Code());
22 return UpdateCodeTarget(&rinfo, callback);
23 }
24 case CODE_ENTRY_SLOT: {
25 return UpdateCodeEntry(addr, callback);
26 }
27 case COMPRESSED_EMBEDDED_OBJECT_SLOT: {
28 RelocInfo rinfo(addr, RelocInfo::COMPRESSED_EMBEDDED_OBJECT, 0, Code());
29 return UpdateEmbeddedPointer(heap, &rinfo, callback);
30 }
31 case FULL_EMBEDDED_OBJECT_SLOT: {
32 RelocInfo rinfo(addr, RelocInfo::FULL_EMBEDDED_OBJECT, 0, Code());
33 return UpdateEmbeddedPointer(heap, &rinfo, callback);
34 }
35 case COMPRESSED_OBJECT_SLOT: {
36 HeapObject old_target = HeapObject::cast(Object(
37 DecompressTaggedAny(heap->isolate(), base::Memory<Tagged_t>(addr))));
38 HeapObject new_target = old_target;
39 SlotCallbackResult result = callback(FullMaybeObjectSlot(&new_target));
40 DCHECK(!HasWeakHeapObjectTag(new_target));
41 if (new_target != old_target) {
42 base::Memory<Tagged_t>(addr) = CompressTagged(new_target.ptr());
43 }
44 return result;
45 }
46 case FULL_OBJECT_SLOT: {
47 return callback(FullMaybeObjectSlot(addr));
48 }
49 case CLEARED_SLOT:
50 break;
51 }
52 UNREACHABLE();
53 }
54
55 } // namespace internal
56 } // namespace v8
57 #endif // V8_HEAP_REMEMBERED_SET_INL_H_
58