LCOV - code coverage report
Current view: top level - src/parsing - parse-info.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 47 60 78.3 %
Date: 2017-10-20 Functions: 13 16 81.2 %

          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/parsing/parse-info.h"
       6             : 
       7             : #include "src/api.h"
       8             : #include "src/ast/ast-source-ranges.h"
       9             : #include "src/ast/ast-value-factory.h"
      10             : #include "src/ast/ast.h"
      11             : #include "src/heap/heap-inl.h"
      12             : #include "src/objects-inl.h"
      13             : #include "src/objects/scope-info.h"
      14             : #include "src/zone/zone.h"
      15             : 
      16             : namespace v8 {
      17             : namespace internal {
      18             : 
      19     2806594 : ParseInfo::ParseInfo(AccountingAllocator* zone_allocator)
      20             :     : zone_(std::make_shared<Zone>(zone_allocator, ZONE_NAME)),
      21             :       flags_(0),
      22             :       extension_(nullptr),
      23             :       compile_options_(ScriptCompiler::kNoCompileOptions),
      24             :       script_scope_(nullptr),
      25             :       unicode_cache_(nullptr),
      26             :       stack_limit_(0),
      27             :       hash_seed_(0),
      28             :       compiler_hints_(0),
      29             :       start_position_(0),
      30             :       end_position_(0),
      31             :       parameters_end_pos_(kNoSourcePosition),
      32             :       function_literal_id_(FunctionLiteral::kIdTypeInvalid),
      33             :       max_function_literal_id_(FunctionLiteral::kIdTypeInvalid),
      34             :       character_stream_(nullptr),
      35             :       cached_data_(nullptr),
      36             :       ast_value_factory_(nullptr),
      37             :       ast_string_constants_(nullptr),
      38             :       function_name_(nullptr),
      39             :       runtime_call_stats_(nullptr),
      40             :       source_range_map_(nullptr),
      41     5613190 :       literal_(nullptr) {}
      42             : 
      43     1129986 : ParseInfo::ParseInfo(Handle<SharedFunctionInfo> shared)
      44     1129986 :     : ParseInfo(shared->GetIsolate()->allocator()) {
      45             :   Isolate* isolate = shared->GetIsolate();
      46     1129987 :   InitFromIsolate(isolate);
      47             : 
      48             :   set_toplevel(shared->is_toplevel());
      49     1129986 :   set_allow_lazy_parsing(FLAG_lazy_inner_functions);
      50             :   set_is_named_expression(shared->is_named_expression());
      51             :   set_compiler_hints(shared->compiler_hints());
      52             :   set_start_position(shared->start_position());
      53             :   set_end_position(shared->end_position());
      54     1129986 :   function_literal_id_ = shared->function_literal_id();
      55             :   set_language_mode(shared->language_mode());
      56             :   set_module(shared->kind() == FunctionKind::kModule);
      57             :   set_asm_wasm_broken(shared->is_asm_wasm_broken());
      58             : 
      59             :   Handle<Script> script(Script::cast(shared->script()));
      60             :   set_script(script);
      61             :   set_native(script->type() == Script::TYPE_NATIVE);
      62             :   set_eval(script->compilation_type() == Script::COMPILATION_TYPE_EVAL);
      63             : 
      64             :   Handle<HeapObject> scope_info(shared->outer_scope_info());
      65     2075583 :   if (!scope_info->IsTheHole(isolate) &&
      66             :       Handle<ScopeInfo>::cast(scope_info)->length() > 0) {
      67             :     set_outer_scope_info(Handle<ScopeInfo>::cast(scope_info));
      68             :   }
      69             : 
      70             :   // CollectTypeProfile uses its own feedback slots. If we have existing
      71             :   // FeedbackMetadata, we can only collect type profile if the feedback vector
      72             :   // has the appropriate slots.
      73             :   set_collect_type_profile(
      74     1130545 :       isolate->is_collecting_type_profile() &&
      75             :       (shared->feedback_metadata()->length() == 0
      76         223 :            ? script->IsUserJavaScript()
      77          56 :            : shared->feedback_metadata()->HasTypeProfileSlot()));
      78     1130323 :   if (block_coverage_enabled() && script->IsUserJavaScript()) {
      79         336 :     AllocateSourceRangeMap();
      80             :   }
      81     1129987 : }
      82             : 
      83     1676469 : ParseInfo::ParseInfo(Handle<Script> script)
      84     1676469 :     : ParseInfo(script->GetIsolate()->allocator()) {
      85     1676468 :   InitFromIsolate(script->GetIsolate());
      86             : 
      87             :   set_allow_lazy_parsing();
      88             :   set_toplevel();
      89             :   set_script(script);
      90             : 
      91             :   set_native(script->type() == Script::TYPE_NATIVE);
      92             :   set_eval(script->compilation_type() == Script::COMPILATION_TYPE_EVAL);
      93             : 
      94     1676498 :   set_collect_type_profile(script->GetIsolate()->is_collecting_type_profile() &&
      95          30 :                            script->IsUserJavaScript());
      96     1676756 :   if (block_coverage_enabled() && script->IsUserJavaScript()) {
      97         288 :     AllocateSourceRangeMap();
      98             :   }
      99     1676468 : }
     100             : 
     101     8419772 : ParseInfo::~ParseInfo() {}
     102             : 
     103             : // static
     104           0 : ParseInfo* ParseInfo::AllocateWithoutScript(Handle<SharedFunctionInfo> shared) {
     105           0 :   Isolate* isolate = shared->GetIsolate();
     106           0 :   ParseInfo* p = new ParseInfo(isolate->allocator());
     107             : 
     108           0 :   p->InitFromIsolate(isolate);
     109             :   p->set_toplevel(shared->is_toplevel());
     110           0 :   p->set_allow_lazy_parsing(FLAG_lazy_inner_functions);
     111             :   p->set_is_named_expression(shared->is_named_expression());
     112             :   p->set_compiler_hints(shared->compiler_hints());
     113             :   p->set_start_position(shared->start_position());
     114             :   p->set_end_position(shared->end_position());
     115           0 :   p->function_literal_id_ = shared->function_literal_id();
     116             :   p->set_language_mode(shared->language_mode());
     117             :   p->set_module(shared->kind() == FunctionKind::kModule);
     118             : 
     119             :   // BUG(5946): This function exists as a workaround until we can
     120             :   // get rid of %SetCode in our native functions. The ParseInfo
     121             :   // is explicitly set up for the case that:
     122             :   // a) you have a native built-in,
     123             :   // b) it's being run for the 2nd-Nth time in an isolate,
     124             :   // c) we've already compiled bytecode and therefore don't need
     125             :   //    to parse.
     126             :   // We tolerate a ParseInfo without a Script in this case.
     127             :   p->set_native(true);
     128             :   p->set_eval(false);
     129             : 
     130             :   Handle<HeapObject> scope_info(shared->outer_scope_info());
     131           0 :   if (!scope_info->IsTheHole(isolate) &&
     132             :       Handle<ScopeInfo>::cast(scope_info)->length() > 0) {
     133             :     p->set_outer_scope_info(Handle<ScopeInfo>::cast(scope_info));
     134             :   }
     135           0 :   return p;
     136             : }
     137             : 
     138         150 : DeclarationScope* ParseInfo::scope() const { return literal()->scope(); }
     139             : 
     140      669550 : bool ParseInfo::is_declaration() const {
     141     1339100 :   return SharedFunctionInfo::IsDeclarationBit::decode(compiler_hints_);
     142             : }
     143             : 
     144     1245401 : FunctionKind ParseInfo::function_kind() const {
     145     2490802 :   return SharedFunctionInfo::FunctionKindBits::decode(compiler_hints_);
     146             : }
     147             : 
     148     8419779 : void ParseInfo::InitFromIsolate(Isolate* isolate) {
     149             :   DCHECK_NOT_NULL(isolate);
     150             :   set_hash_seed(isolate->heap()->HashSeed());
     151     2806593 :   set_stack_limit(isolate->stack_guard()->real_climit());
     152             :   set_unicode_cache(isolate->unicode_cache());
     153     2806593 :   set_runtime_call_stats(isolate->counters()->runtime_call_stats());
     154             :   set_ast_string_constants(isolate->ast_string_constants());
     155     2806593 :   if (isolate->is_block_code_coverage()) set_block_coverage_enabled();
     156     2806593 :   if (isolate->is_collecting_type_profile()) set_collect_type_profile();
     157     2806593 : }
     158             : 
     159         132 : void ParseInfo::UpdateStatisticsAfterBackgroundParse(Isolate* isolate) {
     160             :   // Copy over the counters from the background thread to the main counters on
     161             :   // the isolate.
     162         132 :   RuntimeCallStats* main_call_stats = isolate->counters()->runtime_call_stats();
     163         132 :   if (FLAG_runtime_stats ==
     164             :       v8::tracing::TracingCategoryObserver::ENABLED_BY_NATIVE) {
     165             :     DCHECK_NE(main_call_stats, runtime_call_stats());
     166             :     DCHECK_NOT_NULL(main_call_stats);
     167             :     DCHECK_NOT_NULL(runtime_call_stats());
     168           0 :     main_call_stats->Add(runtime_call_stats());
     169             :   }
     170             :   set_runtime_call_stats(main_call_stats);
     171         132 : }
     172             : 
     173           0 : void ParseInfo::ShareZone(ParseInfo* other) {
     174             :   DCHECK_EQ(0, zone_->allocation_size());
     175             :   zone_ = other->zone_;
     176           0 : }
     177             : 
     178     4696018 : AstValueFactory* ParseInfo::GetOrCreateAstValueFactory() {
     179     2348009 :   if (!ast_value_factory_.get()) {
     180             :     ast_value_factory_.reset(
     181     2348009 :         new AstValueFactory(zone(), ast_string_constants(), hash_seed()));
     182             :   }
     183     2348009 :   return ast_value_factory();
     184             : }
     185             : 
     186           0 : void ParseInfo::ShareAstValueFactory(ParseInfo* other) {
     187             :   DCHECK(!ast_value_factory_.get());
     188             :   ast_value_factory_ = other->ast_value_factory_;
     189           0 : }
     190             : 
     191         624 : void ParseInfo::AllocateSourceRangeMap() {
     192             :   DCHECK(block_coverage_enabled());
     193             :   set_source_range_map(new (zone()) SourceRangeMap(zone()));
     194         624 : }
     195             : 
     196     7085116 : void ParseInfo::ResetCharacterStream() { character_stream_.reset(); }
     197             : 
     198     2348009 : void ParseInfo::set_character_stream(
     199             :     std::unique_ptr<Utf16CharacterStream> character_stream) {
     200             :   DCHECK_NULL(character_stream_);
     201             :   character_stream_.swap(character_stream);
     202     2348009 : }
     203             : 
     204             : }  // namespace internal
     205             : }  // namespace v8

Generated by: LCOV version 1.10