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.h" | 5 #include "src/compiler-dispatcher/compiler-dispatcher.h" |
6 | 6 |
7 #include "include/v8-platform.h" | 7 #include "include/v8-platform.h" |
8 #include "src/base/platform/semaphore.h" | 8 #include "src/base/platform/semaphore.h" |
9 #include "src/compiler-dispatcher/compiler-dispatcher-job.h" | 9 #include "src/compiler-dispatcher/compiler-dispatcher-job.h" |
10 #include "src/compiler-dispatcher/compiler-dispatcher-tracer.h" | 10 #include "src/compiler-dispatcher/compiler-dispatcher-tracer.h" |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 } | 299 } |
300 script += " 'x'; }; return f5; } g();"; | 300 script += " 'x'; }; return f5; } g();"; |
301 Handle<JSFunction> f = | 301 Handle<JSFunction> f = |
302 Handle<JSFunction>::cast(RunJS(isolate(), script.c_str())); | 302 Handle<JSFunction>::cast(RunJS(isolate(), script.c_str())); |
303 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); | 303 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); |
304 | 304 |
305 ASSERT_FALSE(platform.IdleTaskPending()); | 305 ASSERT_FALSE(platform.IdleTaskPending()); |
306 ASSERT_TRUE(dispatcher.Enqueue(shared)); | 306 ASSERT_TRUE(dispatcher.Enqueue(shared)); |
307 ASSERT_TRUE(platform.IdleTaskPending()); | 307 ASSERT_TRUE(platform.IdleTaskPending()); |
308 | 308 |
309 // Idle tasks shouldn't leave exceptions behind. | |
310 v8::TryCatch try_catch(isolate()); | |
311 | |
312 // Since time doesn't progress on the MockPlatform, this is enough idle time | 309 // Since time doesn't progress on the MockPlatform, this is enough idle time |
313 // to finish compiling the function. | 310 // to finish compiling the function. |
314 platform.RunIdleTask(1000.0, 0.0); | 311 platform.RunIdleTask(1000.0, 0.0); |
315 | 312 |
316 ASSERT_FALSE(dispatcher.IsEnqueued(shared)); | 313 ASSERT_FALSE(dispatcher.IsEnqueued(shared)); |
317 ASSERT_FALSE(shared->is_compiled()); | 314 ASSERT_FALSE(shared->is_compiled()); |
318 ASSERT_FALSE(try_catch.HasCaught()); | 315 ASSERT_FALSE(i_isolate()->has_pending_exception()); |
319 } | 316 } |
320 | 317 |
321 TEST_F(IgnitionCompilerDispatcherTest, CompileOnBackgroundThread) { | 318 TEST_F(IgnitionCompilerDispatcherTest, CompileOnBackgroundThread) { |
322 MockPlatform platform; | 319 MockPlatform platform; |
323 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); | 320 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); |
324 | 321 |
325 const char script[] = | 322 const char script[] = |
326 "function g() { var y = 1; function f6(x) { return x * y }; return f6; } " | 323 "function g() { var y = 1; function f6(x) { return x * y }; return f6; } " |
327 "g();"; | 324 "g();"; |
328 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); | 325 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
397 platform.RunBackgroundTasks(V8::GetCurrentPlatform()); | 394 platform.RunBackgroundTasks(V8::GetCurrentPlatform()); |
398 | 395 |
399 ASSERT_TRUE(dispatcher.FinishNow(shared)); | 396 ASSERT_TRUE(dispatcher.FinishNow(shared)); |
400 // Finishing removes the SFI from the queue. | 397 // Finishing removes the SFI from the queue. |
401 ASSERT_FALSE(dispatcher.IsEnqueued(shared)); | 398 ASSERT_FALSE(dispatcher.IsEnqueued(shared)); |
402 ASSERT_TRUE(shared->is_compiled()); | 399 ASSERT_TRUE(shared->is_compiled()); |
403 if (platform.IdleTaskPending()) platform.ClearIdleTask(); | 400 if (platform.IdleTaskPending()) platform.ClearIdleTask(); |
404 ASSERT_FALSE(platform.BackgroundTasksPending()); | 401 ASSERT_FALSE(platform.BackgroundTasksPending()); |
405 } | 402 } |
406 | 403 |
404 TEST_F(CompilerDispatcherTest, IdleTaskMultipleJobs) { | |
405 MockPlatform platform; | |
406 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); | |
407 | |
408 const char script1[] = | |
409 "function g() { var y = 1; function f8(x) { return x * y }; return f8; } " | |
410 "g();"; | |
411 Handle<JSFunction> f1 = Handle<JSFunction>::cast(RunJS(isolate(), script1)); | |
412 Handle<SharedFunctionInfo> shared1(f1->shared(), i_isolate()); | |
413 | |
414 const char script2[] = | |
415 "function g() { var y = 1; function f9(x) { return x * y }; return f9; } " | |
416 "g();"; | |
417 Handle<JSFunction> f2 = Handle<JSFunction>::cast(RunJS(isolate(), script2)); | |
418 Handle<SharedFunctionInfo> shared2(f2->shared(), i_isolate()); | |
419 | |
420 ASSERT_FALSE(platform.IdleTaskPending()); | |
421 ASSERT_TRUE(dispatcher.Enqueue(shared1)); | |
422 ASSERT_TRUE(dispatcher.Enqueue(shared2)); | |
423 ASSERT_TRUE(platform.IdleTaskPending()); | |
424 | |
425 // Since time doesn't progress on the MockPlatform, this is enough idle time | |
426 // to finish compiling the function. | |
427 platform.RunIdleTask(1000.0, 0.0); | |
428 | |
429 ASSERT_FALSE(dispatcher.IsEnqueued(shared1)); | |
430 ASSERT_FALSE(dispatcher.IsEnqueued(shared2)); | |
431 ASSERT_TRUE(shared1->is_compiled()); | |
432 ASSERT_TRUE(shared2->is_compiled()); | |
433 } | |
434 | |
435 TEST_F(CompilerDispatcherTest, FinishNowException) { | |
436 MockPlatform platform; | |
437 CompilerDispatcher dispatcher(i_isolate(), &platform, 50); | |
vogelheim
2017/01/04 10:08:49
For my understanding: The point is to over-run an
jochen (gone - plz use gerrit)
2017/01/04 10:23:18
yes
we can't put a real syntax error here, becaus
| |
438 | |
439 std::string script("function g() { function f10(x) { var a = "); | |
440 for (int i = 0; i < 1000; i++) { | |
441 script += "'x' + "; | |
442 } | |
443 script += " 'x'; }; return f10; } g();"; | |
444 Handle<JSFunction> f = | |
445 Handle<JSFunction>::cast(RunJS(isolate(), script.c_str())); | |
446 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); | |
447 | |
448 ASSERT_FALSE(platform.IdleTaskPending()); | |
449 ASSERT_TRUE(dispatcher.Enqueue(shared)); | |
450 ASSERT_TRUE(platform.IdleTaskPending()); | |
451 | |
452 ASSERT_FALSE(dispatcher.FinishNow(shared)); | |
453 | |
454 ASSERT_FALSE(dispatcher.IsEnqueued(shared)); | |
455 ASSERT_FALSE(shared->is_compiled()); | |
456 ASSERT_TRUE(i_isolate()->has_pending_exception()); | |
457 | |
458 i_isolate()->clear_pending_exception(); | |
459 platform.ClearIdleTask(); | |
460 } | |
461 | |
407 } // namespace internal | 462 } // namespace internal |
408 } // namespace v8 | 463 } // namespace v8 |
OLD | NEW |