tagged-field.h 2.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_OBJECTS_TAGGED_FIELD_H_
#define V8_OBJECTS_TAGGED_FIELD_H_

#include "src/common/globals.h"

#include "src/objects/objects.h"
#include "src/objects/tagged-value.h"

namespace v8 {
namespace internal {

// This helper static class represents a tagged field of type T at offset
// kFieldOffset inside some host HeapObject.
// For full-pointer mode this type adds no overhead but when pointer
// compression is enabled such class allows us to use proper decompression
// function depending on the field type.
21
template <typename T, int kFieldOffset = 0>
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
class TaggedField : public AllStatic {
 public:
  static_assert(std::is_base_of<Object, T>::value ||
                    std::is_same<MapWord, T>::value ||
                    std::is_same<MaybeObject, T>::value,
                "T must be strong or weak tagged type or MapWord");

  // True for Smi fields.
  static constexpr bool kIsSmi = std::is_base_of<Smi, T>::value;

  // True for HeapObject and MapWord fields. The latter may look like a Smi
  // if it contains forwarding pointer but still requires tagged pointer
  // decompression.
  static constexpr bool kIsHeapObject =
      std::is_base_of<HeapObject, T>::value || std::is_same<MapWord, T>::value;

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(const Isolate* 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 48
  template <typename LocalIsolate>
  static inline T Relaxed_Load(const LocalIsolate* isolate, HeapObject host,
49
                               int offset = 0);
50 51

  static inline void Relaxed_Store(HeapObject host, T value);
52
  static inline void Relaxed_Store(HeapObject host, int offset, T value);
53

54
  static inline T Acquire_Load(HeapObject host, int offset = 0);
55 56
  template <typename LocalIsolate>
  static inline T Acquire_Load(const LocalIsolate* isolate, HeapObject host,
57
                               int offset = 0);
58 59

  static inline void Release_Store(HeapObject host, T value);
60
  static inline void Release_Store(HeapObject host, int offset, T value);
61 62 63 64 65

  static inline Tagged_t Release_CompareAndSwap(HeapObject host, T old,
                                                T value);

 private:
66
  static inline Tagged_t* location(HeapObject host, int offset = 0);
67 68 69 70 71 72 73 74 75 76 77 78

  template <typename TOnHeapAddress>
  static inline Address tagged_to_full(TOnHeapAddress on_heap_addr,
                                       Tagged_t tagged_value);

  static inline Tagged_t full_to_tagged(Address value);
};

}  // namespace internal
}  // namespace v8

#endif  // V8_OBJECTS_TAGGED_FIELD_H_