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 | 6 |
7 namespace v8 { | 7 namespace v8 { |
8 namespace internal { | 8 namespace internal { |
9 | 9 |
10 BackgroundParsingTask::BackgroundParsingTask( | 10 BackgroundParsingTask::BackgroundParsingTask( |
11 StreamedSource* source, ScriptCompiler::CompileOptions options, | 11 StreamedSource* source, ScriptCompiler::CompileOptions options, |
12 int stack_size, Isolate* isolate) | 12 int stack_size, Isolate* isolate) |
13 : source_(source), options_(options), stack_size_(stack_size) { | 13 : source_(source), options_(options), stack_size_(stack_size) { |
14 // Prepare the data for the internalization phase and compilation phase, which | |
15 // will happen in the main thread after parsing. | |
16 source->info.Reset(new i::CompilationInfoWithZone(source->source_stream.get(), | |
17 source->encoding, isolate)); | |
18 source->info->MarkAsGlobal(); | |
19 | 14 |
20 // We don't set the context to the CompilationInfo yet, because the background | |
21 // thread cannot do anything with it anyway. We set it just before compilation | |
22 // on the foreground thread. | |
23 DCHECK(options == ScriptCompiler::kProduceParserCache || | 15 DCHECK(options == ScriptCompiler::kProduceParserCache || |
24 options == ScriptCompiler::kProduceCodeCache || | 16 options == ScriptCompiler::kProduceCodeCache || |
25 options == ScriptCompiler::kNoCompileOptions); | 17 options == ScriptCompiler::kNoCompileOptions); |
26 source->allow_lazy = | |
27 !i::Compiler::DebuggerWantsEagerCompilation(source->info.get()); | |
28 | 18 |
29 if (!source->allow_lazy && options_ == ScriptCompiler::kProduceParserCache) { | 19 // Prepare the data for the internalization phase and compilation phase, which |
20 // will happen in the main thread after parsing. | |
21 Zone* zone = new Zone(); | |
22 ParseInfo* info = new ParseInfo(zone); | |
23 source->zone.Reset(zone); | |
24 source->info.Reset(info); | |
25 info->set_source_stream(source->source_stream.get()); | |
marja
2015/03/04 09:24:40
Would it make sense to have a ctor of ParseInfo wh
titzer
2015/03/04 22:39:35
I tried that, and you end up with ctor hell with d
| |
26 info->set_source_stream_encoding(source->encoding); | |
27 info->set_hash_seed(isolate->heap()->HashSeed()); | |
28 info->set_global(); | |
29 info->set_unicode_cache(&source_->unicode_cache); | |
30 | |
31 bool disable_lazy = !Compiler::DebuggerWantsEagerCompilation(isolate); | |
32 if (disable_lazy && options_ == ScriptCompiler::kProduceParserCache) { | |
30 // Producing cached data while parsing eagerly is not supported. | 33 // Producing cached data while parsing eagerly is not supported. |
31 options_ = ScriptCompiler::kNoCompileOptions; | 34 options = ScriptCompiler::kNoCompileOptions; |
marja
2015/03/04 09:24:40
Huh, the options & options_ modifying is a bit unc
titzer
2015/03/04 22:39:35
Ok, I've fixed this so the options are only stored
| |
35 info->set_compile_options(ScriptCompiler::kNoCompileOptions); | |
32 } | 36 } |
37 | |
38 options_ = ScriptCompiler::kNoCompileOptions; | |
marja
2015/03/04 09:24:40
... why is this correct? Won't this just always ki
titzer
2015/03/04 22:39:35
Fixed.
| |
39 info->set_compile_options(options); | |
40 info->set_allow_lazy_parsing(!disable_lazy); | |
41 source->allow_lazy = !disable_lazy; | |
33 source->hash_seed = isolate->heap()->HashSeed(); | 42 source->hash_seed = isolate->heap()->HashSeed(); |
34 } | 43 } |
35 | 44 |
36 | 45 |
37 void BackgroundParsingTask::Run() { | 46 void BackgroundParsingTask::Run() { |
38 DisallowHeapAllocation no_allocation; | 47 DisallowHeapAllocation no_allocation; |
39 DisallowHandleAllocation no_handles; | 48 DisallowHandleAllocation no_handles; |
40 DisallowHandleDereference no_deref; | 49 DisallowHandleDereference no_deref; |
41 | 50 |
42 ScriptData* script_data = NULL; | 51 ScriptData* script_data = NULL; |
43 if (options_ == ScriptCompiler::kProduceParserCache || | 52 if (options_ == ScriptCompiler::kProduceParserCache || |
44 options_ == ScriptCompiler::kProduceCodeCache) { | 53 options_ == ScriptCompiler::kProduceCodeCache) { |
45 source_->info->SetCachedData(&script_data, options_); | 54 source_->info->set_cached_data(&script_data); |
55 // TODO(titzer): this seems redundant to set the options again. | |
56 source_->info->set_compile_options(options_); | |
46 } | 57 } |
47 | 58 |
48 uintptr_t stack_limit = | 59 uintptr_t stack_limit = |
49 reinterpret_cast<uintptr_t>(&stack_limit) - stack_size_ * KB; | 60 reinterpret_cast<uintptr_t>(&stack_limit) - stack_size_ * KB; |
50 | 61 |
62 source_->info->set_stack_limit(stack_limit); | |
51 // Parser needs to stay alive for finalizing the parsing on the main | 63 // Parser needs to stay alive for finalizing the parsing on the main |
52 // thread. Passing &parse_info is OK because Parser doesn't store it. | 64 // thread. Passing &parse_info is OK because Parser doesn't store it. |
53 source_->parser.Reset(new Parser(source_->info.get(), stack_limit, | 65 source_->parser.Reset(new Parser(source_->info.get())); |
54 source_->hash_seed, | |
55 &source_->unicode_cache)); | |
56 source_->parser->set_allow_lazy(source_->allow_lazy); | 66 source_->parser->set_allow_lazy(source_->allow_lazy); |
57 source_->parser->ParseOnBackground(source_->info.get()); | 67 source_->parser->ParseOnBackground(source_->info.get()); |
58 | 68 |
59 if (script_data != NULL) { | 69 if (script_data != NULL) { |
60 source_->cached_data.Reset(new ScriptCompiler::CachedData( | 70 source_->cached_data.Reset(new ScriptCompiler::CachedData( |
61 script_data->data(), script_data->length(), | 71 script_data->data(), script_data->length(), |
62 ScriptCompiler::CachedData::BufferOwned)); | 72 ScriptCompiler::CachedData::BufferOwned)); |
63 script_data->ReleaseDataOwnership(); | 73 script_data->ReleaseDataOwnership(); |
64 delete script_data; | 74 delete script_data; |
65 } | 75 } |
66 } | 76 } |
67 } | 77 } |
68 } // namespace v8::internal | 78 } // namespace v8::internal |
OLD | NEW |