From 1a26c88329ca3021cebfe35aa1309f1e133a96ac Mon Sep 17 00:00:00 2001 From: Gymee Date: Fri, 15 Mar 2024 22:18:37 +0800 Subject: [PATCH] Support BigInt in Sendable object Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I98ZHH Signed-off-by: Gymee Change-Id: Ief90140eaf019ff85eb657964b0e8a0e37d5ee68 --- .../builtins/builtins_object_stub_builder.cpp | 2 +- ecmascript/compiler/profiler_stub_builder.cpp | 5 +- ecmascript/compiler/stub_builder-inl.h | 112 ++++++++------- ecmascript/compiler/stub_builder.cpp | 71 +++++----- ecmascript/compiler/stub_builder.h | 9 +- ecmascript/global_dictionary-inl.h | 2 +- ecmascript/ic/ic_handler.h | 10 +- ecmascript/ic/ic_runtime_stub-inl.h | 4 +- ecmascript/js_array.cpp | 2 +- ecmascript/js_hclass-inl.h | 22 +-- ecmascript/js_hclass.h | 2 +- ecmascript/js_object.cpp | 6 +- ecmascript/js_object.h | 10 +- ecmascript/js_tagged_value.h | 12 ++ .../jspandafile/class_info_extractor.cpp | 37 +++-- ecmascript/jspandafile/class_info_extractor.h | 18 ++- ecmascript/object_factory.cpp | 2 +- ecmascript/object_fast_operator-inl.h | 4 +- ecmascript/object_operator.cpp | 22 +-- ecmascript/object_operator.h | 10 +- ecmascript/property_attributes.h | 131 ++++++++++-------- ecmascript/stubs/runtime_stubs.cpp | 14 +- ecmascript/tagged_dictionary.cpp | 4 +- ecmascript/tagged_hash_table.h | 2 +- test/sharedtest/check/expect_output.txt | 10 +- test/sharedtest/check/sharedcheck.ts | 52 ++++++- 26 files changed, 336 insertions(+), 239 deletions(-) diff --git a/ecmascript/compiler/builtins/builtins_object_stub_builder.cpp b/ecmascript/compiler/builtins/builtins_object_stub_builder.cpp index bee947595a..fc42e74881 100644 --- a/ecmascript/compiler/builtins/builtins_object_stub_builder.cpp +++ b/ecmascript/compiler/builtins/builtins_object_stub_builder.cpp @@ -441,7 +441,7 @@ void BuiltinsObjectStubBuilder::LayoutInfoAssignAllEnumProperty(Variable *result Bind(&next); GateRef key = GetKeyFromLayoutInfo(layout, *idx); - GateRef attr = TruncInt64ToInt32(GetPropAttrFromLayoutInfo(layout, *idx)); + GateRef attr = GetPropAttrFromLayoutInfo(layout, *idx); Label stringKey(env); Branch(TaggedIsString(key), &stringKey, &loopEnd); Bind(&stringKey); diff --git a/ecmascript/compiler/profiler_stub_builder.cpp b/ecmascript/compiler/profiler_stub_builder.cpp index 70e840d4d1..65e2814217 100644 --- a/ecmascript/compiler/profiler_stub_builder.cpp +++ b/ecmascript/compiler/profiler_stub_builder.cpp @@ -407,7 +407,7 @@ GateRef ProfilerStubBuilder::UpdateTrackTypeInPropAttr(GateRef attr, GateRef val GateRef oldTrackType = GetTrackTypeInPropAttr(attr); DEFVARIABLE(newTrackType, VariableType::INT32(), Int32(static_cast(TrackType::TAGGED))); - DEFVARIABLE(result, VariableType::INT32(), attr); + DEFVARIABLE(result, VariableType::INT64(), attr); Label exit(env); Label judgeValue(env); @@ -451,8 +451,7 @@ void ProfilerStubBuilder::UpdatePropAttrIC( GateRef attrIndex = HandlerBaseGetAttrIndex(handler); GateRef hclass = LoadHClass(receiver); GateRef layout = GetLayoutFromHClass(hclass); - GateRef propAttr = GetPropAttrFromLayoutInfo(layout, attrIndex); - GateRef attr = GetInt32OfTInt(propAttr); + GateRef attr = GetPropAttrFromLayoutInfo(layout, attrIndex); GateRef newAttr = UpdateTrackTypeInPropAttr(attr, value, callback); Branch(IsJSShared(receiver), &exit, &handleUnShared); Bind(&handleUnShared); diff --git a/ecmascript/compiler/stub_builder-inl.h b/ecmascript/compiler/stub_builder-inl.h index c71728b27c..69deae226e 100644 --- a/ecmascript/compiler/stub_builder-inl.h +++ b/ecmascript/compiler/stub_builder-inl.h @@ -1390,7 +1390,7 @@ inline GateRef StubBuilder::IsWritable(GateRef attr) { return Int32NotEqual( Int32And( - Int32LSR(attr, Int32(PropertyAttributes::WritableField::START_BIT)), + TruncInt64ToInt32(Int64LSR(attr, Int64(PropertyAttributes::WritableField::START_BIT))), Int32((1LLU << PropertyAttributes::WritableField::SIZE) - 1)), Int32(0)); } @@ -1399,7 +1399,7 @@ inline GateRef StubBuilder::IsDefaultAttribute(GateRef attr) { return Int32NotEqual( Int32And( - Int32LSR(attr, Int32(PropertyAttributes::DefaultAttributesField::START_BIT)), + TruncInt64ToInt32(Int64LSR(attr, Int64(PropertyAttributes::DefaultAttributesField::START_BIT))), Int32((1LLU << PropertyAttributes::DefaultAttributesField::SIZE) - 1)), Int32(0)); } @@ -1408,7 +1408,7 @@ inline GateRef StubBuilder::IsConfigable(GateRef attr) { return Int32NotEqual( Int32And( - Int32LSR(attr, Int32(PropertyAttributes::ConfigurableField::START_BIT)), + TruncInt64ToInt32(Int64LSR(attr, Int64(PropertyAttributes::ConfigurableField::START_BIT))), Int32((1LLU << PropertyAttributes::ConfigurableField::SIZE) - 1)), Int32(0)); } @@ -1416,8 +1416,8 @@ inline GateRef StubBuilder::IsConfigable(GateRef attr) inline GateRef StubBuilder::IsAccessor(GateRef attr) { return Int32NotEqual( - Int32And(Int32LSR(attr, - Int32(PropertyAttributes::IsAccessorField::START_BIT)), + Int32And( + TruncInt64ToInt32(Int64LSR(attr, Int64(PropertyAttributes::IsAccessorField::START_BIT))), Int32((1LLU << PropertyAttributes::IsAccessorField::SIZE) - 1)), Int32(0)); } @@ -1425,8 +1425,8 @@ inline GateRef StubBuilder::IsAccessor(GateRef attr) inline GateRef StubBuilder::IsEnumerable(GateRef attr) { return Int32NotEqual( - Int32And(Int32LSR(attr, - Int32(PropertyAttributes::EnumerableField::START_BIT)), + Int32And( + TruncInt64ToInt32(Int64LSR(attr, Int64(PropertyAttributes::EnumerableField::START_BIT))), Int32((1LLU << PropertyAttributes::EnumerableField::SIZE) - 1)), Int32(0)); } @@ -1434,8 +1434,8 @@ inline GateRef StubBuilder::IsEnumerable(GateRef attr) inline GateRef StubBuilder::IsInlinedProperty(GateRef attr) { return Int32NotEqual( - Int32And(Int32LSR(attr, - Int32(PropertyAttributes::IsInlinedPropsField::START_BIT)), + Int32And( + TruncInt64ToInt32(Int64LSR(attr, Int64(PropertyAttributes::IsInlinedPropsField::START_BIT))), Int32((1LLU << PropertyAttributes::IsInlinedPropsField::SIZE) - 1)), Int32(0)); } @@ -1755,18 +1755,18 @@ inline GateRef StubBuilder::GetTransWithProtoHandlerInfo(GateRef obj) inline GateRef StubBuilder::PropAttrGetOffset(GateRef attr) { return Int32And( - Int32LSR(attr, Int32(PropertyAttributes::OffsetField::START_BIT)), + TruncInt64ToInt32(Int64LSR(attr, Int64(PropertyAttributes::OffsetField::START_BIT))), Int32((1LLU << PropertyAttributes::OffsetField::SIZE) - 1)); } // SetDictionaryOrder func in property_attribute.h inline GateRef StubBuilder::SetDictionaryOrderFieldInPropAttr(GateRef attr, GateRef value) { - GateRef mask = Int32LSL( - Int32((1LLU << PropertyAttributes::DictionaryOrderField::SIZE) - 1), - Int32(PropertyAttributes::DictionaryOrderField::START_BIT)); - GateRef newVal = Int32Or(Int32And(attr, Int32Not(mask)), - Int32LSL(value, Int32(PropertyAttributes::DictionaryOrderField::START_BIT))); + GateRef mask = Int64LSL( + Int64((1LLU << PropertyAttributes::DictionaryOrderField::SIZE) - 1), + Int64(PropertyAttributes::DictionaryOrderField::START_BIT)); + GateRef newVal = Int64Or(Int64And(attr, Int64Not(mask)), + Int64LSL(value, Int64(PropertyAttributes::DictionaryOrderField::START_BIT))); return newVal; } @@ -2094,8 +2094,8 @@ inline void StubBuilder::CheckUpdateSharedType(bool isDicMode, Variable *result, Bind(&isSharedObj); { Label typeMismatch(env); - GateRef trackType = isDicMode ? GetDictTrackTypeInPropAttr(attr) : GetTrackTypeInPropAttr(attr); - MatchTrackType(trackType, value, executeSetProp, &typeMismatch); + GateRef fieldType = isDicMode ? GetDictSharedFieldTypeInPropAttr(attr) : GetSharedFieldTypeInPropAttr(attr); + MatchFieldType(fieldType, value, executeSetProp, &typeMismatch); Bind(&typeMismatch); { GateRef taggedId = Int32(GET_MESSAGE_STRING_ID(SetTypeMismatchedSharedProperty)); @@ -2106,12 +2106,12 @@ inline void StubBuilder::CheckUpdateSharedType(bool isDicMode, Variable *result, } } -inline void StubBuilder::MatchTrackType(Variable *result, GateRef glue, GateRef trackType, GateRef value, +inline void StubBuilder::MatchFieldType(Variable *result, GateRef glue, GateRef fieldType, GateRef value, Label *executeSetProp, Label *exit) { auto *env = GetEnvironment(); Label typeMismatch(env); - MatchTrackType(trackType, value, executeSetProp, &typeMismatch); + MatchFieldType(fieldType, value, executeSetProp, &typeMismatch); Bind(&typeMismatch); { GateRef taggedId = Int32(GET_MESSAGE_STRING_ID(SetTypeMismatchedSharedProperty)); @@ -2121,11 +2121,11 @@ inline void StubBuilder::MatchTrackType(Variable *result, GateRef glue, GateRef } } -inline GateRef StubBuilder::GetTrackTypeFromHandler(GateRef attr) +inline GateRef StubBuilder::GetFieldTypeFromHandler(GateRef attr) { return Int32And(Int32LSR(attr, - Int32(HandlerBase::STrackTypeBit::START_BIT)), - Int32((1LLU << HandlerBase::STrackTypeBit::SIZE) - 1)); + Int32(HandlerBase::SFieldTypeBit::START_BIT)), + Int32((1LLU << HandlerBase::SFieldTypeBit::SIZE) - 1)); } inline GateRef StubBuilder::ClearSharedStoreKind(GateRef handlerInfo) @@ -2180,13 +2180,14 @@ inline void StubBuilder::SetPropAttrToLayoutInfo(GateRef glue, GateRef layout, G { GateRef index = Int32Add(Int32LSL(entry, Int32(LayoutInfo::ELEMENTS_INDEX_LOG2)), Int32(LayoutInfo::ATTR_INDEX_OFFSET)); - GateRef taggedAttr = Int64ToTaggedInt(ZExtInt32ToInt64(attr)); + GateRef taggedAttr = Int64ToTaggedInt(attr); SetValueToTaggedArray(VariableType::JS_ANY(), glue, layout, index, taggedAttr); } inline GateRef StubBuilder::GetPropertyMetaDataFromAttr(GateRef attr) { - return Int32And(Int32LSR(attr, Int32(PropertyAttributes::PropertyMetaDataField::START_BIT)), + return Int32And( + TruncInt64ToInt32(Int64LSR(attr, Int64(PropertyAttributes::PropertyMetaDataField::START_BIT))), Int32((1LLU << PropertyAttributes::PropertyMetaDataField::SIZE) - 1)); } @@ -2429,61 +2430,68 @@ inline GateRef StubBuilder::IsCallable(GateRef obj) inline GateRef StubBuilder::GetOffsetFieldInPropAttr(GateRef attr) { return Int32And( - Int32LSR(attr, Int32(PropertyAttributes::OffsetField::START_BIT)), + TruncInt64ToInt32(Int64LSR(attr, Int64(PropertyAttributes::OffsetField::START_BIT))), Int32((1LLU << PropertyAttributes::OffsetField::SIZE) - 1)); } // SetOffset func in property_attribute.h inline GateRef StubBuilder::SetOffsetFieldInPropAttr(GateRef attr, GateRef value) { - GateRef mask = Int32LSL( - Int32((1LLU << PropertyAttributes::OffsetField::SIZE) - 1), - Int32(PropertyAttributes::OffsetField::START_BIT)); - GateRef newVal = Int32Or(Int32And(attr, Int32Not(mask)), - Int32LSL(value, Int32(PropertyAttributes::OffsetField::START_BIT))); + GateRef mask = Int64LSL( + Int64((1LLU << PropertyAttributes::OffsetField::SIZE) - 1), + Int64(PropertyAttributes::OffsetField::START_BIT)); + GateRef newVal = Int64Or(Int64And(attr, Int64Not(mask)), + Int64LSL(ZExtInt32ToInt64(value), Int64(PropertyAttributes::OffsetField::START_BIT))); return newVal; } // SetIsInlinedProps func in property_attribute.h inline GateRef StubBuilder::SetIsInlinePropsFieldInPropAttr(GateRef attr, GateRef value) { - GateRef mask = Int32LSL( - Int32((1LU << PropertyAttributes::IsInlinedPropsField::SIZE) - 1), - Int32(PropertyAttributes::IsInlinedPropsField::START_BIT)); - GateRef newVal = Int32Or(Int32And(attr, Int32Not(mask)), - Int32LSL(value, Int32(PropertyAttributes::IsInlinedPropsField::START_BIT))); + GateRef mask = Int64LSL( + Int64((1LU << PropertyAttributes::IsInlinedPropsField::SIZE) - 1), + Int64(PropertyAttributes::IsInlinedPropsField::START_BIT)); + GateRef newVal = Int64Or(Int64And(attr, Int64Not(mask)), + Int64LSL(ZExtInt32ToInt64(value), Int64(PropertyAttributes::IsInlinedPropsField::START_BIT))); return newVal; } inline GateRef StubBuilder::SetTrackTypeInPropAttr(GateRef attr, GateRef type) { - GateRef mask = Int32LSL( - Int32((1LU << PropertyAttributes::TrackTypeField::SIZE) - 1), - Int32(PropertyAttributes::TrackTypeField::START_BIT)); - GateRef newVal = Int32Or(Int32And(attr, Int32Not(mask)), - Int32LSL(type, Int32(PropertyAttributes::TrackTypeField::START_BIT))); + GateRef mask = Int64LSL( + Int64((1LU << PropertyAttributes::TrackTypeField::SIZE) - 1), + Int64(PropertyAttributes::TrackTypeField::START_BIT)); + GateRef newVal = Int64Or(Int64And(attr, Int64Not(mask)), + Int64LSL(ZExtInt32ToInt64(type), Int64(PropertyAttributes::TrackTypeField::START_BIT))); return newVal; } +inline GateRef StubBuilder::GetSharedFieldTypeInPropAttr(GateRef attr) +{ + return Int32And( + TruncInt64ToInt32(Int64LSR(attr, Int64(PropertyAttributes::SharedFieldTypeField::START_BIT))), + Int32((1LLU << PropertyAttributes::SharedFieldTypeField::SIZE) - 1)); +} + inline GateRef StubBuilder::GetTrackTypeInPropAttr(GateRef attr) { return Int32And( - Int32LSR(attr, Int32(PropertyAttributes::TrackTypeField::START_BIT)), + TruncInt64ToInt32(Int64LSR(attr, Int64(PropertyAttributes::TrackTypeField::START_BIT))), Int32((1LLU << PropertyAttributes::TrackTypeField::SIZE) - 1)); } -inline GateRef StubBuilder::GetDictTrackTypeInPropAttr(GateRef attr) +inline GateRef StubBuilder::GetDictSharedFieldTypeInPropAttr(GateRef attr) { return Int32And( - Int32LSR(attr, Int32(PropertyAttributes::DictTrackTypeField::START_BIT)), - Int32((1LLU << PropertyAttributes::DictTrackTypeField::SIZE) - 1)); + TruncInt64ToInt32(Int64LSR(attr, Int64(PropertyAttributes::DictSharedFieldTypeField::START_BIT))), + Int32((1LLU << PropertyAttributes::DictSharedFieldTypeField::SIZE) - 1)); } inline GateRef StubBuilder::GetRepInPropAttr(GateRef attr) { return Int32And( - Int32LSR(attr, Int32(PropertyAttributes::RepresentationField::START_BIT)), + TruncInt64ToInt32(Int64LSR(attr, Int64(PropertyAttributes::RepresentationField::START_BIT))), Int32((1LLU << PropertyAttributes::RepresentationField::SIZE) - 1)); } @@ -2499,12 +2507,12 @@ inline GateRef StubBuilder::IsDoubleRepInPropAttr(GateRef rep) inline GateRef StubBuilder::SetTaggedRepInPropAttr(GateRef attr) { - GateRef mask = Int32LSL( - Int32((1LU << PropertyAttributes::RepresentationField::SIZE) - 1), - Int32(PropertyAttributes::RepresentationField::START_BIT)); - GateRef targetType = Int32(static_cast(Representation::TAGGED)); - GateRef newVal = Int32Or(Int32And(attr, Int32Not(mask)), - Int32LSL(targetType, Int32(PropertyAttributes::RepresentationField::START_BIT))); + GateRef mask = Int64LSL( + Int64((1LU << PropertyAttributes::RepresentationField::SIZE) - 1), + Int64(PropertyAttributes::RepresentationField::START_BIT)); + GateRef targetType = Int32(static_cast(Representation::TAGGED)); + GateRef newVal = Int64Or(Int64And(attr, Int64Not(mask)), + Int64LSL(ZExtInt32ToInt64(targetType), Int64(PropertyAttributes::RepresentationField::START_BIT))); return newVal; } @@ -3144,7 +3152,7 @@ inline GateRef StubBuilder::GetKeyIndex(GateRef index) inline GateRef StubBuilder::GetAttr(GateRef layoutInfo, GateRef index) { GateRef fixedIdx = GetAttrIndex(index); - return GetInt32OfTInt(GetValueFromTaggedArray(layoutInfo, fixedIdx)); + return GetInt64OfTInt(GetValueFromTaggedArray(layoutInfo, fixedIdx)); } inline GateRef StubBuilder::GetKey(GateRef layoutInfo, GateRef index) diff --git a/ecmascript/compiler/stub_builder.cpp b/ecmascript/compiler/stub_builder.cpp index 0e79e99d82..da29abf54b 100644 --- a/ecmascript/compiler/stub_builder.cpp +++ b/ecmascript/compiler/stub_builder.cpp @@ -114,7 +114,7 @@ void StubBuilder::LoopEnd(Label *loopHead) env_->SetCurrentLabel(nullptr); } -void StubBuilder::MatchTrackType(GateRef trackType, GateRef value, Label *executeSetProp, Label *typeMismatch) +void StubBuilder::MatchFieldType(GateRef fieldType, GateRef value, Label *executeSetProp, Label *typeMismatch) { auto *env = GetEnvironment(); Label isNumber(env); @@ -124,11 +124,13 @@ void StubBuilder::MatchTrackType(GateRef trackType, GateRef value, Label *execut Label isString(env); Label checkJSShared(env); Label isJSShared(env); + Label checkBigInt(env); + Label isBigInt(env); Label checkJSNone(env); Label isJSNone(env); Label exit(env); DEFVARIABLE(result, VariableType::BOOL(), False()); - Branch(Equal(trackType, Int32(static_cast(TrackType::NUMBER))), &isNumber, &checkBoolean); + Branch(Equal(fieldType, Int32(static_cast(SharedFieldType::NUMBER))), &isNumber, &checkBoolean); Bind(&isNumber); { result = TaggedIsNumber(value); @@ -136,7 +138,7 @@ void StubBuilder::MatchTrackType(GateRef trackType, GateRef value, Label *execut } Bind(&checkBoolean); { - Branch(Equal(trackType, Int32(static_cast(TrackType::BOOLEAN))), &isBoolean, &checkString); + Branch(Equal(fieldType, Int32(static_cast(SharedFieldType::BOOLEAN))), &isBoolean, &checkString); Bind(&isBoolean); { result = TaggedIsBoolean(value); @@ -145,7 +147,7 @@ void StubBuilder::MatchTrackType(GateRef trackType, GateRef value, Label *execut } Bind(&checkString); { - Branch(Equal(trackType, Int32(static_cast(TrackType::STRING))), &isString, &checkJSShared); + Branch(Equal(fieldType, Int32(static_cast(SharedFieldType::STRING))), &isString, &checkJSShared); Bind(&isString); { result = BoolOr(TaggedIsString(value), TaggedIsNull(value)); @@ -154,16 +156,25 @@ void StubBuilder::MatchTrackType(GateRef trackType, GateRef value, Label *execut } Bind(&checkJSShared); { - Branch(Equal(trackType, Int32(static_cast(TrackType::SENDABLE))), &isJSShared, &checkJSNone); + Branch(Equal(fieldType, Int32(static_cast(SharedFieldType::SENDABLE))), &isJSShared, &checkBigInt); Bind(&isJSShared); { result = BoolOr(TaggedIsShared(value), TaggedIsNull(value)); Jump(&exit); } } + Bind(&checkBigInt); + { + Branch(Equal(fieldType, Int32(static_cast(SharedFieldType::BIG_INT))), &isBigInt, &checkJSNone); + Bind(&isBigInt); + { + result = TaggedIsBigInt(value); + Jump(&exit); + } + } Bind(&checkJSNone); { - Branch(Equal(trackType, Int32(static_cast(TrackType::NONE))), &isJSNone, &exit); + Branch(Equal(fieldType, Int32(static_cast(SharedFieldType::NONE))), &isJSNone, &exit); Bind(&isJSNone); { // bypass none type @@ -399,7 +410,6 @@ GateRef StubBuilder::IsMatchInTransitionDictionary(GateRef element, GateRef key, return BoolAnd(Equal(element, key), Int32Equal(metaData, attr)); } -// metaData is int32 type GateRef StubBuilder::FindEntryFromTransitionDictionary(GateRef glue, GateRef elements, GateRef key, GateRef metaData) { auto env = GetEnvironment(); @@ -477,7 +487,8 @@ GateRef StubBuilder::FindEntryFromTransitionDictionary(GateRef glue, GateRef ele Label notMatch(env); Branch( IsMatchInTransitionDictionary(element, key, metaData, - GetAttributesFromDictionary(elements, *entry)), + // metaData is int32 type + TruncInt64ToInt32(GetAttributesFromDictionary(elements, *entry))), &isMatch, ¬Match); { Bind(&isMatch); @@ -837,7 +848,7 @@ void StubBuilder::JSHClassAddProperty(GateRef glue, GateRef receiver, GateRef ke IntToTaggedInt(inlineProps) }); CopyAllHClass(glue, newJshclass, hclass); CallRuntime(glue, RTSTUB_ID(UpdateLayOutAndAddTransition), - { hclass, newJshclass, key, IntToTaggedInt(attr) }); + { hclass, newJshclass, key, Int64ToTaggedInt(attr) }); #if ECMASCRIPT_ENABLE_IC NotifyHClassChanged(glue, hclass, newJshclass); #endif @@ -889,7 +900,7 @@ GateRef StubBuilder::AddPropertyByName(GateRef glue, GateRef receiver, GateRef k } Bind(&afterCtorCon); // 0x111 : default attribute for property: writable, enumerable, configurable - DEFVARIABLE(attr, VariableType::INT32(), propertyAttributes); + DEFVARIABLE(attr, VariableType::INT64(), propertyAttributes); GateRef numberOfProps = GetNumberOfPropsFromHClass(hclass); GateRef inlinedProperties = GetInlinedPropertiesFromHClass(hclass); Label hasUnusedInProps(env); @@ -909,7 +920,7 @@ GateRef StubBuilder::AddPropertyByName(GateRef glue, GateRef receiver, GateRef k GateRef newHclass = LoadHClass(receiver); GateRef newLayoutInfo = GetLayoutFromHClass(newHclass); GateRef offset = GetInlinedPropOffsetFromHClass(hclass, numberOfProps); - attr = GetInt32OfTInt(GetPropAttrFromLayoutInfo(newLayoutInfo, numberOfProps)); + attr = GetPropAttrFromLayoutInfo(newLayoutInfo, numberOfProps); SetValueWithAttr(glue, receiver, offset, key, value, *attr); result = Undefined(); Jump(&exit); @@ -941,7 +952,7 @@ GateRef StubBuilder::AddPropertyByName(GateRef glue, GateRef receiver, GateRef k Bind(&isDictMode); { GateRef res = CallRuntime(glue, RTSTUB_ID(NameDictPutIfAbsent), - {receiver, *array, key, value, IntToTaggedInt(*attr), TaggedFalse()}); + {receiver, *array, key, value, Int64ToTaggedInt(*attr), TaggedFalse()}); SetPropertiesArray(VariableType::JS_POINTER(), glue, receiver, res); Jump(&exit); } @@ -960,7 +971,7 @@ GateRef StubBuilder::AddPropertyByName(GateRef glue, GateRef receiver, GateRef k attr = SetDictionaryOrderFieldInPropAttr(*attr, Int32(PropertyAttributes::MAX_FAST_PROPS_CAPACITY)); GateRef res = CallRuntime(glue, RTSTUB_ID(NameDictPutIfAbsent), - { receiver, *array, key, value, IntToTaggedInt(*attr), TaggedTrue() }); + { receiver, *array, key, value, Int64ToTaggedInt(*attr), TaggedTrue() }); SetPropertiesArray(VariableType::JS_POINTER(), glue, receiver, res); result = Undefined(); Jump(&exit); @@ -2178,8 +2189,8 @@ GateRef StubBuilder::StoreICWithHandler(GateRef glue, GateRef receiver, GateRef Branch(IsStoreShared(handlerInfo), &isShared, ¬Shared); Bind(&isShared); { - GateRef trackType = GetTrackTypeFromHandler(handlerInfo); - MatchTrackType(&result, glue, trackType, value, &prepareIntHandlerLoop, &exit); + GateRef field = GetFieldTypeFromHandler(handlerInfo); + MatchFieldType(&result, glue, field, value, &prepareIntHandlerLoop, &exit); Bind(&prepareIntHandlerLoop); { handler = IntToTaggedPtr(ClearSharedStoreKind(handlerInfo)); @@ -2459,7 +2470,7 @@ GateRef StubBuilder::GetAttributesFromDictionary(GateRef elements, GateRef entry GateRef attributesIndex = Int32Add(arrayIndex, Int32(DictionaryT::ENTRY_DETAILS_INDEX)); auto attrValue = GetValueFromTaggedArray(elements, attributesIndex); - return GetInt32OfTInt(attrValue); + return GetInt64OfTInt(attrValue); } template @@ -2520,7 +2531,7 @@ inline void StubBuilder::UpdateValueAndAttributes(GateRef glue, GateRef elements GateRef attroffset = PtrMul(ZExtInt32ToPtr(attributesIndex), IntPtr(JSTaggedValue::TaggedTypeSize())); GateRef dataOffset = PtrAdd(attroffset, IntPtr(TaggedArray::DATA_OFFSET)); - Store(VariableType::INT64(), glue, elements, dataOffset, IntToTaggedInt(attr)); + Store(VariableType::INT64(), glue, elements, dataOffset, Int64ToTaggedInt(attr)); } template @@ -2835,8 +2846,7 @@ GateRef StubBuilder::GetPropertyByName(GateRef glue, GateRef receiver, GateRef k Bind(&hasEntry); { // PropertyAttributes attr(layoutInfo->GetAttr(entry)) - GateRef propAttr = GetPropAttrFromLayoutInfo(layOutInfo, entryA); - GateRef attr = GetInt32OfTInt(propAttr); + GateRef attr = GetPropAttrFromLayoutInfo(layOutInfo, entryA); GateRef value = JSObjectGetProperty(*holder, hclass, attr); Label isAccessor(env); Label notAccessor(env); @@ -2957,7 +2967,7 @@ void StubBuilder::TransitionForRepChange(GateRef glue, GateRef receiver, GateRef IntToTaggedInt(inlineProps) }); CopyAllHClass(glue, newJshclass, hclass); CallRuntime(glue, RTSTUB_ID(CopyAndUpdateObjLayout), - { hclass, newJshclass, key, IntToTaggedInt(attr) }); + { hclass, newJshclass, key, Int64ToTaggedInt(attr) }); #if ECMASCRIPT_ENABLE_IC NotifyHClassChanged(glue, hclass, newJshclass); #endif @@ -3045,7 +3055,7 @@ GateRef StubBuilder::AddElementInternal(GateRef glue, GateRef receiver, GateRef Bind(&isDicMode); { GateRef res = CallRuntime(glue, RTSTUB_ID(NumberDictionaryPut), - { receiver, elements, IntToTaggedInt(index), value, IntToTaggedInt(attr), TaggedFalse() }); + { receiver, elements, IntToTaggedInt(index), value, Int64ToTaggedInt(attr), TaggedFalse() }); SetElementsArray(VariableType::JS_POINTER(), glue, receiver, res); result = True(); Jump(&exit); @@ -3065,7 +3075,7 @@ GateRef StubBuilder::AddElementInternal(GateRef glue, GateRef receiver, GateRef Bind(&isTransToDict); { GateRef res = CallRuntime(glue, RTSTUB_ID(NumberDictionaryPut), - { receiver, elements, IntToTaggedInt(index), value, IntToTaggedInt(attr), TaggedTrue() }); + { receiver, elements, IntToTaggedInt(index), value, Int64ToTaggedInt(attr), TaggedTrue() }); SetElementsArray(VariableType::JS_POINTER(), glue, receiver, res); result = True(); Jump(&exit); @@ -3233,7 +3243,7 @@ GateRef StubBuilder::IsArrayLengthWritable(GateRef glue, GateRef receiver) } Bind(&isNegtiveOne); { - GateRef attr1 = Int32(PropertyAttributes::GetDefaultAttributes()); + GateRef attr1 = Int64(PropertyAttributes::GetDefaultAttributes()); result = IsWritable(attr1); Jump(&exit); } @@ -3241,8 +3251,7 @@ GateRef StubBuilder::IsArrayLengthWritable(GateRef glue, GateRef receiver) Bind(¬DicMode); { GateRef layoutInfo = GetLayoutFromHClass(hclass); - GateRef propAttr = GetPropAttrFromLayoutInfo(layoutInfo, Int32(JSArray::LENGTH_INLINE_PROPERTY_INDEX)); - GateRef attr = GetInt32OfTInt(propAttr); + GateRef attr = GetPropAttrFromLayoutInfo(layoutInfo, Int32(JSArray::LENGTH_INLINE_PROPERTY_INDEX)); result = IsWritable(attr); Jump(&exit); } @@ -3276,7 +3285,7 @@ GateRef StubBuilder::FindTransitions(GateRef glue, GateRef receiver, GateRef hcl GateRef last = Int32Sub(propNums, Int32(1)); GateRef layoutInfo = GetLayoutFromHClass(transitionHClass); GateRef cachedKey = GetKeyFromLayoutInfo(layoutInfo, last); - GateRef cachedAttr = GetInt32OfTInt(GetPropAttrFromLayoutInfo(layoutInfo, last)); + GateRef cachedAttr = GetPropAttrFromLayoutInfo(layoutInfo, last); GateRef cachedMetaData = GetPropertyMetaDataFromAttr(cachedAttr); Label keyMatch(env); Label isMatch(env); @@ -3532,7 +3541,7 @@ GateRef StubBuilder::SetPropertyByIndex(GateRef glue, GateRef receiver, GateRef Label success(env); Label failed(env); Branch(AddElementInternal(glue, receiver, index, value, - Int32(PropertyAttributes::GetDefaultAttributes())), &success, &failed); + Int64(PropertyAttributes::GetDefaultAttributes())), &success, &failed); Bind(&success); { returnValue = Undefined(); @@ -3658,8 +3667,7 @@ GateRef StubBuilder::SetPropertyByName(GateRef glue, GateRef receiver, GateRef k Bind(&hasEntry); { // PropertyAttributes attr(layoutInfo->GetAttr(entry)) - GateRef propAttr = GetPropAttrFromLayoutInfo(layOutInfo, entry); - GateRef attr = GetInt32OfTInt(propAttr); + GateRef attr = GetPropAttrFromLayoutInfo(layOutInfo, entry); Label isAccessor(env); Label notAccessor(env); Branch(IsAccessor(attr), &isAccessor, ¬Accessor); @@ -3832,8 +3840,7 @@ GateRef StubBuilder::SetPropertyByName(GateRef glue, GateRef receiver, GateRef k { GateRef receiverHClass = LoadHClass(receiver); GateRef receiverLayoutInfo = GetLayoutFromHClass(receiverHClass); - GateRef holePropAttr = GetPropAttrFromLayoutInfo(receiverLayoutInfo, *receiverHoleEntry); - GateRef holeAttr = GetInt32OfTInt(holePropAttr); + GateRef holeAttr = GetPropAttrFromLayoutInfo(receiverLayoutInfo, *receiverHoleEntry); JSObjectSetProperty(glue, receiver, receiverHClass, holeAttr, key, value); ProfilerStubBuilder(env).UpdatePropAttrWithValue( glue, jsType, receiverLayoutInfo, holeAttr, *receiverHoleEntry, value, callback); @@ -3855,7 +3862,7 @@ GateRef StubBuilder::SetPropertyByName(GateRef glue, GateRef receiver, GateRef k Bind(&extensible); { result = AddPropertyByName(glue, receiver, key, value, - Int32(PropertyAttributes::GetDefaultAttributes()), callback); + Int64(PropertyAttributes::GetDefaultAttributes()), callback); Jump(&exit); } Bind(&exit); diff --git a/ecmascript/compiler/stub_builder.h b/ecmascript/compiler/stub_builder.h index e2eb326ee3..6e4bb54480 100644 --- a/ecmascript/compiler/stub_builder.h +++ b/ecmascript/compiler/stub_builder.h @@ -476,9 +476,9 @@ public: GateRef GetValueFromMutantTaggedArray(GateRef elements, GateRef index); void CheckUpdateSharedType(bool isDicMode, Variable *result, GateRef glue, GateRef jsType, GateRef attr, GateRef value, Label *executeSetProp, Label *exit); - void MatchTrackType(Variable *result, GateRef glue, GateRef trackType, GateRef value, Label *executeSetProp, + void MatchFieldType(Variable *result, GateRef glue, GateRef fieldType, GateRef value, Label *executeSetProp, Label *exit); - GateRef GetTrackTypeFromHandler(GateRef attr); + GateRef GetFieldTypeFromHandler(GateRef attr); GateRef ClearSharedStoreKind(GateRef handlerInfo); GateRef GetTaggedValueWithElementsKind(GateRef receiver, GateRef index); GateRef SetValueWithElementsKind(GateRef glue, GateRef receiver, GateRef rawValue, GateRef index, @@ -504,7 +504,7 @@ public: GateRef GetPropertiesAddrFromLayoutInfo(GateRef layout); GateRef GetPropertyMetaDataFromAttr(GateRef attr); GateRef GetKeyFromLayoutInfo(GateRef layout, GateRef entry); - void MatchTrackType(GateRef trackType, GateRef value, Label *executeSetProp, Label *typeMismatch); + void MatchFieldType(GateRef fieldType, GateRef value, Label *executeSetProp, Label *typeMismatch); GateRef FindElementWithCache(GateRef glue, GateRef layoutInfo, GateRef hClass, GateRef key, GateRef propsNum); GateRef FindElementFromNumberDictionary(GateRef glue, GateRef elements, GateRef index); @@ -606,7 +606,8 @@ public: GateRef SetIsInlinePropsFieldInPropAttr(GateRef attr, GateRef value); GateRef SetTrackTypeInPropAttr(GateRef attr, GateRef type); GateRef GetTrackTypeInPropAttr(GateRef attr); - GateRef GetDictTrackTypeInPropAttr(GateRef attr); + GateRef GetSharedFieldTypeInPropAttr(GateRef attr); + GateRef GetDictSharedFieldTypeInPropAttr(GateRef attr); GateRef GetRepInPropAttr(GateRef attr); GateRef IsIntRepInPropAttr(GateRef attr); GateRef IsDoubleRepInPropAttr(GateRef attr); diff --git a/ecmascript/global_dictionary-inl.h b/ecmascript/global_dictionary-inl.h index 3ead58695c..a77633e647 100644 --- a/ecmascript/global_dictionary-inl.h +++ b/ecmascript/global_dictionary-inl.h @@ -61,7 +61,7 @@ JSTaggedValue GlobalDictionary::GetValue(int entry) const PropertyAttributes GlobalDictionary::GetAttributes(int entry) const { int index = GetEntryIndex(entry) + ENTRY_DETAILS_INDEX; - return PropertyAttributes(Get(index).GetInt()); + return PropertyAttributes(Get(index)); } void GlobalDictionary::SetEntry(const JSThread *thread, int entry, const JSTaggedValue &key, const JSTaggedValue &value, diff --git a/ecmascript/ic/ic_handler.h b/ecmascript/ic/ic_handler.h index 9372869c32..cdb2dbb7d2 100644 --- a/ecmascript/ic/ic_handler.h +++ b/ecmascript/ic/ic_handler.h @@ -65,7 +65,7 @@ public: using SWholeKindBit = KindBit; static_assert(SKindBit::START_BIT == SWholeKindBit::START_BIT); static_assert(SSharedBit::Mask() || SKindBit::Mask() == KindBit::Mask()); - using STrackTypeBit = AttrIndexBit::NextField; + using SFieldTypeBit = AttrIndexBit::NextField; static_assert(static_cast(StoreHandlerKind::S_TOTAL_KINDS) <= (1 << STORE_KIND_BIT_LENGTH)); HandlerBase() = default; @@ -81,9 +81,9 @@ public: return InternalAccessorBit::Get(handler); } - static inline TrackType GetTrackType(uint32_t handler) + static inline SharedFieldType GetFieldType(uint32_t handler) { - return static_cast(STrackTypeBit::Get(handler)); + return static_cast(SFieldTypeBit::Get(handler)); } static inline bool IsNonExist(uint32_t handler) @@ -283,9 +283,9 @@ public: SSharedBit::Set(op.GetReceiver()->IsJSShared(), &handler); TaggedArray *array = TaggedArray::Cast(receiver->GetProperties().GetTaggedObject()); if (!array->IsDictionaryMode()) { - STrackTypeBit::Set(static_cast(op.GetAttr().GetTrackType()), &handler); + SFieldTypeBit::Set(op.GetAttr().GetSharedFieldType(), &handler); } else { - STrackTypeBit::Set(static_cast(op.GetAttr().GetDictTrackType()), &handler); + SFieldTypeBit::Set(op.GetAttr().GetDictSharedFieldType(), &handler); } if (op.IsElement()) { return StoreElement(thread, op.GetReceiver(), handler); diff --git a/ecmascript/ic/ic_runtime_stub-inl.h b/ecmascript/ic/ic_runtime_stub-inl.h index 67bfcefa08..e8bb384a76 100644 --- a/ecmascript/ic/ic_runtime_stub-inl.h +++ b/ecmascript/ic/ic_runtime_stub-inl.h @@ -227,8 +227,8 @@ ARK_INLINE JSTaggedValue ICRuntimeStub::StoreICWithHandler(JSThread *thread, JST } bool isShared = HandlerBase::IsStoreShared(handlerInfo); if (isShared) { - TrackType trackType { HandlerBase::GetTrackType(handlerInfo) }; - if (!ClassHelper::MatchTrackType(trackType, value)) { + SharedFieldType fieldType { HandlerBase::GetFieldType(handlerInfo) }; + if (!ClassHelper::MatchFieldType(fieldType, value)) { THROW_TYPE_ERROR_AND_RETURN((thread), GET_MESSAGE_STRING(SetTypeMismatchedSharedProperty), JSTaggedValue::Exception()); } diff --git a/ecmascript/js_array.cpp b/ecmascript/js_array.cpp index aa266effc8..96a27db034 100644 --- a/ecmascript/js_array.cpp +++ b/ecmascript/js_array.cpp @@ -212,7 +212,7 @@ void JSArray::SetCapacity(JSThread *thread, const JSHandle &array, uin JSTaggedValue::StringToElementIndex(value, &output); JSTaggedValue key(static_cast(output)); int entry = dictHandle->FindEntry(key); - uint32_t attr = dictHandle->GetAttributes(entry).GetValue(); + auto attr = dictHandle->GetAttributes(entry).GetValue(); PropertyAttributes propAttr(attr); if (propAttr.IsConfigurable()) { JSHandle newDict = NumberDictionary::Remove(thread, dictHandle, entry); diff --git a/ecmascript/js_hclass-inl.h b/ecmascript/js_hclass-inl.h index 0b657e6a14..9c65b3337a 100644 --- a/ecmascript/js_hclass-inl.h +++ b/ecmascript/js_hclass-inl.h @@ -45,16 +45,16 @@ void JSHClass::AddTransitions(const JSThread *thread, const JSHandle & auto cachedHClass = JSHClass::Cast(transitions.GetTaggedWeakRef()); uint32_t last = cachedHClass->NumberOfProps() - 1; LayoutInfo *layoutInfo = LayoutInfo::Cast(cachedHClass->GetLayout().GetTaggedObject()); - auto attr = JSHandle(thread, JSTaggedValue(layoutInfo->GetAttr(last).GetPropertyMetaData())); + auto metaData = JSHandle(thread, JSTaggedValue(layoutInfo->GetAttr(last).GetPropertyMetaData())); auto lastKey = JSHandle(thread, layoutInfo->GetKey(last)); auto lastHClass = JSHandle(thread, cachedHClass); dict.Update(TransitionsDictionary::Create(thread)); - transitions = TransitionsDictionary::PutIfAbsent(thread, dict, lastKey, lastHClass, attr).GetTaggedValue(); + transitions = TransitionsDictionary::PutIfAbsent(thread, dict, lastKey, lastHClass, metaData).GetTaggedValue(); } - auto attr = JSHandle(thread, JSTaggedValue(attributes.GetPropertyMetaData())); + auto metaData = JSHandle(thread, JSTaggedValue(attributes.GetPropertyMetaData())); dict.Update(transitions); transitions = - TransitionsDictionary::PutIfAbsent(thread, dict, key, JSHandle(child), attr).GetTaggedValue(); + TransitionsDictionary::PutIfAbsent(thread, dict, key, JSHandle(child), metaData).GetTaggedValue(); parent->SetTransitions(thread, transitions); } @@ -78,11 +78,11 @@ void JSHClass::AddProtoTransitions(const JSThread *thread, const JSHandleNumberOfProps() - 1; LayoutInfo *layoutInfo = LayoutInfo::Cast(cachedHClass->GetLayout().GetTaggedObject()); - auto attr = JSHandle(thread, JSTaggedValue(layoutInfo->GetAttr(last).GetPropertyMetaData())); + auto metaData = JSHandle(thread, JSTaggedValue(layoutInfo->GetAttr(last).GetPropertyMetaData())); auto lastKey = JSHandle(thread, layoutInfo->GetKey(last)); auto lastHClass = JSHandle(thread, cachedHClass); dict.Update(TransitionsDictionary::Create(thread)); - transitions = TransitionsDictionary::PutIfAbsent(thread, dict, lastKey, lastHClass, attr).GetTaggedValue(); + transitions = TransitionsDictionary::PutIfAbsent(thread, dict, lastKey, lastHClass, metaData).GetTaggedValue(); } dict.Update(transitions); @@ -91,7 +91,7 @@ void JSHClass::AddProtoTransitions(const JSThread *thread, const JSHandleSetTransitions(thread, transitions); } -inline JSHClass *JSHClass::FindTransitions(const JSTaggedValue &key, const JSTaggedValue &attributes) +inline JSHClass *JSHClass::FindTransitions(const JSTaggedValue &key, const JSTaggedValue &metaData) { DISALLOW_GARBAGE_COLLECTION; JSTaggedValue transitions = GetTransitions(); @@ -102,9 +102,9 @@ inline JSHClass *JSHClass::FindTransitions(const JSTaggedValue &key, const JSTag auto cachedHClass = JSHClass::Cast(transitions.GetTaggedWeakRef()); int last = static_cast(cachedHClass->NumberOfProps()) - 1; LayoutInfo *layoutInfo = LayoutInfo::Cast(cachedHClass->GetLayout().GetTaggedObject()); - auto attr = layoutInfo->GetAttr(last).GetPropertyMetaData(); - auto cachedKey = layoutInfo->GetKey(last); - if (attr == attributes.GetInt() && key == cachedKey) { + auto lastMetaData = layoutInfo->GetAttr(last).GetPropertyMetaData(); + auto lastKey = layoutInfo->GetKey(last); + if (lastMetaData == metaData.GetInt() && key == lastKey) { return cachedHClass; } return nullptr; @@ -112,7 +112,7 @@ inline JSHClass *JSHClass::FindTransitions(const JSTaggedValue &key, const JSTag ASSERT(transitions.IsTaggedArray()); TransitionsDictionary *dict = TransitionsDictionary::Cast(transitions.GetTaggedObject()); - auto entry = dict->FindEntry(key, attributes); + auto entry = dict->FindEntry(key, metaData); if (entry == -1) { return nullptr; } diff --git a/ecmascript/js_hclass.h b/ecmascript/js_hclass.h index 8c8f31ea1b..ff56f13a4b 100644 --- a/ecmascript/js_hclass.h +++ b/ecmascript/js_hclass.h @@ -1850,7 +1850,7 @@ public: return GetProto(); } - inline JSHClass *FindTransitions(const JSTaggedValue &key, const JSTaggedValue &attributes); + inline JSHClass *FindTransitions(const JSTaggedValue &key, const JSTaggedValue &metaData); DECL_DUMP() diff --git a/ecmascript/js_object.cpp b/ecmascript/js_object.cpp index 90410f27a9..8d769901de 100644 --- a/ecmascript/js_object.cpp +++ b/ecmascript/js_object.cpp @@ -874,7 +874,7 @@ bool JSObject::SetPropertyForDataDescriptor(ObjectOperator *op, const JSHandleIsFound() && receiver->IsJSShared()) { - if (!ClassHelper::MatchTrackType(op->GetTrackType(), value.GetTaggedValue())) { + if (!ClassHelper::MatchFieldType(op->GetSharedFieldType(), value.GetTaggedValue())) { if (mayThrow) { THROW_TYPE_ERROR_AND_RETURN(thread, GET_MESSAGE_STRING(SetTypeMismatchedSharedProperty), false); } @@ -907,7 +907,7 @@ bool JSObject::SetPropertyForDataDescriptor(ObjectOperator *op, const JSHandleIsJSShared() && - !ClassHelper::MatchTrackType(op->GetTrackType(), value.GetTaggedValue())) { + !ClassHelper::MatchFieldType(op->GetSharedFieldType(), value.GetTaggedValue())) { if (mayThrow) { THROW_TYPE_ERROR_AND_RETURN(thread, GET_MESSAGE_STRING(SetTypeMismatchedSharedProperty), false); } @@ -1250,7 +1250,7 @@ bool JSObject::ValidateDataDescriptorWhenConfigurable(ObjectOperator *op, const if (!desc.HasValue()) { THROW_TYPE_ERROR_AND_RETURN(op->GetThread(), GET_MESSAGE_STRING(UpdateSendableAttributes), false); } - if (!ClassHelper::MatchTrackType(current.GetTrackType(), desc.GetValue().GetTaggedValue())) { + if (!ClassHelper::MatchFieldType(current.GetSharedFieldType(), desc.GetValue().GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(op->GetThread(), GET_MESSAGE_STRING(SetTypeMismatchedSharedProperty), false); } } diff --git a/ecmascript/js_object.h b/ecmascript/js_object.h index 1558514d8c..5fb9b157a9 100644 --- a/ecmascript/js_object.h +++ b/ecmascript/js_object.h @@ -109,14 +109,14 @@ public: key_ = key; } - inline void SetTrackType(TrackType trackType) + inline void SetSharedFieldType(SharedFieldType fieldType) { - trackType_ = trackType; + fieldType_ = fieldType; } - inline TrackType GetTrackType() const + inline SharedFieldType GetSharedFieldType() const { - return trackType_; + return fieldType_; } inline bool IsWritable() const @@ -243,7 +243,7 @@ private: bool hasWritable_ {false}; bool hasEnumerable_ {false}; bool hasConfigurable_ {false}; - TrackType trackType_ {TrackType::NONE}; + SharedFieldType fieldType_ {SharedFieldType::NONE}; JSHandle value_ {}; JSHandle getter_ {}; diff --git a/ecmascript/js_tagged_value.h b/ecmascript/js_tagged_value.h index 494b04bce1..aa20bb88b2 100644 --- a/ecmascript/js_tagged_value.h +++ b/ecmascript/js_tagged_value.h @@ -699,6 +699,18 @@ private: const JSHandle &key, const JSHandle &value); static JSHandle NativePointerToString(JSThread *thread, const JSHandle &tagged); + + static ARK_INLINE JSTaggedValue WrapUint64(uint64_t v) + { + return JSTaggedValue(static_cast(v) | TAG_INT); + } + static ARK_INLINE uint64_t UnwrapToUint64(JSTaggedValue v) + { + ASSERT_PRINT(v.IsInt(), "can not convert JSTaggedValue to Int :" << std::hex << v.GetRawData()); + return static_cast(v.GetRawData() & (~TAG_INT)); + } + + friend class PropertyAttributes; }; STATIC_ASSERT_EQ_ARCH(sizeof(JSTaggedValue), JSTaggedValue::SizeArch32, JSTaggedValue::SizeArch64); } // namespace panda::ecmascript diff --git a/ecmascript/jspandafile/class_info_extractor.cpp b/ecmascript/jspandafile/class_info_extractor.cpp index 5435fcd2a2..4b3e80c5dc 100644 --- a/ecmascript/jspandafile/class_info_extractor.cpp +++ b/ecmascript/jspandafile/class_info_extractor.cpp @@ -622,39 +622,34 @@ JSHandle ClassHelper::BuildDictionaryProperties(JSThread *thread return dict; } -bool ClassHelper::MatchTrackType(TrackType trackType, JSTaggedValue value) +bool ClassHelper::MatchFieldType(SharedFieldType fieldType, JSTaggedValue value) { bool checkRet = false; - switch (trackType) { - case TrackType::NUMBER: { + switch (fieldType) { + case SharedFieldType::NUMBER: { checkRet = value.IsNumber(); break; } - case TrackType::INT: { - checkRet = value.IsInt(); - break; - } - case TrackType::DOUBLE: { - checkRet = value.IsDouble(); - break; - } - case TrackType::BOOLEAN: { + case SharedFieldType::BOOLEAN: { checkRet = value.IsBoolean(); break; } - case TrackType::STRING: { + case SharedFieldType::STRING: { checkRet = value.IsString() || value.IsNull(); break; } - case TrackType::SENDABLE: { + case SharedFieldType::BIG_INT: { + checkRet = value.IsBigInt(); + break; + } + case SharedFieldType::SENDABLE: { checkRet = value.IsJSShared() || value.IsNull(); break; } - case TrackType::NONE: { + case SharedFieldType::NONE: { checkRet = true; break; } - case TrackType::TAGGED: default: break; } @@ -871,16 +866,16 @@ void SendableClassDefiner::AddFieldTypeToHClass(JSThread *thread, const JSHandle PropertyAttributes attributes = PropertyAttributes::Default(true, true, false); key.Update(fieldTypeArray->Get(i)); ASSERT(key->IsString()); - TrackType type = FromFieldType(FieldType(fieldTypeArray->Get(i + 1).GetInt())); + SharedFieldType type = FromFieldType(FieldType(fieldTypeArray->Get(i + 1).GetInt())); int entry = layout->FindElementWithCache(thread, *hclass, key.GetTaggedValue(), index); if (entry != -1) { attributes = layout->GetAttr(entry); - attributes.SetTrackType(type); + attributes.SetSharedFieldType(type); layout->SetNormalAttr(thread, entry, attributes); } else { attributes.SetIsInlinedProps(true); attributes.SetRepresentation(Representation::TAGGED); - attributes.SetTrackType(type); + attributes.SetSharedFieldType(type); attributes.SetOffset(index); layout->AddKey(thread, index++, key.GetTaggedValue(), attributes); } @@ -905,8 +900,8 @@ void SendableClassDefiner::AddFieldTypeToDict(JSThread *thread, const JSHandleGet(i)); ASSERT(key->IsString()); - TrackType type = FromFieldType(FieldType(fieldTypeArray->Get(i + 1).GetInt())); - attributes.SetTrackType(type); + SharedFieldType type = FromFieldType(FieldType(fieldTypeArray->Get(i + 1).GetInt())); + attributes.SetSharedFieldType(type); attributes.SetBoxType(PropertyBoxType::UNDEFINED); JSHandle newDict = NameDictionary::Put(thread, dict, key, value, attributes); dict.Update(newDict); diff --git a/ecmascript/jspandafile/class_info_extractor.h b/ecmascript/jspandafile/class_info_extractor.h index 3e7e2cb1e0..87a5c335a9 100644 --- a/ecmascript/jspandafile/class_info_extractor.h +++ b/ecmascript/jspandafile/class_info_extractor.h @@ -33,6 +33,7 @@ enum class FieldType { STRING = (1 << 1), BOOLEAN = (1 << 2), TS_TYPE_REF = (1 << 3), + BIG_INT = (1 << 4), }; class ClassInfoExtractor : public TaggedObject { public: @@ -114,7 +115,7 @@ public: const JSHandle &ihclass, const JSHandle &constructorHClass); - static bool PUBLIC_API MatchTrackType(TrackType trackType, JSTaggedValue value); + static bool PUBLIC_API MatchFieldType(SharedFieldType fieldType, JSTaggedValue value); private: static JSHandle BuildDictionaryProperties(JSThread *thread, const JSHandle &object, JSHandle &keys, @@ -141,20 +142,23 @@ public: const JSHandle &properties); private: - static TrackType FromFieldType(FieldType type) + static SharedFieldType FromFieldType(FieldType type) { switch (type) { case FieldType::NONE: - return TrackType::NONE; + return SharedFieldType::NONE; case FieldType::NUMBER: - return TrackType::NUMBER; + return SharedFieldType::NUMBER; case FieldType::STRING: - return TrackType::STRING; + return SharedFieldType::STRING; case FieldType::BOOLEAN: - return TrackType::BOOLEAN; + return SharedFieldType::BOOLEAN; case FieldType::TS_TYPE_REF: - return TrackType::SENDABLE; + return SharedFieldType::SENDABLE; + case FieldType::BIG_INT: + return SharedFieldType::BIG_INT; default: + LOG_ECMA(FATAL) << "Unsupport fieldType in shared object with type: " << static_cast(type); UNREACHABLE(); } } diff --git a/ecmascript/object_factory.cpp b/ecmascript/object_factory.cpp index 48ddd82c37..c8a29b953a 100644 --- a/ecmascript/object_factory.cpp +++ b/ecmascript/object_factory.cpp @@ -4835,7 +4835,7 @@ JSHandle ObjectFactory::CreateDictionaryJSObjectWithNamedProperti void ObjectFactory::FillFreeMemoryRange(uintptr_t start, uintptr_t end) { - ASSERT(start < end); + ASSERT(start <= end); ASSERT(start % static_cast(MemAlignment::MEM_ALIGN_OBJECT) == 0); ASSERT(end % static_cast(MemAlignment::MEM_ALIGN_OBJECT) == 0); while (start < end) { diff --git a/ecmascript/object_fast_operator-inl.h b/ecmascript/object_fast_operator-inl.h index bdf197e04d..bc4e8f7344 100644 --- a/ecmascript/object_fast_operator-inl.h +++ b/ecmascript/object_fast_operator-inl.h @@ -241,7 +241,7 @@ JSTaggedValue ObjectFastOperator::SetPropertyByName(JSThread *thread, JSTaggedVa break; } if (holder.IsJSShared() && (sCheckMode == SCheckMode::CHECK)) { - if (!ClassHelper::MatchTrackType(attr.GetTrackType(), value)) { + if (!ClassHelper::MatchFieldType(attr.GetSharedFieldType(), value)) { THROW_TYPE_ERROR_AND_RETURN((thread), GET_MESSAGE_STRING(SetTypeMismatchedSharedProperty), JSTaggedValue::Exception()); } @@ -271,7 +271,7 @@ JSTaggedValue ObjectFastOperator::SetPropertyByName(JSThread *thread, JSTaggedVa break; } if ((sCheckMode == SCheckMode::CHECK) && holder.IsJSShared()) { - if (!ClassHelper::MatchTrackType(attr.GetDictTrackType(), value)) { + if (!ClassHelper::MatchFieldType(attr.GetDictSharedFieldType(), value)) { THROW_TYPE_ERROR_AND_RETURN((thread), GET_MESSAGE_STRING(SetTypeMismatchedSharedProperty), JSTaggedValue::Exception()); } diff --git a/ecmascript/object_operator.cpp b/ecmascript/object_operator.cpp index 6686ffda05..8ad1dda724 100644 --- a/ecmascript/object_operator.cpp +++ b/ecmascript/object_operator.cpp @@ -398,11 +398,11 @@ bool ObjectOperator::IsDetectorName(JSHandle env, JSTaggedValue key) return (start <= addr) && (addr <= end); } -TrackType ObjectOperator::GetTrackType() const +SharedFieldType ObjectOperator::GetSharedFieldType() const { return JSObject::Cast(holder_->GetTaggedObject())->GetJSHClass()->IsDictionaryMode() - ? attributes_.GetDictTrackType() - : attributes_.GetTrackType(); + ? attributes_.GetDictSharedFieldType() + : attributes_.GetSharedFieldType(); } void ObjectOperator::ToPropertyDescriptor(PropertyDescriptor &desc) const @@ -416,7 +416,7 @@ void ObjectOperator::ToPropertyDescriptor(PropertyDescriptor &desc) const desc.SetWritable(IsWritable()); JSTaggedValue val = GetValue(); desc.SetValue(JSHandle(thread_, val)); - desc.SetTrackType(GetTrackType()); + desc.SetSharedFieldType(GetSharedFieldType()); } else { auto result = GetValue(); bool isPropertyBox = result.IsPropertyBox(); @@ -505,7 +505,7 @@ void ObjectOperator::LookupGlobal(const JSHandle &obj) return; } JSTaggedValue value(dict->GetBox(entry)); - uint32_t attr = dict->GetAttributes(entry).GetValue(); + auto attr = dict->GetAttributes(entry).GetValue(); SetFound(entry, value, attr, true); } @@ -534,7 +534,7 @@ void ObjectOperator::LookupPropertyInlinedProps(const JSHandle &obj) } JSTaggedValue value(dict->GetBox(entry)); - uint32_t attr = dict->GetAttributes(entry).GetValue(); + auto attr = dict->GetAttributes(entry).GetValue(); SetFound(entry, value, attr, true); return; } @@ -575,7 +575,7 @@ void ObjectOperator::LookupPropertyInlinedProps(const JSHandle &obj) } JSTaggedValue value = dict->GetValue(entry); - uint32_t attr = dict->GetAttributes(entry).GetValue(); + auto attr = dict->GetAttributes(entry).GetValue(); SetFound(entry, value, attr, false); } @@ -605,7 +605,7 @@ void ObjectOperator::TransitionForAttributeChanged(const JSHandle &rec JSHandle dict(JSObject::TransitionToDictionary(thread_, receiver)); index = static_cast(dict->FindEntry(key_.GetTaggedValue())); PropertyAttributes origin = dict->GetAttributes(index); - attr.SetDictTrackType(attr.GetTrackType()); + attr.SetDictSharedFieldType(attr.GetSharedFieldType()); attr.SetDictionaryOrder(origin.GetDictionaryOrder()); dict->SetAttributes(thread_, index, attr); } else { @@ -885,7 +885,7 @@ void ObjectOperator::DeleteElementInHolder() const } } -void ObjectOperator::SetFound(uint32_t index, JSTaggedValue value, uint32_t attr, bool mode, bool transition) +void ObjectOperator::SetFound(uint32_t index, JSTaggedValue value, uint64_t attr, bool mode, bool transition) { SetIndex(index); SetValue(value); @@ -894,7 +894,7 @@ void ObjectOperator::SetFound(uint32_t index, JSTaggedValue value, uint32_t attr SetAttr(attr); } -void ObjectOperator::UpdateFound(uint32_t index, uint32_t attr, bool mode, bool transition) +void ObjectOperator::UpdateFound(uint32_t index, uint64_t attr, bool mode, bool transition) { SetIndex(index); SetFastMode(mode); @@ -967,7 +967,7 @@ void ObjectOperator::LookupElementInlinedProps(const JSHandle &obj) return; } - uint32_t attr = dictionary->GetAttributes(entry).GetValue(); + auto attr = dictionary->GetAttributes(entry).GetValue(); SetFound(entry, dictionary->GetValue(entry), attr, false); } } diff --git a/ecmascript/object_operator.h b/ecmascript/object_operator.h index 0e6e0b9237..97a4fde5e5 100644 --- a/ecmascript/object_operator.h +++ b/ecmascript/object_operator.h @@ -159,14 +159,14 @@ public: return attributes_; } - inline void SetAttr(uint32_t attr) + inline void SetAttr(uint64_t attr) { attributes_ = PropertyAttributes(attr); } inline void SetAttr(const PropertyAttributes &attr) { - attributes_ = PropertyAttributes(attr); + attributes_ = attr; } inline bool IsPrimitiveAttr() const @@ -275,7 +275,7 @@ public: } void ToPropertyDescriptor(PropertyDescriptor &desc) const; - TrackType GetTrackType() const; + SharedFieldType GetSharedFieldType() const; void LookupProperty(); void GlobalLookupProperty(); inline void ReLookupPropertyInReceiver() @@ -324,8 +324,8 @@ private: void StartGlobalLookUp(OperatorType type); void HandleKey(const JSHandle &key); uint32_t ComputeElementCapacity(uint32_t oldCapacity); - void SetFound(uint32_t index, JSTaggedValue value, uint32_t attr, bool mode, bool transition = false); - void UpdateFound(uint32_t index, uint32_t attr, bool mode, bool transition); + void SetFound(uint32_t index, JSTaggedValue value, uint64_t attr, bool mode, bool transition = false); + void UpdateFound(uint32_t index, uint64_t attr, bool mode, bool transition); void ResetState(); void ResetStateForAddProperty(); inline void LookupPropertyInHolder() diff --git a/ecmascript/property_attributes.h b/ecmascript/property_attributes.h index aef86ddcc3..a57a38f362 100644 --- a/ecmascript/property_attributes.h +++ b/ecmascript/property_attributes.h @@ -35,10 +35,16 @@ enum class TrackType : uint8_t { INT = 0x1ULL, DOUBLE = 0x1ULL << 1, NUMBER = INT | DOUBLE, - TAGGED = 0x1ULL << 2, - BOOLEAN = 5, - STRING = 6, - SENDABLE = 7 + TAGGED = 0x1ULL << 2 +}; + +enum class SharedFieldType : uint8_t { + NONE = 0, + NUMBER = 1, + STRING = 2, + BOOLEAN = 3, + SENDABLE = 4, + BIG_INT = 5, }; enum class PropertyBoxType { @@ -64,13 +70,14 @@ enum class PropertyBoxType { * -------------------------------- * Fast | OffsetField(bit 8...17) * | TrackTypeField(bit 18...20) - * | SortedIndexField(bit 21...30) - * | IsConstPropsField(bit 31) - * | IsNotHoleField(bit 32) + * | SharedFieldTypeField(bit 21...23) + * | SortedIndexField(bit 24...33) + * | IsConstPropsField(bit 34) + * | IsNotHoleField(bit 35) * ----------------------------- * Slow | PropertyBoxTypeField(bit 8...9) * | DictionaryOrderField(bit 10...29) - * | TrackTypeField(bit 30...32) + * | SharedFieldTypeField(bit 30...32) */ class PropertyAttributes { public: @@ -80,21 +87,24 @@ public: DEFAULT_NOEXCEPT_MOVE_SEMANTIC(PropertyAttributes); DEFAULT_COPY_SEMANTIC(PropertyAttributes); - explicit PropertyAttributes(uint32_t v) : value_(v) {} - explicit PropertyAttributes(int32_t v) : value_(static_cast(v)) {} - explicit PropertyAttributes(JSTaggedValue v) : value_(v.GetInt()) {} + explicit PropertyAttributes(uint64_t v) : value_(v) {} + explicit PropertyAttributes(JSTaggedValue v) : value_(JSTaggedValue::UnwrapToUint64(v)) {} explicit PropertyAttributes(const PropertyDescriptor &desc); static constexpr uint32_t DICTIONARY_ORDER_NUM = 20; static constexpr uint32_t OFFSET_BITFIELD_NUM = 10; static constexpr uint32_t REPRESENTATION_NUM = 2; static constexpr uint32_t TRACK_TYPE_NUM = 3; + static constexpr uint32_t FIELD_TYPE_NUM = 3; static constexpr uint32_t MAX_FAST_PROPS_CAPACITY = (1U << OFFSET_BITFIELD_NUM) - 1; static constexpr unsigned BITS_PER_BYTE = 8; - using PropertyMetaDataField = BitField; // 4: property metaData field occupies 4 bits - using AttributesField = BitField; // 4: attributes field occupies 4 bits - using DefaultAttributesField = BitField; // 3: default attributes field occupies 3 bits + static constexpr uint32_t MAX_BIT_SIZE = 48; + static constexpr int INITIAL_PROPERTY_INDEX = 0; + + using PropertyMetaDataField = BitField; // 4: property metaData field occupies 4 bits + using AttributesField = BitField; // 4: attributes field occupies 4 bits + using DefaultAttributesField = BitField; // 3: default attributes field occupies 3 bits using WritableField = BitField; // 1: writable field occupies 1 bits using EnumerableField = WritableField::NextFlag; using ConfigurableField = EnumerableField::NextFlag; @@ -113,14 +123,16 @@ public: using OffsetField = FastModeStartField::NextField; // 17 using TrackTypeField = OffsetField::NextField; // 20: 3 bits - static constexpr uint32_t NORMAL_ATTR_BITS = 20; - using NormalAttrField = BitField; - using SortedIndexField = TrackTypeField::NextField; // 30 - using IsConstPropsField = SortedIndexField::NextFlag; // 31 - using IsNotHoleField = IsConstPropsField::NextFlag; // 32 + // normal attr should include SharedFieldTypeField when set to layout + static constexpr uint32_t NORMAL_ATTR_BITS = 23; + using NormalAttrField = BitField; + using SharedFieldTypeField = TrackTypeField::NextField; // 23: 3 bits + using SortedIndexField = SharedFieldTypeField::NextField; // 33: 10 bits + using IsConstPropsField = SortedIndexField::NextFlag; // 34 + using IsNotHoleField = IsConstPropsField::NextFlag; // 35 using FastModeLastField = IsNotHoleField; static_assert( - FastModeLastField::START_BIT + FastModeLastField::SIZE <= sizeof(uint32_t) * BITS_PER_BYTE, "Invalid"); + FastModeLastField::START_BIT + FastModeLastField::SIZE <= MAX_BIT_SIZE, "Invalid"); // --------------------------------------------------------------------------------------------- // only for dictionary mode, include global @@ -129,15 +141,13 @@ public: static_assert(DictModeStartField::SIZE == CommonLastBitField::SIZE); using PropertyBoxTypeField = DictModeStartField::NextField; // 2: 2 bits, 8-9 using DictionaryOrderField = PropertyBoxTypeField::NextField; // 29 - using DictTrackTypeField = DictionaryOrderField::NextField; - using DictModeLastField = DictTrackTypeField; + using DictSharedFieldTypeField = DictionaryOrderField::NextField; + using DictModeLastField = DictSharedFieldTypeField; + static_assert( - DictModeLastField::START_BIT + DictModeLastField::SIZE <= sizeof(uint32_t) * BITS_PER_BYTE, "Invalid"); + DictModeLastField::START_BIT + DictModeLastField::SIZE <= MAX_BIT_SIZE, "Invalid"); - static constexpr uint32_t BIT_SIZE = 28; - static constexpr int INITIAL_PROPERTY_INDEX = 0; - - inline int GetPropertyMetaData() const + inline int32_t GetPropertyMetaData() const { return PropertyMetaDataField::Get(value_); } @@ -149,24 +159,24 @@ public: static PropertyAttributes Default(bool w, bool e, bool c, bool isAccessor = false) { - uint32_t value = WritableField::Encode(w) | EnumerableField::Encode(e) | ConfigurableField::Encode(c) | + uint64_t value = WritableField::Encode(w) | EnumerableField::Encode(e) | ConfigurableField::Encode(c) | IsAccessorField::Encode(isAccessor); return PropertyAttributes(value); } static PropertyAttributes DefaultAccessor(bool w, bool e, bool c) { - uint32_t value = WritableField::Encode(w) | EnumerableField::Encode(e) | ConfigurableField::Encode(c) | + uint64_t value = WritableField::Encode(w) | EnumerableField::Encode(e) | ConfigurableField::Encode(c) | IsAccessorField::Encode(true); return PropertyAttributes(value); } inline void SetDefaultAttributes() { - AttributesField::Set(DefaultAttributesField::Mask(), &value_); + AttributesField::Set(DefaultAttributesField::Mask(), &value_); } - static inline int GetDefaultAttributes() + static inline int32_t GetDefaultAttributes() { return DefaultAttributesField::Mask(); } @@ -194,12 +204,12 @@ public: inline bool IsDefaultAttributes() const { - return AttributesField::Get(value_) == static_cast(DefaultAttributesField::Mask()); + return AttributesField::Get(value_) == static_cast(DefaultAttributesField::Mask()); } inline void SetNoneAttributes() { - AttributesField::Set(0U, &value_); + AttributesField::Set(0U, &value_); } inline bool IsNoneAttributes() const @@ -209,7 +219,7 @@ public: inline void SetWritable(bool flag) { - WritableField::Set(flag, &value_); + WritableField::Set(flag, &value_); } inline bool IsWritable() const { @@ -217,7 +227,7 @@ public: } inline void SetEnumerable(bool flag) { - EnumerableField::Set(flag, &value_); + EnumerableField::Set(flag, &value_); } inline bool IsEnumerable() const { @@ -225,7 +235,7 @@ public: } inline void SetConfigurable(bool flag) { - ConfigurableField::Set(flag, &value_); + ConfigurableField::Set(flag, &value_); } inline bool IsConfigurable() const { @@ -234,7 +244,7 @@ public: inline void SetIsAccessor(bool flag) { - IsAccessorField::Set(flag, &value_); + IsAccessorField::Set(flag, &value_); } inline bool IsAccessor() const @@ -244,7 +254,7 @@ public: inline void SetIsInlinedProps(bool flag) { - IsInlinedPropsField::Set(flag, &value_); + IsInlinedPropsField::Set(flag, &value_); } inline bool IsInlinedProps() const @@ -254,7 +264,7 @@ public: inline void SetIsConstProps(bool flag) { - IsConstPropsField::Set(flag, &value_); + IsConstPropsField::Set(flag, &value_); } inline bool IsConstProps() const @@ -264,7 +274,7 @@ public: inline void SetIsNotHole(bool flag) { - IsNotHoleField::Set(flag, &value_); + IsNotHoleField::Set(flag, &value_); } inline bool IsNotHole() const @@ -291,7 +301,7 @@ public: inline void SetRepresentation(Representation representation) { - RepresentationField::Set(representation, &value_); + RepresentationField::Set(representation, &value_); } inline Representation GetRepresentation() const @@ -306,22 +316,32 @@ public: inline void SetTrackType(TrackType type) { - TrackTypeField::Set(type, &value_); + TrackTypeField::Set(type, &value_); } - inline void SetDictTrackType(TrackType type) + inline SharedFieldType GetSharedFieldType() const { - DictTrackTypeField::Set(type, &value_); + return SharedFieldTypeField::Get(value_); } - inline TrackType GetDictTrackType() const + inline void SetSharedFieldType(SharedFieldType fieldType) { - return DictTrackTypeField::Get(value_); + SharedFieldTypeField::Set(fieldType, &value_); + } + + inline void SetDictSharedFieldType(SharedFieldType fieldType) + { + DictSharedFieldTypeField::Set(fieldType, &value_); + } + + inline SharedFieldType GetDictSharedFieldType() const + { + return DictSharedFieldTypeField::Get(value_); } inline void SetDictionaryOrder(uint32_t order) { - DictionaryOrderField::Set(order, &value_); + DictionaryOrderField::Set(order, &value_); } inline uint32_t GetDictionaryOrder() const { @@ -330,8 +350,9 @@ public: inline void SetOffset(uint32_t offset) { - OffsetField::Set(offset, &value_); + OffsetField::Set(offset, &value_); } + inline uint32_t GetOffset() const { return OffsetField::Get(value_); @@ -339,7 +360,7 @@ public: inline void SetSortedIndex(uint32_t sortedIndex) { - SortedIndexField::Set(sortedIndex, &value_); + SortedIndexField::Set(sortedIndex, &value_); } inline uint32_t GetSortedIndex() const { @@ -348,7 +369,7 @@ public: inline void SetNormalAttr(uint32_t normalAttr) { - NormalAttrField::Set(normalAttr, &value_); + NormalAttrField::Set(normalAttr, &value_); } inline uint32_t GetNormalAttr() const @@ -358,17 +379,17 @@ public: inline JSTaggedValue GetNormalTagged() const { - return JSTaggedValue(static_cast(GetNormalAttr())); + return JSTaggedValue::WrapUint64(GetNormalAttr()); } - inline uint32_t GetValue() const + inline uint64_t GetValue() const { return value_; } inline void SetBoxType(PropertyBoxType cellType) { - PropertyBoxTypeField::Set(cellType, &value_); + PropertyBoxTypeField::Set(cellType, &value_); } inline PropertyBoxType GetBoxType() const @@ -383,11 +404,11 @@ public: inline JSTaggedValue GetTaggedValue() const { - return JSTaggedValue(static_cast(value_)); + return JSTaggedValue::WrapUint64(value_); } private: - uint32_t value_{0}; + uint64_t value_{0}; }; } // namespace panda::ecmascript #endif // ECMASCRIPT_PROPERTY_ATTRIBUTES_H diff --git a/ecmascript/stubs/runtime_stubs.cpp b/ecmascript/stubs/runtime_stubs.cpp index 88278395df..6dc9e3bf34 100644 --- a/ecmascript/stubs/runtime_stubs.cpp +++ b/ecmascript/stubs/runtime_stubs.cpp @@ -112,9 +112,9 @@ DEF_RUNTIME_STUBS(AddElementInternal) JSHandle receiver = GetHArg(argv, argc, 0); // 0: means the zeroth parameter JSTaggedValue argIndex = GetArg(argv, argc, 1); // 1: means the first parameter JSHandle value = GetHArg(argv, argc, 2); // 2: means the second parameter - JSTaggedValue argAttr = GetArg(argv, argc, 3); // 3: means the third parameter - auto attr = static_cast(argAttr.GetInt()); - auto result = JSObject::AddElementInternal(thread, receiver, argIndex.GetInt(), value, attr); + JSTaggedValue attr = GetArg(argv, argc, 3); // 3: means the third parameter + PropertyAttributes attrValue(attr); + auto result = JSObject::AddElementInternal(thread, receiver, argIndex.GetInt(), value, attrValue); return JSTaggedValue(result).GetRawData(); } @@ -317,7 +317,7 @@ DEF_RUNTIME_STUBS(NameDictPutIfAbsent) JSTaggedValue attr = GetArg(argv, argc, 4); // 4: means the fourth parameter JSTaggedValue needTransToDict = GetArg(argv, argc, 5); // 5: means the fifth parameter - PropertyAttributes propAttr(attr.GetInt()); + PropertyAttributes propAttr(attr); if (needTransToDict.IsTrue()) { JSHandle objHandle(thread, JSTaggedValue(reinterpret_cast(receiver))); JSHandle dictHandle(JSObject::TransitionToDictionary(thread, objHandle)); @@ -341,7 +341,7 @@ DEF_RUNTIME_STUBS(NumberDictionaryPut) JSTaggedValue needTransToDict = GetArg(argv, argc, 5); // 5: means the fifth parameter JSHandle keyHandle(thread, key); - PropertyAttributes propAttr(attr.GetInt()); + PropertyAttributes propAttr(attr); JSHandle objHandle(thread, JSTaggedValue(reinterpret_cast(receiver))); if (needTransToDict.IsTrue()) { JSObject::ElementsToDictionary(thread, objHandle); @@ -481,7 +481,7 @@ DEF_RUNTIME_STUBS(UpdateLayOutAndAddTransition) JSHandle keyHandle = GetHArg(argv, argc, 2); // 2: means the second parameter JSTaggedValue attr = GetArg(argv, argc, 3); // 3: means the third parameter - PropertyAttributes attrValue(attr.GetInt()); + PropertyAttributes attrValue(attr); JSHClass::AddPropertyToNewHClass(thread, oldHClassHandle, newHClassHandle, keyHandle, attrValue); @@ -499,7 +499,7 @@ DEF_RUNTIME_STUBS(CopyAndUpdateObjLayout) JSTaggedValue attr = GetArg(argv, argc, 3); // 3: means the third parameter auto factory = thread->GetEcmaVM()->GetFactory(); - PropertyAttributes attrValue(attr.GetInt()); + PropertyAttributes attrValue(attr); // 1. Copy JSHandle oldLayout(thread, newHClassHandle->GetLayout()); diff --git a/ecmascript/tagged_dictionary.cpp b/ecmascript/tagged_dictionary.cpp index 413cef4e97..4022d60245 100644 --- a/ecmascript/tagged_dictionary.cpp +++ b/ecmascript/tagged_dictionary.cpp @@ -201,7 +201,7 @@ JSHandle NameDictionary::CreateInSharedHeap(const JSThread *thre PropertyAttributes NameDictionary::GetAttributes(int entry) const { int index = GetEntryIndex(entry) + ENTRY_DETAILS_INDEX; - return PropertyAttributes(Get(index).GetInt()); + return PropertyAttributes(Get(index)); } void NameDictionary::SetAttributes(const JSThread *thread, int entry, const PropertyAttributes &metaData) @@ -377,7 +377,7 @@ JSHandle NumberDictionary::Create(const JSThread *thread, int PropertyAttributes NumberDictionary::GetAttributes(int entry) const { int index = GetEntryIndex(entry) + ENTRY_DETAILS_INDEX; - return PropertyAttributes(Get(index).GetInt()); + return PropertyAttributes(Get(index)); } void NumberDictionary::SetAttributes(const JSThread *thread, int entry, const PropertyAttributes &metaData) diff --git a/ecmascript/tagged_hash_table.h b/ecmascript/tagged_hash_table.h index 85856ac34e..d35a427fa0 100644 --- a/ecmascript/tagged_hash_table.h +++ b/ecmascript/tagged_hash_table.h @@ -450,7 +450,7 @@ public: PropertyAttributes attr(metaData); attr.SetDictionaryOrder(enumIndex); attr.SetRepresentation(Representation::TAGGED); - attr.SetDictTrackType(metaData.GetTrackType()); + attr.SetDictSharedFieldType(metaData.GetSharedFieldType()); int entry = table->FindEntry(key.GetTaggedValue()); if (entry != -1) { table->SetEntry(thread, entry, key.GetTaggedValue(), value.GetTaggedValue(), attr); diff --git a/test/sharedtest/check/expect_output.txt b/test/sharedtest/check/expect_output.txt index 602fbbccc9..21ad1a895a 100644 --- a/test/sharedtest/check/expect_output.txt +++ b/test/sharedtest/check/expect_output.txt @@ -17,12 +17,16 @@ Start testUpdateInstancePropsToNull Success update propString to null with stobjbyname Success update subClassPropSendable to null with stobjbyname Fail to update propNumber to null with stobjbyname. err: TypeError: Cannot set sendable property with mismatched type -Fail to update propNumber to null with stobjbyname. err: TypeError: Cannot set sendable property with mismatched type +Fail to update propBool to null with stobjbyname. err: TypeError: Cannot set sendable property with mismatched type +Fail to update propBigInt1 to null with stobjbyname. err: TypeError: Cannot set sendable property with mismatched type +Fail to update propBigInt2 to null with stobjbyname. err: TypeError: Cannot set sendable property with mismatched type Start testUpdateInstancePropsToUndefined Fail to update propString to undefined with stobjbyname. err: TypeError: Cannot set sendable property with mismatched type Fail to update subClassPropSendable to undefined with stobjbyname. err: TypeError: Cannot set sendable property with mismatched type Fail to update propNumber to undefined with stobjbyname. err: TypeError: Cannot set sendable property with mismatched type -Fail to update propNumber to undefined with stobjbyname. err: TypeError: Cannot set sendable property with mismatched type +Fail to update propBool to undefined with stobjbyname. err: TypeError: Cannot set sendable property with mismatched type +Fail to update propBigInt1 to undefined with stobjbyname. err: TypeError: Cannot set sendable property with mismatched type +Fail to update propBigInt2 to undefined with stobjbyname. err: TypeError: Cannot set sendable property with mismatched type Success update subClassPropString with defineProperties Success update propNumber with defineProperty Fail to update subClassPropString with stobjbyname. err: TypeError: Cannot set sendable property with mismatched type @@ -68,6 +72,8 @@ isExtensible: false Success to call Object.preventExtensions in preventExtensions state. Start testUpdateWithType Fail to update string to int with stobjbynamme. err: TypeError: Cannot set sendable property with mismatched type +Fail to update bigInt to int with stobjbynamme. err: TypeError: Cannot set sendable property with mismatched type +Success update bigInt to bigInt with stobjbynamme. Fail to update subClassPropSendable to number with defineProperty. err: TypeError: Cannot set sendable property with mismatched type I'm constructor for SimpleNumberSendable Success update subClassPropSendable to numberSendable with defineProperty. diff --git a/test/sharedtest/check/sharedcheck.ts b/test/sharedtest/check/sharedcheck.ts index 8b08a8420d..193a5e405d 100644 --- a/test/sharedtest/check/sharedcheck.ts +++ b/test/sharedtest/check/sharedcheck.ts @@ -66,6 +66,8 @@ class SuperClass { propString: string = "I'm propString" propNumber: number = 5 propBool: boolean = false + propBigInt1: bigint = BigInt(12345678910) + propBigInt2: BigInt = BigInt(987654321) static staticPropString: string = "I'm staticPropString"; publicPropString: string = "I'm privatePropString"; @@ -223,9 +225,23 @@ function testUpdateInstancePropsToNull(testObj: SubClass) { try { testObj.propBool = null - print("Success update propNumber to null with stobjbyname") + print("Success update propBool to null with stobjbyname") } catch (error) { - print("Fail to update propNumber to null with stobjbyname. err: " + error) + print("Fail to update propBool to null with stobjbyname. err: " + error) + } + + try { + testObj.propBigInt1 = null + print("Success update propBigInt1 to null with stobjbyname") + } catch (error) { + print("Fail to update propBigInt1 to null with stobjbyname. err: " + error) + } + + try { + testObj.propBigInt2 = null + print("Success update propBigInt2 to null with stobjbyname") + } catch (error) { + print("Fail to update propBigInt2 to null with stobjbyname. err: " + error) } } @@ -254,9 +270,23 @@ function testUpdateInstancePropsToUndefined(testObj: SubClass) { try { testObj.propBool = undefined - print("Success update propNumber to undefined with stobjbyname") + print("Success update propBool to undefined with stobjbyname") } catch (error) { - print("Fail to update propNumber to undefined with stobjbyname. err: " + error) + print("Fail to update propBool to undefined with stobjbyname. err: " + error) + } + + try { + testObj.propBigInt1 = undefined + print("Success update propBigInt1 to undefined with stobjbyname") + } catch (error) { + print("Fail to update propBigInt1 to undefined with stobjbyname. err: " + error) + } + + try { + testObj.propBigInt2 = undefined + print("Success update propBigInt2 to undefined with stobjbyname") + } catch (error) { + print("Fail to update propBigInt2 to undefined with stobjbyname. err: " + error) } } @@ -444,6 +474,20 @@ function testUpdateWithType(testObj: SubClass) { print("Fail to update string to int with stobjbynamme. err: " + error); } + try { + testObj.propBigInt1 = 1; + print("Success update bigInt to int with stobjbynamme.") + } catch (error) { + print("Fail to update bigInt to int with stobjbynamme. err: " + error); + } + + try { + testObj.propBigInt2 = BigInt(123456789); + print("Success update bigInt to bigInt with stobjbynamme.") + } catch (error) { + print("Fail to update bigInt to int with stobjbynamme. err: " + error); + } + try { Object.defineProperty(testObj, "subClassPropSendable", { value: 123, writable: true }); print("Success update subClassPropSendable to number with defineProperty.")