svenpanne@chromium.org | b1df11d | 2012-02-08 10:26:21 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #include "v8.h" |
| 29 | |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 30 | #include "compiler.h" |
| 31 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 32 | #include "bootstrapper.h" |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 33 | #include "codegen.h" |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 34 | #include "compilation-cache.h" |
machenbach@chromium.org | c1789ee | 2013-07-05 07:09:57 +0000 | [diff] [blame] | 35 | #include "cpu-profiler.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 36 | #include "debug.h" |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 37 | #include "deoptimizer.h" |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 38 | #include "full-codegen.h" |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 39 | #include "gdb-jit.h" |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 40 | #include "typing.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 41 | #include "hydrogen.h" |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 42 | #include "isolate-inl.h" |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 43 | #include "lithium.h" |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 44 | #include "liveedit.h" |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 45 | #include "parser.h" |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 46 | #include "rewriter.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 47 | #include "runtime-profiler.h" |
ricow@chromium.org | 55ee807 | 2011-09-08 16:33:10 +0000 | [diff] [blame] | 48 | #include "scanner-character-streams.h" |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 49 | #include "scopeinfo.h" |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 50 | #include "scopes.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 51 | #include "vm-state-inl.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 52 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 53 | namespace v8 { |
| 54 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 55 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 56 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 57 | CompilationInfo::CompilationInfo(Handle<Script> script, |
| 58 | Zone* zone) |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 59 | : flags_(LanguageModeField::encode(CLASSIC_MODE)), |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 60 | script_(script), |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 61 | osr_ast_id_(BailoutId::None()) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 62 | Initialize(script->GetIsolate(), BASE, zone); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 66 | CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info, |
| 67 | Zone* zone) |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 68 | : flags_(LanguageModeField::encode(CLASSIC_MODE) | IsLazy::encode(true)), |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 69 | shared_info_(shared_info), |
| 70 | script_(Handle<Script>(Script::cast(shared_info->script()))), |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 71 | osr_ast_id_(BailoutId::None()) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 72 | Initialize(script_->GetIsolate(), BASE, zone); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 76 | CompilationInfo::CompilationInfo(Handle<JSFunction> closure, |
| 77 | Zone* zone) |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 78 | : flags_(LanguageModeField::encode(CLASSIC_MODE) | IsLazy::encode(true)), |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 79 | closure_(closure), |
| 80 | shared_info_(Handle<SharedFunctionInfo>(closure->shared())), |
| 81 | script_(Handle<Script>(Script::cast(shared_info_->script()))), |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 82 | context_(closure->context()), |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 83 | osr_ast_id_(BailoutId::None()) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 84 | Initialize(script_->GetIsolate(), BASE, zone); |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 88 | CompilationInfo::CompilationInfo(HydrogenCodeStub* stub, |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 89 | Isolate* isolate, |
| 90 | Zone* zone) |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 91 | : flags_(LanguageModeField::encode(CLASSIC_MODE) | |
| 92 | IsLazy::encode(true)), |
| 93 | osr_ast_id_(BailoutId::None()) { |
| 94 | Initialize(isolate, STUB, zone); |
| 95 | code_stub_ = stub; |
| 96 | } |
| 97 | |
| 98 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 99 | void CompilationInfo::Initialize(Isolate* isolate, |
| 100 | Mode mode, |
| 101 | Zone* zone) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 102 | isolate_ = isolate; |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 103 | function_ = NULL; |
| 104 | scope_ = NULL; |
| 105 | global_scope_ = NULL; |
| 106 | extension_ = NULL; |
| 107 | pre_parse_data_ = NULL; |
| 108 | zone_ = zone; |
| 109 | deferred_handles_ = NULL; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 110 | code_stub_ = NULL; |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 111 | prologue_offset_ = kPrologueOffsetNotSet; |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 112 | opt_count_ = shared_info().is_null() ? 0 : shared_info()->opt_count(); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 113 | no_frame_ranges_ = isolate->cpu_profiler()->is_profiling() |
| 114 | ? new List<OffsetRange>(2) : NULL; |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 115 | for (int i = 0; i < DependentCode::kGroupCount; i++) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 116 | dependencies_[i] = NULL; |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 117 | } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 118 | if (mode == STUB) { |
| 119 | mode_ = STUB; |
| 120 | return; |
| 121 | } |
| 122 | mode_ = V8::UseCrankshaft() ? mode : NONOPT; |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 123 | abort_due_to_dependency_ = false; |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 124 | if (script_->type()->value() == Script::TYPE_NATIVE) { |
| 125 | MarkAsNative(); |
| 126 | } |
| 127 | if (!shared_info_.is_null()) { |
| 128 | ASSERT(language_mode() == CLASSIC_MODE); |
| 129 | SetLanguageMode(shared_info_->language_mode()); |
| 130 | } |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 131 | set_bailout_reason(kUnknown); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 135 | CompilationInfo::~CompilationInfo() { |
| 136 | delete deferred_handles_; |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 137 | delete no_frame_ranges_; |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 138 | #ifdef DEBUG |
| 139 | // Check that no dependent maps have been added or added dependent maps have |
| 140 | // been rolled back or committed. |
| 141 | for (int i = 0; i < DependentCode::kGroupCount; i++) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 142 | ASSERT_EQ(NULL, dependencies_[i]); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 143 | } |
| 144 | #endif // DEBUG |
| 145 | } |
| 146 | |
| 147 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 148 | void CompilationInfo::CommitDependencies(Handle<Code> code) { |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 149 | for (int i = 0; i < DependentCode::kGroupCount; i++) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 150 | ZoneList<Handle<HeapObject> >* group_objects = dependencies_[i]; |
| 151 | if (group_objects == NULL) continue; |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 152 | ASSERT(!object_wrapper_.is_null()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 153 | for (int j = 0; j < group_objects->length(); j++) { |
| 154 | DependentCode::DependencyGroup group = |
| 155 | static_cast<DependentCode::DependencyGroup>(i); |
| 156 | DependentCode* dependent_code = |
| 157 | DependentCode::ForObject(group_objects->at(j), group); |
| 158 | dependent_code->UpdateToFinishedCode(group, this, *code); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 159 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 160 | dependencies_[i] = NULL; // Zone-allocated, no need to delete. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 161 | } |
| 162 | } |
| 163 | |
| 164 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 165 | void CompilationInfo::RollbackDependencies() { |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 166 | // Unregister from all dependent maps if not yet committed. |
| 167 | for (int i = 0; i < DependentCode::kGroupCount; i++) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 168 | ZoneList<Handle<HeapObject> >* group_objects = dependencies_[i]; |
| 169 | if (group_objects == NULL) continue; |
| 170 | for (int j = 0; j < group_objects->length(); j++) { |
| 171 | DependentCode::DependencyGroup group = |
| 172 | static_cast<DependentCode::DependencyGroup>(i); |
| 173 | DependentCode* dependent_code = |
| 174 | DependentCode::ForObject(group_objects->at(j), group); |
| 175 | dependent_code->RemoveCompilationInfo(group, this); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 176 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 177 | dependencies_[i] = NULL; // Zone-allocated, no need to delete. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 178 | } |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 182 | int CompilationInfo::num_parameters() const { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 183 | ASSERT(!IsStub()); |
| 184 | return scope()->num_parameters(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | |
| 188 | int CompilationInfo::num_heap_slots() const { |
| 189 | if (IsStub()) { |
| 190 | return 0; |
| 191 | } else { |
| 192 | return scope()->num_heap_slots(); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | |
| 197 | Code::Flags CompilationInfo::flags() const { |
| 198 | if (IsStub()) { |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 199 | return Code::ComputeFlags(code_stub()->GetCodeKind(), |
| 200 | code_stub()->GetICState(), |
| 201 | code_stub()->GetExtraICState(), |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 202 | code_stub()->GetStubType(), |
| 203 | code_stub()->GetStubFlags()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 204 | } else { |
| 205 | return Code::ComputeFlags(Code::OPTIMIZED_FUNCTION); |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 210 | // Disable optimization for the rest of the compilation pipeline. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 211 | void CompilationInfo::DisableOptimization() { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 212 | bool is_optimizable_closure = |
| 213 | FLAG_optimize_closures && |
| 214 | closure_.is_null() && |
| 215 | !scope_->HasTrivialOuterContext() && |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 216 | !scope_->outer_scope_calls_non_strict_eval() && |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 217 | !scope_->inside_with(); |
| 218 | SetMode(is_optimizable_closure ? BASE : NONOPT); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 222 | // Primitive functions are unlikely to be picked up by the stack-walking |
| 223 | // profiler, so they trigger their own optimization when they're called |
| 224 | // for the SharedFunctionInfo::kCallsUntilPrimitiveOptimization-th time. |
| 225 | bool CompilationInfo::ShouldSelfOptimize() { |
| 226 | return FLAG_self_optimization && |
| 227 | FLAG_crankshaft && |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 228 | !function()->flags()->Contains(kDontSelfOptimize) && |
yangguo@chromium.org | a7d3df9 | 2012-02-27 11:46:55 +0000 | [diff] [blame] | 229 | !function()->flags()->Contains(kDontOptimize) && |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 230 | function()->scope()->AllowsLazyCompilation() && |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 231 | (shared_info().is_null() || !shared_info()->optimization_disabled()); |
| 232 | } |
| 233 | |
| 234 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 235 | // Determine whether to use the full compiler for all code. If the flag |
| 236 | // --always-full-compiler is specified this is the case. For the virtual frame |
| 237 | // based compiler the full compiler is also used if a debugger is connected, as |
| 238 | // the code from the full compiler supports mode precise break points. For the |
| 239 | // crankshaft adaptive compiler debugging the optimized code is not possible at |
| 240 | // all. However crankshaft support recompilation of functions, so in this case |
| 241 | // the full compiler need not be be used if a debugger is attached, but only if |
| 242 | // break points has actually been set. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 243 | static bool IsDebuggerActive(Isolate* isolate) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 244 | #ifdef ENABLE_DEBUGGER_SUPPORT |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 245 | return V8::UseCrankshaft() ? |
| 246 | isolate->debug()->has_break_points() : |
| 247 | isolate->debugger()->IsDebuggerActive(); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 248 | #else |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 249 | return false; |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 250 | #endif |
| 251 | } |
| 252 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 253 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 254 | static bool AlwaysFullCompiler(Isolate* isolate) { |
| 255 | return FLAG_always_full_compiler || IsDebuggerActive(isolate); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 259 | void OptimizingCompiler::RecordOptimizationStats() { |
| 260 | Handle<JSFunction> function = info()->closure(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 261 | int opt_count = function->shared()->opt_count(); |
| 262 | function->shared()->set_opt_count(opt_count + 1); |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 263 | double ms_creategraph = |
| 264 | static_cast<double>(time_taken_to_create_graph_) / 1000; |
| 265 | double ms_optimize = static_cast<double>(time_taken_to_optimize_) / 1000; |
| 266 | double ms_codegen = static_cast<double>(time_taken_to_codegen_) / 1000; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 267 | if (FLAG_trace_opt) { |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 268 | PrintF("[optimizing "); |
| 269 | function->ShortPrint(); |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 270 | PrintF(" - took %0.3f, %0.3f, %0.3f ms]\n", ms_creategraph, ms_optimize, |
| 271 | ms_codegen); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 272 | } |
| 273 | if (FLAG_trace_opt_stats) { |
| 274 | static double compilation_time = 0.0; |
| 275 | static int compiled_functions = 0; |
| 276 | static int code_size = 0; |
| 277 | |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 278 | compilation_time += (ms_creategraph + ms_optimize + ms_codegen); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 279 | compiled_functions++; |
| 280 | code_size += function->shared()->SourceSize(); |
| 281 | PrintF("Compiled: %d functions with %d byte source size in %fms.\n", |
| 282 | compiled_functions, |
| 283 | code_size, |
| 284 | compilation_time); |
| 285 | } |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 286 | if (FLAG_hydrogen_stats) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 287 | isolate()->GetHStatistics()->IncrementSubtotals(time_taken_to_create_graph_, |
| 288 | time_taken_to_optimize_, |
| 289 | time_taken_to_codegen_); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 290 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 294 | // A return value of true indicates the compilation pipeline is still |
| 295 | // going, not necessarily that we optimized the code. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 296 | static bool MakeCrankshaftCode(CompilationInfo* info) { |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 297 | OptimizingCompiler compiler(info); |
| 298 | OptimizingCompiler::Status status = compiler.CreateGraph(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 299 | |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 300 | if (status != OptimizingCompiler::SUCCEEDED) { |
| 301 | return status != OptimizingCompiler::FAILED; |
| 302 | } |
| 303 | status = compiler.OptimizeGraph(); |
| 304 | if (status != OptimizingCompiler::SUCCEEDED) { |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 305 | status = compiler.AbortOptimization(); |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 306 | return status != OptimizingCompiler::FAILED; |
| 307 | } |
| 308 | status = compiler.GenerateAndInstallCode(); |
| 309 | return status != OptimizingCompiler::FAILED; |
| 310 | } |
| 311 | |
| 312 | |
| 313 | OptimizingCompiler::Status OptimizingCompiler::CreateGraph() { |
| 314 | ASSERT(V8::UseCrankshaft()); |
| 315 | ASSERT(info()->IsOptimizing()); |
| 316 | ASSERT(!info()->IsCompilingForDebugging()); |
| 317 | |
| 318 | // We should never arrive here if there is no code object on the |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 319 | // shared function object. |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 320 | ASSERT(info()->shared_info()->code()->kind() == Code::FUNCTION); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 321 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 322 | // We should never arrive here if optimization has been disabled on the |
| 323 | // shared function info. |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 324 | ASSERT(!info()->shared_info()->optimization_disabled()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 325 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 326 | // Fall back to using the full code generator if it's not possible |
| 327 | // to use the Hydrogen-based optimizing compiler. We already have |
| 328 | // generated code for this from the shared function object. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 329 | if (AlwaysFullCompiler(isolate())) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 330 | info()->AbortOptimization(); |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 331 | return SetLastStatus(BAILED_OUT); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | // Limit the number of times we re-compile a functions with |
| 335 | // the optimizing compiler. |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 336 | const int kMaxOptCount = |
verwaest@chromium.org | de64f72 | 2012-08-16 15:44:54 +0000 | [diff] [blame] | 337 | FLAG_deopt_every_n_times == 0 ? FLAG_max_opt_count : 1000; |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 338 | if (info()->opt_count() > kMaxOptCount) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 339 | info()->set_bailout_reason(kOptimizedTooManyTimes); |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 340 | return AbortOptimization(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | // Due to an encoding limit on LUnallocated operands in the Lithium |
| 344 | // language, we cannot optimize functions with too many formal parameters |
| 345 | // or perform on-stack replacement for function with too many |
| 346 | // stack-allocated local variables. |
| 347 | // |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 348 | // The encoding is as a signed value, with parameters and receiver using |
| 349 | // the negative indices and locals the non-negative ones. |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 350 | const int parameter_limit = -LUnallocated::kMinFixedSlotIndex; |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 351 | Scope* scope = info()->scope(); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 352 | if ((scope->num_parameters() + 1) > parameter_limit) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 353 | info()->set_bailout_reason(kTooManyParameters); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 354 | return AbortOptimization(); |
| 355 | } |
| 356 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 357 | const int locals_limit = LUnallocated::kMaxFixedSlotIndex; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 358 | if (!info()->osr_ast_id().IsNone() && |
| 359 | scope->num_parameters() + 1 + scope->num_stack_slots() > locals_limit) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 360 | info()->set_bailout_reason(kTooManyParametersLocals); |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 361 | return AbortOptimization(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | // Take --hydrogen-filter into account. |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 365 | if (!info()->closure()->PassesFilter(FLAG_hydrogen_filter)) { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 366 | info()->AbortOptimization(); |
| 367 | return SetLastStatus(BAILED_OUT); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | // Recompile the unoptimized version of the code if the current version |
| 371 | // doesn't have deoptimization support. Alternatively, we may decide to |
| 372 | // run the full code generator to get a baseline for the compile-time |
| 373 | // performance of the hydrogen-based compiler. |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 374 | bool should_recompile = !info()->shared_info()->has_deoptimization_support(); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 375 | if (should_recompile || FLAG_hydrogen_stats) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 376 | int64_t start_ticks = 0; |
| 377 | if (FLAG_hydrogen_stats) { |
| 378 | start_ticks = OS::Ticks(); |
| 379 | } |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 380 | CompilationInfoWithZone unoptimized(info()->shared_info()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 381 | // Note that we use the same AST that we will use for generating the |
| 382 | // optimized code. |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 383 | unoptimized.SetFunction(info()->function()); |
| 384 | unoptimized.SetScope(info()->scope()); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 385 | unoptimized.SetContext(info()->context()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 386 | if (should_recompile) unoptimized.EnableDeoptimizationSupport(); |
| 387 | bool succeeded = FullCodeGenerator::MakeCode(&unoptimized); |
| 388 | if (should_recompile) { |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 389 | if (!succeeded) return SetLastStatus(FAILED); |
| 390 | Handle<SharedFunctionInfo> shared = info()->shared_info(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 391 | shared->EnableDeoptimizationSupport(*unoptimized.code()); |
| 392 | // The existing unoptimized code was replaced with the new one. |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 393 | Compiler::RecordFunctionCompilation( |
| 394 | Logger::LAZY_COMPILE_TAG, &unoptimized, shared); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 395 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 396 | if (FLAG_hydrogen_stats) { |
| 397 | int64_t ticks = OS::Ticks() - start_ticks; |
| 398 | isolate()->GetHStatistics()->IncrementFullCodeGen(ticks); |
| 399 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | // Check that the unoptimized, shared code is ready for |
| 403 | // optimizations. When using the always_opt flag we disregard the |
| 404 | // optimizable marker in the code object and optimize anyway. This |
| 405 | // is safe as long as the unoptimized code has deoptimization |
| 406 | // support. |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 407 | ASSERT(FLAG_always_opt || info()->shared_info()->code()->optimizable()); |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 408 | ASSERT(info()->shared_info()->has_deoptimization_support()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 409 | |
| 410 | if (FLAG_trace_hydrogen) { |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 411 | Handle<String> name = info()->function()->debug_name(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 412 | PrintF("-----------------------------------------------------------\n"); |
| 413 | PrintF("Compiling method %s using hydrogen\n", *name->ToCString()); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 414 | isolate()->GetHTracer()->TraceCompilation(info()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 415 | } |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 416 | |
| 417 | // Type-check the function. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 418 | AstTyper::Run(info()); |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 419 | |
| 420 | graph_builder_ = new(info()->zone()) HOptimizedGraphBuilder(info()); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 421 | |
| 422 | Timer t(this, &time_taken_to_create_graph_); |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 423 | graph_ = graph_builder_->CreateGraph(); |
| 424 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 425 | if (isolate()->has_pending_exception()) { |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 426 | info()->SetCode(Handle<Code>::null()); |
| 427 | return SetLastStatus(FAILED); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 428 | } |
| 429 | |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 430 | // The function being compiled may have bailed out due to an inline |
| 431 | // candidate bailing out. In such a case, we don't disable |
| 432 | // optimization on the shared_info. |
| 433 | ASSERT(!graph_builder_->inline_bailout() || graph_ == NULL); |
| 434 | if (graph_ == NULL) { |
| 435 | if (graph_builder_->inline_bailout()) { |
| 436 | info_->AbortOptimization(); |
| 437 | return SetLastStatus(BAILED_OUT); |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 438 | } else { |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 439 | return AbortOptimization(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 440 | } |
| 441 | } |
| 442 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 443 | if (info()->HasAbortedDueToDependencyChange()) { |
| 444 | info_->set_bailout_reason(kBailedOutDueToDependencyChange); |
| 445 | info_->AbortOptimization(); |
| 446 | return SetLastStatus(BAILED_OUT); |
| 447 | } |
| 448 | |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 449 | return SetLastStatus(SUCCEEDED); |
| 450 | } |
| 451 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 452 | |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 453 | OptimizingCompiler::Status OptimizingCompiler::OptimizeGraph() { |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 454 | DisallowHeapAllocation no_allocation; |
| 455 | DisallowHandleAllocation no_handles; |
| 456 | DisallowHandleDereference no_deref; |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 457 | DisallowCodeDependencyChange no_dependency_change; |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 458 | |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 459 | ASSERT(last_status() == SUCCEEDED); |
| 460 | Timer t(this, &time_taken_to_optimize_); |
| 461 | ASSERT(graph_ != NULL); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 462 | BailoutReason bailout_reason = kNoReason; |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 463 | if (!graph_->Optimize(&bailout_reason)) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 464 | if (bailout_reason == kNoReason) graph_builder_->Bailout(bailout_reason); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 465 | return SetLastStatus(BAILED_OUT); |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 466 | } else { |
| 467 | chunk_ = LChunk::NewChunk(graph_); |
| 468 | if (chunk_ == NULL) { |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 469 | return SetLastStatus(BAILED_OUT); |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 470 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 471 | } |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 472 | return SetLastStatus(SUCCEEDED); |
| 473 | } |
| 474 | |
| 475 | |
| 476 | OptimizingCompiler::Status OptimizingCompiler::GenerateAndInstallCode() { |
| 477 | ASSERT(last_status() == SUCCEEDED); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 478 | ASSERT(!info()->HasAbortedDueToDependencyChange()); |
| 479 | DisallowCodeDependencyChange no_dependency_change; |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 480 | { // Scope for timer. |
| 481 | Timer timer(this, &time_taken_to_codegen_); |
| 482 | ASSERT(chunk_ != NULL); |
| 483 | ASSERT(graph_ != NULL); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 484 | // Deferred handles reference objects that were accessible during |
| 485 | // graph creation. To make sure that we don't encounter inconsistencies |
| 486 | // between graph creation and code generation, we disallow accessing |
| 487 | // objects through deferred handles during the latter, with exceptions. |
yangguo@chromium.org | 2030124 | 2013-06-03 16:06:25 +0000 | [diff] [blame] | 488 | DisallowDeferredHandleDereference no_deferred_handle_deref; |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 489 | Handle<Code> optimized_code = chunk_->Codegen(); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 490 | if (optimized_code.is_null()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 491 | if (info()->bailout_reason() == kNoReason) { |
| 492 | info()->set_bailout_reason(kCodeGenerationFailed); |
| 493 | } |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 494 | return AbortOptimization(); |
| 495 | } |
| 496 | info()->SetCode(optimized_code); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 497 | } |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 498 | RecordOptimizationStats(); |
| 499 | return SetLastStatus(SUCCEEDED); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 503 | static bool GenerateCode(CompilationInfo* info) { |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 504 | bool is_optimizing = V8::UseCrankshaft() && |
| 505 | !info->IsCompilingForDebugging() && |
| 506 | info->IsOptimizing(); |
| 507 | if (is_optimizing) { |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 508 | Logger::TimerEventScope timer( |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 509 | info->isolate(), Logger::TimerEventScope::v8_recompile_synchronous); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 510 | return MakeCrankshaftCode(info); |
| 511 | } else { |
| 512 | if (info->IsOptimizing()) { |
| 513 | // Have the CompilationInfo decide if the compilation should be |
| 514 | // BASE or NONOPT. |
| 515 | info->DisableOptimization(); |
| 516 | } |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 517 | Logger::TimerEventScope timer( |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 518 | info->isolate(), Logger::TimerEventScope::v8_compile_full_code); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 519 | return FullCodeGenerator::MakeCode(info); |
| 520 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 524 | static bool MakeCode(CompilationInfo* info) { |
| 525 | // Precondition: code has been parsed. Postcondition: the code field in |
| 526 | // the compilation info is set if compilation succeeded. |
| 527 | ASSERT(info->function() != NULL); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 528 | return Rewriter::Rewrite(info) && Scope::Analyze(info) && GenerateCode(info); |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 532 | #ifdef ENABLE_DEBUGGER_SUPPORT |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 533 | bool Compiler::MakeCodeForLiveEdit(CompilationInfo* info) { |
| 534 | // Precondition: code has been parsed. Postcondition: the code field in |
| 535 | // the compilation info is set if compilation succeeded. |
| 536 | bool succeeded = MakeCode(info); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 537 | if (!info->shared_info().is_null()) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 538 | Handle<ScopeInfo> scope_info = ScopeInfo::Create(info->scope(), |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 539 | info->zone()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 540 | info->shared_info()->set_scope_info(*scope_info); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 541 | } |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 542 | return succeeded; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 543 | } |
| 544 | #endif |
| 545 | |
| 546 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 547 | static bool DebuggerWantsEagerCompilation(CompilationInfo* info, |
| 548 | bool allow_lazy_without_ctx = false) { |
| 549 | return LiveEditFunctionTracker::IsActive(info->isolate()) || |
| 550 | (info->isolate()->DebuggerHasBreakPoints() && !allow_lazy_without_ctx); |
| 551 | } |
| 552 | |
| 553 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 554 | static Handle<SharedFunctionInfo> MakeFunctionInfo(CompilationInfo* info) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 555 | Isolate* isolate = info->isolate(); |
| 556 | PostponeInterruptsScope postpone(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 557 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 558 | ASSERT(!isolate->native_context().is_null()); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 559 | Handle<Script> script = info->script(); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 560 | // TODO(svenpanne) Obscure place for this, perhaps move to OnBeforeCompile? |
| 561 | FixedArray* array = isolate->native_context()->embedder_data(); |
| 562 | script->set_context_data(array->get(0)); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 563 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 564 | #ifdef ENABLE_DEBUGGER_SUPPORT |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 565 | if (info->is_eval()) { |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 566 | script->set_compilation_type(Script::COMPILATION_TYPE_EVAL); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 567 | // For eval scripts add information on the function from which eval was |
| 568 | // called. |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 569 | if (info->is_eval()) { |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 570 | StackTraceFrameIterator it(isolate); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 571 | if (!it.done()) { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 572 | script->set_eval_from_shared(it.frame()->function()->shared()); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 573 | Code* code = it.frame()->LookupCode(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 574 | int offset = static_cast<int>( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 575 | it.frame()->pc() - code->instruction_start()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 576 | script->set_eval_from_instructions_offset(Smi::FromInt(offset)); |
| 577 | } |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 578 | } |
| 579 | } |
| 580 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 581 | // Notify debugger |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 582 | isolate->debugger()->OnBeforeCompile(script); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 583 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 584 | |
| 585 | // Only allow non-global compiles for eval. |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 586 | ASSERT(info->is_eval() || info->is_global()); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 587 | { |
| 588 | Parser parser(info); |
| 589 | if ((info->pre_parse_data() != NULL || |
| 590 | String::cast(script->source())->length() > FLAG_min_preparse_length) && |
| 591 | !DebuggerWantsEagerCompilation(info)) |
| 592 | parser.set_allow_lazy(true); |
| 593 | if (!parser.Parse()) { |
| 594 | return Handle<SharedFunctionInfo>::null(); |
| 595 | } |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 596 | } |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 597 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 598 | // Measure how long it takes to do the compilation; only take the |
| 599 | // rest of the function into account to avoid overlap with the |
| 600 | // parsing statistics. |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 601 | HistogramTimer* rate = info->is_eval() |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 602 | ? info->isolate()->counters()->compile_eval() |
| 603 | : info->isolate()->counters()->compile(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 604 | HistogramTimerScope timer(rate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 605 | |
| 606 | // Compile the code. |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 607 | FunctionLiteral* lit = info->function(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 608 | LiveEditFunctionTracker live_edit_tracker(isolate, lit); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 609 | if (!MakeCode(info)) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 610 | if (!isolate->has_pending_exception()) isolate->StackOverflow(); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 611 | return Handle<SharedFunctionInfo>::null(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 612 | } |
| 613 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 614 | // Allocate function. |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 615 | ASSERT(!info->code().is_null()); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 616 | Handle<SharedFunctionInfo> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 617 | isolate->factory()->NewSharedFunctionInfo( |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 618 | lit->name(), |
| 619 | lit->materialized_literal_count(), |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 620 | lit->is_generator(), |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 621 | info->code(), |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 622 | ScopeInfo::Create(info->scope(), info->zone())); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 623 | |
| 624 | ASSERT_EQ(RelocInfo::kNoPosition, lit->function_token_position()); |
| 625 | Compiler::SetFunctionInfo(result, lit, true, script); |
| 626 | |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 627 | if (script->name()->IsString()) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 628 | PROFILE(isolate, CodeCreateEvent( |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 629 | info->is_eval() |
| 630 | ? Logger::EVAL_TAG |
| 631 | : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script), |
| 632 | *info->code(), |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 633 | *result, |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 634 | info, |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 635 | String::cast(script->name()))); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 636 | GDBJIT(AddCode(Handle<String>(String::cast(script->name())), |
| 637 | script, |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 638 | info->code(), |
| 639 | info)); |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 640 | } else { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 641 | PROFILE(isolate, CodeCreateEvent( |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 642 | info->is_eval() |
| 643 | ? Logger::EVAL_TAG |
| 644 | : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script), |
| 645 | *info->code(), |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 646 | *result, |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 647 | info, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 648 | isolate->heap()->empty_string())); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 649 | GDBJIT(AddCode(Handle<String>(), script, info->code(), info)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 650 | } |
| 651 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 652 | // Hint to the runtime system used when allocating space for initial |
| 653 | // property space by setting the expected number of properties for |
| 654 | // the instances of the function. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 655 | SetExpectedNofPropertiesFromEstimate(result, lit->expected_property_count()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 656 | |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 657 | script->set_compilation_state(Script::COMPILATION_STATE_COMPILED); |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 658 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 659 | #ifdef ENABLE_DEBUGGER_SUPPORT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 660 | // Notify debugger |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 661 | isolate->debugger()->OnAfterCompile( |
| 662 | script, Debugger::NO_AFTER_COMPILE_FLAGS); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 663 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 664 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 665 | live_edit_tracker.RecordFunctionInfo(result, lit, info->zone()); |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 666 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 667 | return result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 671 | Handle<SharedFunctionInfo> Compiler::Compile(Handle<String> source, |
| 672 | Handle<Object> script_name, |
| 673 | int line_offset, |
| 674 | int column_offset, |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 675 | bool is_shared_cross_origin, |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 676 | Handle<Context> context, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 677 | v8::Extension* extension, |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 678 | ScriptDataImpl* pre_data, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 679 | Handle<Object> script_data, |
| 680 | NativesFlag natives) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 681 | Isolate* isolate = source->GetIsolate(); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 682 | int source_length = source->length(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 683 | isolate->counters()->total_load_size()->Increment(source_length); |
| 684 | isolate->counters()->total_compile_size()->Increment(source_length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 685 | |
| 686 | // The VM is in the COMPILER state until exiting this function. |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 687 | VMState<COMPILER> state(isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 688 | |
| 689 | CompilationCache* compilation_cache = isolate->compilation_cache(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 690 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 691 | // Do a lookup in the compilation cache but not for extensions. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 692 | Handle<SharedFunctionInfo> result; |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 693 | if (extension == NULL) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 694 | result = compilation_cache->LookupScript(source, |
| 695 | script_name, |
| 696 | line_offset, |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 697 | column_offset, |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 698 | is_shared_cross_origin, |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 699 | context); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 700 | } |
| 701 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 702 | if (result.is_null()) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 703 | // No cache entry found. Do pre-parsing, if it makes sense, and compile |
| 704 | // the script. |
| 705 | // Building preparse data that is only used immediately after is only a |
| 706 | // saving if we might skip building the AST for lazily compiled functions. |
| 707 | // I.e., preparse data isn't relevant when the lazy flag is off, and |
| 708 | // for small sources, odds are that there aren't many functions |
| 709 | // that would be compiled lazily anyway, so we skip the preparse step |
| 710 | // in that case too. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 711 | |
| 712 | // Create a script object describing the script to be compiled. |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 713 | Handle<Script> script = isolate->factory()->NewScript(source); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 714 | if (natives == NATIVES_CODE) { |
| 715 | script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); |
| 716 | } |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 717 | if (!script_name.is_null()) { |
| 718 | script->set_name(*script_name); |
| 719 | script->set_line_offset(Smi::FromInt(line_offset)); |
| 720 | script->set_column_offset(Smi::FromInt(column_offset)); |
| 721 | } |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 722 | script->set_is_shared_cross_origin(is_shared_cross_origin); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 723 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 724 | script->set_data(script_data.is_null() ? HEAP->undefined_value() |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 725 | : *script_data); |
| 726 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 727 | // Compile the function and add it to the cache. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 728 | CompilationInfoWithZone info(script); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 729 | info.MarkAsGlobal(); |
| 730 | info.SetExtension(extension); |
| 731 | info.SetPreParseData(pre_data); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 732 | info.SetContext(context); |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 733 | if (FLAG_use_strict) { |
| 734 | info.SetLanguageMode(FLAG_harmony_scoping ? EXTENDED_MODE : STRICT_MODE); |
| 735 | } |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 736 | result = MakeFunctionInfo(&info); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 737 | if (extension == NULL && !result.is_null() && !result->dont_cache()) { |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 738 | compilation_cache->PutScript(source, context, result); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 739 | } |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 740 | } else { |
| 741 | if (result->ic_age() != HEAP->global_ic_age()) { |
| 742 | result->ResetForNewContext(HEAP->global_ic_age()); |
| 743 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 744 | } |
| 745 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 746 | if (result.is_null()) isolate->ReportPendingMessages(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 747 | return result; |
| 748 | } |
| 749 | |
| 750 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 751 | Handle<SharedFunctionInfo> Compiler::CompileEval(Handle<String> source, |
| 752 | Handle<Context> context, |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 753 | bool is_global, |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 754 | LanguageMode language_mode, |
svenpanne@chromium.org | 9faefa4 | 2013-03-08 13:13:16 +0000 | [diff] [blame] | 755 | ParseRestriction restriction, |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 756 | int scope_position) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 757 | Isolate* isolate = source->GetIsolate(); |
ager@chromium.org | c3e50d8 | 2008-11-05 11:53:10 +0000 | [diff] [blame] | 758 | int source_length = source->length(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 759 | isolate->counters()->total_eval_size()->Increment(source_length); |
| 760 | isolate->counters()->total_compile_size()->Increment(source_length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 761 | |
| 762 | // The VM is in the COMPILER state until exiting this function. |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 763 | VMState<COMPILER> state(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 764 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 765 | // Do a lookup in the compilation cache; if the entry is not there, invoke |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 766 | // the compiler and add the result to the cache. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 767 | Handle<SharedFunctionInfo> result; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 768 | CompilationCache* compilation_cache = isolate->compilation_cache(); |
| 769 | result = compilation_cache->LookupEval(source, |
| 770 | context, |
| 771 | is_global, |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 772 | language_mode, |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 773 | scope_position); |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 774 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 775 | if (result.is_null()) { |
| 776 | // Create a script object describing the script to be compiled. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 777 | Handle<Script> script = isolate->factory()->NewScript(source); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 778 | CompilationInfoWithZone info(script); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 779 | info.MarkAsEval(); |
| 780 | if (is_global) info.MarkAsGlobal(); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 781 | info.SetLanguageMode(language_mode); |
svenpanne@chromium.org | 9faefa4 | 2013-03-08 13:13:16 +0000 | [diff] [blame] | 782 | info.SetParseRestriction(restriction); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 783 | info.SetContext(context); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 784 | result = MakeFunctionInfo(&info); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 785 | if (!result.is_null()) { |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 786 | // Explicitly disable optimization for eval code. We're not yet prepared |
| 787 | // to handle eval-code in the optimizing compiler. |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 788 | result->DisableOptimization(kEval); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 789 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 790 | // If caller is strict mode, the result must be in strict mode or |
| 791 | // extended mode as well, but not the other way around. Consider: |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 792 | // eval("'use strict'; ..."); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 793 | ASSERT(language_mode != STRICT_MODE || !result->is_classic_mode()); |
| 794 | // If caller is in extended mode, the result must also be in |
| 795 | // extended mode. |
| 796 | ASSERT(language_mode != EXTENDED_MODE || |
| 797 | result->is_extended_mode()); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 798 | if (!result->dont_cache()) { |
| 799 | compilation_cache->PutEval( |
| 800 | source, context, is_global, result, scope_position); |
| 801 | } |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 802 | } |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 803 | } else { |
| 804 | if (result->ic_age() != HEAP->global_ic_age()) { |
| 805 | result->ResetForNewContext(HEAP->global_ic_age()); |
| 806 | } |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 807 | } |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 808 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 809 | return result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 813 | static bool InstallFullCode(CompilationInfo* info) { |
| 814 | // Update the shared function info with the compiled code and the |
| 815 | // scope info. Please note, that the order of the shared function |
| 816 | // info initialization is important since set_scope_info might |
| 817 | // trigger a GC, causing the ASSERT below to be invalid if the code |
| 818 | // was flushed. By setting the code object last we avoid this. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 819 | Handle<SharedFunctionInfo> shared = info->shared_info(); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 820 | Handle<Code> code = info->code(); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 821 | CHECK(code->kind() == Code::FUNCTION); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 822 | Handle<JSFunction> function = info->closure(); |
| 823 | Handle<ScopeInfo> scope_info = |
| 824 | ScopeInfo::Create(info->scope(), info->zone()); |
| 825 | shared->set_scope_info(*scope_info); |
yangguo@chromium.org | 9768bf1 | 2013-01-11 14:51:07 +0000 | [diff] [blame] | 826 | shared->ReplaceCode(*code); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 827 | if (!function.is_null()) { |
| 828 | function->ReplaceCode(*code); |
| 829 | ASSERT(!function->IsOptimized()); |
| 830 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 831 | |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 832 | // Set the expected number of properties for instances. |
| 833 | FunctionLiteral* lit = info->function(); |
| 834 | int expected = lit->expected_property_count(); |
| 835 | SetExpectedNofPropertiesFromEstimate(shared, expected); |
| 836 | |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 837 | // Check the function has compiled code. |
| 838 | ASSERT(shared->is_compiled()); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 839 | shared->set_dont_optimize(lit->flags()->Contains(kDontOptimize)); |
| 840 | shared->set_dont_inline(lit->flags()->Contains(kDontInline)); |
| 841 | shared->set_ast_node_count(lit->ast_node_count()); |
| 842 | |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 843 | if (V8::UseCrankshaft() && |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 844 | !function.is_null() && |
| 845 | !shared->optimization_disabled()) { |
| 846 | // If we're asked to always optimize, we compile the optimized |
| 847 | // version of the function right away - unless the debugger is |
| 848 | // active as it makes no sense to compile optimized code then. |
| 849 | if (FLAG_always_opt && |
| 850 | !Isolate::Current()->DebuggerHasBreakPoints()) { |
| 851 | CompilationInfoWithZone optimized(function); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 852 | optimized.SetOptimizing(BailoutId::None()); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 853 | return Compiler::CompileLazy(&optimized); |
| 854 | } |
| 855 | } |
| 856 | return true; |
| 857 | } |
| 858 | |
| 859 | |
| 860 | static void InstallCodeCommon(CompilationInfo* info) { |
| 861 | Handle<SharedFunctionInfo> shared = info->shared_info(); |
| 862 | Handle<Code> code = info->code(); |
| 863 | ASSERT(!code.is_null()); |
| 864 | |
| 865 | // Set optimizable to false if this is disallowed by the shared |
| 866 | // function info, e.g., we might have flushed the code and must |
| 867 | // reset this bit when lazy compiling the code again. |
| 868 | if (shared->optimization_disabled()) code->set_optimizable(false); |
| 869 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 870 | if (shared->code() == *code) { |
| 871 | // Do not send compilation event for the same code twice. |
| 872 | return; |
| 873 | } |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 874 | Compiler::RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); |
| 875 | } |
| 876 | |
| 877 | |
| 878 | static void InsertCodeIntoOptimizedCodeMap(CompilationInfo* info) { |
| 879 | Handle<Code> code = info->code(); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 880 | if (FLAG_cache_optimized_code && |
| 881 | info->osr_ast_id().IsNone() && |
| 882 | code->kind() == Code::OPTIMIZED_FUNCTION) { |
| 883 | Handle<JSFunction> function = info->closure(); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 884 | Handle<SharedFunctionInfo> shared(function->shared()); |
| 885 | Handle<FixedArray> literals(function->literals()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 886 | Handle<Context> native_context(function->context()->native_context()); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 887 | SharedFunctionInfo::AddToOptimizedCodeMap( |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 888 | shared, native_context, code, literals); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 889 | } |
| 890 | } |
| 891 | |
| 892 | |
| 893 | static bool InstallCodeFromOptimizedCodeMap(CompilationInfo* info) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 894 | if (FLAG_cache_optimized_code && |
| 895 | info->osr_ast_id().IsNone() && |
| 896 | info->IsOptimizing()) { |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 897 | Handle<SharedFunctionInfo> shared = info->shared_info(); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 898 | Handle<JSFunction> function = info->closure(); |
| 899 | ASSERT(!function.is_null()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 900 | Handle<Context> native_context(function->context()->native_context()); |
| 901 | int index = shared->SearchOptimizedCodeMap(*native_context); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 902 | if (index > 0) { |
| 903 | if (FLAG_trace_opt) { |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 904 | PrintF("[found optimized code for "); |
| 905 | function->ShortPrint(); |
| 906 | PrintF("]\n"); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 907 | } |
ulan@chromium.org | d9e468a | 2012-06-25 09:47:40 +0000 | [diff] [blame] | 908 | // Caching of optimized code enabled and optimized code found. |
| 909 | shared->InstallFromOptimizedCodeMap(*function, index); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 910 | return true; |
| 911 | } |
| 912 | } |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 913 | return false; |
| 914 | } |
| 915 | |
| 916 | |
| 917 | bool Compiler::CompileLazy(CompilationInfo* info) { |
| 918 | Isolate* isolate = info->isolate(); |
| 919 | |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 920 | // The VM is in the COMPILER state until exiting this function. |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 921 | VMState<COMPILER> state(isolate); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 922 | |
| 923 | PostponeInterruptsScope postpone(isolate); |
| 924 | |
| 925 | Handle<SharedFunctionInfo> shared = info->shared_info(); |
| 926 | int compiled_size = shared->end_position() - shared->start_position(); |
| 927 | isolate->counters()->total_compile_size()->Increment(compiled_size); |
| 928 | |
| 929 | if (InstallCodeFromOptimizedCodeMap(info)) return true; |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 930 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 931 | // Generate the AST for the lazily compiled function. |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 932 | if (Parser::Parse(info)) { |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 933 | // Measure how long it takes to do the lazy compilation; only take the |
| 934 | // rest of the function into account to avoid overlap with the lazy |
| 935 | // parsing statistics. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 936 | HistogramTimerScope timer(isolate->counters()->compile_lazy()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 937 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 938 | // After parsing we know the function's language mode. Remember it. |
| 939 | LanguageMode language_mode = info->function()->language_mode(); |
| 940 | info->SetLanguageMode(language_mode); |
| 941 | shared->set_language_mode(language_mode); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 942 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 943 | // Compile the code. |
| 944 | if (!MakeCode(info)) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 945 | if (!isolate->has_pending_exception()) { |
| 946 | isolate->StackOverflow(); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 947 | } |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 948 | } else { |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 949 | InstallCodeCommon(info); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 950 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 951 | if (info->IsOptimizing()) { |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 952 | Handle<Code> code = info->code(); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 953 | ASSERT(shared->scope_info() != ScopeInfo::Empty(isolate)); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 954 | info->closure()->ReplaceCode(*code); |
| 955 | InsertCodeIntoOptimizedCodeMap(info); |
| 956 | return true; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 957 | } else { |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 958 | return InstallFullCode(info); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 959 | } |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 960 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 961 | } |
| 962 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 963 | ASSERT(info->code().is_null()); |
| 964 | return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | |
rossberg@chromium.org | 9259716 | 2013-08-23 13:28:00 +0000 | [diff] [blame] | 968 | void Compiler::RecompileConcurrent(Handle<JSFunction> closure) { |
| 969 | ASSERT(closure->IsMarkedForConcurrentRecompilation()); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 970 | |
| 971 | Isolate* isolate = closure->GetIsolate(); |
rossberg@chromium.org | 9259716 | 2013-08-23 13:28:00 +0000 | [diff] [blame] | 972 | // Here we prepare compile data for the concurrent recompilation thread, but |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 973 | // this still happens synchronously and interrupts execution. |
| 974 | Logger::TimerEventScope timer( |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 975 | isolate, Logger::TimerEventScope::v8_recompile_synchronous); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 976 | |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 977 | if (!isolate->optimizing_compiler_thread()->IsQueueAvailable()) { |
rossberg@chromium.org | 9259716 | 2013-08-23 13:28:00 +0000 | [diff] [blame] | 978 | if (FLAG_trace_concurrent_recompilation) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 979 | PrintF(" ** Compilation queue full, will retry optimizing "); |
| 980 | closure->PrintName(); |
| 981 | PrintF(" on next run.\n"); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 982 | } |
| 983 | return; |
| 984 | } |
| 985 | |
| 986 | SmartPointer<CompilationInfo> info(new CompilationInfoWithZone(closure)); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 987 | VMState<COMPILER> state(isolate); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 988 | PostponeInterruptsScope postpone(isolate); |
| 989 | |
| 990 | Handle<SharedFunctionInfo> shared = info->shared_info(); |
| 991 | int compiled_size = shared->end_position() - shared->start_position(); |
| 992 | isolate->counters()->total_compile_size()->Increment(compiled_size); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 993 | info->SetOptimizing(BailoutId::None()); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 994 | |
| 995 | { |
| 996 | CompilationHandleScope handle_scope(*info); |
| 997 | |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 998 | if (InstallCodeFromOptimizedCodeMap(*info)) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 999 | return; |
| 1000 | } |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1001 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1002 | if (Parser::Parse(*info)) { |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1003 | LanguageMode language_mode = info->function()->language_mode(); |
| 1004 | info->SetLanguageMode(language_mode); |
| 1005 | shared->set_language_mode(language_mode); |
| 1006 | info->SaveHandles(); |
| 1007 | |
| 1008 | if (Rewriter::Rewrite(*info) && Scope::Analyze(*info)) { |
| 1009 | OptimizingCompiler* compiler = |
| 1010 | new(info->zone()) OptimizingCompiler(*info); |
| 1011 | OptimizingCompiler::Status status = compiler->CreateGraph(); |
| 1012 | if (status == OptimizingCompiler::SUCCEEDED) { |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 1013 | info.Detach(); |
| 1014 | shared->code()->set_profiler_ticks(0); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 1015 | isolate->optimizing_compiler_thread()->QueueForOptimization(compiler); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1016 | } else if (status == OptimizingCompiler::BAILED_OUT) { |
| 1017 | isolate->clear_pending_exception(); |
| 1018 | InstallFullCode(*info); |
| 1019 | } |
| 1020 | } |
| 1021 | } |
| 1022 | } |
| 1023 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1024 | if (shared->code()->back_edges_patched_for_osr()) { |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 1025 | // At this point we either put the function on recompilation queue or |
| 1026 | // aborted optimization. In either case we want to continue executing |
| 1027 | // the unoptimized code without running into OSR. If the unoptimized |
| 1028 | // code has been patched for OSR, unpatch it. |
| 1029 | InterruptStub interrupt_stub; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1030 | Handle<Code> interrupt_code = interrupt_stub.GetCode(isolate); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 1031 | Handle<Code> replacement_code = |
| 1032 | isolate->builtins()->OnStackReplacement(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1033 | Deoptimizer::RevertInterruptCode(shared->code(), |
| 1034 | *interrupt_code, |
| 1035 | *replacement_code); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1036 | } |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 1037 | |
| 1038 | if (isolate->has_pending_exception()) isolate->clear_pending_exception(); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | |
| 1042 | void Compiler::InstallOptimizedCode(OptimizingCompiler* optimizing_compiler) { |
| 1043 | SmartPointer<CompilationInfo> info(optimizing_compiler->info()); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 1044 | // The function may have already been optimized by OSR. Simply continue. |
| 1045 | // Except when OSR already disabled optimization for some reason. |
| 1046 | if (info->shared_info()->optimization_disabled()) { |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1047 | info->AbortOptimization(); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 1048 | InstallFullCode(*info); |
rossberg@chromium.org | 9259716 | 2013-08-23 13:28:00 +0000 | [diff] [blame] | 1049 | if (FLAG_trace_concurrent_recompilation) { |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 1050 | PrintF(" ** aborting optimization for "); |
| 1051 | info->closure()->PrintName(); |
| 1052 | PrintF(" as it has been disabled.\n"); |
| 1053 | } |
| 1054 | ASSERT(!info->closure()->IsMarkedForInstallingRecompiledCode()); |
| 1055 | return; |
| 1056 | } |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1057 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 1058 | Isolate* isolate = info->isolate(); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 1059 | VMState<COMPILER> state(isolate); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 1060 | Logger::TimerEventScope timer( |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 1061 | isolate, Logger::TimerEventScope::v8_recompile_synchronous); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1062 | // If crankshaft succeeded, install the optimized code else install |
| 1063 | // the unoptimized code. |
| 1064 | OptimizingCompiler::Status status = optimizing_compiler->last_status(); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1065 | if (info->HasAbortedDueToDependencyChange()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1066 | info->set_bailout_reason(kBailedOutDueToDependencyChange); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1067 | status = optimizing_compiler->AbortOptimization(); |
| 1068 | } else if (status != OptimizingCompiler::SUCCEEDED) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1069 | info->set_bailout_reason(kFailedBailedOutLastTime); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1070 | status = optimizing_compiler->AbortOptimization(); |
machenbach@chromium.org | c1789ee | 2013-07-05 07:09:57 +0000 | [diff] [blame] | 1071 | } else if (isolate->DebuggerHasBreakPoints()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1072 | info->set_bailout_reason(kDebuggerIsActive); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1073 | status = optimizing_compiler->AbortOptimization(); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1074 | } else { |
| 1075 | status = optimizing_compiler->GenerateAndInstallCode(); |
| 1076 | ASSERT(status == OptimizingCompiler::SUCCEEDED || |
| 1077 | status == OptimizingCompiler::BAILED_OUT); |
| 1078 | } |
| 1079 | |
| 1080 | InstallCodeCommon(*info); |
| 1081 | if (status == OptimizingCompiler::SUCCEEDED) { |
| 1082 | Handle<Code> code = info->code(); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1083 | ASSERT(info->shared_info()->scope_info() != ScopeInfo::Empty(isolate)); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1084 | info->closure()->ReplaceCode(*code); |
| 1085 | if (info->shared_info()->SearchOptimizedCodeMap( |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1086 | info->closure()->context()->native_context()) == -1) { |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1087 | InsertCodeIntoOptimizedCodeMap(*info); |
| 1088 | } |
rossberg@chromium.org | 9259716 | 2013-08-23 13:28:00 +0000 | [diff] [blame] | 1089 | if (FLAG_trace_concurrent_recompilation) { |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 1090 | PrintF(" ** Optimized code for "); |
| 1091 | info->closure()->PrintName(); |
| 1092 | PrintF(" installed.\n"); |
| 1093 | } |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1094 | } else { |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 1095 | info->AbortOptimization(); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1096 | InstallFullCode(*info); |
| 1097 | } |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 1098 | // Optimized code is finally replacing unoptimized code. Reset the latter's |
| 1099 | // profiler ticks to prevent too soon re-opt after a deopt. |
| 1100 | info->shared_info()->code()->set_profiler_ticks(0); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 1101 | ASSERT(!info->closure()->IsMarkedForInstallingRecompiledCode()); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1105 | Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal, |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1106 | Handle<Script> script) { |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1107 | // Precondition: code has been parsed and scopes have been analyzed. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1108 | CompilationInfoWithZone info(script); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1109 | info.SetFunction(literal); |
| 1110 | info.SetScope(literal->scope()); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1111 | info.SetLanguageMode(literal->scope()->language_mode()); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1112 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1113 | Isolate* isolate = info.isolate(); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1114 | Factory* factory = isolate->factory(); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1115 | LiveEditFunctionTracker live_edit_tracker(isolate, literal); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1116 | // Determine if the function can be lazily compiled. This is necessary to |
| 1117 | // allow some of our builtin JS files to be lazily compiled. These |
| 1118 | // builtins cannot be handled lazily by the parser, since we have to know |
| 1119 | // if a function uses the special natives syntax, which is something the |
| 1120 | // parser records. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1121 | // If the debugger requests compilation for break points, we cannot be |
| 1122 | // aggressive about lazy compilation, because it might trigger compilation |
| 1123 | // of functions without an outer context when setting a breakpoint through |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 1124 | // Debug::FindSharedFunctionInfoInScript. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1125 | bool allow_lazy_without_ctx = literal->AllowsLazyCompilationWithoutContext(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1126 | bool allow_lazy = literal->AllowsLazyCompilation() && |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1127 | !DebuggerWantsEagerCompilation(&info, allow_lazy_without_ctx); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1128 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1129 | Handle<ScopeInfo> scope_info(ScopeInfo::Empty(isolate)); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1130 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1131 | // Generate code |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1132 | if (FLAG_lazy && allow_lazy && !literal->is_parenthesized()) { |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1133 | Handle<Code> code = isolate->builtins()->LazyCompile(); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1134 | info.SetCode(code); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 1135 | } else if (GenerateCode(&info)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1136 | ASSERT(!info.code().is_null()); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1137 | scope_info = ScopeInfo::Create(info.scope(), info.zone()); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1138 | } else { |
| 1139 | return Handle<SharedFunctionInfo>::null(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1140 | } |
| 1141 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 1142 | // Create a shared function info object. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1143 | Handle<SharedFunctionInfo> result = |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1144 | factory->NewSharedFunctionInfo(literal->name(), |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1145 | literal->materialized_literal_count(), |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 1146 | literal->is_generator(), |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1147 | info.code(), |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1148 | scope_info); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1149 | SetFunctionInfo(result, literal, false, script); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1150 | RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1151 | result->set_allows_lazy_compilation(allow_lazy); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1152 | result->set_allows_lazy_compilation_without_context(allow_lazy_without_ctx); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1153 | |
| 1154 | // Set the expected number of properties for instances and return |
| 1155 | // the resulting function. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1156 | SetExpectedNofPropertiesFromEstimate(result, |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1157 | literal->expected_property_count()); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1158 | live_edit_tracker.RecordFunctionInfo(result, literal, info.zone()); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1159 | return result; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | |
| 1163 | // Sets the function info on a function. |
| 1164 | // The start_position points to the first '(' character after the function name |
| 1165 | // in the full script source. When counting characters in the script source the |
| 1166 | // the first character is number 0 (not 1). |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1167 | void Compiler::SetFunctionInfo(Handle<SharedFunctionInfo> function_info, |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1168 | FunctionLiteral* lit, |
| 1169 | bool is_toplevel, |
| 1170 | Handle<Script> script) { |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1171 | function_info->set_length(lit->parameter_count()); |
| 1172 | function_info->set_formal_parameter_count(lit->parameter_count()); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1173 | function_info->set_script(*script); |
| 1174 | function_info->set_function_token_position(lit->function_token_position()); |
| 1175 | function_info->set_start_position(lit->start_position()); |
| 1176 | function_info->set_end_position(lit->end_position()); |
| 1177 | function_info->set_is_expression(lit->is_expression()); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1178 | function_info->set_is_anonymous(lit->is_anonymous()); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1179 | function_info->set_is_toplevel(is_toplevel); |
| 1180 | function_info->set_inferred_name(*lit->inferred_name()); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1181 | function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1182 | function_info->set_allows_lazy_compilation_without_context( |
| 1183 | lit->AllowsLazyCompilationWithoutContext()); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1184 | function_info->set_language_mode(lit->language_mode()); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1185 | function_info->set_uses_arguments(lit->scope()->arguments() != NULL); |
| 1186 | function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); |
svenpanne@chromium.org | b1df11d | 2012-02-08 10:26:21 +0000 | [diff] [blame] | 1187 | function_info->set_ast_node_count(lit->ast_node_count()); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 1188 | function_info->set_is_function(lit->is_function()); |
| 1189 | function_info->set_dont_optimize(lit->flags()->Contains(kDontOptimize)); |
svenpanne@chromium.org | b1df11d | 2012-02-08 10:26:21 +0000 | [diff] [blame] | 1190 | function_info->set_dont_inline(lit->flags()->Contains(kDontInline)); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 1191 | function_info->set_dont_cache(lit->flags()->Contains(kDontCache)); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1192 | function_info->set_is_generator(lit->is_generator()); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1193 | } |
| 1194 | |
| 1195 | |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 1196 | void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag, |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1197 | CompilationInfo* info, |
| 1198 | Handle<SharedFunctionInfo> shared) { |
| 1199 | // SharedFunctionInfo is passed separately, because if CompilationInfo |
| 1200 | // was created using Script object, it will not have it. |
| 1201 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1202 | // Log the code generation. If source information is available include |
| 1203 | // script name and line number. Check explicitly whether logging is |
| 1204 | // enabled as finding the line number is not free. |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1205 | if (info->isolate()->logger()->is_logging_code_events() || |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1206 | info->isolate()->cpu_profiler()->is_profiling()) { |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1207 | Handle<Script> script = info->script(); |
| 1208 | Handle<Code> code = info->code(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1209 | if (*code == info->isolate()->builtins()->builtin(Builtins::kLazyCompile)) |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1210 | return; |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 1211 | int line_num = GetScriptLineNumber(script, shared->start_position()) + 1; |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 1212 | int column_num = |
| 1213 | GetScriptColumnNumber(script, shared->start_position()) + 1; |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 1214 | USE(line_num); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1215 | if (script->name()->IsString()) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1216 | PROFILE(info->isolate(), |
| 1217 | CodeCreateEvent(Logger::ToNativeByScript(tag, *script), |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1218 | *code, |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1219 | *shared, |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1220 | info, |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 1221 | String::cast(script->name()), |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 1222 | line_num, |
| 1223 | column_num)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1224 | } else { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1225 | PROFILE(info->isolate(), |
| 1226 | CodeCreateEvent(Logger::ToNativeByScript(tag, *script), |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1227 | *code, |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1228 | *shared, |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1229 | info, |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 1230 | info->isolate()->heap()->empty_string(), |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 1231 | line_num, |
| 1232 | column_num)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1233 | } |
| 1234 | } |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1235 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1236 | GDBJIT(AddCode(Handle<String>(shared->DebugName()), |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1237 | Handle<Script>(info->script()), |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1238 | Handle<Code>(info->code()), |
| 1239 | info)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1240 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1241 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1242 | |
| 1243 | CompilationPhase::CompilationPhase(const char* name, CompilationInfo* info) |
| 1244 | : name_(name), info_(info), zone_(info->isolate()) { |
| 1245 | if (FLAG_hydrogen_stats) { |
| 1246 | info_zone_start_allocation_size_ = info->zone()->allocation_size(); |
| 1247 | start_ticks_ = OS::Ticks(); |
| 1248 | } |
| 1249 | } |
| 1250 | |
| 1251 | |
| 1252 | CompilationPhase::~CompilationPhase() { |
| 1253 | if (FLAG_hydrogen_stats) { |
| 1254 | unsigned size = zone()->allocation_size(); |
| 1255 | size += info_->zone()->allocation_size() - info_zone_start_allocation_size_; |
| 1256 | int64_t ticks = OS::Ticks() - start_ticks_; |
| 1257 | isolate()->GetHStatistics()->SaveTiming(name_, ticks, size); |
| 1258 | } |
| 1259 | } |
| 1260 | |
| 1261 | |
| 1262 | bool CompilationPhase::ShouldProduceTraceOutput() const { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1263 | // Trace if the appropriate trace flag is set and the phase name's first |
| 1264 | // character is in the FLAG_trace_phase command line parameter. |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame^] | 1265 | AllowHandleDereference allow_deref; |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 1266 | bool tracing_on = info()->IsStub() |
| 1267 | ? FLAG_trace_hydrogen_stubs |
| 1268 | : (FLAG_trace_hydrogen && |
| 1269 | info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1270 | return (tracing_on && |
| 1271 | OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1272 | } |
| 1273 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1274 | } } // namespace v8::internal |