LCOV - code coverage report
Current view: top level - src/parsing - background-parsing-task.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 26 28 92.9 %
Date: 2017-10-20 Functions: 3 3 100.0 %

          Line data    Source code
       1             : // Copyright 2014 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/background-parsing-task.h"
       6             : 
       7             : #include "src/objects-inl.h"
       8             : #include "src/parsing/parser.h"
       9             : #include "src/parsing/scanner-character-streams.h"
      10             : #include "src/vm-state-inl.h"
      11             : 
      12             : namespace v8 {
      13             : namespace internal {
      14             : 
      15         105 : void StreamedSource::Release() {
      16             :   parser.reset();
      17             :   info.reset();
      18         105 : }
      19             : 
      20         110 : BackgroundParsingTask::BackgroundParsingTask(
      21             :     StreamedSource* source, ScriptCompiler::CompileOptions options,
      22         110 :     int stack_size, Isolate* isolate)
      23         110 :     : source_(source), stack_size_(stack_size), script_data_(nullptr) {
      24             :   // We don't set the context to the CompilationInfo yet, because the background
      25             :   // thread cannot do anything with it anyway. We set it just before compilation
      26             :   // on the foreground thread.
      27             :   DCHECK(options == ScriptCompiler::kProduceParserCache ||
      28             :          options == ScriptCompiler::kProduceCodeCache ||
      29             :          options == ScriptCompiler::kProduceFullCodeCache ||
      30             :          options == ScriptCompiler::kNoCompileOptions);
      31             : 
      32             :   VMState<PARSER> state(isolate);
      33             : 
      34             :   // Prepare the data for the internalization phase and compilation phase, which
      35             :   // will happen in the main thread after parsing.
      36         220 :   ParseInfo* info = new ParseInfo(isolate->allocator());
      37         110 :   info->InitFromIsolate(isolate);
      38         110 :   if (V8_UNLIKELY(FLAG_runtime_stats)) {
      39           0 :     info->set_runtime_call_stats(new (info->zone()) RuntimeCallStats());
      40             :   } else {
      41             :     info->set_runtime_call_stats(nullptr);
      42             :   }
      43             :   info->set_toplevel();
      44             :   std::unique_ptr<Utf16CharacterStream> stream(
      45             :       ScannerStream::For(source->source_stream.get(), source->encoding,
      46         220 :                          info->runtime_call_stats()));
      47         220 :   info->set_character_stream(std::move(stream));
      48         110 :   info->set_unicode_cache(&source_->unicode_cache);
      49             :   info->set_compile_options(options);
      50             :   info->set_allow_lazy_parsing();
      51         110 :   if (V8_UNLIKELY(info->block_coverage_enabled())) {
      52           0 :     info->AllocateSourceRangeMap();
      53             :   }
      54         110 :   info->set_cached_data(&script_data_);
      55             : 
      56             :   source->info.reset(info);
      57             : 
      58             :   // Parser needs to stay alive for finalizing the parsing on the main
      59             :   // thread.
      60         220 :   source_->parser.reset(new Parser(source_->info.get()));
      61             :   source_->parser->DeserializeScopeChain(source_->info.get(),
      62         220 :                                          MaybeHandle<ScopeInfo>());
      63         110 : }
      64             : 
      65         110 : void BackgroundParsingTask::Run() {
      66             :   DisallowHeapAllocation no_allocation;
      67             :   DisallowHandleAllocation no_handles;
      68             :   DisallowHandleDereference no_deref;
      69             : 
      70             :   // Reset the stack limit of the parser to reflect correctly that we're on a
      71             :   // background thread.
      72         110 :   uintptr_t stack_limit = GetCurrentStackPosition() - stack_size_ * KB;
      73         110 :   source_->parser->set_stack_limit(stack_limit);
      74             : 
      75         220 :   source_->parser->ParseOnBackground(source_->info.get());
      76             : 
      77         110 :   if (script_data_ != nullptr) {
      78             :     source_->cached_data.reset(new ScriptCompiler::CachedData(
      79             :         script_data_->data(), script_data_->length(),
      80           5 :         ScriptCompiler::CachedData::BufferOwned));
      81           5 :     script_data_->ReleaseDataOwnership();
      82          10 :     delete script_data_;
      83           5 :     script_data_ = nullptr;
      84             :   }
      85         110 : }
      86             : 
      87             : }  // namespace internal
      88             : }  // namespace v8

Generated by: LCOV version 1.10