Skip to content

[JSC] Move aINT / mINT / uINT bytecode under RTT#64302

Merged
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
Constellation:eng/JSC-Move-aINT-mINT-uINT-bytecode-under-RTT
May 7, 2026
Merged

[JSC] Move aINT / mINT / uINT bytecode under RTT#64302
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
Constellation:eng/JSC-Move-aINT-mINT-uINT-bytecode-under-RTT

Conversation

@Constellation
Copy link
Copy Markdown
Member

@Constellation Constellation commented May 5, 2026

5accc20

[JSC] Move aINT / mINT / uINT bytecode under RTT
https://bugs.webkit.org/show_bug.cgi?id=314133
rdar://176306252

Reviewed by Keith Miller.

We move aINT / mINT / uINT bytecode to RTT since they are tied to the signature.
This allows us to share them between calls with the same signature, and
also this offers an ability to lazily generate it when mINT is actually
used.

1. aINT / uINT are right now generated eagerly. This is similar to what
   we have right now.
2. mINT is generated when a particular callsite encounters RTT and there
   is no already registered bytecode. This becomes lazy generation, and
   not happening until the callsite is actually used.

We save and restore MC in an unused slot before calls, which allows to
switch MC to pointing at shared bytecode instead of IPInt metadata.
We still have local bytecode which is used to initialize locals, but it
should be improved subsequently.

* Source/JavaScriptCore/llint/InPlaceInterpreter.asm:
* Source/JavaScriptCore/llint/InPlaceInterpreter64.asm:
* Source/JavaScriptCore/wasm/WasmCallee.cpp:
(JSC::Wasm::IPIntCallee::IPIntCallee):
* Source/JavaScriptCore/wasm/WasmCallee.h:
* Source/JavaScriptCore/wasm/WasmFunctionIPIntMetadataGenerator.cpp:
(JSC::Wasm::FunctionIPIntMetadataGenerator::addReturnData): Deleted.
* Source/JavaScriptCore/wasm/WasmFunctionIPIntMetadataGenerator.h:
* Source/JavaScriptCore/wasm/WasmIPIntGenerator.cpp:
(JSC::Wasm::IPIntGenerator::getCurrentInstructionLength):
(JSC::Wasm::IPIntGenerator::cachedCallInformationFor):
(JSC::Wasm::IPIntGenerator::addArguments):
(JSC::Wasm::IPIntGenerator::addLocal):
(JSC::Wasm::IPIntGenerator::addTailCallCommonData):
(JSC::Wasm::IPIntGenerator::addCall):
(JSC::Wasm::IPIntGenerator::addCallIndirect):
(JSC::Wasm::IPIntGenerator::addCallRef):
(JSC::Wasm::IPIntGenerator::finalize):
(JSC::Wasm::addCallArgumentBytecode): Deleted.
(JSC::Wasm::addCallResultBytecode): Deleted.
(JSC::Wasm::IPIntGenerator::addCallCommonData): Deleted.
* Source/JavaScriptCore/wasm/WasmIPIntGenerator.h:
* Source/JavaScriptCore/wasm/WasmIPIntPlan.cpp:
(JSC::Wasm::IPIntPlan::compileFunction):
* Source/JavaScriptCore/wasm/WasmIPIntSlowPaths.cpp:
(JSC::IPInt::ensureCallBytecodeForKind):
(JSC::IPInt::prepareCallImpl):
(JSC::IPInt::prepareCallIndirectImpl):
(JSC::IPInt::prepareCallRefImpl):
(JSC::IPInt::WASM_IPINT_EXTERN_CPP_DECL):
* Source/JavaScriptCore/wasm/WasmIPIntSlowPaths.h:
* Source/JavaScriptCore/wasm/WasmTypeDefinition.cpp:
(JSC::Wasm::RTT::ensureArgumINTBytecode const):
(JSC::Wasm::RTT::ensureUINTBytecode const):
(JSC::Wasm::buildCallArgumentBytecode):
(JSC::Wasm::buildCallResultBytecode):
(JSC::Wasm::RTT::ensureCallBytecode const):
(JSC::Wasm::RTT::ensureTailCallBytecode const):
* Source/JavaScriptCore/wasm/WasmTypeDefinition.h:

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

bb3ff1d

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

@Constellation Constellation self-assigned this May 5, 2026
@Constellation Constellation added the JavaScriptCore For bugs in JavaScriptCore, the JS engine used by WebKit, other than kxmlcore issues. label May 5, 2026
@Constellation Constellation force-pushed the eng/JSC-Move-aINT-mINT-uINT-bytecode-under-RTT branch from e7847d6 to 90b9efe Compare May 5, 2026 23:01
@Constellation Constellation force-pushed the eng/JSC-Move-aINT-mINT-uINT-bytecode-under-RTT branch from 90b9efe to 4566606 Compare May 5, 2026 23:03
@Constellation Constellation marked this pull request as ready for review May 5, 2026 23:03
@Constellation Constellation requested a review from a team as a code owner May 5, 2026 23:03
@webkit-ews-buildbot
Copy link
Copy Markdown
Collaborator

macOS Safer C++ Build #100576 (4566606)

❌ Found 1 failing file with 6 issues. Please address these issues before landing. See WebKit Guidelines for Safer C++ Programming.
(cc @rniwa)

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label May 6, 2026
@webkit-ews-buildbot
Copy link
Copy Markdown
Collaborator

iOS Safer C++ Build #18966 (4566606)

❌ Found 1 failing file with 6 issues. Please address these issues before landing. See WebKit Guidelines for Safer C++ Programming.
(cc @rniwa)

@Constellation Constellation removed the merging-blocked Applied to prevent a change from being merged label May 6, 2026
@Constellation Constellation force-pushed the eng/JSC-Move-aINT-mINT-uINT-bytecode-under-RTT branch from 4566606 to aee4c24 Compare May 6, 2026 18:57
Copy link
Copy Markdown
Contributor

@kmiller68 kmiller68 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 with comments


// Function-kind only. Lazy-install under m_ipintBytecodeLock; buffer is
// immutable once published.
Ref<const IPIntSharedBytecode> ensureArgumINTBytecode(const CallInformation&) const;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think you use the results of these ensureXYZBytecode() functions anywhere. Could probably avoid a ref count churn.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sounds good. Changed.

Comment on lines +1074 to +1075
if (auto buffer = m_argumINTBytecode) [[likely]]
return buffer.releaseNonNull();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not do the:

if (m_argumINTBytecode) [[likely]]
    return;

Locker ...
if (m_argumINTBytecode)
    return;

idiom?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sounds good. Changed.

SUPPRESS_UNCOUNTED_LOCAL const auto& rtt = *call->signature.rtt;
rtt.ensureCallBytecode();

auto* callee = IPINT_CALLEE(callFrame);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All this code seems heavily duplicated after the rtt.ensureXYZBytecode() can we have a shared helper?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ditto for the others.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sounds good. Changed.

@Constellation Constellation force-pushed the eng/JSC-Move-aINT-mINT-uINT-bytecode-under-RTT branch from aee4c24 to 834d881 Compare May 7, 2026 04:49
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label May 7, 2026
@Constellation Constellation removed the merging-blocked Applied to prevent a change from being merged label May 7, 2026
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label May 7, 2026
@Constellation Constellation force-pushed the eng/JSC-Move-aINT-mINT-uINT-bytecode-under-RTT branch from 834d881 to 8811767 Compare May 7, 2026 05:02
@Constellation Constellation removed the merging-blocked Applied to prevent a change from being merged label May 7, 2026
@Constellation Constellation force-pushed the eng/JSC-Move-aINT-mINT-uINT-bytecode-under-RTT branch from 8811767 to af5ffec Compare May 7, 2026 08:17
@Constellation Constellation force-pushed the eng/JSC-Move-aINT-mINT-uINT-bytecode-under-RTT branch from af5ffec to da03041 Compare May 7, 2026 08:44
@Constellation Constellation force-pushed the eng/JSC-Move-aINT-mINT-uINT-bytecode-under-RTT branch from da03041 to 3bc3af1 Compare May 7, 2026 08:47
@kmiller68 kmiller68 self-requested a review May 7, 2026 15:55
Copy link
Copy Markdown
Contributor

@kmiller68 kmiller68 left a comment

Choose a reason for hiding this comment

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

Discussing offline, I think there's a bug here because there's no data dependency between the bytecode pointer and the other fields. Since the bytecode pointer controls publication it's possible for one of the other fields to get hoisted by a "reader" thread above the publication.

@Constellation
Copy link
Copy Markdown
Member Author

Discussing offline, I think there's a bug here because there's no data dependency between the bytecode pointer and the other fields. Since the bytecode pointer controls publication it's possible for one of the other fields to get hoisted by a "reader" thread above the publication.

The latest version of the code fixed it by embedding that field into the bytecode :)

@Constellation Constellation force-pushed the eng/JSC-Move-aINT-mINT-uINT-bytecode-under-RTT branch from 3bc3af1 to 06c78ed Compare May 7, 2026 17:37
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is this refcounted rather than unique_ptr?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Originally trying to share even further between some RTTs, like func(array, array) and func(struct, struct), but just going to the simpler way for now. Changed it to unique-ptr.

@Constellation Constellation force-pushed the eng/JSC-Move-aINT-mINT-uINT-bytecode-under-RTT branch from 06c78ed to bb3ff1d Compare May 7, 2026 18:21
@Constellation Constellation added the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label May 7, 2026
https://bugs.webkit.org/show_bug.cgi?id=314133
rdar://176306252

Reviewed by Keith Miller.

We move aINT / mINT / uINT bytecode to RTT since they are tied to the signature.
This allows us to share them between calls with the same signature, and
also this offers an ability to lazily generate it when mINT is actually
used.

1. aINT / uINT are right now generated eagerly. This is similar to what
   we have right now.
2. mINT is generated when a particular callsite encounters RTT and there
   is no already registered bytecode. This becomes lazy generation, and
   not happening until the callsite is actually used.

We save and restore MC in an unused slot before calls, which allows to
switch MC to pointing at shared bytecode instead of IPInt metadata.
We still have local bytecode which is used to initialize locals, but it
should be improved subsequently.

* Source/JavaScriptCore/llint/InPlaceInterpreter.asm:
* Source/JavaScriptCore/llint/InPlaceInterpreter64.asm:
* Source/JavaScriptCore/wasm/WasmCallee.cpp:
(JSC::Wasm::IPIntCallee::IPIntCallee):
* Source/JavaScriptCore/wasm/WasmCallee.h:
* Source/JavaScriptCore/wasm/WasmFunctionIPIntMetadataGenerator.cpp:
(JSC::Wasm::FunctionIPIntMetadataGenerator::addReturnData): Deleted.
* Source/JavaScriptCore/wasm/WasmFunctionIPIntMetadataGenerator.h:
* Source/JavaScriptCore/wasm/WasmIPIntGenerator.cpp:
(JSC::Wasm::IPIntGenerator::getCurrentInstructionLength):
(JSC::Wasm::IPIntGenerator::cachedCallInformationFor):
(JSC::Wasm::IPIntGenerator::addArguments):
(JSC::Wasm::IPIntGenerator::addLocal):
(JSC::Wasm::IPIntGenerator::addTailCallCommonData):
(JSC::Wasm::IPIntGenerator::addCall):
(JSC::Wasm::IPIntGenerator::addCallIndirect):
(JSC::Wasm::IPIntGenerator::addCallRef):
(JSC::Wasm::IPIntGenerator::finalize):
(JSC::Wasm::addCallArgumentBytecode): Deleted.
(JSC::Wasm::addCallResultBytecode): Deleted.
(JSC::Wasm::IPIntGenerator::addCallCommonData): Deleted.
* Source/JavaScriptCore/wasm/WasmIPIntGenerator.h:
* Source/JavaScriptCore/wasm/WasmIPIntPlan.cpp:
(JSC::Wasm::IPIntPlan::compileFunction):
* Source/JavaScriptCore/wasm/WasmIPIntSlowPaths.cpp:
(JSC::IPInt::ensureCallBytecodeForKind):
(JSC::IPInt::prepareCallImpl):
(JSC::IPInt::prepareCallIndirectImpl):
(JSC::IPInt::prepareCallRefImpl):
(JSC::IPInt::WASM_IPINT_EXTERN_CPP_DECL):
* Source/JavaScriptCore/wasm/WasmIPIntSlowPaths.h:
* Source/JavaScriptCore/wasm/WasmTypeDefinition.cpp:
(JSC::Wasm::RTT::ensureArgumINTBytecode const):
(JSC::Wasm::RTT::ensureUINTBytecode const):
(JSC::Wasm::buildCallArgumentBytecode):
(JSC::Wasm::buildCallResultBytecode):
(JSC::Wasm::RTT::ensureCallBytecode const):
(JSC::Wasm::RTT::ensureTailCallBytecode const):
* Source/JavaScriptCore/wasm/WasmTypeDefinition.h:

Canonical link: https://commits.webkit.org/312841@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/JSC-Move-aINT-mINT-uINT-bytecode-under-RTT branch from bb3ff1d to 5accc20 Compare May 7, 2026 23:29
@webkit-commit-queue
Copy link
Copy Markdown
Collaborator

Committed 312841@main (5accc20): https://commits.webkit.org/312841@main

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

@webkit-commit-queue webkit-commit-queue merged commit 5accc20 into WebKit:main May 7, 2026
@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 May 7, 2026
@Constellation Constellation deleted the eng/JSC-Move-aINT-mINT-uINT-bytecode-under-RTT branch May 8, 2026 00:59
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