| 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 20 matching lines...) Expand all Loading... |
| 31 #include "src/execution.h" | 31 #include "src/execution.h" |
| 32 #include "src/field-index-inl.h" | 32 #include "src/field-index-inl.h" |
| 33 #include "src/field-index.h" | 33 #include "src/field-index.h" |
| 34 #include "src/field-type.h" | 34 #include "src/field-type.h" |
| 35 #include "src/frames-inl.h" | 35 #include "src/frames-inl.h" |
| 36 #include "src/full-codegen/full-codegen.h" | 36 #include "src/full-codegen/full-codegen.h" |
| 37 #include "src/ic/ic.h" | 37 #include "src/ic/ic.h" |
| 38 #include "src/identity-map.h" | 38 #include "src/identity-map.h" |
| 39 #include "src/interpreter/bytecode-array-iterator.h" | 39 #include "src/interpreter/bytecode-array-iterator.h" |
| 40 #include "src/interpreter/interpreter.h" | 40 #include "src/interpreter/interpreter.h" |
| 41 #include "src/interpreter/source-position-table.h" | |
| 42 #include "src/isolate-inl.h" | 41 #include "src/isolate-inl.h" |
| 43 #include "src/keys.h" | 42 #include "src/keys.h" |
| 44 #include "src/list.h" | 43 #include "src/list.h" |
| 45 #include "src/log.h" | 44 #include "src/log.h" |
| 46 #include "src/lookup.h" | 45 #include "src/lookup.h" |
| 47 #include "src/macro-assembler.h" | 46 #include "src/macro-assembler.h" |
| 48 #include "src/messages.h" | 47 #include "src/messages.h" |
| 49 #include "src/objects-body-descriptors-inl.h" | 48 #include "src/objects-body-descriptors-inl.h" |
| 50 #include "src/property-descriptor.h" | 49 #include "src/property-descriptor.h" |
| 51 #include "src/prototype.h" | 50 #include "src/prototype.h" |
| 52 #include "src/regexp/jsregexp.h" | 51 #include "src/regexp/jsregexp.h" |
| 53 #include "src/safepoint-table.h" | 52 #include "src/safepoint-table.h" |
| 53 #include "src/source-position-table.h" |
| 54 #include "src/string-builder.h" | 54 #include "src/string-builder.h" |
| 55 #include "src/string-search.h" | 55 #include "src/string-search.h" |
| 56 #include "src/string-stream.h" | 56 #include "src/string-stream.h" |
| 57 #include "src/utils.h" | 57 #include "src/utils.h" |
| 58 #include "src/zone.h" | 58 #include "src/zone.h" |
| 59 | 59 |
| 60 #ifdef ENABLE_DISASSEMBLER | 60 #ifdef ENABLE_DISASSEMBLER |
| 61 #include "src/disasm.h" | 61 #include "src/disasm.h" |
| 62 #include "src/disassembler.h" | 62 #include "src/disassembler.h" |
| 63 #endif | 63 #endif |
| (...skipping 13412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13476 } | 13476 } |
| 13477 } | 13477 } |
| 13478 Assembler::FlushICache(GetIsolate(), instruction_start(), instruction_size()); | 13478 Assembler::FlushICache(GetIsolate(), instruction_start(), instruction_size()); |
| 13479 } | 13479 } |
| 13480 | 13480 |
| 13481 // Locate the source position which is closest to the code offset. This is | 13481 // Locate the source position which is closest to the code offset. This is |
| 13482 // using the source position information embedded in the relocation info. | 13482 // using the source position information embedded in the relocation info. |
| 13483 // The position returned is relative to the beginning of the script where the | 13483 // The position returned is relative to the beginning of the script where the |
| 13484 // source for this function is found. | 13484 // source for this function is found. |
| 13485 int Code::SourcePosition(int code_offset) { | 13485 int Code::SourcePosition(int code_offset) { |
| 13486 int position = RelocInfo::kNoPosition; // Initially no position found. |
| 13486 // Subtract one because the current PC is one instruction after the call site. | 13487 // Subtract one because the current PC is one instruction after the call site. |
| 13487 Address pc = instruction_start() + code_offset - 1; | 13488 code_offset--; |
| 13488 int position = RelocInfo::kNoPosition; // Initially no position found. | |
| 13489 // Find the closest position attached to a pc lower or equal to the current. | 13489 // Find the closest position attached to a pc lower or equal to the current. |
| 13490 // Note that the pc of reloc infos grow monotonically. | 13490 // Note that the pc of reloc infos grow monotonically. |
| 13491 for (RelocIterator it(this, RelocInfo::kPositionMask); | 13491 if (kind() == FUNCTION) { |
| 13492 !it.done() && it.rinfo()->pc() <= pc; it.next()) { | 13492 for (SourcePositionTableIterator it(source_position_table()); |
| 13493 position = static_cast<int>(it.rinfo()->data()); | 13493 !it.done() && it.code_offset() <= code_offset; it.Advance()) { |
| 13494 position = it.source_position(); |
| 13495 } |
| 13496 } else { |
| 13497 Address pc = instruction_start() + code_offset; |
| 13498 for (RelocIterator it(this, RelocInfo::kPositionMask); |
| 13499 !it.done() && it.rinfo()->pc() <= pc; it.next()) { |
| 13500 position = static_cast<int>(it.rinfo()->data()); |
| 13501 } |
| 13494 } | 13502 } |
| 13495 DCHECK(kind() == FUNCTION || (is_optimized_code() && is_turbofanned()) || | 13503 DCHECK(kind() == FUNCTION || (is_optimized_code() && is_turbofanned()) || |
| 13496 is_wasm_code() || position == RelocInfo::kNoPosition); | 13504 is_wasm_code() || position == RelocInfo::kNoPosition); |
| 13497 return position; | 13505 return position; |
| 13498 } | 13506 } |
| 13499 | 13507 |
| 13500 | 13508 |
| 13501 // Same as Code::SourcePosition above except it only looks for statement | 13509 // Same as Code::SourcePosition above except it only looks for statement |
| 13502 // positions. | 13510 // positions. |
| 13503 int Code::SourceStatementPosition(int code_offset) { | 13511 int Code::SourceStatementPosition(int code_offset) { |
| 13504 // First find the closest position. | 13512 // First find the closest position. |
| 13505 int position = SourcePosition(code_offset); | 13513 int position = SourcePosition(code_offset); |
| 13506 // Now find the closest statement position before the position. | 13514 // Now find the closest statement position before the position. |
| 13507 int statement_position = 0; | 13515 int statement_position = 0; |
| 13508 for (RelocIterator it(this, RelocInfo::kPositionMask); !it.done(); | 13516 if (kind() == FUNCTION) { |
| 13509 it.next()) { | 13517 for (SourcePositionTableIterator it(source_position_table()); !it.done(); |
| 13510 if (RelocInfo::IsStatementPosition(it.rinfo()->rmode())) { | 13518 it.Advance()) { |
| 13511 int p = static_cast<int>(it.rinfo()->data()); | 13519 if (it.is_statement()) { |
| 13512 if (statement_position < p && p <= position) { | 13520 int p = it.source_position(); |
| 13513 statement_position = p; | 13521 if (statement_position < p && p <= position) { |
| 13522 statement_position = p; |
| 13523 } |
| 13524 } |
| 13525 } |
| 13526 } else { |
| 13527 for (RelocIterator it(this, RelocInfo::kPositionMask); !it.done(); |
| 13528 it.next()) { |
| 13529 if (RelocInfo::IsStatementPosition(it.rinfo()->rmode())) { |
| 13530 int p = static_cast<int>(it.rinfo()->data()); |
| 13531 if (statement_position < p && p <= position) { |
| 13532 statement_position = p; |
| 13533 } |
| 13514 } | 13534 } |
| 13515 } | 13535 } |
| 13516 } | 13536 } |
| 13517 return statement_position; | 13537 return statement_position; |
| 13518 } | 13538 } |
| 13519 | 13539 |
| 13520 | 13540 |
| 13521 SafepointEntry Code::GetSafepointEntry(Address pc) { | 13541 SafepointEntry Code::GetSafepointEntry(Address pc) { |
| 13522 SafepointTable table(this); | 13542 SafepointTable table(this); |
| 13523 return table.FindEntry(pc); | 13543 return table.FindEntry(pc); |
| (...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14304 os << "RelocInfo (size = " << relocation_size() << ")\n"; | 14324 os << "RelocInfo (size = " << relocation_size() << ")\n"; |
| 14305 for (RelocIterator it(this); !it.done(); it.next()) { | 14325 for (RelocIterator it(this); !it.done(); it.next()) { |
| 14306 it.rinfo()->Print(GetIsolate(), os); | 14326 it.rinfo()->Print(GetIsolate(), os); |
| 14307 } | 14327 } |
| 14308 os << "\n"; | 14328 os << "\n"; |
| 14309 } | 14329 } |
| 14310 #endif // ENABLE_DISASSEMBLER | 14330 #endif // ENABLE_DISASSEMBLER |
| 14311 | 14331 |
| 14312 int BytecodeArray::SourcePosition(int offset) { | 14332 int BytecodeArray::SourcePosition(int offset) { |
| 14313 int last_position = 0; | 14333 int last_position = 0; |
| 14314 for (interpreter::SourcePositionTableIterator iterator( | 14334 for (SourcePositionTableIterator iterator(source_position_table()); |
| 14315 source_position_table()); | 14335 !iterator.done() && iterator.code_offset() <= offset; |
| 14316 !iterator.done() && iterator.bytecode_offset() <= offset; | |
| 14317 iterator.Advance()) { | 14336 iterator.Advance()) { |
| 14318 last_position = iterator.source_position(); | 14337 last_position = iterator.source_position(); |
| 14319 } | 14338 } |
| 14320 return last_position; | 14339 return last_position; |
| 14321 } | 14340 } |
| 14322 | 14341 |
| 14323 int BytecodeArray::SourceStatementPosition(int offset) { | 14342 int BytecodeArray::SourceStatementPosition(int offset) { |
| 14324 // First find the closest position. | 14343 // First find the closest position. |
| 14325 int position = SourcePosition(offset); | 14344 int position = SourcePosition(offset); |
| 14326 // Now find the closest statement position before the position. | 14345 // Now find the closest statement position before the position. |
| 14327 int statement_position = 0; | 14346 int statement_position = 0; |
| 14328 for (interpreter::SourcePositionTableIterator it(source_position_table()); | 14347 for (SourcePositionTableIterator it(source_position_table()); !it.done(); |
| 14329 !it.done(); it.Advance()) { | 14348 it.Advance()) { |
| 14330 if (it.is_statement()) { | 14349 if (it.is_statement()) { |
| 14331 int p = it.source_position(); | 14350 int p = it.source_position(); |
| 14332 if (statement_position < p && p <= position) { | 14351 if (statement_position < p && p <= position) { |
| 14333 statement_position = p; | 14352 statement_position = p; |
| 14334 } | 14353 } |
| 14335 } | 14354 } |
| 14336 } | 14355 } |
| 14337 return statement_position; | 14356 return statement_position; |
| 14338 } | 14357 } |
| 14339 | 14358 |
| 14340 void BytecodeArray::Disassemble(std::ostream& os) { | 14359 void BytecodeArray::Disassemble(std::ostream& os) { |
| 14341 os << "Parameter count " << parameter_count() << "\n"; | 14360 os << "Parameter count " << parameter_count() << "\n"; |
| 14342 os << "Frame size " << frame_size() << "\n"; | 14361 os << "Frame size " << frame_size() << "\n"; |
| 14343 | 14362 |
| 14344 const uint8_t* base_address = GetFirstBytecodeAddress(); | 14363 const uint8_t* base_address = GetFirstBytecodeAddress(); |
| 14345 interpreter::SourcePositionTableIterator source_positions( | 14364 SourcePositionTableIterator source_positions(source_position_table()); |
| 14346 source_position_table()); | |
| 14347 | 14365 |
| 14348 interpreter::BytecodeArrayIterator iterator(handle(this)); | 14366 interpreter::BytecodeArrayIterator iterator(handle(this)); |
| 14349 while (!iterator.done()) { | 14367 while (!iterator.done()) { |
| 14350 if (!source_positions.done() && | 14368 if (!source_positions.done() && |
| 14351 iterator.current_offset() == source_positions.bytecode_offset()) { | 14369 iterator.current_offset() == source_positions.code_offset()) { |
| 14352 os << std::setw(5) << source_positions.source_position(); | 14370 os << std::setw(5) << source_positions.source_position(); |
| 14353 os << (source_positions.is_statement() ? " S> " : " E> "); | 14371 os << (source_positions.is_statement() ? " S> " : " E> "); |
| 14354 source_positions.Advance(); | 14372 source_positions.Advance(); |
| 14355 } else { | 14373 } else { |
| 14356 os << " "; | 14374 os << " "; |
| 14357 } | 14375 } |
| 14358 const uint8_t* current_address = base_address + iterator.current_offset(); | 14376 const uint8_t* current_address = base_address + iterator.current_offset(); |
| 14359 os << reinterpret_cast<const void*>(current_address) << " @ " | 14377 os << reinterpret_cast<const void*>(current_address) << " @ " |
| 14360 << std::setw(4) << iterator.current_offset() << " : "; | 14378 << std::setw(4) << iterator.current_offset() << " : "; |
| 14361 interpreter::Bytecodes::Decode(os, current_address, parameter_count()); | 14379 interpreter::Bytecodes::Decode(os, current_address, parameter_count()); |
| (...skipping 4490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 18852 } else { | 18870 } else { |
| 18853 // Old-style generators. | 18871 // Old-style generators. |
| 18854 int offset = continuation(); | 18872 int offset = continuation(); |
| 18855 CHECK(0 <= offset && offset < function()->code()->instruction_size()); | 18873 CHECK(0 <= offset && offset < function()->code()->instruction_size()); |
| 18856 return function()->code()->SourcePosition(offset); | 18874 return function()->code()->SourcePosition(offset); |
| 18857 } | 18875 } |
| 18858 } | 18876 } |
| 18859 | 18877 |
| 18860 } // namespace internal | 18878 } // namespace internal |
| 18861 } // namespace v8 | 18879 } // namespace v8 |
| OLD | NEW |