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/assert-scope.h" |
8 #include "src/global-handles.h" | 8 #include "src/global-handles.h" |
9 #include "src/isolate.h" | 9 #include "src/isolate.h" |
10 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
(...skipping 28 matching lines...) Expand all Loading... | |
39 void CompilerDispatcherJob::PrepareToParseOnMainThread() { | 39 void CompilerDispatcherJob::PrepareToParseOnMainThread() { |
40 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | 40 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); |
41 DCHECK(status() == CompileJobStatus::kInitial); | 41 DCHECK(status() == CompileJobStatus::kInitial); |
42 HandleScope scope(isolate_); | 42 HandleScope scope(isolate_); |
43 unicode_cache_.reset(new UnicodeCache()); | 43 unicode_cache_.reset(new UnicodeCache()); |
44 zone_.reset(new Zone(isolate_->allocator())); | 44 zone_.reset(new Zone(isolate_->allocator())); |
45 Handle<SharedFunctionInfo> shared(function_->shared(), isolate_); | 45 Handle<SharedFunctionInfo> shared(function_->shared(), isolate_); |
46 Handle<Script> script(Script::cast(shared->script()), isolate_); | 46 Handle<Script> script(Script::cast(shared->script()), isolate_); |
47 Handle<String> source(String::cast(script->source()), isolate_); | 47 Handle<String> source(String::cast(script->source()), isolate_); |
48 if (source->IsExternalTwoByteString()) { | 48 if (source->IsExternalTwoByteString()) { |
49 can_parse_on_background_thread_ = true; | |
50 character_stream_.reset(new ExternalTwoByteStringUtf16CharacterStream( | 49 character_stream_.reset(new ExternalTwoByteStringUtf16CharacterStream( |
51 Handle<ExternalTwoByteString>::cast(source), shared->start_position(), | 50 Handle<ExternalTwoByteString>::cast(source), shared->start_position(), |
52 shared->end_position())); | 51 shared->end_position())); |
53 } else if (source->IsExternalOneByteString()) { | 52 } else if (source->IsExternalOneByteString()) { |
54 can_parse_on_background_thread_ = true; | |
55 character_stream_.reset(new ExternalOneByteStringUtf16CharacterStream( | 53 character_stream_.reset(new ExternalOneByteStringUtf16CharacterStream( |
56 Handle<ExternalOneByteString>::cast(source), shared->start_position(), | 54 Handle<ExternalOneByteString>::cast(source), shared->start_position(), |
57 shared->end_position())); | 55 shared->end_position())); |
58 } else { | 56 } else { |
59 can_parse_on_background_thread_ = false; | 57 source = String::Flatten(source); |
vogelheim
2016/07/29 12:46:18
If the variable is no longer used, pls remove from
| |
58 source_ = Handle<String>::cast(isolate_->global_handles()->Create(*source)); | |
jochen (gone - plz use gerrit)
2016/07/29 12:23:31
have to globalize the reference here, so it surviv
marja
2016/08/01 07:50:24
How about putting this comment into the source cod
| |
60 character_stream_.reset(new GenericStringUtf16CharacterStream( | 59 character_stream_.reset(new GenericStringUtf16CharacterStream( |
61 source, shared->start_position(), shared->end_position())); | 60 source_, shared->start_position(), shared->end_position())); |
62 } | 61 } |
63 parse_info_.reset(new ParseInfo(zone_.get())); | 62 parse_info_.reset(new ParseInfo(zone_.get())); |
64 parse_info_->set_isolate(isolate_); | 63 parse_info_->set_isolate(isolate_); |
65 parse_info_->set_character_stream(character_stream_.get()); | 64 parse_info_->set_character_stream(character_stream_.get()); |
66 parse_info_->set_hash_seed(isolate_->heap()->HashSeed()); | 65 parse_info_->set_hash_seed(isolate_->heap()->HashSeed()); |
67 parse_info_->set_unicode_cache(unicode_cache_.get()); | 66 parse_info_->set_unicode_cache(unicode_cache_.get()); |
68 parser_.reset(new Parser(parse_info_.get())); | 67 parser_.reset(new Parser(parse_info_.get())); |
69 status_ = CompileJobStatus::kReadyToParse; | 68 status_ = CompileJobStatus::kReadyToParse; |
70 } | 69 } |
71 | 70 |
(...skipping 14 matching lines...) Expand all Loading... | |
86 reinterpret_cast<uintptr_t>(&stack_limit) - max_stack_size_ * KB; | 85 reinterpret_cast<uintptr_t>(&stack_limit) - max_stack_size_ * KB; |
87 | 86 |
88 parser_->set_stack_limit(stack_limit); | 87 parser_->set_stack_limit(stack_limit); |
89 parser_->ParseOnBackground(parse_info_.get()); | 88 parser_->ParseOnBackground(parse_info_.get()); |
90 | 89 |
91 parse_info_->set_isolate(isolate_); | 90 parse_info_->set_isolate(isolate_); |
92 | 91 |
93 status_ = CompileJobStatus::kParsed; | 92 status_ = CompileJobStatus::kParsed; |
94 } | 93 } |
95 | 94 |
95 void CompilerDispatcherJob::FinalizeParsingOnMainThread() { | |
96 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | |
97 DCHECK(status() == CompileJobStatus::kParsed); | |
98 | |
99 if (!source_.is_null()) { | |
100 i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location()); | |
101 } | |
102 | |
103 if (parse_info_->literal() == nullptr) { | |
104 status_ = CompileJobStatus::kFailed; | |
105 return; | |
106 } | |
107 | |
108 InternalizeParsingResult(); | |
109 | |
110 status_ = CompileJobStatus::kReadyToCompile; | |
111 } | |
112 | |
113 void CompilerDispatcherJob::ReportErrorsOnMainThread() { | |
114 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | |
115 DCHECK(status() == CompileJobStatus::kFailed); | |
116 | |
117 // Internalizing the parsing result will throw the error. | |
118 InternalizeParsingResult(); | |
119 | |
120 status_ = CompileJobStatus::kDone; | |
121 } | |
122 | |
123 void CompilerDispatcherJob::InternalizeParsingResult() { | |
124 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | |
125 DCHECK(status() == CompileJobStatus::kParsed || | |
126 status() == CompileJobStatus::kFailed); | |
127 | |
128 HandleScope scope(isolate_); | |
129 Handle<SharedFunctionInfo> shared(function_->shared(), isolate_); | |
130 Handle<Script> script(Script::cast(shared->script()), isolate_); | |
131 | |
132 parse_info_->set_script(script); | |
133 parse_info_->set_context(handle(function_->context(), isolate_)); | |
134 | |
135 // Do the parsing tasks which need to be done on the main thread. This will | |
136 // also handle parse errors. | |
137 parser_->Internalize(isolate_, script, parse_info_->literal() == nullptr); | |
138 parser_->HandleSourceURLComments(isolate_, script); | |
139 | |
140 parse_info_->set_character_stream(nullptr); | |
141 parse_info_->set_unicode_cache(nullptr); | |
142 parser_.reset(); | |
143 unicode_cache_.reset(); | |
144 character_stream_.reset(); | |
vogelheim
2016/07/29 12:46:18
[general comment:]
Since this class handles more
jochen (gone - plz use gerrit)
2016/07/29 12:49:42
yeah, that makes sense
| |
145 } | |
146 | |
96 } // namespace internal | 147 } // namespace internal |
97 } // namespace v8 | 148 } // namespace v8 |
OLD | NEW |