• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 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_CODEGEN_EXTERNAL_REFERENCE_ENCODER_H_
6 #define V8_CODEGEN_EXTERNAL_REFERENCE_ENCODER_H_
7 
8 #include "src/base/bit-field.h"
9 #include "src/common/globals.h"
10 #include "src/utils/address-map.h"
11 
12 namespace v8 {
13 namespace internal {
14 
15 class Isolate;
16 
17 class ExternalReferenceEncoder {
18  public:
19   class Value {
20    public:
Value(uint32_t raw)21     explicit Value(uint32_t raw) : value_(raw) {}
Value()22     Value() : value_(0) {}
Encode(uint32_t index,bool is_from_api)23     static uint32_t Encode(uint32_t index, bool is_from_api) {
24       return Index::encode(index) | IsFromAPI::encode(is_from_api);
25     }
26 
is_from_api()27     bool is_from_api() const { return IsFromAPI::decode(value_); }
index()28     uint32_t index() const { return Index::decode(value_); }
29 
30    private:
31     using Index = base::BitField<uint32_t, 0, 31>;
32     using IsFromAPI = base::BitField<bool, 31, 1>;
33     uint32_t value_;
34   };
35 
36   explicit ExternalReferenceEncoder(Isolate* isolate);
37 #ifdef DEBUG
38   ~ExternalReferenceEncoder();
39 #endif  // DEBUG
40 
41   Value Encode(Address key);
42   Maybe<Value> TryEncode(Address key);
43 
44   const char* NameOfAddress(Isolate* isolate, Address address) const;
45 
46  private:
47   AddressToIndexHashMap* map_;
48 
49 #ifdef DEBUG
50   std::vector<int> count_;
51   const intptr_t* api_references_;
52 #endif  // DEBUG
53 
54   DISALLOW_COPY_AND_ASSIGN(ExternalReferenceEncoder);
55 };
56 
57 }  // namespace internal
58 }  // namespace v8
59 
60 #endif  // V8_CODEGEN_EXTERNAL_REFERENCE_ENCODER_H_
61