1983f3055d
This is done now while embedders have yet to adapt to the new API before it becomes hard to migrate. Also renamed variable/methods to use "worker threads" rather than "background" nomenclature. Extracted from https://chromium-review.googlesource.com/c/v8/v8/+/978443/7 while resolving the more contentious bits around using task runners. TBR=rmcilroy@chromium.org Bug: chromium:817421 Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng Change-Id: Ie3ddf15a708e829c0f718d89bebf3e96d1990c16 Reviewed-on: https://chromium-review.googlesource.com/980953 Commit-Queue: Gabriel Charette <gab@chromium.org> Reviewed-by: Gabriel Charette <gab@chromium.org> Cr-Commit-Position: refs/heads/master@{#52231}
74 lines
2.1 KiB
C++
74 lines
2.1 KiB
C++
// Copyright 2017 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
#include "include/libplatform/libplatform.h"
|
|
#include "include/v8-platform.h"
|
|
#include "include/v8.h"
|
|
#include "src/base/macros.h"
|
|
#include "src/base/platform/semaphore.h"
|
|
#include "src/base/template-utils.h"
|
|
#include "src/execution.h"
|
|
#include "src/isolate.h"
|
|
#include "src/v8.h"
|
|
#include "test/unittests/test-utils.h"
|
|
|
|
namespace v8 {
|
|
|
|
typedef TestWithIsolate IsolateTest;
|
|
|
|
namespace {
|
|
|
|
class MemoryPressureTask : public v8::Task {
|
|
public:
|
|
MemoryPressureTask(Isolate* isolate, base::Semaphore* semaphore)
|
|
: isolate_(isolate), semaphore_(semaphore) {}
|
|
~MemoryPressureTask() override = default;
|
|
|
|
// v8::Task implementation.
|
|
void Run() override {
|
|
isolate_->MemoryPressureNotification(MemoryPressureLevel::kCritical);
|
|
semaphore_->Signal();
|
|
}
|
|
|
|
private:
|
|
Isolate* isolate_;
|
|
base::Semaphore* semaphore_;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(MemoryPressureTask);
|
|
};
|
|
|
|
} // namespace
|
|
|
|
// Check that triggering a memory pressure notification on the isolate thread
|
|
// doesn't request a GC interrupt.
|
|
TEST_F(IsolateTest, MemoryPressureNotificationForeground) {
|
|
internal::Isolate* i_isolate =
|
|
reinterpret_cast<internal::Isolate*>(isolate());
|
|
|
|
ASSERT_FALSE(i_isolate->stack_guard()->CheckGC());
|
|
isolate()->MemoryPressureNotification(MemoryPressureLevel::kCritical);
|
|
ASSERT_FALSE(i_isolate->stack_guard()->CheckGC());
|
|
}
|
|
|
|
// Check that triggering a memory pressure notification on an background thread
|
|
// requests a GC interrupt.
|
|
TEST_F(IsolateTest, MemoryPressureNotificationBackground) {
|
|
internal::Isolate* i_isolate =
|
|
reinterpret_cast<internal::Isolate*>(isolate());
|
|
|
|
base::Semaphore semaphore(0);
|
|
|
|
internal::V8::GetCurrentPlatform()->CallOnWorkerThread(
|
|
base::make_unique<MemoryPressureTask>(isolate(), &semaphore));
|
|
|
|
semaphore.Wait();
|
|
|
|
ASSERT_TRUE(i_isolate->stack_guard()->CheckGC());
|
|
v8::platform::PumpMessageLoop(internal::V8::GetCurrentPlatform(), isolate());
|
|
}
|
|
|
|
} // namespace v8
|