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

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

Issue 2608163006: Abort running compiler dispatcher tasks under memory pressure (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 | « src/compiler-dispatcher/compiler-dispatcher.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"
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 ASSERT_FALSE(dispatcher.abort_); 707 ASSERT_FALSE(dispatcher.abort_);
708 } 708 }
709 709
710 ASSERT_TRUE(platform.ForegroundTasksPending()); 710 ASSERT_TRUE(platform.ForegroundTasksPending());
711 ASSERT_TRUE(platform.IdleTaskPending()); 711 ASSERT_TRUE(platform.IdleTaskPending());
712 ASSERT_FALSE(platform.BackgroundTasksPending()); 712 ASSERT_FALSE(platform.BackgroundTasksPending());
713 platform.ClearForegroundTasks(); 713 platform.ClearForegroundTasks();
714 platform.ClearIdleTask(); 714 platform.ClearIdleTask();
715 } 715 }
716 716
717 TEST_F(CompilerDispatcherTest, MemoryPressure) {
718 MockPlatform platform;
719 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
720
721 const char script[] =
722 "function g() { var y = 1; function f14(x) { return x * y }; return f14; "
723 "} g();";
724 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script));
725 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
726
727 // Can't enqueue tasks under memory pressure.
728 dispatcher.MemoryPressureNotification(v8::MemoryPressureLevel::kCritical,
729 true);
730 ASSERT_FALSE(dispatcher.Enqueue(shared));
731
732 dispatcher.MemoryPressureNotification(v8::MemoryPressureLevel::kNone, true);
733 ASSERT_TRUE(dispatcher.Enqueue(shared));
734
735 // Memory pressure cancels current jobs.
736 dispatcher.MemoryPressureNotification(v8::MemoryPressureLevel::kCritical,
737 true);
738 ASSERT_FALSE(dispatcher.IsEnqueued(shared));
739 platform.ClearIdleTask();
740 }
741
742 namespace {
743
744 class PressureNotificationTask : public CancelableTask {
745 public:
746 PressureNotificationTask(Isolate* isolate, CompilerDispatcher* dispatcher,
747 base::Semaphore* sem)
748 : CancelableTask(isolate), dispatcher_(dispatcher), sem_(sem) {}
749 ~PressureNotificationTask() override {}
750
751 void RunInternal() override {
752 dispatcher_->MemoryPressureNotification(v8::MemoryPressureLevel::kCritical,
753 false);
754 sem_->Signal();
755 }
756
757 private:
758 CompilerDispatcher* dispatcher_;
759 base::Semaphore* sem_;
760
761 DISALLOW_COPY_AND_ASSIGN(PressureNotificationTask);
762 };
763
764 } // namespace
765
766 TEST_F(CompilerDispatcherTest, MemoryPressureFromBackground) {
767 MockPlatform platform;
768 CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
769
770 const char script[] =
771 "function g() { var y = 1; function f15(x) { return x * y }; return f15; "
772 "} g();";
773 Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script));
774 Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
775
776 ASSERT_TRUE(dispatcher.Enqueue(shared));
777 base::Semaphore sem(0);
778 V8::GetCurrentPlatform()->CallOnBackgroundThread(
779 new PressureNotificationTask(i_isolate(), &dispatcher, &sem),
780 v8::Platform::kShortRunningTask);
781
782 sem.Wait();
783
784 // A memory pressure task is pending, and running it will cancel the job.
785 ASSERT_TRUE(platform.ForegroundTasksPending());
786 ASSERT_TRUE(dispatcher.IsEnqueued(shared));
787 platform.RunForegroundTasks();
788 ASSERT_FALSE(dispatcher.IsEnqueued(shared));
789 ASSERT_FALSE(shared->is_compiled());
790
791 // Since the AbortAll() call is made from a task, AbortAll thinks that there
792 // is at least one task running, and fires of an AbortTask to be safe.
793 ASSERT_TRUE(platform.ForegroundTasksPending());
794 platform.RunForegroundTasks();
795 ASSERT_FALSE(platform.ForegroundTasksPending());
796
797 platform.ClearIdleTask();
798 }
799
717 } // namespace internal 800 } // namespace internal
718 } // namespace v8 801 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler-dispatcher/compiler-dispatcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698