Changeset 216597 in webkit


Ignore:
Timestamp:
May 10, 2017 11:15:17 AM (7 years ago)
Author:
jfbastien@apple.com
Message:

WebAssembly: support name section
JSTests:

https://bugs.webkit.org/show_bug.cgi?id=171263

Reviewed by Keith Miller.

  • wasm/function-tests/nameSection.js: Added.

(const.compile):

  • wasm/function-tests/nameSection.wasm: Added.
  • wasm/function-tests/stack-trace.js: Update format

Source/JavaScriptCore:

https://bugs.webkit.org/show_bug.cgi?id=171263

Reviewed by Keith Miller.

The name section is an optional custom section in the WebAssembly
spec. At least when debugging, developers expect to be able to use
this section to obtain intelligible stack traces, otherwise we
just number the wasm functions which is somewhat painful.

This patch parses this section, dropping its content eagerly on
error, and if there is a name section then backtraces use their
value instead of numbers. Otherwise we stick to numbers as before.

Note that the format of name sections changed in mid-February:

https://github.com/WebAssembly/design/pull/984

And binaryen was only updated in early March:

https://github.com/WebAssembly/binaryen/pull/933

  • CMakeLists.txt:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • interpreter/Interpreter.cpp:

(JSC::GetStackTraceFunctor::operator()):

  • interpreter/StackVisitor.cpp:

(JSC::StackVisitor::readNonInlinedFrame):
(JSC::StackVisitor::Frame::functionName):

  • interpreter/StackVisitor.h:

(JSC::StackVisitor::Frame::wasmFunctionIndexOrName):

  • runtime/StackFrame.cpp:

(JSC::StackFrame::functionName):

  • runtime/StackFrame.h:

(JSC::StackFrame::StackFrame):
(JSC::StackFrame::wasm):

  • wasm/WasmBBQPlanInlines.h:

(JSC::Wasm::BBQPlan::initializeCallees):

  • wasm/WasmCallee.cpp:

(JSC::Wasm::Callee::Callee):

  • wasm/WasmCallee.h:

(JSC::Wasm::Callee::create):
(JSC::Wasm::Callee::indexOrName):

  • wasm/WasmFormat.cpp:

(JSC::Wasm::makeString):

  • wasm/WasmFormat.h:

(JSC::Wasm::isValidExternalKind):
(JSC::Wasm::isValidNameType):
(JSC::Wasm::NameSection::get):

  • wasm/WasmIndexOrName.cpp: Copied from Source/JavaScriptCore/wasm/WasmCallee.cpp.

(JSC::Wasm::IndexOrName::IndexOrName):
(JSC::Wasm::makeString):

  • wasm/WasmIndexOrName.h: Copied from Source/JavaScriptCore/wasm/WasmFormat.cpp.
  • wasm/WasmModuleInformation.h:
  • wasm/WasmModuleParser.cpp:
  • wasm/WasmName.h: Copied from Source/JavaScriptCore/wasm/WasmCallee.cpp.
  • wasm/WasmNameSectionParser.cpp: Added.
  • wasm/WasmNameSectionParser.h: Copied from Source/JavaScriptCore/wasm/WasmCallee.cpp.

(JSC::Wasm::NameSectionParser::NameSectionParser):

  • wasm/WasmOMGPlan.cpp:

(JSC::Wasm::OMGPlan::work):

  • wasm/WasmParser.h:

(JSC::Wasm::Parser<SuccessType>::consumeUTF8String):

Location:
trunk
Files:
3 added
19 edited
4 copied

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r216593 r216597  
     12017-05-10  JF Bastien  <jfbastien@apple.com>
     2
     3        WebAssembly: support name section
     4        https://bugs.webkit.org/show_bug.cgi?id=171263
     5
     6        Reviewed by Keith Miller.
     7
     8        * wasm/function-tests/nameSection.js: Added.
     9        (const.compile):
     10        * wasm/function-tests/nameSection.wasm: Added.
     11        * wasm/function-tests/stack-trace.js: Update format
     12
    1132017-05-10  Filip Pizlo  <fpizlo@apple.com>
    214
  • trunk/JSTests/wasm/function-tests/stack-trace.js

    r215854 r216597  
    4848    assert(stacktrace[0].indexOf("imp") !== -1); // the arrow function import named "imp".
    4949    assert(stacktrace[1] === "wasm function@[wasm code]"); // the wasm->js stub
    50     assert(stacktrace[2] === "wasm function index: 4@[wasm code]");
    51     assert(stacktrace[3] === "wasm function index: 2@[wasm code]");
    52     assert(stacktrace[4] === "wasm function index: 3@[wasm code]");
    53     assert(stacktrace[5] === "wasm function index: 1@[wasm code]");
     50    assert(stacktrace[2] === "wasm function: 4@[wasm code]");
     51    assert(stacktrace[3] === "wasm function: 2@[wasm code]");
     52    assert(stacktrace[4] === "wasm function: 3@[wasm code]");
     53    assert(stacktrace[5] === "wasm function: 1@[wasm code]");
    5454    assert(stacktrace[6] === "wasm function@[wasm code]"); // wasm entry
    5555
  • trunk/Source/JavaScriptCore/CMakeLists.txt

    r216481 r216597  
    952952    wasm/WasmFaultSignalHandler.cpp
    953953    wasm/WasmFormat.cpp
     954    wasm/WasmIndexOrName.cpp
    954955    wasm/WasmMachineThreads.cpp
    955956    wasm/WasmMemory.cpp
     
    958959    wasm/WasmModuleInformation.cpp
    959960    wasm/WasmModuleParser.cpp
     961    wasm/WasmNameSectionParser.cpp
    960962    wasm/WasmOMGPlan.cpp
    961963    wasm/WasmOpcodeOrigin.cpp
  • trunk/Source/JavaScriptCore/ChangeLog

    r216593 r216597  
     12017-05-10  JF Bastien  <jfbastien@apple.com>
     2
     3        WebAssembly: support name section
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=171263
     6
     7        Reviewed by Keith Miller.
     8
     9        The name section is an optional custom section in the WebAssembly
     10        spec. At least when debugging, developers expect to be able to use
     11        this section to obtain intelligible stack traces, otherwise we
     12        just number the wasm functions which is somewhat painful.
     13
     14        This patch parses this section, dropping its content eagerly on
     15        error, and if there is a name section then backtraces use their
     16        value instead of numbers. Otherwise we stick to numbers as before.
     17
     18        Note that the format of name sections changed in mid-February:
     19          https://github.com/WebAssembly/design/pull/984
     20        And binaryen was only updated in early March:
     21          https://github.com/WebAssembly/binaryen/pull/933
     22
     23        * CMakeLists.txt:
     24        * JavaScriptCore.xcodeproj/project.pbxproj:
     25        * interpreter/Interpreter.cpp:
     26        (JSC::GetStackTraceFunctor::operator()):
     27        * interpreter/StackVisitor.cpp:
     28        (JSC::StackVisitor::readNonInlinedFrame):
     29        (JSC::StackVisitor::Frame::functionName):
     30        * interpreter/StackVisitor.h:
     31        (JSC::StackVisitor::Frame::wasmFunctionIndexOrName):
     32        * runtime/StackFrame.cpp:
     33        (JSC::StackFrame::functionName):
     34        * runtime/StackFrame.h:
     35        (JSC::StackFrame::StackFrame):
     36        (JSC::StackFrame::wasm):
     37        * wasm/WasmBBQPlanInlines.h:
     38        (JSC::Wasm::BBQPlan::initializeCallees):
     39        * wasm/WasmCallee.cpp:
     40        (JSC::Wasm::Callee::Callee):
     41        * wasm/WasmCallee.h:
     42        (JSC::Wasm::Callee::create):
     43        (JSC::Wasm::Callee::indexOrName):
     44        * wasm/WasmFormat.cpp:
     45        (JSC::Wasm::makeString):
     46        * wasm/WasmFormat.h:
     47        (JSC::Wasm::isValidExternalKind):
     48        (JSC::Wasm::isValidNameType):
     49        (JSC::Wasm::NameSection::get):
     50        * wasm/WasmIndexOrName.cpp: Copied from Source/JavaScriptCore/wasm/WasmCallee.cpp.
     51        (JSC::Wasm::IndexOrName::IndexOrName):
     52        (JSC::Wasm::makeString):
     53        * wasm/WasmIndexOrName.h: Copied from Source/JavaScriptCore/wasm/WasmFormat.cpp.
     54        * wasm/WasmModuleInformation.h:
     55        * wasm/WasmModuleParser.cpp:
     56        * wasm/WasmName.h: Copied from Source/JavaScriptCore/wasm/WasmCallee.cpp.
     57        * wasm/WasmNameSectionParser.cpp: Added.
     58        * wasm/WasmNameSectionParser.h: Copied from Source/JavaScriptCore/wasm/WasmCallee.cpp.
     59        (JSC::Wasm::NameSectionParser::NameSectionParser):
     60        * wasm/WasmOMGPlan.cpp:
     61        (JSC::Wasm::OMGPlan::work):
     62        * wasm/WasmParser.h:
     63        (JSC::Wasm::Parser<SuccessType>::consumeUTF8String):
     64
    1652017-05-10  Filip Pizlo  <fpizlo@apple.com>
    266
  • trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r216481 r216597  
    21462146                AD4B1DF91DF244E20071AE32 /* WasmBinding.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AD4B1DF71DF244D70071AE32 /* WasmBinding.cpp */; };
    21472147                AD4B1DFA1DF244E20071AE32 /* WasmBinding.h in Headers */ = {isa = PBXBuildFile; fileRef = AD4B1DF81DF244D70071AE32 /* WasmBinding.h */; };
     2148                AD5B416F1EBAFB77008EFA43 /* WasmName.h in Headers */ = {isa = PBXBuildFile; fileRef = AD5B416E1EBAFB65008EFA43 /* WasmName.h */; settings = {ATTRIBUTES = (Private, ); }; };
    21482149                AD7438C01E0457A400FD0C2A /* WasmSignature.h in Headers */ = {isa = PBXBuildFile; fileRef = AD7438BF1E04579200FD0C2A /* WasmSignature.h */; settings = {ATTRIBUTES = (Private, ); }; };
    21492150                AD7438C11E0457AA00FD0C2A /* WasmSignature.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AD7438BE1E04579200FD0C2A /* WasmSignature.cpp */; };
    21502151                AD86A93E1AA4D88D002FE77F /* WeakGCMapInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = AD86A93D1AA4D87C002FE77F /* WeakGCMapInlines.h */; settings = {ATTRIBUTES = (Private, ); }; };
     2152                AD8FF3971EB5BDA80087FF82 /* WasmIndexOrName.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AD8FF3961EB5BD850087FF82 /* WasmIndexOrName.cpp */; };
     2153                AD8FF3981EB5BDB20087FF82 /* WasmIndexOrName.h in Headers */ = {isa = PBXBuildFile; fileRef = AD8FF3951EB5BD850087FF82 /* WasmIndexOrName.h */; settings = {ATTRIBUTES = (Private, ); }; };
    21512154                AD9E852F1E8A0C7C008DE39E /* JSWebAssemblyCodeBlock.h in Headers */ = {isa = PBXBuildFile; fileRef = AD9E852E1E8A0C6E008DE39E /* JSWebAssemblyCodeBlock.h */; settings = {ATTRIBUTES = (Private, ); }; };
    21522155                ADB6F67D1E15D7600082F384 /* WasmPageCount.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ADB6F67C1E15D7500082F384 /* WasmPageCount.cpp */; };
    21532156                ADBC54D41DF8EA2B005BF738 /* WebAssemblyToJSCallee.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ADBC54D21DF8EA00005BF738 /* WebAssemblyToJSCallee.cpp */; };
    21542157                ADBC54D51DF8EA2B005BF738 /* WebAssemblyToJSCallee.h in Headers */ = {isa = PBXBuildFile; fileRef = ADBC54D31DF8EA00005BF738 /* WebAssemblyToJSCallee.h */; };
     2158                ADD8FA451EB3078E00DF542F /* WasmNameSectionParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ADD8FA441EB3077100DF542F /* WasmNameSectionParser.cpp */; };
     2159                ADD8FA461EB3079700DF542F /* WasmNameSectionParser.h in Headers */ = {isa = PBXBuildFile; fileRef = ADD8FA431EB3077100DF542F /* WasmNameSectionParser.h */; };
    21552160                ADDB1F6318D77DBE009B58A8 /* OpaqueRootSet.h in Headers */ = {isa = PBXBuildFile; fileRef = ADDB1F6218D77DB7009B58A8 /* OpaqueRootSet.h */; settings = {ATTRIBUTES = (Private, ); }; };
    21562161                ADE39FFF16DD144B0003CD4A /* PropertyTable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AD1CF06816DCAB2D00B97123 /* PropertyTable.cpp */; };
     
    47744779                AD4B1DF71DF244D70071AE32 /* WasmBinding.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WasmBinding.cpp; sourceTree = "<group>"; };
    47754780                AD4B1DF81DF244D70071AE32 /* WasmBinding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WasmBinding.h; sourceTree = "<group>"; };
     4781                AD5B416E1EBAFB65008EFA43 /* WasmName.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WasmName.h; sourceTree = "<group>"; };
    47764782                AD7438BE1E04579200FD0C2A /* WasmSignature.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WasmSignature.cpp; sourceTree = "<group>"; };
    47774783                AD7438BF1E04579200FD0C2A /* WasmSignature.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WasmSignature.h; sourceTree = "<group>"; };
    47784784                AD86A93D1AA4D87C002FE77F /* WeakGCMapInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeakGCMapInlines.h; sourceTree = "<group>"; };
     4785                AD8FF3951EB5BD850087FF82 /* WasmIndexOrName.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WasmIndexOrName.h; sourceTree = "<group>"; };
     4786                AD8FF3961EB5BD850087FF82 /* WasmIndexOrName.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WasmIndexOrName.cpp; sourceTree = "<group>"; };
    47794787                AD9E852E1E8A0C6E008DE39E /* JSWebAssemblyCodeBlock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JSWebAssemblyCodeBlock.h; path = js/JSWebAssemblyCodeBlock.h; sourceTree = "<group>"; };
    47804788                ADB6F67C1E15D7500082F384 /* WasmPageCount.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WasmPageCount.cpp; sourceTree = "<group>"; };
    47814789                ADBC54D21DF8EA00005BF738 /* WebAssemblyToJSCallee.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WebAssemblyToJSCallee.cpp; path = js/WebAssemblyToJSCallee.cpp; sourceTree = "<group>"; };
    47824790                ADBC54D31DF8EA00005BF738 /* WebAssemblyToJSCallee.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebAssemblyToJSCallee.h; path = js/WebAssemblyToJSCallee.h; sourceTree = "<group>"; };
     4791                ADD8FA431EB3077100DF542F /* WasmNameSectionParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WasmNameSectionParser.h; sourceTree = "<group>"; };
     4792                ADD8FA441EB3077100DF542F /* WasmNameSectionParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WasmNameSectionParser.cpp; sourceTree = "<group>"; };
    47834793                ADDB1F6218D77DB7009B58A8 /* OpaqueRootSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OpaqueRootSet.h; sourceTree = "<group>"; };
    47844794                ADE802931E08F1C90058DE78 /* JSWebAssemblyLinkError.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = JSWebAssemblyLinkError.cpp; path = js/JSWebAssemblyLinkError.cpp; sourceTree = "<group>"; };
     
    64106420                                AD412B321E7B2E8A008AF157 /* WasmContext.h */,
    64116421                                79DAE2791E03C82200B526AA /* WasmExceptionType.h */,
     6422                                5381B9361E60E9660090F794 /* WasmFaultSignalHandler.cpp */,
     6423                                5381B9381E60E97D0090F794 /* WasmFaultSignalHandler.h */,
    64126424                                AD2FCC321DC4045300B3E736 /* WasmFormat.cpp */,
    64136425                                7BC547D21B69599B00959B58 /* WasmFormat.h */,
    64146426                                53F40E8A1D5901BB0099A1B6 /* WasmFunctionParser.h */,
     6427                                AD8FF3961EB5BD850087FF82 /* WasmIndexOrName.cpp */,
     6428                                AD8FF3951EB5BD850087FF82 /* WasmIndexOrName.h */,
    64156429                                53E9E0A91EAE83DE00FEE251 /* WasmMachineThreads.cpp */,
    64166430                                53E9E0AA1EAE83DE00FEE251 /* WasmMachineThreads.h */,
    6417                                 790081361E95A8EC0052D7CD /* WasmModule.cpp */,
    6418                                 790081371E95A8EC0052D7CD /* WasmModule.h */,
    64196431                                535557151D9DFA32006D583B /* WasmMemory.cpp */,
    64206432                                535557131D9D9EA5006D583B /* WasmMemory.h */,
    64216433                                79B759711DFA4C600052174C /* WasmMemoryInformation.cpp */,
    64226434                                79B759721DFA4C600052174C /* WasmMemoryInformation.h */,
     6435                                790081361E95A8EC0052D7CD /* WasmModule.cpp */,
     6436                                790081371E95A8EC0052D7CD /* WasmModule.h */,
    64236437                                53E777E11E92E265007CBEC4 /* WasmModuleInformation.cpp */,
    64246438                                53E777E21E92E265007CBEC4 /* WasmModuleInformation.h */,
    64256439                                53F40E961D5A7BEC0099A1B6 /* WasmModuleParser.cpp */,
    64266440                                53F40E941D5A7AEF0099A1B6 /* WasmModuleParser.h */,
     6441                                AD5B416E1EBAFB65008EFA43 /* WasmName.h */,
     6442                                ADD8FA441EB3077100DF542F /* WasmNameSectionParser.cpp */,
     6443                                ADD8FA431EB3077100DF542F /* WasmNameSectionParser.h */,
    64276444                                5311BD481EA581E500525281 /* WasmOMGPlan.cpp */,
    64286445                                5311BD491EA581E500525281 /* WasmOMGPlan.h */,
    6429                                 ADB6F67C1E15D7500082F384 /* WasmPageCount.cpp */,
    6430                                 5381B9361E60E9660090F794 /* WasmFaultSignalHandler.cpp */,
    6431                                 5381B9381E60E97D0090F794 /* WasmFaultSignalHandler.h */,
    64326446                                53C6FEF01E8AFE0C00B18425 /* WasmOpcodeOrigin.cpp */,
    64336447                                53C6FEEE1E8ADFA900B18425 /* WasmOpcodeOrigin.h */,
     6448                                ADB6F67C1E15D7500082F384 /* WasmPageCount.cpp */,
    64346449                                79B759731DFA4C600052174C /* WasmPageCount.h */,
    64356450                                53F40E8C1D5901F20099A1B6 /* WasmParser.h */,
     
    82188233                                0F40E4A71C497F7400A577FA /* AirOpcode.h in Headers */,
    82198234                                0F40E4A81C497F7400A577FA /* AirOpcodeGenerated.h in Headers */,
     8235                                AD8FF3981EB5BDB20087FF82 /* WasmIndexOrName.h in Headers */,
    82208236                                0F40E4A91C497F7400A577FA /* AirOpcodeUtils.h in Headers */,
    82218237                                0FB387901BFBC44D00E3AB1E /* AirOptimizeBlockOrder.h in Headers */,
     
    83368352                                0F4C91661C29F4F2004341A6 /* B3OriginDump.h in Headers */,
    83378353                                0FEC85261BDACDAC0080FF74 /* B3PatchpointSpecial.h in Headers */,
     8354                                ADD8FA461EB3079700DF542F /* WasmNameSectionParser.h in Headers */,
    83388355                                0FEC85281BDACDAC0080FF74 /* B3PatchpointValue.h in Headers */,
    83398356                                799EF7C41C56ED96002B0534 /* B3PCToOriginMap.h in Headers */,
     
    86558672                                79FC8A081E32E9F000D88F0E /* DFGRegisteredStructure.h in Headers */,
    86568673                                7980C16D1E3A940E00B71615 /* DFGRegisteredStructureSet.h in Headers */,
     8674                                AD5B416F1EBAFB77008EFA43 /* WasmName.h in Headers */,
    86578675                                0F2FCCFC18A60070001A27F8 /* DFGSafepoint.h in Headers */,
    86588676                                A77A424317A0BBFD00A8DB81 /* DFGSafeToExecute.h in Headers */,
     
    1098411002                                0FE0502C1AA9095600D33B33 /* VarOffset.cpp in Sources */,
    1098511003                                0F20C2591A8013AB00DA3229 /* VirtualRegister.cpp in Sources */,
     11004                                AD8FF3971EB5BDA80087FF82 /* WasmIndexOrName.cpp in Sources */,
    1098611005                                0F952AA21DF7860D00E06FBD /* VisitRaceKey.cpp in Sources */,
    1098711006                                E18E3A590DF9278C00D90B34 /* VM.cpp in Sources */,
     
    1104011059                                86704B8912DBA33700A9FE7B /* YarrPattern.cpp in Sources */,
    1104111060                                86704B4212DB8A8100A9FE7B /* YarrSyntaxChecker.cpp in Sources */,
     11061                                ADD8FA451EB3078E00DF542F /* WasmNameSectionParser.cpp in Sources */,
    1104211062                                321D9E4CFB67423A97F191A7 /* ModuleNamespaceAccessCase.cpp in Sources */,
    1104311063                        );
  • trunk/Source/JavaScriptCore/interpreter/Interpreter.cpp

    r216428 r216597  
    481481        if (m_remainingCapacityForFrameCapture) {
    482482            if (visitor->isWasmFrame()) {
    483                 std::optional<unsigned> wasmFunctionIndex = visitor->wasmFunctionIndex();
    484                 m_results.append(StackFrame::wasm(wasmFunctionIndex ? *wasmFunctionIndex : StackFrame::invalidWasmIndex));
     483                m_results.append(StackFrame::wasm(visitor->wasmFunctionIndexOrName()));
    485484            } else if (!!visitor->codeBlock() && !visitor->codeBlock()->unlinkedCodeBlock()->isBuiltinFunction()) {
    486485                m_results.append(
  • trunk/Source/JavaScriptCore/interpreter/StackVisitor.cpp

    r215854 r216597  
    3333#include "JSCInlines.h"
    3434#include "WasmCallee.h"
     35#include "WasmIndexOrName.h"
    3536#include <wtf/text/StringBuilder.h>
    3637
     
    167168        CalleeBits bits = callFrame->callee();
    168169        if (bits.isWasm())
    169             m_frame.m_wasmFunctionIndex = bits.asWasmCallee()->index();
     170            m_frame.m_wasmFunctionIndexOrName = bits.asWasmCallee()->indexOrName();
    170171#endif
    171172    } else {
     
    284285    switch (codeType()) {
    285286    case CodeType::Wasm:
    286         if (m_wasmFunctionIndex)
    287             traceLine = makeString("wasm function index: ", String::number(*m_wasmFunctionIndex));
     287        if (m_wasmFunctionIndexOrName.isEmpty())
     288            traceLine = makeString("wasm function");
    288289        else
    289             traceLine = ASCIILiteral("wasm function");
     290            traceLine = makeString("wasm function: ", makeString(m_wasmFunctionIndexOrName));
    290291        break;
    291292    case CodeType::Eval:
  • trunk/Source/JavaScriptCore/interpreter/StackVisitor.h

    r215854 r216597  
    2828#include "CalleeBits.h"
    2929#include "VMEntryRecord.h"
     30#include "WasmIndexOrName.h"
    3031#include <functional>
    3132#include <wtf/Indenter.h>
     
    7879        bool isInlinedFrame() const { return !!inlineCallFrame(); }
    7980        bool isWasmFrame() const;
    80         std::optional<unsigned> const wasmFunctionIndex()
     81        Wasm::IndexOrName const wasmFunctionIndexOrName()
    8182        {
    8283            ASSERT(isWasmFrame());
    83             return m_wasmFunctionIndex;
     84            return m_wasmFunctionIndexOrName;
    8485        }
    8586
     
    122123        size_t m_argumentCountIncludingThis;
    123124        unsigned m_bytecodeOffset;
    124         std::optional<unsigned> m_wasmFunctionIndex;
     125        Wasm::IndexOrName m_wasmFunctionIndexOrName;
    125126        bool m_callerIsVMEntryFrame : 1;
    126127        bool m_isWasmFrame : 1;
  • trunk/Source/JavaScriptCore/runtime/StackFrame.cpp

    r215854 r216597  
    11/*
    2  * Copyright (C) 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    5959{
    6060    if (m_isWasmFrame) {
    61         if (m_wasmFunctionIndex == invalidWasmIndex)
     61        if (m_wasmFunctionIndexOrName.isEmpty())
    6262            return ASCIILiteral("wasm function");
    63         return makeString("wasm function index: ", String::number(m_wasmFunctionIndex));
     63        return makeString("wasm function: ", makeString(m_wasmFunctionIndexOrName));
    6464    }
    6565
  • trunk/Source/JavaScriptCore/runtime/StackFrame.h

    r215854 r216597  
    11/*
    2  * Copyright (C) 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2727
    2828#include "Strong.h"
     29#include "WasmIndexOrName.h"
    2930#include <limits.h>
    3031
     
    3637class StackFrame {
    3738public:
    38     StackFrame() = default;
     39    StackFrame()
     40        : m_bytecodeOffset(UINT_MAX)
     41    { }
    3942
    4043    StackFrame(VM& vm, JSCell* callee)
     
    4952    { }
    5053
    51     static constexpr unsigned invalidWasmIndex = UINT_MAX;
    52     static StackFrame wasm(unsigned index)
     54    static StackFrame wasm(Wasm::IndexOrName indexOrName)
    5355    {
    5456        StackFrame result;
    5557        result.m_isWasmFrame = true;
    56         result.m_wasmFunctionIndex = index;
     58        result.m_wasmFunctionIndexOrName = indexOrName;
    5759        return result;
    5860    }
     
    7981    union {
    8082        unsigned m_bytecodeOffset;
    81         unsigned m_wasmFunctionIndex;
     83        Wasm::IndexOrName m_wasmFunctionIndexOrName;
    8284    };
    8385    bool m_isWasmFrame { false };
  • trunk/Source/JavaScriptCore/wasm/WasmBBQPlanInlines.h

    r215854 r216597  
    4444        MacroAssembler::repatchPointer(function->jsToWasmCalleeMoveLocation, CalleeBits::boxWasm(jsEntrypointCallee.ptr()));
    4545
    46         Ref<Wasm::Callee> wasmEntrypointCallee = Wasm::Callee::create(WTFMove(function->wasmEntrypoint), internalFunctionIndex + m_moduleInformation->importFunctionCount());
     46        size_t functionIndexSpace = internalFunctionIndex + m_moduleInformation->importFunctionCount();
     47        Ref<Wasm::Callee> wasmEntrypointCallee = Wasm::Callee::create(WTFMove(function->wasmEntrypoint), functionIndexSpace, m_moduleInformation->nameSection.get(functionIndexSpace));
    4748        MacroAssembler::repatchPointer(function->wasmCalleeMoveLocation, CalleeBits::boxWasm(wasmEntrypointCallee.ptr()));
    4849
  • trunk/Source/JavaScriptCore/wasm/WasmCallee.cpp

    r215854 r216597  
    3333namespace JSC { namespace Wasm {
    3434
    35 Callee::Callee(Entrypoint&& entrypoint, unsigned index)
     35Callee::Callee(Entrypoint&& entrypoint)
    3636    : m_entrypoint(WTFMove(entrypoint))
    37     , m_index(index)
     37{
     38    registerCode(m_entrypoint.compilation->codeRef().executableMemory()->start(), m_entrypoint.compilation->codeRef().executableMemory()->end());
     39}
     40
     41Callee::Callee(Entrypoint&& entrypoint, size_t index, const Name* name)
     42    : m_entrypoint(WTFMove(entrypoint))
     43    , m_indexOrName(index, name)
    3844{
    3945    registerCode(m_entrypoint.compilation->codeRef().executableMemory()->start(), m_entrypoint.compilation->codeRef().executableMemory()->end());
  • trunk/Source/JavaScriptCore/wasm/WasmCallee.h

    r215854 r216597  
    3131#include "RegisterAtOffsetList.h"
    3232#include "WasmFormat.h"
     33#include "WasmIndexOrName.h"
    3334#include <wtf/ThreadSafeRefCounted.h>
    3435
     
    3839    WTF_MAKE_FAST_ALLOCATED;
    3940public:
     41    static Ref<Callee> create(Wasm::Entrypoint&& entrypoint)
     42    {
     43        Callee* callee = new Callee(WTFMove(entrypoint));
     44        return adoptRef(*callee);
     45    }
    4046
    41     // We use this when we're the JS entrypoint, we don't ascribe an index to those.
    42     static constexpr unsigned invalidCalleeIndex = UINT_MAX;
    43 
    44     static Ref<Callee> create(Wasm::Entrypoint&& entrypoint, unsigned index = invalidCalleeIndex)
     47    static Ref<Callee> create(Wasm::Entrypoint&& entrypoint, size_t index, const Name* name)
    4548    {
    46         Callee* callee = new Callee(WTFMove(entrypoint), index);
     49        Callee* callee = new Callee(WTFMove(entrypoint), index, name);
    4750        return adoptRef(*callee);
    4851    }
     
    5154
    5255    RegisterAtOffsetList* calleeSaveRegisters() { return &m_entrypoint.calleeSaveRegisters; }
    53     std::optional<unsigned> index() const
    54     {
    55         if (m_index == invalidCalleeIndex)
    56             return std::nullopt;
    57         return m_index;
    58     }
     56    IndexOrName indexOrName() const { return m_indexOrName; }
    5957
    6058private:
    61     JS_EXPORT_PRIVATE Callee(Wasm::Entrypoint&&, unsigned index);
     59    JS_EXPORT_PRIVATE Callee(Wasm::Entrypoint&&);
     60    JS_EXPORT_PRIVATE Callee(Wasm::Entrypoint&&, size_t, const Name*);
    6261
    6362    Wasm::Entrypoint m_entrypoint;
    64     unsigned m_index;
     63    IndexOrName m_indexOrName;
    6564};
    6665
  • trunk/Source/JavaScriptCore/wasm/WasmFormat.cpp

    r214919 r216597  
    11/*
    2  * Copyright (C) 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    5656}
    5757
    58 String makeString(const Vector<LChar>& characters)
     58String makeString(const Name& characters)
    5959{
    6060    String result = String::fromUTF8(characters);
  • trunk/Source/JavaScriptCore/wasm/WasmFormat.h

    r215843 r216597  
    3434#include "RegisterAtOffsetList.h"
    3535#include "WasmMemoryInformation.h"
     36#include "WasmName.h"
    3637#include "WasmOps.h"
    3738#include "WasmPageCount.h"
     
    7576
    7677template<typename Int>
    77 static bool isValidExternalKind(Int val)
     78inline bool isValidExternalKind(Int val)
    7879{
    7980    switch (val) {
     
    8384    case static_cast<Int>(ExternalKind::Global):
    8485        return true;
    85     default:
    86         return false;
    87     }
     86    }
     87    return false;
    8888}
    8989
     
    106106
    107107struct Import {
    108     const Vector<LChar> module;
    109     const Vector<LChar> field;
     108    const Name module;
     109    const Name field;
    110110    ExternalKind kind;
    111111    unsigned kindIndex; // Index in the vector of the corresponding kind.
     
    113113
    114114struct Export {
    115     const Vector<LChar> field;
     115    const Name field;
    116116    ExternalKind kind;
    117117    unsigned kindIndex; // Index in the vector of the corresponding kind.
    118118};
    119119
    120 String makeString(const Vector<LChar>& characters);
     120String makeString(const Name& characters);
    121121
    122122struct Global {
     
    232232   
    233233struct CustomSection {
    234     Vector<LChar> name;
     234    Name name;
    235235    Vector<uint8_t> payload;
     236};
     237
     238enum class NameType : uint8_t {
     239    Function = 1,
     240    Local = 2,
     241};
     242   
     243template<typename Int>
     244inline bool isValidNameType(Int val)
     245{
     246    switch (val) {
     247    case static_cast<Int>(NameType::Function):
     248    case static_cast<Int>(NameType::Local):
     249        return true;
     250    }
     251    return false;
     252}
     253   
     254struct NameSection {
     255    Vector<Name> functionNames;
     256    const Name* get(size_t functionIndexSpace)
     257    {
     258        return functionIndexSpace < functionNames.size() ? &functionNames[functionIndexSpace] : nullptr;
     259    }
    236260};
    237261
  • trunk/Source/JavaScriptCore/wasm/WasmIndexOrName.cpp

    r216596 r216597  
    11/*
    2  * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2525
    2626#include "config.h"
    27 #include "WasmCallee.h"
    28 
    29 #if ENABLE(WEBASSEMBLY)
    30 
    31 #include "WasmFaultSignalHandler.h"
     27#include "WasmIndexOrName.h"
    3228
    3329namespace JSC { namespace Wasm {
    3430
    35 Callee::Callee(Entrypoint&& entrypoint, unsigned index)
    36     : m_entrypoint(WTFMove(entrypoint))
    37     , m_index(index)
     31IndexOrName::IndexOrName(Index index, const Name* name)
    3832{
    39     registerCode(m_entrypoint.compilation->codeRef().executableMemory()->start(), m_entrypoint.compilation->codeRef().executableMemory()->end());
     33    static_assert(sizeof(m_index) == sizeof(m_name), "bit-tagging depends on sizes being equal");
     34    static_assert(sizeof(m_index) == sizeof(*this), "bit-tagging depends on object being the size of the union's types");
     35
     36    if ((index & allTags) || (bitwise_cast<Index>(name) & allTags))
     37        *this = IndexOrName();
     38    else if (name)
     39        m_name = name;
     40    else
     41        m_index = indexTag | index;
    4042}
    4143
     44String makeString(const IndexOrName& ion)
     45{
     46    if (ion.isEmpty())
     47        return String();
     48    if (ion.isIndex())
     49        return String::number(ion.m_index & ~IndexOrName::indexTag);
     50    return String(ion.m_name->data(), ion.m_name->size());
     51};
     52
    4253} } // namespace JSC::Wasm
    43 
    44 #endif // ENABLE(WEBASSEMBLY)
  • trunk/Source/JavaScriptCore/wasm/WasmIndexOrName.h

    r216596 r216597  
    11/*
    2  * Copyright (C) 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #include "config.h"
     26#pragma once
    2727
    28 #include "WasmFormat.h"
    29 
    30 #if ENABLE(WEBASSEMBLY)
    31 
    32 #include "WasmMemory.h"
    33 #include <wtf/FastMalloc.h>
     28#include "WasmName.h"
     29#include <wtf/StdLibExtras.h>
     30#include <wtf/text/WTFString.h>
    3431
    3532namespace JSC { namespace Wasm {
    3633
    37 Segment* Segment::create(I32InitExpr offset, uint32_t sizeInBytes)
    38 {
    39     auto allocated = tryFastCalloc(sizeof(Segment) + sizeInBytes, 1);
    40     Segment* segment;
    41     if (!allocated.getValue(segment))
    42         return nullptr;
    43     segment->offset = offset;
    44     segment->sizeInBytes = sizeInBytes;
    45     return segment;
    46 }
     34struct IndexOrName {
     35    typedef size_t Index;
    4736
    48 void Segment::destroy(Segment *segment)
    49 {
    50     fastFree(segment);
    51 }
     37    IndexOrName()
     38        : m_index(emptyTag)
     39    { }
     40    IndexOrName(Index, const Name*);
     41    bool isEmpty() const { return bitwise_cast<Index>(*this) & emptyTag; }
     42    bool isIndex() const { return bitwise_cast<Index>(*this) & indexTag; }
     43    bool isName() const { return !(isEmpty() || isName()); }
    5244
    53 Segment::Ptr Segment::adoptPtr(Segment* segment)
    54 {
    55     return Ptr(segment, &Segment::destroy);
    56 }
     45    friend String makeString(const IndexOrName&);
    5746
    58 String makeString(const Vector<LChar>& characters)
    59 {
    60     String result = String::fromUTF8(characters);
    61     ASSERT(result);
    62     return result;
    63 }
     47private:
     48    union {
     49        Index m_index;
     50        const Name* m_name;
     51    };
     52
     53    // Use the top bits as tags. Neither pointers nor the function index space should use them.
     54    static constexpr Index indexTag = 1ull << (CHAR_BIT * sizeof(Index) - 1);
     55    static constexpr Index emptyTag = 1ull << (CHAR_BIT * sizeof(Index) - 2);
     56    static constexpr Index allTags = indexTag | emptyTag;
     57};
     58
     59String makeString(const IndexOrName&);
    6460
    6561} } // namespace JSC::Wasm
    66 
    67 #endif // ENABLE(WEBASSEMBLY)
  • trunk/Source/JavaScriptCore/wasm/WasmModuleInformation.h

    r214919 r216597  
    7575    unsigned firstInternalGlobal { 0 };
    7676    Vector<CustomSection> customSections;
    77 
     77    NameSection nameSection;
    7878};
    7979
  • trunk/Source/JavaScriptCore/wasm/WasmModuleParser.cpp

    r214919 r216597  
    11/*
    2  * Copyright (C) 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3131#include "IdentifierInlines.h"
    3232#include "JSWebAssemblyTable.h"
    33 #include "WasmFormat.h"
    3433#include "WasmMemoryInformation.h"
     34#include "WasmNameSectionParser.h"
    3535#include "WasmOps.h"
    3636#include "WasmSections.h"
    37 
    38 #include <sys/mman.h>
    3937
    4038namespace JSC { namespace Wasm {
     
    157155        uint32_t moduleLen;
    158156        uint32_t fieldLen;
    159         Vector<LChar> moduleString;
    160         Vector<LChar> fieldString;
     157        Name moduleString;
     158        Name fieldString;
    161159        ExternalKind kind;
    162160        unsigned kindIndex { 0 };
     
    369367    for (uint32_t exportNumber = 0; exportNumber < exportCount; ++exportNumber) {
    370368        uint32_t fieldLen;
    371         Vector<LChar> fieldString;
     369        Name fieldString;
    372370        ExternalKind kind;
    373371        unsigned kindIndex;
     
    606604        section.payload.uncheckedAppend(byte);
    607605    }
    608    
     606
     607    Name nameName = { 'n', 'a', 'm', 'e' };
     608    if (section.name == nameName) {
     609        NameSectionParser nameSectionParser(section.payload.begin(), section.payload.size(), m_info);
     610        if (auto nameSection = nameSectionParser.parse())
     611            m_info->nameSection = WTFMove(*nameSection);
     612    }
     613
    609614    m_info->customSections.uncheckedAppend(WTFMove(section));
    610615
  • trunk/Source/JavaScriptCore/wasm/WasmName.h

    r216596 r216597  
    11/*
    2  * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #include "config.h"
    27 #include "WasmCallee.h"
     26#pragma once
    2827
    29 #if ENABLE(WEBASSEMBLY)
     28#include <wtf/Vector.h>
     29#include <wtf/text/LChar.h>
    3030
    31 #include "WasmFaultSignalHandler.h"
     31namespace JSC {
    3232
    33 namespace JSC { namespace Wasm {
     33namespace Wasm {
    3434
    35 Callee::Callee(Entrypoint&& entrypoint, unsigned index)
    36     : m_entrypoint(WTFMove(entrypoint))
    37     , m_index(index)
    38 {
    39     registerCode(m_entrypoint.compilation->codeRef().executableMemory()->start(), m_entrypoint.compilation->codeRef().executableMemory()->end());
    40 }
     35using Name = Vector<LChar>;
    4136
    4237} } // namespace JSC::Wasm
    43 
    44 #endif // ENABLE(WEBASSEMBLY)
  • trunk/Source/JavaScriptCore/wasm/WasmNameSectionParser.h

    r216596 r216597  
    11/*
    2  * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #include "config.h"
    27 #include "WasmCallee.h"
     26#pragma once
    2827
    2928#if ENABLE(WEBASSEMBLY)
    3029
    31 #include "WasmFaultSignalHandler.h"
     30#include "WasmFormat.h"
     31#include "WasmParser.h"
    3232
    3333namespace JSC { namespace Wasm {
    3434
    35 Callee::Callee(Entrypoint&& entrypoint, unsigned index)
    36     : m_entrypoint(WTFMove(entrypoint))
    37     , m_index(index)
    38 {
    39     registerCode(m_entrypoint.compilation->codeRef().executableMemory()->start(), m_entrypoint.compilation->codeRef().executableMemory()->end());
    40 }
     35class NameSectionParser : public Parser<NameSection> {
     36public:
     37    NameSectionParser(const uint8_t* sourceBuffer, size_t sourceLength, const ModuleInformation& info)
     38        : Parser(sourceBuffer, sourceLength)
     39        , m_info(info)
     40    {
     41    }
     42
     43    Result WARN_UNUSED_RETURN parse();
     44   
     45private:
     46    const ModuleInformation& m_info;
     47};
    4148
    4249} } // namespace JSC::Wasm
  • trunk/Source/JavaScriptCore/wasm/WasmOMGPlan.cpp

    r215896 r216597  
    9999    {
    100100        ASSERT(m_codeBlock.ptr() == m_module->codeBlockFor(mode()));
    101         Ref<Callee> callee = Callee::create(WTFMove(omgEntrypoint), functionIndexSpace);
     101        Ref<Callee> callee = Callee::create(WTFMove(omgEntrypoint), functionIndexSpace, m_moduleInformation->nameSection.get(functionIndexSpace));
    102102        MacroAssembler::repatchPointer(parseAndCompileResult.value()->wasmCalleeMoveLocation, CalleeBits::boxWasm(callee.ptr()));
    103103        ASSERT(!m_codeBlock->m_optimizedCallees[m_functionIndex]);
  • trunk/Source/JavaScriptCore/wasm/WasmParser.h

    r214919 r216597  
    11/*
    2  * Copyright (C) 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    6363    bool WARN_UNUSED_RETURN consumeCharacter(char);
    6464    bool WARN_UNUSED_RETURN consumeString(const char*);
    65     bool WARN_UNUSED_RETURN consumeUTF8String(Vector<LChar>&, size_t);
     65    bool WARN_UNUSED_RETURN consumeUTF8String(Name&, size_t);
    6666
    6767    bool WARN_UNUSED_RETURN parseVarUInt1(uint8_t&);
     
    143143
    144144template<typename SuccessType>
    145 ALWAYS_INLINE bool Parser<SuccessType>::consumeUTF8String(Vector<LChar>& result, size_t stringLength)
     145ALWAYS_INLINE bool Parser<SuccessType>::consumeUTF8String(Name& result, size_t stringLength)
    146146{
    147147    if (length() < stringLength || m_offset > length() - stringLength)
Note: See TracChangeset for help on using the changeset viewer.