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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/heap/incremental-marking-job.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 24838 matching lines...) Expand 10 before | Expand all | Expand 10 after
24849 CHECK(proxy->GetTarget()->SameValue(target)); 24849 CHECK(proxy->GetTarget()->SameValue(target));
24850 CHECK(proxy->GetHandler()->SameValue(handler)); 24850 CHECK(proxy->GetHandler()->SameValue(handler));
24851 24851
24852 proxy->Revoke(); 24852 proxy->Revoke();
24853 CHECK(proxy->IsProxy()); 24853 CHECK(proxy->IsProxy());
24854 CHECK(!target->IsProxy()); 24854 CHECK(!target->IsProxy());
24855 CHECK(proxy->IsRevoked()); 24855 CHECK(proxy->IsRevoked());
24856 CHECK(proxy->GetTarget()->SameValue(target)); 24856 CHECK(proxy->GetTarget()->SameValue(target));
24857 CHECK(proxy->GetHandler()->IsNull()); 24857 CHECK(proxy->GetHandler()->IsNull());
24858 } 24858 }
24859
24860 WeakCallCounterAndPersistent<Value>* CreateGarbageWithWeakCallCounter(
24861 v8::Isolate* isolate, WeakCallCounter* counter) {
24862 v8::Locker locker(isolate);
24863 LocalContext env;
24864 HandleScope scope(isolate);
24865 WeakCallCounterAndPersistent<Value>* val =
24866 new WeakCallCounterAndPersistent<Value>(counter);
24867 val->handle.Reset(isolate, Object::New(isolate));
24868 val->handle.SetWeak(val, &WeakPointerCallback,
24869 v8::WeakCallbackType::kParameter);
24870 return val;
24871 }
24872
24873 class MemoryPressureThread : public v8::base::Thread {
24874 public:
24875 explicit MemoryPressureThread(v8::Isolate* isolate,
24876 v8::MemoryPressureLevel level)
24877 : Thread(Options("MemoryPressureThread")),
24878 isolate_(isolate),
24879 level_(level) {}
24880
24881 virtual void Run() { isolate_->MemoryPressureNotification(level_); }
24882
24883 private:
24884 v8::Isolate* isolate_;
24885 v8::MemoryPressureLevel level_;
24886 };
24887
24888 TEST(MemoryPressure) {
24889 v8::Isolate* isolate = CcTest::isolate();
24890 WeakCallCounter counter(1234);
24891
24892 // Check that critical memory pressure notification sets GC interrupt.
24893 auto garbage = CreateGarbageWithWeakCallCounter(isolate, &counter);
24894 CHECK(!v8::Locker::IsLocked(isolate));
24895 {
24896 v8::Locker locker(isolate);
24897 v8::HandleScope scope(isolate);
24898 LocalContext env;
24899 MemoryPressureThread memory_pressure_thread(
24900 isolate, v8::MemoryPressureLevel::kCritical);
24901 memory_pressure_thread.Start();
24902 memory_pressure_thread.Join();
24903 // This should trigger GC.
24904 CHECK_EQ(0, counter.NumberOfWeakCalls());
24905 CompileRun("(function noop() { return 0; })()");
24906 CHECK_EQ(1, counter.NumberOfWeakCalls());
24907 }
24908 delete garbage;
24909 // Check that critical memory pressure notification triggers GC.
24910 garbage = CreateGarbageWithWeakCallCounter(isolate, &counter);
24911 {
24912 v8::Locker locker(isolate);
24913 // If isolate is locked, memory pressure notification should trigger GC.
24914 CHECK_EQ(1, counter.NumberOfWeakCalls());
24915 isolate->MemoryPressureNotification(v8::MemoryPressureLevel::kCritical);
24916 CHECK_EQ(2, counter.NumberOfWeakCalls());
24917 }
24918 delete garbage;
24919 // Check that moderate memory pressure notification sets GC into memory
24920 // optimizing mode.
24921 isolate->MemoryPressureNotification(v8::MemoryPressureLevel::kModerate);
24922 CHECK(CcTest::i_isolate()->heap()->ShouldOptimizeForMemoryUsage());
24923 // Check that disabling memory pressure returns GC into normal mode.
24924 isolate->MemoryPressureNotification(v8::MemoryPressureLevel::kNone);
24925 CHECK(!CcTest::i_isolate()->heap()->ShouldOptimizeForMemoryUsage());
24926 }
OLDNEW
« 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