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 resolved; 18 19 import getters.GetPublicSubclassOfUnresolvedClass2; 20 import unresolved.UnresolvedPublicClass; 21 22 // This class is defined by the child class loader, so access to 23 // package-private classes and members defined in the parent class 24 // loader is illegal even though the package name is the same. 25 public class PublicSubclassOfUnresolvedClass2 extends UnresolvedPublicClass { $noinline$main()26 public static void $noinline$main() { 27 $noinline$testReferrersClass(); 28 $noinline$testInlinedReferrersClass(); 29 $noinline$testInlinedReferrersClassFromSamePackage(); 30 31 $noinline$testResolvedPublicClass(); 32 $noinline$testResolvedPackagePrivateClass(); 33 34 $noinline$testPublicFieldInResolvedPackagePrivateClass(); 35 $noinline$testPublicFieldInPackagePrivateClassViaResolvedPublicSubclass(); 36 $noinline$testPrivateFieldInResolvedPackagePrivateClass(); 37 $noinline$testPrivateFieldInPackagePrivateClassViaResolvedPublicSubclass(); 38 $noinline$testPackagePrivateFieldInResolvedPackagePrivateClass(); 39 $noinline$testPackagePrivateFieldInPackagePrivateClassViaResolvedPublicSubclass(); 40 41 $noinline$testPublicMethodInResolvedPackagePrivateClass(); 42 $noinline$testPublicMethodInPackagePrivateClassViaResolvedPublicSubclass(); 43 $noinline$testPrivateMethodInResolvedPackagePrivateClass(); 44 $noinline$testPrivateMethodInPackagePrivateClassViaResolvedPublicSubclass(); 45 $noinline$testPackagePrivateMethodInResolvedPackagePrivateClass(); 46 $noinline$testPackagePrivateMethodInPackagePrivateClassViaResolvedPublicSubclass(); 47 48 System.out.println("PublicSubclassOfUnresolvedClass2 passed"); 49 } 50 51 /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testReferrersClass() builder (after) 52 /// CHECK: LoadClass class_name:resolved.PublicSubclassOfUnresolvedClass2 needs_access_check:false $noinline$testReferrersClass()53 static void $noinline$testReferrersClass() { 54 Class<?> c = PublicSubclassOfUnresolvedClass2.class; 55 } 56 57 /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testInlinedReferrersClass() inliner (after) 58 // CHECK: LoadClass class_name:resolved.PublicSubclassOfUnresolvedClass2 needs_access_check:false $noinline$testInlinedReferrersClass()59 static void $noinline$testInlinedReferrersClass() { 60 // TODO: Make $inline$ and enable CHECK above when we relax the verifier. b/28313047 61 Class<?> c = GetPublicSubclassOfUnresolvedClass2.get(); 62 } 63 64 /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testInlinedReferrersClassFromSamePackage() inliner (after) 65 // CHECK: LoadClass class_name:resolved.PublicSubclassOfUnresolvedClass2 needs_access_check:true $noinline$testInlinedReferrersClassFromSamePackage()66 static void $noinline$testInlinedReferrersClassFromSamePackage() { 67 // Trying to resolve this class by name in parent class loader throws NoClassDefFoundError. 68 try{ 69 // TODO: Make $inline$ and enable CHECK above when we relax the verifier. b/28313047 70 Class<?> c = GetPublicSubclassOfUnresolvedClass2FromSamePackage.get(); 71 throw new Error("Unreachable"); 72 } catch (NoClassDefFoundError expected) {} 73 } 74 75 /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testResolvedPublicClass() builder (after) 76 /// CHECK: LoadClass class_name:resolved.ResolvedPublicSubclassOfPackagePrivateClass needs_access_check:false $noinline$testResolvedPublicClass()77 static void $noinline$testResolvedPublicClass() { 78 Class<?> c = ResolvedPublicSubclassOfPackagePrivateClass.class; 79 } 80 81 /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testResolvedPackagePrivateClass() builder (after) 82 /// CHECK: LoadClass class_name:resolved.ResolvedPackagePrivateClass needs_access_check:true $noinline$testResolvedPackagePrivateClass()83 static void $noinline$testResolvedPackagePrivateClass() { 84 try { 85 Class<?> c = ResolvedPackagePrivateClass.class; 86 throw new Error("Unreachable"); 87 } catch (IllegalAccessError expected) {} 88 } 89 90 /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testPublicFieldInResolvedPackagePrivateClass() builder (after) 91 /// CHECK: UnresolvedStaticFieldSet 92 93 /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testPublicFieldInResolvedPackagePrivateClass() builder (after) 94 /// CHECK-NOT: StaticFieldSet $noinline$testPublicFieldInResolvedPackagePrivateClass()95 static void $noinline$testPublicFieldInResolvedPackagePrivateClass() { 96 try { 97 ResolvedPackagePrivateClass.publicIntField = 42; 98 throw new Error("Unreachable"); 99 } catch (IllegalAccessError expected) {} 100 } 101 102 /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testPublicFieldInPackagePrivateClassViaResolvedPublicSubclass() builder (after) 103 /// CHECK: StaticFieldSet 104 105 /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testPublicFieldInPackagePrivateClassViaResolvedPublicSubclass() builder (after) 106 /// CHECK-NOT: UnresolvedStaticFieldSet $noinline$testPublicFieldInPackagePrivateClassViaResolvedPublicSubclass()107 static void $noinline$testPublicFieldInPackagePrivateClassViaResolvedPublicSubclass() { 108 ResolvedPublicSubclassOfPackagePrivateClass.publicIntField = 42; 109 } 110 111 /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testPrivateFieldInResolvedPackagePrivateClass() builder (after) 112 /// CHECK: UnresolvedStaticFieldSet 113 114 /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testPrivateFieldInResolvedPackagePrivateClass() builder (after) 115 /// CHECK-NOT: StaticFieldSet $noinline$testPrivateFieldInResolvedPackagePrivateClass()116 static void $noinline$testPrivateFieldInResolvedPackagePrivateClass() { 117 try { 118 ResolvedPackagePrivateClass.privateIntField = 42; 119 throw new Error("Unreachable"); 120 } catch (IllegalAccessError expected) {} 121 } 122 123 /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testPrivateFieldInPackagePrivateClassViaResolvedPublicSubclass() builder (after) 124 /// CHECK: UnresolvedStaticFieldSet 125 126 /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testPrivateFieldInPackagePrivateClassViaResolvedPublicSubclass() builder (after) 127 /// CHECK-NOT: StaticFieldSet $noinline$testPrivateFieldInPackagePrivateClassViaResolvedPublicSubclass()128 static void $noinline$testPrivateFieldInPackagePrivateClassViaResolvedPublicSubclass() { 129 try { 130 ResolvedPublicSubclassOfPackagePrivateClass.privateIntField = 42; 131 throw new Error("Unreachable"); 132 } catch (IllegalAccessError expected) {} 133 } 134 135 /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testPackagePrivateFieldInResolvedPackagePrivateClass() builder (after) 136 /// CHECK: UnresolvedStaticFieldSet 137 138 /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testPackagePrivateFieldInResolvedPackagePrivateClass() builder (after) 139 /// CHECK-NOT: StaticFieldSet $noinline$testPackagePrivateFieldInResolvedPackagePrivateClass()140 static void $noinline$testPackagePrivateFieldInResolvedPackagePrivateClass() { 141 try { 142 ResolvedPackagePrivateClass.intField = 42; 143 throw new Error("Unreachable"); 144 } catch (IllegalAccessError expected) {} 145 } 146 147 /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testPackagePrivateFieldInPackagePrivateClassViaResolvedPublicSubclass() builder (after) 148 /// CHECK: UnresolvedStaticFieldSet 149 150 /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testPackagePrivateFieldInPackagePrivateClassViaResolvedPublicSubclass() builder (after) 151 /// CHECK-NOT: StaticFieldSet $noinline$testPackagePrivateFieldInPackagePrivateClassViaResolvedPublicSubclass()152 static void $noinline$testPackagePrivateFieldInPackagePrivateClassViaResolvedPublicSubclass() { 153 try { 154 ResolvedPublicSubclassOfPackagePrivateClass.intField = 42; 155 throw new Error("Unreachable"); 156 } catch (IllegalAccessError expected) {} 157 } 158 159 /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testPublicMethodInResolvedPackagePrivateClass() builder (after) 160 /// CHECK: InvokeUnresolved method_name:{{[^$]*}}$noinline$publicStaticMethod 161 162 /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testPublicMethodInResolvedPackagePrivateClass() builder (after) 163 /// CHECK-NOT: InvokeStaticOrDirect method_name:{{[^$]*}}$noinline$publicStaticMethod $noinline$testPublicMethodInResolvedPackagePrivateClass()164 static void $noinline$testPublicMethodInResolvedPackagePrivateClass() { 165 try { 166 ResolvedPackagePrivateClass.$noinline$publicStaticMethod(); 167 throw new Error("Unreachable"); 168 } catch (IllegalAccessError expected) {} 169 } 170 171 /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testPublicMethodInPackagePrivateClassViaResolvedPublicSubclass() builder (after) 172 /// CHECK: InvokeStaticOrDirect method_name:{{[^$]*}}$noinline$publicStaticMethod 173 174 /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testPublicMethodInPackagePrivateClassViaResolvedPublicSubclass() builder (after) 175 /// CHECK-NOT: InvokeUnresolved method_name:{{[^$]*}}$noinline$publicStaticMethod $noinline$testPublicMethodInPackagePrivateClassViaResolvedPublicSubclass()176 static void $noinline$testPublicMethodInPackagePrivateClassViaResolvedPublicSubclass() { 177 ResolvedPublicSubclassOfPackagePrivateClass.$noinline$publicStaticMethod(); 178 } 179 180 /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testPrivateMethodInResolvedPackagePrivateClass() builder (after) 181 /// CHECK: InvokeUnresolved method_name:{{[^$]*}}$noinline$privateStaticMethod 182 183 /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testPrivateMethodInResolvedPackagePrivateClass() builder (after) 184 /// CHECK-NOT: InvokeStaticOrDirect method_name:{{[^$]*}}$noinline$privateStaticMethod $noinline$testPrivateMethodInResolvedPackagePrivateClass()185 static void $noinline$testPrivateMethodInResolvedPackagePrivateClass() { 186 try { 187 ResolvedPackagePrivateClass.$noinline$privateStaticMethod(); 188 throw new Error("Unreachable"); 189 } catch (IllegalAccessError expected) {} 190 } 191 192 /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testPrivateMethodInPackagePrivateClassViaResolvedPublicSubclass() builder (after) 193 /// CHECK: InvokeUnresolved method_name:{{[^$]*}}$noinline$privateStaticMethod 194 195 /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testPrivateMethodInPackagePrivateClassViaResolvedPublicSubclass() builder (after) 196 /// CHECK-NOT: InvokeStaticOrDirect method_name:{{[^$]*}}$noinline$privateStaticMethod $noinline$testPrivateMethodInPackagePrivateClassViaResolvedPublicSubclass()197 static void $noinline$testPrivateMethodInPackagePrivateClassViaResolvedPublicSubclass() { 198 try { 199 ResolvedPublicSubclassOfPackagePrivateClass.$noinline$privateStaticMethod(); 200 throw new Error("Unreachable"); 201 } catch (IllegalAccessError expected) {} 202 } 203 204 /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testPackagePrivateMethodInResolvedPackagePrivateClass() builder (after) 205 /// CHECK: InvokeUnresolved method_name:{{[^$]*}}$noinline$staticMethod 206 207 /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testPackagePrivateMethodInResolvedPackagePrivateClass() builder (after) 208 /// CHECK-NOT: InvokeStaticOrDirect method_name:{{[^$]*}}$noinline$staticMethod $noinline$testPackagePrivateMethodInResolvedPackagePrivateClass()209 static void $noinline$testPackagePrivateMethodInResolvedPackagePrivateClass() { 210 try { 211 ResolvedPackagePrivateClass.$noinline$staticMethod(); 212 throw new Error("Unreachable"); 213 } catch (IllegalAccessError expected) {} 214 } 215 216 /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testPackagePrivateMethodInPackagePrivateClassViaResolvedPublicSubclass() builder (after) 217 /// CHECK: InvokeUnresolved method_name:{{[^$]*}}$noinline$staticMethod 218 219 /// CHECK-START: void resolved.PublicSubclassOfUnresolvedClass2.$noinline$testPackagePrivateMethodInPackagePrivateClassViaResolvedPublicSubclass() builder (after) 220 /// CHECK-NOT: InvokeStaticOrDirect method_name:{{[^$]*}}$noinline$staticMethod $noinline$testPackagePrivateMethodInPackagePrivateClassViaResolvedPublicSubclass()221 static void $noinline$testPackagePrivateMethodInPackagePrivateClassViaResolvedPublicSubclass() { 222 try { 223 ResolvedPublicSubclassOfPackagePrivateClass.$noinline$staticMethod(); 224 throw new Error("Unreachable"); 225 } catch (IllegalAccessError expected) {} 226 } 227 } 228