1/* 2 * Copyright (c) 2023 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 16declare function print(arg:any):string; 17declare var ArkTools:any; 18 19function Test1() { 20 function A() { 21 this.x = "1"; // store: this.x --> type: MONO_STORE_PROPERTY 22 } 23 24 // store: A.prototype.foo --> type: MONO_STORE_PROPERTY 25 A.prototype.foo = function() { 26 print("foo"); 27 } 28 29 // store: A.prototype.bar --> type: MONO_STORE_PROPERTY 30 A.prototype.bar = function() { 31 print("bar"); 32 } 33 34 let a = new A(); 35 // load: a.x --> type: LOAD_PROPERTY 36 print(a.x); 37 // store: a.x --> type: STORE_PROPERTY 38 a.x = "2"; 39 // load: a.x --> type: LOAD_PROPERTY 40 print(a.x); 41 // load: a.foo --> type: MONO_LOAD_PROPERTY_ON_PROTO 42 a.foo(); 43 // load: a.bar --> type: MONO_LOAD_PROPERTY_ON_PROTO 44 a.bar(); 45} 46Test1(); 47ArkTools.printTypedOpProfiler("MONO_STORE_PROPERTY"); 48ArkTools.printTypedOpProfiler("LOAD_PROPERTY"); 49ArkTools.printTypedOpProfiler("STORE_PROPERTY"); 50ArkTools.printTypedOpProfiler("MONO_LOAD_PROPERTY_ON_PROTO"); 51ArkTools.clearTypedOpProfiler(); 52print(ArkTools.isAOTDeoptimized(Test1)); 53 54function Test2() { 55 function B() { // asm 56 this.x = 1; 57 } 58 59 function foo(b) { 60 print(b.bar); // --> slow path 61 } 62 63 let b = new B(); 64 foo(b); 65 66 // store: B.prototype.bar --> type: MONO_STORE_PROPERTY 67 B.prototype.bar = "bar"; 68 69 foo(b); 70} 71Test2(); 72ArkTools.printTypedOpProfiler("MONO_STORE_PROPERTY"); 73ArkTools.clearTypedOpProfiler(); 74print(ArkTools.isAOTDeoptimized(Test2)); 75 76//make sure ihc in one thread can only be used once 77function Test3() { 78 for(let i = 0; i<2; ++i) { 79 function A() { 80 this.x = 1; 81 } 82 let a = new A(); 83 print(a.x); // type: LOAD_PROPERTY, second time will cause deopt 84 } 85} 86Test3(); 87ArkTools.printTypedOpProfiler("LOAD_PROPERTY"); 88ArkTools.clearTypedOpProfiler(); 89print(ArkTools.isAOTDeoptimized(Test3)); 90