Title: [136773] trunk/Source
Revision
136773
Author
oli...@apple.com
Date
2012-12-05 15:43:06 -0800 (Wed, 05 Dec 2012)

Log Message

Empty parse cache when receiving a low memory warning
https://bugs.webkit.org/show_bug.cgi?id=104161

Reviewed by Filip Pizlo.

Source/_javascript_Core:

This adds a function to the globaldata to empty all code related data
structures (code in the heap and the code cache).
It also adds a function to allow the CodeCache to actually be cleared
at all.

* runtime/CodeCache.h:
(CacheMap):
(JSC::CacheMap::clear):
(JSC::CodeCache::clear):
(CodeCache):
* runtime/JSGlobalData.cpp:
(JSC::JSGlobalData::discardAllCode):
(JSC):
* runtime/JSGlobalData.h:
(JSGlobalData):

Source/WebCore:

Use new discardAllCode() function on the global data, rather than
directly interacting with the heap.

* bindings/js/GCController.cpp:
(WebCore::GCController::discardAllCompiledCode):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (136772 => 136773)


--- trunk/Source/_javascript_Core/ChangeLog	2012-12-05 23:39:09 UTC (rev 136772)
+++ trunk/Source/_javascript_Core/ChangeLog	2012-12-05 23:43:06 UTC (rev 136773)
@@ -1,3 +1,26 @@
+2012-12-05  Oliver Hunt  <oli...@apple.com>
+
+        Empty parse cache when receiving a low memory warning
+        https://bugs.webkit.org/show_bug.cgi?id=104161
+
+        Reviewed by Filip Pizlo.
+
+        This adds a function to the globaldata to empty all code related data
+        structures (code in the heap and the code cache).
+        It also adds a function to allow the CodeCache to actually be cleared
+        at all. 
+
+        * runtime/CodeCache.h:
+        (CacheMap):
+        (JSC::CacheMap::clear):
+        (JSC::CodeCache::clear):
+        (CodeCache):
+        * runtime/JSGlobalData.cpp:
+        (JSC::JSGlobalData::discardAllCode):
+        (JSC):
+        * runtime/JSGlobalData.h:
+        (JSGlobalData):
+
 2012-12-05  Filip Pizlo  <fpi...@apple.com>
 
         JSC profiler should not count executions of op_call_put_result because doing so changes DFG codegen

Modified: trunk/Source/_javascript_Core/_javascript_Core.vcproj/_javascript_Core/_javascript_Core.def (136772 => 136773)


--- trunk/Source/_javascript_Core/_javascript_Core.vcproj/_javascript_Core/_javascript_Core.def	2012-12-05 23:39:09 UTC (rev 136772)
+++ trunk/Source/_javascript_Core/_javascript_Core.vcproj/_javascript_Core/_javascript_Core.def	2012-12-05 23:43:06 UTC (rev 136773)
@@ -187,6 +187,7 @@
     ?detach@Debugger@JSC@@UAEXPAVJSGlobalObject@2@@Z
     ?detachThread@WTF@@YAXI@Z
     ?didTimeOut@TimeoutChecker@JSC@@QAE_NPAVExecState@2@@Z
+    ?discardAllCode@JSGlobalData@JSC@@QAEXXZ
     ?displayName@JSFunction@JSC@@QAE?AVString@WTF@@PAVExecState@2@@Z
     ?dtoa@WTF@@YAXQADNAA_NAAHAAI@Z
     ?dump@JSValue@JSC@@QBEXAAVPrintStream@WTF@@@Z

Modified: trunk/Source/_javascript_Core/runtime/CodeCache.h (136772 => 136773)


--- trunk/Source/_javascript_Core/runtime/CodeCache.h	2012-12-05 23:39:09 UTC (rev 136772)
+++ trunk/Source/_javascript_Core/runtime/CodeCache.h	2012-12-05 23:43:06 UTC (rev 136773)
@@ -82,6 +82,17 @@
         m_data[newIndex].second = value;
         ASSERT(m_map.size() <= CacheSize);
     }
+
+    void clear()
+    {
+        m_map.clear();
+        for (size_t i = 0; i < CacheSize; i++) {
+            m_data[i].first = KeyType();
+            m_data[i].second = EntryType();
+        }
+    }
+
+
 private:
     HashMap<KeyType, unsigned> m_map;
     FixedArray<std::pair<KeyType, EntryType>, CacheSize> m_data;
@@ -99,6 +110,14 @@
     void usedFunctionCode(JSGlobalData&, UnlinkedFunctionCodeBlock*);
     ~CodeCache();
 
+    void clear()
+    {
+        m_cachedCodeBlocks.clear();
+        m_cachedFunctionExecutables.clear();
+        m_cachedGlobalFunctions.clear();
+        m_recentlyUsedFunctionCode.clear();
+    }
+
     enum CodeType { EvalType, ProgramType, FunctionCallType, FunctionConstructType };
     typedef std::pair<String, unsigned> CodeBlockKey;
     typedef std::pair<String, String> GlobalFunctionKey;

Modified: trunk/Source/_javascript_Core/runtime/JSGlobalData.cpp (136772 => 136773)


--- trunk/Source/_javascript_Core/runtime/JSGlobalData.cpp	2012-12-05 23:39:09 UTC (rev 136772)
+++ trunk/Source/_javascript_Core/runtime/JSGlobalData.cpp	2012-12-05 23:43:06 UTC (rev 136773)
@@ -431,6 +431,12 @@
     interpreter->stopSampling();
 }
 
+void JSGlobalData::discardAllCode()
+{
+    m_codeCache->clear();
+    heap.deleteAllCompiledCode();
+}
+
 void JSGlobalData::dumpSampleData(ExecState* exec)
 {
     interpreter->dumpSampleData(exec);

Modified: trunk/Source/_javascript_Core/runtime/JSGlobalData.h (136772 => 136773)


--- trunk/Source/_javascript_Core/runtime/JSGlobalData.h	2012-12-05 23:39:09 UTC (rev 136772)
+++ trunk/Source/_javascript_Core/runtime/JSGlobalData.h	2012-12-05 23:43:06 UTC (rev 136773)
@@ -450,6 +450,8 @@
         JSLock& apiLock() { return m_apiLock; }
         CodeCache* codeCache() { return m_codeCache.get(); }
 
+        JS_EXPORT_PRIVATE void discardAllCode();
+
     private:
         friend class LLIntOffsetsExtractor;
         

Modified: trunk/Source/WebCore/ChangeLog (136772 => 136773)


--- trunk/Source/WebCore/ChangeLog	2012-12-05 23:39:09 UTC (rev 136772)
+++ trunk/Source/WebCore/ChangeLog	2012-12-05 23:43:06 UTC (rev 136773)
@@ -1,3 +1,16 @@
+2012-12-05  Oliver Hunt  <oli...@apple.com>
+
+        Empty parse cache when receiving a low memory warning
+        https://bugs.webkit.org/show_bug.cgi?id=104161
+
+        Reviewed by Filip Pizlo.
+
+        Use new discardAllCode() function on the global data, rather than
+        directly interacting with the heap.
+
+        * bindings/js/GCController.cpp:
+        (WebCore::GCController::discardAllCompiledCode):
+
 2012-12-05  Dan Bernstein  <m...@apple.com>
 
         Text decorations are rotated when text-combine takes effect

Modified: trunk/Source/WebCore/bindings/js/GCController.cpp (136772 => 136773)


--- trunk/Source/WebCore/bindings/js/GCController.cpp	2012-12-05 23:39:09 UTC (rev 136772)
+++ trunk/Source/WebCore/bindings/js/GCController.cpp	2012-12-05 23:43:06 UTC (rev 136773)
@@ -105,7 +105,7 @@
 void GCController::discardAllCompiledCode()
 {
     JSLockHolder lock(JSDOMWindow::commonJSGlobalData());
-    JSDOMWindow::commonJSGlobalData()->heap.deleteAllCompiledCode();
+    JSDOMWindow::commonJSGlobalData()->discardAllCode();
 }
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to