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

Side by Side Diff: test/unittests/api/isolate-unittest.cc

Issue 2682033002: React immediately to memory pressure on foreground threads (Closed)
Patch Set: updates Created 3 years, 10 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/BUILD.gn ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "testing/gtest/include/gtest/gtest.h"
6
7 #include "include/libplatform/libplatform.h"
8 #include "include/v8-platform.h"
9 #include "include/v8.h"
10 #include "src/base/macros.h"
11 #include "src/base/platform/semaphore.h"
12 #include "src/execution.h"
13 #include "src/isolate.h"
14 #include "src/v8.h"
15 #include "test/unittests/test-utils.h"
16
17 namespace v8 {
18
19 typedef TestWithIsolate IsolateTest;
20
21 namespace {
22
23 class MemoryPressureTask : public v8::Task {
24 public:
25 MemoryPressureTask(Isolate* isolate, base::Semaphore* semaphore)
26 : isolate_(isolate), semaphore_(semaphore) {}
27 ~MemoryPressureTask() override = default;
28
29 // v8::Task implementation.
30 void Run() override {
31 isolate_->MemoryPressureNotification(MemoryPressureLevel::kCritical);
32 semaphore_->Signal();
33 }
34
35 private:
36 Isolate* isolate_;
37 base::Semaphore* semaphore_;
38
39 DISALLOW_COPY_AND_ASSIGN(MemoryPressureTask);
40 };
41
42 } // namespace
43
44 // Check that triggering a memory pressure notification on the isolate thread
45 // doesn't request a GC interrupt.
46 TEST_F(IsolateTest, MemoryPressureNotificationForeground) {
47 Isolate::Scope isolate_scope(isolate());
48
49 internal::Isolate* i_isolate =
50 reinterpret_cast<internal::Isolate*>(isolate());
51
52 ASSERT_FALSE(i_isolate->stack_guard()->CheckGC());
53 isolate()->MemoryPressureNotification(MemoryPressureLevel::kCritical);
54 ASSERT_FALSE(i_isolate->stack_guard()->CheckGC());
55 }
56
57 // Check that triggering a memory pressure notification on an background thread
58 // requests a GC interrupt.
59 TEST_F(IsolateTest, MemoryPressureNotificationBackground) {
60 Isolate::Scope isolate_scope(isolate());
61
62 internal::Isolate* i_isolate =
63 reinterpret_cast<internal::Isolate*>(isolate());
64
65 base::Semaphore semaphore(0);
66
67 internal::V8::GetCurrentPlatform()->CallOnBackgroundThread(
68 new MemoryPressureTask(isolate(), &semaphore),
69 v8::Platform::kShortRunningTask);
70
71 semaphore.Wait();
72
73 ASSERT_TRUE(i_isolate->stack_guard()->CheckGC());
74 v8::platform::PumpMessageLoop(internal::V8::GetCurrentPlatform(), isolate());
75 }
76
77 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/BUILD.gn ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698