| Index: src/runtime/runtime-interpreter.cc
|
| diff --git a/src/runtime/runtime-interpreter.cc b/src/runtime/runtime-interpreter.cc
|
| index 9c53317b4af7cbeec67a3634b96555f4ed803f0f..f593235d20318fc1d899ca4ec887a348367b07b3 100644
|
| --- a/src/runtime/runtime-interpreter.cc
|
| +++ b/src/runtime/runtime-interpreter.cc
|
| @@ -28,8 +28,30 @@ RUNTIME_FUNCTION(Runtime_InterpreterNewClosure) {
|
|
|
| namespace {
|
|
|
| +void AdvanceToOffsetForTracing(
|
| + interpreter::BytecodeArrayIterator& bytecode_iterator, int offset) {
|
| + if (offset > 0) {
|
| + uint8_t last_byte = bytecode_iterator.bytecode_array()->get(offset - 1);
|
| + auto maybe_bytecode = static_cast<interpreter::Bytecode>(last_byte);
|
| + if (interpreter::Bytecodes::IsPrefixScalingBytecode(maybe_bytecode)) {
|
| + // Previous byte looks like a prefix byte so scan forward slowly.
|
| + while (bytecode_iterator.current_offset() +
|
| + bytecode_iterator.current_bytecode_size() <=
|
| + offset) {
|
| + bytecode_iterator.Advance();
|
| + }
|
| + DCHECK(bytecode_iterator.current_offset() == offset ||
|
| + ((bytecode_iterator.current_offset() == offset - 1) &&
|
| + bytecode_iterator.current_operand_scale() > 1));
|
| + } else {
|
| + bytecode_iterator.set_current_offset(offset);
|
| + }
|
| + }
|
| + DCHECK(bytecode_iterator.current_bytecode() != interpreter::Bytecode::kWide);
|
| +}
|
| +
|
| 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 +68,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 +94,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 +116,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 +143,17 @@ 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);
|
| + if (bytecode_iterator.current_operand_scale() == 1 ||
|
| + 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();
|
| }
|
|
|
|
|