V8 Project
v8::internal::Compiler Class Reference

#include <compiler.h>

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

Public Types

enum  ConcurrencyMode { NOT_CONCURRENT , CONCURRENT }
 

Static Public Member Functions

static MUST_USE_RESULT MaybeHandle< CodeGetUnoptimizedCode (Handle< JSFunction > function)
 
static MUST_USE_RESULT MaybeHandle< CodeGetLazyCode (Handle< JSFunction > function)
 
static MUST_USE_RESULT MaybeHandle< CodeGetUnoptimizedCode (Handle< SharedFunctionInfo > shared)
 
static MUST_USE_RESULT MaybeHandle< CodeGetDebugCode (Handle< JSFunction > function)
 
static bool EnsureCompiled (Handle< JSFunction > function, ClearExceptionFlag flag)
 
static bool EnsureDeoptimizationSupport (CompilationInfo *info)
 
static void CompileForLiveEdit (Handle< Script > script)
 
static MUST_USE_RESULT MaybeHandle< JSFunctionGetFunctionFromEval (Handle< String > source, Handle< Context > context, StrictMode strict_mode, ParseRestriction restriction, int scope_position)
 
static Handle< SharedFunctionInfoCompileScript (Handle< String > source, Handle< Object > script_name, int line_offset, int column_offset, bool is_shared_cross_origin, Handle< Context > context, v8::Extension *extension, ScriptData **cached_data, ScriptCompiler::CompileOptions compile_options, NativesFlag is_natives_code)
 
static Handle< SharedFunctionInfoCompileStreamedScript (CompilationInfo *info, int source_length)
 
static Handle< SharedFunctionInfoBuildFunctionInfo (FunctionLiteral *node, Handle< Script > script, CompilationInfo *outer)
 
static MUST_USE_RESULT MaybeHandle< CodeGetOptimizedCode (Handle< JSFunction > function, Handle< Code > current_code, ConcurrencyMode mode, BailoutId osr_ast_id=BailoutId::None())
 
static Handle< CodeGetConcurrentlyOptimizedCode (OptimizedCompileJob *job)
 
static bool DebuggerWantsEagerCompilation (CompilationInfo *info, bool allow_lazy_without_ctx=false)
 

Detailed Description

Definition at line 667 of file compiler.h.

Member Enumeration Documentation

◆ ConcurrencyMode

Enumerator
NOT_CONCURRENT 
CONCURRENT 

Definition at line 709 of file compiler.h.

Member Function Documentation

◆ BuildFunctionInfo()

Handle< SharedFunctionInfo > v8::internal::Compiler::BuildFunctionInfo ( FunctionLiteral *  node,
Handle< Script script,
CompilationInfo outer 
)
static

Definition at line 1243 of file compiler.cc.

1245  {
1246  // Precondition: code has been parsed and scopes have been analyzed.
1247  CompilationInfoWithZone info(script);
1248  info.SetFunction(literal);
1249  info.PrepareForCompilation(literal->scope());
1250  info.SetStrictMode(literal->scope()->strict_mode());
1251  if (outer_info->will_serialize()) info.PrepareForSerializing();
1252 
1253  Isolate* isolate = info.isolate();
1254  Factory* factory = isolate->factory();
1255  LiveEditFunctionTracker live_edit_tracker(isolate, literal);
1256  // Determine if the function can be lazily compiled. This is necessary to
1257  // allow some of our builtin JS files to be lazily compiled. These
1258  // builtins cannot be handled lazily by the parser, since we have to know
1259  // if a function uses the special natives syntax, which is something the
1260  // parser records.
1261  // If the debugger requests compilation for break points, we cannot be
1262  // aggressive about lazy compilation, because it might trigger compilation
1263  // of functions without an outer context when setting a breakpoint through
1264  // Debug::FindSharedFunctionInfoInScript.
1265  bool allow_lazy_without_ctx = literal->AllowsLazyCompilationWithoutContext();
1266  bool allow_lazy = literal->AllowsLazyCompilation() &&
1267  !DebuggerWantsEagerCompilation(&info, allow_lazy_without_ctx);
1268 
1269 
1270  if (outer_info->is_toplevel() && outer_info->will_serialize()) {
1271  // Make sure that if the toplevel code (possibly to be serialized),
1272  // the inner unction must be allowed to be compiled lazily.
1273  DCHECK(allow_lazy);
1274  }
1275 
1276  // Generate code
1277  Handle<ScopeInfo> scope_info;
1278  if (FLAG_lazy && allow_lazy && !literal->is_parenthesized()) {
1279  Handle<Code> code = isolate->builtins()->CompileLazy();
1280  info.SetCode(code);
1281  scope_info = Handle<ScopeInfo>(ScopeInfo::Empty(isolate));
1282  } else if (FullCodeGenerator::MakeCode(&info)) {
1283  DCHECK(!info.code().is_null());
1284  scope_info = ScopeInfo::Create(info.scope(), info.zone());
1285  } else {
1287  }
1288 
1289  // Create a shared function info object.
1290  Handle<SharedFunctionInfo> result = factory->NewSharedFunctionInfo(
1291  literal->name(), literal->materialized_literal_count(), literal->kind(),
1292  info.code(), scope_info, info.feedback_vector());
1293  SetFunctionInfo(result, literal, false, script);
1294  RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result);
1295  result->set_allows_lazy_compilation(allow_lazy);
1296  result->set_allows_lazy_compilation_without_context(allow_lazy_without_ctx);
1297 
1298  // Set the expected number of properties for instances and return
1299  // the resulting function.
1301  literal->expected_property_count());
1302  live_edit_tracker.RecordFunctionInfo(result, literal, info.zone());
1303  return result;
1304 }
static bool DebuggerWantsEagerCompilation(CompilationInfo *info, bool allow_lazy_without_ctx=false)
Definition: compiler.cc:1404
static bool MakeCode(CompilationInfo *info)
static Handle< T > null()
Definition: handles.h:123
static Handle< ScopeInfo > Create(Scope *scope, Zone *zone)
Definition: scopeinfo.cc:16
static ScopeInfo * Empty(Isolate *isolate)
Definition: scopeinfo.cc:132
#define DCHECK(condition)
Definition: logging.h:205
static void SetFunctionInfo(Handle< SharedFunctionInfo > function_info, FunctionLiteral *lit, bool is_toplevel, Handle< Script > script)
Definition: compiler.cc:569
static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, CompilationInfo *info, Handle< SharedFunctionInfo > shared)
Definition: compiler.cc:598
void SetExpectedNofPropertiesFromEstimate(Handle< SharedFunctionInfo > shared, int estimate)
Definition: compiler.cc:542

References v8::internal::Isolate::builtins(), v8::internal::CompilationInfo::code(), v8::internal::ScopeInfo::Create(), DCHECK, DebuggerWantsEagerCompilation(), v8::internal::ScopeInfo::Empty(), v8::internal::Isolate::factory(), v8::internal::CompilationInfo::feedback_vector(), v8::internal::CompilationInfo::is_toplevel(), v8::internal::CompilationInfo::isolate(), v8::internal::FullCodeGenerator::MakeCode(), v8::internal::Handle< T >::null(), v8::internal::CompilationInfo::PrepareForCompilation(), v8::internal::CompilationInfo::PrepareForSerializing(), v8::internal::RecordFunctionCompilation(), v8::internal::LiveEditFunctionTracker::RecordFunctionInfo(), v8::internal::CompilationInfo::scope(), v8::internal::CompilationInfo::SetCode(), v8::internal::SetExpectedNofPropertiesFromEstimate(), v8::internal::CompilationInfo::SetFunction(), v8::internal::SetFunctionInfo(), v8::internal::CompilationInfo::SetStrictMode(), v8::internal::CompilationInfo::will_serialize(), and v8::internal::CompilationInfo::zone().

+ Here is the call graph for this function:

◆ CompileForLiveEdit()

void v8::internal::Compiler::CompileForLiveEdit ( Handle< Script script)
static

Definition at line 964 of file compiler.cc.

964  {
965  // TODO(635): support extensions.
966  CompilationInfoWithZone info(script);
967  PostponeInterruptsScope postpone(info.isolate());
968  VMState<COMPILER> state(info.isolate());
969 
970  info.MarkAsGlobal();
971  if (!Parser::Parse(&info)) return;
972 
973  LiveEditFunctionTracker tracker(info.isolate(), info.function());
974  if (!CompileUnoptimizedCode(&info)) return;
975  if (!info.shared_info().is_null()) {
976  Handle<ScopeInfo> scope_info = ScopeInfo::Create(info.scope(),
977  info.zone());
978  info.shared_info()->set_scope_info(*scope_info);
979  }
980  tracker.RecordRootFunctionInfo(info.code());
981 }
static bool CompileUnoptimizedCode(CompilationInfo *info)
Definition: compiler.cc:632

References v8::internal::CompilationInfo::code(), v8::internal::CompileUnoptimizedCode(), v8::internal::ScopeInfo::Create(), v8::internal::CompilationInfo::function(), v8::internal::CompilationInfo::isolate(), v8::internal::CompilationInfo::MarkAsGlobal(), v8::internal::Parser::Parse(), v8::internal::LiveEditFunctionTracker::RecordRootFunctionInfo(), v8::internal::CompilationInfo::scope(), v8::internal::CompilationInfo::shared_info(), and v8::internal::CompilationInfo::zone().

Referenced by v8::internal::LiveEdit::GatherCompileInfo().

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

◆ CompileScript()

Handle< SharedFunctionInfo > v8::internal::Compiler::CompileScript ( Handle< String source,
Handle< Object script_name,
int  line_offset,
int  column_offset,
bool  is_shared_cross_origin,
Handle< Context context,
v8::Extension extension,
ScriptData **  cached_data,
ScriptCompiler::CompileOptions  compile_options,
NativesFlag  is_natives_code 
)
static

Definition at line 1134 of file compiler.cc.

1138  {
1139  if (compile_options == ScriptCompiler::kNoCompileOptions) {
1140  cached_data = NULL;
1141  } else if (compile_options == ScriptCompiler::kProduceParserCache ||
1142  compile_options == ScriptCompiler::kProduceCodeCache) {
1143  DCHECK(cached_data && !*cached_data);
1144  DCHECK(extension == NULL);
1145  } else {
1146  DCHECK(compile_options == ScriptCompiler::kConsumeParserCache ||
1147  compile_options == ScriptCompiler::kConsumeCodeCache);
1148  DCHECK(cached_data && *cached_data);
1149  DCHECK(extension == NULL);
1150  }
1151  Isolate* isolate = source->GetIsolate();
1152  int source_length = source->length();
1153  isolate->counters()->total_load_size()->Increment(source_length);
1154  isolate->counters()->total_compile_size()->Increment(source_length);
1155 
1156  CompilationCache* compilation_cache = isolate->compilation_cache();
1157 
1158  // Do a lookup in the compilation cache but not for extensions.
1159  MaybeHandle<SharedFunctionInfo> maybe_result;
1160  Handle<SharedFunctionInfo> result;
1161  if (extension == NULL) {
1162  if (FLAG_serialize_toplevel &&
1163  compile_options == ScriptCompiler::kConsumeCodeCache &&
1164  !isolate->debug()->is_loaded()) {
1165  HistogramTimerScope timer(isolate->counters()->compile_deserialize());
1166  return CodeSerializer::Deserialize(isolate, *cached_data, source);
1167  } else {
1168  maybe_result = compilation_cache->LookupScript(
1169  source, script_name, line_offset, column_offset,
1170  is_shared_cross_origin, context);
1171  }
1172  }
1173 
1174  base::ElapsedTimer timer;
1175  if (FLAG_profile_deserialization && FLAG_serialize_toplevel &&
1176  compile_options == ScriptCompiler::kProduceCodeCache) {
1177  timer.Start();
1178  }
1179 
1180  if (!maybe_result.ToHandle(&result)) {
1181  // No cache entry found. Compile the script.
1182 
1183  // Create a script object describing the script to be compiled.
1184  Handle<Script> script = isolate->factory()->NewScript(source);
1185  if (natives == NATIVES_CODE) {
1186  script->set_type(Smi::FromInt(Script::TYPE_NATIVE));
1187  }
1188  if (!script_name.is_null()) {
1189  script->set_name(*script_name);
1190  script->set_line_offset(Smi::FromInt(line_offset));
1191  script->set_column_offset(Smi::FromInt(column_offset));
1192  }
1193  script->set_is_shared_cross_origin(is_shared_cross_origin);
1194 
1195  // Compile the function and add it to the cache.
1196  CompilationInfoWithZone info(script);
1197  info.MarkAsGlobal();
1198  info.SetCachedData(cached_data, compile_options);
1199  info.SetExtension(extension);
1200  info.SetContext(context);
1201  if (FLAG_serialize_toplevel &&
1202  compile_options == ScriptCompiler::kProduceCodeCache) {
1203  info.PrepareForSerializing();
1204  }
1205  if (FLAG_use_strict) info.SetStrictMode(STRICT);
1206 
1207  result = CompileToplevel(&info);
1208  if (extension == NULL && !result.is_null() && !result->dont_cache()) {
1209  compilation_cache->PutScript(source, context, result);
1210  if (FLAG_serialize_toplevel &&
1211  compile_options == ScriptCompiler::kProduceCodeCache) {
1212  HistogramTimerScope histogram_timer(
1213  isolate->counters()->compile_serialize());
1214  *cached_data = CodeSerializer::Serialize(isolate, result, source);
1215  if (FLAG_profile_deserialization) {
1216  PrintF("[Compiling and serializing %d bytes took %0.3f ms]\n",
1217  (*cached_data)->length(), timer.Elapsed().InMillisecondsF());
1218  }
1219  }
1220  }
1221 
1222  if (result.is_null()) isolate->ReportPendingMessages();
1223  } else if (result->ic_age() != isolate->heap()->global_ic_age()) {
1224  result->ResetForNewContext(isolate->heap()->global_ic_age());
1225  }
1226  return result;
1227 }
@ kProduceParserCache
Definition: v8.h:1161
@ kConsumeParserCache
Definition: v8.h:1162
@ kProduceCodeCache
Definition: v8.h:1163
@ kNoCompileOptions
Definition: v8.h:1160
@ kConsumeCodeCache
Definition: v8.h:1164
static ScriptData * Serialize(Isolate *isolate, Handle< SharedFunctionInfo > info, Handle< String > source)
Definition: serialize.cc:1836
static Handle< SharedFunctionInfo > Deserialize(Isolate *isolate, ScriptData *data, Handle< String > source)
Definition: serialize.cc:2024
static Smi * FromInt(int value)
Definition: objects-inl.h:1321
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
void PrintF(const char *format,...)
Definition: utils.cc:80
static Handle< SharedFunctionInfo > CompileToplevel(CompilationInfo *info)
Definition: compiler.cc:984
@ NATIVES_CODE
Definition: globals.h:401

References v8::internal::Isolate::compilation_cache(), v8::internal::CompileToplevel(), v8::internal::Isolate::counters(), DCHECK, v8::internal::Isolate::debug(), v8::internal::CodeSerializer::Deserialize(), v8::internal::Isolate::factory(), v8::internal::Smi::FromInt(), v8::internal::Heap::global_ic_age(), v8::internal::Isolate::heap(), v8::internal::Debug::is_loaded(), v8::internal::Handle< T >::is_null(), v8::ScriptCompiler::kConsumeCodeCache, v8::ScriptCompiler::kConsumeParserCache, v8::ScriptCompiler::kNoCompileOptions, v8::ScriptCompiler::kProduceCodeCache, v8::ScriptCompiler::kProduceParserCache, v8::internal::CompilationCache::LookupScript(), v8::internal::CompilationInfo::MarkAsGlobal(), v8::internal::NATIVES_CODE, NULL, v8::internal::CompilationInfo::PrepareForSerializing(), v8::internal::PrintF(), v8::internal::CompilationCache::PutScript(), v8::internal::Isolate::ReportPendingMessages(), v8::internal::CodeSerializer::Serialize(), v8::internal::CompilationInfo::SetCachedData(), v8::internal::CompilationInfo::SetContext(), v8::internal::CompilationInfo::SetExtension(), v8::internal::CompilationInfo::SetStrictMode(), v8::internal::STRICT, and v8::internal::Script::TYPE_NATIVE.

Referenced by v8::internal::Debug::CompileDebuggerScript(), and v8::ScriptCompiler::CompileUnbound().

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

◆ CompileStreamedScript()

Handle< SharedFunctionInfo > v8::internal::Compiler::CompileStreamedScript ( CompilationInfo info,
int  source_length 
)
static

Definition at line 1230 of file compiler.cc.

1231  {
1232  Isolate* isolate = info->isolate();
1233  isolate->counters()->total_load_size()->Increment(source_length);
1234  isolate->counters()->total_compile_size()->Increment(source_length);
1235 
1236  if (FLAG_use_strict) info->SetStrictMode(STRICT);
1237  // TODO(marja): FLAG_serialize_toplevel is not honoured and won't be; when the
1238  // real code caching lands, streaming needs to be adapted to use it.
1239  return CompileToplevel(info);
1240 }

References v8::internal::CompileToplevel(), v8::internal::Isolate::counters(), v8::internal::CompilationInfo::isolate(), v8::internal::CompilationInfo::SetStrictMode(), and v8::internal::STRICT.

Referenced by v8::ScriptCompiler::Compile().

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

◆ DebuggerWantsEagerCompilation()

bool v8::internal::Compiler::DebuggerWantsEagerCompilation ( CompilationInfo info,
bool  allow_lazy_without_ctx = false 
)
static

Definition at line 1404 of file compiler.cc.

1405  {
1406  return LiveEditFunctionTracker::IsActive(info->isolate()) ||
1407  (info->isolate()->DebuggerHasBreakPoints() && !allow_lazy_without_ctx);
1408 }
static bool IsActive(Isolate *isolate)
Definition: liveedit.cc:2083

References v8::internal::Isolate::DebuggerHasBreakPoints(), v8::internal::LiveEditFunctionTracker::IsActive(), and v8::internal::CompilationInfo::isolate().

Referenced by v8::internal::BackgroundParsingTask::BackgroundParsingTask(), BuildFunctionInfo(), and v8::internal::CompileToplevel().

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

◆ EnsureCompiled()

bool v8::internal::Compiler::EnsureCompiled ( Handle< JSFunction function,
ClearExceptionFlag  flag 
)
static

Definition at line 876 of file compiler.cc.

877  {
878  if (function->is_compiled()) return true;
879  MaybeHandle<Code> maybe_code = Compiler::GetLazyCode(function);
880  Handle<Code> code;
881  if (!maybe_code.ToHandle(&code)) {
882  if (flag == CLEAR_EXCEPTION) {
883  function->GetIsolate()->clear_pending_exception();
884  }
885  return false;
886  }
887  function->ReplaceCode(*code);
888  DCHECK(function->is_compiled());
889  return true;
890 }
static MUST_USE_RESULT MaybeHandle< Code > GetLazyCode(Handle< JSFunction > function)
Definition: compiler.cc:821
@ CLEAR_EXCEPTION
Definition: globals.h:762
kFeedbackVectorOffset flag
Definition: objects-inl.h:5418

References v8::internal::CLEAR_EXCEPTION, DCHECK, v8::internal::flag, and GetLazyCode().

Referenced by v8::internal::Debug::EnsureDebugInfo(), v8::internal::RUNTIME_FUNCTION(), and v8::internal::Runtime_NewObjectHelper().

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

◆ EnsureDeoptimizationSupport()

bool v8::internal::Compiler::EnsureDeoptimizationSupport ( CompilationInfo info)
static

Definition at line 895 of file compiler.cc.

895  {
896  if (!info->shared_info()->has_deoptimization_support()) {
897  CompilationInfoWithZone unoptimized(info->shared_info());
898  // Note that we use the same AST that we will use for generating the
899  // optimized code.
900  unoptimized.SetFunction(info->function());
901  unoptimized.PrepareForCompilation(info->scope());
902  unoptimized.SetContext(info->context());
903  unoptimized.EnableDeoptimizationSupport();
904  if (!FullCodeGenerator::MakeCode(&unoptimized)) return false;
905 
906  Handle<SharedFunctionInfo> shared = info->shared_info();
907  shared->EnableDeoptimizationSupport(*unoptimized.code());
908  shared->set_feedback_vector(*unoptimized.feedback_vector());
909 
910  // The scope info might not have been set if a lazily compiled
911  // function is inlined before being called for the first time.
912  if (shared->scope_info() == ScopeInfo::Empty(info->isolate())) {
913  Handle<ScopeInfo> target_scope_info =
914  ScopeInfo::Create(info->scope(), info->zone());
915  shared->set_scope_info(*target_scope_info);
916  }
917 
918  // The existing unoptimized code was replaced with the new one.
919  RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, &unoptimized, shared);
920  }
921  return true;
922 }

References v8::internal::CompilationInfo::code(), v8::internal::CompilationInfo::context(), v8::internal::ScopeInfo::Create(), v8::internal::ScopeInfo::Empty(), v8::internal::CompilationInfo::EnableDeoptimizationSupport(), v8::internal::CompilationInfo::feedback_vector(), v8::internal::CompilationInfo::function(), v8::internal::CompilationInfo::isolate(), v8::internal::FullCodeGenerator::MakeCode(), v8::internal::CompilationInfo::PrepareForCompilation(), v8::internal::RecordFunctionCompilation(), v8::internal::CompilationInfo::scope(), v8::internal::CompilationInfo::SetContext(), v8::internal::CompilationInfo::SetFunction(), v8::internal::CompilationInfo::shared_info(), and v8::internal::CompilationInfo::zone().

Referenced by v8::internal::OptimizedCompileJob::CreateGraph(), v8::internal::compiler::Parse(), and v8::internal::HOptimizedGraphBuilder::TryInline().

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

◆ GetConcurrentlyOptimizedCode()

Handle< Code > v8::internal::Compiler::GetConcurrentlyOptimizedCode ( OptimizedCompileJob job)
static

Definition at line 1354 of file compiler.cc.

1354  {
1355  // Take ownership of compilation info. Deleting compilation info
1356  // also tears down the zone and the recompile job.
1357  SmartPointer<CompilationInfo> info(job->info());
1358  Isolate* isolate = info->isolate();
1359 
1360  VMState<COMPILER> state(isolate);
1361  TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate());
1362 
1363  Handle<SharedFunctionInfo> shared = info->shared_info();
1364  shared->code()->set_profiler_ticks(0);
1365 
1366  // 1) Optimization on the concurrent thread may have failed.
1367  // 2) The function may have already been optimized by OSR. Simply continue.
1368  // Except when OSR already disabled optimization for some reason.
1369  // 3) The code may have already been invalidated due to dependency change.
1370  // 4) Debugger may have been activated.
1371  // 5) Code generation may have failed.
1372  if (job->last_status() == OptimizedCompileJob::SUCCEEDED) {
1373  if (shared->optimization_disabled()) {
1374  job->RetryOptimization(kOptimizationDisabled);
1375  } else if (info->HasAbortedDueToDependencyChange()) {
1376  job->RetryOptimization(kBailedOutDueToDependencyChange);
1377  } else if (isolate->DebuggerHasBreakPoints()) {
1378  job->RetryOptimization(kDebuggerHasBreakPoints);
1379  } else if (job->GenerateCode() == OptimizedCompileJob::SUCCEEDED) {
1380  RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info.get(), shared);
1381  if (info->shared_info()->SearchOptimizedCodeMap(
1382  info->context()->native_context(), info->osr_ast_id()) == -1) {
1383  InsertCodeIntoOptimizedCodeMap(info.get());
1384  }
1385  if (FLAG_trace_opt) {
1386  PrintF("[completed optimizing ");
1387  info->closure()->ShortPrint();
1388  PrintF("]\n");
1389  }
1390  return Handle<Code>(*info->code());
1391  }
1392  }
1393 
1394  DCHECK(job->last_status() != OptimizedCompileJob::SUCCEEDED);
1395  if (FLAG_trace_opt) {
1396  PrintF("[aborted optimizing ");
1397  info->closure()->ShortPrint();
1398  PrintF(" because: %s]\n", GetBailoutReason(info->bailout_reason()));
1399  }
1400  return Handle<Code>::null();
1401 }
const char * GetBailoutReason(BailoutReason reason)
static void InsertCodeIntoOptimizedCodeMap(CompilationInfo *info)
Definition: compiler.cc:709

References DCHECK, v8::internal::Isolate::DebuggerHasBreakPoints(), v8::internal::OptimizedCompileJob::GenerateCode(), v8::internal::SmartPointerBase< Deallocator, T >::get(), v8::internal::GetBailoutReason(), v8::internal::OptimizedCompileJob::info(), v8::internal::InsertCodeIntoOptimizedCodeMap(), v8::internal::OptimizedCompileJob::last_status(), v8::internal::Handle< T >::null(), v8::internal::PrintF(), v8::internal::RecordFunctionCompilation(), v8::internal::OptimizedCompileJob::RetryOptimization(), and v8::internal::OptimizedCompileJob::SUCCEEDED.

Referenced by v8::internal::OptimizingCompilerThread::InstallOptimizedFunctions(), and v8::internal::RUNTIME_FUNCTION().

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

◆ GetDebugCode()

MaybeHandle< Code > v8::internal::Compiler::GetDebugCode ( Handle< JSFunction function)
static

Definition at line 934 of file compiler.cc.

934  {
935  CompilationInfoWithZone info(function);
936  Isolate* isolate = info.isolate();
937  VMState<COMPILER> state(isolate);
938 
939  info.MarkAsDebug();
940 
941  DCHECK(!isolate->has_pending_exception());
942  Handle<Code> old_code(function->shared()->code());
943  DCHECK(old_code->kind() == Code::FUNCTION);
944  DCHECK(!old_code->has_debug_break_slots());
945 
946  info.MarkCompilingForDebugging();
947  if (old_code->is_compiled_optimizable()) {
948  info.EnableDeoptimizationSupport();
949  } else {
950  info.MarkNonOptimizable();
951  }
952  MaybeHandle<Code> maybe_new_code = GetUnoptimizedCodeCommon(&info);
953  Handle<Code> new_code;
954  if (!maybe_new_code.ToHandle(&new_code)) {
955  isolate->clear_pending_exception();
956  } else {
957  DCHECK_EQ(old_code->is_compiled_optimizable(),
958  new_code->is_compiled_optimizable());
959  }
960  return maybe_new_code;
961 }
#define DCHECK_EQ(v1, v2)
Definition: logging.h:206
static MUST_USE_RESULT MaybeHandle< Code > GetUnoptimizedCodeCommon(CompilationInfo *info)
Definition: compiler.cc:648

References v8::internal::Isolate::clear_pending_exception(), DCHECK, DCHECK_EQ, v8::internal::CompilationInfo::EnableDeoptimizationSupport(), v8::internal::GetUnoptimizedCodeCommon(), v8::internal::Isolate::has_pending_exception(), v8::internal::CompilationInfo::isolate(), v8::internal::CompilationInfo::MarkAsDebug(), v8::internal::CompilationInfo::MarkCompilingForDebugging(), and v8::internal::CompilationInfo::MarkNonOptimizable().

Referenced by v8::internal::EnsureFunctionHasDebugBreakSlots().

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

◆ GetFunctionFromEval()

MaybeHandle< JSFunction > v8::internal::Compiler::GetFunctionFromEval ( Handle< String source,
Handle< Context context,
StrictMode  strict_mode,
ParseRestriction  restriction,
int  scope_position 
)
static

Definition at line 1081 of file compiler.cc.

1086  {
1087  Isolate* isolate = source->GetIsolate();
1088  int source_length = source->length();
1089  isolate->counters()->total_eval_size()->Increment(source_length);
1090  isolate->counters()->total_compile_size()->Increment(source_length);
1091 
1092  CompilationCache* compilation_cache = isolate->compilation_cache();
1093  MaybeHandle<SharedFunctionInfo> maybe_shared_info =
1094  compilation_cache->LookupEval(source, context, strict_mode,
1095  scope_position);
1096  Handle<SharedFunctionInfo> shared_info;
1097 
1098  if (!maybe_shared_info.ToHandle(&shared_info)) {
1099  Handle<Script> script = isolate->factory()->NewScript(source);
1100  CompilationInfoWithZone info(script);
1101  info.MarkAsEval();
1102  if (context->IsNativeContext()) info.MarkAsGlobal();
1103  info.SetStrictMode(strict_mode);
1104  info.SetParseRestriction(restriction);
1105  info.SetContext(context);
1106 
1107  Debug::RecordEvalCaller(script);
1108 
1109  shared_info = CompileToplevel(&info);
1110 
1111  if (shared_info.is_null()) {
1112  return MaybeHandle<JSFunction>();
1113  } else {
1114  // Explicitly disable optimization for eval code. We're not yet prepared
1115  // to handle eval-code in the optimizing compiler.
1116  shared_info->DisableOptimization(kEval);
1117 
1118  // If caller is strict mode, the result must be in strict mode as well.
1119  DCHECK(strict_mode == SLOPPY || shared_info->strict_mode() == STRICT);
1120  if (!shared_info->dont_cache()) {
1121  compilation_cache->PutEval(
1122  source, context, shared_info, scope_position);
1123  }
1124  }
1125  } else if (shared_info->ic_age() != isolate->heap()->global_ic_age()) {
1126  shared_info->ResetForNewContext(isolate->heap()->global_ic_age());
1127  }
1128 
1129  return isolate->factory()->NewFunctionFromSharedFunctionInfo(
1130  shared_info, context, NOT_TENURED);
1131 }
static void RecordEvalCaller(Handle< Script > script)
Definition: debug.cc:2419

References v8::internal::Isolate::compilation_cache(), v8::internal::CompileToplevel(), v8::internal::Isolate::counters(), DCHECK, v8::internal::Isolate::factory(), v8::internal::Heap::global_ic_age(), v8::internal::Isolate::heap(), v8::internal::Handle< T >::is_null(), v8::internal::CompilationCache::LookupEval(), v8::internal::CompilationInfo::MarkAsEval(), v8::internal::CompilationInfo::MarkAsGlobal(), v8::internal::NOT_TENURED, v8::internal::CompilationCache::PutEval(), v8::internal::Debug::RecordEvalCaller(), v8::internal::CompilationInfo::SetContext(), v8::internal::CompilationInfo::SetParseRestriction(), v8::internal::CompilationInfo::SetStrictMode(), v8::internal::SLOPPY, and v8::internal::STRICT.

Referenced by v8::internal::CompileGlobalEval(), v8::internal::DebugEvaluate(), and v8::internal::RUNTIME_FUNCTION().

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

◆ GetLazyCode()

MaybeHandle< Code > v8::internal::Compiler::GetLazyCode ( Handle< JSFunction function)
static

Definition at line 821 of file compiler.cc.

821  {
822  DCHECK(!function->GetIsolate()->has_pending_exception());
823  DCHECK(!function->is_compiled());
824 
825  if (FLAG_turbo_asm && function->shared()->asm_function()) {
826  CompilationInfoWithZone info(function);
827 
828  VMState<COMPILER> state(info.isolate());
829  PostponeInterruptsScope postpone(info.isolate());
830 
831  info.SetOptimizing(BailoutId::None(),
832  Handle<Code>(function->shared()->code()));
833 
834  info.MarkAsContextSpecializing();
835  info.MarkAsTypingEnabled();
836  info.MarkAsInliningDisabled();
837 
838  if (GetOptimizedCodeNow(&info)) return info.code();
839  }
840 
841  if (function->shared()->is_compiled()) {
842  return Handle<Code>(function->shared()->code());
843  }
844 
845  CompilationInfoWithZone info(function);
846  Handle<Code> result;
847  ASSIGN_RETURN_ON_EXCEPTION(info.isolate(), result,
848  GetUnoptimizedCodeCommon(&info), Code);
849 
850  if (FLAG_always_opt &&
851  info.isolate()->use_crankshaft() &&
852  !info.shared_info()->optimization_disabled() &&
853  !info.isolate()->DebuggerHasBreakPoints()) {
854  Handle<Code> opt_code;
856  function, result,
857  Compiler::NOT_CONCURRENT).ToHandle(&opt_code)) {
858  result = opt_code;
859  }
860  }
861 
862  return result;
863 }
static BailoutId None()
Definition: utils.h:960
static MUST_USE_RESULT MaybeHandle< Code > GetOptimizedCode(Handle< JSFunction > function, Handle< Code > current_code, ConcurrencyMode mode, BailoutId osr_ast_id=BailoutId::None())
Definition: compiler.cc:1307
#define ASSIGN_RETURN_ON_EXCEPTION(isolate, dst, call, T)
Definition: isolate.h:135
static bool GetOptimizedCodeNow(CompilationInfo *info)
Definition: compiler.cc:739

References ASSIGN_RETURN_ON_EXCEPTION, v8::internal::CompilationInfo::code(), DCHECK, v8::internal::Isolate::DebuggerHasBreakPoints(), GetOptimizedCode(), v8::internal::GetOptimizedCodeNow(), v8::internal::GetUnoptimizedCodeCommon(), v8::internal::CompilationInfo::isolate(), v8::internal::CompilationInfo::MarkAsContextSpecializing(), v8::internal::CompilationInfo::MarkAsInliningDisabled(), v8::internal::CompilationInfo::MarkAsTypingEnabled(), v8::internal::BailoutId::None(), NOT_CONCURRENT, v8::internal::CompilationInfo::SetOptimizing(), v8::internal::CompilationInfo::shared_info(), and v8::internal::Isolate::use_crankshaft().

Referenced by EnsureCompiled(), and v8::internal::RUNTIME_FUNCTION().

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

◆ GetOptimizedCode()

MaybeHandle< Code > v8::internal::Compiler::GetOptimizedCode ( Handle< JSFunction function,
Handle< Code current_code,
ConcurrencyMode  mode,
BailoutId  osr_ast_id = BailoutId::None() 
)
static

Definition at line 1307 of file compiler.cc.

1310  {
1311  Handle<Code> cached_code;
1313  function, osr_ast_id).ToHandle(&cached_code)) {
1314  return cached_code;
1315  }
1316 
1317  SmartPointer<CompilationInfo> info(new CompilationInfoWithZone(function));
1318  Isolate* isolate = info->isolate();
1319  DCHECK(AllowCompilation::IsAllowed(isolate));
1320  VMState<COMPILER> state(isolate);
1321  DCHECK(!isolate->has_pending_exception());
1322  PostponeInterruptsScope postpone(isolate);
1323 
1324  Handle<SharedFunctionInfo> shared = info->shared_info();
1325  if (shared->code()->kind() != Code::FUNCTION ||
1326  ScopeInfo::Empty(isolate) == shared->scope_info()) {
1327  // The function was never compiled. Compile it unoptimized first.
1328  // TODO(titzer): reuse the AST and scope info from this compile.
1329  CompilationInfoWithZone nested(function);
1330  nested.EnableDeoptimizationSupport();
1331  if (!GetUnoptimizedCodeCommon(&nested).ToHandle(&current_code)) {
1332  return MaybeHandle<Code>();
1333  }
1334  shared->ReplaceCode(*current_code);
1335  }
1336  current_code->set_profiler_ticks(0);
1337 
1338  info->SetOptimizing(osr_ast_id, current_code);
1339 
1340  if (mode == CONCURRENT) {
1341  if (GetOptimizedCodeLater(info.get())) {
1342  info.Detach(); // The background recompile job owns this now.
1343  return isolate->builtins()->InOptimizationQueue();
1344  }
1345  } else {
1346  if (GetOptimizedCodeNow(info.get())) return info->code();
1347  }
1348 
1349  if (isolate->has_pending_exception()) isolate->clear_pending_exception();
1350  return MaybeHandle<Code>();
1351 }
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 mode(MIPS only)") DEFINE_BOOL(enable_always_align_csp
static MUST_USE_RESULT MaybeHandle< Code > GetCodeFromOptimizedCodeMap(Handle< JSFunction > function, BailoutId osr_ast_id)
Definition: compiler.cc:682
static bool GetOptimizedCodeLater(CompilationInfo *info)
Definition: compiler.cc:770

References v8::internal::Isolate::builtins(), v8::internal::Isolate::clear_pending_exception(), CONCURRENT, DCHECK, v8::internal::SmartPointerBase< Deallocator, T >::Detach(), v8::internal::ScopeInfo::Empty(), v8::internal::CompilationInfo::EnableDeoptimizationSupport(), v8::internal::SmartPointerBase< Deallocator, T >::get(), v8::internal::GetCodeFromOptimizedCodeMap(), v8::internal::GetOptimizedCodeLater(), v8::internal::GetOptimizedCodeNow(), v8::internal::GetUnoptimizedCodeCommon(), v8::internal::Isolate::has_pending_exception(), and mode().

Referenced by GetLazyCode(), and v8::internal::RUNTIME_FUNCTION().

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

◆ GetUnoptimizedCode() [1/2]

MaybeHandle< Code > v8::internal::Compiler::GetUnoptimizedCode ( Handle< JSFunction function)
static

Definition at line 805 of file compiler.cc.

805  {
806  DCHECK(!function->GetIsolate()->has_pending_exception());
807  DCHECK(!function->is_compiled());
808  if (function->shared()->is_compiled()) {
809  return Handle<Code>(function->shared()->code());
810  }
811 
812  CompilationInfoWithZone info(function);
813  Handle<Code> result;
814  ASSIGN_RETURN_ON_EXCEPTION(info.isolate(), result,
816  Code);
817  return result;
818 }

References ASSIGN_RETURN_ON_EXCEPTION, DCHECK, v8::internal::GetUnoptimizedCodeCommon(), and v8::internal::CompilationInfo::isolate().

Referenced by v8::internal::Debug::FindSharedFunctionInfoInScript().

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

◆ GetUnoptimizedCode() [2/2]

MaybeHandle< Code > v8::internal::Compiler::GetUnoptimizedCode ( Handle< SharedFunctionInfo shared)
static

Definition at line 866 of file compiler.cc.

867  {
868  DCHECK(!shared->GetIsolate()->has_pending_exception());
869  DCHECK(!shared->is_compiled());
870 
871  CompilationInfoWithZone info(shared);
872  return GetUnoptimizedCodeCommon(&info);
873 }

References DCHECK, and v8::internal::GetUnoptimizedCodeCommon().

+ Here is the call graph for this function:

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