Ignore:
Timestamp:
Sep 7, 2018, 10:29:04 AM (7 years ago)
Author:
[email protected]
Message:

[WebAssembly] Optimize JS to Wasm call by using pointer of Signature as SignatureIndex
https://bugs.webkit.org/show_bug.cgi?id=189401

Reviewed by Mark Lam.

SignatureInformation is a global repository for Signature to make Signature atomic.
It takes Ref<Signature>&& and generates SignatureIndex. And we get const Signature&
by using this SignatureIndex. However, converting SignatureIndex to const Signature&
always looks up a hash table. This is costly since JS to Wasm calls always use
Signature& to check types of arguments.

Instead of using this hash table, this patch uses a pointer of Signature as SignatureIndex.
This allows us to convert SignatureIndex to Signature by just casting it.

We also optimize SignatureInformation::singleton by making an accessor function inlined.
And we move ProtoCallFrame::init to the header since it's just setting values.

This change significantly optimizes JS to wasm calls (1e7 times) from 600ms to 320ms.

In the future, we can remove SignatureIndex by directly handling Ref<Signature>: adding
deref() of Signature which unregisters itself from SignatureInformation carefully. Or we can
make SignatureIndex uint32_t by introducing a mechanism similar to StructureID.

  • JavaScriptCore.xcodeproj/project.pbxproj:
  • Sources.txt:
  • interpreter/ProtoCallFrame.h:

(JSC::ProtoCallFrame::init):

  • wasm/WasmB3IRGenerator.cpp:

(JSC::Wasm::B3IRGenerator::addCallIndirect):

  • wasm/WasmBBQPlan.cpp:
  • wasm/WasmFormat.h:

(JSC::Wasm::WasmToWasmImportableFunction::offsetOfSignatureIndex):

  • wasm/WasmFunctionParser.h:
  • wasm/WasmModule.h:
  • wasm/WasmOMGPlan.cpp:
  • wasm/WasmSectionParser.cpp:

(JSC::Wasm::SectionParser::parseType):

  • wasm/WasmSignature.cpp:

(JSC::Wasm::SignatureInformation::adopt):
(JSC::Wasm::SignatureInformation::tryCleanup):
(JSC::Wasm::SignatureInformation::singleton): Deleted.
(JSC::Wasm::SignatureInformation::get): Deleted.

  • wasm/WasmSignature.h:

(JSC::Wasm::Signature::index const):
(JSC::Wasm::SignatureHash::SignatureHash):
(JSC::Wasm::SignatureHash::hash):
(JSC::Wasm::SignatureHash::isHashTableDeletedValue const):
(JSC::Wasm::SignatureHash::empty): Deleted.
(JSC::Wasm::SignatureHash::deleted): Deleted.

  • wasm/WasmSignatureInlines.h: Renamed from Source/JavaScriptCore/interpreter/ProtoCallFrame.cpp.

(JSC::Wasm::SignatureInformation::singleton):
(JSC::Wasm::SignatureInformation::get):

  • wasm/js/JSToWasm.cpp:
  • wasm/js/JSWebAssemblyModule.h:
  • wasm/js/WasmToJS.cpp:

(JSC::Wasm::wasmToJS):

  • wasm/js/WebAssemblyFunction.cpp:
  • wasm/js/WebAssemblyModuleRecord.cpp:
  • wasm/js/WebAssemblyWrapperFunction.cpp:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/interpreter/ProtoCallFrame.h

    r229373 r235786  
    2626#pragma once
    2727
     28#include "CodeBlock.h"
    2829#include "Register.h"
     30#include "StackAlignment.h"
    2931#include <wtf/ForbidHeapAllocation.h>
    3032
     
    7476};
    7577
     78inline void ProtoCallFrame::init(CodeBlock* codeBlock, JSObject* callee, JSValue thisValue, int argCountIncludingThis, JSValue* otherArgs)
     79{
     80    this->args = otherArgs;
     81    this->setCodeBlock(codeBlock);
     82    this->setCallee(callee);
     83    this->setArgumentCountIncludingThis(argCountIncludingThis);
     84    if (codeBlock && argCountIncludingThis < codeBlock->numParameters())
     85        this->hasArityMismatch = true;
     86    else
     87        this->hasArityMismatch = false;
     88
     89    // Round up argCountIncludingThis to keep the stack frame size aligned.
     90    size_t paddedArgsCount = roundArgumentCountToAlignFrame(argCountIncludingThis);
     91    this->setPaddedArgCount(paddedArgsCount);
     92    this->clearCurrentVPC();
     93    this->setThisValue(thisValue);
     94}
     95
    7696} // namespace JSC
Note: See TracChangeset for help on using the changeset viewer.