OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/bootstrapper.h" | 7 #include "src/bootstrapper.h" |
8 #include "src/codegen.h" | 8 #include "src/codegen.h" |
9 #include "src/compiler.h" | 9 #include "src/compiler.h" |
10 #include "src/cpu-profiler.h" | 10 #include "src/cpu-profiler.h" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 : (FLAG_print_code || | 168 : (FLAG_print_code || |
169 (info->IsStub() && FLAG_print_code_stubs) || | 169 (info->IsStub() && FLAG_print_code_stubs) || |
170 (info->IsOptimizing() && FLAG_print_opt_code)); | 170 (info->IsOptimizing() && FLAG_print_opt_code)); |
171 if (print_code) { | 171 if (print_code) { |
172 // Print the source code if available. | 172 // Print the source code if available. |
173 FunctionLiteral* function = info->function(); | 173 FunctionLiteral* function = info->function(); |
174 bool print_source = code->kind() == Code::OPTIMIZED_FUNCTION || | 174 bool print_source = code->kind() == Code::OPTIMIZED_FUNCTION || |
175 code->kind() == Code::FUNCTION; | 175 code->kind() == Code::FUNCTION; |
176 | 176 |
177 CodeTracer::Scope tracing_scope(info->isolate()->GetCodeTracer()); | 177 CodeTracer::Scope tracing_scope(info->isolate()->GetCodeTracer()); |
| 178 OFStream os(tracing_scope.file()); |
178 if (print_source) { | 179 if (print_source) { |
179 Handle<Script> script = info->script(); | 180 Handle<Script> script = info->script(); |
180 if (!script->IsUndefined() && !script->source()->IsUndefined()) { | 181 if (!script->IsUndefined() && !script->source()->IsUndefined()) { |
181 PrintF(tracing_scope.file(), "--- Raw source ---\n"); | 182 os << "--- Raw source ---\n"; |
182 ConsStringIteratorOp op; | 183 ConsStringIteratorOp op; |
183 StringCharacterStream stream(String::cast(script->source()), | 184 StringCharacterStream stream(String::cast(script->source()), |
184 &op, | 185 &op, |
185 function->start_position()); | 186 function->start_position()); |
186 // fun->end_position() points to the last character in the stream. We | 187 // fun->end_position() points to the last character in the stream. We |
187 // need to compensate by adding one to calculate the length. | 188 // need to compensate by adding one to calculate the length. |
188 int source_len = | 189 int source_len = |
189 function->end_position() - function->start_position() + 1; | 190 function->end_position() - function->start_position() + 1; |
190 for (int i = 0; i < source_len; i++) { | 191 for (int i = 0; i < source_len; i++) { |
191 if (stream.HasMore()) { | 192 if (stream.HasMore()) { |
192 PrintF(tracing_scope.file(), "%c", stream.GetNext()); | 193 os.put(stream.GetNext()); |
193 } | 194 } |
194 } | 195 } |
195 PrintF(tracing_scope.file(), "\n\n"); | 196 os << "\n\n"; |
196 } | 197 } |
197 } | 198 } |
198 if (info->IsOptimizing()) { | 199 if (info->IsOptimizing()) { |
199 if (FLAG_print_unopt_code) { | 200 if (FLAG_print_unopt_code) { |
200 PrintF(tracing_scope.file(), "--- Unoptimized code ---\n"); | 201 os << "--- Unoptimized code ---\n"; |
201 info->closure()->shared()->code()->Disassemble( | 202 info->closure()->shared()->code()->Disassemble( |
202 function->debug_name()->ToCString().get(), tracing_scope.file()); | 203 function->debug_name()->ToCString().get(), os); |
203 } | 204 } |
204 PrintF(tracing_scope.file(), "--- Optimized code ---\n"); | 205 os << "--- Optimized code ---\n" |
205 PrintF(tracing_scope.file(), | 206 << "optimization_id = " << info->optimization_id() << "\n"; |
206 "optimization_id = %d\n", info->optimization_id()); | |
207 } else { | 207 } else { |
208 PrintF(tracing_scope.file(), "--- Code ---\n"); | 208 os << "--- Code ---\n"; |
209 } | 209 } |
210 if (print_source) { | 210 if (print_source) { |
211 PrintF(tracing_scope.file(), | 211 os << "source_position = " << function->start_position() << "\n"; |
212 "source_position = %d\n", function->start_position()); | |
213 } | 212 } |
214 if (info->IsStub()) { | 213 if (info->IsStub()) { |
215 CodeStub::Major major_key = info->code_stub()->MajorKey(); | 214 CodeStub::Major major_key = info->code_stub()->MajorKey(); |
216 code->Disassemble(CodeStub::MajorName(major_key, false), | 215 code->Disassemble(CodeStub::MajorName(major_key, false), os); |
217 tracing_scope.file()); | |
218 } else { | 216 } else { |
219 code->Disassemble(function->debug_name()->ToCString().get(), | 217 code->Disassemble(function->debug_name()->ToCString().get(), os); |
220 tracing_scope.file()); | |
221 } | 218 } |
222 PrintF(tracing_scope.file(), "--- End code ---\n"); | 219 os << "--- End code ---\n"; |
223 } | 220 } |
224 #endif // ENABLE_DISASSEMBLER | 221 #endif // ENABLE_DISASSEMBLER |
225 } | 222 } |
226 | 223 |
227 | 224 |
228 bool CodeGenerator::RecordPositions(MacroAssembler* masm, | 225 bool CodeGenerator::RecordPositions(MacroAssembler* masm, |
229 int pos, | 226 int pos, |
230 bool right_here) { | 227 bool right_here) { |
231 if (pos != RelocInfo::kNoPosition) { | 228 if (pos != RelocInfo::kNoPosition) { |
232 masm->positions_recorder()->RecordStatementPosition(pos); | 229 masm->positions_recorder()->RecordStatementPosition(pos); |
(...skipping 29 matching lines...) Expand all Loading... |
262 ASSERT(result_size_ == 1 || result_size_ == 2); | 259 ASSERT(result_size_ == 1 || result_size_ == 2); |
263 #ifdef _WIN64 | 260 #ifdef _WIN64 |
264 return result | ((result_size_ == 1) ? 0 : 2); | 261 return result | ((result_size_ == 1) ? 0 : 2); |
265 #else | 262 #else |
266 return result; | 263 return result; |
267 #endif | 264 #endif |
268 } | 265 } |
269 | 266 |
270 | 267 |
271 } } // namespace v8::internal | 268 } } // namespace v8::internal |
OLD | NEW |