LCOV - code coverage report
Current view: top level - src - external-reference-table.h (source / functions) Hit Total Coverage
Test: app.info Lines: 3 4 75.0 %
Date: 2019-01-20 Functions: 0 0 -

          Line data    Source code
       1             : // Copyright 2016 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_EXTERNAL_REFERENCE_TABLE_H_
       6             : #define V8_EXTERNAL_REFERENCE_TABLE_H_
       7             : 
       8             : #include <vector>
       9             : 
      10             : #include "src/accessors.h"
      11             : #include "src/builtins/builtins.h"
      12             : #include "src/external-reference.h"
      13             : 
      14             : namespace v8 {
      15             : namespace internal {
      16             : 
      17             : class Isolate;
      18             : 
      19             : // ExternalReferenceTable is a helper class that defines the relationship
      20             : // between external references and their encodings. It is used to build
      21             : // hashmaps in ExternalReferenceEncoder and ExternalReferenceDecoder.
      22             : class ExternalReferenceTable {
      23             :  public:
      24             :   // For the nullptr ref, see the constructor.
      25             :   static constexpr int kSpecialReferenceCount = 1;
      26             :   static constexpr int kExternalReferenceCount =
      27             :       ExternalReference::kExternalReferenceCount;
      28             :   static constexpr int kBuiltinsReferenceCount =
      29             : #define COUNT_C_BUILTIN(...) +1
      30             :       BUILTIN_LIST_C(COUNT_C_BUILTIN);
      31             : #undef COUNT_C_BUILTIN
      32             :   static constexpr int kRuntimeReferenceCount =
      33             :       Runtime::kNumFunctions -
      34             :       Runtime::kNumInlineFunctions;  // Don't count dupe kInline... functions.
      35             :   static constexpr int kIsolateAddressReferenceCount = kIsolateAddressCount;
      36             :   static constexpr int kAccessorReferenceCount =
      37             :       Accessors::kAccessorInfoCount + Accessors::kAccessorSetterCount;
      38             :   // The number of stub cache external references, see AddStubCache.
      39             :   static constexpr int kStubCacheReferenceCount = 12;
      40             :   static constexpr int kSize =
      41             :       kSpecialReferenceCount + kExternalReferenceCount +
      42             :       kBuiltinsReferenceCount + kRuntimeReferenceCount +
      43             :       kIsolateAddressReferenceCount + kAccessorReferenceCount +
      44             :       kStubCacheReferenceCount;
      45             :   static constexpr uint32_t kEntrySize =
      46             :       static_cast<uint32_t>(kSystemPointerSize);
      47             :   static constexpr uint32_t kSizeInBytes = kSize * kEntrySize + 2 * kUInt32Size;
      48             : 
      49     2546437 :   Address address(uint32_t i) const { return ref_addr_[i]; }
      50           0 :   const char* name(uint32_t i) const { return ref_name_[i]; }
      51             : 
      52             :   bool is_initialized() const { return is_initialized_ != 0; }
      53             : 
      54             :   static const char* ResolveSymbol(void* address);
      55             : 
      56             :   static constexpr uint32_t OffsetOfEntry(uint32_t i) {
      57             :     // Used in CodeAssembler::LookupExternalReference.
      58      805344 :     return i * kEntrySize;
      59             :   }
      60             : 
      61             :   const char* NameFromOffset(uint32_t offset) {
      62             :     DCHECK_EQ(offset % kEntrySize, 0);
      63             :     DCHECK_LT(offset, kSizeInBytes);
      64             :     int index = offset / kEntrySize;
      65             :     return name(index);
      66             :   }
      67             : 
      68       62882 :   ExternalReferenceTable() = default;
      69             :   void Init(Isolate* isolate);
      70             : 
      71             :  private:
      72             :   void Add(Address address, int* index);
      73             : 
      74             :   void AddReferences(Isolate* isolate, int* index);
      75             :   void AddBuiltins(int* index);
      76             :   void AddRuntimeFunctions(int* index);
      77             :   void AddIsolateAddresses(Isolate* isolate, int* index);
      78             :   void AddAccessors(int* index);
      79             :   void AddStubCache(Isolate* isolate, int* index);
      80             : 
      81             :   STATIC_ASSERT(sizeof(Address) == kEntrySize);
      82             :   Address ref_addr_[kSize];
      83             :   static const char* const ref_name_[kSize];
      84             : 
      85             :   uint32_t is_initialized_ = 0;  // Not bool to guarantee deterministic size.
      86             :   uint32_t unused_padding_ = 0;  // For alignment.
      87             : 
      88             :   DISALLOW_COPY_AND_ASSIGN(ExternalReferenceTable);
      89             : };
      90             : 
      91             : STATIC_ASSERT(ExternalReferenceTable::kSizeInBytes ==
      92             :               sizeof(ExternalReferenceTable));
      93             : 
      94             : }  // namespace internal
      95             : }  // namespace v8
      96             : #endif  // V8_EXTERNAL_REFERENCE_TABLE_H_

Generated by: LCOV version 1.10