LCOV - code coverage report
Current view: top level - src - turbo-assembler.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 44 46 95.7 %
Date: 2019-01-20 Functions: 10 11 90.9 %

          Line data    Source code
       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             : #include "src/turbo-assembler.h"
       6             : 
       7             : #include "src/builtins/builtins.h"
       8             : #include "src/builtins/constants-table-builder.h"
       9             : #include "src/isolate-data.h"
      10             : #include "src/isolate-inl.h"
      11             : #include "src/snapshot/serializer-common.h"
      12             : 
      13             : namespace v8 {
      14             : namespace internal {
      15             : 
      16     5790401 : TurboAssemblerBase::TurboAssemblerBase(Isolate* isolate,
      17             :                                        const AssemblerOptions& options,
      18             :                                        CodeObjectRequired create_code_object,
      19             :                                        std::unique_ptr<AssemblerBuffer> buffer)
      20    17372039 :     : Assembler(options, std::move(buffer)), isolate_(isolate) {
      21     5790819 :   if (create_code_object == CodeObjectRequired::kYes) {
      22             :     code_object_ = Handle<HeapObject>::New(
      23      319664 :         ReadOnlyRoots(isolate).self_reference_marker(), isolate);
      24             :   }
      25     5790819 : }
      26             : 
      27       49280 : void TurboAssemblerBase::IndirectLoadConstant(Register destination,
      28       89712 :                                               Handle<HeapObject> object) {
      29       49280 :   CHECK(root_array_available_);
      30             : 
      31             :   // Before falling back to the (fairly slow) lookup from the constants table,
      32             :   // check if any of the fast paths can be applied.
      33             : 
      34             :   int builtin_index;
      35             :   RootIndex root_index;
      36       49280 :   if (isolate()->roots_table().IsRootHandle(object, &root_index)) {
      37             :     // Roots are loaded relative to the root register.
      38         112 :     LoadRoot(destination, root_index);
      39       49168 :   } else if (isolate()->builtins()->IsBuiltinHandle(object, &builtin_index)) {
      40             :     // Similar to roots, builtins may be loaded from the builtins table.
      41             :     LoadRootRelative(destination,
      42       16128 :                      RootRegisterOffsetForBuiltinIndex(builtin_index));
      43       41776 :   } else if (object.is_identical_to(code_object_) &&
      44         672 :              Builtins::IsBuiltinId(maybe_builtin_index_)) {
      45             :     // The self-reference loaded through Codevalue() may also be a builtin
      46             :     // and thus viable for a fast load.
      47             :     LoadRootRelative(destination,
      48        1344 :                      RootRegisterOffsetForBuiltinIndex(maybe_builtin_index_));
      49             :   } else {
      50       40432 :     CHECK(isolate()->ShouldLoadConstantsFromRootList());
      51             :     // Ensure the given object is in the builtins constants table and fetch its
      52             :     // index.
      53             :     BuiltinsConstantsTableBuilder* builder =
      54             :         isolate()->builtins_constants_table_builder();
      55       40432 :     uint32_t index = builder->AddObject(object);
      56             : 
      57             :     // Slow load from the constants table.
      58       40432 :     LoadFromConstantsTable(destination, index);
      59             :   }
      60       49280 : }
      61             : 
      62      814640 : void TurboAssemblerBase::IndirectLoadExternalReference(
      63      814640 :     Register destination, ExternalReference reference) {
      64      814640 :   CHECK(root_array_available_);
      65             : 
      66      814640 :   if (IsAddressableThroughRootRegister(isolate(), reference)) {
      67             :     // Some external references can be efficiently loaded as an offset from
      68             :     // kRootRegister.
      69             :     intptr_t offset =
      70             :         RootRegisterOffsetForExternalReference(isolate(), reference);
      71       17136 :     LoadRootRegisterOffset(destination, offset);
      72             :   } else {
      73             :     // Otherwise, do a memory load from the external reference table.
      74             :     LoadRootRelative(
      75             :         destination,
      76      797504 :         RootRegisterOffsetForExternalReferenceTableEntry(isolate(), reference));
      77             :   }
      78      814640 : }
      79             : 
      80             : // static
      81     3186348 : int32_t TurboAssemblerBase::RootRegisterOffsetForRootIndex(
      82             :     RootIndex root_index) {
      83     3186348 :   return IsolateData::root_slot_offset(root_index);
      84             : }
      85             : 
      86             : // static
      87           0 : int32_t TurboAssemblerBase::RootRegisterOffsetForBuiltinIndex(
      88             :     int builtin_index) {
      89           0 :   return IsolateData::builtin_slot_offset(builtin_index);
      90             : }
      91             : 
      92             : // static
      93      574688 : intptr_t TurboAssemblerBase::RootRegisterOffsetForExternalReference(
      94             :     Isolate* isolate, const ExternalReference& reference) {
      95      591824 :   return static_cast<intptr_t>(reference.address() - isolate->isolate_root());
      96             : }
      97             : 
      98             : // static
      99      805344 : int32_t TurboAssemblerBase::RootRegisterOffsetForExternalReferenceTableEntry(
     100             :     Isolate* isolate, const ExternalReference& reference) {
     101             :   // Encode as an index into the external reference table stored on the
     102             :   // isolate.
     103      805344 :   ExternalReferenceEncoder encoder(isolate);
     104      805344 :   ExternalReferenceEncoder::Value v = encoder.Encode(reference.address());
     105      805344 :   CHECK(!v.is_from_api());
     106             : 
     107      805344 :   return IsolateData::external_reference_table_offset() +
     108      805344 :          ExternalReferenceTable::OffsetOfEntry(v.index());
     109             : }
     110             : 
     111             : // static
     112       92008 : bool TurboAssemblerBase::IsAddressableThroughRootRegister(
     113             :     Isolate* isolate, const ExternalReference& reference) {
     114             :   Address address = reference.address();
     115       92008 :   return isolate->root_register_addressable_region().contains(address);
     116             : }
     117             : 
     118     3959440 : void TurboAssemblerBase::RecordCommentForOffHeapTrampoline(int builtin_index) {
     119     7917506 :   if (!FLAG_code_comments) return;
     120        1374 :   std::ostringstream str;
     121        1374 :   str << "-- Inlined Trampoline to " << Builtins::name(builtin_index) << " --";
     122        2748 :   RecordComment(str.str().c_str());
     123             : }
     124             : 
     125             : }  // namespace internal
     126      183867 : }  // namespace v8

Generated by: LCOV version 1.10