OLD | NEW |
---|---|
1 // Copyright 2016 the V8 project authors. All rights reserved. | 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 | 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/compiler-dispatcher/compiler-dispatcher-job.h" | 5 #include "src/compiler-dispatcher/compiler-dispatcher-job.h" |
6 | 6 |
7 #include "src/assert-scope.h" | |
7 #include "src/global-handles.h" | 8 #include "src/global-handles.h" |
8 #include "src/isolate.h" | 9 #include "src/isolate.h" |
9 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
10 #include "src/parsing/parser.h" | 11 #include "src/parsing/parser.h" |
11 #include "src/parsing/scanner-character-streams.h" | 12 #include "src/parsing/scanner-character-streams.h" |
12 #include "src/unicode-cache.h" | 13 #include "src/unicode-cache.h" |
13 #include "src/zone.h" | 14 #include "src/zone.h" |
14 | 15 |
15 namespace v8 { | 16 namespace v8 { |
16 namespace internal { | 17 namespace internal { |
17 | 18 |
18 CompilerDispatcherJob::CompilerDispatcherJob(Isolate* isolate, | 19 CompilerDispatcherJob::CompilerDispatcherJob(Isolate* isolate, |
19 Handle<JSFunction> function) | 20 Handle<JSFunction> function, |
21 size_t max_stack_size) | |
20 : isolate_(isolate), | 22 : isolate_(isolate), |
21 function_(Handle<JSFunction>::cast( | 23 function_(Handle<JSFunction>::cast( |
22 isolate_->global_handles()->Create(*function))), | 24 isolate_->global_handles()->Create(*function))), |
23 can_parse_on_background_thread_(false) {} | 25 max_stack_size_(max_stack_size) { |
26 HandleScope scope(isolate_); | |
27 Handle<SharedFunctionInfo> shared(function_->shared(), isolate_); | |
28 Handle<Script> script(Script::cast(shared->script()), isolate_); | |
29 Handle<String> source(String::cast(script->source()), isolate_); | |
30 if (source->IsExternalTwoByteString()) { | |
vogelheim
2016/07/29 10:19:56
nitpick:
can_parse_on_background_thread_ = source
jochen (gone - plz use gerrit)
2016/07/29 10:27:45
will update in my next cl
| |
31 can_parse_on_background_thread_ = true; | |
32 } else if (source->IsExternalOneByteString()) { | |
33 can_parse_on_background_thread_ = true; | |
34 } else { | |
35 can_parse_on_background_thread_ = false; | |
36 } | |
37 } | |
24 | 38 |
25 CompilerDispatcherJob::~CompilerDispatcherJob() { | 39 CompilerDispatcherJob::~CompilerDispatcherJob() { |
26 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | 40 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); |
27 i::GlobalHandles::Destroy(Handle<Object>::cast(function_).location()); | 41 i::GlobalHandles::Destroy(Handle<Object>::cast(function_).location()); |
28 } | 42 } |
29 | 43 |
30 void CompilerDispatcherJob::PrepareToParseOnMainThread() { | 44 void CompilerDispatcherJob::PrepareToParseOnMainThread() { |
31 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | 45 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); |
32 DCHECK(status_ == CompileJobStatus::kInitial); | 46 DCHECK(status() == CompileJobStatus::kInitial); |
33 HandleScope scope(isolate_); | 47 HandleScope scope(isolate_); |
34 unicode_cache_.reset(new UnicodeCache()); | 48 unicode_cache_.reset(new UnicodeCache()); |
35 zone_.reset(new Zone(isolate_->allocator())); | 49 zone_.reset(new Zone(isolate_->allocator())); |
36 Handle<SharedFunctionInfo> shared(function_->shared(), isolate_); | 50 Handle<SharedFunctionInfo> shared(function_->shared(), isolate_); |
37 Handle<Script> script(Script::cast(shared->script()), isolate_); | 51 Handle<Script> script(Script::cast(shared->script()), isolate_); |
38 Handle<String> source(String::cast(script->source()), isolate_); | 52 Handle<String> source(String::cast(script->source()), isolate_); |
39 if (source->IsExternalTwoByteString()) { | 53 if (source->IsExternalTwoByteString()) { |
40 can_parse_on_background_thread_ = true; | 54 can_parse_on_background_thread_ = true; |
41 character_stream_.reset(new ExternalTwoByteStringUtf16CharacterStream( | 55 character_stream_.reset(new ExternalTwoByteStringUtf16CharacterStream( |
42 Handle<ExternalTwoByteString>::cast(source), shared->start_position(), | 56 Handle<ExternalTwoByteString>::cast(source), shared->start_position(), |
43 shared->end_position())); | 57 shared->end_position())); |
44 } else if (source->IsExternalOneByteString()) { | 58 } else if (source->IsExternalOneByteString()) { |
45 can_parse_on_background_thread_ = true; | 59 can_parse_on_background_thread_ = true; |
46 character_stream_.reset(new ExternalOneByteStringUtf16CharacterStream( | 60 character_stream_.reset(new ExternalOneByteStringUtf16CharacterStream( |
47 Handle<ExternalOneByteString>::cast(source), shared->start_position(), | 61 Handle<ExternalOneByteString>::cast(source), shared->start_position(), |
48 shared->end_position())); | 62 shared->end_position())); |
49 } else { | 63 } else { |
50 can_parse_on_background_thread_ = false; | 64 can_parse_on_background_thread_ = false; |
51 character_stream_.reset(new GenericStringUtf16CharacterStream( | 65 character_stream_.reset(new GenericStringUtf16CharacterStream( |
52 source, shared->start_position(), shared->end_position())); | 66 source, shared->start_position(), shared->end_position())); |
53 } | 67 } |
54 parse_info_.reset(new ParseInfo(zone_.get())); | 68 parse_info_.reset(new ParseInfo(zone_.get())); |
55 parse_info_->set_isolate(isolate_); | 69 parse_info_->set_isolate(isolate_); |
56 parse_info_->set_character_stream(character_stream_.get()); | 70 parse_info_->set_character_stream(character_stream_.get()); |
57 parse_info_->set_hash_seed(isolate_->heap()->HashSeed()); | 71 parse_info_->set_hash_seed(isolate_->heap()->HashSeed()); |
58 parse_info_->set_unicode_cache(unicode_cache_.get()); | 72 parse_info_->set_unicode_cache(unicode_cache_.get()); |
59 status_ = CompileJobStatus::kReadyToParse; | 73 parser_.reset(new Parser(parse_info_.get())); |
74 status_.SetValue(CompileJobStatus::kReadyToParse); | |
75 } | |
76 | |
77 void CompilerDispatcherJob::Parse() { | |
78 DCHECK(can_parse_on_background_thread_ || | |
79 ThreadId::Current().Equals(isolate_->thread_id())); | |
80 DCHECK(status() == CompileJobStatus::kReadyToParse); | |
vogelheim
2016/07/29 10:19:56
I don't understand the concurrency model.
- You'v
jochen (gone - plz use gerrit)
2016/07/29 10:27:45
Yeah, I guess I can make it non-atomic and just in
| |
81 | |
82 DisallowHeapAllocation no_allocation; | |
83 DisallowHandleAllocation no_handles; | |
84 DisallowHandleDereference no_deref; | |
85 | |
86 // Nullify the Isolate temporarily so that the parser doesn't accidentally | |
87 // use it. | |
88 parse_info_->set_isolate(nullptr); | |
89 | |
90 uintptr_t stack_limit = | |
91 reinterpret_cast<uintptr_t>(&stack_limit) - max_stack_size_ * KB; | |
92 | |
93 parser_->set_stack_limit(stack_limit); | |
94 parser_->ParseOnBackground(parse_info_.get()); | |
95 | |
96 parse_info_->set_isolate(isolate_); | |
97 | |
98 status_.SetValue(CompileJobStatus::kParsed); | |
60 } | 99 } |
61 | 100 |
62 } // namespace internal | 101 } // namespace internal |
63 } // namespace v8 | 102 } // namespace v8 |
OLD | NEW |