From 3f9599f53fd439e4def1de7f9ee1fa8361127ae7 Mon Sep 17 00:00:00 2001 From: Artem Udovichenko Date: Fri, 9 Dec 2022 11:03:12 +0300 Subject: [PATCH] Fix IC after GC After full GC some IC elements may get undefined. In this case fill IC elements again. Change-Id: I8bf1330611de83481c6c30835422eec6ff9958f3 --- runtime/ic/ic_runtime_stub-inl.h | 28 ++++++++++++++++++++++++---- runtime/ic/profile_type_info.cpp | 2 +- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/runtime/ic/ic_runtime_stub-inl.h b/runtime/ic/ic_runtime_stub-inl.h index 38c294ed2..cfcc9b114 100644 --- a/runtime/ic/ic_runtime_stub-inl.h +++ b/runtime/ic/ic_runtime_stub-inl.h @@ -142,7 +142,10 @@ JSTaggedValue ICRuntimeStub::LoadICByName(JSThread *thread, JSTaggedValue receiv } if (LIKELY(hclass_value.GetTaggedObject() == hclass)) { JSTaggedValue handler = profile_type_info->Get(index + 1); - if (handler.IsUndefined()) { + if (UNLIKELY(handler.IsUndefined())) { + // handler is collected by GC. + // Clear profile data to fill it again in LoadMiss. + profile_type_info->Set(thread, index, JSTaggedValue::Undefined()); break; } return LoadICWithHandler(thread, receiver, receiver, handler); @@ -176,7 +179,14 @@ JSTaggedValue ICRuntimeStub::LoadICByValue(JSThread *thread, JSTaggedValue recei JSTaggedValue hclass_value = profile_type_info->Get(slot_id + 1); if (hclass_value.GetTaggedObject() == hclass) { JSTaggedValue handler = profile_type_info->Get(slot_id + 2); - return LoadICWithHandler(thread, receiver, receiver, handler); + if (UNLIKELY(handler.IsUndefined())) { + // handler is collected by GC. + // Clear profile data to fill it again in LoadMiss. + profile_type_info->Set(thread, slot_id, JSTaggedValue::Undefined()); + profile_type_info->Set(thread, slot_id + 1, JSTaggedValue::Undefined()); + } else { + return LoadICWithHandler(thread, receiver, receiver, handler); + } } } } @@ -206,7 +216,14 @@ JSTaggedValue ICRuntimeStub::StoreICByValue(JSThread *thread, JSTaggedValue rece JSTaggedValue hclass_value = profile_type_info->Get(slot_id + 1); if (hclass_value.GetTaggedObject() == hclass) { JSTaggedValue handler = profile_type_info->Get(slot_id + 2); - return StoreICWithHandler(thread, receiver, receiver, value, handler); + if (UNLIKELY(handler.IsUndefined())) { + // handler is collected by GC. + // Clear profile data to fill it again in StoreMiss. + profile_type_info->Set(thread, slot_id, JSTaggedValue::Undefined()); + profile_type_info->Set(thread, slot_id + 1, JSTaggedValue::Undefined()); + } else { + return StoreICWithHandler(thread, receiver, receiver, value, handler); + } } } } @@ -234,7 +251,10 @@ JSTaggedValue ICRuntimeStub::StoreICByName(JSThread *thread, JSTaggedValue recei } if (LIKELY(hclass_value.GetTaggedObject() == hclass)) { JSTaggedValue handler = profile_type_info->Get(index + 1); - if (handler.IsUndefined()) { + if (UNLIKELY(handler.IsUndefined())) { + // handler is collected by GC. + // Clear profile data to fill it again in StoreMiss. + profile_type_info->Set(thread, index, JSTaggedValue::Undefined()); break; } return StoreICWithHandler(thread, receiver, receiver, value, handler); diff --git a/runtime/ic/profile_type_info.cpp b/runtime/ic/profile_type_info.cpp index e62d72fb6..08a6e0584 100644 --- a/runtime/ic/profile_type_info.cpp +++ b/runtime/ic/profile_type_info.cpp @@ -70,7 +70,7 @@ void ProfileTypeAccessor::AddHandlerWithKey(JSHandle key, JSHandl return; } auto profileData = profile_type_info_->Get(slot_id_); - if (profileData.IsUndefined() && profile_type_info_->Get(slot_id_ + 1).IsUndefined()) { + if (profileData.IsUndefined() || profile_type_info_->Get(slot_id_ + 1).IsUndefined()) { profile_type_info_->Set(thread_, slot_id_, key.GetTaggedValue()); profile_type_info_->Set(thread_, slot_id_ + 1U, dynclass.GetTaggedValue()); profile_type_info_->Set(thread_, slot_id_ + 2U, handler.GetTaggedValue()); -- Gitee