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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler-dispatcher/compiler-dispatcher.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/unittests/compiler-dispatcher/compiler-dispatcher-unittest.cc
diff --git a/test/unittests/compiler-dispatcher/compiler-dispatcher-unittest.cc b/test/unittests/compiler-dispatcher/compiler-dispatcher-unittest.cc
index d9d09b4fb6bbc5690f0c04cbe10679875203aca3..1e4023c4edce9c75106f38b8a98bbf9cfe68008b 100644
--- a/test/unittests/compiler-dispatcher/compiler-dispatcher-unittest.cc
+++ b/test/unittests/compiler-dispatcher/compiler-dispatcher-unittest.cc
@@ -714,5 +714,88 @@ TEST_F(IgnitionCompilerDispatcherTest, FinishNowDuringAbortAll) {
platform.ClearIdleTask();
}
+TEST_F(CompilerDispatcherTest, MemoryPressure) {
+ MockPlatform platform;
+ CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
+
+ const char script[] =
+ "function g() { var y = 1; function f14(x) { return x * y }; return f14; "
+ "} g();";
+ Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script));
+ Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
+
+ // Can't enqueue tasks under memory pressure.
+ dispatcher.MemoryPressureNotification(v8::MemoryPressureLevel::kCritical,
+ true);
+ ASSERT_FALSE(dispatcher.Enqueue(shared));
+
+ dispatcher.MemoryPressureNotification(v8::MemoryPressureLevel::kNone, true);
+ ASSERT_TRUE(dispatcher.Enqueue(shared));
+
+ // Memory pressure cancels current jobs.
+ dispatcher.MemoryPressureNotification(v8::MemoryPressureLevel::kCritical,
+ true);
+ ASSERT_FALSE(dispatcher.IsEnqueued(shared));
+ platform.ClearIdleTask();
+}
+
+namespace {
+
+class PressureNotificationTask : public CancelableTask {
+ public:
+ PressureNotificationTask(Isolate* isolate, CompilerDispatcher* dispatcher,
+ base::Semaphore* sem)
+ : CancelableTask(isolate), dispatcher_(dispatcher), sem_(sem) {}
+ ~PressureNotificationTask() override {}
+
+ void RunInternal() override {
+ dispatcher_->MemoryPressureNotification(v8::MemoryPressureLevel::kCritical,
+ false);
+ sem_->Signal();
+ }
+
+ private:
+ CompilerDispatcher* dispatcher_;
+ base::Semaphore* sem_;
+
+ DISALLOW_COPY_AND_ASSIGN(PressureNotificationTask);
+};
+
+} // namespace
+
+TEST_F(CompilerDispatcherTest, MemoryPressureFromBackground) {
+ MockPlatform platform;
+ CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
+
+ const char script[] =
+ "function g() { var y = 1; function f15(x) { return x * y }; return f15; "
+ "} g();";
+ Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script));
+ Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
+
+ ASSERT_TRUE(dispatcher.Enqueue(shared));
+ base::Semaphore sem(0);
+ V8::GetCurrentPlatform()->CallOnBackgroundThread(
+ new PressureNotificationTask(i_isolate(), &dispatcher, &sem),
+ v8::Platform::kShortRunningTask);
+
+ sem.Wait();
+
+ // A memory pressure task is pending, and running it will cancel the job.
+ ASSERT_TRUE(platform.ForegroundTasksPending());
+ ASSERT_TRUE(dispatcher.IsEnqueued(shared));
+ platform.RunForegroundTasks();
+ ASSERT_FALSE(dispatcher.IsEnqueued(shared));
+ ASSERT_FALSE(shared->is_compiled());
+
+ // Since the AbortAll() call is made from a task, AbortAll thinks that there
+ // is at least one task running, and fires of an AbortTask to be safe.
+ ASSERT_TRUE(platform.ForegroundTasksPending());
+ platform.RunForegroundTasks();
+ ASSERT_FALSE(platform.ForegroundTasksPending());
+
+ platform.ClearIdleTask();
+}
+
} // namespace internal
} // namespace v8
« 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