Commit 66f8f20a authored by Jakob Gruber's avatar Jakob Gruber Committed by V8 LUCI CQ

Reland "Address comments from `[osr] Basic support for concurrent OSR`"

- Unhandlify OSROptimizedCodeCache::GetOptimizedCode.
- Unstatic-fy FeedbackVector::SetOptimizedCode.
- Remove frame-walking logic during the OSR tierup decision.

The reland is unchanged from the original CL.

Bug: v8:12161
Change-Id: Ibf03a9dd9a6fcd38c0664e5d5014a26d0240e035
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3568463Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Jakob Linke <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79752}
parent a7e94ad8
......@@ -903,10 +903,9 @@ class OptimizedCodeCache : public AllStatic {
CodeT code;
if (IsOSR(osr_offset)) {
// For OSR, check the OSR optimized code cache.
code =
function->native_context()
code = function->native_context()
.GetOSROptimizedCodeCache()
.GetOptimizedCode(handle(shared, isolate), osr_offset, isolate);
.GetOptimizedCode(shared, osr_offset, isolate);
} else {
// Non-OSR code may be cached on the feedback vector.
if (function->has_feedback_vector()) {
......@@ -960,9 +959,7 @@ class OptimizedCodeCache : public AllStatic {
return;
}
Handle<FeedbackVector> vector =
handle(function->feedback_vector(), isolate);
FeedbackVector::SetOptimizedCode(vector, code);
function->feedback_vector().SetOptimizedCode(code);
}
};
......@@ -3397,15 +3394,6 @@ MaybeHandle<CodeT> Compiler::CompileOptimizedOSR(Isolate* isolate,
return {};
}
// If we are trying to do OSR when there are already optimized activations of
// the function, it means (a) the function is directly or indirectly
// recursive and (b) an optimized invocation has been deoptimized so that we
// are currently in an unoptimized activation.
for (JavaScriptFrameIterator it(isolate); !it.done(); it.Advance()) {
JavaScriptFrame* frame = it.frame();
if (frame->is_optimized() && frame->function() == *function) return {};
}
// -- Alright, decided to proceed. --
// Disarm all back edges, i.e. reset the OSR urgency.
......
......@@ -386,25 +386,22 @@ void FeedbackVector::SaturatingIncrementProfilerTicks() {
if (ticks < Smi::kMaxValue) set_profiler_ticks(ticks + 1);
}
// static
void FeedbackVector::SetOptimizedCode(Handle<FeedbackVector> vector,
Handle<CodeT> code) {
void FeedbackVector::SetOptimizedCode(Handle<CodeT> code) {
DCHECK(CodeKindIsOptimizedJSFunction(code->kind()));
// We should set optimized code only when there is no valid optimized code.
DCHECK(!vector->has_optimized_code() ||
vector->optimized_code().marked_for_deoptimization() ||
DCHECK(!has_optimized_code() ||
optimized_code().marked_for_deoptimization() ||
FLAG_stress_concurrent_inlining_attach_code);
// TODO(mythria): We could see a CompileOptimized state here either from
// tests that use %OptimizeFunctionOnNextCall, --always-opt or because we
// re-mark the function for non-concurrent optimization after an OSR. We
// should avoid these cases and also check that state isn't
// should avoid these cases and also check that marker isn't
// TieringState::kRequestTurbofan*.
vector->set_maybe_optimized_code(HeapObjectReference::Weak(*code),
kReleaseStore);
int32_t state = vector->flags();
set_maybe_optimized_code(HeapObjectReference::Weak(*code), kReleaseStore);
int32_t state = flags();
state = TieringStateBits::update(state, TieringState::kNone);
state = MaybeHasOptimizedCodeBit::update(state, true);
vector->set_flags(state);
set_flags(state);
}
void FeedbackVector::ClearOptimizedCode() {
......
......@@ -228,8 +228,7 @@ class FeedbackVector
// the world, thus 'maybe'.
inline bool maybe_has_optimized_code() const;
inline void set_maybe_has_optimized_code(bool value);
static void SetOptimizedCode(Handle<FeedbackVector> vector,
Handle<CodeT> code);
void SetOptimizedCode(Handle<CodeT> code);
void EvictOptimizedCodeMarkedForDeoptimization(SharedFunctionInfo shared,
const char* reason);
void ClearOptimizedCode();
......
......@@ -27,7 +27,7 @@ void OSROptimizedCodeCache::AddOptimizedCode(
Handle<OSROptimizedCodeCache> osr_cache(
native_context->GetOSROptimizedCodeCache(), isolate);
DCHECK_EQ(osr_cache->FindEntry(shared, osr_offset), -1);
DCHECK_EQ(osr_cache->FindEntry(*shared, osr_offset), -1);
int entry = -1;
for (int index = 0; index < osr_cache->length(); index += kEntryLength) {
if (osr_cache->Get(index + kSharedOffset)->IsCleared() ||
......@@ -90,7 +90,7 @@ void OSROptimizedCodeCache::Compact(Handle<NativeContext> native_context) {
native_context->set_osr_code_cache(*new_osr_cache);
}
CodeT OSROptimizedCodeCache::GetOptimizedCode(Handle<SharedFunctionInfo> shared,
CodeT OSROptimizedCodeCache::GetOptimizedCode(SharedFunctionInfo shared,
BytecodeOffset osr_offset,
Isolate* isolate) {
DisallowGarbageCollection no_gc;
......@@ -178,12 +178,12 @@ BytecodeOffset OSROptimizedCodeCache::GetBytecodeOffsetFromEntry(int index) {
return BytecodeOffset(osr_offset_entry.value());
}
int OSROptimizedCodeCache::FindEntry(Handle<SharedFunctionInfo> shared,
int OSROptimizedCodeCache::FindEntry(SharedFunctionInfo shared,
BytecodeOffset osr_offset) {
DisallowGarbageCollection no_gc;
DCHECK(!osr_offset.IsNone());
for (int index = 0; index < length(); index += kEntryLength) {
if (GetSFIFromEntry(index) != *shared) continue;
if (GetSFIFromEntry(index) != shared) continue;
if (GetBytecodeOffsetFromEntry(index) != osr_offset) continue;
return index;
}
......
......@@ -51,8 +51,8 @@ class V8_EXPORT OSROptimizedCodeCache : public WeakFixedArray {
// Returns the code corresponding to the shared function |shared| and
// BytecodeOffset |offset| if an entry exists in the cache. Returns an empty
// object otherwise.
CodeT GetOptimizedCode(Handle<SharedFunctionInfo> shared,
BytecodeOffset osr_offset, Isolate* isolate);
CodeT GetOptimizedCode(SharedFunctionInfo shared, BytecodeOffset osr_offset,
Isolate* isolate);
// Remove all code objects marked for deoptimization from OSR code cache.
void EvictMarkedCode(Isolate* isolate);
......@@ -73,8 +73,7 @@ class V8_EXPORT OSROptimizedCodeCache : public WeakFixedArray {
SharedFunctionInfo GetSFIFromEntry(int index);
BytecodeOffset GetBytecodeOffsetFromEntry(int index);
inline int FindEntry(Handle<SharedFunctionInfo> shared,
BytecodeOffset osr_offset);
inline int FindEntry(SharedFunctionInfo shared, BytecodeOffset osr_offset);
inline void ClearEntry(int src, Isolate* isolate);
inline void InitializeEntry(int entry, SharedFunctionInfo shared, CodeT code,
BytecodeOffset osr_offset);
......
......@@ -144,20 +144,20 @@ TEST_F(TestWithNativeContext, FindCachedEntry) {
Handle<OSROptimizedCodeCache> osr_cache(
native_context->GetOSROptimizedCodeCache(), isolate);
EXPECT_EQ(osr_cache->GetOptimizedCode(shared, BytecodeOffset(0), isolate),
EXPECT_EQ(osr_cache->GetOptimizedCode(*shared, BytecodeOffset(0), isolate),
*code);
EXPECT_EQ(
osr_cache->GetOptimizedCode(shared1, BytecodeOffset(bailout_id), isolate),
EXPECT_EQ(osr_cache->GetOptimizedCode(*shared1, BytecodeOffset(bailout_id),
isolate),
*code1);
RunJS("%DeoptimizeFunction(f1)");
EXPECT_TRUE(
osr_cache->GetOptimizedCode(shared1, BytecodeOffset(bailout_id), isolate)
osr_cache->GetOptimizedCode(*shared1, BytecodeOffset(bailout_id), isolate)
.is_null());
osr_cache->Set(OSROptimizedCodeCache::kCachedCodeOffset,
HeapObjectReference::ClearedValue(isolate));
EXPECT_TRUE(osr_cache->GetOptimizedCode(shared, BytecodeOffset(0), isolate)
EXPECT_TRUE(osr_cache->GetOptimizedCode(*shared, BytecodeOffset(0), isolate)
.is_null());
}
......
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