mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-11-23 10:09:54 +00:00
Use generic array for toReversed if elementskind is disabled
Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IB0R0G Signed-off-by: ZhouGuangyuan <zhouguangyuan1@huawei.com> Change-Id: Ib0bab54f299644db1d76193cd7c1ca3d7e53518c
This commit is contained in:
parent
29ed61f07d
commit
ddd61b2917
@ -1928,26 +1928,42 @@ void BuiltinsArrayStubBuilder::ToReversed(GateRef glue, GateRef thisValue, [[may
|
||||
Bind(&isStability);
|
||||
BRANCH(IsJsCOWArray(thisValue), slowPath, ¬COWArray);
|
||||
Bind(¬COWArray);
|
||||
Label newArrayIsTagged(env);
|
||||
Label notChange(env);
|
||||
Label ElementsKindEnabled(env);
|
||||
Label ElementsKindDisabled(env);
|
||||
Label next(env);
|
||||
GateRef isElementsKindEnabled = IsEnableElementsKind(glue);
|
||||
DEFVARIABLE(newHClass, VariableType::JS_ANY(), LoadHClass(thisValue));
|
||||
DEFVARIABLE(receiver, VariableType::JS_ANY(), Hole());
|
||||
GateRef kind = GetElementsKindFromHClass(LoadHClass(thisValue));
|
||||
BRANCH_NO_WEIGHT(LogicAndBuilder(env).And(isElementsKindEnabled).And(ElementsKindHasHole(kind)).Done(),
|
||||
&newArrayIsTagged, ¬Change);
|
||||
Bind(&newArrayIsTagged);
|
||||
{
|
||||
// If the kind has hole, we know it must be transited to TAGGED kind;
|
||||
// There will be no hole in the new array because hole will be converted to undefined.
|
||||
newHClass = GetGlobalConstantValue(VariableType::JS_ANY(), glue, ConstantIndex::ELEMENT_TAGGED_HCLASS_INDEX);
|
||||
Jump(¬Change);
|
||||
}
|
||||
|
||||
Bind(¬Change);
|
||||
GateRef thisArrLen = GetArrayLength(thisValue);
|
||||
GateRef receiver = NewEmptyArrayWithHClass(glue, *newHClass);
|
||||
GrowElementsCapacity(glue, receiver, thisArrLen);
|
||||
SetArrayLength(glue, receiver, thisArrLen);
|
||||
BRANCH_UNLIKELY(isElementsKindEnabled, &ElementsKindEnabled, &ElementsKindDisabled);
|
||||
Bind(&ElementsKindEnabled);
|
||||
{
|
||||
Label newArrayIsTagged(env);
|
||||
Label reuseOldHClass(env);
|
||||
BRANCH_NO_WEIGHT(ElementsKindHasHole(kind), &newArrayIsTagged, &reuseOldHClass);
|
||||
Bind(&newArrayIsTagged);
|
||||
{
|
||||
// If the kind has hole, we know it must be transited to TAGGED kind;
|
||||
// There will be no hole in the new array because hole will be converted to undefined.
|
||||
GateRef newHClass = GetGlobalConstantValue(VariableType::JS_ANY(), glue,
|
||||
ConstantIndex::ELEMENT_TAGGED_HCLASS_INDEX);
|
||||
receiver = NewEmptyArrayWithHClass(glue, newHClass);
|
||||
Jump(&next);
|
||||
}
|
||||
Bind(&reuseOldHClass);
|
||||
{
|
||||
receiver = NewEmptyArrayWithHClass(glue, LoadHClass(thisValue));
|
||||
Jump(&next);
|
||||
}
|
||||
}
|
||||
Bind(&ElementsKindDisabled);
|
||||
{
|
||||
receiver = NewArray(glue, Int64(0));
|
||||
Jump(&next);
|
||||
}
|
||||
Bind(&next);
|
||||
GrowElementsCapacity(glue, *receiver, thisArrLen);
|
||||
SetArrayLength(glue, *receiver, thisArrLen);
|
||||
|
||||
Label afterReverse(env);
|
||||
Label isIntOrNumber(env);
|
||||
@ -1976,25 +1992,25 @@ void BuiltinsArrayStubBuilder::ToReversed(GateRef glue, GateRef thisValue, [[may
|
||||
{
|
||||
// The old array and new array are both TaggedArray, so load and store the element directly.
|
||||
// And barrier is needed.
|
||||
DoReverse(glue, thisValue, receiver, true, false, MemoryAttribute::Default());
|
||||
DoReverse(glue, thisValue, *receiver, true, false, MemoryAttribute::Default());
|
||||
Jump(&afterReverse);
|
||||
}
|
||||
Bind(&isIntOrNumber);
|
||||
{
|
||||
// The old array and new array are both MutantTaggedArray, so load and store the element directly.
|
||||
// And barrier is not needed.
|
||||
DoReverse(glue, thisValue, receiver, false, false, MemoryAttribute::NoBarrier());
|
||||
DoReverse(glue, thisValue, *receiver, false, false, MemoryAttribute::NoBarrier());
|
||||
Jump(&afterReverse);
|
||||
}
|
||||
Bind(&isHoleOrIntOrNumber);
|
||||
{
|
||||
// The old array is mutant, but new array is TaggedArray, so load the value from old array with
|
||||
// elements kind. And set it to new array directly, And barrier is not needed.
|
||||
DoReverse(glue, thisValue, receiver, true, true, MemoryAttribute::NoBarrier());
|
||||
DoReverse(glue, thisValue, *receiver, true, true, MemoryAttribute::NoBarrier());
|
||||
Jump(&afterReverse);
|
||||
}
|
||||
Bind(&afterReverse);
|
||||
result->WriteVariable(receiver);
|
||||
result->WriteVariable(*receiver);
|
||||
Jump(exit);
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ interface ArkTools{
|
||||
}
|
||||
class EventBusClass {
|
||||
public result: Object[] = [];
|
||||
|
||||
public holeIntArray: Object[] = [0, 1, 2, , 4, 5, 6];
|
||||
public addEventListener(): void {
|
||||
this.result.push({});
|
||||
}
|
||||
@ -42,4 +42,17 @@ function main(): void {
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
main();
|
||||
|
||||
function testToReversed() {
|
||||
let c = new EventBusClass();
|
||||
let b = c.holeIntArray.toReversed();
|
||||
// when pgo profiler is enabled, but elementsKind are not enabled, the array created in builtins are generic.
|
||||
if (b.length == 7 && ArkTools.getElementsKind(b) == 31) {
|
||||
print("testToReversed - success");
|
||||
} else {
|
||||
print("testToReversed - failed, expected: " + 31 + " , but get: " + ArkTools.getElementsKind(b));
|
||||
}
|
||||
}
|
||||
|
||||
testToReversed()
|
@ -61,3 +61,4 @@
|
||||
16
|
||||
16
|
||||
16
|
||||
testToReversed - success
|
@ -61,3 +61,4 @@
|
||||
16
|
||||
16
|
||||
16
|
||||
testToReversed - success
|
Loading…
Reference in New Issue
Block a user