xref: /aosp_15_r20/art/test/2234-checker-remove-entry-suspendcheck/src/Main.java (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 public class Main {
18   public static class Inner {
19     String str;
20     int[] arr = {1, 2, 3};
21 
22     // Test 1: This test checks whether the SuspendCheck is removed from a simple field get.
23 
24     /// CHECK-START: java.lang.String Main$Inner.$noinline$removeSuspendCheckFieldGet() register (before)
25     /// CHECK: SuspendCheck
26     /// CHECK: InstanceFieldGet
27     /// CHECK-START: java.lang.String Main$Inner.$noinline$removeSuspendCheckFieldGet() register (after)
28     /// CHECK-NOT: SuspendCheck
29     /// CHECK: InstanceFieldGet
$noinline$removeSuspendCheckFieldGet()30     public String $noinline$removeSuspendCheckFieldGet() {
31       return this.str;
32     }
33 
34     // Test 2: This test checks whether the SuspendCheck is removed from a simple array get.
35 
36     /// CHECK-START: int Main$Inner.$noinline$removeSuspendCheckArrayGet() register (before)
37     /// CHECK: SuspendCheck
38     /// CHECK: ArrayGet
39     /// CHECK-START: int Main$Inner.$noinline$removeSuspendCheckArrayGet() register (after)
40     /// CHECK-NOT: SuspendCheck
41     /// CHECK: ArrayGet
$noinline$removeSuspendCheckArrayGet()42     public int $noinline$removeSuspendCheckArrayGet() {
43       return this.arr[0];
44     }
45 
46     // Test 3: This test checks whether the SuspendCheck is removed from a simple array set.
47 
48     /// CHECK-START: int Main$Inner.$noinline$removeSuspendCheckArraySet() register (before)
49     /// CHECK: SuspendCheck
50     /// CHECK: ArraySet
51     /// CHECK-START: int Main$Inner.$noinline$removeSuspendCheckArraySet() register (after)
52     /// CHECK-NOT: SuspendCheck
53     /// CHECK: ArraySet
$noinline$removeSuspendCheckArraySet()54     public int $noinline$removeSuspendCheckArraySet() {
55       return this.arr[0] = 2;
56     }
57   }
58 
main(String[] args)59   public static void main(String[] args) throws Exception {
60     Inner i = new Inner();
61     i.$noinline$removeSuspendCheckFieldGet();
62     i.$noinline$removeSuspendCheckArrayGet();
63     i.$noinline$removeSuspendCheckArraySet();
64   }
65 }