OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/background-parsing-task.h" | 5 #include "src/background-parsing-task.h" |
6 #include "src/debug/debug.h" | 6 #include "src/debug/debug.h" |
7 | 7 |
8 namespace v8 { | 8 namespace v8 { |
9 namespace internal { | 9 namespace internal { |
10 | 10 |
11 BackgroundParsingTask::BackgroundParsingTask( | 11 BackgroundParsingTask::BackgroundParsingTask( |
12 StreamedSource* source, ScriptCompiler::CompileOptions options, | 12 StreamedSource* source, ScriptCompiler::CompileOptions options, |
13 int stack_size, Isolate* isolate) | 13 int stack_size, Isolate* isolate) |
14 : source_(source), stack_size_(stack_size) { | 14 : source_(source), stack_size_(stack_size), script_data_(nullptr) { |
15 // We don't set the context to the CompilationInfo yet, because the background | 15 // We don't set the context to the CompilationInfo yet, because the background |
16 // thread cannot do anything with it anyway. We set it just before compilation | 16 // thread cannot do anything with it anyway. We set it just before compilation |
17 // on the foreground thread. | 17 // on the foreground thread. |
18 DCHECK(options == ScriptCompiler::kProduceParserCache || | 18 DCHECK(options == ScriptCompiler::kProduceParserCache || |
19 options == ScriptCompiler::kProduceCodeCache || | 19 options == ScriptCompiler::kProduceCodeCache || |
20 options == ScriptCompiler::kNoCompileOptions); | 20 options == ScriptCompiler::kNoCompileOptions); |
21 | 21 |
22 // Prepare the data for the internalization phase and compilation phase, which | 22 // Prepare the data for the internalization phase and compilation phase, which |
23 // will happen in the main thread after parsing. | 23 // will happen in the main thread after parsing. |
24 Zone* zone = new Zone(isolate->allocator()); | 24 Zone* zone = new Zone(isolate->allocator()); |
25 ParseInfo* info = new ParseInfo(zone); | 25 ParseInfo* info = new ParseInfo(zone); |
26 source->zone.reset(zone); | 26 source->zone.reset(zone); |
27 source->info.reset(info); | 27 source->info.reset(info); |
28 info->set_isolate(isolate); | 28 info->set_isolate(isolate); |
29 info->set_source_stream(source->source_stream.get()); | 29 info->set_source_stream(source->source_stream.get()); |
30 info->set_source_stream_encoding(source->encoding); | 30 info->set_source_stream_encoding(source->encoding); |
31 info->set_hash_seed(isolate->heap()->HashSeed()); | 31 info->set_hash_seed(isolate->heap()->HashSeed()); |
32 info->set_global(); | 32 info->set_global(); |
33 info->set_unicode_cache(&source_->unicode_cache); | 33 info->set_unicode_cache(&source_->unicode_cache); |
34 info->set_compile_options(options); | 34 info->set_compile_options(options); |
35 // Parse eagerly with ignition since we will compile eagerly. | 35 // Parse eagerly with ignition since we will compile eagerly. |
36 info->set_allow_lazy_parsing(!(i::FLAG_ignition && i::FLAG_ignition_eager)); | 36 info->set_allow_lazy_parsing(!(i::FLAG_ignition && i::FLAG_ignition_eager)); |
| 37 |
| 38 if (options == ScriptCompiler::kProduceParserCache || |
| 39 options == ScriptCompiler::kProduceCodeCache) { |
| 40 source_->info->set_cached_data(&script_data_); |
| 41 } |
| 42 // Parser needs to stay alive for finalizing the parsing on the main |
| 43 // thread. |
| 44 source_->parser.reset(new Parser(source_->info.get())); |
37 } | 45 } |
38 | 46 |
39 | 47 |
40 void BackgroundParsingTask::Run() { | 48 void BackgroundParsingTask::Run() { |
41 DisallowHeapAllocation no_allocation; | 49 DisallowHeapAllocation no_allocation; |
42 DisallowHandleAllocation no_handles; | 50 DisallowHandleAllocation no_handles; |
43 DisallowHandleDereference no_deref; | 51 DisallowHandleDereference no_deref; |
44 | 52 |
45 ScriptData* script_data = NULL; | 53 // Reset the stack limit of the parser to reflect correctly that we're on a |
46 ScriptCompiler::CompileOptions options = source_->info->compile_options(); | 54 // background thread. |
47 if (options == ScriptCompiler::kProduceParserCache || | 55 uintptr_t stack_limit = |
48 options == ScriptCompiler::kProduceCodeCache) { | 56 reinterpret_cast<uintptr_t>(&stack_limit) - stack_size_ * KB; |
49 source_->info->set_cached_data(&script_data); | 57 source_->parser->set_stack_limit(stack_limit); |
50 } | |
51 | 58 |
52 // Nullify the Isolate temporarily so that the background parser doesn't | 59 // Nullify the Isolate temporarily so that the background parser doesn't |
53 // accidentally use it. | 60 // accidentally use it. |
54 Isolate* isolate = source_->info->isolate(); | 61 Isolate* isolate = source_->info->isolate(); |
55 source_->info->set_isolate(nullptr); | 62 source_->info->set_isolate(nullptr); |
56 | 63 |
57 uintptr_t stack_limit = | |
58 reinterpret_cast<uintptr_t>(&stack_limit) - stack_size_ * KB; | |
59 | |
60 source_->info->set_stack_limit(stack_limit); | |
61 // Parser needs to stay alive for finalizing the parsing on the main | |
62 // thread. Passing &parse_info is OK because Parser doesn't store it. | |
63 source_->parser.reset(new Parser(source_->info.get())); | |
64 source_->parser->ParseOnBackground(source_->info.get()); | 64 source_->parser->ParseOnBackground(source_->info.get()); |
65 | 65 |
66 if (script_data != NULL) { | 66 if (script_data_ != nullptr) { |
67 source_->cached_data.reset(new ScriptCompiler::CachedData( | 67 source_->cached_data.reset(new ScriptCompiler::CachedData( |
68 script_data->data(), script_data->length(), | 68 script_data_->data(), script_data_->length(), |
69 ScriptCompiler::CachedData::BufferOwned)); | 69 ScriptCompiler::CachedData::BufferOwned)); |
70 script_data->ReleaseDataOwnership(); | 70 script_data_->ReleaseDataOwnership(); |
71 delete script_data; | 71 delete script_data_; |
| 72 script_data_ = nullptr; |
72 } | 73 } |
73 source_->info->set_isolate(isolate); | 74 source_->info->set_isolate(isolate); |
74 } | 75 } |
75 } // namespace internal | 76 } // namespace internal |
76 } // namespace v8 | 77 } // namespace v8 |
OLD | NEW |