| 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/ast-numbering.h" | 9 #include "src/ast/ast-numbering.h" |
| 10 #include "src/ast/prettyprinter.h" | 10 #include "src/ast/prettyprinter.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 | 113 |
| 114 // ---------------------------------------------------------------------------- | 114 // ---------------------------------------------------------------------------- |
| 115 // Implementation of CompilationInfo | 115 // Implementation of CompilationInfo |
| 116 | 116 |
| 117 bool CompilationInfo::has_shared_info() const { | 117 bool CompilationInfo::has_shared_info() const { |
| 118 return parse_info_ && !parse_info_->shared_info().is_null(); | 118 return parse_info_ && !parse_info_->shared_info().is_null(); |
| 119 } | 119 } |
| 120 | 120 |
| 121 CompilationInfo::CompilationInfo(ParseInfo* parse_info, | 121 CompilationInfo::CompilationInfo(ParseInfo* parse_info, |
| 122 Handle<JSFunction> closure) | 122 Handle<JSFunction> closure) |
| 123 : CompilationInfo(parse_info, nullptr, Code::ComputeFlags(Code::FUNCTION), | 123 : CompilationInfo(parse_info, {}, Code::ComputeFlags(Code::FUNCTION), BASE, |
| 124 BASE, parse_info->isolate(), parse_info->zone()) { | 124 parse_info->isolate(), parse_info->zone()) { |
| 125 closure_ = closure; | 125 closure_ = closure; |
| 126 | 126 |
| 127 // Compiling for the snapshot typically results in different code than | 127 // Compiling for the snapshot typically results in different code than |
| 128 // compiling later on. This means that code recompiled with deoptimization | 128 // compiling later on. This means that code recompiled with deoptimization |
| 129 // support won't be "equivalent" (as defined by SharedFunctionInfo:: | 129 // support won't be "equivalent" (as defined by SharedFunctionInfo:: |
| 130 // EnableDeoptimizationSupport), so it will replace the old code and all | 130 // EnableDeoptimizationSupport), so it will replace the old code and all |
| 131 // its type feedback. To avoid this, always compile functions in the snapshot | 131 // its type feedback. To avoid this, always compile functions in the snapshot |
| 132 // with deoptimization support. | 132 // with deoptimization support. |
| 133 if (isolate_->serializer_enabled()) EnableDeoptimizationSupport(); | 133 if (isolate_->serializer_enabled()) EnableDeoptimizationSupport(); |
| 134 | 134 |
| 135 if (FLAG_function_context_specialization) MarkAsFunctionContextSpecializing(); | 135 if (FLAG_function_context_specialization) MarkAsFunctionContextSpecializing(); |
| 136 if (FLAG_turbo_inlining) MarkAsInliningEnabled(); | 136 if (FLAG_turbo_inlining) MarkAsInliningEnabled(); |
| 137 if (FLAG_turbo_source_positions) MarkAsSourcePositionsEnabled(); | 137 if (FLAG_turbo_source_positions) MarkAsSourcePositionsEnabled(); |
| 138 if (FLAG_turbo_splitting) MarkAsSplittingEnabled(); | 138 if (FLAG_turbo_splitting) MarkAsSplittingEnabled(); |
| 139 } | 139 } |
| 140 | 140 |
| 141 CompilationInfo::CompilationInfo(Vector<const char> function_name, |
| 142 Isolate* isolate, Zone* zone, |
| 143 Code::Flags code_flags) |
| 144 : CompilationInfo(nullptr, function_name, code_flags, STUB, isolate, zone) { |
| 145 } |
| 141 | 146 |
| 142 CompilationInfo::CompilationInfo(const char* debug_name, Isolate* isolate, | 147 CompilationInfo::CompilationInfo(ParseInfo* parse_info, |
| 143 Zone* zone, Code::Flags code_flags) | 148 Vector<const char> function_name, |
| 144 : CompilationInfo(nullptr, debug_name, code_flags, STUB, isolate, zone) {} | |
| 145 | |
| 146 CompilationInfo::CompilationInfo(ParseInfo* parse_info, const char* debug_name, | |
| 147 Code::Flags code_flags, Mode mode, | 149 Code::Flags code_flags, Mode mode, |
| 148 Isolate* isolate, Zone* zone) | 150 Isolate* isolate, Zone* zone) |
| 149 : parse_info_(parse_info), | 151 : parse_info_(parse_info), |
| 150 isolate_(isolate), | 152 isolate_(isolate), |
| 151 flags_(0), | 153 flags_(0), |
| 152 code_flags_(code_flags), | 154 code_flags_(code_flags), |
| 153 mode_(mode), | 155 mode_(mode), |
| 154 osr_ast_id_(BailoutId::None()), | 156 osr_ast_id_(BailoutId::None()), |
| 155 zone_(zone), | 157 zone_(zone), |
| 156 deferred_handles_(nullptr), | 158 deferred_handles_(nullptr), |
| 157 dependencies_(isolate, zone), | 159 dependencies_(isolate, zone), |
| 158 bailout_reason_(kNoReason), | 160 bailout_reason_(kNoReason), |
| 159 prologue_offset_(Code::kPrologueOffsetNotSet), | 161 prologue_offset_(Code::kPrologueOffsetNotSet), |
| 160 track_positions_(FLAG_hydrogen_track_positions || | 162 track_positions_(FLAG_hydrogen_track_positions || |
| 161 isolate->cpu_profiler()->is_profiling()), | 163 isolate->cpu_profiler()->is_profiling()), |
| 162 parameter_count_(0), | 164 parameter_count_(0), |
| 163 optimization_id_(-1), | 165 optimization_id_(-1), |
| 164 osr_expr_stack_height_(0), | 166 osr_expr_stack_height_(0), |
| 165 debug_name_(debug_name) {} | 167 function_name_(function_name) {} |
| 166 | |
| 167 | 168 |
| 168 CompilationInfo::~CompilationInfo() { | 169 CompilationInfo::~CompilationInfo() { |
| 169 DisableFutureOptimization(); | 170 DisableFutureOptimization(); |
| 170 delete deferred_handles_; | 171 delete deferred_handles_; |
| 171 #ifdef DEBUG | 172 #ifdef DEBUG |
| 172 // Check that no dependent maps have been added or added dependent maps have | 173 // Check that no dependent maps have been added or added dependent maps have |
| 173 // been rolled back or committed. | 174 // been rolled back or committed. |
| 174 DCHECK(dependencies()->IsEmpty()); | 175 DCHECK(dependencies()->IsEmpty()); |
| 175 #endif // DEBUG | 176 #endif // DEBUG |
| 176 } | 177 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 | 261 |
| 261 | 262 |
| 262 base::SmartArrayPointer<char> CompilationInfo::GetDebugName() const { | 263 base::SmartArrayPointer<char> CompilationInfo::GetDebugName() const { |
| 263 if (parse_info() && parse_info()->literal()) { | 264 if (parse_info() && parse_info()->literal()) { |
| 264 AllowHandleDereference allow_deref; | 265 AllowHandleDereference allow_deref; |
| 265 return parse_info()->literal()->debug_name()->ToCString(); | 266 return parse_info()->literal()->debug_name()->ToCString(); |
| 266 } | 267 } |
| 267 if (parse_info() && !parse_info()->shared_info().is_null()) { | 268 if (parse_info() && !parse_info()->shared_info().is_null()) { |
| 268 return parse_info()->shared_info()->DebugName()->ToCString(); | 269 return parse_info()->shared_info()->DebugName()->ToCString(); |
| 269 } | 270 } |
| 270 const char* str = debug_name_ ? debug_name_ : "unknown"; | 271 Vector<const char> name_vec = GetFunctionName(); |
| 271 size_t len = strlen(str) + 1; | 272 if (name_vec.is_empty()) name_vec = ArrayVector("unknown"); |
| 272 base::SmartArrayPointer<char> name(new char[len]); | 273 base::SmartArrayPointer<char> name(new char[name_vec.length() + 1]); |
| 273 memcpy(name.get(), str, len); | 274 memcpy(name.get(), name_vec.start(), name_vec.length()); |
| 275 name[name_vec.length()] = '\0'; |
| 274 return name; | 276 return name; |
| 275 } | 277 } |
| 276 | 278 |
| 277 StackFrame::Type CompilationInfo::GetOutputStackFrameType() const { | 279 StackFrame::Type CompilationInfo::GetOutputStackFrameType() const { |
| 278 switch (output_code_kind()) { | 280 switch (output_code_kind()) { |
| 279 case Code::STUB: | 281 case Code::STUB: |
| 280 case Code::BYTECODE_HANDLER: | 282 case Code::BYTECODE_HANDLER: |
| 281 case Code::HANDLER: | 283 case Code::HANDLER: |
| 282 case Code::BUILTIN: | 284 case Code::BUILTIN: |
| 283 return StackFrame::STUB; | 285 return StackFrame::STUB; |
| (...skipping 1393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1677 MaybeHandle<Code> code; | 1679 MaybeHandle<Code> code; |
| 1678 if (cached.code != nullptr) code = handle(cached.code); | 1680 if (cached.code != nullptr) code = handle(cached.code); |
| 1679 Handle<Context> native_context(function->context()->native_context()); | 1681 Handle<Context> native_context(function->context()->native_context()); |
| 1680 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, | 1682 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, |
| 1681 literals, BailoutId::None()); | 1683 literals, BailoutId::None()); |
| 1682 } | 1684 } |
| 1683 } | 1685 } |
| 1684 | 1686 |
| 1685 } // namespace internal | 1687 } // namespace internal |
| 1686 } // namespace v8 | 1688 } // namespace v8 |
| OLD | NEW |