LCOV - code coverage report
Current view: top level - src - optimized-compilation-info.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 68 80 85.0 %
Date: 2019-01-20 Functions: 15 20 75.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             : #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             : 
      14             : namespace v8 {
      15             : namespace internal {
      16             : 
      17      474509 : OptimizedCompilationInfo::OptimizedCompilationInfo(
      18             :     Zone* zone, Isolate* isolate, Handle<SharedFunctionInfo> shared,
      19             :     Handle<JSFunction> closure)
      20      474509 :     : OptimizedCompilationInfo(Code::OPTIMIZED_FUNCTION, zone) {
      21             :   DCHECK(shared->is_compiled());
      22      949039 :   bytecode_array_ = handle(shared->GetBytecodeArray(), isolate);
      23      474520 :   shared_info_ = shared;
      24      474520 :   closure_ = closure;
      25      474520 :   optimization_id_ = isolate->NextOptimizationId();
      26             : 
      27             :   // Collect source positions for optimized code when profiling or if debugger
      28             :   // is active, to be able to get more precise source positions at the price of
      29             :   // more memory consumption.
      30      474520 :   if (isolate->NeedsDetailedOptimizedCodeLineInfo()) {
      31             :     MarkAsSourcePositionsEnabled();
      32             :   }
      33             : 
      34      949039 :   SetTracingFlags(shared->PassesFilter(FLAG_trace_turbo_filter));
      35      474516 : }
      36             : 
      37     2444657 : OptimizedCompilationInfo::OptimizedCompilationInfo(
      38             :     Vector<const char> debug_name, Zone* zone, Code::Kind code_kind)
      39     2444657 :     : OptimizedCompilationInfo(code_kind, zone) {
      40     2444661 :   debug_name_ = debug_name;
      41             : 
      42             :   SetTracingFlags(
      43     4889322 :       PassesFilter(debug_name, CStrVector(FLAG_trace_turbo_filter)));
      44     2444699 : }
      45             : 
      46     2919169 : OptimizedCompilationInfo::OptimizedCompilationInfo(Code::Kind code_kind,
      47             :                                                    Zone* zone)
      48     8757507 :     : code_kind_(code_kind), zone_(zone) {
      49     2919169 :   ConfigureFlags();
      50     2919174 : }
      51             : 
      52     2919159 : void OptimizedCompilationInfo::ConfigureFlags() {
      53     2919159 :   if (FLAG_untrusted_code_mitigations) SetFlag(kUntrustedCodeMitigations);
      54             : 
      55     2919159 :   switch (code_kind_) {
      56             :     case Code::OPTIMIZED_FUNCTION:
      57             :       SetFlag(kCalledWithCodeStartRegister);
      58             :       SetFlag(kSwitchJumpTableEnabled);
      59      474510 :       if (FLAG_function_context_specialization) {
      60             :         MarkAsFunctionContextSpecializing();
      61             :       }
      62      474510 :       if (FLAG_turbo_splitting) {
      63             :         MarkAsSplittingEnabled();
      64             :       }
      65      474510 :       if (FLAG_untrusted_code_mitigations) {
      66             :         MarkAsPoisoningRegisterArguments();
      67             :       }
      68      474510 :       if (FLAG_analyze_environment_liveness) {
      69             :         // TODO(yangguo): Disable this in case of debugging for crbug.com/826613
      70             :         MarkAsAnalyzeEnvironmentLiveness();
      71             :       }
      72             :       break;
      73             :     case Code::BYTECODE_HANDLER:
      74             :       SetFlag(kCalledWithCodeStartRegister);
      75             :       break;
      76             :     case Code::BUILTIN:
      77             :     case Code::STUB:
      78             : #if ENABLE_GDB_JIT_INTERFACE && DEBUG
      79             :       MarkAsSourcePositionsEnabled();
      80             : #endif  // ENABLE_GDB_JIT_INTERFACE && DEBUG
      81             :       break;
      82             :     case Code::WASM_FUNCTION:
      83             :       SetFlag(kSwitchJumpTableEnabled);
      84             :       break;
      85             :     default:
      86             :       break;
      87             :   }
      88     2919159 : }
      89             : 
      90     2937684 : OptimizedCompilationInfo::~OptimizedCompilationInfo() {
      91     2919324 :   if (GetFlag(kDisableFutureOptimization) && has_shared_info()) {
      92       18360 :     shared_info()->DisableOptimization(bailout_reason());
      93             :   }
      94     2919330 : }
      95             : 
      96           0 : void OptimizedCompilationInfo::set_deferred_handles(
      97             :     std::shared_ptr<DeferredHandles> deferred_handles) {
      98             :   DCHECK_NULL(deferred_handles_);
      99             :   deferred_handles_.swap(deferred_handles);
     100           0 : }
     101             : 
     102        7210 : void OptimizedCompilationInfo::set_deferred_handles(
     103             :     DeferredHandles* deferred_handles) {
     104             :   DCHECK_NULL(deferred_handles_);
     105        7210 :   deferred_handles_.reset(deferred_handles);
     106        7210 : }
     107             : 
     108      454290 : void OptimizedCompilationInfo::ReopenHandlesInNewHandleScope(Isolate* isolate) {
     109      454290 :   if (!shared_info_.is_null()) {
     110      454304 :     shared_info_ = Handle<SharedFunctionInfo>(*shared_info_, isolate);
     111             :   }
     112      454296 :   if (!bytecode_array_.is_null()) {
     113      454304 :     bytecode_array_ = Handle<BytecodeArray>(*bytecode_array_, isolate);
     114             :   }
     115      454296 :   if (!closure_.is_null()) {
     116      454304 :     closure_ = Handle<JSFunction>(*closure_, isolate);
     117             :   }
     118      454296 : }
     119             : 
     120     2979020 : std::unique_ptr<char[]> OptimizedCompilationInfo::GetDebugName() const {
     121     2979020 :   if (!shared_info().is_null()) {
     122      474492 :     return shared_info()->DebugName()->ToCString();
     123             :   }
     124     2504535 :   Vector<const char> name_vec = debug_name_;
     125     2504535 :   if (name_vec.is_empty()) name_vec = ArrayVector("unknown");
     126     2504535 :   std::unique_ptr<char[]> name(new char[name_vec.length() + 1]);
     127     2504779 :   memcpy(name.get(), name_vec.start(), name_vec.length());
     128     2504779 :   name[name_vec.length()] = '\0';
     129             :   return name;
     130             : }
     131             : 
     132     1178079 : StackFrame::Type OptimizedCompilationInfo::GetOutputStackFrameType() const {
     133     1178079 :   switch (code_kind()) {
     134             :     case Code::STUB:
     135             :     case Code::BYTECODE_HANDLER:
     136             :     case Code::BUILTIN:
     137             :       return StackFrame::STUB;
     138             :     case Code::WASM_FUNCTION:
     139     1061129 :       return StackFrame::WASM_COMPILED;
     140             :     case Code::JS_TO_WASM_FUNCTION:
     141           0 :       return StackFrame::JS_TO_WASM;
     142             :     case Code::WASM_TO_JS_FUNCTION:
     143        7087 :       return StackFrame::WASM_TO_JS;
     144             :     case Code::WASM_INTERPRETER_ENTRY:
     145        1214 :       return StackFrame::WASM_INTERPRETER_ENTRY;
     146             :     default:
     147           0 :       UNIMPLEMENTED();
     148             :       return StackFrame::NONE;
     149             :   }
     150             : }
     151             : 
     152           0 : bool OptimizedCompilationInfo::has_context() const {
     153           0 :   return !closure().is_null();
     154             : }
     155             : 
     156      428850 : Context OptimizedCompilationInfo::context() const {
     157             :   DCHECK(has_context());
     158      428855 :   return closure()->context();
     159             : }
     160             : 
     161           0 : bool OptimizedCompilationInfo::has_native_context() const {
     162           0 :   return !closure().is_null() && !closure()->native_context().is_null();
     163             : }
     164             : 
     165     1554384 : Context OptimizedCompilationInfo::native_context() const {
     166             :   DCHECK(has_native_context());
     167     1554395 :   return closure()->native_context();
     168             : }
     169             : 
     170           0 : bool OptimizedCompilationInfo::has_global_object() const {
     171           0 :   return has_native_context();
     172             : }
     173             : 
     174           0 : JSGlobalObject OptimizedCompilationInfo::global_object() const {
     175             :   DCHECK(has_global_object());
     176           0 :   return native_context()->global_object();
     177             : }
     178             : 
     179       66980 : int OptimizedCompilationInfo::AddInlinedFunction(
     180             :     Handle<SharedFunctionInfo> inlined_function,
     181             :     Handle<BytecodeArray> inlined_bytecode, SourcePosition pos) {
     182      133960 :   int id = static_cast<int>(inlined_functions_.size());
     183             :   inlined_functions_.push_back(
     184      133960 :       InlinedFunctionHolder(inlined_function, inlined_bytecode, pos));
     185       66980 :   return id;
     186             : }
     187             : 
     188     2919165 : void OptimizedCompilationInfo::SetTracingFlags(bool passes_filter) {
     189     5838330 :   if (!passes_filter) return;
     190     2919183 :   if (FLAG_trace_turbo) SetFlag(kTraceTurboJson);
     191     2919183 :   if (FLAG_trace_turbo_graph) SetFlag(kTraceTurboGraph);
     192     2919183 :   if (FLAG_trace_turbo_scheduled) SetFlag(kTraceTurboScheduled);
     193             : }
     194             : 
     195             : }  // namespace internal
     196      183867 : }  // namespace v8

Generated by: LCOV version 1.10