LCOV - code coverage report
Current view: top level - src - optimized-compilation-info.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 75 89 84.3 %
Date: 2019-02-19 Functions: 17 23 73.9 %

          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             : #include "src/optimized-compilation-info.h"
       6             : 
       7             : #include "src/api.h"
       8             : #include "src/debug/debug.h"
       9             : #include "src/isolate.h"
      10             : #include "src/objects-inl.h"
      11             : #include "src/objects/shared-function-info.h"
      12             : #include "src/source-position.h"
      13             : #include "src/wasm/function-compiler.h"
      14             : 
      15             : namespace v8 {
      16             : namespace internal {
      17             : 
      18      475336 : OptimizedCompilationInfo::OptimizedCompilationInfo(
      19             :     Zone* zone, Isolate* isolate, Handle<SharedFunctionInfo> shared,
      20             :     Handle<JSFunction> closure)
      21      475336 :     : OptimizedCompilationInfo(Code::OPTIMIZED_FUNCTION, zone) {
      22             :   DCHECK(shared->is_compiled());
      23      950673 :   bytecode_array_ = handle(shared->GetBytecodeArray(), isolate);
      24      475336 :   shared_info_ = shared;
      25      475336 :   closure_ = closure;
      26      475336 :   optimization_id_ = isolate->NextOptimizationId();
      27             : 
      28             :   // Collect source positions for optimized code when profiling or if debugger
      29             :   // is active, to be able to get more precise source positions at the price of
      30             :   // more memory consumption.
      31      475336 :   if (isolate->NeedsDetailedOptimizedCodeLineInfo()) {
      32             :     MarkAsSourcePositionsEnabled();
      33             :   }
      34             : 
      35      950674 :   SetTracingFlags(shared->PassesFilter(FLAG_trace_turbo_filter));
      36      475337 : }
      37             : 
      38     1634782 : OptimizedCompilationInfo::OptimizedCompilationInfo(
      39             :     Vector<const char> debug_name, Zone* zone, Code::Kind code_kind)
      40     1634782 :     : OptimizedCompilationInfo(code_kind, zone) {
      41     1634810 :   debug_name_ = debug_name;
      42             : 
      43             :   SetTracingFlags(
      44     3269620 :       PassesFilter(debug_name, CStrVector(FLAG_trace_turbo_filter)));
      45     1634843 : }
      46             : 
      47     2110122 : OptimizedCompilationInfo::OptimizedCompilationInfo(Code::Kind code_kind,
      48             :                                                    Zone* zone)
      49     6330366 :     : code_kind_(code_kind), zone_(zone) {
      50     2110122 :   ConfigureFlags();
      51     2110143 : }
      52             : 
      53     2110136 : void OptimizedCompilationInfo::ConfigureFlags() {
      54     2110136 :   if (FLAG_untrusted_code_mitigations) SetFlag(kUntrustedCodeMitigations);
      55             : 
      56     2110136 :   switch (code_kind_) {
      57             :     case Code::OPTIMIZED_FUNCTION:
      58             :       SetFlag(kCalledWithCodeStartRegister);
      59             :       SetFlag(kSwitchJumpTableEnabled);
      60      475336 :       if (FLAG_function_context_specialization) {
      61             :         MarkAsFunctionContextSpecializing();
      62             :       }
      63      475336 :       if (FLAG_turbo_splitting) {
      64             :         MarkAsSplittingEnabled();
      65             :       }
      66      475336 :       if (FLAG_untrusted_code_mitigations) {
      67             :         MarkAsPoisoningRegisterArguments();
      68             :       }
      69      475336 :       if (FLAG_analyze_environment_liveness) {
      70             :         // TODO(yangguo): Disable this in case of debugging for crbug.com/826613
      71             :         MarkAsAnalyzeEnvironmentLiveness();
      72             :       }
      73             :       break;
      74             :     case Code::BYTECODE_HANDLER:
      75             :       SetFlag(kCalledWithCodeStartRegister);
      76             :       break;
      77             :     case Code::BUILTIN:
      78             :     case Code::STUB:
      79             : #if ENABLE_GDB_JIT_INTERFACE && DEBUG
      80             :       MarkAsSourcePositionsEnabled();
      81             : #endif  // ENABLE_GDB_JIT_INTERFACE && DEBUG
      82             :       break;
      83             :     case Code::WASM_FUNCTION:
      84             :       SetFlag(kSwitchJumpTableEnabled);
      85             :       break;
      86             :     default:
      87             :       break;
      88             :   }
      89     2110136 : }
      90             : 
      91     2128584 : OptimizedCompilationInfo::~OptimizedCompilationInfo() {
      92     2109986 :   if (GetFlag(kDisableFutureOptimization) && has_shared_info()) {
      93       18598 :     shared_info()->DisableOptimization(bailout_reason());
      94             :   }
      95     2109964 : }
      96             : 
      97           0 : void OptimizedCompilationInfo::set_deferred_handles(
      98             :     std::shared_ptr<DeferredHandles> deferred_handles) {
      99             :   DCHECK_NULL(deferred_handles_);
     100             :   deferred_handles_.swap(deferred_handles);
     101           0 : }
     102             : 
     103        7169 : void OptimizedCompilationInfo::set_deferred_handles(
     104             :     DeferredHandles* deferred_handles) {
     105             :   DCHECK_NULL(deferred_handles_);
     106        7169 :   deferred_handles_.reset(deferred_handles);
     107        7169 : }
     108             : 
     109      455183 : void OptimizedCompilationInfo::ReopenHandlesInNewHandleScope(Isolate* isolate) {
     110      455183 :   if (!shared_info_.is_null()) {
     111      455185 :     shared_info_ = Handle<SharedFunctionInfo>(*shared_info_, isolate);
     112             :   }
     113      455185 :   if (!bytecode_array_.is_null()) {
     114      455185 :     bytecode_array_ = Handle<BytecodeArray>(*bytecode_array_, isolate);
     115             :   }
     116      455185 :   if (!closure_.is_null()) {
     117      455185 :     closure_ = Handle<JSFunction>(*closure_, isolate);
     118             :   }
     119      455185 : }
     120             : 
     121     2169857 : std::unique_ptr<char[]> OptimizedCompilationInfo::GetDebugName() const {
     122     2169857 :   if (!shared_info().is_null()) {
     123      475313 :     return shared_info()->DebugName()->ToCString();
     124             :   }
     125     1694544 :   Vector<const char> name_vec = debug_name_;
     126     1694544 :   if (name_vec.is_empty()) name_vec = ArrayVector("unknown");
     127     1694544 :   std::unique_ptr<char[]> name(new char[name_vec.length() + 1]);
     128     1694659 :   memcpy(name.get(), name_vec.start(), name_vec.length());
     129     1694659 :   name[name_vec.length()] = '\0';
     130             :   return name;
     131             : }
     132             : 
     133      610934 : StackFrame::Type OptimizedCompilationInfo::GetOutputStackFrameType() const {
     134      610934 :   switch (code_kind()) {
     135             :     case Code::STUB:
     136             :     case Code::BYTECODE_HANDLER:
     137             :     case Code::BUILTIN:
     138             :       return StackFrame::STUB;
     139             :     case Code::WASM_FUNCTION:
     140      497165 :       return StackFrame::WASM_COMPILED;
     141             :     case Code::JS_TO_WASM_FUNCTION:
     142           0 :       return StackFrame::JS_TO_WASM;
     143             :     case Code::WASM_TO_JS_FUNCTION:
     144        6342 :       return StackFrame::WASM_TO_JS;
     145             :     case Code::WASM_INTERPRETER_ENTRY:
     146        2444 :       return StackFrame::WASM_INTERPRETER_ENTRY;
     147             :     default:
     148           0 :       UNIMPLEMENTED();
     149             :       return StackFrame::NONE;
     150             :   }
     151             : }
     152             : 
     153      496393 : void OptimizedCompilationInfo::SetWasmCompilationResult(
     154             :     std::unique_ptr<wasm::WasmCompilationResult> wasm_compilation_result) {
     155             :   wasm_compilation_result_ = std::move(wasm_compilation_result);
     156      496393 : }
     157             : 
     158             : std::unique_ptr<wasm::WasmCompilationResult>
     159      496420 : OptimizedCompilationInfo::ReleaseWasmCompilationResult() {
     160      496420 :   return std::move(wasm_compilation_result_);
     161             : }
     162             : 
     163           0 : bool OptimizedCompilationInfo::has_context() const {
     164           0 :   return !closure().is_null();
     165             : }
     166             : 
     167      430295 : Context OptimizedCompilationInfo::context() const {
     168             :   DCHECK(has_context());
     169      430297 :   return closure()->context();
     170             : }
     171             : 
     172           0 : bool OptimizedCompilationInfo::has_native_context() const {
     173           0 :   return !closure().is_null() && !closure()->native_context().is_null();
     174             : }
     175             : 
     176     1554170 : Context OptimizedCompilationInfo::native_context() const {
     177             :   DCHECK(has_native_context());
     178     3108340 :   return closure()->native_context();
     179             : }
     180             : 
     181           0 : bool OptimizedCompilationInfo::has_global_object() const {
     182           0 :   return has_native_context();
     183             : }
     184             : 
     185           0 : JSGlobalObject OptimizedCompilationInfo::global_object() const {
     186             :   DCHECK(has_global_object());
     187           0 :   return native_context()->global_object();
     188             : }
     189             : 
     190       66104 : int OptimizedCompilationInfo::AddInlinedFunction(
     191             :     Handle<SharedFunctionInfo> inlined_function,
     192             :     Handle<BytecodeArray> inlined_bytecode, SourcePosition pos) {
     193      132208 :   int id = static_cast<int>(inlined_functions_.size());
     194             :   inlined_functions_.push_back(
     195      132208 :       InlinedFunctionHolder(inlined_function, inlined_bytecode, pos));
     196       66104 :   return id;
     197             : }
     198             : 
     199     2110143 : void OptimizedCompilationInfo::SetTracingFlags(bool passes_filter) {
     200     4220286 :   if (!passes_filter) return;
     201     2110154 :   if (FLAG_trace_turbo) SetFlag(kTraceTurboJson);
     202     2110154 :   if (FLAG_trace_turbo_graph) SetFlag(kTraceTurboGraph);
     203     2110154 :   if (FLAG_trace_turbo_scheduled) SetFlag(kTraceTurboScheduled);
     204             : }
     205             : 
     206           0 : OptimizedCompilationInfo::InlinedFunctionHolder::InlinedFunctionHolder(
     207             :     Handle<SharedFunctionInfo> inlined_shared_info,
     208             :     Handle<BytecodeArray> inlined_bytecode, SourcePosition pos)
     209       66104 :     : shared_info(inlined_shared_info), bytecode_array(inlined_bytecode) {
     210             :   DCHECK_EQ(shared_info->GetBytecodeArray(), *bytecode_array);
     211       66104 :   position.position = pos;
     212             :   // initialized when generating the deoptimization literals
     213       66104 :   position.inlined_function_id = DeoptimizationData::kNotInlinedIndex;
     214           0 : }
     215             : 
     216             : }  // namespace internal
     217      178779 : }  // namespace v8

Generated by: LCOV version 1.10