From e9ec5e2bd88175db1d16930850668e3f32f2d317 Mon Sep 17 00:00:00 2001 From: sunzibo Date: Wed, 3 Sep 2025 14:58:52 +0800 Subject: [PATCH] fix poly merge Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICW5W1 Change-Id: I256883d0f3b619d9ae1f68a03c1b5d2f152235fc Signed-off-by: sunzibo --- ecmascript/compiler/type_info_accessors.h | 12 ++++++-- test/jittest/BUILD.gn | 1 + test/jittest/poly_merge/BUILD.gn | 18 ++++++++++++ test/jittest/poly_merge/expect_output.txt | 16 ++++++++++ test/jittest/poly_merge/poly_merge.ts | 36 +++++++++++++++++++++++ 5 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 test/jittest/poly_merge/BUILD.gn create mode 100644 test/jittest/poly_merge/expect_output.txt create mode 100644 test/jittest/poly_merge/poly_merge.ts diff --git a/ecmascript/compiler/type_info_accessors.h b/ecmascript/compiler/type_info_accessors.h index 129ec111cc..cdadaa822d 100644 --- a/ecmascript/compiler/type_info_accessors.h +++ b/ecmascript/compiler/type_info_accessors.h @@ -1130,8 +1130,8 @@ protected: bool GeneratePlrInJIT(JSHClass* hclass, ObjectAccessInfo &info, JSTaggedValue key) const; bool hasIllegalType_; - ChunkVector accessInfos_; - ChunkVector checkerInfos_; + ChunkVector accessInfos_; // holder + ChunkVector checkerInfos_; // receiver }; class LoadPrivatePropertyTypeInfoAccessor final : public ObjAccByNameTypeInfoAccessor { @@ -1541,13 +1541,21 @@ public: rightCheckerInfo.GetPrimitiveType() != PrimitiveType::PRIMITIVE_TYPE_INVALID) { return false; } + // left receiver equal holder if (leftCheckerInfo.HClassIndex() == leftAccessInfo.HClassIndex()) { + // right receiver equal holder if (rightAccessInfo.HClassIndex() == rightCheckerInfo.HClassIndex() && rightAccessInfo.GetData() == leftAccessInfo.GetData()) { return true; } return false; } else { + // when left receiver not equal holder, bug right receiver equal holder, + // these two cannot be merged + if (rightAccessInfo.HClassIndex() == rightCheckerInfo.HClassIndex()) { + return false; + } + // left and right has same holder if (leftAccessInfo.HClassIndex() == rightAccessInfo.HClassIndex() && rightAccessInfo.GetData() == leftAccessInfo.GetData()) { return true; diff --git a/test/jittest/BUILD.gn b/test/jittest/BUILD.gn index 7622ee2c6f..7ee895cd2d 100644 --- a/test/jittest/BUILD.gn +++ b/test/jittest/BUILD.gn @@ -103,6 +103,7 @@ group("ark_jit_ts_test") { "hole_in_array", "definefunc", "jnez", + "poly_merge", "constructor", "intrinsic_test", "intrinsic_test2", diff --git a/test/jittest/poly_merge/BUILD.gn b/test/jittest/poly_merge/BUILD.gn new file mode 100644 index 0000000000..3b40c9f287 --- /dev/null +++ b/test/jittest/poly_merge/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//arkcompiler/ets_runtime/test/test_helper.gni") + +host_jit_test_action("poly_merge") { + deps = [] +} diff --git a/test/jittest/poly_merge/expect_output.txt b/test/jittest/poly_merge/expect_output.txt new file mode 100644 index 0000000000..b16a333ffe --- /dev/null +++ b/test/jittest/poly_merge/expect_output.txt @@ -0,0 +1,16 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +true +10 +10 diff --git a/test/jittest/poly_merge/poly_merge.ts b/test/jittest/poly_merge/poly_merge.ts new file mode 100644 index 0000000000..fb9c675ae6 --- /dev/null +++ b/test/jittest/poly_merge/poly_merge.ts @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function A() {} +let a = new A(); +a.x = 10; + +let b = {}; +b.__proto__ = a; + +function read(obj) { + return obj.x; +} + +for (var i = 0; i < 10; i++) { + read(a); + read(b); +} + +ArkTools.jitCompileAsync(read); +var ret = ArkTools.waitJitCompileFinish(read); +print(ret); +print(read(a)); +print(read(b)); -- Gitee