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

Unified Diff: test/cctest/test-api.cc

Issue 1813963002: Add memory pressure notification API (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: GC interrupt on kModerate to start incremental marking Created 4 years, 9 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/heap/incremental-marking-job.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index b0369938846bd02ecdbeb631b527af1e489e30bb..481d269baf8a14bc33388931c52e06131ab79d3b 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -24856,3 +24856,71 @@ TEST(Proxy) {
CHECK(proxy->GetTarget()->SameValue(target));
CHECK(proxy->GetHandler()->IsNull());
}
+
+WeakCallCounterAndPersistent<Value>* CreateGarbageWithWeakCallCounter(
+ v8::Isolate* isolate, WeakCallCounter* counter) {
+ v8::Locker locker(isolate);
+ LocalContext env;
+ HandleScope scope(isolate);
+ WeakCallCounterAndPersistent<Value>* val =
+ new WeakCallCounterAndPersistent<Value>(counter);
+ val->handle.Reset(isolate, Object::New(isolate));
+ val->handle.SetWeak(val, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
+ return val;
+}
+
+class MemoryPressureThread : public v8::base::Thread {
+ public:
+ explicit MemoryPressureThread(v8::Isolate* isolate,
+ v8::MemoryPressureLevel level)
+ : Thread(Options("MemoryPressureThread")),
+ isolate_(isolate),
+ level_(level) {}
+
+ virtual void Run() { isolate_->MemoryPressureNotification(level_); }
+
+ private:
+ v8::Isolate* isolate_;
+ v8::MemoryPressureLevel level_;
+};
+
+TEST(MemoryPressure) {
+ v8::Isolate* isolate = CcTest::isolate();
+ WeakCallCounter counter(1234);
+
+ // Check that critical memory pressure notification sets GC interrupt.
+ auto garbage = CreateGarbageWithWeakCallCounter(isolate, &counter);
+ CHECK(!v8::Locker::IsLocked(isolate));
+ {
+ v8::Locker locker(isolate);
+ v8::HandleScope scope(isolate);
+ LocalContext env;
+ MemoryPressureThread memory_pressure_thread(
+ isolate, v8::MemoryPressureLevel::kCritical);
+ memory_pressure_thread.Start();
+ memory_pressure_thread.Join();
+ // This should trigger GC.
+ CHECK_EQ(0, counter.NumberOfWeakCalls());
+ CompileRun("(function noop() { return 0; })()");
+ CHECK_EQ(1, counter.NumberOfWeakCalls());
+ }
+ delete garbage;
+ // Check that critical memory pressure notification triggers GC.
+ garbage = CreateGarbageWithWeakCallCounter(isolate, &counter);
+ {
+ v8::Locker locker(isolate);
+ // If isolate is locked, memory pressure notification should trigger GC.
+ CHECK_EQ(1, counter.NumberOfWeakCalls());
+ isolate->MemoryPressureNotification(v8::MemoryPressureLevel::kCritical);
+ CHECK_EQ(2, counter.NumberOfWeakCalls());
+ }
+ delete garbage;
+ // Check that moderate memory pressure notification sets GC into memory
+ // optimizing mode.
+ isolate->MemoryPressureNotification(v8::MemoryPressureLevel::kModerate);
+ CHECK(CcTest::i_isolate()->heap()->ShouldOptimizeForMemoryUsage());
+ // Check that disabling memory pressure returns GC into normal mode.
+ isolate->MemoryPressureNotification(v8::MemoryPressureLevel::kNone);
+ CHECK(!CcTest::i_isolate()->heap()->ShouldOptimizeForMemoryUsage());
+}
« no previous file with comments | « src/heap/incremental-marking-job.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698