Changeset 224272 in webkit
- Timestamp:
- Oct 31, 2017 11:15:59 PM (6 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r224263 r224272 1 2017-10-31 JF Bastien <jfbastien@apple.com> 2 3 WebAssembly: Wasm::IndexOrName has a raw pointer to Name 4 https://bugs.webkit.org/show_bug.cgi?id=176644 5 6 Reviewed by Michael Saboff. 7 8 IndexOrName now keeps a RefPtr to its original NameSection, which 9 holds the Name (or references nullptr if Index). Holding onto the 10 entire section seems like the better thing to do, since backtraces 11 probably contain multiple names from the same Module. 12 13 * JavaScriptCore.xcodeproj/project.pbxproj: 14 * interpreter/Interpreter.cpp: 15 (JSC::GetStackTraceFunctor::operator() const): 16 * interpreter/StackVisitor.h: Frame is no longer POD because of the 17 RefPtr. 18 * runtime/StackFrame.cpp: 19 (JSC::StackFrame::StackFrame): 20 * runtime/StackFrame.h: Drop the union, size is now 40 bytes. 21 (JSC::StackFrame::StackFrame): Deleted. Initialized in class instead. 22 (JSC::StackFrame::wasm): Deleted. Make it a ctor instead. 23 * wasm/WasmBBQPlanInlines.h: 24 (JSC::Wasm::BBQPlan::initializeCallees): 25 * wasm/WasmCallee.cpp: 26 (JSC::Wasm::Callee::Callee): 27 * wasm/WasmCallee.h: 28 (JSC::Wasm::Callee::create): 29 * wasm/WasmFormat.h: Move NameSection to its own header. 30 (JSC::Wasm::isValidNameType): 31 (JSC::Wasm::NameSection::get): Deleted. 32 * wasm/WasmIndexOrName.cpp: 33 (JSC::Wasm::IndexOrName::IndexOrName): 34 (JSC::Wasm::makeString): 35 * wasm/WasmIndexOrName.h: 36 (JSC::Wasm::IndexOrName::IndexOrName): 37 (JSC::Wasm::IndexOrName::isEmpty const): 38 (JSC::Wasm::IndexOrName::isIndex const): 39 * wasm/WasmModuleInformation.cpp: 40 (JSC::Wasm::ModuleInformation::ModuleInformation): 41 * wasm/WasmModuleInformation.h: 42 (JSC::Wasm::ModuleInformation::ModuleInformation): Deleted. 43 * wasm/WasmNameSection.h: 44 (JSC::Wasm::NameSection::get): 45 (JSC::Wasm::NameSection::create): Deleted. 46 * wasm/WasmNameSectionParser.cpp: 47 (JSC::Wasm::NameSectionParser::parse): 48 * wasm/WasmNameSectionParser.h: 49 * wasm/WasmOMGPlan.cpp: 50 (JSC::Wasm::OMGPlan::work): 51 1 52 2017-10-31 Tim Horton <timothy_horton@apple.com> 2 53 -
trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
r224136 r224272 1489 1489 AD5C36EF1F7A263A000BCAAF /* WasmMemoryMode.h in Headers */ = {isa = PBXBuildFile; fileRef = AD5C36EE1F7A2629000BCAAF /* WasmMemoryMode.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1490 1490 AD7438C01E0457A400FD0C2A /* WasmSignature.h in Headers */ = {isa = PBXBuildFile; fileRef = AD7438BF1E04579200FD0C2A /* WasmSignature.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1491 AD7B4B2E1FA3E29800C9DF79 /* WasmNameSection.h in Headers */ = {isa = PBXBuildFile; fileRef = AD7B4B2D1FA3E28600C9DF79 /* WasmNameSection.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1491 1492 AD86A93E1AA4D88D002FE77F /* WeakGCMapInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = AD86A93D1AA4D87C002FE77F /* WeakGCMapInlines.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1492 1493 AD8FF3981EB5BDB20087FF82 /* WasmIndexOrName.h in Headers */ = {isa = PBXBuildFile; fileRef = AD8FF3951EB5BD850087FF82 /* WasmIndexOrName.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 4239 4240 AD7438BE1E04579200FD0C2A /* WasmSignature.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WasmSignature.cpp; sourceTree = "<group>"; }; 4240 4241 AD7438BF1E04579200FD0C2A /* WasmSignature.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WasmSignature.h; sourceTree = "<group>"; }; 4242 AD7B4B2D1FA3E28600C9DF79 /* WasmNameSection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WasmNameSection.h; sourceTree = "<group>"; }; 4241 4243 AD86A93D1AA4D87C002FE77F /* WeakGCMapInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeakGCMapInlines.h; sourceTree = "<group>"; }; 4242 4244 AD8DD6CF1F67089F0004EB52 /* JSToWasm.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = JSToWasm.h; path = js/JSToWasm.h; sourceTree = "<group>"; }; … … 6154 6156 53F40E941D5A7AEF0099A1B6 /* WasmModuleParser.h */, 6155 6157 AD5B416E1EBAFB65008EFA43 /* WasmName.h */, 6158 AD7B4B2D1FA3E28600C9DF79 /* WasmNameSection.h */, 6156 6159 ADD8FA441EB3077100DF542F /* WasmNameSectionParser.cpp */, 6157 6160 ADD8FA431EB3077100DF542F /* WasmNameSectionParser.h */, … … 8263 8266 A77A423E17A0BBFD00A8DB81 /* DFGAbstractHeap.h in Headers */, 8264 8267 A704D90317A0BAA8006BA554 /* DFGAbstractInterpreter.h in Headers */, 8268 AD7B4B2E1FA3E29800C9DF79 /* WasmNameSection.h in Headers */, 8265 8269 A704D90417A0BAA8006BA554 /* DFGAbstractInterpreterInlines.h in Headers */, 8266 8270 0F620177143FCD3F0068B77C /* DFGAbstractValue.h in Headers */, -
trunk/Source/JavaScriptCore/interpreter/Interpreter.cpp
r223875 r224272 508 508 if (m_remainingCapacityForFrameCapture) { 509 509 if (visitor->isWasmFrame()) { 510 m_results.append(StackFrame ::wasm(visitor->wasmFunctionIndexOrName()));510 m_results.append(StackFrame(visitor->wasmFunctionIndexOrName())); 511 511 } else if (!!visitor->codeBlock() && !visitor->codeBlock()->unlinkedCodeBlock()->isBuiltinFunction()) { 512 512 m_results.append( -
trunk/Source/JavaScriptCore/interpreter/StackVisitor.h
r223738 r224272 122 122 size_t m_argumentCountIncludingThis; 123 123 unsigned m_bytecodeOffset; 124 Wasm::IndexOrName m_wasmFunctionIndexOrName;125 124 bool m_callerIsEntryFrame : 1; 126 125 bool m_isWasmFrame : 1; 126 Wasm::IndexOrName m_wasmFunctionIndexOrName; 127 127 128 128 friend class StackVisitor; -
trunk/Source/JavaScriptCore/runtime/StackFrame.cpp
r221836 r224272 36 36 StackFrame::StackFrame(VM& vm, JSCell* owner, JSCell* callee) 37 37 : m_callee(vm, owner, callee) 38 , m_bytecodeOffset(UINT_MAX)39 38 { 40 39 } … … 44 43 , m_codeBlock(vm, owner, codeBlock) 45 44 , m_bytecodeOffset(bytecodeOffset) 45 { 46 } 47 48 StackFrame::StackFrame(Wasm::IndexOrName indexOrName) 49 : m_wasmFunctionIndexOrName(indexOrName) 50 , m_isWasmFrame(true) 46 51 { 47 52 } -
trunk/Source/JavaScriptCore/runtime/StackFrame.h
r221836 r224272 38 38 class StackFrame { 39 39 public: 40 StackFrame()41 : m_bytecodeOffset(UINT_MAX)42 { }43 44 40 StackFrame(VM&, JSCell* owner, JSCell* callee); 45 46 41 StackFrame(VM&, JSCell* owner, JSCell* callee, CodeBlock*, unsigned bytecodeOffset); 47 48 static StackFrame wasm(Wasm::IndexOrName indexOrName) 49 { 50 StackFrame result; 51 result.m_isWasmFrame = true; 52 result.m_wasmFunctionIndexOrName = indexOrName; 53 return result; 54 } 42 StackFrame(Wasm::IndexOrName); 55 43 56 44 bool hasLineAndColumnInfo() const { return !!m_codeBlock; } … … 74 62 WriteBarrier<JSCell> m_callee { }; 75 63 WriteBarrier<CodeBlock> m_codeBlock { }; 76 union { 77 unsigned m_bytecodeOffset; 78 Wasm::IndexOrName m_wasmFunctionIndexOrName; 79 }; 64 Wasm::IndexOrName m_wasmFunctionIndexOrName; 65 unsigned m_bytecodeOffset { UINT_MAX }; 80 66 bool m_isWasmFrame { false }; 81 67 }; -
trunk/Source/JavaScriptCore/wasm/WasmBBQPlanInlines.h
r223738 r224272 31 31 #include "WasmBBQPlan.h" 32 32 #include "WasmCallee.h" 33 #include "WasmNameSection.h" 33 34 34 35 namespace JSC { namespace Wasm { … … 48 49 InternalFunction* function = m_wasmInternalFunctions[internalFunctionIndex].get(); 49 50 size_t functionIndexSpace = internalFunctionIndex + m_moduleInformation->importFunctionCount(); 50 Ref<Wasm::Callee> wasmEntrypointCallee = Wasm::Callee::create(WTFMove(function->entrypoint), functionIndexSpace, m_moduleInformation->nameSection .get(functionIndexSpace));51 Ref<Wasm::Callee> wasmEntrypointCallee = Wasm::Callee::create(WTFMove(function->entrypoint), functionIndexSpace, m_moduleInformation->nameSection->get(functionIndexSpace)); 51 52 MacroAssembler::repatchPointer(function->calleeMoveLocation, CalleeBits::boxWasm(wasmEntrypointCallee.ptr())); 52 53 -
trunk/Source/JavaScriptCore/wasm/WasmCallee.cpp
r216597 r224272 39 39 } 40 40 41 Callee::Callee(Entrypoint&& entrypoint, size_t index, const Name*name)41 Callee::Callee(Entrypoint&& entrypoint, size_t index, std::pair<const Name*, RefPtr<NameSection>>&& name) 42 42 : m_entrypoint(WTFMove(entrypoint)) 43 , m_indexOrName(index, name)43 , m_indexOrName(index, WTFMove(name)) 44 44 { 45 45 registerCode(m_entrypoint.compilation->codeRef().executableMemory()->start(), m_entrypoint.compilation->codeRef().executableMemory()->end()); -
trunk/Source/JavaScriptCore/wasm/WasmCallee.h
r216597 r224272 45 45 } 46 46 47 static Ref<Callee> create(Wasm::Entrypoint&& entrypoint, size_t index, const Name*name)47 static Ref<Callee> create(Wasm::Entrypoint&& entrypoint, size_t index, std::pair<const Name*, RefPtr<NameSection>>&& name) 48 48 { 49 Callee* callee = new Callee(WTFMove(entrypoint), index, name);49 Callee* callee = new Callee(WTFMove(entrypoint), index, WTFMove(name)); 50 50 return adoptRef(*callee); 51 51 } … … 58 58 private: 59 59 JS_EXPORT_PRIVATE Callee(Wasm::Entrypoint&&); 60 JS_EXPORT_PRIVATE Callee(Wasm::Entrypoint&&, size_t, const Name*);60 JS_EXPORT_PRIVATE Callee(Wasm::Entrypoint&&, size_t, std::pair<const Name*, RefPtr<NameSection>>&&); 61 61 62 62 Wasm::Entrypoint m_entrypoint; -
trunk/Source/JavaScriptCore/wasm/WasmFormat.h
r223907 r224272 35 35 #include "WasmMemoryInformation.h" 36 36 #include "WasmName.h" 37 #include "WasmNameSection.h" 37 38 #include "WasmOps.h" 38 39 #include "WasmPageCount.h" … … 254 255 return false; 255 256 } 256 257 struct NameSection {258 Name moduleName;259 Vector<Name> functionNames;260 const Name* get(size_t functionIndexSpace)261 {262 return functionIndexSpace < functionNames.size() ? &functionNames[functionIndexSpace] : nullptr;263 }264 };265 257 266 258 struct UnlinkedWasmToWasmCall { -
trunk/Source/JavaScriptCore/wasm/WasmIndexOrName.cpp
r216597 r224272 29 29 namespace JSC { namespace Wasm { 30 30 31 IndexOrName::IndexOrName(Index index, const Name*name)31 IndexOrName::IndexOrName(Index index, std::pair<const Name*, RefPtr<NameSection>>&& name) 32 32 { 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"); 33 static_assert(sizeof(m_indexName.index) == sizeof(m_indexName.name), "bit-tagging depends on sizes being equal"); 35 34 36 if ((index & allTags) || (bitwise_cast<Index>(name ) & allTags))35 if ((index & allTags) || (bitwise_cast<Index>(name.first) & allTags)) 37 36 *this = IndexOrName(); 38 else if (name) 39 m_name = name; 40 else 41 m_index = indexTag | index; 37 else { 38 if (name.first) 39 m_indexName.name = name.first; 40 else 41 m_indexName.index = indexTag | index; 42 m_nameSection = WTFMove(name.second); 43 } 42 44 } 43 45 … … 47 49 return String(); 48 50 if (ion.isIndex()) 49 return String::number(ion.m_index & ~IndexOrName::indexTag);50 return String(ion.m_ name->data(), ion.m_name->size());51 return String::number(ion.m_indexName.index & ~IndexOrName::indexTag); 52 return String(ion.m_indexName.name->data(), ion.m_indexName.name->size()); 51 53 }; 52 54 -
trunk/Source/JavaScriptCore/wasm/WasmIndexOrName.h
r216597 r224272 27 27 28 28 #include "WasmName.h" 29 #include "WasmNameSection.h" 30 #include <wtf/RefPtr.h> 29 31 #include <wtf/StdLibExtras.h> 30 32 #include <wtf/text/WTFString.h> … … 32 34 namespace JSC { namespace Wasm { 33 35 36 struct NameSection; 37 34 38 struct IndexOrName { 35 39 typedef size_t Index; 36 40 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; } 41 IndexOrName() { m_indexName.index = emptyTag; } 42 IndexOrName(Index, std::pair<const Name*, RefPtr<NameSection>>&&); 43 bool isEmpty() const { return bitwise_cast<Index>(m_indexName) & emptyTag; } 44 bool isIndex() const { return bitwise_cast<Index>(m_indexName) & indexTag; } 43 45 bool isName() const { return !(isEmpty() || isName()); } 44 46 … … 47 49 private: 48 50 union { 49 Index m_index; 50 const Name* m_name; 51 }; 51 Index index; 52 const Name* name; 53 } m_indexName; 54 RefPtr<NameSection> m_nameSection; 52 55 53 56 // Use the top bits as tags. Neither pointers nor the function index space should use them. -
trunk/Source/JavaScriptCore/wasm/WasmModuleInformation.cpp
r214919 r224272 29 29 #if ENABLE(WEBASSEMBLY) 30 30 31 #include "WasmNameSection.h" 32 31 33 namespace JSC { namespace Wasm { 32 34 35 ModuleInformation::ModuleInformation(Vector<uint8_t>&& sourceBytes) 36 : source(WTFMove(sourceBytes)) 37 , nameSection(new NameSection()) 38 { 39 } 33 40 ModuleInformation::~ModuleInformation() { } 34 41 -
trunk/Source/JavaScriptCore/wasm/WasmModuleInformation.h
r216597 r224272 33 33 34 34 struct ModuleInformation : public ThreadSafeRefCounted<ModuleInformation> { 35 ModuleInformation() = delete; 36 ModuleInformation(const ModuleInformation&) = delete; 37 ModuleInformation(ModuleInformation&&) = delete; 38 39 ModuleInformation(Vector<uint8_t>&& sourceBytes); 40 41 JS_EXPORT_PRIVATE ~ModuleInformation(); 42 35 43 size_t functionIndexSpaceSize() const { return importFunctionSignatureIndices.size() + internalFunctionSignatureIndices.size(); } 36 44 bool isImportedFunctionFromFunctionIndexSpace(size_t functionIndex) const … … 48 56 uint32_t importFunctionCount() const { return importFunctionSignatureIndices.size(); } 49 57 uint32_t internalFunctionCount() const { return internalFunctionSignatureIndices.size(); } 50 51 ModuleInformation(Vector<uint8_t>&& sourceBytes)52 : source(WTFMove(sourceBytes))53 {54 }55 56 JS_EXPORT_PRIVATE ~ModuleInformation();57 58 58 59 const Vector<uint8_t> source; … … 75 76 unsigned firstInternalGlobal { 0 }; 76 77 Vector<CustomSection> customSections; 77 NameSectionnameSection;78 RefPtr<NameSection> nameSection; 78 79 }; 79 80 -
trunk/Source/JavaScriptCore/wasm/WasmNameSection.h
r223738 r224272 29 29 #include <wtf/ThreadSafeRefCounted.h> 30 30 #include <wtf/Vector.h> 31 #include <utility> 31 32 32 33 namespace JSC { namespace Wasm { 33 34 34 struct NameSection : ThreadSafeRefCounted<NameSection> {35 st atic Ref<NameSection> create()35 struct NameSection : public ThreadSafeRefCounted<NameSection> { 36 std::pair<const Name*, RefPtr<NameSection>> get(size_t functionIndexSpace) 36 37 { 37 return adoptRef(*new NameSection());38 return functionIndexSpace < functionNames.size() ? std::make_pair(&functionNames[functionIndexSpace], RefPtr<NameSection>(this)) : std::pair<const Name*, RefPtr<NameSection>>(nullptr, nullptr); 38 39 } 39 40 40 Name moduleName; 41 41 Vector<Name> functionNames; 42 const Name* get(size_t functionIndexSpace)43 {44 return functionIndexSpace < functionNames.size() ? &functionNames[functionIndexSpace] : nullptr;45 }46 42 }; 47 43 -
trunk/Source/JavaScriptCore/wasm/WasmNameSectionParser.cpp
r219134 r224272 30 30 31 31 #include "IdentifierInlines.h" 32 #include "WasmNameSection.h" 32 33 33 34 namespace JSC { namespace Wasm { … … 35 36 auto NameSectionParser::parse() -> Result 36 37 { 37 NameSection nameSection;38 WASM_PARSER_FAIL_IF(!nameSection .functionNames.tryReserveCapacity(m_info.functionIndexSpaceSize()), "can't allocate enough memory for function names");39 nameSection .functionNames.resize(m_info.functionIndexSpaceSize());38 RefPtr<NameSection> nameSection(adoptRef(*new NameSection())); 39 WASM_PARSER_FAIL_IF(!nameSection->functionNames.tryReserveCapacity(m_info.functionIndexSpaceSize()), "can't allocate enough memory for function names"); 40 nameSection->functionNames.resize(m_info.functionIndexSpaceSize()); 40 41 41 42 for (size_t payloadNumber = 0; m_offset < length(); ++payloadNumber) { … … 59 60 WASM_PARSER_FAIL_IF(!parseVarUInt32(nameLen), "can't get module's name length for payload ", payloadNumber); 60 61 WASM_PARSER_FAIL_IF(!consumeUTF8String(nameString, nameLen), "can't get module's name of length ", nameLen, " for payload ", payloadNumber); 61 nameSection .moduleName = WTFMove(nameString);62 nameSection->moduleName = WTFMove(nameString); 62 63 break; 63 64 } … … 73 74 WASM_PARSER_FAIL_IF(!parseVarUInt32(nameLen), "can't get functions ", function, "'s name length for payload ", payloadNumber); 74 75 WASM_PARSER_FAIL_IF(!consumeUTF8String(nameString, nameLen), "can't get function ", function, "'s name of length ", nameLen, " for payload ", payloadNumber); 75 nameSection .functionNames[index] = WTFMove(nameString);76 nameSection->functionNames[index] = WTFMove(nameString); 76 77 } 77 78 break; -
trunk/Source/JavaScriptCore/wasm/WasmNameSectionParser.h
r216597 r224272 30 30 #include "WasmFormat.h" 31 31 #include "WasmParser.h" 32 #include <wtf/RefPtr.h> 32 33 33 34 namespace JSC { namespace Wasm { 34 35 35 class NameSectionParser : public Parser< NameSection> {36 class NameSectionParser : public Parser<RefPtr<NameSection>> { 36 37 public: 37 38 NameSectionParser(const uint8_t* sourceBuffer, size_t sourceLength, const ModuleInformation& info) -
trunk/Source/JavaScriptCore/wasm/WasmOMGPlan.cpp
r224020 r224272 39 39 #include "WasmMachineThreads.h" 40 40 #include "WasmMemory.h" 41 #include "WasmNameSection.h" 41 42 #include "WasmValidate.h" 42 43 #include "WasmWorklist.h" … … 106 107 { 107 108 ASSERT(m_codeBlock.ptr() == m_module->codeBlockFor(mode())); 108 Ref<Callee> callee = Callee::create(WTFMove(omgEntrypoint), functionIndexSpace, m_moduleInformation->nameSection .get(functionIndexSpace));109 Ref<Callee> callee = Callee::create(WTFMove(omgEntrypoint), functionIndexSpace, m_moduleInformation->nameSection->get(functionIndexSpace)); 109 110 MacroAssembler::repatchPointer(parseAndCompileResult.value()->calleeMoveLocation, CalleeBits::boxWasm(callee.ptr())); 110 111 ASSERT(!m_codeBlock->m_optimizedCallees[m_functionIndex]);
Note: See TracChangeset
for help on using the changeset viewer.