OLD | NEW |
(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 |
OLD | NEW |