diff --git a/runtime/ic/ic_runtime_stub-inl.h b/runtime/ic/ic_runtime_stub-inl.h index 38c294ed2b47f6840759e5a22831a9d8481ce511..cfcc9b114cccaae9cf6c0874dcfffca1757b5f24 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 e62d72fb6a06cd9a47489d4898a19700e3b45546..08a6e05848eb75317865d33018e16fdaaffc7fff 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());