• 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 'Test2' is compiled,
20 *    modifying an HClass invalidates the function,
21 *    and subsequent accesses to it will detect this invalidation.
22 * 2. Speciall Test3 throw a exception before lazy deoptimization.
23 *    It verifies that exceptions are handled correctly when lazy deoptimization is bypassed.
24 *    Note: In this situation, lazy deoptimization will not be triggered.
25 */
26
27function Test3(shouldChange)
28{
29    if (shouldChange) {
30        ArkTools.forceLazyDeopt(C.prototype, 1, true);
31    }
32
33    // Additional code to prevent aggressive inlining.
34    let test = {};
35    test.x; test.x; test.x; test.x; test.x; test.x; test.x; test.x; test.x; test.x;
36    test.x; test.x; test.x; test.x; test.x; test.x; test.x; test.x; test.x; test.x;
37    test.x; test.x; test.x; test.x; test.x; test.x; test.x; test.x; test.x; test.x;
38    test.x; test.x; test.x; test.x; test.x; test.x; test.x; test.x; test.x; test.x;
39}
40
41function Test2(obj, shouldChange) {
42    obj.x;
43    Test3(shouldChange);
44}
45
46class A {}
47class B extends A {}
48class C extends B {}
49
50// Set the initial value of property x through A.prototype.
51A.prototype.x = 1;
52
53const c = new C();
54
55// Initial call to test without changing the prototype's property.
56Test2(c, false);
57
58ArkTools.jitCompileAsync(Test2);
59print(ArkTools.waitJitCompileFinish(Test2));
60
61print("------------------------------------------------------");
62try {
63    Test2(c, true);
64} catch (e) {
65    print(e);
66}