Refactor recompileAllJSFunctions() to be less expensive
https://bugs.webkit.org/show_bug.cgi?id=80330
Reviewed by Filip Pizlo.
This change is performance neutral on the JS benchmarks we track. It's mostly to improve page
load performance, which currently does at least a couple full GCs per navigation.
* heap/Heap.cpp:
(JSC::Heap::discardAllCompiledCode): Rename recompileAllJSFunctions to discardAllCompiledCode
because the function doesn't actually recompile anything (and never did); it simply throws code
away for it to be recompiled later if we determine we should do so.
(JSC):
(JSC::Heap::collectAllGarbage):
(JSC::Heap::addFunctionExecutable): Adds a newly created FunctionExecutable to the Heap's list.
(JSC::Heap::removeFunctionExecutable): Removes the specified FunctionExecutable from the Heap's list.
* heap/Heap.h:
(JSC):
(Heap):
* runtime/Executable.cpp: Added next and prev fields to FunctionExecutables so that they can
be used in DoublyLinkedLists.
(JSC::FunctionExecutable::FunctionExecutable):
(JSC::FunctionExecutable::finalize): Removes the FunctionExecutable from the Heap's list.
* runtime/Executable.h:
(FunctionExecutable):
(JSC::FunctionExecutable::create): Adds the FunctionExecutable to the Heap's list.
* runtime/JSGlobalData.cpp: Remove recompileAllJSFunctions, as it's the Heap's job to own and manage
the list of FunctionExecutables.
* runtime/JSGlobalData.h:
(JSGlobalData):
* runtime/JSGlobalObject.cpp:
(JSC::DynamicGlobalObjectScope::DynamicGlobalObjectScope): Use the new discardAllCompiledCode.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@112624 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/heap/Heap.cpp b/Source/JavaScriptCore/heap/Heap.cpp
index 6241fb3..c54ba77 100644
--- a/Source/JavaScriptCore/heap/Heap.cpp
+++ b/Source/JavaScriptCore/heap/Heap.cpp
@@ -765,12 +765,22 @@
return m_objectSpace.forEachCell<RecordType>();
}
+void Heap::discardAllCompiledCode()
+{
+ // If JavaScript is running, it's not safe to recompile, since we'll end
+ // up throwing away code that is live on the stack.
+ ASSERT(!m_globalData->dynamicGlobalObject);
+
+ for (FunctionExecutable* current = m_functions.head(); current; current = current->next())
+ current->discardCode();
+}
+
void Heap::collectAllGarbage()
{
if (!m_isSafeToCollect)
return;
if (!m_globalData->dynamicGlobalObject)
- m_globalData->recompileAllJSFunctions();
+ discardAllCompiledCode();
collect(DoSweep);
}
@@ -925,4 +935,14 @@
finalizer(weak.get());
}
+void Heap::addFunctionExecutable(FunctionExecutable* executable)
+{
+ m_functions.append(executable);
+}
+
+void Heap::removeFunctionExecutable(FunctionExecutable* executable)
+{
+ m_functions.remove(executable);
+}
+
} // namespace JSC