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 16// load load 17function test1() { 18 let obj = ArkTools.createNapiObject(); 19 print(obj.x); // load: slow 20 print(obj.y); // load: slow 21} 22test1(); 23print(ArkTools.isAOTCompiled(test1)) 24print(ArkTools.isAOTDeoptimized(test1)) 25 26// load store load store load load 27function test2() { 28 let obj = ArkTools.createNapiObject(); 29 print(obj.x); // load: slow 30 obj.x = 1; // store: fast 31 print(obj.x); // load: fast 32 obj.y = 2; // store: fast 33 print(obj.y); // load: fast 34 print(obj.z); // load: slow 35} 36test2(); 37print(ArkTools.isAOTCompiled(test2)) 38print(ArkTools.isAOTDeoptimized(test2)) 39 40// store store load load load 41function test3() { 42 let obj = ArkTools.createNapiObject(); 43 obj.x = 1; // store: fast 44 obj.y = 1; // store: fast 45 print(obj.x); // load: fast 46 print(obj.y); // load: fast 47 print(obj.z); // load: slow 48} 49test3(); 50print(ArkTools.isAOTCompiled(test3)) 51print(ArkTools.isAOTDeoptimized(test3)) 52 53// test __proto__ 54function test4() { 55 let objproto = ArkTools.createNapiObject(); 56 let obj = ArkTools.createNapiObject(); 57 obj.__proto__ = objproto; // store: slow 58 objproto.x = 1; // store: slow 59 objproto.y = 1; // store: slow 60} 61test4(); 62print(ArkTools.isAOTCompiled(test4)) 63print(ArkTools.isAOTDeoptimized(test4)) 64 65ArkTools.printTypedOpProfiler("MONO_STORE_PROPERTY"); 66ArkTools.printTypedOpProfiler("LOAD_PROPERTY"); 67ArkTools.clearTypedOpProfiler(); 68 69// test for 70function test5() { 71 let obj = ArkTools.createNapiObject(); 72 obj.x = 1; // store: fast 73 for (let i = 0; i < 100; i++) { 74 obj.x; // load: fast 75 } 76 ArkTools.printTypedOpProfiler("LOAD_PROPERTY"); 77 ArkTools.clearTypedOpProfiler(); 78} 79test5(); 80print(ArkTools.isAOTCompiled(test5)) 81print(ArkTools.isAOTDeoptimized(test5)) 82 83// test normal js object 84function test6() { 85 let obj = ArkTools.createNapiObject(); 86 let obj2 = {}; 87 obj.x = 1; // store: fast 88 obj2.x = 1; // store: slow 89 print(obj.x); // load: fast 90 print(obj.y); // load: slow 91 print(obj2.x); // load: slow 92 print(obj2.y); // load: slow 93 ArkTools.printTypedOpProfiler("MONO_STORE_PROPERTY"); 94 ArkTools.printTypedOpProfiler("LOAD_PROPERTY"); 95 ArkTools.clearTypedOpProfiler(); 96} 97test6(); 98print(ArkTools.isAOTCompiled(test6)) 99print(ArkTools.isAOTDeoptimized(test6)) 100