Changeset 209560 in webkit for trunk/Source/JavaScriptCore/wasm/WasmPlan.cpp
- Timestamp:
- Dec 8, 2016, 1:09:06 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/wasm/WasmPlan.cpp
r209312 r209560 34 34 #include "JSWebAssemblyCallee.h" 35 35 #include "WasmB3IRGenerator.h" 36 #include "WasmBinding.h" 36 37 #include "WasmCallingConvention.h" 37 38 #include "WasmMemory.h" … … 39 40 #include "WasmValidate.h" 40 41 #include <wtf/DataLog.h> 42 #include <wtf/StdLibExtras.h> 41 43 #include <wtf/text/StringBuilder.h> 42 44 … … 70 72 } 71 73 m_moduleInformation = WTFMove(moduleParser.moduleInformation()); 74 m_functionLocationInBinary = WTFMove(moduleParser.functionLocationInBinary()); 75 m_functionIndexSpace = WTFMove(moduleParser.functionIndexSpace()); 72 76 } 73 77 if (verbose) 74 78 dataLogLn("Parsed module."); 75 79 76 if (!m_compiledFunctions.tryReserveCapacity(m_moduleInformation->functions.size())) { 77 StringBuilder builder; 78 builder.appendLiteral("Failed allocating enough space for "); 79 builder.appendNumber(m_moduleInformation->functions.size()); 80 builder.appendLiteral(" compiled functions"); 81 m_errorMessage = builder.toString(); 80 auto tryReserveCapacity = [this] (auto& vector, size_t size, const char* what) { 81 if (UNLIKELY(!vector.tryReserveCapacity(size))) { 82 StringBuilder builder; 83 builder.appendLiteral("Failed allocating enough space for "); 84 builder.appendNumber(size); 85 builder.append(what); 86 m_errorMessage = builder.toString(); 87 return false; 88 } 89 return true; 90 }; 91 Vector<Vector<UnlinkedWasmToWasmCall>> unlinkedWasmToWasmCalls; 92 if (!tryReserveCapacity(m_wasmToJSStubs, m_moduleInformation->importFunctions.size(), " WebAssembly to JavaScript stubs") 93 || !tryReserveCapacity(unlinkedWasmToWasmCalls, m_functionLocationInBinary.size(), " unlinked WebAssembly to WebAssembly calls") 94 || !tryReserveCapacity(m_wasmInternalFunctions, m_functionLocationInBinary.size(), " WebAssembly functions")) 82 95 return; 96 97 for (unsigned importIndex = 0; importIndex < m_moduleInformation->imports.size(); ++importIndex) { 98 Import* import = &m_moduleInformation->imports[importIndex]; 99 if (import->kind != External::Function) 100 continue; 101 unsigned importFunctionIndex = m_wasmToJSStubs.size(); 102 if (verbose) 103 dataLogLn("Processing import function number ", importFunctionIndex, ": ", import->module, ": ", import->field); 104 Signature* signature = m_moduleInformation->importFunctions.at(import->kindIndex); 105 m_wasmToJSStubs.uncheckedAppend(importStubGenerator(m_vm, m_callLinkInfos, signature, importFunctionIndex)); 106 m_functionIndexSpace[importFunctionIndex].code = m_wasmToJSStubs[importFunctionIndex].code().executableAddress(); 83 107 } 84 108 85 for ( const FunctionInformation& info : m_moduleInformation->functions) {109 for (unsigned functionIndex = 0; functionIndex < m_functionLocationInBinary.size(); ++functionIndex) { 86 110 if (verbose) 87 dataLogLn("Processing function starting at: ", info.start, " and ending at: ", info.end);88 const uint8_t* functionStart = m_source + info.start;89 size_t functionLength = info.end - info.start;111 dataLogLn("Processing function starting at: ", m_functionLocationInBinary[functionIndex].start, " and ending at: ", m_functionLocationInBinary[functionIndex].end); 112 const uint8_t* functionStart = m_source + m_functionLocationInBinary[functionIndex].start; 113 size_t functionLength = m_functionLocationInBinary[functionIndex].end - m_functionLocationInBinary[functionIndex].start; 90 114 ASSERT(functionLength <= m_sourceLength); 115 Signature* signature = m_moduleInformation->internalFunctionSignatures[functionIndex]; 116 unsigned functionIndexSpace = m_wasmToJSStubs.size() + functionIndex; 117 ASSERT(m_functionIndexSpace[functionIndexSpace].signature == signature); 91 118 92 String error = validateFunction(functionStart, functionLength, info.signature, m_moduleInformation->functions);119 String error = validateFunction(functionStart, functionLength, signature, m_functionIndexSpace); 93 120 if (!error.isNull()) { 94 121 if (verbose) { … … 101 128 } 102 129 103 m_compiledFunctions.uncheckedAppend(parseAndCompile(*m_vm, functionStart, functionLength, m_moduleInformation->memory.get(), info.signature, m_moduleInformation->functions)); 130 unlinkedWasmToWasmCalls.uncheckedAppend(Vector<UnlinkedWasmToWasmCall>()); 131 m_wasmInternalFunctions.uncheckedAppend(parseAndCompile(*m_vm, functionStart, functionLength, m_moduleInformation->memory.get(), signature, unlinkedWasmToWasmCalls.at(functionIndex), m_functionIndexSpace)); 132 m_functionIndexSpace[functionIndexSpace].code = m_wasmInternalFunctions[functionIndex]->code->code().executableAddress(); 104 133 } 105 134 106 // Patch the call sites for each function. 107 for (std::unique_ptr<FunctionCompilation>& functionPtr : m_compiledFunctions) { 108 FunctionCompilation* function = functionPtr.get(); 109 for (auto& call : function->unlinkedCalls) 110 MacroAssembler::repatchCall(call.callLocation, CodeLocationLabel(m_compiledFunctions[call.functionIndex]->code->code())); 135 // Patch the call sites for each WebAssembly function. 136 for (auto& unlinked : unlinkedWasmToWasmCalls) { 137 for (auto& call : unlinked) 138 MacroAssembler::repatchCall(call.callLocation, CodeLocationLabel(m_functionIndexSpace[call.functionIndex].code)); 111 139 } 112 140 … … 117 145 { 118 146 ASSERT(!failed()); 119 for (unsigned i = 0; i < m_compiledFunctions.size(); i++) {120 std::unique_ptr<FunctionCompilation>& compilation = m_compiledFunctions[i];121 CodeLocationDataLabelPtr calleeMoveLocation = compilation->calleeMoveLocation;122 JSWebAssemblyCallee* callee = JSWebAssemblyCallee::create(globalObject->vm(), WTFMove( compilation));147 for (unsigned internalFunctionIndex = 0; internalFunctionIndex < m_wasmInternalFunctions.size(); ++internalFunctionIndex) { 148 WasmInternalFunction* function = m_wasmInternalFunctions[internalFunctionIndex].get(); 149 CodeLocationDataLabelPtr calleeMoveLocation = function->calleeMoveLocation; 150 JSWebAssemblyCallee* callee = JSWebAssemblyCallee::create(globalObject->vm(), WTFMove(function->code), WTFMove(function->jsToWasmEntryPoint)); 123 151 124 152 MacroAssembler::repatchPointer(calleeMoveLocation, callee); … … 127 155 dataLogLn("Made Wasm callee: ", RawPointer(callee)); 128 156 129 callback(i , callee);157 callback(internalFunctionIndex, callee); 130 158 } 131 159 }
Note:
See TracChangeset
for help on using the changeset viewer.