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(IsolateRoot isolate, HeapObject host, int offset = 0); 42 43 static inline void store(HeapObject host, T value); 44 static inline void store(HeapObject host, int offset, T value); 45 46 static inline T Relaxed_Load(HeapObject host, int offset = 0); 47 static inline T Relaxed_Load(IsolateRoot isolate, HeapObject host, 48 int offset = 0); 49 50 static inline void Relaxed_Store(HeapObject host, T value); 51 static inline void Relaxed_Store(HeapObject host, int offset, T value); 52 53 static inline T Acquire_Load(HeapObject host, int offset = 0); 54 static inline T Acquire_Load(IsolateRoot isolate, HeapObject host, 55 int offset = 0); 56 57 static inline void Release_Store(HeapObject host, T value); 58 static inline void Release_Store(HeapObject host, int offset, T value); 59 60 static inline Tagged_t Release_CompareAndSwap(HeapObject host, T old, 61 T value); 62 63 private: 64 static inline Tagged_t* location(HeapObject host, int offset = 0); 65 66 template <typename TOnHeapAddress> 67 static inline Address tagged_to_full(TOnHeapAddress on_heap_addr, 68 Tagged_t tagged_value); 69 70 static inline Tagged_t full_to_tagged(Address value); 71 }; 72 73 } // namespace internal 74 } // namespace v8 75 76 #endif // V8_OBJECTS_TAGGED_FIELD_H_ 77