V8 Project
v8::internal::OptimizedCompileJob Class Reference

#include <compiler.h>

+ Inheritance diagram for v8::internal::OptimizedCompileJob:
+ Collaboration diagram for v8::internal::OptimizedCompileJob:

Classes

struct  Timer
 

Public Types

enum  Status { FAILED , BAILED_OUT , SUCCEEDED }
 

Public Member Functions

 OptimizedCompileJob (CompilationInfo *info)
 
MUST_USE_RESULT Status CreateGraph ()
 
MUST_USE_RESULT Status OptimizeGraph ()
 
MUST_USE_RESULT Status GenerateCode ()
 
Status last_status () const
 
CompilationInfoinfo () const
 
Isolateisolate () const
 
Status RetryOptimization (BailoutReason reason)
 
Status AbortOptimization (BailoutReason reason)
 
void WaitForInstall ()
 
bool IsWaitingForInstall ()
 
- Public Member Functions inherited from v8::internal::ZoneObject
 INLINE (void *operator new(size_t size, Zone *zone))
 
void operator delete (void *, size_t)
 
void operator delete (void *pointer, Zone *zone)
 

Private Member Functions

MUST_USE_RESULT Status SetLastStatus (Status status)
 
void RecordOptimizationStats ()
 

Private Attributes

CompilationInfoinfo_
 
HOptimizedGraphBuildergraph_builder_
 
HGraph * graph_
 
LChunkchunk_
 
base::TimeDelta time_taken_to_create_graph_
 
base::TimeDelta time_taken_to_optimize_
 
base::TimeDelta time_taken_to_codegen_
 
Status last_status_
 
bool awaiting_install_
 

Detailed Description

Definition at line 582 of file compiler.h.

Member Enumeration Documentation

◆ Status

Enumerator
FAILED 
BAILED_OUT 
SUCCEEDED 

Definition at line 592 of file compiler.h.

Constructor & Destructor Documentation

◆ OptimizedCompileJob()

v8::internal::OptimizedCompileJob::OptimizedCompileJob ( CompilationInfo info)
inlineexplicit

Definition at line 584 of file compiler.h.

585  : info_(info),
587  graph_(NULL),
588  chunk_(NULL),
590  awaiting_install_(false) { }
HOptimizedGraphBuilder * graph_builder_
Definition: compiler.h:623
CompilationInfo * info() const
Definition: compiler.h:601
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL

Member Function Documentation

◆ AbortOptimization()

Status v8::internal::OptimizedCompileJob::AbortOptimization ( BailoutReason  reason)
inline

Definition at line 609 of file compiler.h.

609  {
610  info_->AbortOptimization(reason);
611  return SetLastStatus(BAILED_OUT);
612  }
void AbortOptimization(BailoutReason reason)
Definition: compiler.h:330
MUST_USE_RESULT Status SetLastStatus(Status status)
Definition: compiler.h:632

References v8::internal::CompilationInfo::AbortOptimization(), BAILED_OUT, info_, and SetLastStatus().

Referenced by CreateGraph(), and GenerateCode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CreateGraph()

OptimizedCompileJob::Status v8::internal::OptimizedCompileJob::CreateGraph ( )

Definition at line 325 of file compiler.cc.

325  {
326  DCHECK(info()->IsOptimizing());
327  DCHECK(!info()->IsCompilingForDebugging());
328 
329  // We should never arrive here if optimization has been disabled on the
330  // shared function info.
331  DCHECK(!info()->shared_info()->optimization_disabled());
332 
333  // Do not use crankshaft if we need to be able to set break points.
334  if (isolate()->DebuggerHasBreakPoints()) {
335  return RetryOptimization(kDebuggerHasBreakPoints);
336  }
337 
338  // Limit the number of times we re-compile a functions with
339  // the optimizing compiler.
340  const int kMaxOptCount =
341  FLAG_deopt_every_n_times == 0 ? FLAG_max_opt_count : 1000;
342  if (info()->opt_count() > kMaxOptCount) {
343  return AbortOptimization(kOptimizedTooManyTimes);
344  }
345 
346  // Due to an encoding limit on LUnallocated operands in the Lithium
347  // language, we cannot optimize functions with too many formal parameters
348  // or perform on-stack replacement for function with too many
349  // stack-allocated local variables.
350  //
351  // The encoding is as a signed value, with parameters and receiver using
352  // the negative indices and locals the non-negative ones.
353  const int parameter_limit = -LUnallocated::kMinFixedSlotIndex;
354  Scope* scope = info()->scope();
355  if ((scope->num_parameters() + 1) > parameter_limit) {
356  return AbortOptimization(kTooManyParameters);
357  }
358 
359  const int locals_limit = LUnallocated::kMaxFixedSlotIndex;
360  if (info()->is_osr() &&
361  scope->num_parameters() + 1 + scope->num_stack_slots() > locals_limit) {
362  return AbortOptimization(kTooManyParametersLocals);
363  }
364 
365  if (scope->HasIllegalRedeclaration()) {
366  return AbortOptimization(kFunctionWithIllegalRedeclaration);
367  }
368 
369  // Check the whitelist for Crankshaft.
370  if (!info()->closure()->PassesFilter(FLAG_hydrogen_filter)) {
371  return AbortOptimization(kHydrogenFilter);
372  }
373 
374  // Crankshaft requires a version of fullcode with deoptimization support.
375  // Recompile the unoptimized version of the code if the current version
376  // doesn't have deoptimization support already.
377  // Otherwise, if we are gathering compilation time and space statistics
378  // for hydrogen, gather baseline statistics for a fullcode compilation.
379  bool should_recompile = !info()->shared_info()->has_deoptimization_support();
380  if (should_recompile || FLAG_hydrogen_stats) {
381  base::ElapsedTimer timer;
382  if (FLAG_hydrogen_stats) {
383  timer.Start();
384  }
386  return SetLastStatus(FAILED);
387  }
388  if (FLAG_hydrogen_stats) {
389  isolate()->GetHStatistics()->IncrementFullCodeGen(timer.Elapsed());
390  }
391  }
392 
393  DCHECK(info()->shared_info()->has_deoptimization_support());
394 
395  // Check the whitelist for TurboFan.
396  if ((FLAG_turbo_asm && info()->shared_info()->asm_function()) ||
397  info()->closure()->PassesFilter(FLAG_turbo_filter)) {
398  compiler::Pipeline pipeline(info());
399  pipeline.GenerateCode();
400  if (!info()->code().is_null()) {
401  if (FLAG_turbo_deoptimization) {
402  info()->context()->native_context()->AddOptimizedCode(*info()->code());
403  }
404  return SetLastStatus(SUCCEEDED);
405  }
406  }
407 
408  if (FLAG_trace_hydrogen) {
409  Handle<String> name = info()->function()->debug_name();
410  PrintF("-----------------------------------------------------------\n");
411  PrintF("Compiling method %s using hydrogen\n", name->ToCString().get());
412  isolate()->GetHTracer()->TraceCompilation(info());
413  }
414 
415  // Type-check the function.
416  AstTyper::Run(info());
417 
418  graph_builder_ = (FLAG_hydrogen_track_positions || FLAG_trace_ic)
419  ? new(info()->zone()) HOptimizedGraphBuilderWithPositions(info())
420  : new(info()->zone()) HOptimizedGraphBuilder(info());
421 
422  Timer t(this, &time_taken_to_create_graph_);
423  info()->set_this_has_uses(false);
425 
426  if (isolate()->has_pending_exception()) {
427  return SetLastStatus(FAILED);
428  }
429 
430  if (graph_ == NULL) return SetLastStatus(BAILED_OUT);
431 
432  if (info()->HasAbortedDueToDependencyChange()) {
433  // Dependency has changed during graph creation. Let's try again later.
434  return RetryOptimization(kBailedOutDueToDependencyChange);
435  }
436 
437  return SetLastStatus(SUCCEEDED);
438 }
static void Run(CompilationInfo *info)
Definition: typing.cc:36
Handle< Context > context() const
Definition: compiler.h:127
void set_this_has_uses(bool has_no_uses)
Definition: compiler.h:150
FunctionLiteral * function() const
Definition: compiler.h:107
Handle< SharedFunctionInfo > shared_info() const
Definition: compiler.h:112
static bool EnsureDeoptimizationSupport(CompilationInfo *info)
Definition: compiler.cc:895
HTracer * GetHTracer()
Definition: isolate.cc:2148
HStatistics * GetHStatistics()
Definition: isolate.cc:2136
static const int kMinFixedSlotIndex
Definition: lithium.h:178
static const int kMaxFixedSlotIndex
Definition: lithium.h:177
Status AbortOptimization(BailoutReason reason)
Definition: compiler.h:609
base::TimeDelta time_taken_to_create_graph_
Definition: compiler.h:626
Status RetryOptimization(BailoutReason reason)
Definition: compiler.h:604
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in name
#define DCHECK(condition)
Definition: logging.h:205
void PrintF(const char *format,...)
Definition: utils.cc:80

References AbortOptimization(), BAILED_OUT, v8::internal::CompilationInfo::context(), v8::internal::HGraphBuilder::CreateGraph(), DCHECK, v8::internal::Compiler::EnsureDeoptimizationSupport(), FAILED, v8::internal::CompilationInfo::function(), v8::internal::compiler::Pipeline::GenerateCode(), v8::internal::Isolate::GetHStatistics(), v8::internal::Isolate::GetHTracer(), graph_, graph_builder_, v8::internal::Scope::HasIllegalRedeclaration(), info(), isolate(), v8::internal::LUnallocated::kMaxFixedSlotIndex, v8::internal::LUnallocated::kMinFixedSlotIndex, name, NULL, v8::internal::Scope::num_parameters(), v8::internal::Scope::num_stack_slots(), v8::internal::PrintF(), RetryOptimization(), v8::internal::AstTyper::Run(), v8::internal::CompilationInfo::scope(), v8::internal::CompilationInfo::set_this_has_uses(), SetLastStatus(), v8::internal::CompilationInfo::shared_info(), SUCCEEDED, time_taken_to_create_graph_, and v8::internal::CompilationInfo::zone().

Referenced by v8::internal::GetOptimizedCodeLater(), and v8::internal::GetOptimizedCodeNow().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GenerateCode()

OptimizedCompileJob::Status v8::internal::OptimizedCompileJob::GenerateCode ( )

Definition at line 468 of file compiler.cc.

468  {
470  // TODO(turbofan): Currently everything is done in the first phase.
471  if (!info()->code().is_null()) {
473  return last_status();
474  }
475 
476  DCHECK(!info()->HasAbortedDueToDependencyChange());
477  DisallowCodeDependencyChange no_dependency_change;
479  { // Scope for timer.
480  Timer timer(this, &time_taken_to_codegen_);
481  DCHECK(chunk_ != NULL);
482  DCHECK(graph_ != NULL);
483  // Deferred handles reference objects that were accessible during
484  // graph creation. To make sure that we don't encounter inconsistencies
485  // between graph creation and code generation, we disallow accessing
486  // objects through deferred handles during the latter, with exceptions.
487  DisallowDeferredHandleDereference no_deferred_handle_deref;
488  Handle<Code> optimized_code = chunk_->Codegen();
489  if (optimized_code.is_null()) {
490  if (info()->bailout_reason() == kNoReason) {
491  return AbortOptimization(kCodeGenerationFailed);
492  }
493  return SetLastStatus(BAILED_OUT);
494  }
495  info()->SetCode(optimized_code);
496  }
498  // Add to the weak list of optimized code objects.
499  info()->context()->native_context()->AddOptimizedCode(*info()->code());
500  return SetLastStatus(SUCCEEDED);
501 }
void SetCode(Handle< Code > code)
Definition: compiler.h:242
Handle< Code > Codegen()
Definition: lithium.cc:461
base::TimeDelta time_taken_to_codegen_
Definition: compiler.h:628
PerThreadAssertScopeDebugOnly< DEFERRED_HANDLE_DEREFERENCE_ASSERT, false > DisallowDeferredHandleDereference
Definition: assert-scope.h:126
PerThreadAssertScopeDebugOnly< CODE_DEPENDENCY_CHANGE_ASSERT, false > DisallowCodeDependencyChange
Definition: assert-scope.h:134
PerIsolateAssertScope< JAVASCRIPT_EXECUTION_ASSERT, false > DisallowJavascriptExecution
Definition: assert-scope.h:145

References AbortOptimization(), BAILED_OUT, chunk_, v8::internal::LChunk::Codegen(), v8::internal::CompilationInfo::context(), DCHECK, graph_, info(), v8::internal::Handle< T >::is_null(), isolate(), last_status(), NULL, RecordOptimizationStats(), v8::internal::CompilationInfo::SetCode(), SetLastStatus(), SUCCEEDED, and time_taken_to_codegen_.

Referenced by v8::internal::Compiler::GetConcurrentlyOptimizedCode(), and v8::internal::GetOptimizedCodeNow().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ info()

◆ isolate()

Isolate* v8::internal::OptimizedCompileJob::isolate ( ) const
inline

Definition at line 602 of file compiler.h.

602 { return info()->isolate(); }
Isolate * isolate() const
Definition: compiler.h:96

References info(), and v8::internal::CompilationInfo::isolate().

Referenced by CreateGraph(), GenerateCode(), and RecordOptimizationStats().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsWaitingForInstall()

bool v8::internal::OptimizedCompileJob::IsWaitingForInstall ( )
inline

Definition at line 619 of file compiler.h.

619 { return awaiting_install_; }

References awaiting_install_.

Referenced by v8::internal::OptimizingCompilerThread::AddToOsrBuffer(), v8::internal::DisposeOptimizedCompileJob(), v8::internal::OptimizingCompilerThread::FindReadyOSRCandidate(), and v8::internal::OptimizingCompilerThread::IsQueuedForOSR().

+ Here is the caller graph for this function:

◆ last_status()

Status v8::internal::OptimizedCompileJob::last_status ( ) const
inline

Definition at line 600 of file compiler.h.

600 { return last_status_; }

References last_status_.

Referenced by GenerateCode(), v8::internal::Compiler::GetConcurrentlyOptimizedCode(), and OptimizeGraph().

+ Here is the caller graph for this function:

◆ OptimizeGraph()

OptimizedCompileJob::Status v8::internal::OptimizedCompileJob::OptimizeGraph ( )

Definition at line 441 of file compiler.cc.

441  {
442  DisallowHeapAllocation no_allocation;
443  DisallowHandleAllocation no_handles;
444  DisallowHandleDereference no_deref;
445  DisallowCodeDependencyChange no_dependency_change;
446 
448  // TODO(turbofan): Currently everything is done in the first phase.
449  if (!info()->code().is_null()) {
450  return last_status();
451  }
452 
453  Timer t(this, &time_taken_to_optimize_);
454  DCHECK(graph_ != NULL);
455  BailoutReason bailout_reason = kNoReason;
456 
457  if (graph_->Optimize(&bailout_reason)) {
459  if (chunk_ != NULL) return SetLastStatus(SUCCEEDED);
460  } else if (bailout_reason != kNoReason) {
461  graph_builder_->Bailout(bailout_reason);
462  }
463 
464  return SetLastStatus(BAILED_OUT);
465 }
void Bailout(BailoutReason reason)
Definition: hydrogen.cc:4212
static LChunk * NewChunk(HGraph *graph)
Definition: lithium.cc:434
base::TimeDelta time_taken_to_optimize_
Definition: compiler.h:627
PerThreadAssertScopeDebugOnly< HEAP_ALLOCATION_ASSERT, false > DisallowHeapAllocation
Definition: assert-scope.h:110
PerThreadAssertScopeDebugOnly< HANDLE_DEREFERENCE_ASSERT, false > DisallowHandleDereference
Definition: assert-scope.h:118
PerThreadAssertScopeDebugOnly< HANDLE_ALLOCATION_ASSERT, false > DisallowHandleAllocation
Definition: assert-scope.h:102

References BAILED_OUT, v8::internal::HOptimizedGraphBuilder::Bailout(), chunk_, DCHECK, graph_, graph_builder_, info(), last_status(), v8::internal::LChunk::NewChunk(), NULL, SetLastStatus(), SUCCEEDED, and time_taken_to_optimize_.

Referenced by v8::internal::OptimizingCompilerThread::CompileNext(), and v8::internal::GetOptimizedCodeNow().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RecordOptimizationStats()

void v8::internal::OptimizedCompileJob::RecordOptimizationStats ( )
private

Definition at line 504 of file compiler.cc.

504  {
505  Handle<JSFunction> function = info()->closure();
506  if (!function->IsOptimized()) {
507  // Concurrent recompilation and OSR may race. Increment only once.
508  int opt_count = function->shared()->opt_count();
509  function->shared()->set_opt_count(opt_count + 1);
510  }
511  double ms_creategraph = time_taken_to_create_graph_.InMillisecondsF();
512  double ms_optimize = time_taken_to_optimize_.InMillisecondsF();
513  double ms_codegen = time_taken_to_codegen_.InMillisecondsF();
514  if (FLAG_trace_opt) {
515  PrintF("[optimizing ");
516  function->ShortPrint();
517  PrintF(" - took %0.3f, %0.3f, %0.3f ms]\n", ms_creategraph, ms_optimize,
518  ms_codegen);
519  }
520  if (FLAG_trace_opt_stats) {
521  static double compilation_time = 0.0;
522  static int compiled_functions = 0;
523  static int code_size = 0;
524 
525  compilation_time += (ms_creategraph + ms_optimize + ms_codegen);
526  compiled_functions++;
527  code_size += function->shared()->SourceSize();
528  PrintF("Compiled: %d functions with %d byte source size in %fms.\n",
529  compiled_functions,
530  code_size,
531  compilation_time);
532  }
533  if (FLAG_hydrogen_stats) {
534  isolate()->GetHStatistics()->IncrementSubtotals(time_taken_to_create_graph_,
537  }
538 }
Handle< JSFunction > closure() const
Definition: compiler.h:111

References v8::internal::CompilationInfo::closure(), v8::internal::Isolate::GetHStatistics(), info(), isolate(), v8::internal::PrintF(), time_taken_to_codegen_, time_taken_to_create_graph_, and time_taken_to_optimize_.

Referenced by GenerateCode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RetryOptimization()

Status v8::internal::OptimizedCompileJob::RetryOptimization ( BailoutReason  reason)
inline

Definition at line 604 of file compiler.h.

604  {
605  info_->RetryOptimization(reason);
606  return SetLastStatus(BAILED_OUT);
607  }
void RetryOptimization(BailoutReason reason)
Definition: compiler.h:335

References BAILED_OUT, info_, v8::internal::CompilationInfo::RetryOptimization(), and SetLastStatus().

Referenced by CreateGraph(), and v8::internal::Compiler::GetConcurrentlyOptimizedCode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetLastStatus()

MUST_USE_RESULT Status v8::internal::OptimizedCompileJob::SetLastStatus ( Status  status)
inlineprivate

Definition at line 632 of file compiler.h.

632  {
633  last_status_ = status;
634  return last_status_;
635  }

References last_status_.

Referenced by AbortOptimization(), CreateGraph(), GenerateCode(), OptimizeGraph(), and RetryOptimization().

+ Here is the caller graph for this function:

◆ WaitForInstall()

void v8::internal::OptimizedCompileJob::WaitForInstall ( )
inline

Definition at line 614 of file compiler.h.

614  {
615  DCHECK(info_->is_osr());
616  awaiting_install_ = true;
617  }

References awaiting_install_, DCHECK, info_, and v8::internal::CompilationInfo::is_osr().

Referenced by v8::internal::OptimizingCompilerThread::InstallOptimizedFunctions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ awaiting_install_

bool v8::internal::OptimizedCompileJob::awaiting_install_
private

Definition at line 630 of file compiler.h.

Referenced by IsWaitingForInstall(), and WaitForInstall().

◆ chunk_

LChunk* v8::internal::OptimizedCompileJob::chunk_
private

Definition at line 625 of file compiler.h.

Referenced by GenerateCode(), and OptimizeGraph().

◆ graph_

HGraph* v8::internal::OptimizedCompileJob::graph_
private

Definition at line 624 of file compiler.h.

Referenced by CreateGraph(), GenerateCode(), and OptimizeGraph().

◆ graph_builder_

HOptimizedGraphBuilder* v8::internal::OptimizedCompileJob::graph_builder_
private

Definition at line 623 of file compiler.h.

Referenced by CreateGraph(), and OptimizeGraph().

◆ info_

CompilationInfo* v8::internal::OptimizedCompileJob::info_
private

Definition at line 622 of file compiler.h.

Referenced by AbortOptimization(), info(), RetryOptimization(), and WaitForInstall().

◆ last_status_

Status v8::internal::OptimizedCompileJob::last_status_
private

Definition at line 629 of file compiler.h.

Referenced by last_status(), and SetLastStatus().

◆ time_taken_to_codegen_

base::TimeDelta v8::internal::OptimizedCompileJob::time_taken_to_codegen_
private

Definition at line 628 of file compiler.h.

Referenced by GenerateCode(), and RecordOptimizationStats().

◆ time_taken_to_create_graph_

base::TimeDelta v8::internal::OptimizedCompileJob::time_taken_to_create_graph_
private

Definition at line 626 of file compiler.h.

Referenced by CreateGraph(), and RecordOptimizationStats().

◆ time_taken_to_optimize_

base::TimeDelta v8::internal::OptimizedCompileJob::time_taken_to_optimize_
private

Definition at line 627 of file compiler.h.

Referenced by OptimizeGraph(), and RecordOptimizationStats().


The documentation for this class was generated from the following files: