OLD | NEW |
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/objects.h" | 5 #include "src/objects.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <iomanip> | 8 #include <iomanip> |
9 #include <sstream> | 9 #include <sstream> |
10 | 10 |
(...skipping 13487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13498 } | 13498 } |
13499 } | 13499 } |
13500 Assembler::FlushICache(GetIsolate(), instruction_start(), instruction_size()); | 13500 Assembler::FlushICache(GetIsolate(), instruction_start(), instruction_size()); |
13501 } | 13501 } |
13502 | 13502 |
13503 // Locate the source position which is closest to the code offset. This is | 13503 // Locate the source position which is closest to the code offset. This is |
13504 // using the source position information embedded in the relocation info. | 13504 // using the source position information embedded in the relocation info. |
13505 // The position returned is relative to the beginning of the script where the | 13505 // The position returned is relative to the beginning of the script where the |
13506 // source for this function is found. | 13506 // source for this function is found. |
13507 int Code::SourcePosition(int code_offset) { | 13507 int Code::SourcePosition(int code_offset) { |
13508 Address pc = instruction_start() + code_offset; | 13508 // Subtract one because the current PC is one instruction after the call site. |
13509 int distance = kMaxInt; | 13509 Address pc = instruction_start() + code_offset - 1; |
13510 int position = RelocInfo::kNoPosition; // Initially no position found. | 13510 int position = RelocInfo::kNoPosition; // Initially no position found. |
13511 // Run through all the relocation info to find the best matching source | 13511 // Find the closest position attached to a pc lower or equal to the current. |
13512 // position. All the code needs to be considered as the sequence of the | 13512 // Note that the pc of reloc infos grow monotonically. |
13513 // instructions in the code does not necessarily follow the same order as the | 13513 for (RelocIterator it(this, RelocInfo::kPositionMask); |
13514 // source. | 13514 !it.done() && it.rinfo()->pc() <= pc; it.next()) { |
13515 RelocIterator it(this, RelocInfo::kPositionMask); | 13515 position = static_cast<int>(it.rinfo()->data()); |
13516 while (!it.done()) { | |
13517 // Only look at positions after the current pc. | |
13518 if (it.rinfo()->pc() < pc) { | |
13519 // Get position and distance. | |
13520 | |
13521 int dist = static_cast<int>(pc - it.rinfo()->pc()); | |
13522 int pos = static_cast<int>(it.rinfo()->data()); | |
13523 // If this position is closer than the current candidate or if it has the | |
13524 // same distance as the current candidate and the position is higher then | |
13525 // this position is the new candidate. | |
13526 if ((dist < distance) || | |
13527 (dist == distance && pos > position)) { | |
13528 position = pos; | |
13529 distance = dist; | |
13530 } | |
13531 } | |
13532 it.next(); | |
13533 } | 13516 } |
13534 DCHECK(kind() == FUNCTION || (is_optimized_code() && is_turbofanned()) || | 13517 DCHECK(kind() == FUNCTION || (is_optimized_code() && is_turbofanned()) || |
13535 is_wasm_code() || position == RelocInfo::kNoPosition); | 13518 is_wasm_code() || position == RelocInfo::kNoPosition); |
13536 return position; | 13519 return position; |
13537 } | 13520 } |
13538 | 13521 |
13539 | 13522 |
13540 // Same as Code::SourcePosition above except it only looks for statement | 13523 // Same as Code::SourcePosition above except it only looks for statement |
13541 // positions. | 13524 // positions. |
13542 int Code::SourceStatementPosition(int code_offset) { | 13525 int Code::SourceStatementPosition(int code_offset) { |
13543 // First find the position as close as possible using all position | 13526 // First find the closest position. |
13544 // information. | |
13545 int position = SourcePosition(code_offset); | 13527 int position = SourcePosition(code_offset); |
13546 // Now find the closest statement position before the position. | 13528 // Now find the closest statement position before the position. |
13547 int statement_position = 0; | 13529 int statement_position = 0; |
13548 RelocIterator it(this, RelocInfo::kPositionMask); | 13530 for (RelocIterator it(this, RelocInfo::kPositionMask); !it.done(); |
13549 while (!it.done()) { | 13531 it.next()) { |
13550 if (RelocInfo::IsStatementPosition(it.rinfo()->rmode())) { | 13532 if (RelocInfo::IsStatementPosition(it.rinfo()->rmode())) { |
13551 int p = static_cast<int>(it.rinfo()->data()); | 13533 int p = static_cast<int>(it.rinfo()->data()); |
13552 if (statement_position < p && p <= position) { | 13534 if (statement_position < p && p <= position) { |
13553 statement_position = p; | 13535 statement_position = p; |
13554 } | 13536 } |
13555 } | 13537 } |
13556 it.next(); | |
13557 } | 13538 } |
13558 return statement_position; | 13539 return statement_position; |
13559 } | 13540 } |
13560 | 13541 |
13561 | 13542 |
13562 SafepointEntry Code::GetSafepointEntry(Address pc) { | 13543 SafepointEntry Code::GetSafepointEntry(Address pc) { |
13563 SafepointTable table(this); | 13544 SafepointTable table(this); |
13564 return table.FindEntry(pc); | 13545 return table.FindEntry(pc); |
13565 } | 13546 } |
13566 | 13547 |
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14355 for (interpreter::SourcePositionTableIterator iterator( | 14336 for (interpreter::SourcePositionTableIterator iterator( |
14356 source_position_table()); | 14337 source_position_table()); |
14357 !iterator.done() && iterator.bytecode_offset() <= offset; | 14338 !iterator.done() && iterator.bytecode_offset() <= offset; |
14358 iterator.Advance()) { | 14339 iterator.Advance()) { |
14359 last_position = iterator.source_position(); | 14340 last_position = iterator.source_position(); |
14360 } | 14341 } |
14361 return last_position; | 14342 return last_position; |
14362 } | 14343 } |
14363 | 14344 |
14364 int BytecodeArray::SourceStatementPosition(int offset) { | 14345 int BytecodeArray::SourceStatementPosition(int offset) { |
14365 // First find the position as close as possible using all position | 14346 // First find the closest position. |
14366 // information. | |
14367 int position = SourcePosition(offset); | 14347 int position = SourcePosition(offset); |
14368 // Now find the closest statement position before the position. | 14348 // Now find the closest statement position before the position. |
14369 int statement_position = 0; | 14349 int statement_position = 0; |
14370 interpreter::SourcePositionTableIterator iterator(source_position_table()); | 14350 for (interpreter::SourcePositionTableIterator it(source_position_table()); |
14371 while (!iterator.done()) { | 14351 !it.done(); it.Advance()) { |
14372 if (iterator.is_statement()) { | 14352 if (it.is_statement()) { |
14373 int p = iterator.source_position(); | 14353 int p = it.source_position(); |
14374 if (statement_position < p && p <= position) { | 14354 if (statement_position < p && p <= position) { |
14375 statement_position = p; | 14355 statement_position = p; |
14376 } | 14356 } |
14377 } | 14357 } |
14378 iterator.Advance(); | |
14379 } | 14358 } |
14380 return statement_position; | 14359 return statement_position; |
14381 } | 14360 } |
14382 | 14361 |
14383 void BytecodeArray::Disassemble(std::ostream& os) { | 14362 void BytecodeArray::Disassemble(std::ostream& os) { |
14384 os << "Parameter count " << parameter_count() << "\n"; | 14363 os << "Parameter count " << parameter_count() << "\n"; |
14385 os << "Frame size " << frame_size() << "\n"; | 14364 os << "Frame size " << frame_size() << "\n"; |
14386 | 14365 |
14387 const uint8_t* base_address = GetFirstBytecodeAddress(); | 14366 const uint8_t* base_address = GetFirstBytecodeAddress(); |
14388 interpreter::SourcePositionTableIterator source_positions( | 14367 interpreter::SourcePositionTableIterator source_positions( |
(...skipping 4466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18855 } else { | 18834 } else { |
18856 // Old-style generators. | 18835 // Old-style generators. |
18857 int offset = continuation(); | 18836 int offset = continuation(); |
18858 CHECK(0 <= offset && offset < function()->code()->instruction_size()); | 18837 CHECK(0 <= offset && offset < function()->code()->instruction_size()); |
18859 return function()->code()->SourcePosition(offset); | 18838 return function()->code()->SourcePosition(offset); |
18860 } | 18839 } |
18861 } | 18840 } |
18862 | 18841 |
18863 } // namespace internal | 18842 } // namespace internal |
18864 } // namespace v8 | 18843 } // namespace v8 |
OLD | NEW |