1/*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16function addprop(o, p) {
17    o[p] = 0;
18    return o;
19}
20
21function propdict(o, sz) {
22    for (let i = 0; i < sz; ++i) {
23        addprop(o, "prop" + i)
24    }
25    return o
26}
27
28function warmup(fn, num) {
29    for (let i = 0; i < num; ++i) {
30        print(fn.name + " warmup: " + i);
31        fn();
32    }
33}
34
35warmup((function testICTransition() {
36    let x = {};
37    x.a = 0;
38    let y = {};
39    print(!ArkTools.haveSameMap(x, y));
40    y.a = 0;
41    print(ArkTools.haveSameMap(x, y));
42}), 3);
43
44warmup((function testObjLiterals() {
45    print(!ArkTools.haveSameMap({ a: 0, b: 0 }, { b: 0, a: 0 }))
46    print(ArkTools.haveSameMap({ a: 0, b: 0 }, { a: 0, b: 0 }))
47}), 0); // NOTE: broken with force-gc
48
49warmup((function testICByValueTransition() {
50    let x = addprop({}, "a");
51    let y = {}
52    print(!ArkTools.haveSameMap(x, y))
53    y.a = 0
54    print(ArkTools.haveSameMap(x, y))
55}), 3);
56
57warmup((function testDictTransition() {
58    const dictSzHeuristic = 1024;
59    print(ArkTools.haveSameMap(
60        propdict({}, dictSzHeuristic / 2),
61        propdict({}, dictSzHeuristic / 2)));
62    print(!ArkTools.haveSameMap(
63        propdict({}, dictSzHeuristic * 2),
64        propdict({}, dictSzHeuristic * 2)));
65}), 0); // NOTE: broken with force-gc
66