V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
refs-map.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_COMPILER_REFS_MAP_H_
6 #define V8_COMPILER_REFS_MAP_H_
7 
8 #include "src/base/hashmap.h"
9 #include "src/globals.h"
10 #include "src/zone/zone.h"
11 
12 namespace v8 {
13 namespace internal {
14 namespace compiler {
15 
16 class ObjectData;
17 
18 class AddressMatcher : public base::KeyEqualityMatcher<Address> {
19  public:
20  bool operator()(uint32_t hash1, uint32_t hash2, const Address& key1,
21  const Address& key2) const {
22  return key1 == key2;
23  }
24 };
25 
26 // This class employs our own implementation of hash map for the purpose of
27 // storing the mapping between canonical Addresses and allocated ObjectData.
28 // It's used as the refs map in JSHeapBroker and as the snapshot in
29 // PerIsolateCompilerCache, as we need a cheap copy between the two and
30 // std::unordered_map doesn't satisfy this requirement, as it rehashes the
31 // whole map and copies all entries one by one.
32 class RefsMap
33  : public base::TemplateHashMapImpl<Address, ObjectData*, AddressMatcher,
34  ZoneAllocationPolicy>,
35  public ZoneObject {
36  public:
37  RefsMap(uint32_t capacity, AddressMatcher match, Zone* zone);
38  RefsMap(const RefsMap* other, Zone* zone);
39 
40  bool IsEmpty() const { return occupancy() == 0; }
41 
42  // Wrappers around methods from UnderlyingMap
43  Entry* Lookup(const Address& key) const;
44  Entry* LookupOrInsert(const Address& key, Zone* zone);
45 
46  private:
47  static uint32_t Hash(Address addr);
48 };
49 
50 } // namespace compiler
51 } // namespace internal
52 } // namespace v8
53 
54 #endif // V8_COMPILER_REFS_MAP_H_
Definition: libplatform.h:13