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 g() 41 } 42} 43 44function f() { 45 try { 46 let a = new B(); 47 } catch (e) { 48 print("Exception:", e); 49 } 50 print(a2.x); 51} 52 53f(); 54ArkTools.jitCompileAsync(f); 55print(ArkTools.waitJitCompileFinish(f)); 56 57print("------------------------------------------------------"); 58f();