v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
address-map.h
Go to the documentation of this file.
1// Copyright 2015 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_UTILS_ADDRESS_MAP_H_
6#define V8_UTILS_ADDRESS_MAP_H_
7
8#include "src/base/hashmap.h"
11#include "src/roots/roots.h"
12
13namespace v8 {
14namespace internal {
15
16template <typename Type>
18 : public base::TemplateHashMapImpl<uintptr_t, uint32_t,
19 base::KeyEqualityMatcher<intptr_t>,
20 base::DefaultAllocationPolicy> {
21 public:
23
24 inline void Set(Type value, uint32_t index) {
25 uintptr_t key = Key(value);
27 }
28
29 inline Maybe<uint32_t> Get(Type value) const {
30 uintptr_t key = Key(value);
31 Entry* entry = Lookup(key, Hash(key));
32 if (entry == nullptr) return Nothing<uint32_t>();
33 return Just(entry->value);
34 }
35
36 private:
37 static inline uintptr_t Key(Type value);
38
39 static uint32_t Hash(uintptr_t key) { return static_cast<uint32_t>(key); }
40};
41
42template <>
44 return static_cast<uintptr_t>(value);
45}
46
47template <>
49 Tagged<HeapObject> value) {
50 return value.ptr();
51}
52
55 : public PointerToIndexHashMap<Tagged<HeapObject>> {};
56
58 public:
59 explicit RootIndexMap(Isolate* isolate);
60 RootIndexMap(const RootIndexMap&) = delete;
62
63 // Returns true on successful lookup and sets *|out_root_list|.
65 RootIndex* out_root_list) const {
66 Maybe<uint32_t> maybe_index = map_->Get(obj);
67 if (maybe_index.IsJust()) {
68 *out_root_list = static_cast<RootIndex>(maybe_index.FromJust());
69 return true;
70 }
71 return false;
72 }
73
74 private:
76};
77
78} // namespace internal
79} // namespace v8
80
81#endif // V8_UTILS_ADDRESS_MAP_H_
V8_INLINE bool IsJust() const
Definition v8-maybe.h:36
V8_INLINE T FromJust() const &
Definition v8-maybe.h:64
static uintptr_t Key(Type value)
void Set(Type value, uint32_t index)
Definition address-map.h:24
Maybe< uint32_t > Get(Type value) const
Definition address-map.h:29
static uint32_t Hash(uintptr_t key)
Definition address-map.h:39
V8_EXPORT_PRIVATE bool Lookup(Tagged< HeapObject > obj, RootIndex *out_root_list) const
Definition address-map.h:64
RootIndexMap & operator=(const RootIndexMap &)=delete
RootIndexMap(const RootIndexMap &)=delete
RootIndexMap(Isolate *isolate)
HeapObjectToIndexHashMap * map_
Definition address-map.h:75
return value
Definition map-inl.h:893
Maybe< T > Nothing()
Definition v8-maybe.h:112
Maybe< T > Just(const T &t)
Definition v8-maybe.h:117
#define V8_EXPORT_PRIVATE
Definition macros.h:460