Commit 6cf10c80 authored by Jakob Gruber's avatar Jakob Gruber Committed by Commit Bot

[snapshot] Fix clearing compiled code from JSFunction

JSFunctions with an attached InterpreterEntryTrampoline should also be
reset to CompileLazy, but this was recently broken by
https://crrev.com/c/2345966.

This CL introduces a new JSFunction::CanDiscardCompiled helper to
mirror SFI::CanDiscardCompiled, and uses it during serialization.

Bug: v8:10869
Change-Id: I176b77278d2d40d34db671638232faec4dda1d9c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2390145Reviewed-by: 's avatarMythri Alle <mythria@chromium.org>
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69689}
parent 214d26d4
...@@ -147,6 +147,17 @@ CodeKind JSFunction::NextTier() const { ...@@ -147,6 +147,17 @@ CodeKind JSFunction::NextTier() const {
: CodeKind::OPTIMIZED_FUNCTION; : CodeKind::OPTIMIZED_FUNCTION;
} }
bool JSFunction::CanDiscardCompiled() const {
// Essentially, what we are asking here is, has this function been compiled
// from JS code? We can currently tell only indirectly, by looking at
// available code kinds. If any JS code kind exists, we can discard.
//
// Note that when the function has not yet been compiled we also return
// false; that's fine, since nothing must be discarded in that case.
CodeKinds result = GetAvailableCodeKinds();
return (result & kJSFunctionCodeKindsMask) != 0;
}
bool JSFunction::HasOptimizationMarker() { bool JSFunction::HasOptimizationMarker() {
return has_feedback_vector() && feedback_vector().has_optimization_marker(); return has_feedback_vector() && feedback_vector().has_optimization_marker();
} }
......
...@@ -116,6 +116,11 @@ class JSFunction : public JSFunctionOrBoundFunction { ...@@ -116,6 +116,11 @@ class JSFunction : public JSFunctionOrBoundFunction {
CodeKind NextTier() const; CodeKind NextTier() const;
// Similar to SharedFunctionInfo::CanDiscardCompiled. Returns true, if the
// attached code can be recreated at a later point by replacing it with
// CompileLazy.
bool CanDiscardCompiled() const;
// Tells whether or not this function checks its optimization marker in its // Tells whether or not this function checks its optimization marker in its
// feedback vector. // feedback vector.
bool ChecksOptimizationMarker(); bool ChecksOptimizationMarker();
......
...@@ -251,8 +251,8 @@ void Snapshot::ClearReconstructableDataForSerialization( ...@@ -251,8 +251,8 @@ void Snapshot::ClearReconstructableDataForSerialization(
continue; // Don't clear extensions, they cannot be recompiled. continue; // Don't clear extensions, they cannot be recompiled.
} }
// Also, clear out feedback vectors and any optimized code. // Also, clear out feedback vectors and recompilable code.
if (CodeKindIsJSFunction(fun.code().kind())) { if (fun.CanDiscardCompiled()) {
fun.set_code(*BUILTIN_CODE(isolate, CompileLazy)); fun.set_code(*BUILTIN_CODE(isolate, CompileLazy));
} }
if (!fun.raw_feedback_cell().value().IsUndefined()) { if (!fun.raw_feedback_cell().value().IsUndefined()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment