@@ -289,7 +289,7 @@ bool UseAsmWasm(DeclarationScope* scope, Handle<SharedFunctionInfo> shared_info,
289
289
290
290
// Modules that have validated successfully, but were subsequently broken by
291
291
// invalid module instantiation attempts are off limit forever.
292
- if (shared_info->is_asm_wasm_broken ()) return false ;
292
+ if (!shared_info. is_null () && shared_info->is_asm_wasm_broken ()) return false ;
293
293
294
294
// Compiling for debugging is not supported, fall back.
295
295
if (is_debug) return false ;
@@ -326,6 +326,18 @@ CompilationJob* GetUnoptimizedCompilationJob(CompilationInfo* info) {
326
326
327
327
void InstallUnoptimizedCode (CompilationInfo* info) {
328
328
Handle <SharedFunctionInfo> shared = info->shared_info ();
329
+ DCHECK_EQ (info->shared_info ()->language_mode (),
330
+ info->literal ()->language_mode ());
331
+
332
+ // Ensure feedback metadata is installed.
333
+ EnsureFeedbackMetadata (info);
334
+
335
+ // Mark code to be executed once before being aged if necessary.
336
+ // TODO(6409): Remove when full-codegen dies.
337
+ DCHECK (!info->code ().is_null ());
338
+ if (info->parse_info ()->literal ()->should_be_used_once_hint ()) {
339
+ info->code ()->MarkToBeExecutedOnce (info->isolate ());
340
+ }
329
341
330
342
// Update the shared function info with the scope info.
331
343
Handle <ScopeInfo> scope_info = info->scope ()->scope_info ();
@@ -357,6 +369,19 @@ void InstallUnoptimizedCode(CompilationInfo* info) {
357
369
}
358
370
}
359
371
372
+ void EnsureSharedFunctionInfosArrayOnScript (CompilationInfo* info) {
373
+ DCHECK (info->parse_info ()->is_toplevel ());
374
+ DCHECK (!info->script ().is_null ());
375
+ if (info->script ()->shared_function_infos ()->length () > 0 ) {
376
+ DCHECK_EQ (info->script ()->shared_function_infos ()->length (),
377
+ info->parse_info ()->max_function_literal_id () + 1 );
378
+ return ;
379
+ }
380
+ Handle <FixedArray> infos (info->isolate ()->factory ()->NewFixedArray (
381
+ info->parse_info ()->max_function_literal_id () + 1 ));
382
+ info->script ()->set_shared_function_infos (*infos);
383
+ }
384
+
360
385
void SetSharedFunctionFlagsFromLiteral (FunctionLiteral* literal,
361
386
Handle <SharedFunctionInfo> shared_info) {
362
387
// Don't overwrite values set by the bootstrapper.
@@ -374,17 +399,33 @@ void SetSharedFunctionFlagsFromLiteral(FunctionLiteral* literal,
374
399
375
400
CompilationJob::Status FinalizeUnoptimizedCompilationJob (CompilationJob* job) {
376
401
CompilationInfo* info = job->info ();
402
+ ParseInfo* parse_info = info->parse_info ();
403
+ Isolate* isolate = info->isolate ();
404
+
405
+ if (parse_info->is_toplevel ()) {
406
+ // Allocate a shared function info and an array for shared function infos
407
+ // for inner functions.
408
+ EnsureSharedFunctionInfosArrayOnScript (info);
409
+ DCHECK_EQ (kNoSourcePosition , info->literal ()->function_token_position ());
410
+ if (!info->has_shared_info ()) {
411
+ Handle <SharedFunctionInfo> shared =
412
+ isolate->factory ()->NewSharedFunctionInfoForLiteral (info->literal (),
413
+ info->script ());
414
+ shared->set_is_toplevel (true );
415
+ parse_info->set_shared_info (shared);
416
+ }
417
+ }
377
418
SetSharedFunctionFlagsFromLiteral (info->literal (), info->shared_info ());
378
419
379
420
CompilationJob::Status status = job->FinalizeJob ();
380
421
if (status == CompilationJob::SUCCEEDED) {
381
- EnsureFeedbackMetadata (info);
382
- DCHECK (!info->code ().is_null ());
383
- if (info->parse_info ()->literal ()->should_be_used_once_hint ()) {
384
- info->code ()->MarkToBeExecutedOnce (info->isolate ());
385
- }
386
422
InstallUnoptimizedCode (info);
387
- RecordFunctionCompilation (CodeEventListener::FUNCTION_TAG, info);
423
+ CodeEventListener::LogEventsAndTags log_tags =
424
+ parse_info->is_toplevel () ? parse_info->is_eval ()
425
+ ? CodeEventListener::EVAL_TAG
426
+ : CodeEventListener::SCRIPT_TAG
427
+ : CodeEventListener::FUNCTION_TAG;
428
+ RecordFunctionCompilation (log_tags, info);
388
429
job->RecordUnoptimizedCompilationStats ();
389
430
}
390
431
return status;
@@ -418,7 +459,6 @@ bool Renumber(ParseInfo* parse_info,
418
459
419
460
bool GenerateUnoptimizedCode (CompilationInfo* info) {
420
461
if (UseAsmWasm (info->scope (), info->shared_info (), info->is_debug ())) {
421
- EnsureFeedbackMetadata (info);
422
462
MaybeHandle<FixedArray> wasm_data;
423
463
wasm_data = AsmJs::CompileAsmViaWasm (info);
424
464
if (!wasm_data.is_null ()) {
@@ -475,7 +515,7 @@ bool CompileUnoptimizedInnerFunctions(
475
515
ParseInfo parse_info (script);
476
516
CompilationInfo info (parse_info.zone (), &parse_info, isolate,
477
517
Handle <JSFunction>::null ());
478
-
518
+ parse_info. set_toplevel ( false );
479
519
parse_info.set_literal (literal);
480
520
parse_info.set_shared_info (shared);
481
521
parse_info.set_function_literal_id (shared->function_literal_id ());
@@ -498,11 +538,11 @@ bool CompileUnoptimizedInnerFunctions(
498
538
return true ;
499
539
}
500
540
501
- bool InnerFunctionIsAsmModule (
541
+ bool InnerFunctionShouldUseFullCodegen (
502
542
ThreadedList<ThreadedListZoneEntry<FunctionLiteral*>>* literals) {
503
543
for (auto it : *literals) {
504
544
FunctionLiteral* literal = it->value ();
505
- if (literal-> scope ()-> IsAsmModule ( )) return true ;
545
+ if (ShouldUseFullCodegen (literal )) return true ;
506
546
}
507
547
return false ;
508
548
}
@@ -524,11 +564,12 @@ bool CompileUnoptimizedCode(CompilationInfo* info,
524
564
}
525
565
}
526
566
527
- // Disable concurrent inner compilation for asm-wasm code.
528
- // TODO(rmcilroy,bradnelson): Remove this AsmWasm check once the asm-wasm
529
- // builder doesn't do parsing when visiting function declarations.
530
- if (info->scope ()->IsAsmModule () ||
531
- InnerFunctionIsAsmModule (&inner_literals)) {
567
+ if (info->parse_info ()->is_toplevel () &&
568
+ (ShouldUseFullCodegen (info->literal ()) ||
569
+ InnerFunctionShouldUseFullCodegen (&inner_literals))) {
570
+ // Full-codegen needs to access SFI when compiling, so allocate the array
571
+ // now.
572
+ EnsureSharedFunctionInfosArrayOnScript (info);
532
573
inner_function_mode = ConcurrencyMode::kNotConcurrent ;
533
574
}
534
575
@@ -541,34 +582,16 @@ bool CompileUnoptimizedCode(CompilationInfo* info,
541
582
parse_zone->Seal ();
542
583
}
543
584
544
- if (!CompileUnoptimizedInnerFunctions (&inner_literals, inner_function_mode,
545
- parse_zone, info) ||
546
- ! GenerateUnoptimizedCode ( info)) {
585
+ if (!GenerateUnoptimizedCode (info) ||
586
+ ! CompileUnoptimizedInnerFunctions (&inner_literals, inner_function_mode,
587
+ parse_zone, info)) {
547
588
if (!isolate->has_pending_exception ()) isolate->StackOverflow ();
548
589
return false ;
549
590
}
550
591
551
592
return true ;
552
593
}
553
594
554
- void EnsureSharedFunctionInfosArrayOnScript (ParseInfo* info, Isolate* isolate) {
555
- DCHECK (info->is_toplevel ());
556
- DCHECK (!info->script ().is_null ());
557
- if (info->script ()->shared_function_infos ()->length () > 0 ) {
558
- DCHECK_EQ (info->script ()->shared_function_infos ()->length (),
559
- info->max_function_literal_id () + 1 );
560
- return ;
561
- }
562
- Handle <FixedArray> infos (
563
- isolate->factory ()->NewFixedArray (info->max_function_literal_id () + 1 ));
564
- info->script ()->set_shared_function_infos (*infos);
565
- }
566
-
567
- void EnsureSharedFunctionInfosArrayOnScript (CompilationInfo* info) {
568
- return EnsureSharedFunctionInfosArrayOnScript (info->parse_info (),
569
- info->isolate ());
570
- }
571
-
572
595
MUST_USE_RESULT MaybeHandle<Code> GetUnoptimizedCode (
573
596
CompilationInfo* info, ConcurrencyMode inner_function_mode) {
574
597
RuntimeCallTimerScope runtimeTimer (
@@ -591,9 +614,6 @@ MUST_USE_RESULT MaybeHandle<Code> GetUnoptimizedCode(
591
614
}
592
615
}
593
616
594
- DCHECK_EQ (info->shared_info ()->language_mode (),
595
- info->literal ()->language_mode ());
596
-
597
617
// Compile either unoptimized code or bytecode for the interpreter.
598
618
if (!CompileUnoptimizedCode (info, inner_function_mode)) {
599
619
return MaybeHandle<Code>();
@@ -1042,8 +1062,6 @@ Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) {
1042
1062
}
1043
1063
}
1044
1064
1045
- EnsureSharedFunctionInfosArrayOnScript (info);
1046
-
1047
1065
// Measure how long it takes to do the compilation; only take the
1048
1066
// rest of the function into account to avoid overlap with the
1049
1067
// parsing statistics.
@@ -1054,37 +1072,17 @@ Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) {
1054
1072
TRACE_EVENT0 (TRACE_DISABLED_BY_DEFAULT (" v8.compile" ),
1055
1073
parse_info->is_eval () ? " V8.CompileEval" : " V8.Compile" );
1056
1074
1057
- // Allocate a shared function info object.
1058
- FunctionLiteral* lit = parse_info->literal ();
1059
- DCHECK_EQ (kNoSourcePosition , lit->function_token_position ());
1060
- result = isolate->factory ()->NewSharedFunctionInfoForLiteral (lit, script);
1061
- result->set_is_toplevel (true );
1062
- parse_info->set_shared_info (result);
1063
- parse_info->set_function_literal_id (result->function_literal_id ());
1064
-
1065
1075
// Compile the code.
1066
1076
if (!CompileUnoptimizedCode (info, inner_function_mode)) {
1067
1077
return Handle <SharedFunctionInfo>::null ();
1068
1078
}
1069
1079
1070
- Handle <String> script_name =
1071
- script->name ()->IsString ()
1072
- ? Handle <String>(String::cast (script->name ()))
1073
- : isolate->factory ()->empty_string ();
1074
- CodeEventListener::LogEventsAndTags log_tag =
1075
- parse_info->is_eval ()
1076
- ? CodeEventListener::EVAL_TAG
1077
- : Logger::ToNativeByScript (CodeEventListener::SCRIPT_TAG, *script);
1078
-
1079
- PROFILE (isolate, CodeCreateEvent (log_tag, result->abstract_code (), *result,
1080
- *script_name));
1081
-
1082
1080
if (!script.is_null ()) {
1083
1081
script->set_compilation_state (Script::COMPILATION_STATE_COMPILED);
1084
1082
}
1085
1083
}
1086
1084
1087
- return result ;
1085
+ return info-> shared_info () ;
1088
1086
}
1089
1087
1090
1088
} // namespace
0 commit comments