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 <iomanip> | |
6 | |
5 #include "src/runtime/runtime-utils.h" | 7 #include "src/runtime/runtime-utils.h" |
Michael Starzinger
2016/01/28 12:07:06
nit: Let's keep the runtime-utils.h include first.
rmcilroy
2016/01/28 16:39:51
Done.
| |
6 | 8 |
7 #include "src/arguments.h" | 9 #include "src/arguments.h" |
10 #include "src/frames-inl.h" | |
11 #include "src/frames.h" | |
Michael Starzinger
2016/01/28 12:07:06
nit: For us "frames-inl.h" satisfies "frames.h", o
rmcilroy
2016/01/28 16:39:51
Done.
| |
12 #include "src/interpreter/bytecode-array-iterator.h" | |
13 #include "src/interpreter/bytecodes.h" | |
8 #include "src/isolate-inl.h" | 14 #include "src/isolate-inl.h" |
9 | 15 |
10 namespace v8 { | 16 namespace v8 { |
11 namespace internal { | 17 namespace internal { |
12 | 18 |
13 | 19 |
14 RUNTIME_FUNCTION(Runtime_InterpreterEquals) { | 20 RUNTIME_FUNCTION(Runtime_InterpreterEquals) { |
15 HandleScope scope(isolate); | 21 HandleScope scope(isolate); |
16 DCHECK_EQ(2, args.length()); | 22 DCHECK_EQ(2, args.length()); |
17 CONVERT_ARG_HANDLE_CHECKED(Object, x, 0); | 23 CONVERT_ARG_HANDLE_CHECKED(Object, x, 0); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 RUNTIME_FUNCTION(Runtime_InterpreterNewClosure) { | 146 RUNTIME_FUNCTION(Runtime_InterpreterNewClosure) { |
141 HandleScope scope(isolate); | 147 HandleScope scope(isolate); |
142 DCHECK_EQ(2, args.length()); | 148 DCHECK_EQ(2, args.length()); |
143 CONVERT_ARG_HANDLE_CHECKED(SharedFunctionInfo, shared, 0); | 149 CONVERT_ARG_HANDLE_CHECKED(SharedFunctionInfo, shared, 0); |
144 CONVERT_SMI_ARG_CHECKED(pretenured_flag, 1); | 150 CONVERT_SMI_ARG_CHECKED(pretenured_flag, 1); |
145 Handle<Context> context(isolate->context(), isolate); | 151 Handle<Context> context(isolate->context(), isolate); |
146 return *isolate->factory()->NewFunctionFromSharedFunctionInfo( | 152 return *isolate->factory()->NewFunctionFromSharedFunctionInfo( |
147 shared, context, static_cast<PretenureFlag>(pretenured_flag)); | 153 shared, context, static_cast<PretenureFlag>(pretenured_flag)); |
148 } | 154 } |
149 | 155 |
156 static void PrintRegisters(std::ostream& os, bool is_input, | |
Michael Starzinger
2016/01/28 12:07:06
nit: Can we put this into an anonymous namespace i
rmcilroy
2016/01/28 16:39:51
Done.
| |
157 Handle<BytecodeArray> bytecode_array, | |
158 int bytecode_offset, Handle<Object> accumulator) { | |
159 static const int kRegFieldWidth = static_cast<int>(strlen("accumulator")); | |
160 static const char* kInputColourCode = "\033[0;36m"; | |
161 static const char* kOutputColourCode = "\033[0;35m"; | |
162 static const char* kNormalColourCode = "\033[0;m"; | |
163 const char* kArrowDirection = is_input ? " -> " : " <- "; | |
164 if (FLAG_log_colour) { | |
165 os << (is_input ? kInputColourCode : kOutputColourCode); | |
166 } | |
167 | |
168 // Print accumulator. | |
169 os << " [ accumulator" << kArrowDirection; | |
170 accumulator->ShortPrint(); | |
171 os << " ]" << std::endl; | |
172 | |
173 // Find the location of the register file. | |
174 JavaScriptFrameIterator frame_iterator(bytecode_array->GetIsolate()); | |
175 JavaScriptFrame* frame = frame_iterator.frame(); | |
176 Address register_file = | |
177 frame->fp() + InterpreterFrameConstants::kRegisterFilePointerFromFp; | |
178 | |
179 // Print the registers. | |
180 interpreter::BytecodeArrayIterator bytecode_iterator(bytecode_array); | |
181 bytecode_iterator.set_current_offset( | |
182 bytecode_offset - BytecodeArray::kHeaderSize + kHeapObjectTag); | |
183 interpreter::Bytecode bytecode = bytecode_iterator.current_bytecode(); | |
184 for (int operand_index = 0; | |
185 operand_index < interpreter::Bytecodes::NumberOfOperands(bytecode); | |
186 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 RUNTIME_FUNCTION(Runtime_InterpreterTraceBytecodeEntry) { | |
216 SealHandleScope shs(isolate); | |
217 DCHECK_EQ(3, args.length()); | |
218 CONVERT_ARG_HANDLE_CHECKED(BytecodeArray, bytecode_array, 0); | |
219 CONVERT_SMI_ARG_CHECKED(bytecode_offset, 1); | |
220 CONVERT_ARG_HANDLE_CHECKED(Object, accumulator, 2); | |
221 OFStream os(stdout); | |
222 | |
223 // Print bytecode. | |
224 const uint8_t* bytecode_address = | |
225 reinterpret_cast<const uint8_t*>(*bytecode_array) + bytecode_offset; | |
226 Vector<char> buf = Vector<char>::New(50); | |
227 SNPrintF(buf, "%p", bytecode_address); | |
228 os << " -> " << buf.start() << " (" << bytecode_offset << ") : "; | |
229 interpreter::Bytecodes::Decode(os, bytecode_address, | |
230 bytecode_array->parameter_count()); | |
231 os << std::endl; | |
232 | |
233 // Print all input registers and accumulator. | |
234 PrintRegisters(os, true, bytecode_array, bytecode_offset, accumulator); | |
235 | |
236 os << std::flush; | |
237 return isolate->heap()->undefined_value(); | |
238 } | |
239 | |
240 RUNTIME_FUNCTION(Runtime_InterpreterTraceBytecodeExit) { | |
241 SealHandleScope shs(isolate); | |
242 DCHECK_EQ(3, args.length()); | |
243 CONVERT_ARG_HANDLE_CHECKED(BytecodeArray, bytecode_array, 0); | |
244 CONVERT_SMI_ARG_CHECKED(bytecode_offset, 1); | |
245 CONVERT_ARG_HANDLE_CHECKED(Object, accumulator, 2); | |
246 OFStream os(stdout); | |
247 | |
248 // Print all output registers and accumulator. | |
249 PrintRegisters(os, false, bytecode_array, bytecode_offset, accumulator); | |
250 os << std::flush; | |
251 return isolate->heap()->undefined_value(); | |
252 } | |
253 | |
150 } // namespace internal | 254 } // namespace internal |
151 } // namespace v8 | 255 } // namespace v8 |
OLD | NEW |