v8  3.11.10(node0.8.26)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
compiler.cc
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
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 
30 #include "compiler.h"
31 
32 #include "bootstrapper.h"
33 #include "codegen.h"
34 #include "compilation-cache.h"
35 #include "debug.h"
36 #include "full-codegen.h"
37 #include "gdb-jit.h"
38 #include "hydrogen.h"
39 #include "isolate-inl.h"
40 #include "lithium.h"
41 #include "liveedit.h"
42 #include "parser.h"
43 #include "rewriter.h"
44 #include "runtime-profiler.h"
46 #include "scopeinfo.h"
47 #include "scopes.h"
48 #include "vm-state-inl.h"
49 
50 namespace v8 {
51 namespace internal {
52 
53 
54 CompilationInfo::CompilationInfo(Handle<Script> script)
55  : isolate_(script->GetIsolate()),
56  flags_(LanguageModeField::encode(CLASSIC_MODE)),
57  function_(NULL),
58  scope_(NULL),
59  global_scope_(NULL),
60  script_(script),
61  extension_(NULL),
62  pre_parse_data_(NULL),
63  osr_ast_id_(AstNode::kNoNumber) {
64  Initialize(BASE);
65 }
66 
67 
68 CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info)
69  : isolate_(shared_info->GetIsolate()),
70  flags_(LanguageModeField::encode(CLASSIC_MODE) |
71  IsLazy::encode(true)),
72  function_(NULL),
73  scope_(NULL),
74  global_scope_(NULL),
75  shared_info_(shared_info),
76  script_(Handle<Script>(Script::cast(shared_info->script()))),
77  extension_(NULL),
78  pre_parse_data_(NULL),
79  osr_ast_id_(AstNode::kNoNumber) {
80  Initialize(BASE);
81 }
82 
83 
84 CompilationInfo::CompilationInfo(Handle<JSFunction> closure)
85  : isolate_(closure->GetIsolate()),
86  flags_(LanguageModeField::encode(CLASSIC_MODE) |
87  IsLazy::encode(true)),
88  function_(NULL),
89  scope_(NULL),
90  global_scope_(NULL),
91  closure_(closure),
92  shared_info_(Handle<SharedFunctionInfo>(closure->shared())),
93  script_(Handle<Script>(Script::cast(shared_info_->script()))),
94  extension_(NULL),
95  pre_parse_data_(NULL),
96  osr_ast_id_(AstNode::kNoNumber) {
97  Initialize(BASE);
98 }
99 
100 
101 // Disable optimization for the rest of the compilation pipeline.
102 void CompilationInfo::DisableOptimization() {
103  bool is_optimizable_closure =
104  FLAG_optimize_closures &&
105  closure_.is_null() &&
106  !scope_->HasTrivialOuterContext() &&
107  !scope_->outer_scope_calls_non_strict_eval() &&
108  !scope_->inside_with();
109  SetMode(is_optimizable_closure ? BASE : NONOPT);
110 }
111 
112 
113 // Primitive functions are unlikely to be picked up by the stack-walking
114 // profiler, so they trigger their own optimization when they're called
115 // for the SharedFunctionInfo::kCallsUntilPrimitiveOptimization-th time.
116 bool CompilationInfo::ShouldSelfOptimize() {
117  return FLAG_self_optimization &&
118  FLAG_crankshaft &&
119  !function()->flags()->Contains(kDontSelfOptimize) &&
120  !function()->flags()->Contains(kDontOptimize) &&
121  function()->scope()->AllowsLazyRecompilation() &&
122  (shared_info().is_null() || !shared_info()->optimization_disabled());
123 }
124 
125 
126 void CompilationInfo::AbortOptimization() {
127  Handle<Code> code(shared_info()->code());
128  SetCode(code);
129 }
130 
131 
132 // Determine whether to use the full compiler for all code. If the flag
133 // --always-full-compiler is specified this is the case. For the virtual frame
134 // based compiler the full compiler is also used if a debugger is connected, as
135 // the code from the full compiler supports mode precise break points. For the
136 // crankshaft adaptive compiler debugging the optimized code is not possible at
137 // all. However crankshaft support recompilation of functions, so in this case
138 // the full compiler need not be be used if a debugger is attached, but only if
139 // break points has actually been set.
140 static bool is_debugging_active() {
141 #ifdef ENABLE_DEBUGGER_SUPPORT
142  Isolate* isolate = Isolate::Current();
143  return V8::UseCrankshaft() ?
144  isolate->debug()->has_break_points() :
145  isolate->debugger()->IsDebuggerActive();
146 #else
147  return false;
148 #endif
149 }
150 
151 
152 static bool AlwaysFullCompiler() {
153  return FLAG_always_full_compiler || is_debugging_active();
154 }
155 
156 
157 static void FinishOptimization(Handle<JSFunction> function, int64_t start) {
158  int opt_count = function->shared()->opt_count();
159  function->shared()->set_opt_count(opt_count + 1);
160  double ms = static_cast<double>(OS::Ticks() - start) / 1000;
161  if (FLAG_trace_opt) {
162  PrintF("[optimizing: ");
163  function->PrintName();
164  PrintF(" / %" V8PRIxPTR, reinterpret_cast<intptr_t>(*function));
165  PrintF(" - took %0.3f ms]\n", ms);
166  }
167  if (FLAG_trace_opt_stats) {
168  static double compilation_time = 0.0;
169  static int compiled_functions = 0;
170  static int code_size = 0;
171 
172  compilation_time += ms;
173  compiled_functions++;
174  code_size += function->shared()->SourceSize();
175  PrintF("Compiled: %d functions with %d byte source size in %fms.\n",
176  compiled_functions,
177  code_size,
178  compilation_time);
179  }
180 }
181 
182 
183 static bool MakeCrankshaftCode(CompilationInfo* info) {
184  // Test if we can optimize this function when asked to. We can only
185  // do this after the scopes are computed.
186  if (!V8::UseCrankshaft()) {
187  info->DisableOptimization();
188  }
189 
190  // In case we are not optimizing simply return the code from
191  // the full code generator.
192  if (!info->IsOptimizing()) {
193  return FullCodeGenerator::MakeCode(info);
194  }
195 
196  // We should never arrive here if there is not code object on the
197  // shared function object.
198  Handle<Code> code(info->shared_info()->code());
199  ASSERT(code->kind() == Code::FUNCTION);
200 
201  // We should never arrive here if optimization has been disabled on the
202  // shared function info.
203  ASSERT(!info->shared_info()->optimization_disabled());
204 
205  // Fall back to using the full code generator if it's not possible
206  // to use the Hydrogen-based optimizing compiler. We already have
207  // generated code for this from the shared function object.
208  if (AlwaysFullCompiler()) {
209  info->SetCode(code);
210  return true;
211  }
212 
213  // Limit the number of times we re-compile a functions with
214  // the optimizing compiler.
215  const int kMaxOptCount =
216  FLAG_deopt_every_n_times == 0 ? Compiler::kDefaultMaxOptCount : 1000;
217  if (info->shared_info()->opt_count() > kMaxOptCount) {
218  info->AbortOptimization();
219  info->shared_info()->DisableOptimization();
220  // True indicates the compilation pipeline is still going, not
221  // necessarily that we optimized the code.
222  return true;
223  }
224 
225  // Due to an encoding limit on LUnallocated operands in the Lithium
226  // language, we cannot optimize functions with too many formal parameters
227  // or perform on-stack replacement for function with too many
228  // stack-allocated local variables.
229  //
230  // The encoding is as a signed value, with parameters and receiver using
231  // the negative indices and locals the non-negative ones.
232  const int parameter_limit = -LUnallocated::kMinFixedIndex;
233  const int locals_limit = LUnallocated::kMaxFixedIndex;
234  Scope* scope = info->scope();
235  if ((scope->num_parameters() + 1) > parameter_limit ||
236  (info->osr_ast_id() != AstNode::kNoNumber &&
237  scope->num_parameters() + 1 + scope->num_stack_slots() > locals_limit)) {
238  info->AbortOptimization();
239  info->shared_info()->DisableOptimization();
240  // True indicates the compilation pipeline is still going, not
241  // necessarily that we optimized the code.
242  return true;
243  }
244 
245  // Take --hydrogen-filter into account.
246  Handle<String> name = info->function()->debug_name();
247  if (*FLAG_hydrogen_filter != '\0') {
248  Vector<const char> filter = CStrVector(FLAG_hydrogen_filter);
249  if ((filter[0] == '-'
250  && name->IsEqualTo(filter.SubVector(1, filter.length())))
251  || (filter[0] != '-' && !name->IsEqualTo(filter))) {
252  info->SetCode(code);
253  return true;
254  }
255  }
256 
257  // Recompile the unoptimized version of the code if the current version
258  // doesn't have deoptimization support. Alternatively, we may decide to
259  // run the full code generator to get a baseline for the compile-time
260  // performance of the hydrogen-based compiler.
261  int64_t start = OS::Ticks();
262  bool should_recompile = !info->shared_info()->has_deoptimization_support();
263  if (should_recompile || FLAG_hydrogen_stats) {
264  HPhase phase(HPhase::kFullCodeGen);
265  CompilationInfo unoptimized(info->shared_info());
266  // Note that we use the same AST that we will use for generating the
267  // optimized code.
268  unoptimized.SetFunction(info->function());
269  unoptimized.SetScope(info->scope());
270  if (should_recompile) unoptimized.EnableDeoptimizationSupport();
271  bool succeeded = FullCodeGenerator::MakeCode(&unoptimized);
272  if (should_recompile) {
273  if (!succeeded) return false;
274  Handle<SharedFunctionInfo> shared = info->shared_info();
275  shared->EnableDeoptimizationSupport(*unoptimized.code());
276  // The existing unoptimized code was replaced with the new one.
278  Logger::LAZY_COMPILE_TAG, &unoptimized, shared);
279  }
280  }
281 
282  // Check that the unoptimized, shared code is ready for
283  // optimizations. When using the always_opt flag we disregard the
284  // optimizable marker in the code object and optimize anyway. This
285  // is safe as long as the unoptimized code has deoptimization
286  // support.
287  ASSERT(FLAG_always_opt || code->optimizable());
288  ASSERT(info->shared_info()->has_deoptimization_support());
289 
290  if (FLAG_trace_hydrogen) {
291  PrintF("-----------------------------------------------------------\n");
292  PrintF("Compiling method %s using hydrogen\n", *name->ToCString());
293  HTracer::Instance()->TraceCompilation(info->function());
294  }
295 
296  Handle<Context> global_context(info->closure()->context()->global_context());
297  TypeFeedbackOracle oracle(code, global_context, info->isolate(),
298  info->isolate()->zone());
299  HGraphBuilder builder(info, &oracle, info->isolate()->zone());
300  HPhase phase(HPhase::kTotal);
301  HGraph* graph = builder.CreateGraph();
302  if (info->isolate()->has_pending_exception()) {
303  info->SetCode(Handle<Code>::null());
304  return false;
305  }
306 
307  if (graph != NULL) {
308  Handle<Code> optimized_code = graph->Compile(info, graph->zone());
309  if (!optimized_code.is_null()) {
310  info->SetCode(optimized_code);
311  FinishOptimization(info->closure(), start);
312  return true;
313  }
314  }
315 
316  // Keep using the shared code.
317  info->AbortOptimization();
318  if (!builder.inline_bailout()) {
319  // Mark the shared code as unoptimizable unless it was an inlined
320  // function that bailed out.
321  info->shared_info()->DisableOptimization();
322  }
323  // True indicates the compilation pipeline is still going, not necessarily
324  // that we optimized the code.
325  return true;
326 }
327 
328 
329 static bool GenerateCode(CompilationInfo* info) {
330  return info->IsCompilingForDebugging() || !V8::UseCrankshaft() ?
332  MakeCrankshaftCode(info);
333 }
334 
335 
336 static bool MakeCode(CompilationInfo* info) {
337  // Precondition: code has been parsed. Postcondition: the code field in
338  // the compilation info is set if compilation succeeded.
339  ASSERT(info->function() != NULL);
340  return Rewriter::Rewrite(info) && Scope::Analyze(info) && GenerateCode(info);
341 }
342 
343 
344 #ifdef ENABLE_DEBUGGER_SUPPORT
345 bool Compiler::MakeCodeForLiveEdit(CompilationInfo* info) {
346  // Precondition: code has been parsed. Postcondition: the code field in
347  // the compilation info is set if compilation succeeded.
348  bool succeeded = MakeCode(info);
349  if (!info->shared_info().is_null()) {
350  Handle<ScopeInfo> scope_info = ScopeInfo::Create(info->scope(),
351  info->isolate()->zone());
352  info->shared_info()->set_scope_info(*scope_info);
353  }
354  return succeeded;
355 }
356 #endif
357 
358 
359 static Handle<SharedFunctionInfo> MakeFunctionInfo(CompilationInfo* info) {
360  Isolate* isolate = info->isolate();
361  ZoneScope zone_scope(isolate, DELETE_ON_EXIT);
362  PostponeInterruptsScope postpone(isolate);
363 
364  ASSERT(!isolate->global_context().is_null());
365  Handle<Script> script = info->script();
366  script->set_context_data((*isolate->global_context())->data());
367 
368 #ifdef ENABLE_DEBUGGER_SUPPORT
369  if (info->is_eval()) {
371  script->set_compilation_type(Smi::FromInt(compilation_type));
372  // For eval scripts add information on the function from which eval was
373  // called.
374  if (info->is_eval()) {
375  StackTraceFrameIterator it(isolate);
376  if (!it.done()) {
377  script->set_eval_from_shared(
378  JSFunction::cast(it.frame()->function())->shared());
379  Code* code = it.frame()->LookupCode();
380  int offset = static_cast<int>(
381  it.frame()->pc() - code->instruction_start());
382  script->set_eval_from_instructions_offset(Smi::FromInt(offset));
383  }
384  }
385  }
386 
387  // Notify debugger
388  isolate->debugger()->OnBeforeCompile(script);
389 #endif
390 
391  // Only allow non-global compiles for eval.
392  ASSERT(info->is_eval() || info->is_global());
394  if (info->pre_parse_data() != NULL ||
395  String::cast(script->source())->length() > FLAG_min_preparse_length) {
396  flags = kAllowLazy;
397  }
398  if (!ParserApi::Parse(info, flags)) {
400  }
401 
402  // Measure how long it takes to do the compilation; only take the
403  // rest of the function into account to avoid overlap with the
404  // parsing statistics.
405  HistogramTimer* rate = info->is_eval()
406  ? info->isolate()->counters()->compile_eval()
407  : info->isolate()->counters()->compile();
408  HistogramTimerScope timer(rate);
409 
410  // Compile the code.
411  FunctionLiteral* lit = info->function();
412  LiveEditFunctionTracker live_edit_tracker(isolate, lit);
413  if (!MakeCode(info)) {
414  if (!isolate->has_pending_exception()) isolate->StackOverflow();
416  }
417 
418  // Allocate function.
419  ASSERT(!info->code().is_null());
420  Handle<SharedFunctionInfo> result =
421  isolate->factory()->NewSharedFunctionInfo(
422  lit->name(),
423  lit->materialized_literal_count(),
424  info->code(),
425  ScopeInfo::Create(info->scope(), info->isolate()->zone()));
426 
427  ASSERT_EQ(RelocInfo::kNoPosition, lit->function_token_position());
428  Compiler::SetFunctionInfo(result, lit, true, script);
429 
430  if (script->name()->IsString()) {
431  PROFILE(isolate, CodeCreateEvent(
432  info->is_eval()
433  ? Logger::EVAL_TAG
434  : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script),
435  *info->code(),
436  *result,
437  String::cast(script->name())));
438  GDBJIT(AddCode(Handle<String>(String::cast(script->name())),
439  script,
440  info->code(),
441  info));
442  } else {
443  PROFILE(isolate, CodeCreateEvent(
444  info->is_eval()
445  ? Logger::EVAL_TAG
446  : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script),
447  *info->code(),
448  *result,
449  isolate->heap()->empty_string()));
450  GDBJIT(AddCode(Handle<String>(), script, info->code(), info));
451  }
452 
453  // Hint to the runtime system used when allocating space for initial
454  // property space by setting the expected number of properties for
455  // the instances of the function.
456  SetExpectedNofPropertiesFromEstimate(result, lit->expected_property_count());
457 
458  script->set_compilation_state(
460 
461 #ifdef ENABLE_DEBUGGER_SUPPORT
462  // Notify debugger
463  isolate->debugger()->OnAfterCompile(
464  script, Debugger::NO_AFTER_COMPILE_FLAGS);
465 #endif
466 
467  live_edit_tracker.RecordFunctionInfo(result, lit, isolate->zone());
468 
469  return result;
470 }
471 
472 
474  Handle<Object> script_name,
475  int line_offset,
476  int column_offset,
477  v8::Extension* extension,
478  ScriptDataImpl* pre_data,
479  Handle<Object> script_data,
480  NativesFlag natives) {
481  Isolate* isolate = source->GetIsolate();
482  int source_length = source->length();
483  isolate->counters()->total_load_size()->Increment(source_length);
484  isolate->counters()->total_compile_size()->Increment(source_length);
485 
486  // The VM is in the COMPILER state until exiting this function.
487  VMState state(isolate, COMPILER);
488 
489  CompilationCache* compilation_cache = isolate->compilation_cache();
490 
491  // Do a lookup in the compilation cache but not for extensions.
493  if (extension == NULL) {
494  result = compilation_cache->LookupScript(source,
495  script_name,
496  line_offset,
497  column_offset);
498  }
499 
500  if (result.is_null()) {
501  // No cache entry found. Do pre-parsing, if it makes sense, and compile
502  // the script.
503  // Building preparse data that is only used immediately after is only a
504  // saving if we might skip building the AST for lazily compiled functions.
505  // I.e., preparse data isn't relevant when the lazy flag is off, and
506  // for small sources, odds are that there aren't many functions
507  // that would be compiled lazily anyway, so we skip the preparse step
508  // in that case too.
509 
510  // Create a script object describing the script to be compiled.
511  Handle<Script> script = FACTORY->NewScript(source);
512  if (natives == NATIVES_CODE) {
513  script->set_type(Smi::FromInt(Script::TYPE_NATIVE));
514  }
515  if (!script_name.is_null()) {
516  script->set_name(*script_name);
517  script->set_line_offset(Smi::FromInt(line_offset));
518  script->set_column_offset(Smi::FromInt(column_offset));
519  }
520 
521  script->set_data(script_data.is_null() ? HEAP->undefined_value()
522  : *script_data);
523 
524  // Compile the function and add it to the cache.
525  CompilationInfo info(script);
526  info.MarkAsGlobal();
527  info.SetExtension(extension);
528  info.SetPreParseData(pre_data);
529  if (FLAG_use_strict) {
530  info.SetLanguageMode(FLAG_harmony_scoping ? EXTENDED_MODE : STRICT_MODE);
531  }
532  result = MakeFunctionInfo(&info);
533  if (extension == NULL && !result.is_null()) {
534  compilation_cache->PutScript(source, result);
535  }
536  } else {
537  if (result->ic_age() != HEAP->global_ic_age()) {
538  result->ResetForNewContext(HEAP->global_ic_age());
539  }
540  }
541 
542  if (result.is_null()) isolate->ReportPendingMessages();
543  return result;
544 }
545 
546 
548  Handle<Context> context,
549  bool is_global,
550  LanguageMode language_mode,
551  int scope_position) {
552  Isolate* isolate = source->GetIsolate();
553  int source_length = source->length();
554  isolate->counters()->total_eval_size()->Increment(source_length);
555  isolate->counters()->total_compile_size()->Increment(source_length);
556 
557  // The VM is in the COMPILER state until exiting this function.
558  VMState state(isolate, COMPILER);
559 
560  // Do a lookup in the compilation cache; if the entry is not there, invoke
561  // the compiler and add the result to the cache.
563  CompilationCache* compilation_cache = isolate->compilation_cache();
564  result = compilation_cache->LookupEval(source,
565  context,
566  is_global,
567  language_mode,
568  scope_position);
569 
570  if (result.is_null()) {
571  // Create a script object describing the script to be compiled.
572  Handle<Script> script = isolate->factory()->NewScript(source);
573  CompilationInfo info(script);
574  info.MarkAsEval();
575  if (is_global) info.MarkAsGlobal();
576  info.SetLanguageMode(language_mode);
577  info.SetCallingContext(context);
578  result = MakeFunctionInfo(&info);
579  if (!result.is_null()) {
580  // Explicitly disable optimization for eval code. We're not yet prepared
581  // to handle eval-code in the optimizing compiler.
582  result->DisableOptimization();
583 
584  // If caller is strict mode, the result must be in strict mode or
585  // extended mode as well, but not the other way around. Consider:
586  // eval("'use strict'; ...");
587  ASSERT(language_mode != STRICT_MODE || !result->is_classic_mode());
588  // If caller is in extended mode, the result must also be in
589  // extended mode.
590  ASSERT(language_mode != EXTENDED_MODE ||
591  result->is_extended_mode());
592  compilation_cache->PutEval(
593  source, context, is_global, result, scope_position);
594  }
595  } else {
596  if (result->ic_age() != HEAP->global_ic_age()) {
597  result->ResetForNewContext(HEAP->global_ic_age());
598  }
599  }
600 
601  return result;
602 }
603 
604 
605 bool Compiler::CompileLazy(CompilationInfo* info) {
606  Isolate* isolate = info->isolate();
607 
608  ZoneScope zone_scope(isolate, DELETE_ON_EXIT);
609 
610  // The VM is in the COMPILER state until exiting this function.
611  VMState state(isolate, COMPILER);
612 
613  PostponeInterruptsScope postpone(isolate);
614 
615  Handle<SharedFunctionInfo> shared = info->shared_info();
616  int compiled_size = shared->end_position() - shared->start_position();
617  isolate->counters()->total_compile_size()->Increment(compiled_size);
618 
619  // Generate the AST for the lazily compiled function.
620  if (ParserApi::Parse(info, kNoParsingFlags)) {
621  // Measure how long it takes to do the lazy compilation; only take the
622  // rest of the function into account to avoid overlap with the lazy
623  // parsing statistics.
624  HistogramTimerScope timer(isolate->counters()->compile_lazy());
625 
626  // After parsing we know the function's language mode. Remember it.
627  LanguageMode language_mode = info->function()->language_mode();
628  info->SetLanguageMode(language_mode);
629  shared->set_language_mode(language_mode);
630 
631  // Compile the code.
632  if (!MakeCode(info)) {
633  if (!isolate->has_pending_exception()) {
634  isolate->StackOverflow();
635  }
636  } else {
637  ASSERT(!info->code().is_null());
638  Handle<Code> code = info->code();
639  // Set optimizable to false if this is disallowed by the shared
640  // function info, e.g., we might have flushed the code and must
641  // reset this bit when lazy compiling the code again.
642  if (shared->optimization_disabled()) code->set_optimizable(false);
643 
644  Handle<JSFunction> function = info->closure();
645  RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared);
646 
647  if (info->IsOptimizing()) {
648  ASSERT(shared->scope_info() != ScopeInfo::Empty());
649  function->ReplaceCode(*code);
650  } else {
651  // Update the shared function info with the compiled code and the
652  // scope info. Please note, that the order of the shared function
653  // info initialization is important since set_scope_info might
654  // trigger a GC, causing the ASSERT below to be invalid if the code
655  // was flushed. By setting the code object last we avoid this.
656  Handle<ScopeInfo> scope_info =
657  ScopeInfo::Create(info->scope(), info->isolate()->zone());
658  shared->set_scope_info(*scope_info);
659  shared->set_code(*code);
660  if (!function.is_null()) {
661  function->ReplaceCode(*code);
662  ASSERT(!function->IsOptimized());
663  }
664 
665  // Set the expected number of properties for instances.
666  FunctionLiteral* lit = info->function();
667  int expected = lit->expected_property_count();
668  SetExpectedNofPropertiesFromEstimate(shared, expected);
669 
670  // Set the optimization hints after performing lazy compilation, as
671  // these are not set when the function is set up as a lazily
672  // compiled function.
673  shared->SetThisPropertyAssignmentsInfo(
675  *lit->this_property_assignments());
676 
677  // Check the function has compiled code.
678  ASSERT(shared->is_compiled());
679  shared->set_code_age(0);
680  shared->set_dont_optimize(lit->flags()->Contains(kDontOptimize));
681  shared->set_dont_inline(lit->flags()->Contains(kDontInline));
682  shared->set_ast_node_count(lit->ast_node_count());
683 
684  if (V8::UseCrankshaft()&&
685  !function.is_null() &&
686  !shared->optimization_disabled()) {
687  // If we're asked to always optimize, we compile the optimized
688  // version of the function right away - unless the debugger is
689  // active as it makes no sense to compile optimized code then.
690  if (FLAG_always_opt &&
691  !Isolate::Current()->DebuggerHasBreakPoints()) {
692  CompilationInfo optimized(function);
693  optimized.SetOptimizing(AstNode::kNoNumber);
694  return CompileLazy(&optimized);
695  }
696  }
697  }
698 
699  return true;
700  }
701  }
702 
703  ASSERT(info->code().is_null());
704  return false;
705 }
706 
707 
709  Handle<Script> script) {
710  // Precondition: code has been parsed and scopes have been analyzed.
711  CompilationInfo info(script);
712  info.SetFunction(literal);
713  info.SetScope(literal->scope());
714  info.SetLanguageMode(literal->scope()->language_mode());
715 
716  LiveEditFunctionTracker live_edit_tracker(info.isolate(), literal);
717  // Determine if the function can be lazily compiled. This is necessary to
718  // allow some of our builtin JS files to be lazily compiled. These
719  // builtins cannot be handled lazily by the parser, since we have to know
720  // if a function uses the special natives syntax, which is something the
721  // parser records.
722  bool allow_lazy = literal->AllowsLazyCompilation() &&
723  !LiveEditFunctionTracker::IsActive(info.isolate());
724 
725  Handle<ScopeInfo> scope_info(ScopeInfo::Empty());
726 
727  // Generate code
728  if (FLAG_lazy && allow_lazy) {
729  Handle<Code> code = info.isolate()->builtins()->LazyCompile();
730  info.SetCode(code);
731  } else if ((V8::UseCrankshaft() && MakeCrankshaftCode(&info)) ||
733  ASSERT(!info.code().is_null());
734  scope_info = ScopeInfo::Create(info.scope(), info.isolate()->zone());
735  } else {
737  }
738 
739  // Create a shared function info object.
741  FACTORY->NewSharedFunctionInfo(literal->name(),
742  literal->materialized_literal_count(),
743  info.code(),
744  scope_info);
745  SetFunctionInfo(result, literal, false, script);
746  RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result);
747  result->set_allows_lazy_compilation(allow_lazy);
748 
749  // Set the expected number of properties for instances and return
750  // the resulting function.
752  literal->expected_property_count());
753  live_edit_tracker.RecordFunctionInfo(result, literal, info.isolate()->zone());
754  return result;
755 }
756 
757 
758 // Sets the function info on a function.
759 // The start_position points to the first '(' character after the function name
760 // in the full script source. When counting characters in the script source the
761 // the first character is number 0 (not 1).
763  FunctionLiteral* lit,
764  bool is_toplevel,
765  Handle<Script> script) {
766  function_info->set_length(lit->parameter_count());
767  function_info->set_formal_parameter_count(lit->parameter_count());
768  function_info->set_script(*script);
769  function_info->set_function_token_position(lit->function_token_position());
770  function_info->set_start_position(lit->start_position());
771  function_info->set_end_position(lit->end_position());
772  function_info->set_is_expression(lit->is_expression());
773  function_info->set_is_anonymous(lit->is_anonymous());
774  function_info->set_is_toplevel(is_toplevel);
775  function_info->set_inferred_name(*lit->inferred_name());
776  function_info->SetThisPropertyAssignmentsInfo(
778  *lit->this_property_assignments());
779  function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation());
780  function_info->set_language_mode(lit->language_mode());
781  function_info->set_uses_arguments(lit->scope()->arguments() != NULL);
782  function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters());
783  function_info->set_ast_node_count(lit->ast_node_count());
784  function_info->set_is_function(lit->is_function());
785  function_info->set_dont_optimize(lit->flags()->Contains(kDontOptimize));
786  function_info->set_dont_inline(lit->flags()->Contains(kDontInline));
787 }
788 
789 
791  CompilationInfo* info,
793  // SharedFunctionInfo is passed separately, because if CompilationInfo
794  // was created using Script object, it will not have it.
795 
796  // Log the code generation. If source information is available include
797  // script name and line number. Check explicitly whether logging is
798  // enabled as finding the line number is not free.
799  if (info->isolate()->logger()->is_logging() ||
800  CpuProfiler::is_profiling(info->isolate())) {
801  Handle<Script> script = info->script();
802  Handle<Code> code = info->code();
803  if (*code == info->isolate()->builtins()->builtin(Builtins::kLazyCompile))
804  return;
805  if (script->name()->IsString()) {
806  int line_num = GetScriptLineNumber(script, shared->start_position()) + 1;
807  USE(line_num);
808  PROFILE(info->isolate(),
809  CodeCreateEvent(Logger::ToNativeByScript(tag, *script),
810  *code,
811  *shared,
812  String::cast(script->name()),
813  line_num));
814  } else {
815  PROFILE(info->isolate(),
816  CodeCreateEvent(Logger::ToNativeByScript(tag, *script),
817  *code,
818  *shared,
819  shared->DebugName()));
820  }
821  }
822 
823  GDBJIT(AddCode(Handle<String>(shared->DebugName()),
824  Handle<Script>(info->script()),
825  Handle<Code>(info->code()),
826  info));
827 }
828 
829 } } // namespace v8::internal
Failure * StackOverflow()
Definition: isolate.cc:897
Handle< FixedArray > this_property_assignments()
Definition: ast.h:2062
static const int kDefaultMaxOptCount
Definition: compiler.h:276
static bool IsActive(Isolate *isolate)
Definition: liveedit.cc:1827
#define V8PRIxPTR
Definition: globals.h:204
CompilationCache * compilation_cache()
Definition: isolate.h:812
void PrintF(const char *format,...)
Definition: v8utils.cc:40
static String * cast(Object *obj)
static bool UseCrankshaft()
Definition: v8.h:86
static int64_t Ticks()
static Smi * FromInt(int value)
Definition: objects-inl.h:973
static bool MakeCode(CompilationInfo *info)
Handle< Script > NewScript(Handle< String > source)
Definition: factory.cc:366
value format" "after each garbage collection") DEFINE_bool(print_cumulative_gc_stat, false, "print cumulative GC statistics in name=value format on exit") DEFINE_bool(trace_gc_verbose, false, "print more details following each garbage collection") DEFINE_bool(trace_fragmentation, false, "report fragmentation for old pointer and data pages") DEFINE_bool(collect_maps, true, "garbage collect maps from which no objects can be reached") DEFINE_bool(flush_code, true, "flush code that we expect not to use again before full gc") DEFINE_bool(incremental_marking, true, "use incremental marking") DEFINE_bool(incremental_marking_steps, true, "do incremental marking steps") DEFINE_bool(trace_incremental_marking, false, "trace progress of the incremental marking") DEFINE_bool(use_idle_notification, true, "Use idle notification to reduce memory footprint.") DEFINE_bool(send_idle_notification, false, "Send idle notifcation between stress runs.") DEFINE_bool(use_ic, true, "use inline caching") DEFINE_bool(native_code_counters, false, "generate extra code for manipulating stats counters") DEFINE_bool(always_compact, false, "Perform compaction on every full GC") DEFINE_bool(lazy_sweeping, true, "Use lazy sweeping for old pointer and data spaces") DEFINE_bool(never_compact, false, "Never perform compaction on full GC-testing only") DEFINE_bool(compact_code_space, true, "Compact code space on full non-incremental collections") DEFINE_bool(cleanup_code_caches_at_gc, true, "Flush inline caches prior to mark compact collection and" "flush code caches in maps during mark compact cycle.") DEFINE_int(random_seed, 0, "Default seed for initializing random generator" "(0, the default, means to use system random).") DEFINE_bool(use_verbose_printer, true, "allows verbose printing") DEFINE_bool(allow_natives_syntax, false, "allow natives syntax") DEFINE_bool(trace_sim, false, "Trace simulator execution") DEFINE_bool(check_icache, false, "Check icache flushes in ARM and MIPS simulator") DEFINE_int(stop_sim_at, 0, "Simulator stop after x number of instructions") DEFINE_int(sim_stack_alignment, 8, "Stack alingment in bytes in simulator(4 or 8, 8 is default)") DEFINE_bool(trace_exception, false, "print stack trace when throwing exceptions") DEFINE_bool(preallocate_message_memory, false, "preallocate some memory to build stack traces.") DEFINE_bool(randomize_hashes, true, "randomize hashes to avoid predictable hash collisions" "(with snapshots this option cannot override the baked-in seed)") DEFINE_int(hash_seed, 0, "Fixed seed to use to hash property keys(0 means random)" "(with snapshots this option cannot override the baked-in seed)") DEFINE_bool(preemption, false, "activate a 100ms timer that switches between V8 threads") DEFINE_bool(regexp_optimization, true, "generate optimized regexp code") DEFINE_bool(testing_bool_flag, true, "testing_bool_flag") DEFINE_int(testing_int_flag, 13, "testing_int_flag") DEFINE_float(testing_float_flag, 2.5, "float-flag") DEFINE_string(testing_string_flag, "Hello, world!", "string-flag") DEFINE_int(testing_prng_seed, 42, "Seed used for threading test randomness") DEFINE_string(testing_serialization_file, "/tmp/serdes", "file in which to serialize heap") DEFINE_bool(help, false, "Print usage message, including flags, on console") DEFINE_bool(dump_counters, false, "Dump counters on exit") DEFINE_string(map_counters, "", "Map counters to a file") DEFINE_args(js_arguments, JSARGUMENTS_INIT, "Pass all remaining arguments to the script.Alias for\"--\".") DEFINE_bool(debug_compile_events, true,"Enable debugger compile events") DEFINE_bool(debug_script_collected_events, true,"Enable debugger script collected events") DEFINE_bool(gdbjit, false,"enable GDBJIT interface (disables compacting GC)") DEFINE_bool(gdbjit_full, false,"enable GDBJIT interface for all code objects") DEFINE_bool(gdbjit_dump, false,"dump elf objects with debug info to disk") DEFINE_string(gdbjit_dump_filter,"","dump only objects containing this substring") DEFINE_bool(force_marking_deque_overflows, false,"force overflows of marking deque by reducing it's size ""to 64 words") DEFINE_bool(stress_compaction, false,"stress the GC compactor to flush out bugs (implies ""--force_marking_deque_overflows)")#define FLAG DEFINE_bool(enable_slow_asserts, false,"enable asserts that are slow to execute") DEFINE_bool(trace_codegen, false,"print name of functions for which code is generated") DEFINE_bool(print_source, false,"pretty print source code") DEFINE_bool(print_builtin_source, false,"pretty print source code for builtins") DEFINE_bool(print_ast, false,"print source AST") DEFINE_bool(print_builtin_ast, false,"print source AST for builtins") DEFINE_string(stop_at,"","function name where to insert a breakpoint") DEFINE_bool(print_builtin_scopes, false,"print scopes for builtins") DEFINE_bool(print_scopes, false,"print scopes") DEFINE_bool(trace_contexts, false,"trace contexts operations") DEFINE_bool(gc_greedy, false,"perform GC prior to some allocations") DEFINE_bool(gc_verbose, false,"print stuff during garbage collection") DEFINE_bool(heap_stats, false,"report heap statistics before and after GC") DEFINE_bool(code_stats, false,"report code statistics after GC") DEFINE_bool(verify_heap, false,"verify heap pointers before and after GC") DEFINE_bool(print_handles, false,"report handles after GC") DEFINE_bool(print_global_handles, false,"report global handles after GC") DEFINE_bool(trace_ic, false,"trace inline cache state transitions") DEFINE_bool(print_interfaces, false,"print interfaces") DEFINE_bool(print_interface_details, false,"print interface inference details") DEFINE_int(print_interface_depth, 5,"depth for printing interfaces") DEFINE_bool(trace_normalization, false,"prints when objects are turned into dictionaries.") DEFINE_bool(trace_lazy, false,"trace lazy compilation") DEFINE_bool(collect_heap_spill_statistics, false,"report heap spill statistics along with heap_stats ""(requires heap_stats)") DEFINE_bool(trace_isolates, false,"trace isolate state changes") DEFINE_bool(log_state_changes, false,"Log state changes.") DEFINE_bool(regexp_possessive_quantifier, false,"enable possessive quantifier syntax for testing") DEFINE_bool(trace_regexp_bytecodes, false,"trace regexp bytecode execution") DEFINE_bool(trace_regexp_assembler, false,"trace regexp macro assembler calls.")#define FLAG DEFINE_bool(log, false,"Minimal logging (no API, code, GC, suspect, or handles samples).") DEFINE_bool(log_all, false,"Log all events to the log file.") DEFINE_bool(log_runtime, false,"Activate runtime system %Log call.") DEFINE_bool(log_api, false,"Log API events to the log file.") DEFINE_bool(log_code, false,"Log code events to the log file without profiling.") DEFINE_bool(log_gc, false,"Log heap samples on garbage collection for the hp2ps tool.") DEFINE_bool(log_handles, false,"Log global handle events.") DEFINE_bool(log_snapshot_positions, false,"log positions of (de)serialized objects in the snapshot.") DEFINE_bool(log_suspect, false,"Log suspect operations.") DEFINE_bool(prof, false,"Log statistical profiling information (implies --log-code).") DEFINE_bool(prof_auto, true,"Used with --prof, starts profiling automatically") DEFINE_bool(prof_lazy, false,"Used with --prof, only does sampling and logging"" when profiler is active (implies --noprof_auto).") DEFINE_bool(prof_browser_mode, true,"Used with --prof, turns on browser-compatible mode for profiling.") DEFINE_bool(log_regexp, false,"Log regular expression execution.") DEFINE_bool(sliding_state_window, false,"Update sliding state window counters.") DEFINE_string(logfile,"v8.log","Specify the name of the log file.") DEFINE_bool(ll_prof, false,"Enable low-level linux profiler.")#define FLAG DEFINE_bool(trace_elements_transitions, false,"trace elements transitions") DEFINE_bool(print_code_stubs, false,"print code stubs") DEFINE_bool(test_secondary_stub_cache, false,"test secondary stub cache by disabling the primary one") DEFINE_bool(test_primary_stub_cache, false,"test primary stub cache by disabling the secondary one") DEFINE_bool(print_code, false,"print generated code") DEFINE_bool(print_opt_code, false,"print optimized code") DEFINE_bool(print_unopt_code, false,"print unoptimized code before ""printing optimized code based on it") DEFINE_bool(print_code_verbose, false,"print more information for code") DEFINE_bool(print_builtin_code, false,"print generated code for builtins")#43"/Users/thlorenz/dev/dx/v8-perf/build/v8/src/flags.cc"2#define FLAG_MODE_DEFINE_DEFAULTS#1"/Users/thlorenz/dev/dx/v8-perf/build/v8/src/flag-definitions.h"1#define FLAG_FULL(ftype, ctype, nam, def, cmt)#define FLAG_READONLY(ftype, ctype, nam, def, cmt)#define DEFINE_implication(whenflag, thenflag)#define DEFINE_bool(nam, def, cmt)#define DEFINE_int(nam, def, cmt)#define DEFINE_float(nam, def, cmt)#define DEFINE_string(nam, def, cmt)#define DEFINE_args(nam, def, cmt)#define FLAG DEFINE_bool(use_strict, false,"enforce strict mode") DEFINE_bool(es5_readonly, false,"activate correct semantics for inheriting readonliness") DEFINE_bool(es52_globals, false,"activate new semantics for global var declarations") DEFINE_bool(harmony_typeof, false,"enable harmony semantics for typeof") DEFINE_bool(harmony_scoping, false,"enable harmony block scoping") DEFINE_bool(harmony_modules, false,"enable harmony modules (implies block scoping)") DEFINE_bool(harmony_proxies, false,"enable harmony proxies") DEFINE_bool(harmony_collections, false,"enable harmony collections (sets, maps, and weak maps)") DEFINE_bool(harmony, false,"enable all harmony features (except typeof)") DEFINE_implication(harmony, harmony_scoping) DEFINE_implication(harmony, harmony_modules) DEFINE_implication(harmony, harmony_proxies) DEFINE_implication(harmony, harmony_collections) DEFINE_implication(harmony_modules, harmony_scoping) DEFINE_bool(packed_arrays, false,"optimizes arrays that have no holes") DEFINE_bool(smi_only_arrays, true,"tracks arrays with only smi values") DEFINE_bool(clever_optimizations, true,"Optimize object size, Array shift, DOM strings and string +") DEFINE_bool(unbox_double_arrays, true,"automatically unbox arrays of doubles") DEFINE_bool(string_slices, true,"use string slices") DEFINE_bool(crankshaft, true,"use crankshaft") DEFINE_string(hydrogen_filter,"","optimization filter") DEFINE_bool(use_range, true,"use hydrogen range analysis") DEFINE_bool(eliminate_dead_phis, true,"eliminate dead phis") DEFINE_bool(use_gvn, true,"use hydrogen global value numbering") DEFINE_bool(use_canonicalizing, true,"use hydrogen instruction canonicalizing") DEFINE_bool(use_inlining, true,"use function inlining") DEFINE_int(max_inlined_source_size, 600,"maximum source size in bytes considered for a single inlining") DEFINE_int(max_inlined_nodes, 196,"maximum number of AST nodes considered for a single inlining") DEFINE_int(max_inlined_nodes_cumulative, 196,"maximum cumulative number of AST nodes considered for inlining") DEFINE_bool(loop_invariant_code_motion, true,"loop invariant code motion") DEFINE_bool(collect_megamorphic_maps_from_stub_cache, true,"crankshaft harvests type feedback from stub cache") DEFINE_bool(hydrogen_stats, false,"print statistics for hydrogen") DEFINE_bool(trace_hydrogen, false,"trace generated hydrogen to file") DEFINE_string(trace_phase,"Z","trace generated IR for specified phases") DEFINE_bool(trace_inlining, false,"trace inlining decisions") DEFINE_bool(trace_alloc, false,"trace register allocator") DEFINE_bool(trace_all_uses, false,"trace all use positions") DEFINE_bool(trace_range, false,"trace range analysis") DEFINE_bool(trace_gvn, false,"trace global value numbering") DEFINE_bool(trace_representation, false,"trace representation types") DEFINE_bool(stress_pointer_maps, false,"pointer map for every instruction") DEFINE_bool(stress_environments, false,"environment for every instruction") DEFINE_int(deopt_every_n_times, 0,"deoptimize every n times a deopt point is passed") DEFINE_bool(trap_on_deopt, false,"put a break point before deoptimizing") DEFINE_bool(deoptimize_uncommon_cases, true,"deoptimize uncommon cases") DEFINE_bool(polymorphic_inlining, true,"polymorphic inlining") DEFINE_bool(use_osr, true,"use on-stack replacement") DEFINE_bool(array_bounds_checks_elimination, false,"perform array bounds checks elimination") DEFINE_bool(array_index_dehoisting, false,"perform array index dehoisting") DEFINE_bool(trace_osr, false,"trace on-stack replacement") DEFINE_int(stress_runs, 0,"number of stress runs") DEFINE_bool(optimize_closures, true,"optimize closures") DEFINE_bool(inline_construct, true,"inline constructor calls") DEFINE_bool(inline_arguments, true,"inline functions with arguments object") DEFINE_int(loop_weight, 1,"loop weight for representation inference") DEFINE_bool(optimize_for_in, true,"optimize functions containing for-in loops") DEFINE_bool(experimental_profiler, true,"enable all profiler experiments") DEFINE_bool(watch_ic_patching, false,"profiler considers IC stability") DEFINE_int(frame_count, 1,"number of stack frames inspected by the profiler") DEFINE_bool(self_optimization, false,"primitive functions trigger their own optimization") DEFINE_bool(direct_self_opt, false,"call recompile stub directly when self-optimizing") DEFINE_bool(retry_self_opt, false,"re-try self-optimization if it failed") DEFINE_bool(count_based_interrupts, false,"trigger profiler ticks based on counting instead of timing") DEFINE_bool(interrupt_at_exit, false,"insert an interrupt check at function exit") DEFINE_bool(weighted_back_edges, false,"weight back edges by jump distance for interrupt triggering") DEFINE_int(interrupt_budget, 5900,"execution budget before interrupt is triggered") DEFINE_int(type_info_threshold, 15,"percentage of ICs that must have type info to allow optimization") DEFINE_int(self_opt_count, 130,"call count before self-optimization") DEFINE_implication(experimental_profiler, watch_ic_patching) DEFINE_implication(experimental_profiler, self_optimization) DEFINE_implication(experimental_profiler, retry_self_opt) DEFINE_implication(experimental_profiler, count_based_interrupts) DEFINE_implication(experimental_profiler, interrupt_at_exit) DEFINE_implication(experimental_profiler, weighted_back_edges) DEFINE_bool(trace_opt_verbose, false,"extra verbose compilation tracing") DEFINE_implication(trace_opt_verbose, trace_opt) DEFINE_bool(debug_code, false,"generate extra code (assertions) for debugging") DEFINE_bool(code_comments, false,"emit comments in code disassembly") DEFINE_bool(enable_sse2, true,"enable use of SSE2 instructions if available") DEFINE_bool(enable_sse3, true,"enable use of SSE3 instructions if available") DEFINE_bool(enable_sse4_1, true,"enable use of SSE4.1 instructions if available") DEFINE_bool(enable_cmov, true,"enable use of CMOV instruction if available") DEFINE_bool(enable_rdtsc, true,"enable use of RDTSC instruction if available") DEFINE_bool(enable_sahf, true,"enable use of SAHF instruction if available (X64 only)") DEFINE_bool(enable_vfp3, true,"enable use of VFP3 instructions if available - this implies ""enabling ARMv7 instructions (ARM only)") DEFINE_bool(enable_armv7, true,"enable use of ARMv7 instructions if available (ARM only)") DEFINE_bool(enable_fpu, true,"enable use of MIPS FPU instructions if available (MIPS only)") DEFINE_string(expose_natives_as, NULL,"expose natives in global object") DEFINE_string(expose_debug_as, NULL,"expose debug in global object") DEFINE_bool(expose_gc, false,"expose gc extension") DEFINE_bool(expose_externalize_string, false,"expose externalize string extension") DEFINE_int(stack_trace_limit, 10,"number of stack frames to capture") DEFINE_bool(builtins_in_stack_traces, false,"show built-in functions in stack traces") DEFINE_bool(disable_native_files, false,"disable builtin natives files") DEFINE_bool(inline_new, true,"use fast inline allocation") DEFINE_bool(stack_trace_on_abort, true,"print a stack trace if an assertion failure occurs") DEFINE_bool(trace, false,"trace function calls") DEFINE_bool(mask_constants_with_cookie, true,"use random jit cookie to mask large constants") DEFINE_bool(lazy, true,"use lazy compilation") DEFINE_bool(trace_opt, false,"trace lazy optimization") DEFINE_bool(trace_opt_stats, false,"trace lazy optimization statistics") DEFINE_bool(opt, true,"use adaptive optimizations") DEFINE_bool(always_opt, false,"always try to optimize functions") DEFINE_bool(prepare_always_opt, false,"prepare for turning on always opt") DEFINE_bool(trace_deopt, false,"trace deoptimization") DEFINE_int(min_preparse_length, 1024,"minimum length for automatic enable preparsing") DEFINE_bool(always_full_compiler, false,"try to use the dedicated run-once backend for all code") DEFINE_bool(trace_bailout, false,"print reasons for falling back to using the classic V8 backend") DEFINE_bool(compilation_cache, true,"enable compilation cache") DEFINE_bool(cache_prototype_transitions, true,"cache prototype transitions") DEFINE_bool(trace_debug_json, false,"trace debugging JSON request/response") DEFINE_bool(debugger_auto_break, true,"automatically set the debug break flag when debugger commands are ""in the queue") DEFINE_bool(enable_liveedit, true,"enable liveedit experimental feature") DEFINE_bool(break_on_abort, true,"always cause a debug break before aborting") DEFINE_int(stack_size, kPointerSize *123,"default size of stack region v8 is allowed to use (in kBytes)") DEFINE_int(max_stack_trace_source_length, 300,"maximum length of function source code printed in a stack trace.") DEFINE_bool(always_inline_smi_code, false,"always inline smi code in non-opt code") DEFINE_int(max_new_space_size, 0,"max size of the new generation (in kBytes)") DEFINE_int(max_old_space_size, 0,"max size of the old generation (in Mbytes)") DEFINE_int(max_executable_size, 0,"max size of executable memory (in Mbytes)") DEFINE_bool(gc_global, false,"always perform global GCs") DEFINE_int(gc_interval,-1,"garbage collect after <n> allocations") DEFINE_bool(trace_gc, false,"print one trace line following each garbage collection") DEFINE_bool(trace_gc_nvp, false,"print one detailed trace line in name=value format ""after each garbage collection") DEFINE_bool(print_cumulative_gc_stat, false,"print cumulative GC statistics in name=value format on exit") DEFINE_bool(trace_gc_verbose, false,"print more details following each garbage collection") DEFINE_bool(trace_fragmentation, false,"report fragmentation for old pointer and data pages") DEFINE_bool(collect_maps, true,"garbage collect maps from which no objects can be reached") DEFINE_bool(flush_code, true,"flush code that we expect not to use again before full gc") DEFINE_bool(incremental_marking, true,"use incremental marking") DEFINE_bool(incremental_marking_steps, true,"do incremental marking steps") DEFINE_bool(trace_incremental_marking, false,"trace progress of the incremental marking") DEFINE_bool(use_idle_notification, true,"Use idle notification to reduce memory footprint.") DEFINE_bool(send_idle_notification, false,"Send idle notifcation between stress runs.") DEFINE_bool(use_ic, true,"use inline caching") DEFINE_bool(native_code_counters, false,"generate extra code for manipulating stats counters") DEFINE_bool(always_compact, false,"Perform compaction on every full GC") DEFINE_bool(lazy_sweeping, true,"Use lazy sweeping for old pointer and data spaces") DEFINE_bool(never_compact, false,"Never perform compaction on full GC - testing only") DEFINE_bool(compact_code_space, true,"Compact code space on full non-incremental collections") DEFINE_bool(cleanup_code_caches_at_gc, true,"Flush inline caches prior to mark compact collection and ""flush code caches in maps during mark compact cycle.") DEFINE_int(random_seed, 0,"Default seed for initializing random generator ""(0, the default, means to use system random).") DEFINE_bool(use_verbose_printer, true,"allows verbose printing") DEFINE_bool(allow_natives_syntax, false,"allow natives syntax") DEFINE_bool(trace_sim, false,"Trace simulator execution") DEFINE_bool(check_icache, false,"Check icache flushes in ARM and MIPS simulator") DEFINE_int(stop_sim_at, 0,"Simulator stop after x number of instructions") DEFINE_int(sim_stack_alignment, 8,"Stack alingment in bytes in simulator (4 or 8, 8 is default)") DEFINE_bool(trace_exception, false,"print stack trace when throwing exceptions") DEFINE_bool(preallocate_message_memory, false,"preallocate some memory to build stack traces.") DEFINE_bool(randomize_hashes, true,"randomize hashes to avoid predictable hash collisions ""(with snapshots this option cannot override the baked-in seed)") DEFINE_int(hash_seed, 0,"Fixed seed to use to hash property keys (0 means random)""(with snapshots this option cannot override the baked-in seed)") DEFINE_bool(preemption, false,"activate a 100ms timer that switches between V8 threads") DEFINE_bool(regexp_optimization, true,"generate optimized regexp code") DEFINE_bool(testing_bool_flag, true,"testing_bool_flag") DEFINE_int(testing_int_flag, 13,"testing_int_flag") DEFINE_float(testing_float_flag, 2.5,"float-flag") DEFINE_string(testing_string_flag,"Hello, world!","string-flag") DEFINE_int(testing_prng_seed, 42,"Seed used for threading test randomness") DEFINE_string(testing_serialization_file,"/tmp/serdes","file in which to serialize heap") DEFINE_bool(help, false,"Print usage message, including flags, on console") DEFINE_bool(dump_counters, false,"Dump counters on exit") DEFINE_string(map_counters,"","Map counters to a file") DEFINE_args(js_arguments, JSARGUMENTS_INIT,"Pass all remaining arguments to the script. Alias for \"--\".") DEFINE_bool(debug_compile_events, true,"Enable debugger compile events") DEFINE_bool(debug_script_collected_events, true,"Enable debugger script collected events") DEFINE_bool(gdbjit, false,"enable GDBJIT interface (disables compacting GC)") DEFINE_bool(gdbjit_full, false,"enable GDBJIT interface for all code objects") DEFINE_bool(gdbjit_dump, false,"dump elf objects with debug info to disk") DEFINE_string(gdbjit_dump_filter,"","dump only objects containing this substring") DEFINE_bool(force_marking_deque_overflows, false,"force overflows of marking deque by reducing it's size ""to 64 words") DEFINE_bool(stress_compaction, false,"stress the GC compactor to flush out bugs (implies ""--force_marking_deque_overflows)")#define FLAG DEFINE_bool(enable_slow_asserts, false,"enable asserts that are slow to execute") DEFINE_bool(trace_codegen, false,"print name of functions for which code is generated") DEFINE_bool(print_source, false,"pretty print source code") DEFINE_bool(print_builtin_source, false,"pretty print source code for builtins") DEFINE_bool(print_ast, false,"print source AST") DEFINE_bool(print_builtin_ast, false,"print source AST for builtins") DEFINE_string(stop_at,"","function name where to insert a breakpoint") DEFINE_bool(print_builtin_scopes, false,"print scopes for builtins") DEFINE_bool(print_scopes, false,"print scopes") DEFINE_bool(trace_contexts, false,"trace contexts operations") DEFINE_bool(gc_greedy, false,"perform GC prior to some allocations") DEFINE_bool(gc_verbose, false,"print stuff during garbage collection") DEFINE_bool(heap_stats, false,"report heap statistics before and after GC") DEFINE_bool(code_stats, false,"report code statistics after GC") DEFINE_bool(verify_heap, false,"verify heap pointers before and after GC") DEFINE_bool(print_handles, false,"report handles after GC") DEFINE_bool(print_global_handles, false,"report global handles after GC") DEFINE_bool(trace_ic, false,"trace inline cache state transitions") DEFINE_bool(print_interfaces, false,"print interfaces") DEFINE_bool(print_interface_details, false,"print interface inference details") DEFINE_int(print_interface_depth, 5,"depth for printing interfaces") DEFINE_bool(trace_normalization, false,"prints when objects are turned into dictionaries.") DEFINE_bool(trace_lazy, false,"trace lazy compilation") DEFINE_bool(collect_heap_spill_statistics, false,"report heap spill statistics along with heap_stats ""(requires heap_stats)") DEFINE_bool(trace_isolates, false,"trace isolate state changes") DEFINE_bool(log_state_changes, false,"Log state changes.") DEFINE_bool(regexp_possessive_quantifier, false,"enable possessive quantifier syntax for testing") DEFINE_bool(trace_regexp_bytecodes, false,"trace regexp bytecode execution") DEFINE_bool(trace_regexp_assembler, false,"trace regexp macro assembler calls.")#define FLAG DEFINE_bool(log, false,"Minimal logging (no API, code, GC, suspect, or handles samples).") DEFINE_bool(log_all, false,"Log all events to the log file.") DEFINE_bool(log_runtime, false,"Activate runtime system %Log call.") DEFINE_bool(log_api, false,"Log API events to the log file.") DEFINE_bool(log_code, false,"Log code events to the log file without profiling.") DEFINE_bool(log_gc, false,"Log heap samples on garbage collection for the hp2ps tool.") DEFINE_bool(log_handles, false,"Log global handle events.") DEFINE_bool(log_snapshot_positions, false,"log positions of (de)serialized objects in the snapshot.") DEFINE_bool(log_suspect, false,"Log suspect operations.") DEFINE_bool(prof, false,"Log statistical profiling information (implies --log-code).") DEFINE_bool(prof_auto, true,"Used with --prof, starts profiling automatically") DEFINE_bool(prof_lazy, false,"Used with --prof, only does sampling and logging"" when profiler is active (implies --noprof_auto).") DEFINE_bool(prof_browser_mode, true,"Used with --prof, turns on browser-compatible mode for profiling.") DEFINE_bool(log_regexp, false,"Log regular expression execution.") DEFINE_bool(sliding_state_window, false,"Update sliding state window counters.") DEFINE_string(logfile,"v8.log","Specify the name of the log file.") DEFINE_bool(ll_prof, false,"Enable low-level linux profiler.")#define FLAG DEFINE_bool(trace_elements_transitions, false,"trace elements transitions") DEFINE_bool(print_code_stubs, false,"print code stubs") DEFINE_bool(test_secondary_stub_cache, false,"test secondary stub cache by disabling the primary one") DEFINE_bool(test_primary_stub_cache, false,"test primary stub cache by disabling the secondary one") DEFINE_bool(print_code, false,"print generated code") DEFINE_bool(print_opt_code, false,"print optimized code") DEFINE_bool(print_unopt_code, false,"print unoptimized code before ""printing optimized code based on it") DEFINE_bool(print_code_verbose, false,"print more information for code") DEFINE_bool(print_builtin_code, false,"print generated code for builtins")#47"/Users/thlorenz/dev/dx/v8-perf/build/v8/src/flags.cc"2 namespace{struct Flag{enum FlagType{TYPE_BOOL, TYPE_INT, TYPE_FLOAT, TYPE_STRING, TYPE_ARGS} name
Definition: flags.cc:1349
static bool Analyze(CompilationInfo *info)
Definition: scopes.cc:263
bool is_expression() const
Definition: ast.h:2051
Flag flags[]
Definition: flags.cc:1467
static const int kNoNumber
Definition: ast.h:197
#define ASSERT(condition)
Definition: checks.h:270
#define PROFILE(isolate, Call)
Definition: cpu-profiler.h:190
void PutEval(Handle< String > source, Handle< Context > context, bool is_global, Handle< SharedFunctionInfo > function_info, int scope_position)
bool has_only_simple_this_property_assignments()
Definition: ast.h:2059
Factory * factory()
Definition: isolate.h:977
static Handle< SharedFunctionInfo > CompileEval(Handle< String > source, Handle< Context > context, bool is_global, LanguageMode language_mode, int scope_position)
Definition: compiler.cc:547
static Handle< ScopeInfo > Create(Scope *scope, Zone *zone)
Definition: scopeinfo.cc:41
static bool Parse(CompilationInfo *info, int flags)
Definition: parser.cc:6026
Handle< SharedFunctionInfo > LookupEval(Handle< String > source, Handle< Context > context, bool is_global, LanguageMode language_mode, int scope_position)
void ReportPendingMessages()
Definition: isolate.cc:1203
Variable * arguments() const
Definition: scopes.h:338
LanguageMode language_mode() const
Definition: ast.cc:169
int end_position() const
Definition: ast.cc:164
int function_token_position() const
Definition: ast.h:2047
static HTracer * Instance()
Definition: hydrogen.h:1359
Handle< String > inferred_name() const
Definition: ast.h:2074
static void SetFunctionInfo(Handle< SharedFunctionInfo > function_info, FunctionLiteral *lit, bool is_toplevel, Handle< Script > script)
Definition: compiler.cc:762
bool has_pending_exception()
Definition: isolate.h:554
static ScopeInfo * Empty()
Definition: scopeinfo.cc:152
Vector< const char > CStrVector(const char *data)
Definition: utils.h:525
bool is_anonymous() const
Definition: ast.h:2052
static const int kMaxFixedIndex
Definition: lithium.h:157
#define GDBJIT(action)
Definition: gdb-jit.h:141
Scope * scope() const
Definition: ast.h:2044
int GetScriptLineNumber(Handle< Script > script, int code_pos)
Definition: handles.cc:479
bool is_null() const
Definition: handles.h:87
static Handle< SharedFunctionInfo > Compile(Handle< String > source, Handle< Object > script_name, int line_offset, int column_offset, v8::Extension *extension, ScriptDataImpl *pre_data, Handle< Object > script_data, NativesFlag is_natives_code)
Definition: compiler.cc:473
int start_position() const
Definition: ast.cc:159
static Handle< T > null()
Definition: handles.h:86
#define HEAP
Definition: isolate.h:1408
#define ASSERT_EQ(v1, v2)
Definition: checks.h:271
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination trace on stack replacement optimize closures functions with arguments object optimize functions containing for in loops profiler considers IC stability primitive functions trigger their own optimization re try self optimization if it failed insert an interrupt check at function exit execution budget before interrupt is triggered call count before self optimization self_optimization count_based_interrupts weighted_back_edges trace_opt emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 enable use of ARMv7 instructions if enable use of MIPS FPU instructions if NULL
Definition: flags.cc:274
static Handle< SharedFunctionInfo > BuildFunctionInfo(FunctionLiteral *node, Handle< Script > script)
Definition: compiler.cc:708
void USE(T)
Definition: globals.h:303
Handle< String > name() const
Definition: ast.h:2043
Counters * counters()
Definition: isolate.h:804
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping true
Definition: flags.cc:157
AstProperties::Flags * flags()
Definition: ast.h:2089
static bool CompileLazy(CompilationInfo *info)
Definition: compiler.cc:605
#define FACTORY
Definition: isolate.h:1409
Handle< SharedFunctionInfo > LookupScript(Handle< String > source, Handle< Object > name, int line_offset, int column_offset)
LanguageMode language_mode() const
Definition: scopes.h:316
void SetExpectedNofPropertiesFromEstimate(Handle< SharedFunctionInfo > shared, int estimate)
Definition: handles.cc:201
void TraceCompilation(FunctionLiteral *function)
Definition: hydrogen.cc:8867
void PutScript(Handle< String > source, Handle< SharedFunctionInfo > function_info)
static const int kMinFixedIndex
Definition: lithium.h:158
static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, CompilationInfo *info, Handle< SharedFunctionInfo > shared)
Definition: compiler.cc:790
static bool Rewrite(CompilationInfo *info)
Definition: rewriter.cc:235
static JSFunction * cast(Object *obj)