Skip to content

Commit

Permalink
[JSC] Optimize C++ -> JS calls more by removing unnecessary callee st…
Browse files Browse the repository at this point in the history
…oring to VMEntryRecord

https://bugs.webkit.org/show_bug.cgi?id=265178
rdar://118672952

Reviewed by Ross Kirsling.

This remoes unnecessary callee storing in VMEntryRecord. We are using it only in one place, and it is just getting JSGlobalObject
when there is no JS CallFrame (then, instead, it is querying to VMEntryRecord). In this case, we can just use VMEntryScope's
JSGlobalObject, which is also created before VMEntryRecord is instantiated. This removes some more unnecessary code in LowLevelInterpreter's
doVMEntry.

    cpp-to-js-cached-call       12.8405+-0.0760     ^     12.5615+-0.0582        ^ definitely 1.0222x faster

* Source/JavaScriptCore/interpreter/CallFrame.cpp:
(JSC::CallFrame::convertToStackOverflowFrame):
* Source/JavaScriptCore/interpreter/VMEntryRecord.h:
(JSC::VMEntryRecord::callee const): Deleted.
* Source/JavaScriptCore/llint/LowLevelInterpreter32_64.asm:
* Source/JavaScriptCore/llint/LowLevelInterpreter64.asm:

Canonical link: https://commits.webkit.org/271027@main
  • Loading branch information
Constellation committed Nov 21, 2023
1 parent 0c248b2 commit 70ed411
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 9 deletions.
8 changes: 6 additions & 2 deletions Source/JavaScriptCore/interpreter/CallFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,12 @@ void CallFrame::convertToStackOverflowFrame(VM& vm, CodeBlock* codeBlockToKeepAl
throwOriginFrame = throwOriginFrame->callerFrame(entryFrame);
} while (throwOriginFrame && throwOriginFrame->callee().isNativeCallee());

JSObject* originCallee = throwOriginFrame ? throwOriginFrame->jsCallee() : vmEntryRecord(vm.topEntryFrame)->callee();
JSObject* stackOverflowCallee = originCallee->globalObject()->stackOverflowFrameCallee();
JSGlobalObject* globalObject = nullptr;
if (throwOriginFrame)
globalObject = throwOriginFrame->jsCallee()->globalObject();
else
globalObject = vm.entryScope->globalObject();
JSObject* stackOverflowCallee = globalObject->stackOverflowFrameCallee();

setCodeBlock(codeBlockToKeepAliveUntilFrameIsUnwound);
setCallee(stackOverflowCallee);
Expand Down
3 changes: 0 additions & 3 deletions Source/JavaScriptCore/interpreter/VMEntryRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ struct VMEntryRecord {
VM* const m_vm;
CallFrame* const m_prevTopCallFrame;
EntryFrame* const m_prevTopEntryFrame;
JSObject* const m_callee;

JSObject* callee() const { return m_callee; }

#if !ENABLE(C_LOOP) && NUMBER_OF_CALLEE_SAVES_REGISTERS > 0
CPURegister calleeSaveRegistersBuffer[NUMBER_OF_CALLEE_SAVES_REGISTERS];
Expand Down
2 changes: 0 additions & 2 deletions Source/JavaScriptCore/llint/LowLevelInterpreter32_64.asm
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,6 @@ macro doVMEntry(makeCall)
storep t4, VMEntryRecord::m_prevTopCallFrame[sp]
loadp VM::topEntryFrame[vm], t4
storep t4, VMEntryRecord::m_prevTopEntryFrame[sp]
loadp ProtoCallFrame::calleeValue[protoCallFrame], t4
storep t4, VMEntryRecord::m_callee[sp]

# Align stack pointer
if X86_WIN or MIPS
Expand Down
2 changes: 0 additions & 2 deletions Source/JavaScriptCore/llint/LowLevelInterpreter64.asm
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,6 @@ macro doVMEntry(makeCall)
loadp VM::topEntryFrame[vm], t4
storep t4, VMEntryRecord::m_prevTopEntryFrame[sp]
end
loadp ProtoCallFrame::calleeValue[protoCallFrame], t4
storep t4, VMEntryRecord::m_callee[sp]

loadi ProtoCallFrame::paddedArgCount[protoCallFrame], t4
addp CallFrameHeaderSlots, t4, t4
Expand Down

0 comments on commit 70ed411

Please sign in to comment.