Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: src/wasm/module-decoder.cc

Issue 2493823003: [wasm] Allocate a single script per wasm module (Closed)
Patch Set: rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/wasm/module-decoder.h ('k') | src/wasm/wasm-debug.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/wasm/module-decoder.h" 5 #include "src/wasm/module-decoder.h"
6 6
7 #include "src/base/functional.h" 7 #include "src/base/functional.h"
8 #include "src/base/platform/platform.h" 8 #include "src/base/platform/platform.h"
9 #include "src/flags.h" 9 #include "src/flags.h"
10 #include "src/macro-assembler.h" 10 #include "src/macro-assembler.h"
(...skipping 1145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 if (function_start > function_end) return FunctionError("start > end"); 1156 if (function_start > function_end) return FunctionError("start > end");
1157 if (size > kMaxFunctionSize) 1157 if (size > kMaxFunctionSize)
1158 return FunctionError("size > maximum function size"); 1158 return FunctionError("size > maximum function size");
1159 isolate->counters()->wasm_function_size_bytes()->AddSample( 1159 isolate->counters()->wasm_function_size_bytes()->AddSample(
1160 static_cast<int>(size)); 1160 static_cast<int>(size));
1161 WasmFunction* function = new WasmFunction(); 1161 WasmFunction* function = new WasmFunction();
1162 ModuleDecoder decoder(zone, function_start, function_end, kWasmOrigin); 1162 ModuleDecoder decoder(zone, function_start, function_end, kWasmOrigin);
1163 return decoder.DecodeSingleFunction(module_env, function); 1163 return decoder.DecodeSingleFunction(module_env, function);
1164 } 1164 }
1165 1165
1166 FunctionOffsetsResult DecodeWasmFunctionOffsets( 1166 FunctionOffsetsResult DecodeWasmFunctionOffsets(const byte* module_start,
1167 const byte* module_start, const byte* module_end, 1167 const byte* module_end) {
1168 uint32_t num_imported_functions) {
1169 // Find and decode the code section. 1168 // Find and decode the code section.
1170 Vector<const byte> code_section = 1169 Vector<const byte> code_section =
1171 FindSection(module_start, module_end, kCodeSectionCode); 1170 FindSection(module_start, module_end, kCodeSectionCode);
1172 Decoder decoder(code_section.start(), code_section.end()); 1171 Decoder decoder(code_section.start(), code_section.end());
1173 FunctionOffsets table; 1172 FunctionOffsets table;
1174 if (!code_section.start()) { 1173 if (!code_section.start()) {
1175 decoder.error("no code section"); 1174 decoder.error("no code section");
1176 return decoder.toResult(std::move(table)); 1175 return decoder.toResult(std::move(table));
1177 } 1176 }
1178 1177
1179 uint32_t functions_count = decoder.consume_u32v("functions count"); 1178 uint32_t functions_count = decoder.consume_u32v("functions count");
1180 // Reserve space for the entries, taking care of invalid input. 1179 // Reserve space for the entries, taking care of invalid input.
1181 if (functions_count < static_cast<unsigned>(code_section.length()) / 2) { 1180 if (functions_count < static_cast<unsigned>(code_section.length()) / 2) {
1182 table.reserve(num_imported_functions + functions_count); 1181 table.reserve(functions_count);
1183 } 1182 }
1184 1183
1185 // Add null entries for the imported functions.
1186 table.resize(num_imported_functions);
1187
1188 int section_offset = static_cast<int>(code_section.start() - module_start); 1184 int section_offset = static_cast<int>(code_section.start() - module_start);
1189 DCHECK_LE(0, section_offset); 1185 DCHECK_LE(0, section_offset);
1190 for (uint32_t i = 0; i < functions_count && decoder.ok(); ++i) { 1186 for (uint32_t i = 0; i < functions_count && decoder.ok(); ++i) {
1191 uint32_t size = decoder.consume_u32v("body size"); 1187 uint32_t size = decoder.consume_u32v("body size");
1192 int offset = static_cast<int>(section_offset + decoder.pc_offset()); 1188 int offset = static_cast<int>(section_offset + decoder.pc_offset());
1193 table.push_back(std::make_pair(offset, static_cast<int>(size))); 1189 table.push_back(std::make_pair(offset, static_cast<int>(size)));
1194 DCHECK(table.back().first >= 0 && table.back().second >= 0); 1190 DCHECK(table.back().first >= 0 && table.back().second >= 0);
1195 decoder.consume_bytes(size); 1191 decoder.consume_bytes(size);
1196 } 1192 }
1197 if (decoder.more()) decoder.error("unexpected additional bytes"); 1193 if (decoder.more()) decoder.error("unexpected additional bytes");
1198 1194
1199 return decoder.toResult(std::move(table)); 1195 return decoder.toResult(std::move(table));
1200 } 1196 }
1201 1197
1202 AsmJsOffsetsResult DecodeAsmJsOffsets(const byte* tables_start, 1198 AsmJsOffsetsResult DecodeAsmJsOffsets(const byte* tables_start,
1203 const byte* tables_end, 1199 const byte* tables_end) {
1204 uint32_t num_imported_functions) {
1205 AsmJsOffsets table; 1200 AsmJsOffsets table;
1206 1201
1207 Decoder decoder(tables_start, tables_end); 1202 Decoder decoder(tables_start, tables_end);
1208 uint32_t functions_count = decoder.consume_u32v("functions count"); 1203 uint32_t functions_count = decoder.consume_u32v("functions count");
1209 // Reserve space for the entries, taking care of invalid input. 1204 // Reserve space for the entries, taking care of invalid input.
1210 if (functions_count < static_cast<unsigned>(tables_end - tables_start)) { 1205 if (functions_count < static_cast<unsigned>(tables_end - tables_start)) {
1211 table.reserve(num_imported_functions + functions_count); 1206 table.reserve(functions_count);
1212 } 1207 }
1213 1208
1214 // Add null entries for the imported functions.
1215 table.resize(num_imported_functions);
1216
1217 for (uint32_t i = 0; i < functions_count && decoder.ok(); ++i) { 1209 for (uint32_t i = 0; i < functions_count && decoder.ok(); ++i) {
1218 uint32_t size = decoder.consume_u32v("table size"); 1210 uint32_t size = decoder.consume_u32v("table size");
1219 if (size == 0) { 1211 if (size == 0) {
1220 table.push_back(std::vector<std::pair<int, int>>()); 1212 table.push_back(std::vector<std::pair<int, int>>());
1221 continue; 1213 continue;
1222 } 1214 }
1223 if (!decoder.checkAvailable(size)) { 1215 if (!decoder.checkAvailable(size)) {
1224 decoder.error("illegal asm function offset table size"); 1216 decoder.error("illegal asm function offset table size");
1225 } 1217 }
1226 const byte* table_end = decoder.pc() + size; 1218 const byte* table_end = decoder.pc() + size;
(...skipping 13 matching lines...) Expand all
1240 table.push_back(std::move(func_asm_offsets)); 1232 table.push_back(std::move(func_asm_offsets));
1241 } 1233 }
1242 if (decoder.more()) decoder.error("unexpected additional bytes"); 1234 if (decoder.more()) decoder.error("unexpected additional bytes");
1243 1235
1244 return decoder.toResult(std::move(table)); 1236 return decoder.toResult(std::move(table));
1245 } 1237 }
1246 1238
1247 } // namespace wasm 1239 } // namespace wasm
1248 } // namespace internal 1240 } // namespace internal
1249 } // namespace v8 1241 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/module-decoder.h ('k') | src/wasm/wasm-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698