• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    print(cnt);
33    if (cnt == 2) {
34        // Change the property 'x' at the the prototype chain,
35        // triggering lazy deoptimization of the JIT-compiled 'f' function.
36        A.prototype.x = 2;
37    }
38}
39class B extends A{
40    constructor() {
41        super();
42        g();
43    }
44}
45
46function f() {
47    try {
48        let a = Reflect.construct(B, []);
49        print(a.name);
50    } catch (e) {
51        print("Exception:", e);
52    }
53    print(a2.x);
54}
55
56f();
57ArkTools.jitCompileAsync(f);
58print(ArkTools.waitJitCompileFinish(f));
59
60print("------------------------------------------------------");
61f();