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 constructor. 23 */ 24 25class A {} 26let a2 = new A(); 27A.prototype.__proto__.x = 1; 28let cnt = 0; 29function g() 30{ 31 cnt++; 32 if (cnt == 2) { 33 // Change the property 'x' at the the prototype chain, 34 // triggering lazy deoptimization of the JIT-compiled 'f' function. 35 A.prototype.x = 2; 36 } 37} 38class B extends A{ 39 constructor() { 40 super(); 41 g(); 42 this.name = 233; 43 return 233; 44 } 45} 46 47function f() { 48 try { 49 let a = new B(); 50 print(a.name); 51 } catch (e) { 52 print("Exception:", e); 53 } 54 print(a2.x); 55} 56 57f(); 58ArkTools.jitCompileAsync(f); 59print(ArkTools.waitJitCompileFinish(f)); 60 61print("------------------------------------------------------"); 62f();