blob: 9ed66d64e306a68fe392dcdbb8c313c4b71fb65a [file] [log] [blame]
Nicolas Geoffrayef87c5d2015-01-30 12:41:14 +00001/*
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
17public class Main {
18
19 // CHECK-START: int Main.inlineInstanceCall(Main) inliner (before)
David Brazdilc2c48ff2015-05-15 14:24:31 +010020 // CHECK-DAG: <<Invoke:i\d+>> InvokeStaticOrDirect
David Brazdilc57397b2015-05-15 16:01:59 +010021 // CHECK-DAG: Return [<<Invoke>>]
Nicolas Geoffrayef87c5d2015-01-30 12:41:14 +000022
23 // CHECK-START: int Main.inlineInstanceCall(Main) inliner (after)
24 // CHECK-NOT: InvokeStaticOrDirect
25
26 // CHECK-START: int Main.inlineInstanceCall(Main) inliner (after)
David Brazdilc2c48ff2015-05-15 14:24:31 +010027 // CHECK-DAG: <<Field:i\d+>> InstanceFieldGet
David Brazdilc57397b2015-05-15 16:01:59 +010028 // CHECK-DAG: Return [<<Field>>]
Nicolas Geoffrayef87c5d2015-01-30 12:41:14 +000029
30 public static int inlineInstanceCall(Main m) {
31 return m.foo();
32 }
33
34 private int foo() {
35 return field;
36 }
37
38 int field = 42;
39
40 // CHECK-START: int Main.inlineNestedCall() inliner (before)
David Brazdilc2c48ff2015-05-15 14:24:31 +010041 // CHECK-DAG: <<Invoke:i\d+>> InvokeStaticOrDirect
David Brazdilc57397b2015-05-15 16:01:59 +010042 // CHECK-DAG: Return [<<Invoke>>]
Nicolas Geoffrayef87c5d2015-01-30 12:41:14 +000043
44 // CHECK-START: int Main.inlineNestedCall() inliner (after)
45 // CHECK-NOT: InvokeStaticOrDirect
46
47 // CHECK-START: int Main.inlineNestedCall() inliner (after)
David Brazdilc2c48ff2015-05-15 14:24:31 +010048 // CHECK-DAG: <<Const38:i\d+>> IntConstant 38
David Brazdilc57397b2015-05-15 16:01:59 +010049 // CHECK-DAG: Return [<<Const38>>]
Nicolas Geoffrayef87c5d2015-01-30 12:41:14 +000050
51 public static int inlineNestedCall() {
52 return nestedCall();
53 }
54
55 public static int nestedCall() {
56 return bar();
57 }
58
59 public static int bar() {
60 return 38;
61 }
62
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}