• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 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_OBJECTS_TAGGED_FIELD_H_
6 #define V8_OBJECTS_TAGGED_FIELD_H_
7 
8 #include "src/common/globals.h"
9 
10 #include "src/objects/objects.h"
11 #include "src/objects/tagged-value.h"
12 
13 namespace v8 {
14 namespace internal {
15 
16 // This helper static class represents a tagged field of type T at offset
17 // kFieldOffset inside some host HeapObject.
18 // For full-pointer mode this type adds no overhead but when pointer
19 // compression is enabled such class allows us to use proper decompression
20 // function depending on the field type.
21 template <typename T, int kFieldOffset = 0>
22 class TaggedField : public AllStatic {
23  public:
24   static_assert(std::is_base_of<Object, T>::value ||
25                     std::is_same<MapWord, T>::value ||
26                     std::is_same<MaybeObject, T>::value,
27                 "T must be strong or weak tagged type or MapWord");
28 
29   // True for Smi fields.
30   static constexpr bool kIsSmi = std::is_base_of<Smi, T>::value;
31 
32   // True for HeapObject and MapWord fields. The latter may look like a Smi
33   // if it contains forwarding pointer but still requires tagged pointer
34   // decompression.
35   static constexpr bool kIsHeapObject =
36       std::is_base_of<HeapObject, T>::value || std::is_same<MapWord, T>::value;
37 
38   static inline Address address(HeapObject host, int offset = 0);
39 
40   static inline T load(HeapObject host, int offset = 0);
41   static inline T load(PtrComprCageBase cage_base, HeapObject host,
42                        int offset = 0);
43 
44   static inline void store(HeapObject host, T value);
45   static inline void store(HeapObject host, int offset, T value);
46 
47   static inline T Relaxed_Load(HeapObject host, int offset = 0);
48   static inline T Relaxed_Load(PtrComprCageBase cage_base, HeapObject host,
49                                int offset = 0);
50 
51   static inline void Relaxed_Store(HeapObject host, T value);
52   static void Relaxed_Store(HeapObject host, int offset, T value);
53 
54   static inline T Acquire_Load(HeapObject host, int offset = 0);
55   static inline T Acquire_Load_No_Unpack(PtrComprCageBase cage_base,
56                                          HeapObject host, int offset = 0);
57   static inline T Acquire_Load(PtrComprCageBase cage_base, HeapObject host,
58                                int offset = 0);
59 
60   static inline T SeqCst_Load(HeapObject host, int offset = 0);
61   static inline T SeqCst_Load(PtrComprCageBase cage_base, HeapObject host,
62                               int offset = 0);
63 
64   static inline void Release_Store(HeapObject host, T value);
65   static inline void Release_Store(HeapObject host, int offset, T value);
66 
67   static inline void SeqCst_Store(HeapObject host, T value);
68   static inline void SeqCst_Store(HeapObject host, int offset, T value);
69 
70   static inline T SeqCst_Swap(HeapObject host, int offset, T value);
71   static inline T SeqCst_Swap(PtrComprCageBase cage_base, HeapObject host,
72                               int offset, T value);
73 
74   static inline Tagged_t Release_CompareAndSwap(HeapObject host, T old,
75                                                 T value);
76 
77   // Note: Use these *_Map_Word methods only when loading a MapWord from a
78   // MapField.
79   static inline T Relaxed_Load_Map_Word(PtrComprCageBase cage_base,
80                                         HeapObject host);
81   static inline void Relaxed_Store_Map_Word(HeapObject host, T value);
82   static inline void Release_Store_Map_Word(HeapObject host, T value);
83 
84  private:
85   static inline Tagged_t* location(HeapObject host, int offset = 0);
86 
87   template <typename TOnHeapAddress>
88   static inline Address tagged_to_full(TOnHeapAddress on_heap_addr,
89                                        Tagged_t tagged_value);
90 
91   static inline Tagged_t full_to_tagged(Address value);
92 };
93 
94 }  // namespace internal
95 }  // namespace v8
96 
97 #endif  // V8_OBJECTS_TAGGED_FIELD_H_
98