V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
embedder-data-slot.h
1 // Copyright 2018 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_EMBEDDER_DATA_SLOT_H_
6 #define V8_OBJECTS_EMBEDDER_DATA_SLOT_H_
7 
8 #include <utility>
9 
10 #include "src/assert-scope.h"
11 #include "src/globals.h"
12 #include "src/objects/slots.h"
13 
14 // Has to be the last include (doesn't have include guards):
15 #include "src/objects/object-macros.h"
16 
17 namespace v8 {
18 namespace internal {
19 
20 class EmbedderDataArray;
21 class JSObject;
22 class Object;
23 
24 // An EmbedderDataSlot instance describes a kEmbedderDataSlotSize field ("slot")
25 // holding an embedder data which may contain raw aligned pointer or a tagged
26 // pointer (smi or heap object).
27 // Its address() is the address of the slot.
28 // The slot's contents can be read and written using respective load_XX() and
29 // store_XX() methods.
30 // Storing heap object through this slot may require triggering write barriers
31 // so this operation must be done via static store_tagged() methods.
33  : public SlotBase<EmbedderDataSlot, Address, kEmbedderDataSlotSize> {
34  public:
35  EmbedderDataSlot() : SlotBase(kNullAddress) {}
36  V8_INLINE EmbedderDataSlot(EmbedderDataArray array, int entry_index);
37  V8_INLINE EmbedderDataSlot(JSObject* object, int embedder_field_index);
38 
39 #ifdef V8_COMPRESS_POINTERS
40  static constexpr int kRawPayloadOffset = kTaggedSize;
41 #endif
42  static constexpr int kTaggedPayloadOffset = 0;
43  static constexpr int kRequiredPtrAlignment = kSmiTagSize;
44 
45  // Opaque type used for storing raw embedder data.
46  struct RawData {
47  const Address data_[kEmbedderDataSlotSizeInTaggedSlots];
48  };
49 
50  V8_INLINE Object* load_tagged() const;
51  V8_INLINE void store_smi(Smi value);
52 
53  // Setting an arbitrary tagged value requires triggering a write barrier
54  // which requires separate object and offset values, therefore these static
55  // functions a
56  static V8_INLINE void store_tagged(EmbedderDataArray array, int entry_index,
57  Object* value);
58  static V8_INLINE void store_tagged(JSObject* object, int embedder_field_index,
59  Object* value);
60 
61  // Tries reinterpret the value as an aligned pointer and on success sets
62  // *out_result to the pointer-like value and returns true. Note, that some
63  // Smis could still look like an aligned pointers.
64  // Returns false otherwise.
65  V8_INLINE bool ToAlignedPointer(void** out_result) const;
66 
67  // Returns true if the pointer was successfully stored or false it the pointer
68  // was improperly aligned.
69  V8_INLINE V8_WARN_UNUSED_RESULT bool store_aligned_pointer(void* ptr);
70 
71  V8_INLINE RawData load_raw(const DisallowHeapAllocation& no_gc) const;
72  V8_INLINE void store_raw(const RawData& data,
73  const DisallowHeapAllocation& no_gc);
74 };
75 
76 } // namespace internal
77 } // namespace v8
78 
79 #include "src/objects/object-macros-undef.h"
80 
81 #endif // V8_OBJECTS_EMBEDDER_DATA_SLOT_H_
Definition: libplatform.h:13