Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | // Add a class that will be the first entry in the dex cache, to |
| 18 | // avoid having the OtherDex and Main classes share the same cache index. |
| 19 | class AAA { |
| 20 | } |
| 21 | |
| 22 | public class Main { |
| 23 | |
| 24 | // CHECK-START: void Main.inlineEmptyMethod() inliner (before) |
David Brazdil | c2c48ff | 2015-05-15 14:24:31 +0100 | [diff] [blame] | 25 | // CHECK-DAG: <<Invoke:v\d+>> InvokeStaticOrDirect |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 26 | // CHECK-DAG: ReturnVoid |
| 27 | |
| 28 | // CHECK-START: void Main.inlineEmptyMethod() inliner (after) |
| 29 | // CHECK-NOT: InvokeStaticOrDirect |
| 30 | |
| 31 | public static void inlineEmptyMethod() { |
| 32 | OtherDex.emptyMethod(); |
| 33 | } |
| 34 | |
| 35 | // CHECK-START: int Main.inlineReturnIntMethod() inliner (before) |
David Brazdil | c2c48ff | 2015-05-15 14:24:31 +0100 | [diff] [blame] | 36 | // CHECK-DAG: <<Invoke:i\d+>> InvokeStaticOrDirect |
David Brazdil | c57397b | 2015-05-15 16:01:59 +0100 | [diff] [blame^] | 37 | // CHECK-DAG: Return [<<Invoke>>] |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 38 | |
| 39 | // CHECK-START: int Main.inlineReturnIntMethod() inliner (after) |
| 40 | // CHECK-NOT: InvokeStaticOrDirect |
| 41 | |
| 42 | // CHECK-START: int Main.inlineReturnIntMethod() inliner (after) |
David Brazdil | c2c48ff | 2015-05-15 14:24:31 +0100 | [diff] [blame] | 43 | // CHECK-DAG: <<Const38:i\d+>> IntConstant 38 |
David Brazdil | c57397b | 2015-05-15 16:01:59 +0100 | [diff] [blame^] | 44 | // CHECK-DAG: Return [<<Const38>>] |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 45 | |
| 46 | public static int inlineReturnIntMethod() { |
| 47 | return OtherDex.returnIntMethod(); |
| 48 | } |
| 49 | |
| 50 | // CHECK-START: int Main.dontInlineOtherDexStatic() inliner (before) |
David Brazdil | c2c48ff | 2015-05-15 14:24:31 +0100 | [diff] [blame] | 51 | // CHECK-DAG: <<Invoke:i\d+>> InvokeStaticOrDirect |
David Brazdil | c57397b | 2015-05-15 16:01:59 +0100 | [diff] [blame^] | 52 | // CHECK-DAG: Return [<<Invoke>>] |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 53 | |
| 54 | // CHECK-START: int Main.dontInlineOtherDexStatic() inliner (after) |
David Brazdil | c2c48ff | 2015-05-15 14:24:31 +0100 | [diff] [blame] | 55 | // CHECK-DAG: <<Invoke:i\d+>> InvokeStaticOrDirect |
David Brazdil | c57397b | 2015-05-15 16:01:59 +0100 | [diff] [blame^] | 56 | // CHECK-DAG: Return [<<Invoke>>] |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 57 | |
| 58 | public static int dontInlineOtherDexStatic() { |
| 59 | return OtherDex.returnOtherDexStatic(); |
| 60 | } |
| 61 | |
| 62 | // CHECK-START: int Main.inlineMainStatic() inliner (before) |
David Brazdil | c2c48ff | 2015-05-15 14:24:31 +0100 | [diff] [blame] | 63 | // CHECK-DAG: <<Invoke:i\d+>> InvokeStaticOrDirect |
David Brazdil | c57397b | 2015-05-15 16:01:59 +0100 | [diff] [blame^] | 64 | // CHECK-DAG: Return [<<Invoke>>] |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 65 | |
| 66 | // CHECK-START: int Main.inlineMainStatic() inliner (after) |
| 67 | // CHECK-NOT: InvokeStaticOrDirect |
| 68 | |
| 69 | // CHECK-START: int Main.inlineMainStatic() inliner (after) |
David Brazdil | c2c48ff | 2015-05-15 14:24:31 +0100 | [diff] [blame] | 70 | // CHECK-DAG: <<Static:i\d+>> StaticFieldGet |
David Brazdil | c57397b | 2015-05-15 16:01:59 +0100 | [diff] [blame^] | 71 | // CHECK-DAG: Return [<<Static>>] |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 72 | |
| 73 | public static int inlineMainStatic() { |
| 74 | return OtherDex.returnMainStatic(); |
| 75 | } |
| 76 | |
| 77 | // CHECK-START: int Main.dontInlineRecursiveCall() inliner (before) |
David Brazdil | c2c48ff | 2015-05-15 14:24:31 +0100 | [diff] [blame] | 78 | // CHECK-DAG: <<Invoke:i\d+>> InvokeStaticOrDirect |
David Brazdil | c57397b | 2015-05-15 16:01:59 +0100 | [diff] [blame^] | 79 | // CHECK-DAG: Return [<<Invoke>>] |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 80 | |
| 81 | // CHECK-START: int Main.dontInlineRecursiveCall() inliner (after) |
David Brazdil | c2c48ff | 2015-05-15 14:24:31 +0100 | [diff] [blame] | 82 | // CHECK-DAG: <<Invoke:i\d+>> InvokeStaticOrDirect |
David Brazdil | c57397b | 2015-05-15 16:01:59 +0100 | [diff] [blame^] | 83 | // CHECK-DAG: Return [<<Invoke>>] |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 84 | |
| 85 | public static int dontInlineRecursiveCall() { |
| 86 | return OtherDex.recursiveCall(); |
| 87 | } |
| 88 | |
| 89 | // CHECK-START: java.lang.String Main.dontInlineReturnString() inliner (before) |
David Brazdil | c2c48ff | 2015-05-15 14:24:31 +0100 | [diff] [blame] | 90 | // CHECK-DAG: <<Invoke:l\d+>> InvokeStaticOrDirect |
David Brazdil | c57397b | 2015-05-15 16:01:59 +0100 | [diff] [blame^] | 91 | // CHECK-DAG: Return [<<Invoke>>] |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 92 | |
| 93 | // CHECK-START: java.lang.String Main.dontInlineReturnString() inliner (after) |
David Brazdil | c2c48ff | 2015-05-15 14:24:31 +0100 | [diff] [blame] | 94 | // CHECK-DAG: <<Invoke:l\d+>> InvokeStaticOrDirect |
David Brazdil | c57397b | 2015-05-15 16:01:59 +0100 | [diff] [blame^] | 95 | // CHECK-DAG: Return [<<Invoke>>] |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 96 | |
| 97 | public static String dontInlineReturnString() { |
| 98 | return OtherDex.returnString(); |
| 99 | } |
| 100 | |
| 101 | // CHECK-START: java.lang.Class Main.dontInlineOtherDexClass() inliner (before) |
David Brazdil | c2c48ff | 2015-05-15 14:24:31 +0100 | [diff] [blame] | 102 | // CHECK-DAG: <<Invoke:l\d+>> InvokeStaticOrDirect |
David Brazdil | c57397b | 2015-05-15 16:01:59 +0100 | [diff] [blame^] | 103 | // CHECK-DAG: Return [<<Invoke>>] |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 104 | |
| 105 | // CHECK-START: java.lang.Class Main.dontInlineOtherDexClass() inliner (after) |
David Brazdil | c2c48ff | 2015-05-15 14:24:31 +0100 | [diff] [blame] | 106 | // CHECK-DAG: <<Invoke:l\d+>> InvokeStaticOrDirect |
David Brazdil | c57397b | 2015-05-15 16:01:59 +0100 | [diff] [blame^] | 107 | // CHECK-DAG: Return [<<Invoke>>] |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 108 | |
| 109 | public static Class dontInlineOtherDexClass() { |
| 110 | return OtherDex.returnOtherDexClass(); |
| 111 | } |
| 112 | |
| 113 | // CHECK-START: java.lang.Class Main.inlineMainClass() inliner (before) |
David Brazdil | c2c48ff | 2015-05-15 14:24:31 +0100 | [diff] [blame] | 114 | // CHECK-DAG: <<Invoke:l\d+>> InvokeStaticOrDirect |
David Brazdil | c57397b | 2015-05-15 16:01:59 +0100 | [diff] [blame^] | 115 | // CHECK-DAG: Return [<<Invoke>>] |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 116 | |
| 117 | // CHECK-START: java.lang.Class Main.inlineMainClass() inliner (after) |
| 118 | // CHECK-NOT: InvokeStaticOrDirect |
| 119 | |
| 120 | // CHECK-START: java.lang.Class Main.inlineMainClass() inliner (after) |
David Brazdil | c57397b | 2015-05-15 16:01:59 +0100 | [diff] [blame^] | 121 | // CHECK-DAG: Return [<<Class:l\d+>>] |
| 122 | // CHECK-DAG: <<Class>> LoadClass |
| 123 | // Note: Verify backwards because there are two LoadClass instructions |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 124 | |
| 125 | public static Class inlineMainClass() { |
| 126 | return OtherDex.returnMainClass(); |
| 127 | } |
| 128 | |
| 129 | // CHECK-START: java.lang.Class Main.dontInlineOtherDexClassStaticCall() inliner (before) |
David Brazdil | c2c48ff | 2015-05-15 14:24:31 +0100 | [diff] [blame] | 130 | // CHECK-DAG: <<Invoke:l\d+>> InvokeStaticOrDirect |
David Brazdil | c57397b | 2015-05-15 16:01:59 +0100 | [diff] [blame^] | 131 | // CHECK-DAG: Return [<<Invoke>>] |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 132 | |
| 133 | // CHECK-START: java.lang.Class Main.dontInlineOtherDexClassStaticCall() inliner (after) |
David Brazdil | c2c48ff | 2015-05-15 14:24:31 +0100 | [diff] [blame] | 134 | // CHECK-DAG: <<Invoke:l\d+>> InvokeStaticOrDirect |
David Brazdil | c57397b | 2015-05-15 16:01:59 +0100 | [diff] [blame^] | 135 | // CHECK-DAG: Return [<<Invoke>>] |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 136 | |
| 137 | public static Class dontInlineOtherDexClassStaticCall() { |
| 138 | return OtherDex.returnOtherDexClassStaticCall(); |
| 139 | } |
| 140 | |
| 141 | // CHECK-START: java.lang.Class Main.inlineOtherDexCallingMain() inliner (before) |
David Brazdil | c2c48ff | 2015-05-15 14:24:31 +0100 | [diff] [blame] | 142 | // CHECK-DAG: <<Invoke:l\d+>> InvokeStaticOrDirect |
David Brazdil | c57397b | 2015-05-15 16:01:59 +0100 | [diff] [blame^] | 143 | // CHECK-DAG: Return [<<Invoke>>] |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 144 | |
| 145 | // CHECK-START: java.lang.Class Main.inlineOtherDexCallingMain() inliner (after) |
| 146 | // CHECK-NOT: InvokeStaticOrDirect |
| 147 | |
| 148 | // CHECK-START: java.lang.Class Main.inlineOtherDexCallingMain() inliner (after) |
David Brazdil | c57397b | 2015-05-15 16:01:59 +0100 | [diff] [blame^] | 149 | // CHECK-DAG: Return [<<Class:l\d+>>] |
| 150 | // CHECK-DAG: <<Class>> LoadClass |
| 151 | // Note: Verify backwards because there are two LoadClass instructions |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 152 | |
| 153 | public static Class inlineOtherDexCallingMain() { |
| 154 | return OtherDex.returnOtherDexCallingMain(); |
| 155 | } |
| 156 | |
| 157 | public static Class getOtherClass() { |
| 158 | return Main.class; |
| 159 | } |
| 160 | |
| 161 | public static void main(String[] args) { |
| 162 | inlineEmptyMethod(); |
| 163 | if (inlineReturnIntMethod() != 38) { |
| 164 | throw new Error("Expected 38"); |
| 165 | } |
| 166 | |
| 167 | if (dontInlineOtherDexStatic() != 1) { |
| 168 | throw new Error("Expected 1"); |
| 169 | } |
| 170 | |
| 171 | if (inlineMainStatic() != 42) { |
| 172 | throw new Error("Expected 42"); |
| 173 | } |
| 174 | |
| 175 | if (dontInlineReturnString() != "OtherDex") { |
| 176 | throw new Error("Expected OtherDex"); |
| 177 | } |
| 178 | |
| 179 | if (dontInlineOtherDexClass() != OtherDex.class) { |
| 180 | throw new Error("Expected " + OtherDex.class); |
| 181 | } |
| 182 | |
| 183 | if (dontInlineOtherDexClassStaticCall() != OtherDex.class) { |
| 184 | throw new Error("Expected " + OtherDex.class); |
| 185 | } |
| 186 | |
| 187 | if (inlineMainClass() != Main.class) { |
| 188 | throw new Error("Expected " + Main.class); |
| 189 | } |
| 190 | |
| 191 | if (inlineOtherDexCallingMain() != Main.class) { |
| 192 | throw new Error("Expected " + Main.class); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | // Reference the AAA class to ensure it is in the dex cache. |
| 197 | public static Class<?> cls = AAA.class; |
| 198 | |
| 199 | // Add a field that will be the first entry in the dex cache, to |
| 200 | // avoid having the OtherDex.myStatic and Main.myStatic fields |
| 201 | // share the same cache index. |
| 202 | public static int aaa = 32; |
| 203 | public static int myStatic = 42; |
| 204 | } |