| Index: src/runtime/runtime-interpreter.cc
|
| diff --git a/src/runtime/runtime-interpreter.cc b/src/runtime/runtime-interpreter.cc
|
| index 9c53317b4af7cbeec67a3634b96555f4ed803f0f..21b4016359fb4f1e52001e3dd21eb73a0de059c8 100644
|
| --- a/src/runtime/runtime-interpreter.cc
|
| +++ b/src/runtime/runtime-interpreter.cc
|
| @@ -28,8 +28,18 @@ RUNTIME_FUNCTION(Runtime_InterpreterNewClosure) {
|
|
|
| namespace {
|
|
|
| +void AdvanceToOffsetForTracing(
|
| + interpreter::BytecodeArrayIterator& bytecode_iterator, int offset) {
|
| + while (bytecode_iterator.current_offset() +
|
| + bytecode_iterator.current_bytecode_size() <=
|
| + offset) {
|
| + bytecode_iterator.Advance();
|
| + }
|
| + DCHECK_EQ(offset, bytecode_iterator.current_offset());
|
| +}
|
| +
|
| void PrintRegisters(std::ostream& os, bool is_input,
|
| - Handle<BytecodeArray> bytecode_array, int bytecode_offset,
|
| + interpreter::BytecodeArrayIterator& bytecode_iterator,
|
| Handle<Object> accumulator) {
|
| static const int kRegFieldWidth = static_cast<int>(strlen("accumulator"));
|
| static const char* kInputColourCode = "\033[0;36m";
|
| @@ -46,15 +56,13 @@ void PrintRegisters(std::ostream& os, bool is_input,
|
| os << " ]" << std::endl;
|
|
|
| // Find the location of the register file.
|
| - JavaScriptFrameIterator frame_iterator(bytecode_array->GetIsolate());
|
| + JavaScriptFrameIterator frame_iterator(
|
| + bytecode_iterator.bytecode_array()->GetIsolate());
|
| JavaScriptFrame* frame = frame_iterator.frame();
|
| Address register_file =
|
| frame->fp() + InterpreterFrameConstants::kRegisterFilePointerFromFp;
|
|
|
| // Print the registers.
|
| - interpreter::BytecodeArrayIterator bytecode_iterator(bytecode_array);
|
| - bytecode_iterator.set_current_offset(
|
| - bytecode_offset - BytecodeArray::kHeaderSize + kHeapObjectTag);
|
| interpreter::Bytecode bytecode = bytecode_iterator.current_bytecode();
|
| int operand_count = interpreter::Bytecodes::NumberOfOperands(bytecode);
|
| for (int operand_index = 0; operand_index < operand_count; operand_index++) {
|
| @@ -74,7 +82,7 @@ void PrintRegisters(std::ostream& os, bool is_input,
|
| Object* reg_object = Memory::Object_at(reg_location);
|
| os << " [ " << std::setw(kRegFieldWidth)
|
| << interpreter::Register(reg_index).ToString(
|
| - bytecode_array->parameter_count())
|
| + bytecode_iterator.bytecode_array()->parameter_count())
|
| << kArrowDirection;
|
| reg_object->ShortPrint(os);
|
| os << " ]" << std::endl;
|
| @@ -96,20 +104,24 @@ RUNTIME_FUNCTION(Runtime_InterpreterTraceBytecodeEntry) {
|
| CONVERT_ARG_HANDLE_CHECKED(Object, accumulator, 2);
|
| OFStream os(stdout);
|
|
|
| - // Print bytecode.
|
| - const uint8_t* bytecode_address =
|
| - reinterpret_cast<const uint8_t*>(*bytecode_array) + bytecode_offset;
|
| - Vector<char> buf = Vector<char>::New(50);
|
| - SNPrintF(buf, "%p", bytecode_address);
|
| - os << " -> " << buf.start() << " (" << bytecode_offset << ") : ";
|
| - interpreter::Bytecodes::Decode(os, bytecode_address,
|
| - bytecode_array->parameter_count());
|
| - os << std::endl;
|
| -
|
| - // Print all input registers and accumulator.
|
| - PrintRegisters(os, true, bytecode_array, bytecode_offset, accumulator);
|
| -
|
| - os << std::flush;
|
| + int offset = bytecode_offset - BytecodeArray::kHeaderSize + kHeapObjectTag;
|
| + interpreter::BytecodeArrayIterator bytecode_iterator(bytecode_array);
|
| + AdvanceToOffsetForTracing(bytecode_iterator, offset);
|
| + if (offset == bytecode_iterator.current_offset()) {
|
| + // Print bytecode.
|
| + const uint8_t* bytecode_address =
|
| + reinterpret_cast<const uint8_t*>(*bytecode_array) + bytecode_offset;
|
| + Vector<char> buf = Vector<char>::New(50);
|
| + SNPrintF(buf, "%p", bytecode_address);
|
| + os << " -> " << buf.start() << " (" << bytecode_offset << ") : ";
|
| + interpreter::Bytecodes::Decode(os, bytecode_address,
|
| + bytecode_array->parameter_count());
|
| + os << std::endl;
|
| + // Print all input registers and accumulator.
|
| + PrintRegisters(os, true, bytecode_iterator, accumulator);
|
| +
|
| + os << std::flush;
|
| + }
|
| return isolate->heap()->undefined_value();
|
| }
|
|
|
| @@ -119,11 +131,21 @@ RUNTIME_FUNCTION(Runtime_InterpreterTraceBytecodeExit) {
|
| CONVERT_ARG_HANDLE_CHECKED(BytecodeArray, bytecode_array, 0);
|
| CONVERT_SMI_ARG_CHECKED(bytecode_offset, 1);
|
| CONVERT_ARG_HANDLE_CHECKED(Object, accumulator, 2);
|
| - OFStream os(stdout);
|
|
|
| - // Print all output registers and accumulator.
|
| - PrintRegisters(os, false, bytecode_array, bytecode_offset, accumulator);
|
| - os << std::flush;
|
| + int offset = bytecode_offset - BytecodeArray::kHeaderSize + kHeapObjectTag;
|
| + interpreter::BytecodeArrayIterator bytecode_iterator(bytecode_array);
|
| + AdvanceToOffsetForTracing(bytecode_iterator, offset);
|
| + // The offset comparison here ensures registers only printed when the
|
| + // (potentially) widened bytecode has completed. The iterator reports
|
| + // the offset as the offset of the prefix bytecode.
|
| + if (bytecode_iterator.current_operand_scale() ==
|
| + interpreter::OperandScale::kSingle ||
|
| + offset > bytecode_iterator.current_offset()) {
|
| + OFStream os(stdout);
|
| + // Print all output registers and accumulator.
|
| + PrintRegisters(os, false, bytecode_iterator, accumulator);
|
| + os << std::flush;
|
| + }
|
| return isolate->heap()->undefined_value();
|
| }
|
|
|
|
|