Changeset 239195 in webkit for trunk/Source/JavaScriptCore/jsc.cpp
- Timestamp:
- Dec 13, 2018, 8:05:41 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/jsc.cpp
r239187 r239195 81 81 #include <thread> 82 82 #include <type_traits> 83 #include <wtf/Box.h> 83 84 #include <wtf/CommaPrinter.h> 84 85 #include <wtf/MainThread.h> 86 #include <wtf/MemoryPressureHandler.h> 85 87 #include <wtf/MonotonicTime.h> 86 88 #include <wtf/NeverDestroyed.h> … … 2872 2874 Gigacage::disableDisablingPrimitiveGigacageIfShouldBeEnabled(); 2873 2875 2876 #if PLATFORM(COCOA) 2877 auto& memoryPressureHandler = MemoryPressureHandler::singleton(); 2878 { 2879 dispatch_queue_t queue = dispatch_queue_create("jsc shell memory pressure handler", DISPATCH_QUEUE_SERIAL); 2880 memoryPressureHandler.setDispatchQueue(queue); 2881 dispatch_release(queue); 2882 } 2883 Box<Critical> memoryPressureCriticalState = Box<Critical>::create(Critical::No); 2884 Box<Synchronous> memoryPressureSynchronousState = Box<Synchronous>::create(Synchronous::No); 2885 memoryPressureHandler.setLowMemoryHandler([=] (Critical critical, Synchronous synchronous) { 2886 // We set these racily with respect to reading them from the JS execution thread. 2887 *memoryPressureCriticalState = critical; 2888 *memoryPressureSynchronousState = synchronous; 2889 }); 2890 memoryPressureHandler.setShouldLogMemoryMemoryPressureEvents(false); 2891 memoryPressureHandler.install(); 2892 2893 auto onEachMicrotaskTick = [&] (VM& vm) { 2894 if (*memoryPressureCriticalState == Critical::No) 2895 return; 2896 2897 *memoryPressureCriticalState = Critical::No; 2898 bool isSynchronous = *memoryPressureSynchronousState == Synchronous::Yes; 2899 2900 WTF::releaseFastMallocFreeMemory(); 2901 vm.deleteAllCode(DeleteAllCodeIfNotCollecting); 2902 2903 if (!vm.heap.isCurrentThreadBusy()) { 2904 if (isSynchronous) { 2905 vm.heap.collectNow(Sync, CollectionScope::Full); 2906 WTF::releaseFastMallocFreeMemory(); 2907 } else 2908 vm.heap.collectNowFullIfNotDoneRecently(Async); 2909 } 2910 }; 2911 #endif 2912 2874 2913 int result = runJSC( 2875 2914 options, false, 2876 [&] (VM&, GlobalObject* globalObject, bool& success) { 2915 [&] (VM& vm, GlobalObject* globalObject, bool& success) { 2916 #if PLATFORM(COCOA) 2917 vm.setOnEachMicrotaskTick(WTFMove(onEachMicrotaskTick)); 2918 #endif 2877 2919 runWithOptions(globalObject, options, success); 2878 2920 });
Note:
See TracChangeset
for help on using the changeset viewer.