Skip to content

[JSC] Concurrently computing CodeBlockHash #47214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

Constellation
Copy link
Member

@Constellation Constellation commented Jun 26, 2025

82de5bb

[JSC] Concurrently computing CodeBlockHash
https://bugs.webkit.org/show_bug.cgi?id=295000
rdar://154307835

Reviewed by Yijia Huang.

This patch fixes an issue for concurrent CodeBlockHash. We put some
locks around CachedScriptSourceProvider / ScriptBufferSourceProvider
to ensure that we can touch these source code safely (do not ref them.
This is concurrently touched).

* Source/JavaScriptCore/bytecode/CodeBlock.cpp:
(JSC::CodeBlock::hash const):
* Source/JavaScriptCore/bytecode/CodeBlockHash.cpp:
(JSC::CodeBlockHash::CodeBlockHash):
* Source/JavaScriptCore/bytecode/CodeBlockHash.h:
* Source/JavaScriptCore/parser/SourceProvider.cpp:
(JSC::SourceProvider::codeBlockHashConcurrently):
* Source/JavaScriptCore/parser/SourceProvider.h:
(JSC::SourceProviderBufferGuard::provider):
* Source/WebCore/bindings/js/CachedScriptSourceProvider.h:
* Source/WebCore/bindings/js/ScriptBufferSourceProvider.h:
* Source/WebCore/loader/TextResourceDecoder.cpp:
(WebCore::TextResourceDecoder::TextResourceDecoder):
(WebCore::TextResourceDecoder::create):
* Source/WebCore/loader/TextResourceDecoder.h:
(WebCore::TextResourceDecoder::contentType const):
(WebCore::TextResourceDecoder::usesEncodingDetector const):
* Source/WebCore/loader/cache/CachedScript.cpp:
(WebCore::CachedScript::script):
(WebCore::CachedScript::codeBlockHashConcurrently):
(WebCore::CachedScript::destroyDecodedData):
(WebCore::CachedScript::setBodyDataFrom):
* Source/WebCore/loader/cache/CachedScript.h:

Canonical link: https://commits.webkit.org/296668@main

6a8d18c

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
❌ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ⏳ 🧪 win-tests
loading 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
✅ 🧪 ios-wk2-wpt ✅ 🧪 mac-wk1 ✅ 🛠 wpe-cairo
✅ 🛠 🧪 jsc ✅ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk
✅ 🛠 🧪 jsc-arm64 ✅ 🛠 vision ✅ 🧪 mac-AS-debug-wk2 ❌ 🧪 gtk-wk2
✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress ❌ 🧪 api-gtk
✅ 🧪 vision-wk2 ✅ 🧪 mac-intel-wk2 ✅ 🛠 playstation
✅ 🛠 🧪 unsafe-merge ✅ 🛠 tv ✅ 🛠 mac-safer-cpp ✅ 🛠 jsc-armv7
✅ 🛠 tv-sim ✅ 🧪 jsc-armv7-tests
✅ 🛠 watch
✅ 🛠 watch-sim

@Constellation Constellation requested review from cdumez and a team as code owners June 26, 2025 01:30
@Constellation Constellation self-assigned this Jun 26, 2025
@Constellation Constellation added the JavaScriptCore For bugs in JavaScriptCore, the JS engine used by WebKit, other than kxmlcore issues. label Jun 26, 2025
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jun 26, 2025
@Constellation Constellation removed the merging-blocked Applied to prevent a change from being merged label Jun 26, 2025
@Constellation Constellation force-pushed the eng/JSC-Concurrently-computing-CodeBlockHash branch from b086f91 to 5894f5d Compare June 26, 2025 01:44
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jun 26, 2025
@Constellation Constellation removed the merging-blocked Applied to prevent a change from being merged label Jun 26, 2025
@Constellation Constellation force-pushed the eng/JSC-Concurrently-computing-CodeBlockHash branch from 5894f5d to 43c1fea Compare June 26, 2025 02:03
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jun 26, 2025
Copy link
Contributor

@hyjorc1 hyjorc1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me

@@ -68,6 +61,7 @@ class CachedScriptSourceProvider final : public JSC::SourceProvider, public Cach

CachedResourceHandle<CachedScript> m_cachedScript;
RefPtr<FragmentedSharedBuffer> m_buffer;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to remove the m_buffer in CachedScriptSourceProvider as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right!

@@ -68,6 +61,7 @@ class CachedScriptSourceProvider final : public JSC::SourceProvider, public Cach

CachedResourceHandle<CachedScript> m_cachedScript;
RefPtr<FragmentedSharedBuffer> m_buffer;
mutable Lock m_lock;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And we don't need this lock right? Since CachedScript has its own lock.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right! Removed.

@Constellation Constellation removed the merging-blocked Applied to prevent a change from being merged label Jun 26, 2025
@Constellation Constellation force-pushed the eng/JSC-Concurrently-computing-CodeBlockHash branch from 43c1fea to 6a8d18c Compare June 26, 2025 13:44
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jun 26, 2025
@Constellation Constellation added unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing and removed merging-blocked Applied to prevent a change from being merged labels Jun 26, 2025
https://bugs.webkit.org/show_bug.cgi?id=295000
rdar://154307835

Reviewed by Yijia Huang.

This patch fixes an issue for concurrent CodeBlockHash. We put some
locks around CachedScriptSourceProvider / ScriptBufferSourceProvider
to ensure that we can touch these source code safely (do not ref them.
This is concurrently touched).

* Source/JavaScriptCore/bytecode/CodeBlock.cpp:
(JSC::CodeBlock::hash const):
* Source/JavaScriptCore/bytecode/CodeBlockHash.cpp:
(JSC::CodeBlockHash::CodeBlockHash):
* Source/JavaScriptCore/bytecode/CodeBlockHash.h:
* Source/JavaScriptCore/parser/SourceProvider.cpp:
(JSC::SourceProvider::codeBlockHashConcurrently):
* Source/JavaScriptCore/parser/SourceProvider.h:
(JSC::SourceProviderBufferGuard::provider):
* Source/WebCore/bindings/js/CachedScriptSourceProvider.h:
* Source/WebCore/bindings/js/ScriptBufferSourceProvider.h:
* Source/WebCore/loader/TextResourceDecoder.cpp:
(WebCore::TextResourceDecoder::TextResourceDecoder):
(WebCore::TextResourceDecoder::create):
* Source/WebCore/loader/TextResourceDecoder.h:
(WebCore::TextResourceDecoder::contentType const):
(WebCore::TextResourceDecoder::usesEncodingDetector const):
* Source/WebCore/loader/cache/CachedScript.cpp:
(WebCore::CachedScript::script):
(WebCore::CachedScript::codeBlockHashConcurrently):
(WebCore::CachedScript::destroyDecodedData):
(WebCore::CachedScript::setBodyDataFrom):
* Source/WebCore/loader/cache/CachedScript.h:

Canonical link: https://commits.webkit.org/296668@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/JSC-Concurrently-computing-CodeBlockHash branch from 6a8d18c to 82de5bb Compare June 26, 2025 16:58
@webkit-commit-queue
Copy link
Collaborator

Committed 296668@main (82de5bb): https://commits.webkit.org/296668@main

Reviewed commits have been landed. Closing PR #47214 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 82de5bb into WebKit:main Jun 26, 2025
@webkit-commit-queue webkit-commit-queue removed the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Jun 26, 2025
@Constellation Constellation deleted the eng/JSC-Concurrently-computing-CodeBlockHash branch June 26, 2025 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JavaScriptCore For bugs in JavaScriptCore, the JS engine used by WebKit, other than kxmlcore issues.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants