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 #if defined(V8_OS_AIX) | 7 #if defined(V8_OS_AIX) |
8 #include <fenv.h> | 8 #include <fenv.h> |
9 #endif | 9 #endif |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
11 #include "src/codegen.h" | 11 #include "src/codegen.h" |
12 #include "src/compiler.h" | 12 #include "src/compiler.h" |
13 #include "src/cpu-profiler.h" | 13 #include "src/cpu-profiler.h" |
14 #include "src/debug.h" | 14 #include "src/debug.h" |
| 15 #include "src/parser.h" |
15 #include "src/prettyprinter.h" | 16 #include "src/prettyprinter.h" |
16 #include "src/rewriter.h" | 17 #include "src/rewriter.h" |
17 #include "src/runtime/runtime.h" | 18 #include "src/runtime/runtime.h" |
18 | 19 |
19 namespace v8 { | 20 namespace v8 { |
20 namespace internal { | 21 namespace internal { |
21 | 22 |
22 | 23 |
23 #if defined(_WIN64) | 24 #if defined(_WIN64) |
24 typedef double (*ModuloFunction)(double, double); | 25 typedef double (*ModuloFunction)(double, double); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 CodeStub::MajorName(info->code_stub()->MajorKey(), true); | 128 CodeStub::MajorName(info->code_stub()->MajorKey(), true); |
128 PrintF("%s", name == NULL ? "<unknown>" : name); | 129 PrintF("%s", name == NULL ? "<unknown>" : name); |
129 } else { | 130 } else { |
130 AllowDeferredHandleDereference allow_deference_for_trace; | 131 AllowDeferredHandleDereference allow_deference_for_trace; |
131 PrintF("%s", info->function()->debug_name()->ToCString().get()); | 132 PrintF("%s", info->function()->debug_name()->ToCString().get()); |
132 } | 133 } |
133 PrintF("]\n"); | 134 PrintF("]\n"); |
134 } | 135 } |
135 | 136 |
136 #ifdef DEBUG | 137 #ifdef DEBUG |
137 if (!info->IsStub() && print_source) { | 138 if (info->parse_info() && print_source) { |
138 PrintF("--- Source from AST ---\n%s\n", | 139 PrintF("--- Source from AST ---\n%s\n", |
139 PrettyPrinter(info->isolate(), info->zone()) | 140 PrettyPrinter(info->isolate(), info->zone()) |
140 .PrintProgram(info->function())); | 141 .PrintProgram(info->function())); |
141 } | 142 } |
142 | 143 |
143 if (!info->IsStub() && print_ast) { | 144 if (info->parse_info() && print_ast) { |
144 PrintF("--- AST ---\n%s\n", AstPrinter(info->isolate(), info->zone()) | 145 PrintF("--- AST ---\n%s\n", AstPrinter(info->isolate(), info->zone()) |
145 .PrintProgram(info->function())); | 146 .PrintProgram(info->function())); |
146 } | 147 } |
147 #endif // DEBUG | 148 #endif // DEBUG |
148 } | 149 } |
149 | 150 |
150 | 151 |
151 Handle<Code> CodeGenerator::MakeCodeEpilogue(MacroAssembler* masm, | 152 Handle<Code> CodeGenerator::MakeCodeEpilogue(MacroAssembler* masm, |
152 Code::Flags flags, | 153 Code::Flags flags, |
153 CompilationInfo* info) { | 154 CompilationInfo* info) { |
(...skipping 20 matching lines...) Expand all Loading... |
174 | 175 |
175 void CodeGenerator::PrintCode(Handle<Code> code, CompilationInfo* info) { | 176 void CodeGenerator::PrintCode(Handle<Code> code, CompilationInfo* info) { |
176 #ifdef ENABLE_DISASSEMBLER | 177 #ifdef ENABLE_DISASSEMBLER |
177 AllowDeferredHandleDereference allow_deference_for_print_code; | 178 AllowDeferredHandleDereference allow_deference_for_print_code; |
178 bool print_code = info->isolate()->bootstrapper()->IsActive() | 179 bool print_code = info->isolate()->bootstrapper()->IsActive() |
179 ? FLAG_print_builtin_code | 180 ? FLAG_print_builtin_code |
180 : (FLAG_print_code || | 181 : (FLAG_print_code || |
181 (info->IsStub() && FLAG_print_code_stubs) || | 182 (info->IsStub() && FLAG_print_code_stubs) || |
182 (info->IsOptimizing() && FLAG_print_opt_code)); | 183 (info->IsOptimizing() && FLAG_print_opt_code)); |
183 if (print_code) { | 184 if (print_code) { |
184 // Print the source code if available. | 185 const char* debug_name; |
185 FunctionLiteral* function = info->function(); | 186 if (info->IsStub()) { |
186 bool print_source = code->kind() == Code::OPTIMIZED_FUNCTION || | 187 CodeStub::Major major_key = info->code_stub()->MajorKey(); |
187 code->kind() == Code::FUNCTION; | 188 debug_name = CodeStub::MajorName(major_key, false); |
| 189 } else { |
| 190 debug_name = |
| 191 info->parse_info()->function()->debug_name()->ToCString().get(); |
| 192 } |
188 | 193 |
189 CodeTracer::Scope tracing_scope(info->isolate()->GetCodeTracer()); | 194 CodeTracer::Scope tracing_scope(info->isolate()->GetCodeTracer()); |
190 OFStream os(tracing_scope.file()); | 195 OFStream os(tracing_scope.file()); |
| 196 |
| 197 // Print the source code if available. |
| 198 FunctionLiteral* function = nullptr; |
| 199 bool print_source = |
| 200 info->parse_info() && (code->kind() == Code::OPTIMIZED_FUNCTION || |
| 201 code->kind() == Code::FUNCTION); |
191 if (print_source) { | 202 if (print_source) { |
| 203 function = info->function(); |
192 Handle<Script> script = info->script(); | 204 Handle<Script> script = info->script(); |
193 if (!script->IsUndefined() && !script->source()->IsUndefined()) { | 205 if (!script->IsUndefined() && !script->source()->IsUndefined()) { |
194 os << "--- Raw source ---\n"; | 206 os << "--- Raw source ---\n"; |
195 StringCharacterStream stream(String::cast(script->source()), | 207 StringCharacterStream stream(String::cast(script->source()), |
196 function->start_position()); | 208 function->start_position()); |
197 // fun->end_position() points to the last character in the stream. We | 209 // fun->end_position() points to the last character in the stream. We |
198 // need to compensate by adding one to calculate the length. | 210 // need to compensate by adding one to calculate the length. |
199 int source_len = | 211 int source_len = |
200 function->end_position() - function->start_position() + 1; | 212 function->end_position() - function->start_position() + 1; |
201 for (int i = 0; i < source_len; i++) { | 213 for (int i = 0; i < source_len; i++) { |
202 if (stream.HasMore()) { | 214 if (stream.HasMore()) { |
203 os << AsReversiblyEscapedUC16(stream.GetNext()); | 215 os << AsReversiblyEscapedUC16(stream.GetNext()); |
204 } | 216 } |
205 } | 217 } |
206 os << "\n\n"; | 218 os << "\n\n"; |
207 } | 219 } |
208 } | 220 } |
209 if (info->IsOptimizing()) { | 221 if (info->IsOptimizing()) { |
210 if (FLAG_print_unopt_code) { | 222 if (FLAG_print_unopt_code && info->parse_info()) { |
211 os << "--- Unoptimized code ---\n"; | 223 os << "--- Unoptimized code ---\n"; |
212 info->closure()->shared()->code()->Disassemble( | 224 info->closure()->shared()->code()->Disassemble(debug_name, os); |
213 function->debug_name()->ToCString().get(), os); | |
214 } | 225 } |
215 os << "--- Optimized code ---\n" | 226 os << "--- Optimized code ---\n" |
216 << "optimization_id = " << info->optimization_id() << "\n"; | 227 << "optimization_id = " << info->optimization_id() << "\n"; |
217 } else { | 228 } else { |
218 os << "--- Code ---\n"; | 229 os << "--- Code ---\n"; |
219 } | 230 } |
220 if (print_source) { | 231 if (print_source) { |
221 os << "source_position = " << function->start_position() << "\n"; | 232 os << "source_position = " << function->start_position() << "\n"; |
222 } | 233 } |
223 if (info->IsStub()) { | 234 code->Disassemble(debug_name, os); |
224 CodeStub::Major major_key = info->code_stub()->MajorKey(); | |
225 code->Disassemble(CodeStub::MajorName(major_key, false), os); | |
226 } else { | |
227 code->Disassemble(function->debug_name()->ToCString().get(), os); | |
228 } | |
229 os << "--- End code ---\n"; | 235 os << "--- End code ---\n"; |
230 } | 236 } |
231 #endif // ENABLE_DISASSEMBLER | 237 #endif // ENABLE_DISASSEMBLER |
232 } | 238 } |
233 | 239 |
234 | 240 |
235 bool CodeGenerator::RecordPositions(MacroAssembler* masm, | 241 bool CodeGenerator::RecordPositions(MacroAssembler* masm, |
236 int pos, | 242 int pos, |
237 bool right_here) { | 243 bool right_here) { |
238 if (pos != RelocInfo::kNoPosition) { | 244 if (pos != RelocInfo::kNoPosition) { |
239 masm->positions_recorder()->RecordStatementPosition(pos); | 245 masm->positions_recorder()->RecordStatementPosition(pos); |
240 masm->positions_recorder()->RecordPosition(pos); | 246 masm->positions_recorder()->RecordPosition(pos); |
241 if (right_here) { | 247 if (right_here) { |
242 return masm->positions_recorder()->WriteRecordedPositions(); | 248 return masm->positions_recorder()->WriteRecordedPositions(); |
243 } | 249 } |
244 } | 250 } |
245 return false; | 251 return false; |
246 } | 252 } |
247 | 253 |
248 } } // namespace v8::internal | 254 } } // namespace v8::internal |
OLD | NEW |