1 /* 2 * Copyright (C) 2020 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 package unresolved; 18 19 import getters.GetUnresolvedPublicClass; 20 import getters.GetUnresolvedPublicClassFromDifferentDexFile; 21 import resolved.PackagePrivateSubclassOfUnresolvedClass; 22 import resolved.PublicSubclassOfUnresolvedClass; 23 import resolved.ResolvedPackagePrivateClass; 24 import resolved.ResolvedPublicSubclassOfPackagePrivateClass; 25 26 public class UnresolvedPublicClass { $noinline$main()27 public static void $noinline$main() { 28 $noinline$testReferrersClass(); 29 $noinline$testInlinedReferrersClass(); 30 $noinline$testInlinedReferrersClassFromDifferentDexFile(); 31 $noinline$testInlinedClassDescriptorCompare1(); 32 $noinline$testInlinedClassDescriptorCompare2(); 33 34 $noinline$testResolvedPublicClass(); 35 $noinline$testResolvedPackagePrivateClass(); 36 $noinline$testUnresolvedPublicClass(); 37 $noinline$testUnresolvedPackagePrivateClass(); 38 $noinline$testUnresolvedPublicClassInSamePackage(); 39 $noinline$testUnresolvedPackagePrivateClassInSamePackage(); 40 41 $noinline$testPublicFieldInResolvedPackagePrivateClass(); 42 $noinline$testPublicFieldInPackagePrivateClassViaResolvedPublicSubclass(); 43 $noinline$testPrivateFieldInResolvedPackagePrivateClass(); 44 $noinline$testPrivateFieldInPackagePrivateClassViaResolvedPublicSubclass(); 45 $noinline$testPackagePrivateFieldInResolvedPackagePrivateClass(); 46 $noinline$testPackagePrivateFieldInPackagePrivateClassViaResolvedPublicSubclass(); 47 48 $noinline$testPublicMethodInResolvedPackagePrivateClass(); 49 $noinline$testPublicMethodInPackagePrivateClassViaResolvedPublicSubclass(); 50 $noinline$testPrivateMethodInResolvedPackagePrivateClass(); 51 $noinline$testPrivateMethodInPackagePrivateClassViaResolvedPublicSubclass(); 52 $noinline$testPackagePrivateMethodInResolvedPackagePrivateClass(); 53 $noinline$testPackagePrivateMethodInPackagePrivateClassViaResolvedPublicSubclass(); 54 55 System.out.println("UnresolvedPublicClass passed"); 56 } 57 58 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testReferrersClass() builder (after) 59 /// CHECK: LoadClass class_name:unresolved.UnresolvedPublicClass needs_access_check:false $noinline$testReferrersClass()60 static void $noinline$testReferrersClass() { 61 Class<?> c = UnresolvedPublicClass.class; 62 } 63 64 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testInlinedReferrersClass() inliner (after) 65 // CHECK: LoadClass class_name:unresolved.UnresolvedPublicClass needs_access_check:false $noinline$testInlinedReferrersClass()66 static void $noinline$testInlinedReferrersClass() { 67 // TODO: Make $inline$ and enable CHECK above when we relax the verifier. b/28313047 68 Class<?> c = GetUnresolvedPublicClass.get(); 69 } 70 71 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testInlinedReferrersClassFromDifferentDexFile() inliner (after) 72 // CHECK: LoadClass class_name:unresolved.UnresolvedPublicClass needs_access_check:false $noinline$testInlinedReferrersClassFromDifferentDexFile()73 static void $noinline$testInlinedReferrersClassFromDifferentDexFile() { 74 // TODO: Make $inline$ and enable CHECK above when we relax the verifier. b/28313047 75 Class<?> c = GetUnresolvedPublicClassFromDifferentDexFile.get(); 76 } 77 78 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testInlinedClassDescriptorCompare1() inliner (after) 79 // CHECK: LoadClass class_name:resolved.PublicSubclassOfUnresolvedClass needs_access_check:true $noinline$testInlinedClassDescriptorCompare1()80 static void $noinline$testInlinedClassDescriptorCompare1() { 81 // TODO: Make $inline$ and enable CHECK above when we relax the verifier. b/28313047 82 Class<?> c = 83 GetUnresolvedPublicClassFromDifferentDexFile.getOtherClass(); 84 } 85 86 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testInlinedClassDescriptorCompare2() inliner (after) 87 // CHECK: LoadClass class_name:unresolved.UnresolvedPublicClazz needs_access_check:true $noinline$testInlinedClassDescriptorCompare2()88 static void $noinline$testInlinedClassDescriptorCompare2() { 89 // This is useful for code coverage of descriptor comparison 90 // implemented by first comparing the utf16 lengths and then 91 // checking strcmp(). Using these classes we cover the path 92 // where utf16 lengths match but string contents differ. 93 // TODO: Make $inline$ and enable CHECK above when we relax the verifier. b/28313047 94 Class<?> c = 95 GetUnresolvedPublicClassFromDifferentDexFile.getOtherClassWithSameDescriptorLength(); 96 } 97 98 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testResolvedPublicClass() builder (after) 99 /// CHECK: LoadClass class_name:resolved.ResolvedPublicSubclassOfPackagePrivateClass needs_access_check:false $noinline$testResolvedPublicClass()100 static void $noinline$testResolvedPublicClass() { 101 Class<?> c = ResolvedPublicSubclassOfPackagePrivateClass.class; 102 } 103 104 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testResolvedPackagePrivateClass() builder (after) 105 /// CHECK: LoadClass class_name:resolved.ResolvedPackagePrivateClass needs_access_check:true $noinline$testResolvedPackagePrivateClass()106 static void $noinline$testResolvedPackagePrivateClass() { 107 try { 108 Class<?> c = ResolvedPackagePrivateClass.class; 109 throw new Error("Unreachable"); 110 } catch (IllegalAccessError expected) {} 111 } 112 113 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testUnresolvedPublicClass() builder (after) 114 /// CHECK: LoadClass class_name:resolved.PublicSubclassOfUnresolvedClass needs_access_check:true 115 116 /// CHECK-START-{ARM,ARM64,X86,X86_64}: void unresolved.UnresolvedPublicClass.$noinline$testUnresolvedPublicClass() builder (after) 117 /// CHECK: LoadClass load_kind:BssEntryPublic class_name:resolved.PublicSubclassOfUnresolvedClass $noinline$testUnresolvedPublicClass()118 static void $noinline$testUnresolvedPublicClass() { 119 Class<?> c = PublicSubclassOfUnresolvedClass.class; 120 } 121 122 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testUnresolvedPackagePrivateClass() builder (after) 123 /// CHECK: LoadClass class_name:resolved.PackagePrivateSubclassOfUnresolvedClass needs_access_check:true 124 125 /// CHECK-START-{ARM,ARM64,X86,X86_64}: void unresolved.UnresolvedPublicClass.$noinline$testUnresolvedPackagePrivateClass() builder (after) 126 /// CHECK: LoadClass load_kind:BssEntryPublic class_name:resolved.PackagePrivateSubclassOfUnresolvedClass $noinline$testUnresolvedPackagePrivateClass()127 static void $noinline$testUnresolvedPackagePrivateClass() { 128 try { 129 Class<?> c = PackagePrivateSubclassOfUnresolvedClass.class; 130 throw new Error("Unreachable"); 131 } catch (IllegalAccessError expected) {} 132 } 133 134 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testUnresolvedPublicClassInSamePackage() builder (after) 135 /// CHECK: LoadClass class_name:unresolved.UnresolvedPublicClazz needs_access_check:true 136 137 /// CHECK-START-{ARM,ARM64,X86,X86_64}: void unresolved.UnresolvedPublicClass.$noinline$testUnresolvedPublicClassInSamePackage() builder (after) 138 /// CHECK: LoadClass load_kind:BssEntryPackage class_name:unresolved.UnresolvedPublicClazz $noinline$testUnresolvedPublicClassInSamePackage()139 static void $noinline$testUnresolvedPublicClassInSamePackage() { 140 Class<?> c = UnresolvedPublicClazz.class; 141 } 142 143 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testUnresolvedPackagePrivateClassInSamePackage() builder (after) 144 /// CHECK: LoadClass class_name:unresolved.UnresolvedPackagePrivateClass needs_access_check:true 145 146 /// CHECK-START-{ARM,ARM64,X86,X86_64}: void unresolved.UnresolvedPublicClass.$noinline$testUnresolvedPackagePrivateClassInSamePackage() builder (after) 147 /// CHECK: LoadClass load_kind:BssEntryPackage class_name:unresolved.UnresolvedPackagePrivateClass $noinline$testUnresolvedPackagePrivateClassInSamePackage()148 static void $noinline$testUnresolvedPackagePrivateClassInSamePackage() { 149 Class<?> c = UnresolvedPackagePrivateClass.class; 150 } 151 152 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testPublicFieldInResolvedPackagePrivateClass() builder (after) 153 /// CHECK: UnresolvedStaticFieldSet 154 155 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testPublicFieldInResolvedPackagePrivateClass() builder (after) 156 /// CHECK-NOT: StaticFieldSet $noinline$testPublicFieldInResolvedPackagePrivateClass()157 static void $noinline$testPublicFieldInResolvedPackagePrivateClass() { 158 try { 159 ResolvedPackagePrivateClass.publicIntField = 42; 160 throw new Error("Unreachable"); 161 } catch (IllegalAccessError expected) {} 162 } 163 164 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testPublicFieldInPackagePrivateClassViaResolvedPublicSubclass() builder (after) 165 /// CHECK: StaticFieldSet 166 167 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testPublicFieldInPackagePrivateClassViaResolvedPublicSubclass() builder (after) 168 /// CHECK-NOT: UnresolvedStaticFieldSet $noinline$testPublicFieldInPackagePrivateClassViaResolvedPublicSubclass()169 static void $noinline$testPublicFieldInPackagePrivateClassViaResolvedPublicSubclass() { 170 ResolvedPublicSubclassOfPackagePrivateClass.publicIntField = 42; 171 } 172 173 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testPrivateFieldInResolvedPackagePrivateClass() builder (after) 174 /// CHECK: UnresolvedStaticFieldSet 175 176 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testPrivateFieldInResolvedPackagePrivateClass() builder (after) 177 /// CHECK-NOT: StaticFieldSet $noinline$testPrivateFieldInResolvedPackagePrivateClass()178 static void $noinline$testPrivateFieldInResolvedPackagePrivateClass() { 179 try { 180 ResolvedPackagePrivateClass.privateIntField = 42; 181 throw new Error("Unreachable"); 182 } catch (IllegalAccessError expected) {} 183 } 184 185 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testPrivateFieldInPackagePrivateClassViaResolvedPublicSubclass() builder (after) 186 /// CHECK: UnresolvedStaticFieldSet 187 188 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testPrivateFieldInPackagePrivateClassViaResolvedPublicSubclass() builder (after) 189 /// CHECK-NOT: StaticFieldSet $noinline$testPrivateFieldInPackagePrivateClassViaResolvedPublicSubclass()190 static void $noinline$testPrivateFieldInPackagePrivateClassViaResolvedPublicSubclass() { 191 try { 192 ResolvedPublicSubclassOfPackagePrivateClass.privateIntField = 42; 193 throw new Error("Unreachable"); 194 } catch (IllegalAccessError expected) {} 195 } 196 197 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testPackagePrivateFieldInResolvedPackagePrivateClass() builder (after) 198 /// CHECK: UnresolvedStaticFieldSet 199 200 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testPackagePrivateFieldInResolvedPackagePrivateClass() builder (after) 201 /// CHECK-NOT: StaticFieldSet $noinline$testPackagePrivateFieldInResolvedPackagePrivateClass()202 static void $noinline$testPackagePrivateFieldInResolvedPackagePrivateClass() { 203 try { 204 ResolvedPackagePrivateClass.intField = 42; 205 throw new Error("Unreachable"); 206 } catch (IllegalAccessError expected) {} 207 } 208 209 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testPackagePrivateFieldInPackagePrivateClassViaResolvedPublicSubclass() builder (after) 210 /// CHECK: UnresolvedStaticFieldSet 211 212 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testPackagePrivateFieldInPackagePrivateClassViaResolvedPublicSubclass() builder (after) 213 /// CHECK-NOT: StaticFieldSet $noinline$testPackagePrivateFieldInPackagePrivateClassViaResolvedPublicSubclass()214 static void $noinline$testPackagePrivateFieldInPackagePrivateClassViaResolvedPublicSubclass() { 215 try { 216 ResolvedPublicSubclassOfPackagePrivateClass.intField = 42; 217 throw new Error("Unreachable"); 218 } catch (IllegalAccessError expected) {} 219 } 220 221 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testPublicMethodInResolvedPackagePrivateClass() builder (after) 222 /// CHECK: InvokeUnresolved method_name:{{[^$]*}}$noinline$publicStaticMethod 223 224 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testPublicMethodInResolvedPackagePrivateClass() builder (after) 225 /// CHECK-NOT: InvokeStaticOrDirect method_name:{{[^$]*}}$noinline$publicStaticMethod $noinline$testPublicMethodInResolvedPackagePrivateClass()226 static void $noinline$testPublicMethodInResolvedPackagePrivateClass() { 227 try { 228 ResolvedPackagePrivateClass.$noinline$publicStaticMethod(); 229 throw new Error("Unreachable"); 230 } catch (IllegalAccessError expected) {} 231 } 232 233 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testPublicMethodInPackagePrivateClassViaResolvedPublicSubclass() builder (after) 234 /// CHECK: InvokeStaticOrDirect method_name:{{[^$]*}}$noinline$publicStaticMethod 235 236 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testPublicMethodInPackagePrivateClassViaResolvedPublicSubclass() builder (after) 237 /// CHECK-NOT: InvokeUnresolved method_name:{{[^$]*}}$noinline$publicStaticMethod $noinline$testPublicMethodInPackagePrivateClassViaResolvedPublicSubclass()238 static void $noinline$testPublicMethodInPackagePrivateClassViaResolvedPublicSubclass() { 239 ResolvedPublicSubclassOfPackagePrivateClass.$noinline$publicStaticMethod(); 240 } 241 242 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testPrivateMethodInResolvedPackagePrivateClass() builder (after) 243 /// CHECK: InvokeUnresolved method_name:{{[^$]*}}$noinline$privateStaticMethod 244 245 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testPrivateMethodInResolvedPackagePrivateClass() builder (after) 246 /// CHECK-NOT: InvokeStaticOrDirect method_name:{{[^$]*}}$noinline$privateStaticMethod $noinline$testPrivateMethodInResolvedPackagePrivateClass()247 static void $noinline$testPrivateMethodInResolvedPackagePrivateClass() { 248 try { 249 ResolvedPackagePrivateClass.$noinline$privateStaticMethod(); 250 throw new Error("Unreachable"); 251 } catch (IllegalAccessError expected) {} 252 } 253 254 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testPrivateMethodInPackagePrivateClassViaResolvedPublicSubclass() builder (after) 255 /// CHECK: InvokeUnresolved method_name:{{[^$]*}}$noinline$privateStaticMethod 256 257 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testPrivateMethodInPackagePrivateClassViaResolvedPublicSubclass() builder (after) 258 /// CHECK-NOT: InvokeStaticOrDirect method_name:{{[^$]*}}$noinline$privateStaticMethod $noinline$testPrivateMethodInPackagePrivateClassViaResolvedPublicSubclass()259 static void $noinline$testPrivateMethodInPackagePrivateClassViaResolvedPublicSubclass() { 260 try { 261 ResolvedPublicSubclassOfPackagePrivateClass.$noinline$privateStaticMethod(); 262 throw new Error("Unreachable"); 263 } catch (IllegalAccessError expected) {} 264 } 265 266 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testPackagePrivateMethodInResolvedPackagePrivateClass() builder (after) 267 /// CHECK: InvokeUnresolved method_name:{{[^$]*}}$noinline$staticMethod 268 269 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testPackagePrivateMethodInResolvedPackagePrivateClass() builder (after) 270 /// CHECK-NOT: InvokeStaticOrDirect method_name:{{[^$]*}}$noinline$staticMethod $noinline$testPackagePrivateMethodInResolvedPackagePrivateClass()271 static void $noinline$testPackagePrivateMethodInResolvedPackagePrivateClass() { 272 try { 273 ResolvedPackagePrivateClass.$noinline$staticMethod(); 274 throw new Error("Unreachable"); 275 } catch (IllegalAccessError expected) {} 276 } 277 278 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testPackagePrivateMethodInPackagePrivateClassViaResolvedPublicSubclass() builder (after) 279 /// CHECK: InvokeUnresolved method_name:{{[^$]*}}$noinline$staticMethod 280 281 /// CHECK-START: void unresolved.UnresolvedPublicClass.$noinline$testPackagePrivateMethodInPackagePrivateClassViaResolvedPublicSubclass() builder (after) 282 /// CHECK-NOT: InvokeStaticOrDirect method_name:{{[^$]*}}$noinline$staticMethod $noinline$testPackagePrivateMethodInPackagePrivateClassViaResolvedPublicSubclass()283 static void $noinline$testPackagePrivateMethodInPackagePrivateClassViaResolvedPublicSubclass() { 284 try { 285 ResolvedPublicSubclassOfPackagePrivateClass.$noinline$staticMethod(); 286 throw new Error("Unreachable"); 287 } catch (IllegalAccessError expected) {} 288 } 289 } 290