1 /*
2  * Copyright (C) 2014 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 
19   /// CHECK-START: int Main.inlineInstanceCall(Main) inliner (before)
20   /// CHECK-DAG:     <<Invoke:i\d+>>  InvokeStaticOrDirect
21   /// CHECK-DAG:                      Return [<<Invoke>>]
22 
23   /// CHECK-START: int Main.inlineInstanceCall(Main) inliner (after)
24   /// CHECK-NOT:                      InvokeStaticOrDirect
25 
26   /// CHECK-START: int Main.inlineInstanceCall(Main) inliner (after)
27   /// CHECK-DAG:     <<Field:i\d+>>   InstanceFieldGet
28   /// CHECK-DAG:                      Return [<<Field>>]
29 
inlineInstanceCall(Main m)30   public static int inlineInstanceCall(Main m) {
31     return m.foo();
32   }
33 
foo()34   private int foo() {
35     return field;
36   }
37 
38   int field = 42;
39 
40   /// CHECK-START: int Main.inlineNestedCall() inliner (before)
41   /// CHECK-DAG:     <<Invoke:i\d+>>  InvokeStaticOrDirect
42   /// CHECK-DAG:                      Return [<<Invoke>>]
43 
44   /// CHECK-START: int Main.inlineNestedCall() inliner (after)
45   /// CHECK-NOT:                      InvokeStaticOrDirect
46 
47   /// CHECK-START: int Main.inlineNestedCall() inliner (after)
48   /// CHECK-DAG:     <<Const38:i\d+>> IntConstant 38
49   /// CHECK-DAG:                      Return [<<Const38>>]
50 
inlineNestedCall()51   public static int inlineNestedCall() {
52     return nestedCall();
53   }
54 
nestedCall()55   public static int nestedCall() {
56     return bar();
57   }
58 
bar()59   public static int bar() {
60     return 38;
61   }
62 
main(String[] args)63   public static void main(String[] args) {
64     if (inlineInstanceCall(new Main()) != 42) {
65       throw new Error("Expected 42");
66     }
67 
68     if (inlineNestedCall() != 38) {
69       throw new Error("Expected 38");
70     }
71   }
72 }
73