Commit 72bad21c authored by jochen's avatar jochen Committed by Commit bot

React immediately to memory pressure on foreground threads

R=marja@chromium.org
BUG=

Review-Url: https://codereview.chromium.org/2682033002
Cr-Commit-Position: refs/heads/master@{#43027}
parent c78d7fa1
......@@ -8555,10 +8555,14 @@ void Isolate::IsolateInBackgroundNotification() {
void Isolate::MemoryPressureNotification(MemoryPressureLevel level) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
isolate->heap()->MemoryPressureNotification(level, Locker::IsLocked(this));
bool on_isolate_thread =
v8::Locker::IsActive()
? isolate->thread_manager()->IsLockedByCurrentThread()
: i::ThreadId::Current().Equals(isolate->thread_id());
isolate->heap()->MemoryPressureNotification(level, on_isolate_thread);
isolate->allocator()->MemoryPressureNotification(level);
isolate->compiler_dispatcher()->MemoryPressureNotification(
level, Locker::IsLocked(this));
isolate->compiler_dispatcher()->MemoryPressureNotification(level,
on_isolate_thread);
}
void Isolate::SetRAILMode(RAILMode rail_mode) {
......
......@@ -7,6 +7,7 @@
#include "src/allocation.h"
#include "src/base/atomicops.h"
#include "src/globals.h"
#include "src/utils.h"
namespace v8 {
......@@ -63,7 +64,7 @@ class PostponeInterruptsScope;
// StackGuard contains the handling of the limits that are used to limit the
// number of nested invocations of JavaScript and the stack size used in each
// invocation.
class StackGuard final {
class V8_EXPORT_PRIVATE StackGuard final {
public:
// Pass the address beyond which the stack should not grow. The stack
// is assumed to grow downwards.
......
......@@ -10,6 +10,7 @@ v8_executable("unittests") {
sources = [
"../../testing/gmock-support.h",
"../../testing/gtest-support.h",
"api/isolate-unittest.cc",
"base/atomic-utils-unittest.cc",
"base/bits-unittest.cc",
"base/cpu-unittest.cc",
......
// 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/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) {
Isolate::Scope isolate_scope(isolate());
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) {
Isolate::Scope isolate_scope(isolate());
internal::Isolate* i_isolate =
reinterpret_cast<internal::Isolate*>(isolate());
base::Semaphore semaphore(0);
internal::V8::GetCurrentPlatform()->CallOnBackgroundThread(
new MemoryPressureTask(isolate(), &semaphore),
v8::Platform::kShortRunningTask);
semaphore.Wait();
ASSERT_TRUE(i_isolate->stack_guard()->CheckGC());
v8::platform::PumpMessageLoop(internal::V8::GetCurrentPlatform(), isolate());
}
} // namespace v8
......@@ -8,6 +8,7 @@
'variables': {
'v8_code': 1,
'unittests_sources': [ ### gcmole(all) ###
'api/isolate-unittest.cc',
'base/atomic-utils-unittest.cc',
'base/bits-unittest.cc',
'base/cpu-unittest.cc',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment