OLD | NEW |
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 24840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
24851 CHECK(proxy->GetTarget()->SameValue(target)); | 24851 CHECK(proxy->GetTarget()->SameValue(target)); |
24852 CHECK(proxy->GetHandler()->SameValue(handler)); | 24852 CHECK(proxy->GetHandler()->SameValue(handler)); |
24853 | 24853 |
24854 proxy->Revoke(); | 24854 proxy->Revoke(); |
24855 CHECK(proxy->IsProxy()); | 24855 CHECK(proxy->IsProxy()); |
24856 CHECK(!target->IsProxy()); | 24856 CHECK(!target->IsProxy()); |
24857 CHECK(proxy->IsRevoked()); | 24857 CHECK(proxy->IsRevoked()); |
24858 CHECK(proxy->GetTarget()->SameValue(target)); | 24858 CHECK(proxy->GetTarget()->SameValue(target)); |
24859 CHECK(proxy->GetHandler()->IsNull()); | 24859 CHECK(proxy->GetHandler()->IsNull()); |
24860 } | 24860 } |
| 24861 |
| 24862 WeakCallCounterAndPersistent<Value>* CreateGarbageWithWeakCallCounter( |
| 24863 v8::Isolate* isolate, WeakCallCounter* counter) { |
| 24864 v8::Locker locker(isolate); |
| 24865 LocalContext env; |
| 24866 HandleScope scope(isolate); |
| 24867 WeakCallCounterAndPersistent<Value>* val = |
| 24868 new WeakCallCounterAndPersistent<Value>(counter); |
| 24869 val->handle.Reset(isolate, Object::New(isolate)); |
| 24870 val->handle.SetWeak(val, &WeakPointerCallback, |
| 24871 v8::WeakCallbackType::kParameter); |
| 24872 return val; |
| 24873 } |
| 24874 |
| 24875 class MemoryPressureThread : public v8::base::Thread { |
| 24876 public: |
| 24877 explicit MemoryPressureThread(v8::Isolate* isolate, |
| 24878 v8::MemoryPressureLevel level) |
| 24879 : Thread(Options("MemoryPressureThread")), |
| 24880 isolate_(isolate), |
| 24881 level_(level) {} |
| 24882 |
| 24883 virtual void Run() { isolate_->MemoryPressureNotification(level_); } |
| 24884 |
| 24885 private: |
| 24886 v8::Isolate* isolate_; |
| 24887 v8::MemoryPressureLevel level_; |
| 24888 }; |
| 24889 |
| 24890 TEST(MemoryPressure) { |
| 24891 v8::Isolate* isolate = CcTest::isolate(); |
| 24892 WeakCallCounter counter(1234); |
| 24893 |
| 24894 // Check that critical memory pressure notification sets GC interrupt. |
| 24895 auto garbage = CreateGarbageWithWeakCallCounter(isolate, &counter); |
| 24896 CHECK(!v8::Locker::IsLocked(isolate)); |
| 24897 { |
| 24898 v8::Locker locker(isolate); |
| 24899 v8::HandleScope scope(isolate); |
| 24900 LocalContext env; |
| 24901 MemoryPressureThread memory_pressure_thread( |
| 24902 isolate, v8::MemoryPressureLevel::kCritical); |
| 24903 memory_pressure_thread.Start(); |
| 24904 memory_pressure_thread.Join(); |
| 24905 // This should trigger GC. |
| 24906 CHECK_EQ(0, counter.NumberOfWeakCalls()); |
| 24907 CompileRun("(function noop() { return 0; })()"); |
| 24908 CHECK_EQ(1, counter.NumberOfWeakCalls()); |
| 24909 } |
| 24910 delete garbage; |
| 24911 // Check that critical memory pressure notification triggers GC. |
| 24912 garbage = CreateGarbageWithWeakCallCounter(isolate, &counter); |
| 24913 { |
| 24914 v8::Locker locker(isolate); |
| 24915 // If isolate is locked, memory pressure notification should trigger GC. |
| 24916 CHECK_EQ(1, counter.NumberOfWeakCalls()); |
| 24917 isolate->MemoryPressureNotification(v8::MemoryPressureLevel::kCritical); |
| 24918 CHECK_EQ(2, counter.NumberOfWeakCalls()); |
| 24919 } |
| 24920 delete garbage; |
| 24921 // Check that moderate memory pressure notification sets GC into memory |
| 24922 // optimizing mode. |
| 24923 isolate->MemoryPressureNotification(v8::MemoryPressureLevel::kModerate); |
| 24924 CHECK(CcTest::i_isolate()->heap()->ShouldOptimizeForMemoryUsage()); |
| 24925 // Check that disabling memory pressure returns GC into normal mode. |
| 24926 isolate->MemoryPressureNotification(v8::MemoryPressureLevel::kNone); |
| 24927 CHECK(!CcTest::i_isolate()->heap()->ShouldOptimizeForMemoryUsage()); |
| 24928 } |
OLD | NEW |