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

Side by Side Diff: src/runtime/runtime-interpreter.cc

Issue 1640213002: [Interpreter] Add option to trace bytecode execution. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Review comments Created 4 years, 10 months 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
« no previous file with comments | « src/runtime/runtime.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include <iomanip>
8
7 #include "src/arguments.h" 9 #include "src/arguments.h"
10 #include "src/frames-inl.h"
11 #include "src/interpreter/bytecode-array-iterator.h"
12 #include "src/interpreter/bytecodes.h"
8 #include "src/isolate-inl.h" 13 #include "src/isolate-inl.h"
9 14
10 namespace v8 { 15 namespace v8 {
11 namespace internal { 16 namespace internal {
12 17
13 18
14 RUNTIME_FUNCTION(Runtime_InterpreterEquals) { 19 RUNTIME_FUNCTION(Runtime_InterpreterEquals) {
15 HandleScope scope(isolate); 20 HandleScope scope(isolate);
16 DCHECK_EQ(2, args.length()); 21 DCHECK_EQ(2, args.length());
17 CONVERT_ARG_HANDLE_CHECKED(Object, x, 0); 22 CONVERT_ARG_HANDLE_CHECKED(Object, x, 0);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 RUNTIME_FUNCTION(Runtime_InterpreterNewClosure) { 145 RUNTIME_FUNCTION(Runtime_InterpreterNewClosure) {
141 HandleScope scope(isolate); 146 HandleScope scope(isolate);
142 DCHECK_EQ(2, args.length()); 147 DCHECK_EQ(2, args.length());
143 CONVERT_ARG_HANDLE_CHECKED(SharedFunctionInfo, shared, 0); 148 CONVERT_ARG_HANDLE_CHECKED(SharedFunctionInfo, shared, 0);
144 CONVERT_SMI_ARG_CHECKED(pretenured_flag, 1); 149 CONVERT_SMI_ARG_CHECKED(pretenured_flag, 1);
145 Handle<Context> context(isolate->context(), isolate); 150 Handle<Context> context(isolate->context(), isolate);
146 return *isolate->factory()->NewFunctionFromSharedFunctionInfo( 151 return *isolate->factory()->NewFunctionFromSharedFunctionInfo(
147 shared, context, static_cast<PretenureFlag>(pretenured_flag)); 152 shared, context, static_cast<PretenureFlag>(pretenured_flag));
148 } 153 }
149 154
155 namespace {
156
157 void PrintRegisters(std::ostream& os, bool is_input,
158 Handle<BytecodeArray> bytecode_array, int bytecode_offset,
159 Handle<Object> accumulator) {
160 static const int kRegFieldWidth = static_cast<int>(strlen("accumulator"));
161 static const char* kInputColourCode = "\033[0;36m";
162 static const char* kOutputColourCode = "\033[0;35m";
163 static const char* kNormalColourCode = "\033[0;m";
164 const char* kArrowDirection = is_input ? " -> " : " <- ";
165 if (FLAG_log_colour) {
166 os << (is_input ? kInputColourCode : kOutputColourCode);
167 }
168
169 // Print accumulator.
170 os << " [ accumulator" << kArrowDirection;
171 accumulator->ShortPrint();
172 os << " ]" << std::endl;
173
174 // Find the location of the register file.
175 JavaScriptFrameIterator frame_iterator(bytecode_array->GetIsolate());
176 JavaScriptFrame* frame = frame_iterator.frame();
177 Address register_file =
178 frame->fp() + InterpreterFrameConstants::kRegisterFilePointerFromFp;
179
180 // Print the registers.
181 interpreter::BytecodeArrayIterator bytecode_iterator(bytecode_array);
182 bytecode_iterator.set_current_offset(
183 bytecode_offset - BytecodeArray::kHeaderSize + kHeapObjectTag);
184 interpreter::Bytecode bytecode = bytecode_iterator.current_bytecode();
185 int operand_count = interpreter::Bytecodes::NumberOfOperands(bytecode);
186 for (int operand_index = 0; operand_index < operand_count; operand_index++) {
187 interpreter::OperandType operand_type =
188 interpreter::Bytecodes::GetOperandType(bytecode, operand_index);
189 bool should_print =
190 is_input
191 ? interpreter::Bytecodes::IsRegisterInputOperandType(operand_type)
192 : interpreter::Bytecodes::IsRegisterOutputOperandType(operand_type);
193 if (should_print) {
194 interpreter::Register first_reg =
195 bytecode_iterator.GetRegisterOperand(operand_index);
196 int range = bytecode_iterator.GetRegisterOperandRange(operand_index);
197 for (int reg_index = first_reg.index();
198 reg_index < first_reg.index() + range; reg_index++) {
199 Address reg_location = register_file - reg_index * kPointerSize;
200 Object* reg_object = Memory::Object_at(reg_location);
201 os << " [ " << std::setw(kRegFieldWidth)
202 << interpreter::Register(reg_index).ToString(
203 bytecode_array->parameter_count())
204 << kArrowDirection;
205 reg_object->ShortPrint(os);
206 os << " ]" << std::endl;
207 }
208 }
209 }
210 if (FLAG_log_colour) {
211 os << kNormalColourCode;
212 }
213 }
214
215 } // namespace
216
217 RUNTIME_FUNCTION(Runtime_InterpreterTraceBytecodeEntry) {
218 SealHandleScope shs(isolate);
219 DCHECK_EQ(3, args.length());
220 CONVERT_ARG_HANDLE_CHECKED(BytecodeArray, bytecode_array, 0);
221 CONVERT_SMI_ARG_CHECKED(bytecode_offset, 1);
222 CONVERT_ARG_HANDLE_CHECKED(Object, accumulator, 2);
223 OFStream os(stdout);
224
225 // Print bytecode.
226 const uint8_t* bytecode_address =
227 reinterpret_cast<const uint8_t*>(*bytecode_array) + bytecode_offset;
228 Vector<char> buf = Vector<char>::New(50);
229 SNPrintF(buf, "%p", bytecode_address);
230 os << " -> " << buf.start() << " (" << bytecode_offset << ") : ";
231 interpreter::Bytecodes::Decode(os, bytecode_address,
232 bytecode_array->parameter_count());
233 os << std::endl;
234
235 // Print all input registers and accumulator.
236 PrintRegisters(os, true, bytecode_array, bytecode_offset, accumulator);
237
238 os << std::flush;
239 return isolate->heap()->undefined_value();
240 }
241
242 RUNTIME_FUNCTION(Runtime_InterpreterTraceBytecodeExit) {
243 SealHandleScope shs(isolate);
244 DCHECK_EQ(3, args.length());
245 CONVERT_ARG_HANDLE_CHECKED(BytecodeArray, bytecode_array, 0);
246 CONVERT_SMI_ARG_CHECKED(bytecode_offset, 1);
247 CONVERT_ARG_HANDLE_CHECKED(Object, accumulator, 2);
248 OFStream os(stdout);
249
250 // Print all output registers and accumulator.
251 PrintRegisters(os, false, bytecode_array, bytecode_offset, accumulator);
252 os << std::flush;
253 return isolate->heap()->undefined_value();
254 }
255
150 } // namespace internal 256 } // namespace internal
151 } // namespace v8 257 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698