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 <memory> | 5 #include <memory> |
6 | 6 |
7 #include "include/v8.h" | 7 #include "include/v8.h" |
8 #include "src/api.h" | 8 #include "src/api.h" |
9 #include "src/ast/ast.h" | 9 #include "src/ast/ast.h" |
10 #include "src/ast/scopes.h" | 10 #include "src/ast/scopes.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( | 105 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( |
106 i_isolate(), tracer(), CreateSharedFunctionInfo(i_isolate(), nullptr), | 106 i_isolate(), tracer(), CreateSharedFunctionInfo(i_isolate(), nullptr), |
107 FLAG_stack_size)); | 107 FLAG_stack_size)); |
108 | 108 |
109 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial); | 109 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial); |
110 job->PrepareToParseOnMainThread(); | 110 job->PrepareToParseOnMainThread(); |
111 ASSERT_TRUE(job->status() == CompileJobStatus::kReadyToParse); | 111 ASSERT_TRUE(job->status() == CompileJobStatus::kReadyToParse); |
112 job->Parse(); | 112 job->Parse(); |
113 ASSERT_TRUE(job->status() == CompileJobStatus::kParsed); | 113 ASSERT_TRUE(job->status() == CompileJobStatus::kParsed); |
114 ASSERT_TRUE(job->FinalizeParsingOnMainThread()); | 114 ASSERT_TRUE(job->FinalizeParsingOnMainThread()); |
115 ASSERT_TRUE(job->status() == CompileJobStatus::kReadyToAnalyze); | 115 ASSERT_TRUE(job->status() == CompileJobStatus::kReadyToAnalyse); |
116 ASSERT_TRUE(job->AnalyzeOnMainThread()); | |
117 ASSERT_TRUE(job->status() == CompileJobStatus::kAnalyzed); | |
118 ASSERT_TRUE(job->PrepareToCompileOnMainThread()); | 116 ASSERT_TRUE(job->PrepareToCompileOnMainThread()); |
119 ASSERT_TRUE(job->status() == CompileJobStatus::kReadyToCompile); | 117 ASSERT_TRUE(job->status() == CompileJobStatus::kReadyToCompile); |
120 job->Compile(); | 118 job->Compile(); |
121 ASSERT_TRUE(job->status() == CompileJobStatus::kCompiled); | 119 ASSERT_TRUE(job->status() == CompileJobStatus::kCompiled); |
122 ASSERT_TRUE(job->FinalizeCompilingOnMainThread()); | 120 ASSERT_TRUE(job->FinalizeCompilingOnMainThread()); |
123 ASSERT_TRUE(job->status() == CompileJobStatus::kDone); | 121 ASSERT_TRUE(job->status() == CompileJobStatus::kDone); |
124 job->ResetOnMainThread(); | 122 job->ResetOnMainThread(); |
125 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial); | 123 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial); |
126 } | 124 } |
127 | 125 |
(...skipping 20 matching lines...) Expand all Loading... |
148 "function g() { var y = 1; function f(x) { return x * y }; return f; } " | 146 "function g() { var y = 1; function f(x) { return x * y }; return f; } " |
149 "g();"; | 147 "g();"; |
150 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); | 148 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); |
151 | 149 |
152 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( | 150 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( |
153 i_isolate(), tracer(), handle(f->shared()), FLAG_stack_size)); | 151 i_isolate(), tracer(), handle(f->shared()), FLAG_stack_size)); |
154 | 152 |
155 job->PrepareToParseOnMainThread(); | 153 job->PrepareToParseOnMainThread(); |
156 job->Parse(); | 154 job->Parse(); |
157 ASSERT_TRUE(job->FinalizeParsingOnMainThread()); | 155 ASSERT_TRUE(job->FinalizeParsingOnMainThread()); |
158 ASSERT_TRUE(job->AnalyzeOnMainThread()); | |
159 ASSERT_TRUE(job->PrepareToCompileOnMainThread()); | 156 ASSERT_TRUE(job->PrepareToCompileOnMainThread()); |
160 ASSERT_TRUE(job->status() == CompileJobStatus::kReadyToCompile); | 157 ASSERT_TRUE(job->status() == CompileJobStatus::kReadyToCompile); |
161 | 158 |
162 const AstRawString* var_x = | 159 const AstRawString* var_x = |
163 job->parse_info_->ast_value_factory()->GetOneByteString("x"); | 160 job->parse_info_->ast_value_factory()->GetOneByteString("x"); |
164 Variable* var = job->parse_info_->literal()->scope()->Lookup(var_x); | 161 Variable* var = job->parse_info_->literal()->scope()->Lookup(var_x); |
165 ASSERT_TRUE(var); | 162 ASSERT_TRUE(var); |
166 ASSERT_TRUE(var->IsParameter()); | 163 ASSERT_TRUE(var->IsParameter()); |
167 | 164 |
168 const AstRawString* var_y = | 165 const AstRawString* var_y = |
(...skipping 16 matching lines...) Expand all Loading... |
185 " return f;\n" | 182 " return f;\n" |
186 "}\n" | 183 "}\n" |
187 "g();"; | 184 "g();"; |
188 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); | 185 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); |
189 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( | 186 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( |
190 i_isolate(), tracer(), handle(f->shared()), FLAG_stack_size)); | 187 i_isolate(), tracer(), handle(f->shared()), FLAG_stack_size)); |
191 | 188 |
192 job->PrepareToParseOnMainThread(); | 189 job->PrepareToParseOnMainThread(); |
193 job->Parse(); | 190 job->Parse(); |
194 job->FinalizeParsingOnMainThread(); | 191 job->FinalizeParsingOnMainThread(); |
195 job->AnalyzeOnMainThread(); | |
196 job->PrepareToCompileOnMainThread(); | 192 job->PrepareToCompileOnMainThread(); |
197 job->Compile(); | 193 job->Compile(); |
198 ASSERT_TRUE(job->FinalizeCompilingOnMainThread()); | 194 ASSERT_TRUE(job->FinalizeCompilingOnMainThread()); |
199 ASSERT_TRUE(job->status() == CompileJobStatus::kDone); | 195 ASSERT_TRUE(job->status() == CompileJobStatus::kDone); |
200 | 196 |
201 Smi* value = Smi::cast(*RunJS(isolate(), "f(100);")); | 197 Smi* value = Smi::cast(*RunJS(isolate(), "f(100);")); |
202 ASSERT_TRUE(value == Smi::FromInt(160)); | 198 ASSERT_TRUE(value == Smi::FromInt(160)); |
203 | 199 |
204 job->ResetOnMainThread(); | 200 job->ResetOnMainThread(); |
205 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial); | 201 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial); |
206 } | 202 } |
207 | 203 |
208 TEST_F(CompilerDispatcherJobTest, CompileFailureToAnalyse) { | 204 TEST_F(CompilerDispatcherJobTest, CompileFailureToPrepare) { |
209 std::string raw_script("() { var a = "); | 205 std::string raw_script("() { var a = "); |
210 for (int i = 0; i < 100000; i++) { | 206 for (int i = 0; i < 100000; i++) { |
211 raw_script += "'x' + "; | 207 raw_script += "'x' + "; |
212 } | 208 } |
213 raw_script += " 'x'; }"; | 209 raw_script += " 'x'; }"; |
214 ScriptResource script(raw_script.c_str(), strlen(raw_script.c_str())); | 210 ScriptResource script(raw_script.c_str(), strlen(raw_script.c_str())); |
215 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( | 211 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( |
216 i_isolate(), tracer(), CreateSharedFunctionInfo(i_isolate(), &script), | 212 i_isolate(), tracer(), CreateSharedFunctionInfo(i_isolate(), &script), |
217 100)); | 213 100)); |
218 | 214 |
219 job->PrepareToParseOnMainThread(); | 215 job->PrepareToParseOnMainThread(); |
220 job->Parse(); | 216 job->Parse(); |
221 job->FinalizeParsingOnMainThread(); | 217 job->FinalizeParsingOnMainThread(); |
222 ASSERT_FALSE(job->AnalyzeOnMainThread()); | 218 ASSERT_FALSE(job->PrepareToCompileOnMainThread()); |
223 ASSERT_TRUE(job->status() == CompileJobStatus::kFailed); | 219 ASSERT_TRUE(job->status() == CompileJobStatus::kFailed); |
224 ASSERT_TRUE(i_isolate()->has_pending_exception()); | 220 ASSERT_TRUE(i_isolate()->has_pending_exception()); |
225 | 221 |
226 i_isolate()->clear_pending_exception(); | 222 i_isolate()->clear_pending_exception(); |
227 job->ResetOnMainThread(); | 223 job->ResetOnMainThread(); |
228 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial); | 224 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial); |
229 } | 225 } |
230 | 226 |
231 TEST_F(CompilerDispatcherJobTest, CompileFailureToFinalize) { | 227 TEST_F(CompilerDispatcherJobTest, CompileFailureToFinalize) { |
232 std::string raw_script("() { var a = "); | 228 std::string raw_script("() { var a = "); |
233 for (int i = 0; i < 1000; i++) { | 229 for (int i = 0; i < 1000; i++) { |
234 raw_script += "'x' + "; | 230 raw_script += "'x' + "; |
235 } | 231 } |
236 raw_script += " 'x'; }"; | 232 raw_script += " 'x'; }"; |
237 ScriptResource script(raw_script.c_str(), strlen(raw_script.c_str())); | 233 ScriptResource script(raw_script.c_str(), strlen(raw_script.c_str())); |
238 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( | 234 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( |
239 i_isolate(), tracer(), CreateSharedFunctionInfo(i_isolate(), &script), | 235 i_isolate(), tracer(), CreateSharedFunctionInfo(i_isolate(), &script), |
240 50)); | 236 50)); |
241 | 237 |
242 job->PrepareToParseOnMainThread(); | 238 job->PrepareToParseOnMainThread(); |
243 job->Parse(); | 239 job->Parse(); |
244 job->FinalizeParsingOnMainThread(); | 240 job->FinalizeParsingOnMainThread(); |
245 job->AnalyzeOnMainThread(); | |
246 job->PrepareToCompileOnMainThread(); | 241 job->PrepareToCompileOnMainThread(); |
247 job->Compile(); | 242 job->Compile(); |
248 ASSERT_FALSE(job->FinalizeCompilingOnMainThread()); | 243 ASSERT_FALSE(job->FinalizeCompilingOnMainThread()); |
249 ASSERT_TRUE(job->status() == CompileJobStatus::kFailed); | 244 ASSERT_TRUE(job->status() == CompileJobStatus::kFailed); |
250 ASSERT_TRUE(i_isolate()->has_pending_exception()); | 245 ASSERT_TRUE(i_isolate()->has_pending_exception()); |
251 | 246 |
252 i_isolate()->clear_pending_exception(); | 247 i_isolate()->clear_pending_exception(); |
253 job->ResetOnMainThread(); | 248 job->ResetOnMainThread(); |
254 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial); | 249 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial); |
255 } | 250 } |
(...skipping 24 matching lines...) Expand all Loading... |
280 " return bar;" | 275 " return bar;" |
281 "}"; | 276 "}"; |
282 ScriptResource script(raw_script, strlen(raw_script)); | 277 ScriptResource script(raw_script, strlen(raw_script)); |
283 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( | 278 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( |
284 i_isolate(), tracer(), CreateSharedFunctionInfo(i_isolate(), &script), | 279 i_isolate(), tracer(), CreateSharedFunctionInfo(i_isolate(), &script), |
285 100)); | 280 100)); |
286 | 281 |
287 job->PrepareToParseOnMainThread(); | 282 job->PrepareToParseOnMainThread(); |
288 job->Parse(); | 283 job->Parse(); |
289 job->FinalizeParsingOnMainThread(); | 284 job->FinalizeParsingOnMainThread(); |
290 job->AnalyzeOnMainThread(); | |
291 job->PrepareToCompileOnMainThread(); | 285 job->PrepareToCompileOnMainThread(); |
292 | 286 |
293 base::Semaphore semaphore(0); | 287 base::Semaphore semaphore(0); |
294 CompileTask* background_task = new CompileTask(job.get(), &semaphore); | 288 CompileTask* background_task = new CompileTask(job.get(), &semaphore); |
295 V8::GetCurrentPlatform()->CallOnBackgroundThread(background_task, | 289 V8::GetCurrentPlatform()->CallOnBackgroundThread(background_task, |
296 Platform::kShortRunningTask); | 290 Platform::kShortRunningTask); |
297 semaphore.Wait(); | 291 semaphore.Wait(); |
298 ASSERT_TRUE(job->FinalizeCompilingOnMainThread()); | 292 ASSERT_TRUE(job->FinalizeCompilingOnMainThread()); |
299 ASSERT_TRUE(job->status() == CompileJobStatus::kDone); | 293 ASSERT_TRUE(job->status() == CompileJobStatus::kDone); |
300 | 294 |
(...skipping 12 matching lines...) Expand all Loading... |
313 "}\n" | 307 "}\n" |
314 "g();"; | 308 "g();"; |
315 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); | 309 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); |
316 | 310 |
317 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( | 311 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( |
318 i_isolate(), tracer(), handle(f->shared()), FLAG_stack_size)); | 312 i_isolate(), tracer(), handle(f->shared()), FLAG_stack_size)); |
319 | 313 |
320 job->PrepareToParseOnMainThread(); | 314 job->PrepareToParseOnMainThread(); |
321 job->Parse(); | 315 job->Parse(); |
322 ASSERT_TRUE(job->FinalizeParsingOnMainThread()); | 316 ASSERT_TRUE(job->FinalizeParsingOnMainThread()); |
323 ASSERT_TRUE(job->AnalyzeOnMainThread()); | |
324 ASSERT_TRUE(job->PrepareToCompileOnMainThread()); | 317 ASSERT_TRUE(job->PrepareToCompileOnMainThread()); |
325 job->Compile(); | 318 job->Compile(); |
326 ASSERT_TRUE(job->FinalizeCompilingOnMainThread()); | 319 ASSERT_TRUE(job->FinalizeCompilingOnMainThread()); |
327 ASSERT_TRUE(job->status() == CompileJobStatus::kDone); | 320 ASSERT_TRUE(job->status() == CompileJobStatus::kDone); |
328 | 321 |
329 Handle<JSFunction> e = Handle<JSFunction>::cast(RunJS(isolate(), "f();")); | 322 Handle<JSFunction> e = Handle<JSFunction>::cast(RunJS(isolate(), "f();")); |
330 | 323 |
331 ASSERT_FALSE(e->shared()->HasBaselineCode()); | 324 ASSERT_FALSE(e->shared()->HasBaselineCode()); |
332 | 325 |
333 job->ResetOnMainThread(); | 326 job->ResetOnMainThread(); |
334 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial); | 327 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial); |
335 } | 328 } |
336 | 329 |
337 } // namespace internal | 330 } // namespace internal |
338 } // namespace v8 | 331 } // namespace v8 |
OLD | NEW |