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

Side by Side Diff: src/wasm/wasm-objects.cc

Issue 2555243002: [wasm] Fix location for error in asm.js ToNumber conversion (Closed)
Patch Set: No need to store parent in VisitCall Created 4 years 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
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/wasm-objects.h" 5 #include "src/wasm/wasm-objects.h"
6 #include "src/utils.h" 6 #include "src/utils.h"
7 7
8 #include "src/wasm/module-decoder.h" 8 #include "src/wasm/module-decoder.h"
9 #include "src/wasm/wasm-module.h" 9 #include "src/wasm/wasm-module.h"
10 #include "src/wasm/wasm-text.h" 10 #include "src/wasm/wasm-text.h"
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 asm_offsets = wasm::DecodeAsmJsOffsets(bytes_start, bytes_end); 481 asm_offsets = wasm::DecodeAsmJsOffsets(bytes_start, bytes_end);
482 } 482 }
483 // Wasm bytes must be valid and must contain asm.js offset table. 483 // Wasm bytes must be valid and must contain asm.js offset table.
484 DCHECK(asm_offsets.ok()); 484 DCHECK(asm_offsets.ok());
485 DCHECK_GE(kMaxInt, asm_offsets.val.size()); 485 DCHECK_GE(kMaxInt, asm_offsets.val.size());
486 int num_functions = static_cast<int>(asm_offsets.val.size()); 486 int num_functions = static_cast<int>(asm_offsets.val.size());
487 int num_imported_functions = 487 int num_imported_functions =
488 static_cast<int>(compiled_module->module()->num_imported_functions); 488 static_cast<int>(compiled_module->module()->num_imported_functions);
489 DCHECK_EQ(compiled_module->module()->functions.size(), 489 DCHECK_EQ(compiled_module->module()->functions.size(),
490 static_cast<size_t>(num_functions) + num_imported_functions); 490 static_cast<size_t>(num_functions) + num_imported_functions);
491 int num_entries = 0;
492 for (int func = 0; func < num_functions; ++func) {
493 size_t new_size = asm_offsets.val[func].size();
494 DCHECK_LE(new_size, static_cast<size_t>(kMaxInt) - num_entries);
495 num_entries += static_cast<int>(new_size);
496 }
491 // One byte to encode that this is a decoded table. 497 // One byte to encode that this is a decoded table.
492 int total_size = 1; 498 DCHECK_GE(kMaxInt, 1 + static_cast<uint64_t>(num_entries) * 3 * kIntSize);
493 for (int func = 0; func < num_functions; ++func) { 499 int total_size = 1 + num_entries * 3 * kIntSize;
494 size_t new_size = asm_offsets.val[func].size() * 2 * kIntSize;
495 DCHECK_LE(new_size, static_cast<size_t>(kMaxInt) - total_size);
496 total_size += static_cast<int>(new_size);
497 }
498 Handle<ByteArray> decoded_table = 500 Handle<ByteArray> decoded_table =
499 isolate->factory()->NewByteArray(total_size, TENURED); 501 isolate->factory()->NewByteArray(total_size, TENURED);
500 decoded_table->set(total_size - 1, AsmJsTableType::Decoded); 502 decoded_table->set(total_size - 1, AsmJsTableType::Decoded);
501 compiled_module->set_asm_js_offset_table(decoded_table); 503 compiled_module->set_asm_js_offset_table(decoded_table);
502 504
503 int idx = 0; 505 int idx = 0;
504 std::vector<WasmFunction>& wasm_funs = compiled_module->module()->functions; 506 std::vector<WasmFunction>& wasm_funs = compiled_module->module()->functions;
505 for (int func = 0; func < num_functions; ++func) { 507 for (int func = 0; func < num_functions; ++func) {
506 std::vector<std::pair<int, int>>& func_asm_offsets = asm_offsets.val[func]; 508 std::vector<AsmJsOffsetEntry>& func_asm_offsets = asm_offsets.val[func];
507 if (func_asm_offsets.empty()) continue; 509 if (func_asm_offsets.empty()) continue;
508 int func_offset = 510 int func_offset =
509 wasm_funs[num_imported_functions + func].code_start_offset; 511 wasm_funs[num_imported_functions + func].code_start_offset;
510 for (std::pair<int, int> p : func_asm_offsets) { 512 for (AsmJsOffsetEntry& e : func_asm_offsets) {
511 // Byte offsets must be strictly monotonously increasing: 513 // Byte offsets must be strictly monotonously increasing:
512 DCHECK(idx == 0 || 514 DCHECK(idx == 0 ||
513 func_offset + p.first > decoded_table->get_int(idx - 2)); 515 func_offset + e.byte_offset > decoded_table->get_int(idx - 3));
514 decoded_table->set_int(idx++, func_offset + p.first); 516 decoded_table->set_int(idx++, func_offset + e.byte_offset);
515 decoded_table->set_int(idx++, p.second); 517 decoded_table->set_int(idx++, e.source_position_call);
518 decoded_table->set_int(idx++, e.source_position_number_conversion);
516 } 519 }
517 } 520 }
518 DCHECK_EQ(total_size, idx * kIntSize + 1); 521 DCHECK_EQ(total_size, idx * kIntSize + 1);
519 return decoded_table; 522 return decoded_table;
520 } 523 }
521 } // namespace 524 } // namespace
522 525
523 int WasmCompiledModule::GetAsmJsSourcePosition( 526 int WasmCompiledModule::GetAsmJsSourcePosition(
524 Handle<WasmCompiledModule> compiled_module, uint32_t func_index, 527 Handle<WasmCompiledModule> compiled_module, uint32_t func_index,
525 uint32_t byte_offset) { 528 uint32_t byte_offset, bool is_at_number_conversion) {
526 Isolate* isolate = compiled_module->GetIsolate(); 529 Isolate* isolate = compiled_module->GetIsolate();
527 Handle<ByteArray> offset_table = 530 Handle<ByteArray> offset_table =
528 GetDecodedAsmJsOffsetTable(compiled_module, isolate); 531 GetDecodedAsmJsOffsetTable(compiled_module, isolate);
529 532
530 DCHECK_LT(func_index, compiled_module->module()->functions.size()); 533 DCHECK_LT(func_index, compiled_module->module()->functions.size());
531 uint32_t func_code_offset = 534 uint32_t func_code_offset =
532 compiled_module->module()->functions[func_index].code_start_offset; 535 compiled_module->module()->functions[func_index].code_start_offset;
533 uint32_t total_offset = func_code_offset + byte_offset; 536 uint32_t total_offset = func_code_offset + byte_offset;
534 537
535 // Binary search for the total byte offset. 538 // Binary search for the total byte offset.
536 int left = 0; // inclusive 539 int left = 0; // inclusive
537 int right = offset_table->length() / kIntSize / 2; // exclusive 540 int right = offset_table->length() / kIntSize / 3; // exclusive
bradnelson 2016/12/07 19:19:06 At the point you've got 3 fields, maybe have an en
Clemens Hammacher 2016/12/08 10:50:23 Cool idea, done!
538 DCHECK_LT(left, right); 541 DCHECK_LT(left, right);
539 while (right - left > 1) { 542 while (right - left > 1) {
540 int mid = left + (right - left) / 2; 543 int mid = left + (right - left) / 2;
541 int mid_entry = offset_table->get_int(2 * mid); 544 int mid_entry = offset_table->get_int(3 * mid);
542 DCHECK_GE(kMaxInt, mid_entry); 545 DCHECK_GE(kMaxInt, mid_entry);
543 if (static_cast<uint32_t>(mid_entry) <= total_offset) { 546 if (static_cast<uint32_t>(mid_entry) <= total_offset) {
544 left = mid; 547 left = mid;
545 } else { 548 } else {
546 right = mid; 549 right = mid;
547 } 550 }
548 } 551 }
549 // There should be an entry for each position that could show up on the stack 552 // There should be an entry for each position that could show up on the stack
550 // trace: 553 // trace:
551 DCHECK_EQ(total_offset, 554 DCHECK_EQ(total_offset,
552 static_cast<uint32_t>(offset_table->get_int(2 * left))); 555 static_cast<uint32_t>(offset_table->get_int(3 * left)));
553 return offset_table->get_int(2 * left + 1); 556 return offset_table->get_int(3 * left + (is_at_number_conversion ? 2 : 1));
554 } 557 }
555 558
556 v8::debug::WasmDisassembly WasmCompiledModule::DisassembleFunction( 559 v8::debug::WasmDisassembly WasmCompiledModule::DisassembleFunction(
557 int func_index) { 560 int func_index) {
558 DisallowHeapAllocation no_gc; 561 DisallowHeapAllocation no_gc;
559 562
560 if (func_index < 0 || 563 if (func_index < 0 ||
561 static_cast<uint32_t>(func_index) >= module()->functions.size()) 564 static_cast<uint32_t>(func_index) >= module()->functions.size())
562 return {}; 565 return {};
563 566
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 !array->get(kPreviousInstanceWrapper)->IsFixedArray()) 600 !array->get(kPreviousInstanceWrapper)->IsFixedArray())
598 return false; 601 return false;
599 return true; 602 return true;
600 } 603 }
601 604
602 void WasmInstanceWrapper::set_instance_object(Handle<JSObject> instance, 605 void WasmInstanceWrapper::set_instance_object(Handle<JSObject> instance,
603 Isolate* isolate) { 606 Isolate* isolate) {
604 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(instance); 607 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(instance);
605 set(kWrapperInstanceObject, *cell); 608 set(kWrapperInstanceObject, *cell);
606 } 609 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698