Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(231)

Side by Side Diff: test/unittests/compiler-dispatcher/compiler-dispatcher-unittest.cc

Issue 2625413004: [compiler-dispatcher] make it so that we can always parse on bg threads (Closed)
Patch Set: updates Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/unittests/compiler-dispatcher/compiler-dispatcher-job-unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "src/flags.h" 11 #include "src/flags.h"
12 #include "src/handles.h" 12 #include "src/handles.h"
13 #include "src/objects-inl.h" 13 #include "src/objects-inl.h"
14 #include "src/v8.h" 14 #include "src/v8.h"
15 #include "test/unittests/compiler-dispatcher/compiler-dispatcher-helper.h" 15 #include "test/unittests/compiler-dispatcher/compiler-dispatcher-helper.h"
16 #include "test/unittests/test-utils.h" 16 #include "test/unittests/test-utils.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 namespace v8 { 19 namespace v8 {
20 namespace internal { 20 namespace internal {
21 21
22 class CompilerDispatcherTest : public TestWithContext { 22 class CompilerDispatcherTest : public TestWithContext {
23 public: 23 public:
24 CompilerDispatcherTest() = default; 24 CompilerDispatcherTest() = default;
25 ~CompilerDispatcherTest() override = default; 25 ~CompilerDispatcherTest() override = default;
26 26
27 static void SetUpTestCase() { 27 static void SetUpTestCase() {
28 old_flag_ = i::FLAG_ignition; 28 old_flag_ = i::FLAG_ignition;
29 i::FLAG_compiler_dispatcher = true; 29 i::FLAG_compiler_dispatcher = true;
30 old_ignition_flag_ = i::FLAG_ignition;
31 i::FLAG_ignition = true;
30 TestWithContext::SetUpTestCase(); 32 TestWithContext::SetUpTestCase();
31 } 33 }
32 34
33 static void TearDownTestCase() { 35 static void TearDownTestCase() {
34 TestWithContext::TearDownTestCase(); 36 TestWithContext::TearDownTestCase();
35 i::FLAG_compiler_dispatcher = old_flag_; 37 i::FLAG_compiler_dispatcher = old_flag_;
38 i::FLAG_ignition = old_ignition_flag_;
36 } 39 }
37 40
38 private: 41 private:
39 static bool old_flag_; 42 static bool old_flag_;
43 static bool old_ignition_flag_;
40 44
41 DISALLOW_COPY_AND_ASSIGN(CompilerDispatcherTest); 45 DISALLOW_COPY_AND_ASSIGN(CompilerDispatcherTest);
42 }; 46 };
43 47
44 bool CompilerDispatcherTest::old_flag_; 48 bool CompilerDispatcherTest::old_flag_;
45 49 bool CompilerDispatcherTest::old_ignition_flag_;
46 class IgnitionCompilerDispatcherTest : public CompilerDispatcherTest {
47 public:
48 IgnitionCompilerDispatcherTest() = default;
49 ~IgnitionCompilerDispatcherTest() override = default;
50
51 static void SetUpTestCase() {
52 old_flag_ = i::FLAG_ignition;
53 i::FLAG_ignition = true;
54 CompilerDispatcherTest::SetUpTestCase();
55 }
56
57 static void TearDownTestCase() {
58 CompilerDispatcherTest::TearDownTestCase();
59 i::FLAG_ignition = old_flag_;
60 }
61
62 private:
63 static bool old_flag_;
64 DISALLOW_COPY_AND_ASSIGN(IgnitionCompilerDispatcherTest);
65 };
66
67 bool IgnitionCompilerDispatcherTest::old_flag_;
68 50
69 namespace { 51 namespace {
70 52
71 class MockPlatform : public v8::Platform { 53 class MockPlatform : public v8::Platform {
72 public: 54 public:
73 MockPlatform() : time_(0.0), time_step_(0.0), idle_task_(nullptr), sem_(0) {} 55 MockPlatform() : time_(0.0), time_step_(0.0), idle_task_(nullptr), sem_(0) {}
74 ~MockPlatform() override { 56 ~MockPlatform() override {
75 base::LockGuard<base::Mutex> lock(&mutex_); 57 base::LockGuard<base::Mutex> lock(&mutex_);
76 EXPECT_TRUE(foreground_tasks_.empty()); 58 EXPECT_TRUE(foreground_tasks_.empty());
77 EXPECT_TRUE(background_tasks_.empty()); 59 EXPECT_TRUE(background_tasks_.empty());
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 348
367 // Since time doesn't progress on the MockPlatform, this is enough idle time 349 // Since time doesn't progress on the MockPlatform, this is enough idle time
368 // to finish compiling the function. 350 // to finish compiling the function.
369 platform.RunIdleTask(1000.0, 0.0); 351 platform.RunIdleTask(1000.0, 0.0);
370 352
371 ASSERT_FALSE(dispatcher.IsEnqueued(shared)); 353 ASSERT_FALSE(dispatcher.IsEnqueued(shared));
372 ASSERT_FALSE(shared->is_compiled()); 354 ASSERT_FALSE(shared->is_compiled());
373 ASSERT_FALSE(i_isolate()->has_pending_exception()); 355 ASSERT_FALSE(i_isolate()->has_pending_exception());
374 } 356 }
375 357
376 TEST_F(IgnitionCompilerDispatcherTest, CompileOnBackgroundThread) { 358 TEST_F(CompilerDispatcherTest, CompileOnBackgroundThread) {
377 MockPlatform platform; 359 MockPlatform platform;
378 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); 360 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
379 361
380 const char script[] = 362 const char script[] =
381 "function g() { var y = 1; function f6(x) { return x * y }; return f6; } " 363 "function g() { var y = 1; function f6(x) { return x * y }; return f6; } "
382 "g();"; 364 "g();";
383 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); 365 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script));
384 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); 366 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
385 367
386 ASSERT_FALSE(platform.IdleTaskPending()); 368 ASSERT_FALSE(platform.IdleTaskPending());
(...skipping 24 matching lines...) Expand all
411 CompileJobStatus::kCompiled); 393 CompileJobStatus::kCompiled);
412 394
413 // Now grant a lot of idle time and freeze time. 395 // Now grant a lot of idle time and freeze time.
414 platform.RunIdleTask(1000.0, 0.0); 396 platform.RunIdleTask(1000.0, 0.0);
415 397
416 ASSERT_FALSE(dispatcher.IsEnqueued(shared)); 398 ASSERT_FALSE(dispatcher.IsEnqueued(shared));
417 ASSERT_TRUE(shared->is_compiled()); 399 ASSERT_TRUE(shared->is_compiled());
418 ASSERT_FALSE(platform.IdleTaskPending()); 400 ASSERT_FALSE(platform.IdleTaskPending());
419 } 401 }
420 402
421 TEST_F(IgnitionCompilerDispatcherTest, FinishNowWithBackgroundTask) { 403 TEST_F(CompilerDispatcherTest, FinishNowWithBackgroundTask) {
422 MockPlatform platform; 404 MockPlatform platform;
423 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); 405 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
424 406
425 const char script[] = 407 const char script[] =
426 "function g() { var y = 1; function f7(x) { return x * y }; return f7; } " 408 "function g() { var y = 1; function f7(x) { return x * y }; return f7; } "
427 "g();"; 409 "g();";
428 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); 410 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script));
429 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); 411 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
430 412
431 ASSERT_FALSE(platform.IdleTaskPending()); 413 ASSERT_FALSE(platform.IdleTaskPending());
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 ASSERT_FALSE(dispatcher.FinishNow(shared)); 492 ASSERT_FALSE(dispatcher.FinishNow(shared));
511 493
512 ASSERT_FALSE(dispatcher.IsEnqueued(shared)); 494 ASSERT_FALSE(dispatcher.IsEnqueued(shared));
513 ASSERT_FALSE(shared->is_compiled()); 495 ASSERT_FALSE(shared->is_compiled());
514 ASSERT_TRUE(i_isolate()->has_pending_exception()); 496 ASSERT_TRUE(i_isolate()->has_pending_exception());
515 497
516 i_isolate()->clear_pending_exception(); 498 i_isolate()->clear_pending_exception();
517 platform.ClearIdleTask(); 499 platform.ClearIdleTask();
518 } 500 }
519 501
520 TEST_F(IgnitionCompilerDispatcherTest, AsyncAbortAllPendingBackgroundTask) { 502 TEST_F(CompilerDispatcherTest, AsyncAbortAllPendingBackgroundTask) {
521 MockPlatform platform; 503 MockPlatform platform;
522 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); 504 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
523 505
524 const char script[] = 506 const char script[] =
525 "function g() { var y = 1; function f11(x) { return x * y }; return f11; " 507 "function g() { var y = 1; function f11(x) { return x * y }; return f11; "
526 "} g();"; 508 "} g();";
527 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); 509 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script));
528 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); 510 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
529 511
530 ASSERT_FALSE(platform.IdleTaskPending()); 512 ASSERT_FALSE(platform.IdleTaskPending());
(...skipping 23 matching lines...) Expand all
554 ASSERT_FALSE(dispatcher.IsEnqueued(shared)); 536 ASSERT_FALSE(dispatcher.IsEnqueued(shared));
555 ASSERT_FALSE(shared->is_compiled()); 537 ASSERT_FALSE(shared->is_compiled());
556 538
557 platform.RunBackgroundTasksAndBlock(V8::GetCurrentPlatform()); 539 platform.RunBackgroundTasksAndBlock(V8::GetCurrentPlatform());
558 540
559 if (platform.IdleTaskPending()) platform.ClearIdleTask(); 541 if (platform.IdleTaskPending()) platform.ClearIdleTask();
560 ASSERT_FALSE(platform.BackgroundTasksPending()); 542 ASSERT_FALSE(platform.BackgroundTasksPending());
561 ASSERT_FALSE(platform.ForegroundTasksPending()); 543 ASSERT_FALSE(platform.ForegroundTasksPending());
562 } 544 }
563 545
564 TEST_F(IgnitionCompilerDispatcherTest, AsyncAbortAllRunningBackgroundTask) { 546 TEST_F(CompilerDispatcherTest, AsyncAbortAllRunningBackgroundTask) {
565 MockPlatform platform; 547 MockPlatform platform;
566 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); 548 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
567 549
568 const char script1[] = 550 const char script1[] =
569 "function g() { var y = 1; function f11(x) { return x * y }; return f11; " 551 "function g() { var y = 1; function f11(x) { return x * y }; return f11; "
570 "} g();"; 552 "} g();";
571 Handle<JSFunction> f1 = Handle<JSFunction>::cast(RunJS(isolate(), script1)); 553 Handle<JSFunction> f1 = Handle<JSFunction>::cast(RunJS(isolate(), script1));
572 Handle<SharedFunctionInfo> shared1(f1->shared(), i_isolate()); 554 Handle<SharedFunctionInfo> shared1(f1->shared(), i_isolate());
573 555
574 const char script2[] = 556 const char script2[] =
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 ASSERT_FALSE(platform.ForegroundTasksPending()); 620 ASSERT_FALSE(platform.ForegroundTasksPending());
639 621
640 // Now it's possible to enqueue new functions again. 622 // Now it's possible to enqueue new functions again.
641 ASSERT_TRUE(dispatcher.Enqueue(shared2)); 623 ASSERT_TRUE(dispatcher.Enqueue(shared2));
642 ASSERT_TRUE(platform.IdleTaskPending()); 624 ASSERT_TRUE(platform.IdleTaskPending());
643 ASSERT_FALSE(platform.BackgroundTasksPending()); 625 ASSERT_FALSE(platform.BackgroundTasksPending());
644 ASSERT_FALSE(platform.ForegroundTasksPending()); 626 ASSERT_FALSE(platform.ForegroundTasksPending());
645 platform.ClearIdleTask(); 627 platform.ClearIdleTask();
646 } 628 }
647 629
648 TEST_F(IgnitionCompilerDispatcherTest, FinishNowDuringAbortAll) { 630 TEST_F(CompilerDispatcherTest, FinishNowDuringAbortAll) {
649 MockPlatform platform; 631 MockPlatform platform;
650 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); 632 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
651 633
652 const char script[] = 634 const char script[] =
653 "function g() { var y = 1; function f13(x) { return x * y }; return f13; " 635 "function g() { var y = 1; function f13(x) { return x * y }; return f13; "
654 "} g();"; 636 "} g();";
655 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script)); 637 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script));
656 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); 638 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
657 639
658 ASSERT_FALSE(platform.IdleTaskPending()); 640 ASSERT_FALSE(platform.IdleTaskPending());
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 791
810 ASSERT_FALSE(dispatcher.IsEnqueued(shared)); 792 ASSERT_FALSE(dispatcher.IsEnqueued(shared));
811 ASSERT_TRUE(dispatcher.EnqueueAndStep(shared)); 793 ASSERT_TRUE(dispatcher.EnqueueAndStep(shared));
812 ASSERT_TRUE(dispatcher.IsEnqueued(shared)); 794 ASSERT_TRUE(dispatcher.IsEnqueued(shared));
813 795
814 ASSERT_TRUE(dispatcher.jobs_.begin()->second->status() == 796 ASSERT_TRUE(dispatcher.jobs_.begin()->second->status() ==
815 CompileJobStatus::kReadyToParse); 797 CompileJobStatus::kReadyToParse);
816 798
817 ASSERT_TRUE(platform.IdleTaskPending()); 799 ASSERT_TRUE(platform.IdleTaskPending());
818 platform.ClearIdleTask(); 800 platform.ClearIdleTask();
819 ASSERT_FALSE(platform.BackgroundTasksPending()); 801 ASSERT_TRUE(platform.BackgroundTasksPending());
802 platform.ClearBackgroundTasks();
820 } 803 }
821 804
822 } // namespace internal 805 } // namespace internal
823 } // namespace v8 806 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/compiler-dispatcher/compiler-dispatcher-job-unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698