[nci] Also spawn NCI tasks for OSR requests
In addition to normal optimization requests, it also makes sense to consider OSR requests. In that case, the function is definitely hot, and since we've seen it OSR (i.e. we spend a long time inside a loop in the interpreted function), immediately jumping into NCI code in future contexts would be great. Future work: support OSR from NCI to TF. Bug: v8:8888 Change-Id: Iaa4c60bc0c2e1bf3dc067053bb7b50e9af51c0d1 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2448462 Commit-Queue: Jakob Gruber <jgruber@chromium.org> Reviewed-by: Tobias Tebbi <tebbi@chromium.org> Cr-Commit-Position: refs/heads/master@{#70364}
This commit is contained in:
parent
608b732d14
commit
ec76fb0f6f
@ -1088,7 +1088,8 @@ MaybeHandle<Code> GetOptimizedCode(Handle<JSFunction> function,
|
||||
// contexts).
|
||||
if (CodeKindIsNativeContextIndependentJSFunction(code_kind)) {
|
||||
DCHECK(osr_offset.IsNone());
|
||||
DCHECK(FLAG_turbo_nci_as_midtier || shared->has_optimized_at_least_once());
|
||||
DCHECK(FLAG_turbo_nci_as_midtier || !FLAG_turbo_nci_delayed_codegen ||
|
||||
shared->has_optimized_at_least_once());
|
||||
|
||||
Handle<Code> cached_code;
|
||||
if (GetCodeFromCompilationCache(isolate, shared).ToHandle(&cached_code)) {
|
||||
|
@ -60,8 +60,29 @@ RUNTIME_FUNCTION(Runtime_CompileLazy) {
|
||||
|
||||
namespace {
|
||||
|
||||
inline bool MaybeSpawnNativeContextIndependentCompilationJob() {
|
||||
return FLAG_turbo_nci && !FLAG_turbo_nci_as_midtier;
|
||||
// Returns false iff an exception was thrown.
|
||||
bool MaybeSpawnNativeContextIndependentCompilationJob(
|
||||
Handle<JSFunction> function, ConcurrencyMode mode) {
|
||||
if (!FLAG_turbo_nci || FLAG_turbo_nci_as_midtier) {
|
||||
return true; // Nothing to do.
|
||||
}
|
||||
|
||||
// If delayed codegen is enabled, the first optimization request does not
|
||||
// trigger NCI compilation, since we try to avoid compiling Code that
|
||||
// remains unused in the future. Repeated optimization (possibly in
|
||||
// different native contexts) is taken as a signal that this SFI will
|
||||
// continue to be used in the future, thus we trigger NCI compilation.
|
||||
if (!FLAG_turbo_nci_delayed_codegen ||
|
||||
function->shared().has_optimized_at_least_once()) {
|
||||
if (!Compiler::CompileOptimized(function, mode,
|
||||
CodeKind::NATIVE_CONTEXT_INDEPENDENT)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
function->shared().set_has_optimized_at_least_once(true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Object CompileOptimized(Isolate* isolate, Handle<JSFunction> function,
|
||||
@ -77,21 +98,8 @@ Object CompileOptimized(Isolate* isolate, Handle<JSFunction> function,
|
||||
}
|
||||
|
||||
// Possibly compile for NCI caching.
|
||||
if (MaybeSpawnNativeContextIndependentCompilationJob()) {
|
||||
// If delayed codegen is enabled, the first optimization request does not
|
||||
// trigger NCI compilation, since we try to avoid compiling Code that
|
||||
// remains unused in the future. Repeated optimization (possibly in
|
||||
// different native contexts) is taken as a signal that this SFI will
|
||||
// continue to be used in the future, thus we trigger NCI compilation.
|
||||
if (!FLAG_turbo_nci_delayed_codegen ||
|
||||
function->shared().has_optimized_at_least_once()) {
|
||||
if (!Compiler::CompileOptimized(function, mode,
|
||||
CodeKind::NATIVE_CONTEXT_INDEPENDENT)) {
|
||||
return ReadOnlyRoots(isolate).exception();
|
||||
}
|
||||
} else {
|
||||
function->shared().set_has_optimized_at_least_once(true);
|
||||
}
|
||||
if (!MaybeSpawnNativeContextIndependentCompilationJob(function, mode)) {
|
||||
return ReadOnlyRoots(isolate).exception();
|
||||
}
|
||||
|
||||
DCHECK(function->is_compiled());
|
||||
@ -300,6 +308,14 @@ RUNTIME_FUNCTION(Runtime_CompileForOnStackReplacement) {
|
||||
PrintF(scope.file(), " at AST id %d]\n", ast_id.ToInt());
|
||||
}
|
||||
maybe_result = Compiler::GetOptimizedCodeForOSR(function, ast_id, frame);
|
||||
|
||||
// Possibly compile for NCI caching.
|
||||
if (!MaybeSpawnNativeContextIndependentCompilationJob(
|
||||
function, FLAG_concurrent_recompilation
|
||||
? ConcurrencyMode::kConcurrent
|
||||
: ConcurrencyMode::kNotConcurrent)) {
|
||||
return Object();
|
||||
}
|
||||
}
|
||||
|
||||
// Check whether we ended up with usable optimized code.
|
||||
|
Loading…
Reference in New Issue
Block a user