5 #ifndef V8_SNAPSHOT_REFERENCES_H_ 6 #define V8_SNAPSHOT_REFERENCES_H_ 8 #include "src/assert-scope.h" 9 #include "src/base/hashmap.h" 10 #include "src/utils.h" 17 enum SpecialValueType {
24 static const int kSpecialValueSpace = LAST_SPACE + 1;
25 STATIC_ASSERT(kSpecialValueSpace < (1 << kSpaceTagSize));
28 : bitfield_(SpaceBits::encode(kSpecialValueSpace) |
29 SpecialValueTypeBits::encode(
type)),
37 : bitfield_(SpaceBits::encode(space) |
38 ChunkIndexBits::encode(chunk_index)),
39 value_(chunk_offset) {}
44 DCHECK(IsAligned(chunk_offset, kObjectAlignment));
45 DCHECK_LT(space, LO_SPACE);
69 bool is_valid()
const {
70 return SpaceBits::decode(bitfield_) != kSpecialValueSpace ||
71 SpecialValueTypeBits::decode(bitfield_) != kInvalidValue;
74 bool is_back_reference()
const {
75 return SpaceBits::decode(bitfield_) <= LAST_SPACE;
78 AllocationSpace space()
const {
79 DCHECK(is_back_reference());
80 return static_cast<AllocationSpace
>(SpaceBits::decode(bitfield_));
84 DCHECK(is_back_reference());
89 DCHECK(space() != MAP_SPACE && space() != LO_SPACE);
90 return ChunkIndexBits::decode(bitfield_);
94 DCHECK_EQ(MAP_SPACE, SpaceBits::decode(bitfield_));
98 bool is_off_heap_backing_store_reference()
const {
99 return SpaceBits::decode(bitfield_) == kSpecialValueSpace &&
100 SpecialValueTypeBits::decode(bitfield_) == kOffHeapBackingStore;
103 uint32_t off_heap_backing_store_index()
const {
104 DCHECK(is_off_heap_backing_store_reference());
108 uint32_t large_object_index()
const {
109 DCHECK_EQ(LO_SPACE, SpaceBits::decode(bitfield_));
113 bool is_attached_reference()
const {
114 return SpaceBits::decode(bitfield_) == kSpecialValueSpace &&
115 SpecialValueTypeBits::decode(bitfield_) == kAttachedReference;
118 uint32_t attached_reference_index()
const {
119 DCHECK(is_attached_reference());
123 bool is_builtin_reference()
const {
124 return SpaceBits::decode(bitfield_) == kSpecialValueSpace &&
125 SpecialValueTypeBits::decode(bitfield_) == kBuiltinReference;
129 DCHECK(is_builtin_reference());
134 class SpaceBits :
public BitField<int, 0, kSpaceTagSize> {};
136 :
public BitField<uint32_t, SpaceBits::kNext, 32 - kSpaceTagSize> {};
137 class SpecialValueTypeBits
138 :
public BitField<SpecialValueType, SpaceBits::kNext,
139 32 - kSpaceTagSize> {};
154 base::KeyEqualityMatcher<intptr_t>,
155 base::DefaultAllocationPolicy> {
163 Entry* entry = Lookup(key, Hash(key));
169 DCHECK(reference.is_valid());
170 DCHECK(!LookupReference(obj).is_valid());
172 LookupOrInsert(key, Hash(key))->value = reference;
177 SerializerReference::AttachedReference(attached_reference_index_++);
178 Add(attached_reference, reference);
183 static inline uintptr_t Key(
void* value) {
184 return reinterpret_cast<uintptr_t>(value);
189 DISALLOW_HEAP_ALLOCATION(no_allocation_);
190 int attached_reference_index_;
197 #endif // V8_SNAPSHOT_REFERENCES_H_