| 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/compiler.h" | 5 #include "src/compiler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "src/ast-numbering.h" | 9 #include "src/ast-numbering.h" |
| 10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 149 |
| 150 CompilationInfo::CompilationInfo(CodeStub* stub, Isolate* isolate, Zone* zone) | 150 CompilationInfo::CompilationInfo(CodeStub* stub, Isolate* isolate, Zone* zone) |
| 151 : CompilationInfo(nullptr, stub, CodeStub::MajorName(stub->MajorKey()), | 151 : CompilationInfo(nullptr, stub, CodeStub::MajorName(stub->MajorKey()), |
| 152 STUB, isolate, zone) {} | 152 STUB, isolate, zone) {} |
| 153 | 153 |
| 154 CompilationInfo::CompilationInfo(const char* debug_name, Isolate* isolate, | 154 CompilationInfo::CompilationInfo(const char* debug_name, Isolate* isolate, |
| 155 Zone* zone) | 155 Zone* zone) |
| 156 : CompilationInfo(nullptr, nullptr, debug_name, STUB, isolate, zone) {} | 156 : CompilationInfo(nullptr, nullptr, debug_name, STUB, isolate, zone) {} |
| 157 | 157 |
| 158 CompilationInfo::CompilationInfo(ParseInfo* parse_info, CodeStub* code_stub, | 158 CompilationInfo::CompilationInfo(ParseInfo* parse_info, CodeStub* code_stub, |
| 159 const char* code_stub_debug_name, Mode mode, | 159 const char* debug_name, Mode mode, |
| 160 Isolate* isolate, Zone* zone) | 160 Isolate* isolate, Zone* zone) |
| 161 : parse_info_(parse_info), | 161 : parse_info_(parse_info), |
| 162 isolate_(isolate), | 162 isolate_(isolate), |
| 163 flags_(0), | 163 flags_(0), |
| 164 code_stub_(code_stub), | 164 code_stub_(code_stub), |
| 165 mode_(mode), | 165 mode_(mode), |
| 166 osr_ast_id_(BailoutId::None()), | 166 osr_ast_id_(BailoutId::None()), |
| 167 zone_(zone), | 167 zone_(zone), |
| 168 deferred_handles_(nullptr), | 168 deferred_handles_(nullptr), |
| 169 dependencies_(isolate, zone), | 169 dependencies_(isolate, zone), |
| 170 bailout_reason_(kNoReason), | 170 bailout_reason_(kNoReason), |
| 171 prologue_offset_(Code::kPrologueOffsetNotSet), | 171 prologue_offset_(Code::kPrologueOffsetNotSet), |
| 172 no_frame_ranges_(isolate->cpu_profiler()->is_profiling() | 172 no_frame_ranges_(isolate->cpu_profiler()->is_profiling() |
| 173 ? new List<OffsetRange>(2) | 173 ? new List<OffsetRange>(2) |
| 174 : nullptr), | 174 : nullptr), |
| 175 track_positions_(FLAG_hydrogen_track_positions || | 175 track_positions_(FLAG_hydrogen_track_positions || |
| 176 isolate->cpu_profiler()->is_profiling()), | 176 isolate->cpu_profiler()->is_profiling()), |
| 177 opt_count_(has_shared_info() ? shared_info()->opt_count() : 0), | 177 opt_count_(has_shared_info() ? shared_info()->opt_count() : 0), |
| 178 parameter_count_(0), | 178 parameter_count_(0), |
| 179 optimization_id_(-1), | 179 optimization_id_(-1), |
| 180 osr_expr_stack_height_(0), | 180 osr_expr_stack_height_(0), |
| 181 function_type_(nullptr), | 181 function_type_(nullptr), |
| 182 code_stub_debug_name_(code_stub_debug_name) { | 182 debug_name_(debug_name) { |
| 183 // Parameter count is number of stack parameters. | 183 // Parameter count is number of stack parameters. |
| 184 if (code_stub_ != NULL) { | 184 if (code_stub_ != NULL) { |
| 185 CodeStubDescriptor descriptor(code_stub_); | 185 CodeStubDescriptor descriptor(code_stub_); |
| 186 parameter_count_ = descriptor.GetStackParameterCount(); | 186 parameter_count_ = descriptor.GetStackParameterCount(); |
| 187 if (descriptor.function_mode() == NOT_JS_FUNCTION_STUB_MODE) { | 187 if (descriptor.function_mode() == NOT_JS_FUNCTION_STUB_MODE) { |
| 188 parameter_count_--; | 188 parameter_count_--; |
| 189 } | 189 } |
| 190 } | 190 } |
| 191 } | 191 } |
| 192 | 192 |
| 193 | 193 |
| 194 CompilationInfo::~CompilationInfo() { | 194 CompilationInfo::~CompilationInfo() { |
| 195 DisableFutureOptimization(); | 195 DisableFutureOptimization(); |
| 196 delete deferred_handles_; | 196 delete deferred_handles_; |
| 197 delete no_frame_ranges_; | 197 delete no_frame_ranges_; |
| 198 #ifdef DEBUG | 198 #ifdef DEBUG |
| 199 // Check that no dependent maps have been added or added dependent maps have | 199 // Check that no dependent maps have been added or added dependent maps have |
| 200 // been rolled back or committed. | 200 // been rolled back or committed. |
| 201 DCHECK(dependencies()->IsEmpty()); | 201 DCHECK(dependencies()->IsEmpty()); |
| 202 #endif // DEBUG | 202 #endif // DEBUG |
| 203 } | 203 } |
| 204 | 204 |
| 205 | 205 |
| 206 void CompilationInfo::SetStub(CodeStub* code_stub) { | 206 void CompilationInfo::SetStub(CodeStub* code_stub) { |
| 207 SetMode(STUB); | 207 SetMode(STUB); |
| 208 code_stub_ = code_stub; | 208 code_stub_ = code_stub; |
| 209 code_stub_debug_name_ = CodeStub::MajorName(code_stub->MajorKey()); | 209 debug_name_ = CodeStub::MajorName(code_stub->MajorKey()); |
| 210 } | 210 } |
| 211 | 211 |
| 212 | 212 |
| 213 int CompilationInfo::num_parameters() const { | 213 int CompilationInfo::num_parameters() const { |
| 214 return has_scope() ? scope()->num_parameters() : parameter_count_; | 214 return has_scope() ? scope()->num_parameters() : parameter_count_; |
| 215 } | 215 } |
| 216 | 216 |
| 217 | 217 |
| 218 int CompilationInfo::num_parameters_including_this() const { | 218 int CompilationInfo::num_parameters_including_this() const { |
| 219 return num_parameters() + (is_this_defined() ? 1 : 0); | 219 return num_parameters() + (is_this_defined() ? 1 : 0); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 | 304 |
| 305 | 305 |
| 306 void CompilationInfo::LogDeoptCallPosition(int pc_offset, int inlining_id) { | 306 void CompilationInfo::LogDeoptCallPosition(int pc_offset, int inlining_id) { |
| 307 if (!track_positions_ || IsStub()) return; | 307 if (!track_positions_ || IsStub()) return; |
| 308 DCHECK_LT(static_cast<size_t>(inlining_id), inlined_function_infos_.size()); | 308 DCHECK_LT(static_cast<size_t>(inlining_id), inlined_function_infos_.size()); |
| 309 inlined_function_infos_.at(inlining_id).deopt_pc_offsets.push_back(pc_offset); | 309 inlined_function_infos_.at(inlining_id).deopt_pc_offsets.push_back(pc_offset); |
| 310 } | 310 } |
| 311 | 311 |
| 312 | 312 |
| 313 base::SmartArrayPointer<char> CompilationInfo::GetDebugName() const { | 313 base::SmartArrayPointer<char> CompilationInfo::GetDebugName() const { |
| 314 if (IsStub()) { | 314 if (parse_info()) { |
| 315 size_t len = strlen(code_stub_debug_name_) + 1; | |
| 316 base::SmartArrayPointer<char> name(new char[len]); | |
| 317 memcpy(name.get(), code_stub_debug_name_, len); | |
| 318 return name; | |
| 319 } else { | |
| 320 AllowHandleDereference allow_deref; | 315 AllowHandleDereference allow_deref; |
| 321 return literal()->debug_name()->ToCString(); | 316 return parse_info()->literal()->debug_name()->ToCString(); |
| 322 } | 317 } |
| 318 const char* str = debug_name_ ? debug_name_ : "unknown"; |
| 319 size_t len = strlen(str) + 1; |
| 320 base::SmartArrayPointer<char> name(new char[len]); |
| 321 memcpy(name.get(), str, len); |
| 322 return name; |
| 323 } | 323 } |
| 324 | 324 |
| 325 | 325 |
| 326 bool CompilationInfo::MustReplaceUndefinedReceiverWithGlobalProxy() { | 326 bool CompilationInfo::MustReplaceUndefinedReceiverWithGlobalProxy() { |
| 327 return is_sloppy(language_mode()) && !is_native() && | 327 return is_sloppy(language_mode()) && !is_native() && |
| 328 scope()->has_this_declaration() && scope()->receiver()->is_used(); | 328 scope()->has_this_declaration() && scope()->receiver()->is_used(); |
| 329 } | 329 } |
| 330 | 330 |
| 331 | 331 |
| 332 class HOptimizedGraphBuilderWithPositions: public HOptimizedGraphBuilder { | 332 class HOptimizedGraphBuilderWithPositions: public HOptimizedGraphBuilder { |
| (...skipping 1419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1752 } | 1752 } |
| 1753 | 1753 |
| 1754 #if DEBUG | 1754 #if DEBUG |
| 1755 void CompilationInfo::PrintAstForTesting() { | 1755 void CompilationInfo::PrintAstForTesting() { |
| 1756 PrintF("--- Source from AST ---\n%s\n", | 1756 PrintF("--- Source from AST ---\n%s\n", |
| 1757 PrettyPrinter(isolate(), zone()).PrintProgram(literal())); | 1757 PrettyPrinter(isolate(), zone()).PrintProgram(literal())); |
| 1758 } | 1758 } |
| 1759 #endif | 1759 #endif |
| 1760 } // namespace internal | 1760 } // namespace internal |
| 1761 } // namespace v8 | 1761 } // namespace v8 |
| OLD | NEW |