1/* 2 * Copyright (c) 2025 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/* 17 * Description: 18 * 1. This code tests the lazy deoptimization that occurs in ldobjbyname. 19 * After the JIT code for function 'f' is compiled, 20 * modifying an HClass invalidates the function, 21 * and subsequent accesses to it will detect this invalidation. 22 * 2. Lazy deopt occurs on super call (fastpath). 23 */ 24 25let cnt = 0; 26class A { 27 constructor() { 28 g(); 29 this.name = 233; 30 // Additional code to prevent aggressive inlining. 31 let test = {}; 32 test.x; test.x; test.x; test.x; test.x; test.x; test.x; test.x; test.x; test.x; 33 test.x; test.x; test.x; test.x; test.x; test.x; test.x; test.x; test.x; test.x; 34 test.x; test.x; test.x; test.x; test.x; test.x; test.x; test.x; test.x; test.x; 35 test.x; test.x; test.x; test.x; test.x; test.x; test.x; test.x; test.x; test.x; 36 } 37} 38let a2 = new A(); 39A.prototype.__proto__.x = 1; 40function g() 41{ 42 cnt++; 43 if (cnt == 3) { 44 // Change the property 'x' at the the prototype chain, 45 // triggering lazy deoptimization of the JIT-compiled 'f' function. 46 A.prototype.x = 2; 47 } 48} 49 50class B extends A{ 51 constructor() { 52 super(); 53 print(this.name); 54 print(a2.x); 55 } 56} 57 58function f() { 59 try { 60 let a = new B(); 61 print(a.name); 62 } catch (e) { 63 print("Exception:", e); 64 } 65} 66 67f(); 68ArkTools.jitCompileAsync(f); 69print(ArkTools.waitJitCompileFinish(f)); 70ArkTools.jitCompileAsync(B); 71print(ArkTools.waitJitCompileFinish(B)); 72 73print("------------------------------------------------------"); 74f();