Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Move std::function from JSFunction into NativeStdFunctionCell to corr…
…ectly destroy the heap allocated std::function https://bugs.webkit.org/show_bug.cgi?id=148262 Reviewed by Filip Pizlo. Source/JavaScriptCore: std::function is heap allocated value. So if this is held in the JSCell, the cell should be destructible. Before this patch, it is held in the JSStdFunction. JSStdFunction is the derived class from the JSFunction, and they are not destructible. So it leaked the memory. This patch extracts std::function field from the JSStdFunction to the NativeStdFunctionCell. NativeStdFunctionCell is responsible for destructing the held std::function. Instead of moving std::function to the ExecutableBase, we move it to the newly created NativeStdFunctionCell cell. The reason is the following. - Each NativeExecutable (in 64_32 JIT environment) has the trampolines to call given host functions. And the address of the host function is directly embedded on the JIT-compiled trampoline code. - To suppress the overuse of the executable memory (which is used to generate the trampoline), NativeExecutable is cached. The host function address is used as the key to look up the cached executable from the table. - In all the JSStdFunction, we use the same host function that immediately calls the each std::function. - As a result, without any change, all the JSStdFunction hit the same cached NativeExecutable even if the held std::function is different. - To solve it, if we put the std::function in the NativeExecutable, we need to add this std::function identity (like address) to the cache key, because the address of the stub host function (that calls the std::function) is the same in the all JSStdFunction. - But since the std::function will be allocated in the heap, this address is always different. So caching has no effect. - If we do not cache the NativeExecutable that holds the std::function, each time when creating the JSStdFunction, we need to regenerate the completely same trampolines (since it just calls the same host function stub that calls the std::function). And this patch drops JSArrowFunction::destroy because (1) JSArrowFunction is not destructible and (2) it no longer holds any fields that require destructions. * CMakeLists.txt: * JavaScriptCore.vcxproj/JavaScriptCore.vcxproj: * JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters: * JavaScriptCore.xcodeproj/project.pbxproj: * jsc.cpp: (runWithScripts): * runtime/JSArrowFunction.cpp: (JSC::JSArrowFunction::destroy): Deleted. * runtime/JSArrowFunction.h: * runtime/JSFunction.cpp: (JSC::JSFunction::lookUpOrCreateNativeExecutable): (JSC::JSFunction::create): (JSC::getNativeExecutable): Deleted. (JSC::JSStdFunction::JSStdFunction): Deleted. (JSC::runStdFunction): Deleted. * runtime/JSFunction.h: * runtime/JSGlobalObject.cpp: (JSC::JSGlobalObject::init): (JSC::JSGlobalObject::visitChildren): * runtime/JSGlobalObject.h: (JSC::JSGlobalObject::nativeStdFunctionStructure): * runtime/JSNativeStdFunction.cpp: Added. (JSC::JSNativeStdFunction::JSNativeStdFunction): (JSC::JSNativeStdFunction::visitChildren): (JSC::JSNativeStdFunction::finishCreation): (JSC::runStdFunction): (JSC::JSNativeStdFunction::create): * runtime/JSNativeStdFunction.h: Copied from Source/JavaScriptCore/runtime/JSArrowFunction.h. (JSC::JSNativeStdFunction::createStructure): (JSC::JSNativeStdFunction::nativeStdFunctionCell): * runtime/NativeStdFunctionCell.cpp: Added. (JSC::NativeStdFunctionCell::create): (JSC::NativeStdFunctionCell::NativeStdFunctionCell): (JSC::NativeStdFunctionCell::destroy): * runtime/NativeStdFunctionCell.h: Added. (JSC::NativeStdFunctionCell::createStructure): (JSC::NativeStdFunctionCell::function): * runtime/VM.cpp: (JSC::VM::VM): * runtime/VM.h: Source/WebCore: No behavior change. Change JSFunction::create to JSNativeStdFunction::create to explicitly create the JSNativeStdFunction with the C++ lambda. * ForwardingHeaders/runtime/JSNativeStdFunction.h: Added. * bindings/js/ReadableJSStream.cpp: (WebCore::createStartResultFulfilledFunction): (WebCore::createPullResultFulfilledFunction): (WebCore::createCancelResultFulfilledFunction): (WebCore::createCancelResultRejectedFunction): (WebCore::ReadableJSStream::ReadableJSStream): Canonical link: https://commits.webkit.org/166702@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@189124 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
1 parent
a6610da
commit a961702751484f6de7c6f7019698133a56cc56a0
Showing
21 changed files
with
418 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.