LCOV - code coverage report
Current view: top level - src - turbo-assembler.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 42 47 89.4 %
Date: 2019-03-21 Functions: 9 10 90.0 %

          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    40902184 : TurboAssemblerBase::TurboAssemblerBase(Isolate* isolate,
      17             :                                        const AssemblerOptions& options,
      18             :                                        CodeObjectRequired create_code_object,
      19             :                                        std::unique_ptr<AssemblerBuffer> buffer)
      20   122713616 :     : Assembler(options, std::move(buffer)), isolate_(isolate) {
      21    40905716 :   if (create_code_object == CodeObjectRequired::kYes) {
      22             :     code_object_ = Handle<HeapObject>::New(
      23      315431 :         ReadOnlyRoots(isolate).self_reference_marker(), isolate);
      24             :   }
      25    40905716 : }
      26             : 
      27       47936 : void TurboAssemblerBase::IndirectLoadConstant(Register destination,
      28             :                                               Handle<HeapObject> object) {
      29       47936 :   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       47936 :   if (isolate()->roots_table().IsRootHandle(object, &root_index)) {
      37             :     // Roots are loaded relative to the root register.
      38         112 :     LoadRoot(destination, root_index);
      39       47824 :   } else if (isolate()->builtins()->IsBuiltinHandle(object, &builtin_index)) {
      40             :     // Similar to roots, builtins may be loaded from the builtins table.
      41        8176 :     LoadRootRelative(destination,
      42       16352 :                      RootRegisterOffsetForBuiltinIndex(builtin_index));
      43       39648 :   } else if (object.is_identical_to(code_object_) &&
      44           0 :              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           0 :     LoadRootRelative(destination,
      48           0 :                      RootRegisterOffsetForBuiltinIndex(maybe_builtin_index_));
      49             :   } else {
      50       39648 :     CHECK(isolate()->IsGeneratingEmbeddedBuiltins());
      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       39648 :     uint32_t index = builder->AddObject(object);
      56             : 
      57             :     // Slow load from the constants table.
      58       39648 :     LoadFromConstantsTable(destination, index);
      59             :   }
      60       47936 : }
      61             : 
      62      818552 : void TurboAssemblerBase::IndirectLoadExternalReference(
      63             :     Register destination, ExternalReference reference) {
      64      818552 :   CHECK(root_array_available_);
      65             : 
      66      818552 :   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       18816 :     LoadRootRegisterOffset(destination, offset);
      72             :   } else {
      73             :     // Otherwise, do a memory load from the external reference table.
      74      799736 :     LoadRootRelative(
      75             :         destination,
      76     1599472 :         RootRegisterOffsetForExternalReferenceTableEntry(isolate(), reference));
      77             :   }
      78      818552 : }
      79             : 
      80             : // static
      81     3573757 : int32_t TurboAssemblerBase::RootRegisterOffsetForRootIndex(
      82             :     RootIndex root_index) {
      83     3573757 :   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      642167 : intptr_t TurboAssemblerBase::RootRegisterOffsetForExternalReference(
      94             :     Isolate* isolate, const ExternalReference& reference) {
      95      660983 :   return static_cast<intptr_t>(reference.address() - isolate->isolate_root());
      96             : }
      97             : 
      98             : // static
      99      800352 : 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     1600704 :   ExternalReferenceEncoder encoder(isolate);
     104      800352 :   ExternalReferenceEncoder::Value v = encoder.Encode(reference.address());
     105      800352 :   CHECK(!v.is_from_api());
     106             : 
     107      800352 :   return IsolateData::external_reference_table_offset() +
     108     1600704 :          ExternalReferenceTable::OffsetOfEntry(v.index());
     109             : }
     110             : 
     111             : // static
     112       90832 : bool TurboAssemblerBase::IsAddressableThroughRootRegister(
     113             :     Isolate* isolate, const ExternalReference& reference) {
     114             :   Address address = reference.address();
     115       90832 :   return isolate->root_register_addressable_region().contains(address);
     116             : }
     117             : 
     118     4742074 : void TurboAssemblerBase::RecordCommentForOffHeapTrampoline(int builtin_index) {
     119     9482455 :   if (!FLAG_code_comments) return;
     120        3386 :   std::ostringstream str;
     121        3386 :   str << "-- Inlined Trampoline to " << Builtins::name(builtin_index) << " --";
     122        3386 :   RecordComment(str.str().c_str());
     123             : }
     124             : 
     125             : }  // namespace internal
     126      120216 : }  // namespace v8

Generated by: LCOV version 1.10