kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1 | // Copyright 2011 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" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 35 | #include "debug.h" |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 36 | #include "full-codegen.h" |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 37 | #include "gdb-jit.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 38 | #include "hydrogen.h" |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 39 | #include "lithium.h" |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 40 | #include "liveedit.h" |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 41 | #include "parser.h" |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 42 | #include "rewriter.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 43 | #include "runtime-profiler.h" |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 44 | #include "scopeinfo.h" |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 45 | #include "scopes.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 46 | #include "vm-state-inl.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 47 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 48 | namespace v8 { |
| 49 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 50 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 51 | |
| 52 | CompilationInfo::CompilationInfo(Handle<Script> script) |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 53 | : isolate_(script->GetIsolate()), |
| 54 | flags_(0), |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 55 | function_(NULL), |
| 56 | scope_(NULL), |
| 57 | script_(script), |
| 58 | extension_(NULL), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 59 | pre_parse_data_(NULL), |
| 60 | supports_deoptimization_(false), |
| 61 | osr_ast_id_(AstNode::kNoNumber) { |
| 62 | Initialize(NONOPT); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | |
| 66 | CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info) |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 67 | : isolate_(shared_info->GetIsolate()), |
| 68 | flags_(IsLazy::encode(true)), |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 69 | function_(NULL), |
| 70 | scope_(NULL), |
| 71 | shared_info_(shared_info), |
| 72 | script_(Handle<Script>(Script::cast(shared_info->script()))), |
| 73 | extension_(NULL), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 74 | pre_parse_data_(NULL), |
| 75 | supports_deoptimization_(false), |
| 76 | osr_ast_id_(AstNode::kNoNumber) { |
| 77 | Initialize(BASE); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | |
| 81 | CompilationInfo::CompilationInfo(Handle<JSFunction> closure) |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 82 | : isolate_(closure->GetIsolate()), |
| 83 | flags_(IsLazy::encode(true)), |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 84 | function_(NULL), |
| 85 | scope_(NULL), |
| 86 | closure_(closure), |
| 87 | shared_info_(Handle<SharedFunctionInfo>(closure->shared())), |
| 88 | script_(Handle<Script>(Script::cast(shared_info_->script()))), |
| 89 | extension_(NULL), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 90 | pre_parse_data_(NULL), |
| 91 | supports_deoptimization_(false), |
| 92 | osr_ast_id_(AstNode::kNoNumber) { |
| 93 | Initialize(BASE); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 97 | // Disable optimization for the rest of the compilation pipeline. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 98 | void CompilationInfo::DisableOptimization() { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 99 | bool is_optimizable_closure = |
| 100 | FLAG_optimize_closures && |
| 101 | closure_.is_null() && |
| 102 | !scope_->HasTrivialOuterContext() && |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 103 | !scope_->outer_scope_calls_non_strict_eval() && |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 104 | !scope_->inside_with(); |
| 105 | SetMode(is_optimizable_closure ? BASE : NONOPT); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 109 | void CompilationInfo::AbortOptimization() { |
| 110 | Handle<Code> code(shared_info()->code()); |
| 111 | SetCode(code); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 115 | // Determine whether to use the full compiler for all code. If the flag |
| 116 | // --always-full-compiler is specified this is the case. For the virtual frame |
| 117 | // based compiler the full compiler is also used if a debugger is connected, as |
| 118 | // the code from the full compiler supports mode precise break points. For the |
| 119 | // crankshaft adaptive compiler debugging the optimized code is not possible at |
| 120 | // all. However crankshaft support recompilation of functions, so in this case |
| 121 | // the full compiler need not be be used if a debugger is attached, but only if |
| 122 | // break points has actually been set. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 123 | static bool is_debugging_active() { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 124 | #ifdef ENABLE_DEBUGGER_SUPPORT |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 125 | Isolate* isolate = Isolate::Current(); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 126 | return V8::UseCrankshaft() ? |
| 127 | isolate->debug()->has_break_points() : |
| 128 | isolate->debugger()->IsDebuggerActive(); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 129 | #else |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 130 | return false; |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 131 | #endif |
| 132 | } |
| 133 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 134 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 135 | static bool AlwaysFullCompiler() { |
| 136 | return FLAG_always_full_compiler || is_debugging_active(); |
| 137 | } |
| 138 | |
| 139 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 140 | static void FinishOptimization(Handle<JSFunction> function, int64_t start) { |
| 141 | int opt_count = function->shared()->opt_count(); |
| 142 | function->shared()->set_opt_count(opt_count + 1); |
lrn@chromium.org | 8541d77 | 2010-12-15 12:05:09 +0000 | [diff] [blame] | 143 | double ms = static_cast<double>(OS::Ticks() - start) / 1000; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 144 | if (FLAG_trace_opt) { |
| 145 | PrintF("[optimizing: "); |
| 146 | function->PrintName(); |
| 147 | PrintF(" / %" V8PRIxPTR, reinterpret_cast<intptr_t>(*function)); |
| 148 | PrintF(" - took %0.3f ms]\n", ms); |
| 149 | } |
| 150 | if (FLAG_trace_opt_stats) { |
| 151 | static double compilation_time = 0.0; |
| 152 | static int compiled_functions = 0; |
| 153 | static int code_size = 0; |
| 154 | |
| 155 | compilation_time += ms; |
| 156 | compiled_functions++; |
| 157 | code_size += function->shared()->SourceSize(); |
| 158 | PrintF("Compiled: %d functions with %d byte source size in %fms.\n", |
| 159 | compiled_functions, |
| 160 | code_size, |
| 161 | compilation_time); |
| 162 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 166 | static bool MakeCrankshaftCode(CompilationInfo* info) { |
| 167 | // Test if we can optimize this function when asked to. We can only |
| 168 | // do this after the scopes are computed. |
| 169 | if (!info->AllowOptimize()) info->DisableOptimization(); |
| 170 | |
| 171 | // In case we are not optimizing simply return the code from |
| 172 | // the full code generator. |
| 173 | if (!info->IsOptimizing()) { |
| 174 | return FullCodeGenerator::MakeCode(info); |
| 175 | } |
| 176 | |
| 177 | // We should never arrive here if there is not code object on the |
| 178 | // shared function object. |
| 179 | Handle<Code> code(info->shared_info()->code()); |
| 180 | ASSERT(code->kind() == Code::FUNCTION); |
| 181 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 182 | // We should never arrive here if optimization has been disabled on the |
| 183 | // shared function info. |
| 184 | ASSERT(!info->shared_info()->optimization_disabled()); |
| 185 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 186 | // Fall back to using the full code generator if it's not possible |
| 187 | // to use the Hydrogen-based optimizing compiler. We already have |
| 188 | // generated code for this from the shared function object. |
| 189 | if (AlwaysFullCompiler() || !FLAG_use_hydrogen) { |
| 190 | info->SetCode(code); |
| 191 | return true; |
| 192 | } |
| 193 | |
| 194 | // Limit the number of times we re-compile a functions with |
| 195 | // the optimizing compiler. |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 196 | const int kMaxOptCount = |
| 197 | FLAG_deopt_every_n_times == 0 ? Compiler::kDefaultMaxOptCount : 1000; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 198 | if (info->shared_info()->opt_count() > kMaxOptCount) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 199 | info->AbortOptimization(); |
| 200 | Handle<JSFunction> closure = info->closure(); |
| 201 | info->shared_info()->DisableOptimization(*closure); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 202 | // True indicates the compilation pipeline is still going, not |
| 203 | // necessarily that we optimized the code. |
| 204 | return true; |
| 205 | } |
| 206 | |
| 207 | // Due to an encoding limit on LUnallocated operands in the Lithium |
| 208 | // language, we cannot optimize functions with too many formal parameters |
| 209 | // or perform on-stack replacement for function with too many |
| 210 | // stack-allocated local variables. |
| 211 | // |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 212 | // The encoding is as a signed value, with parameters and receiver using |
| 213 | // the negative indices and locals the non-negative ones. |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 214 | const int parameter_limit = -LUnallocated::kMinFixedIndex; |
| 215 | const int locals_limit = LUnallocated::kMaxFixedIndex; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 216 | Scope* scope = info->scope(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 217 | if ((scope->num_parameters() + 1) > parameter_limit || |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 218 | (info->osr_ast_id() != AstNode::kNoNumber && |
| 219 | scope->num_parameters() + 1 + scope->num_stack_slots() > locals_limit)) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 220 | info->AbortOptimization(); |
| 221 | Handle<JSFunction> closure = info->closure(); |
| 222 | info->shared_info()->DisableOptimization(*closure); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 223 | // True indicates the compilation pipeline is still going, not |
| 224 | // necessarily that we optimized the code. |
| 225 | return true; |
| 226 | } |
| 227 | |
| 228 | // Take --hydrogen-filter into account. |
| 229 | Vector<const char> filter = CStrVector(FLAG_hydrogen_filter); |
| 230 | Handle<String> name = info->function()->debug_name(); |
| 231 | bool match = filter.is_empty() || name->IsEqualTo(filter); |
| 232 | if (!match) { |
| 233 | info->SetCode(code); |
| 234 | return true; |
| 235 | } |
| 236 | |
| 237 | // Recompile the unoptimized version of the code if the current version |
| 238 | // doesn't have deoptimization support. Alternatively, we may decide to |
| 239 | // run the full code generator to get a baseline for the compile-time |
| 240 | // performance of the hydrogen-based compiler. |
| 241 | int64_t start = OS::Ticks(); |
| 242 | bool should_recompile = !info->shared_info()->has_deoptimization_support(); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 243 | if (should_recompile || FLAG_hydrogen_stats) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 244 | HPhase phase(HPhase::kFullCodeGen); |
| 245 | CompilationInfo unoptimized(info->shared_info()); |
| 246 | // Note that we use the same AST that we will use for generating the |
| 247 | // optimized code. |
| 248 | unoptimized.SetFunction(info->function()); |
| 249 | unoptimized.SetScope(info->scope()); |
| 250 | if (should_recompile) unoptimized.EnableDeoptimizationSupport(); |
| 251 | bool succeeded = FullCodeGenerator::MakeCode(&unoptimized); |
| 252 | if (should_recompile) { |
| 253 | if (!succeeded) return false; |
| 254 | Handle<SharedFunctionInfo> shared = info->shared_info(); |
| 255 | shared->EnableDeoptimizationSupport(*unoptimized.code()); |
| 256 | // The existing unoptimized code was replaced with the new one. |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 257 | Compiler::RecordFunctionCompilation( |
| 258 | Logger::LAZY_COMPILE_TAG, &unoptimized, shared); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | |
| 262 | // Check that the unoptimized, shared code is ready for |
| 263 | // optimizations. When using the always_opt flag we disregard the |
| 264 | // optimizable marker in the code object and optimize anyway. This |
| 265 | // is safe as long as the unoptimized code has deoptimization |
| 266 | // support. |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 267 | ASSERT(FLAG_always_opt || code->optimizable()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 268 | ASSERT(info->shared_info()->has_deoptimization_support()); |
| 269 | |
| 270 | if (FLAG_trace_hydrogen) { |
| 271 | PrintF("-----------------------------------------------------------\n"); |
| 272 | PrintF("Compiling method %s using hydrogen\n", *name->ToCString()); |
| 273 | HTracer::Instance()->TraceCompilation(info->function()); |
| 274 | } |
| 275 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 276 | Handle<Context> global_context(info->closure()->context()->global_context()); |
| 277 | TypeFeedbackOracle oracle(code, global_context); |
| 278 | HGraphBuilder builder(info, &oracle); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 279 | HPhase phase(HPhase::kTotal); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 280 | HGraph* graph = builder.CreateGraph(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 281 | if (info->isolate()->has_pending_exception()) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 282 | info->SetCode(Handle<Code>::null()); |
| 283 | return false; |
| 284 | } |
| 285 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 286 | if (graph != NULL && FLAG_build_lithium) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 287 | Handle<Code> optimized_code = graph->Compile(info); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 288 | if (!optimized_code.is_null()) { |
| 289 | info->SetCode(optimized_code); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 290 | FinishOptimization(info->closure(), start); |
| 291 | return true; |
| 292 | } |
| 293 | } |
| 294 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 295 | // Keep using the shared code. |
| 296 | info->AbortOptimization(); |
| 297 | if (!builder.inline_bailout()) { |
| 298 | // Mark the shared code as unoptimizable unless it was an inlined |
| 299 | // function that bailed out. |
| 300 | Handle<JSFunction> closure = info->closure(); |
| 301 | info->shared_info()->DisableOptimization(*closure); |
| 302 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 303 | // True indicates the compilation pipeline is still going, not necessarily |
| 304 | // that we optimized the code. |
| 305 | return true; |
| 306 | } |
| 307 | |
| 308 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 309 | static bool GenerateCode(CompilationInfo* info) { |
| 310 | return V8::UseCrankshaft() ? |
| 311 | MakeCrankshaftCode(info) : |
| 312 | FullCodeGenerator::MakeCode(info); |
| 313 | } |
| 314 | |
| 315 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 316 | static bool MakeCode(CompilationInfo* info) { |
| 317 | // Precondition: code has been parsed. Postcondition: the code field in |
| 318 | // the compilation info is set if compilation succeeded. |
| 319 | ASSERT(info->function() != NULL); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 320 | return Rewriter::Rewrite(info) && Scope::Analyze(info) && GenerateCode(info); |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 324 | #ifdef ENABLE_DEBUGGER_SUPPORT |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 325 | bool Compiler::MakeCodeForLiveEdit(CompilationInfo* info) { |
| 326 | // Precondition: code has been parsed. Postcondition: the code field in |
| 327 | // the compilation info is set if compilation succeeded. |
| 328 | bool succeeded = MakeCode(info); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 329 | if (!info->shared_info().is_null()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 330 | Handle<SerializedScopeInfo> scope_info = |
| 331 | SerializedScopeInfo::Create(info->scope()); |
| 332 | info->shared_info()->set_scope_info(*scope_info); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 333 | } |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 334 | return succeeded; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 335 | } |
| 336 | #endif |
| 337 | |
| 338 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 339 | static Handle<SharedFunctionInfo> MakeFunctionInfo(CompilationInfo* info) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 340 | Isolate* isolate = info->isolate(); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 341 | ZoneScope zone_scope(isolate, DELETE_ON_EXIT); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 342 | PostponeInterruptsScope postpone(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 343 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 344 | ASSERT(!isolate->global_context().is_null()); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 345 | Handle<Script> script = info->script(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 346 | script->set_context_data((*isolate->global_context())->data()); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 347 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 348 | #ifdef ENABLE_DEBUGGER_SUPPORT |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 349 | if (info->is_eval()) { |
| 350 | Script::CompilationType compilation_type = Script::COMPILATION_TYPE_EVAL; |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 351 | script->set_compilation_type(Smi::FromInt(compilation_type)); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 352 | // For eval scripts add information on the function from which eval was |
| 353 | // called. |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 354 | if (info->is_eval()) { |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 355 | StackTraceFrameIterator it(isolate); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 356 | if (!it.done()) { |
| 357 | script->set_eval_from_shared( |
| 358 | JSFunction::cast(it.frame()->function())->shared()); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 359 | Code* code = it.frame()->LookupCode(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 360 | int offset = static_cast<int>( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 361 | it.frame()->pc() - code->instruction_start()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 362 | script->set_eval_from_instructions_offset(Smi::FromInt(offset)); |
| 363 | } |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 364 | } |
| 365 | } |
| 366 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 367 | // Notify debugger |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 368 | isolate->debugger()->OnBeforeCompile(script); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 369 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 370 | |
| 371 | // Only allow non-global compiles for eval. |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 372 | ASSERT(info->is_eval() || info->is_global()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 373 | |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 374 | if (!ParserApi::Parse(info)) return Handle<SharedFunctionInfo>::null(); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 375 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 376 | // Measure how long it takes to do the compilation; only take the |
| 377 | // rest of the function into account to avoid overlap with the |
| 378 | // parsing statistics. |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 379 | HistogramTimer* rate = info->is_eval() |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 380 | ? info->isolate()->counters()->compile_eval() |
| 381 | : info->isolate()->counters()->compile(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 382 | HistogramTimerScope timer(rate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 383 | |
| 384 | // Compile the code. |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 385 | FunctionLiteral* lit = info->function(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 386 | LiveEditFunctionTracker live_edit_tracker(isolate, lit); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 387 | if (!MakeCode(info)) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 388 | isolate->StackOverflow(); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 389 | return Handle<SharedFunctionInfo>::null(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 390 | } |
| 391 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 392 | // Allocate function. |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 393 | ASSERT(!info->code().is_null()); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 394 | Handle<SharedFunctionInfo> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 395 | isolate->factory()->NewSharedFunctionInfo( |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 396 | lit->name(), |
| 397 | lit->materialized_literal_count(), |
| 398 | info->code(), |
| 399 | SerializedScopeInfo::Create(info->scope())); |
| 400 | |
| 401 | ASSERT_EQ(RelocInfo::kNoPosition, lit->function_token_position()); |
| 402 | Compiler::SetFunctionInfo(result, lit, true, script); |
| 403 | |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 404 | if (script->name()->IsString()) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 405 | PROFILE(isolate, CodeCreateEvent( |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 406 | info->is_eval() |
| 407 | ? Logger::EVAL_TAG |
| 408 | : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script), |
| 409 | *info->code(), |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 410 | *result, |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 411 | String::cast(script->name()))); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 412 | GDBJIT(AddCode(Handle<String>(String::cast(script->name())), |
| 413 | script, |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 414 | info->code(), |
| 415 | info)); |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 416 | } else { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 417 | PROFILE(isolate, CodeCreateEvent( |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 418 | info->is_eval() |
| 419 | ? Logger::EVAL_TAG |
| 420 | : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script), |
| 421 | *info->code(), |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 422 | *result, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 423 | isolate->heap()->empty_string())); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 424 | GDBJIT(AddCode(Handle<String>(), script, info->code(), info)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 425 | } |
| 426 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 427 | // Hint to the runtime system used when allocating space for initial |
| 428 | // property space by setting the expected number of properties for |
| 429 | // the instances of the function. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 430 | SetExpectedNofPropertiesFromEstimate(result, lit->expected_property_count()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 431 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 432 | #ifdef ENABLE_DEBUGGER_SUPPORT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 433 | // Notify debugger |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 434 | isolate->debugger()->OnAfterCompile( |
| 435 | script, Debugger::NO_AFTER_COMPILE_FLAGS); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 436 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 437 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 438 | live_edit_tracker.RecordFunctionInfo(result, lit); |
| 439 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 440 | return result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 444 | Handle<SharedFunctionInfo> Compiler::Compile(Handle<String> source, |
| 445 | Handle<Object> script_name, |
| 446 | int line_offset, |
| 447 | int column_offset, |
| 448 | v8::Extension* extension, |
| 449 | ScriptDataImpl* input_pre_data, |
| 450 | Handle<Object> script_data, |
| 451 | NativesFlag natives) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 452 | Isolate* isolate = source->GetIsolate(); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 453 | int source_length = source->length(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 454 | isolate->counters()->total_load_size()->Increment(source_length); |
| 455 | isolate->counters()->total_compile_size()->Increment(source_length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 456 | |
| 457 | // The VM is in the COMPILER state until exiting this function. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 458 | VMState state(isolate, COMPILER); |
| 459 | |
| 460 | CompilationCache* compilation_cache = isolate->compilation_cache(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 461 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 462 | // Do a lookup in the compilation cache but not for extensions. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 463 | Handle<SharedFunctionInfo> result; |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 464 | if (extension == NULL) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 465 | result = compilation_cache->LookupScript(source, |
| 466 | script_name, |
| 467 | line_offset, |
| 468 | column_offset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 469 | } |
| 470 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 471 | if (result.is_null()) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 472 | // No cache entry found. Do pre-parsing, if it makes sense, and compile |
| 473 | // the script. |
| 474 | // Building preparse data that is only used immediately after is only a |
| 475 | // saving if we might skip building the AST for lazily compiled functions. |
| 476 | // I.e., preparse data isn't relevant when the lazy flag is off, and |
| 477 | // for small sources, odds are that there aren't many functions |
| 478 | // that would be compiled lazily anyway, so we skip the preparse step |
| 479 | // in that case too. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 480 | ScriptDataImpl* pre_data = input_pre_data; |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 481 | bool harmony_block_scoping = natives != NATIVES_CODE && |
| 482 | FLAG_harmony_block_scoping; |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 483 | if (pre_data == NULL |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 484 | && source_length >= FLAG_min_preparse_length) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 485 | if (source->IsExternalTwoByteString()) { |
| 486 | ExternalTwoByteStringUC16CharacterStream stream( |
| 487 | Handle<ExternalTwoByteString>::cast(source), 0, source->length()); |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 488 | pre_data = ParserApi::PartialPreParse(&stream, |
| 489 | extension, |
| 490 | harmony_block_scoping); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 491 | } else { |
| 492 | GenericStringUC16CharacterStream stream(source, 0, source->length()); |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 493 | pre_data = ParserApi::PartialPreParse(&stream, |
| 494 | extension, |
| 495 | harmony_block_scoping); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 496 | } |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | // Create a script object describing the script to be compiled. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 500 | Handle<Script> script = FACTORY->NewScript(source); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 501 | if (natives == NATIVES_CODE) { |
| 502 | script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); |
| 503 | } |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 504 | if (!script_name.is_null()) { |
| 505 | script->set_name(*script_name); |
| 506 | script->set_line_offset(Smi::FromInt(line_offset)); |
| 507 | script->set_column_offset(Smi::FromInt(column_offset)); |
| 508 | } |
| 509 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 510 | script->set_data(script_data.is_null() ? HEAP->undefined_value() |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 511 | : *script_data); |
| 512 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 513 | // Compile the function and add it to the cache. |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 514 | CompilationInfo info(script); |
| 515 | info.MarkAsGlobal(); |
| 516 | info.SetExtension(extension); |
| 517 | info.SetPreParseData(pre_data); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 518 | if (natives == NATIVES_CODE) { |
| 519 | info.MarkAsAllowingNativesSyntax(); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 520 | } |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 521 | result = MakeFunctionInfo(&info); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 522 | if (extension == NULL && !result.is_null()) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 523 | compilation_cache->PutScript(source, result); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | // Get rid of the pre-parsing data (if necessary). |
| 527 | if (input_pre_data == NULL && pre_data != NULL) { |
| 528 | delete pre_data; |
| 529 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 530 | } |
| 531 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 532 | if (result.is_null()) isolate->ReportPendingMessages(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 533 | return result; |
| 534 | } |
| 535 | |
| 536 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 537 | Handle<SharedFunctionInfo> Compiler::CompileEval(Handle<String> source, |
| 538 | Handle<Context> context, |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 539 | bool is_global, |
| 540 | StrictModeFlag strict_mode) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 541 | Isolate* isolate = source->GetIsolate(); |
ager@chromium.org | c3e50d8 | 2008-11-05 11:53:10 +0000 | [diff] [blame] | 542 | int source_length = source->length(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 543 | isolate->counters()->total_eval_size()->Increment(source_length); |
| 544 | isolate->counters()->total_compile_size()->Increment(source_length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 545 | |
| 546 | // The VM is in the COMPILER state until exiting this function. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 547 | VMState state(isolate, COMPILER); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 548 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 549 | // 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] | 550 | // the compiler and add the result to the cache. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 551 | Handle<SharedFunctionInfo> result; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 552 | CompilationCache* compilation_cache = isolate->compilation_cache(); |
| 553 | result = compilation_cache->LookupEval(source, |
| 554 | context, |
| 555 | is_global, |
| 556 | strict_mode); |
ager@chromium.org | add848f | 2009-08-13 12:44:13 +0000 | [diff] [blame] | 557 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 558 | if (result.is_null()) { |
| 559 | // Create a script object describing the script to be compiled. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 560 | Handle<Script> script = isolate->factory()->NewScript(source); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 561 | CompilationInfo info(script); |
| 562 | info.MarkAsEval(); |
| 563 | if (is_global) info.MarkAsGlobal(); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 564 | if (strict_mode == kStrictMode) info.MarkAsStrictMode(); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 565 | info.SetCallingContext(context); |
| 566 | result = MakeFunctionInfo(&info); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 567 | if (!result.is_null()) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 568 | CompilationCache* compilation_cache = isolate->compilation_cache(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 569 | // If caller is strict mode, the result must be strict as well, |
| 570 | // but not the other way around. Consider: |
| 571 | // eval("'use strict'; ..."); |
| 572 | ASSERT(strict_mode == kNonStrictMode || result->strict_mode()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 573 | compilation_cache->PutEval(source, context, is_global, result); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 574 | } |
| 575 | } |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 576 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 577 | return result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 581 | bool Compiler::CompileLazy(CompilationInfo* info) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 582 | Isolate* isolate = info->isolate(); |
| 583 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 584 | ZoneScope zone_scope(isolate, DELETE_ON_EXIT); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 585 | |
| 586 | // The VM is in the COMPILER state until exiting this function. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 587 | VMState state(isolate, COMPILER); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 588 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 589 | PostponeInterruptsScope postpone(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 590 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 591 | Handle<SharedFunctionInfo> shared = info->shared_info(); |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 592 | int compiled_size = shared->end_position() - shared->start_position(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 593 | isolate->counters()->total_compile_size()->Increment(compiled_size); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 594 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 595 | // Generate the AST for the lazily compiled function. |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 596 | if (ParserApi::Parse(info)) { |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 597 | // Measure how long it takes to do the lazy compilation; only take the |
| 598 | // rest of the function into account to avoid overlap with the lazy |
| 599 | // parsing statistics. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 600 | HistogramTimerScope timer(isolate->counters()->compile_lazy()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 601 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 602 | // After parsing we know function's strict mode. Remember it. |
| 603 | if (info->function()->strict_mode()) { |
| 604 | shared->set_strict_mode(true); |
| 605 | info->MarkAsStrictMode(); |
| 606 | } |
| 607 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 608 | // Compile the code. |
| 609 | if (!MakeCode(info)) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 610 | if (!isolate->has_pending_exception()) { |
| 611 | isolate->StackOverflow(); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 612 | } |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 613 | } else { |
| 614 | ASSERT(!info->code().is_null()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 615 | Handle<Code> code = info->code(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 616 | // Set optimizable to false if this is disallowed by the shared |
| 617 | // function info, e.g., we might have flushed the code and must |
| 618 | // reset this bit when lazy compiling the code again. |
| 619 | if (shared->optimization_disabled()) code->set_optimizable(false); |
| 620 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 621 | Handle<JSFunction> function = info->closure(); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 622 | RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 623 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 624 | if (info->IsOptimizing()) { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 625 | ASSERT(shared->scope_info() != SerializedScopeInfo::Empty()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 626 | function->ReplaceCode(*code); |
| 627 | } else { |
| 628 | // Update the shared function info with the compiled code and the |
| 629 | // scope info. Please note, that the order of the shared function |
| 630 | // info initialization is important since set_scope_info might |
| 631 | // trigger a GC, causing the ASSERT below to be invalid if the code |
| 632 | // was flushed. By settting the code object last we avoid this. |
| 633 | Handle<SerializedScopeInfo> scope_info = |
| 634 | SerializedScopeInfo::Create(info->scope()); |
| 635 | shared->set_scope_info(*scope_info); |
| 636 | shared->set_code(*code); |
| 637 | if (!function.is_null()) { |
| 638 | function->ReplaceCode(*code); |
| 639 | ASSERT(!function->IsOptimized()); |
| 640 | } |
| 641 | |
| 642 | // Set the expected number of properties for instances. |
| 643 | FunctionLiteral* lit = info->function(); |
| 644 | int expected = lit->expected_property_count(); |
| 645 | SetExpectedNofPropertiesFromEstimate(shared, expected); |
| 646 | |
| 647 | // Set the optimization hints after performing lazy compilation, as |
| 648 | // these are not set when the function is set up as a lazily |
| 649 | // compiled function. |
| 650 | shared->SetThisPropertyAssignmentsInfo( |
| 651 | lit->has_only_simple_this_property_assignments(), |
| 652 | *lit->this_property_assignments()); |
| 653 | |
| 654 | // Check the function has compiled code. |
| 655 | ASSERT(shared->is_compiled()); |
| 656 | shared->set_code_age(0); |
| 657 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 658 | if (info->AllowOptimize() && !shared->optimization_disabled()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 659 | // If we're asked to always optimize, we compile the optimized |
| 660 | // version of the function right away - unless the debugger is |
| 661 | // active as it makes no sense to compile optimized code then. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 662 | if (FLAG_always_opt && |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 663 | !Isolate::Current()->DebuggerHasBreakPoints()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 664 | CompilationInfo optimized(function); |
| 665 | optimized.SetOptimizing(AstNode::kNoNumber); |
| 666 | return CompileLazy(&optimized); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 667 | } |
| 668 | } |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 669 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 670 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 671 | return true; |
| 672 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 673 | } |
| 674 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 675 | ASSERT(info->code().is_null()); |
| 676 | return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 680 | Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal, |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 681 | Handle<Script> script) { |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 682 | // Precondition: code has been parsed and scopes have been analyzed. |
| 683 | CompilationInfo info(script); |
| 684 | info.SetFunction(literal); |
| 685 | info.SetScope(literal->scope()); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 686 | if (literal->scope()->is_strict_mode()) info.MarkAsStrictMode(); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 687 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 688 | LiveEditFunctionTracker live_edit_tracker(info.isolate(), literal); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 689 | // Determine if the function can be lazily compiled. This is necessary to |
| 690 | // allow some of our builtin JS files to be lazily compiled. These |
| 691 | // builtins cannot be handled lazily by the parser, since we have to know |
| 692 | // if a function uses the special natives syntax, which is something the |
| 693 | // parser records. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 694 | bool allow_lazy = literal->AllowsLazyCompilation() && |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 695 | !LiveEditFunctionTracker::IsActive(info.isolate()); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 696 | |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 697 | Handle<SerializedScopeInfo> scope_info(SerializedScopeInfo::Empty()); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 698 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 699 | // Generate code |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 700 | if (FLAG_lazy && allow_lazy) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 701 | Handle<Code> code = info.isolate()->builtins()->LazyCompile(); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 702 | info.SetCode(code); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 703 | } else if ((V8::UseCrankshaft() && MakeCrankshaftCode(&info)) || |
| 704 | (!V8::UseCrankshaft() && FullCodeGenerator::MakeCode(&info))) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 705 | ASSERT(!info.code().is_null()); |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 706 | scope_info = SerializedScopeInfo::Create(info.scope()); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 707 | } else { |
| 708 | return Handle<SharedFunctionInfo>::null(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 709 | } |
| 710 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 711 | // Create a shared function info object. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 712 | Handle<SharedFunctionInfo> result = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 713 | FACTORY->NewSharedFunctionInfo(literal->name(), |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 714 | literal->materialized_literal_count(), |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 715 | info.code(), |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 716 | scope_info); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 717 | SetFunctionInfo(result, literal, false, script); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 718 | RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 719 | result->set_allows_lazy_compilation(allow_lazy); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 720 | |
| 721 | // Set the expected number of properties for instances and return |
| 722 | // the resulting function. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 723 | SetExpectedNofPropertiesFromEstimate(result, |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 724 | literal->expected_property_count()); |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 725 | live_edit_tracker.RecordFunctionInfo(result, literal); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 726 | return result; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | |
| 730 | // Sets the function info on a function. |
| 731 | // The start_position points to the first '(' character after the function name |
| 732 | // in the full script source. When counting characters in the script source the |
| 733 | // the first character is number 0 (not 1). |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 734 | void Compiler::SetFunctionInfo(Handle<SharedFunctionInfo> function_info, |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 735 | FunctionLiteral* lit, |
| 736 | bool is_toplevel, |
| 737 | Handle<Script> script) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 738 | function_info->set_length(lit->num_parameters()); |
| 739 | function_info->set_formal_parameter_count(lit->num_parameters()); |
| 740 | function_info->set_script(*script); |
| 741 | function_info->set_function_token_position(lit->function_token_position()); |
| 742 | function_info->set_start_position(lit->start_position()); |
| 743 | function_info->set_end_position(lit->end_position()); |
| 744 | function_info->set_is_expression(lit->is_expression()); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 745 | function_info->set_is_anonymous(lit->is_anonymous()); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 746 | function_info->set_is_toplevel(is_toplevel); |
| 747 | function_info->set_inferred_name(*lit->inferred_name()); |
| 748 | function_info->SetThisPropertyAssignmentsInfo( |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 749 | lit->has_only_simple_this_property_assignments(), |
| 750 | *lit->this_property_assignments()); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 751 | function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 752 | function_info->set_strict_mode(lit->strict_mode()); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 753 | function_info->set_uses_arguments(lit->scope()->arguments() != NULL); |
| 754 | function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 758 | void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag, |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 759 | CompilationInfo* info, |
| 760 | Handle<SharedFunctionInfo> shared) { |
| 761 | // SharedFunctionInfo is passed separately, because if CompilationInfo |
| 762 | // was created using Script object, it will not have it. |
| 763 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 764 | // Log the code generation. If source information is available include |
| 765 | // script name and line number. Check explicitly whether logging is |
| 766 | // enabled as finding the line number is not free. |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 767 | if (info->isolate()->logger()->is_logging() || |
| 768 | CpuProfiler::is_profiling(info->isolate())) { |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 769 | Handle<Script> script = info->script(); |
| 770 | Handle<Code> code = info->code(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 771 | if (*code == info->isolate()->builtins()->builtin(Builtins::kLazyCompile)) |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 772 | return; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 773 | if (script->name()->IsString()) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 774 | int line_num = GetScriptLineNumber(script, shared->start_position()) + 1; |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 775 | USE(line_num); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 776 | PROFILE(info->isolate(), |
| 777 | CodeCreateEvent(Logger::ToNativeByScript(tag, *script), |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 778 | *code, |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 779 | *shared, |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 780 | String::cast(script->name()), |
| 781 | line_num)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 782 | } else { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 783 | PROFILE(info->isolate(), |
| 784 | CodeCreateEvent(Logger::ToNativeByScript(tag, *script), |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 785 | *code, |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 786 | *shared, |
| 787 | shared->DebugName())); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 788 | } |
| 789 | } |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 790 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 791 | GDBJIT(AddCode(Handle<String>(shared->DebugName()), |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 792 | Handle<Script>(info->script()), |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 793 | Handle<Code>(info->code()), |
| 794 | info)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 795 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 796 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 797 | } } // namespace v8::internal |