OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 script_(Handle<Script>(Script::cast(shared_info_->script()))), | 88 script_(Handle<Script>(Script::cast(shared_info_->script()))), |
89 extension_(NULL), | 89 extension_(NULL), |
90 pre_parse_data_(NULL), | 90 pre_parse_data_(NULL), |
91 supports_deoptimization_(false), | 91 supports_deoptimization_(false), |
92 osr_ast_id_(AstNode::kNoNumber) { | 92 osr_ast_id_(AstNode::kNoNumber) { |
93 Initialize(BASE); | 93 Initialize(BASE); |
94 } | 94 } |
95 | 95 |
96 | 96 |
97 void CompilationInfo::DisableOptimization() { | 97 void CompilationInfo::DisableOptimization() { |
98 if (FLAG_optimize_closures) { | 98 bool is_optimizable_closure = |
99 // If we allow closures optimizations and it's an optimizable closure | 99 FLAG_optimize_closures && |
100 // mark it correspondingly. | 100 closure_.is_null() && |
101 bool is_closure = closure_.is_null() && !scope_->HasTrivialOuterContext(); | 101 !scope_->HasTrivialOuterContext() && |
102 if (is_closure) { | 102 !scope_->outer_scope_calls_eval() && |
103 bool is_optimizable_closure = | 103 !scope_->inside_with(); |
104 !scope_->outer_scope_calls_eval() && !scope_->inside_with(); | 104 SetMode(is_optimizable_closure ? BASE : NONOPT); |
105 if (is_optimizable_closure) { | |
106 SetMode(BASE); | |
107 return; | |
108 } | |
109 } | |
110 } | |
111 | |
112 SetMode(NONOPT); | |
113 } | 105 } |
114 | 106 |
115 | 107 |
116 // Determine whether to use the full compiler for all code. If the flag | 108 // Determine whether to use the full compiler for all code. If the flag |
117 // --always-full-compiler is specified this is the case. For the virtual frame | 109 // --always-full-compiler is specified this is the case. For the virtual frame |
118 // based compiler the full compiler is also used if a debugger is connected, as | 110 // based compiler the full compiler is also used if a debugger is connected, as |
119 // the code from the full compiler supports mode precise break points. For the | 111 // the code from the full compiler supports mode precise break points. For the |
120 // crankshaft adaptive compiler debugging the optimized code is not possible at | 112 // crankshaft adaptive compiler debugging the optimized code is not possible at |
121 // all. However crankshaft support recompilation of functions, so in this case | 113 // all. However crankshaft support recompilation of functions, so in this case |
122 // the full compiler need not be be used if a debugger is attached, but only if | 114 // the full compiler need not be be used if a debugger is attached, but only if |
123 // break points has actually been set. | 115 // break points has actually been set. |
124 static bool AlwaysFullCompiler() { | 116 static bool is_debugging_active() { |
Kevin Millikin (Chromium)
2011/05/06 10:51:31
I prefer debugging_is_active as a name, but I don'
Sven Panne
2011/05/06 11:01:06
I don't have very strong feelings about this, eith
| |
125 #ifdef ENABLE_DEBUGGER_SUPPORT | 117 #ifdef ENABLE_DEBUGGER_SUPPORT |
126 Isolate* isolate = Isolate::Current(); | 118 Isolate* isolate = Isolate::Current(); |
127 if (V8::UseCrankshaft()) { | 119 return V8::UseCrankshaft() ? |
128 return FLAG_always_full_compiler || isolate->debug()->has_break_points(); | 120 isolate->debug()->has_break_points() : |
129 } else { | 121 isolate->debugger()->IsDebuggerActive(); |
130 return FLAG_always_full_compiler || isolate->debugger()->IsDebuggerActive(); | |
131 } | |
132 #else | 122 #else |
133 return FLAG_always_full_compiler; | 123 return false; |
134 #endif | 124 #endif |
135 } | 125 } |
136 | 126 |
137 | 127 |
128 static bool AlwaysFullCompiler() { | |
129 return FLAG_always_full_compiler || is_debugging_active(); | |
130 } | |
131 | |
132 | |
138 static void FinishOptimization(Handle<JSFunction> function, int64_t start) { | 133 static void FinishOptimization(Handle<JSFunction> function, int64_t start) { |
139 int opt_count = function->shared()->opt_count(); | 134 int opt_count = function->shared()->opt_count(); |
140 function->shared()->set_opt_count(opt_count + 1); | 135 function->shared()->set_opt_count(opt_count + 1); |
141 double ms = static_cast<double>(OS::Ticks() - start) / 1000; | 136 double ms = static_cast<double>(OS::Ticks() - start) / 1000; |
142 if (FLAG_trace_opt) { | 137 if (FLAG_trace_opt) { |
143 PrintF("[optimizing: "); | 138 PrintF("[optimizing: "); |
144 function->PrintName(); | 139 function->PrintName(); |
145 PrintF(" / %" V8PRIxPTR, reinterpret_cast<intptr_t>(*function)); | 140 PrintF(" / %" V8PRIxPTR, reinterpret_cast<intptr_t>(*function)); |
146 PrintF(" - took %0.3f ms]\n", ms); | 141 PrintF(" - took %0.3f ms]\n", ms); |
147 } | 142 } |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
311 | 306 |
312 // Compilation with the Hydrogen compiler failed. Keep using the | 307 // Compilation with the Hydrogen compiler failed. Keep using the |
313 // shared code but mark it as unoptimizable. | 308 // shared code but mark it as unoptimizable. |
314 AbortAndDisable(info); | 309 AbortAndDisable(info); |
315 // True indicates the compilation pipeline is still going, not necessarily | 310 // True indicates the compilation pipeline is still going, not necessarily |
316 // that we optimized the code. | 311 // that we optimized the code. |
317 return true; | 312 return true; |
318 } | 313 } |
319 | 314 |
320 | 315 |
316 static bool GenerateCode(CompilationInfo* info) { | |
317 return V8::UseCrankshaft() ? | |
318 MakeCrankshaftCode(info) : | |
319 FullCodeGenerator::MakeCode(info); | |
320 } | |
321 | |
322 | |
321 static bool MakeCode(CompilationInfo* info) { | 323 static bool MakeCode(CompilationInfo* info) { |
322 // Precondition: code has been parsed. Postcondition: the code field in | 324 // Precondition: code has been parsed. Postcondition: the code field in |
323 // the compilation info is set if compilation succeeded. | 325 // the compilation info is set if compilation succeeded. |
324 ASSERT(info->function() != NULL); | 326 ASSERT(info->function() != NULL); |
325 | 327 return Rewriter::Rewrite(info) && Scope::Analyze(info) && GenerateCode(info); |
326 if (Rewriter::Rewrite(info) && Scope::Analyze(info)) { | |
327 if (V8::UseCrankshaft()) return MakeCrankshaftCode(info); | |
328 // If crankshaft is not supported fall back to full code generator | |
329 // for all compilation. | |
330 return FullCodeGenerator::MakeCode(info); | |
331 } | |
332 | |
333 return false; | |
334 } | 328 } |
335 | 329 |
336 | 330 |
337 #ifdef ENABLE_DEBUGGER_SUPPORT | 331 #ifdef ENABLE_DEBUGGER_SUPPORT |
338 bool Compiler::MakeCodeForLiveEdit(CompilationInfo* info) { | 332 bool Compiler::MakeCodeForLiveEdit(CompilationInfo* info) { |
339 // Precondition: code has been parsed. Postcondition: the code field in | 333 // Precondition: code has been parsed. Postcondition: the code field in |
340 // the compilation info is set if compilation succeeded. | 334 // the compilation info is set if compilation succeeded. |
341 bool succeeded = MakeCode(info); | 335 bool succeeded = MakeCode(info); |
342 if (!info->shared_info().is_null()) { | 336 if (!info->shared_info().is_null()) { |
343 Handle<SerializedScopeInfo> scope_info = | 337 Handle<SerializedScopeInfo> scope_info = |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
789 shared->DebugName())); | 783 shared->DebugName())); |
790 } | 784 } |
791 } | 785 } |
792 | 786 |
793 GDBJIT(AddCode(Handle<String>(shared->DebugName()), | 787 GDBJIT(AddCode(Handle<String>(shared->DebugName()), |
794 Handle<Script>(info->script()), | 788 Handle<Script>(info->script()), |
795 Handle<Code>(info->code()))); | 789 Handle<Code>(info->code()))); |
796 } | 790 } |
797 | 791 |
798 } } // namespace v8::internal | 792 } } // namespace v8::internal |
OLD | NEW |