1 /*
2  * Copyright (C) 2022 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 {
main(String[] args)18     public static void main(String[] args) throws Exception {
19         assertNotNull($noinline$testReturnTryBoundaryExitInLoop(new Object()));
20     }
21 
assertNotNull(Object o)22     public static void assertNotNull(Object o) {
23         if (o == null) {
24             throw new Error("Expected not null!");
25         }
26     }
27 
28     // Simple method to have a call inside of the synchronized block.
$noinline$call()29     private static Object $noinline$call() {
30         return new Object();
31     }
32 
33     // Consistency check: Three try boundary kind:exit. One for the explicit try catch, and two for
34     // the synchronized block (normal, and exceptional path).
35 
36     /// CHECK-START: java.lang.Object Main.$inline$inner(java.lang.Object) builder (after)
37     /// CHECK:     TryBoundary kind:exit
38     /// CHECK:     TryBoundary kind:exit
39     /// CHECK:     TryBoundary kind:exit
40     /// CHECK-NOT: TryBoundary kind:exit
41 
42     /// CHECK-START: java.lang.Object Main.$inline$inner(java.lang.Object) builder (after)
43     /// CHECK: Return loop:B2
44 
45     /// CHECK-START: java.lang.Object Main.$inline$inner(java.lang.Object) builder (after)
46     /// CHECK: TryBoundary kind:exit loop:B2
47     /// CHECK: TryBoundary kind:exit loop:B2
48     /// CHECK: TryBoundary kind:exit loop:B2
$inline$inner(Object o)49     private static Object $inline$inner(Object o) {
50         for (int i = 0; i < 4; i++) {
51             try {
52                 synchronized (o) {
53                     return $noinline$call();
54                 }
55             } catch (Error e) {
56                 continue;
57             }
58         }
59         return null;
60     }
61 
62     // Simple outer to inline `inner`.
$noinline$testReturnTryBoundaryExitInLoop(Object o)63     private static Object $noinline$testReturnTryBoundaryExitInLoop(Object o) {
64         return $inline$inner(o);
65     }
66 }
67