From 7d3826ea480f8e15589d193cd17cbc7b072fe45c Mon Sep 17 00:00:00 2001 From: Ross McIlroy Date: Wed, 5 Dec 2018 17:31:16 +0000 Subject: [PATCH] [Compile] Update JSFunction predicates to handle bytecode flushing. Update is_compiled() and has_feedback_vector() to return false in the case where the SFI's bytecode has been flushed, but the JSFunction hasn't yet been reset to uncompiled. Also add code to reset the JSFunction when it is recompiled lazily. BUG=v8:8394 Change-Id: I7c5f79066603ac1ae097a0a62c625b1a8e39431c Reviewed-on: https://chromium-review.googlesource.com/c/1363138 Reviewed-by: Ulan Degenbaev Reviewed-by: Michael Starzinger Reviewed-by: Jakob Gruber Commit-Queue: Ross McIlroy Cr-Commit-Position: refs/heads/master@{#58148} --- src/api.cc | 4 +-- src/compiler.cc | 11 +++++-- src/compiler/pipeline.cc | 2 +- src/debug/liveedit.cc | 6 ++-- src/heap/factory.cc | 4 +-- src/objects-debug.cc | 4 +-- src/objects.cc | 12 ++++--- src/objects/js-objects-inl.h | 34 ++++++++++++++------ src/objects/js-objects.h | 13 +++++--- src/profiler/heap-snapshot-generator.cc | 4 +-- test/cctest/interpreter/interpreter-tester.h | 2 +- test/cctest/test-code-stub-assembler.cc | 2 +- 12 files changed, 64 insertions(+), 34 deletions(-) diff --git a/src/api.cc b/src/api.cc index 8d6f9c167a..06d912974b 100644 --- a/src/api.cc +++ b/src/api.cc @@ -800,8 +800,8 @@ StartupData SnapshotCreator::CreateBlob( fun->CompleteInobjectSlackTrackingIfActive(); // Also, clear out feedback vectors, or any optimized code. - if (fun->has_feedback_vector()) { - fun->feedback_cell()->set_value( + if (!fun->raw_feedback_cell()->value()->IsUndefined()) { + fun->raw_feedback_cell()->set_value( i::ReadOnlyRoots(isolate).undefined_value()); fun->set_code(isolate->builtins()->builtin(i::Builtins::kCompileLazy)); } diff --git a/src/compiler.cc b/src/compiler.cc index 62fb393895..70d18fed09 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -607,7 +607,7 @@ V8_WARN_UNUSED_RESULT MaybeHandle GetCodeFromOptimizedCodeCache( Handle shared(function->shared(), function->GetIsolate()); DisallowHeapAllocation no_gc; if (osr_offset.IsNone()) { - if (function->feedback_cell()->value()->IsFeedbackVector()) { + if (function->has_feedback_vector()) { FeedbackVector feedback_vector = function->feedback_vector(); feedback_vector->EvictOptimizedCodeMarkedForDeoptimization( function->shared(), "GetCodeFromOptimizedCodeCache"); @@ -1196,6 +1196,10 @@ bool Compiler::Compile(Handle function, ClearExceptionFlag flag, DCHECK(!function->HasOptimizationMarker()); DCHECK(!function->HasOptimizedCode()); + // Reset the JSFunction if we are recompiling due to the bytecode having been + // flushed. + function->ResetIfBytecodeFlushed(); + Isolate* isolate = function->GetIsolate(); Handle shared_info = handle(function->shared(), isolate); @@ -1406,7 +1410,7 @@ MaybeHandle Compiler::GetFunctionFromEval( JSFunction::EnsureFeedbackVector(result); if (allow_eval_cache) { // Make sure to cache this result. - Handle new_feedback_cell(result->feedback_cell(), + Handle new_feedback_cell(result->raw_feedback_cell(), isolate); compilation_cache->PutEval(source, outer_info, context, shared_info, new_feedback_cell, eval_scope_position); @@ -1419,7 +1423,8 @@ MaybeHandle Compiler::GetFunctionFromEval( if (allow_eval_cache) { // Add the SharedFunctionInfo and the LiteralsArray to the eval cache if // we didn't retrieve from there. - Handle new_feedback_cell(result->feedback_cell(), isolate); + Handle new_feedback_cell(result->raw_feedback_cell(), + isolate); compilation_cache->PutEval(source, outer_info, context, shared_info, new_feedback_cell, eval_scope_position); } diff --git a/src/compiler/pipeline.cc b/src/compiler/pipeline.cc index f2cf7350e8..f563cb82fd 100644 --- a/src/compiler/pipeline.cc +++ b/src/compiler/pipeline.cc @@ -913,7 +913,7 @@ PipelineCompilationJob::Status PipelineCompilationJob::PrepareJobImpl( compilation_info()->MarkAsAllocationFoldingEnabled(); } - if (compilation_info()->closure()->feedback_cell()->map() == + if (compilation_info()->closure()->raw_feedback_cell()->map() == ReadOnlyRoots(isolate).one_closure_cell_map()) { compilation_info()->MarkAsFunctionContextSpecializing(); } diff --git a/src/debug/liveedit.cc b/src/debug/liveedit.cc index 866bdd8796..466c176842 100644 --- a/src/debug/liveedit.cc +++ b/src/debug/liveedit.cc @@ -1133,7 +1133,8 @@ void LiveEdit::PatchScript(Isolate* isolate, Handle