| Andreas Gampe | e492ae3 | 2016-10-28 19:34:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | |
| Andreas Gampe | 70f1639 | 2017-01-16 14:20:10 -0800 | [diff] [blame] | 17 | import java.lang.reflect.Constructor; |
| Andreas Gampe | e492ae3 | 2016-10-28 19:34:57 -0700 | [diff] [blame] | 18 | import java.lang.reflect.Proxy; |
| 19 | import java.util.Arrays; |
| Andreas Gampe | 70f1639 | 2017-01-16 14:20:10 -0800 | [diff] [blame] | 20 | import java.util.Comparator; |
| Andreas Gampe | e492ae3 | 2016-10-28 19:34:57 -0700 | [diff] [blame] | 21 | |
| 22 | public class Main { |
| 23 | public static void main(String[] args) throws Exception { |
| Andreas Gampe | e492ae3 | 2016-10-28 19:34:57 -0700 | [diff] [blame] | 24 | doTest(); |
| 25 | } |
| 26 | |
| 27 | public static void doTest() throws Exception { |
| 28 | testClass("java.lang.Object"); |
| 29 | testClass("java.lang.String"); |
| 30 | testClass("java.lang.Math"); |
| 31 | testClass("java.util.List"); |
| 32 | |
| 33 | testClass(getProxyClass()); |
| 34 | |
| 35 | testClass(int.class); |
| 36 | testClass(double[].class); |
| Andreas Gampe | 4fd66ec | 2017-01-05 14:42:13 -0800 | [diff] [blame] | 37 | |
| 38 | testClassType(int.class); |
| 39 | testClassType(getProxyClass()); |
| 40 | testClassType(Runnable.class); |
| 41 | testClassType(String.class); |
| 42 | |
| 43 | testClassType(int[].class); |
| 44 | testClassType(Runnable[].class); |
| 45 | testClassType(String[].class); |
| Andreas Gampe | ac58727 | 2017-01-05 15:21:34 -0800 | [diff] [blame] | 46 | |
| 47 | testClassFields(Integer.class); |
| 48 | testClassFields(int.class); |
| 49 | testClassFields(String[].class); |
| Andreas Gampe | ff9d209 | 2017-01-06 09:12:49 -0800 | [diff] [blame] | 50 | |
| Andreas Gampe | 18fee4d | 2017-01-06 11:36:35 -0800 | [diff] [blame] | 51 | testClassMethods(Integer.class); |
| 52 | testClassMethods(int.class); |
| 53 | testClassMethods(String[].class); |
| 54 | |
| Andreas Gampe | ff9d209 | 2017-01-06 09:12:49 -0800 | [diff] [blame] | 55 | testClassStatus(int.class); |
| 56 | testClassStatus(String[].class); |
| 57 | testClassStatus(Object.class); |
| 58 | testClassStatus(TestForNonInit.class); |
| 59 | try { |
| 60 | System.out.println(TestForInitFail.dummy); |
| 61 | } catch (ExceptionInInitializerError e) { |
| 62 | } |
| 63 | testClassStatus(TestForInitFail.class); |
| Andreas Gampe | 8b07e47 | 2017-01-06 14:20:39 -0800 | [diff] [blame] | 64 | |
| 65 | testInterfaces(int.class); |
| 66 | testInterfaces(String[].class); |
| 67 | testInterfaces(Object.class); |
| 68 | testInterfaces(InfA.class); |
| 69 | testInterfaces(InfB.class); |
| 70 | testInterfaces(InfC.class); |
| 71 | testInterfaces(ClassA.class); |
| 72 | testInterfaces(ClassB.class); |
| 73 | testInterfaces(ClassC.class); |
| Andreas Gampe | 8f5b603 | 2017-01-06 15:50:55 -0800 | [diff] [blame] | 74 | |
| 75 | testClassLoader(String.class); |
| 76 | testClassLoader(String[].class); |
| 77 | testClassLoader(InfA.class); |
| 78 | testClassLoader(getProxyClass()); |
| Andreas Gampe | 70f1639 | 2017-01-16 14:20:10 -0800 | [diff] [blame] | 79 | |
| 80 | testClassLoaderClasses(); |
| Andreas Gampe | 812a244 | 2017-01-19 22:04:46 -0800 | [diff] [blame] | 81 | |
| 82 | System.out.println(); |
| 83 | |
| 84 | testClassVersion(); |
| Andreas Gampe | e637746 | 2017-01-20 17:37:50 -0800 | [diff] [blame] | 85 | |
| 86 | System.out.println(); |
| 87 | |
| 88 | testClassEvents(); |
| Andreas Gampe | e492ae3 | 2016-10-28 19:34:57 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | private static Class<?> proxyClass = null; |
| 92 | |
| 93 | private static Class<?> getProxyClass() throws Exception { |
| 94 | if (proxyClass != null) { |
| 95 | return proxyClass; |
| 96 | } |
| 97 | |
| 98 | proxyClass = Proxy.getProxyClass(Main.class.getClassLoader(), new Class[] { Runnable.class }); |
| 99 | return proxyClass; |
| 100 | } |
| 101 | |
| 102 | private static void testClass(String className) throws Exception { |
| 103 | Class<?> base = Class.forName(className); |
| 104 | testClass(base); |
| 105 | } |
| 106 | |
| 107 | private static void testClass(Class<?> base) throws Exception { |
| 108 | String[] result = getClassSignature(base); |
| 109 | System.out.println(Arrays.toString(result)); |
| Andreas Gampe | 64013e5 | 2017-01-06 13:07:19 -0800 | [diff] [blame] | 110 | int mod = getClassModifiers(base); |
| 111 | if (mod != base.getModifiers()) { |
| 112 | throw new RuntimeException("Unexpected modifiers: " + base.getModifiers() + " vs " + mod); |
| 113 | } |
| 114 | System.out.println(Integer.toHexString(mod)); |
| Andreas Gampe | e492ae3 | 2016-10-28 19:34:57 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| Andreas Gampe | 4fd66ec | 2017-01-05 14:42:13 -0800 | [diff] [blame] | 117 | private static void testClassType(Class<?> c) throws Exception { |
| 118 | boolean isInterface = isInterface(c); |
| 119 | boolean isArray = isArrayClass(c); |
| Alex Light | e4a8863 | 2017-01-10 07:41:24 -0800 | [diff] [blame] | 120 | boolean isModifiable = isModifiableClass(c); |
| 121 | System.out.println(c.getName() + " interface=" + isInterface + " array=" + isArray + |
| 122 | " modifiable=" + isModifiable); |
| Andreas Gampe | 4fd66ec | 2017-01-05 14:42:13 -0800 | [diff] [blame] | 123 | } |
| 124 | |
| Andreas Gampe | ac58727 | 2017-01-05 15:21:34 -0800 | [diff] [blame] | 125 | private static void testClassFields(Class<?> c) throws Exception { |
| 126 | System.out.println(Arrays.toString(getClassFields(c))); |
| 127 | } |
| 128 | |
| Andreas Gampe | 18fee4d | 2017-01-06 11:36:35 -0800 | [diff] [blame] | 129 | private static void testClassMethods(Class<?> c) throws Exception { |
| 130 | System.out.println(Arrays.toString(getClassMethods(c))); |
| 131 | } |
| 132 | |
| Andreas Gampe | ff9d209 | 2017-01-06 09:12:49 -0800 | [diff] [blame] | 133 | private static void testClassStatus(Class<?> c) { |
| 134 | System.out.println(c + " " + Integer.toBinaryString(getClassStatus(c))); |
| 135 | } |
| 136 | |
| Andreas Gampe | 8b07e47 | 2017-01-06 14:20:39 -0800 | [diff] [blame] | 137 | private static void testInterfaces(Class<?> c) { |
| 138 | System.out.println(c + " " + Arrays.toString(getImplementedInterfaces(c))); |
| 139 | } |
| 140 | |
| Andreas Gampe | 8f5b603 | 2017-01-06 15:50:55 -0800 | [diff] [blame] | 141 | private static boolean IsBootClassLoader(ClassLoader l) { |
| 142 | // Hacky check for Android's fake boot classloader. |
| 143 | return l.getClass().getName().equals("java.lang.BootClassLoader"); |
| 144 | } |
| 145 | |
| 146 | private static void testClassLoader(Class<?> c) { |
| 147 | Object cl = getClassLoader(c); |
| 148 | System.out.println(c + " " + (cl != null ? cl.getClass().getName() : "null")); |
| 149 | if (cl == null) { |
| 150 | if (c.getClassLoader() != null && !IsBootClassLoader(c.getClassLoader())) { |
| 151 | throw new RuntimeException("Expected " + c.getClassLoader() + ", but got null."); |
| 152 | } |
| 153 | } else { |
| 154 | if (!(cl instanceof ClassLoader)) { |
| 155 | throw new RuntimeException("Unexpected \"classloader\": " + cl + " (" + cl.getClass() + |
| 156 | ")"); |
| 157 | } |
| 158 | if (cl != c.getClassLoader()) { |
| 159 | throw new RuntimeException("Unexpected classloader: " + c.getClassLoader() + " vs " + cl); |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | |
| Andreas Gampe | 70f1639 | 2017-01-16 14:20:10 -0800 | [diff] [blame] | 164 | private static void testClassLoaderClasses() throws Exception { |
| 165 | ClassLoader boot = ClassLoader.getSystemClassLoader().getParent(); |
| 166 | while (boot.getParent() != null) { |
| 167 | boot = boot.getParent(); |
| 168 | } |
| 169 | |
| 170 | System.out.println(); |
| 171 | System.out.println("boot <- src <- src-ex (A,B)"); |
| 172 | ClassLoader cl1 = create(create(boot, DEX1), DEX2); |
| 173 | Class.forName("B", false, cl1); |
| 174 | Class.forName("A", false, cl1); |
| 175 | printClassLoaderClasses(cl1); |
| 176 | |
| 177 | System.out.println(); |
| 178 | System.out.println("boot <- src (B) <- src-ex (A, List)"); |
| 179 | ClassLoader cl2 = create(create(boot, DEX1), DEX2); |
| 180 | Class.forName("A", false, cl2); |
| 181 | Class.forName("java.util.List", false, cl2); |
| 182 | Class.forName("B", false, cl2.getParent()); |
| 183 | printClassLoaderClasses(cl2); |
| 184 | |
| 185 | System.out.println(); |
| 186 | System.out.println("boot <- src+src-ex (A,B)"); |
| 187 | ClassLoader cl3 = create(boot, DEX1, DEX2); |
| 188 | Class.forName("B", false, cl3); |
| 189 | Class.forName("A", false, cl3); |
| 190 | printClassLoaderClasses(cl3); |
| 191 | |
| 192 | // Check that the boot classloader dumps something non-empty. |
| 193 | Class<?>[] bootClasses = getClassLoaderClasses(boot); |
| 194 | if (bootClasses.length == 0) { |
| 195 | throw new RuntimeException("No classes initiated by boot classloader."); |
| 196 | } |
| 197 | // Check that at least java.util.List is loaded. |
| 198 | boolean foundList = false; |
| 199 | for (Class<?> c : bootClasses) { |
| 200 | if (c == java.util.List.class) { |
| 201 | foundList = true; |
| 202 | break; |
| 203 | } |
| 204 | } |
| 205 | if (!foundList) { |
| 206 | System.out.println(Arrays.toString(bootClasses)); |
| 207 | throw new RuntimeException("Could not find class java.util.List."); |
| 208 | } |
| 209 | } |
| 210 | |
| Andreas Gampe | 812a244 | 2017-01-19 22:04:46 -0800 | [diff] [blame] | 211 | private static void testClassVersion() { |
| 212 | System.out.println(Arrays.toString(getClassVersion(Main.class))); |
| 213 | } |
| 214 | |
| Andreas Gampe | e637746 | 2017-01-20 17:37:50 -0800 | [diff] [blame] | 215 | private static void testClassEvents() throws Exception { |
| 216 | ClassLoader cl = Main.class.getClassLoader(); |
| 217 | while (cl.getParent() != null) { |
| 218 | cl = cl.getParent(); |
| 219 | } |
| 220 | final ClassLoader boot = cl; |
| 221 | |
| Andreas Gampe | e2744c6 | 2017-02-08 16:28:59 +0000 | [diff] [blame] | 222 | // The JIT may deeply inline and load some classes. Preload these for test determinism. |
| 223 | final String PRELOAD_FOR_JIT[] = { |
| 224 | "java.nio.charset.CoderMalfunctionError", |
| 225 | "java.util.NoSuchElementException" |
| 226 | }; |
| 227 | for (String s : PRELOAD_FOR_JIT) { |
| 228 | Class.forName(s); |
| 229 | } |
| 230 | |
| Andreas Gampe | 1995859 | 2017-01-23 17:29:07 -0800 | [diff] [blame] | 231 | Runnable r = new Runnable() { |
| 232 | @Override |
| 233 | public void run() { |
| 234 | try { |
| 235 | ClassLoader cl6 = create(boot, DEX1, DEX2); |
| 236 | System.out.println("C, true"); |
| 237 | Class.forName("C", true, cl6); |
| 238 | } catch (Exception e) { |
| 239 | throw new RuntimeException(e); |
| 240 | } |
| 241 | } |
| 242 | }; |
| 243 | |
| Andreas Gampe | 4152661 | 2017-01-23 22:48:15 -0800 | [diff] [blame] | 244 | Thread dummyThread = new Thread(); |
| 245 | dummyThread.start(); |
| 246 | dummyThread.join(); |
| 247 | |
| 248 | ensureJitCompiled(Main.class, "testClassEvents"); |
| 249 | |
| Andreas Gampe | e2744c6 | 2017-02-08 16:28:59 +0000 | [diff] [blame] | 250 | enableClassLoadPreparePrintEvents(true); |
| Andreas Gampe | e637746 | 2017-01-20 17:37:50 -0800 | [diff] [blame] | 251 | |
| 252 | ClassLoader cl1 = create(boot, DEX1, DEX2); |
| 253 | System.out.println("B, false"); |
| 254 | Class.forName("B", false, cl1); |
| 255 | |
| 256 | ClassLoader cl2 = create(boot, DEX1, DEX2); |
| 257 | System.out.println("B, true"); |
| 258 | Class.forName("B", true, cl2); |
| 259 | |
| 260 | ClassLoader cl3 = create(boot, DEX1, DEX2); |
| 261 | System.out.println("C, false"); |
| 262 | Class.forName("C", false, cl3); |
| 263 | System.out.println("A, false"); |
| 264 | Class.forName("A", false, cl3); |
| 265 | |
| 266 | ClassLoader cl4 = create(boot, DEX1, DEX2); |
| 267 | System.out.println("C, true"); |
| 268 | Class.forName("C", true, cl4); |
| 269 | System.out.println("A, true"); |
| 270 | Class.forName("A", true, cl4); |
| 271 | |
| 272 | ClassLoader cl5 = create(boot, DEX1, DEX2); |
| 273 | System.out.println("A, true"); |
| 274 | Class.forName("A", true, cl5); |
| 275 | System.out.println("C, true"); |
| 276 | Class.forName("C", true, cl5); |
| 277 | |
| Andreas Gampe | e637746 | 2017-01-20 17:37:50 -0800 | [diff] [blame] | 278 | Thread t = new Thread(r, "TestRunner"); |
| 279 | t.start(); |
| 280 | t.join(); |
| 281 | |
| Andreas Gampe | e2744c6 | 2017-02-08 16:28:59 +0000 | [diff] [blame] | 282 | enableClassLoadPreparePrintEvents(false); |
| 283 | |
| 284 | // Note: the JIT part of this test is about the JIT pulling in a class not yet touched by |
| 285 | // anything else in the system. This could be the verifier or the interpreter. We |
| 286 | // block the interpreter by calling ensureJitCompiled. The verifier, however, must |
| 287 | // run in configurations where dex2oat didn't verify the class itself. So explicitly |
| 288 | // check whether the class has been already loaded, and skip then. |
| 289 | // TODO: Add multiple configurations to the run script once that becomes easier to do. |
| 290 | if (hasJit() && !isLoadedClass("Main$ClassD")) { |
| 291 | testClassEventsJit(); |
| 292 | } |
| Andreas Gampe | 691051b | 2017-02-09 09:15:24 -0800 | [diff] [blame] | 293 | |
| 294 | testClassLoadPrepareEquality(); |
| Andreas Gampe | e2744c6 | 2017-02-08 16:28:59 +0000 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | private static void testClassEventsJit() throws Exception { |
| 298 | enableClassLoadSeenEvents(true); |
| 299 | |
| 300 | testClassEventsJitImpl(); |
| 301 | |
| 302 | enableClassLoadSeenEvents(false); |
| 303 | |
| 304 | if (!hadLoadEvent()) { |
| 305 | throw new RuntimeException("Did not get expected load event."); |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | private static void testClassEventsJitImpl() throws Exception { |
| 310 | ensureJitCompiled(Main.class, "testClassEventsJitImpl"); |
| 311 | |
| 312 | if (ClassD.x != 1) { |
| 313 | throw new RuntimeException("Unexpected value"); |
| 314 | } |
| Andreas Gampe | e637746 | 2017-01-20 17:37:50 -0800 | [diff] [blame] | 315 | } |
| 316 | |
| Andreas Gampe | 691051b | 2017-02-09 09:15:24 -0800 | [diff] [blame] | 317 | private static void testClassLoadPrepareEquality() throws Exception { |
| Andreas Gampe | a67354b | 2017-02-10 16:18:30 -0800 | [diff] [blame^] | 318 | setEqualityEventStorageClass(ClassF.class); |
| 319 | |
| Andreas Gampe | 691051b | 2017-02-09 09:15:24 -0800 | [diff] [blame] | 320 | enableClassLoadPrepareEqualityEvents(true); |
| 321 | |
| 322 | Class.forName("Main$ClassE"); |
| 323 | |
| 324 | enableClassLoadPrepareEqualityEvents(false); |
| 325 | } |
| 326 | |
| Andreas Gampe | 70f1639 | 2017-01-16 14:20:10 -0800 | [diff] [blame] | 327 | private static void printClassLoaderClasses(ClassLoader cl) { |
| 328 | for (;;) { |
| 329 | if (cl == null || !cl.getClass().getName().startsWith("dalvik.system")) { |
| 330 | break; |
| 331 | } |
| 332 | |
| 333 | ClassLoader saved = cl; |
| 334 | for (;;) { |
| 335 | if (cl == null || !cl.getClass().getName().startsWith("dalvik.system")) { |
| 336 | break; |
| 337 | } |
| 338 | String s = cl.toString(); |
| 339 | int index1 = s.indexOf("zip file"); |
| 340 | int index2 = s.indexOf(']', index1); |
| 341 | if (index2 < 0) { |
| 342 | throw new RuntimeException("Unexpected classloader " + s); |
| 343 | } |
| 344 | String zip_file = s.substring(index1, index2); |
| 345 | int index3 = zip_file.indexOf('"'); |
| 346 | int index4 = zip_file.indexOf('"', index3 + 1); |
| 347 | if (index4 < 0) { |
| 348 | throw new RuntimeException("Unexpected classloader " + s); |
| 349 | } |
| 350 | String paths = zip_file.substring(index3 + 1, index4); |
| 351 | String pathArray[] = paths.split(":"); |
| 352 | for (String path : pathArray) { |
| 353 | int index5 = path.lastIndexOf('/'); |
| 354 | System.out.print(path.substring(index5 + 1)); |
| 355 | System.out.print('+'); |
| 356 | } |
| 357 | System.out.print(" -> "); |
| 358 | cl = cl.getParent(); |
| 359 | } |
| 360 | System.out.println(); |
| 361 | Class<?> classes[] = getClassLoaderClasses(saved); |
| 362 | Arrays.sort(classes, new ClassNameComparator()); |
| 363 | System.out.println(Arrays.toString(classes)); |
| 364 | |
| 365 | cl = saved.getParent(); |
| 366 | } |
| 367 | } |
| 368 | |
| Alex Light | e4a8863 | 2017-01-10 07:41:24 -0800 | [diff] [blame] | 369 | private static native boolean isModifiableClass(Class<?> c); |
| Andreas Gampe | e492ae3 | 2016-10-28 19:34:57 -0700 | [diff] [blame] | 370 | private static native String[] getClassSignature(Class<?> c); |
| Andreas Gampe | 4fd66ec | 2017-01-05 14:42:13 -0800 | [diff] [blame] | 371 | |
| 372 | private static native boolean isInterface(Class<?> c); |
| 373 | private static native boolean isArrayClass(Class<?> c); |
| Andreas Gampe | ac58727 | 2017-01-05 15:21:34 -0800 | [diff] [blame] | 374 | |
| Andreas Gampe | 64013e5 | 2017-01-06 13:07:19 -0800 | [diff] [blame] | 375 | private static native int getClassModifiers(Class<?> c); |
| 376 | |
| Andreas Gampe | ac58727 | 2017-01-05 15:21:34 -0800 | [diff] [blame] | 377 | private static native Object[] getClassFields(Class<?> c); |
| Andreas Gampe | 18fee4d | 2017-01-06 11:36:35 -0800 | [diff] [blame] | 378 | private static native Object[] getClassMethods(Class<?> c); |
| Andreas Gampe | 70f1639 | 2017-01-16 14:20:10 -0800 | [diff] [blame] | 379 | private static native Class<?>[] getImplementedInterfaces(Class<?> c); |
| Andreas Gampe | ff9d209 | 2017-01-06 09:12:49 -0800 | [diff] [blame] | 380 | |
| 381 | private static native int getClassStatus(Class<?> c); |
| 382 | |
| Andreas Gampe | 8f5b603 | 2017-01-06 15:50:55 -0800 | [diff] [blame] | 383 | private static native Object getClassLoader(Class<?> c); |
| 384 | |
| Andreas Gampe | 70f1639 | 2017-01-16 14:20:10 -0800 | [diff] [blame] | 385 | private static native Class<?>[] getClassLoaderClasses(ClassLoader cl); |
| 386 | |
| Andreas Gampe | 812a244 | 2017-01-19 22:04:46 -0800 | [diff] [blame] | 387 | private static native int[] getClassVersion(Class<?> c); |
| 388 | |
| Andreas Gampe | e2744c6 | 2017-02-08 16:28:59 +0000 | [diff] [blame] | 389 | private static native void enableClassLoadPreparePrintEvents(boolean b); |
| Andreas Gampe | e637746 | 2017-01-20 17:37:50 -0800 | [diff] [blame] | 390 | |
| Andreas Gampe | e2744c6 | 2017-02-08 16:28:59 +0000 | [diff] [blame] | 391 | private static native void ensureJitCompiled(Class<?> c, String name); |
| 392 | |
| 393 | private static native boolean hasJit(); |
| 394 | private static native boolean isLoadedClass(String name); |
| 395 | private static native void enableClassLoadSeenEvents(boolean b); |
| 396 | private static native boolean hadLoadEvent(); |
| Andreas Gampe | 4152661 | 2017-01-23 22:48:15 -0800 | [diff] [blame] | 397 | |
| Andreas Gampe | a67354b | 2017-02-10 16:18:30 -0800 | [diff] [blame^] | 398 | private static native void setEqualityEventStorageClass(Class<?> c); |
| Andreas Gampe | 691051b | 2017-02-09 09:15:24 -0800 | [diff] [blame] | 399 | private static native void enableClassLoadPrepareEqualityEvents(boolean b); |
| 400 | |
| Andreas Gampe | ff9d209 | 2017-01-06 09:12:49 -0800 | [diff] [blame] | 401 | private static class TestForNonInit { |
| 402 | public static double dummy = Math.random(); // So it can't be compile-time initialized. |
| 403 | } |
| 404 | |
| 405 | private static class TestForInitFail { |
| 406 | public static int dummy = ((int)Math.random())/0; // So it throws when initializing. |
| 407 | } |
| Andreas Gampe | 8b07e47 | 2017-01-06 14:20:39 -0800 | [diff] [blame] | 408 | |
| 409 | public static interface InfA { |
| 410 | } |
| 411 | public static interface InfB extends InfA { |
| 412 | } |
| 413 | public static interface InfC extends InfB { |
| 414 | } |
| 415 | |
| 416 | public abstract static class ClassA implements InfA { |
| 417 | } |
| 418 | public abstract static class ClassB extends ClassA implements InfB { |
| 419 | } |
| 420 | public abstract static class ClassC implements InfA, InfC { |
| 421 | } |
| Andreas Gampe | 70f1639 | 2017-01-16 14:20:10 -0800 | [diff] [blame] | 422 | |
| Andreas Gampe | e2744c6 | 2017-02-08 16:28:59 +0000 | [diff] [blame] | 423 | public static class ClassD { |
| 424 | static int x = 1; |
| 425 | } |
| 426 | |
| Andreas Gampe | 691051b | 2017-02-09 09:15:24 -0800 | [diff] [blame] | 427 | public static class ClassE { |
| 428 | public void foo() { |
| 429 | } |
| 430 | public void bar() { |
| 431 | } |
| 432 | } |
| 433 | |
| Andreas Gampe | a67354b | 2017-02-10 16:18:30 -0800 | [diff] [blame^] | 434 | public static class ClassF { |
| 435 | public static Object STATIC = null; |
| 436 | } |
| 437 | |
| Andreas Gampe | 70f1639 | 2017-01-16 14:20:10 -0800 | [diff] [blame] | 438 | private static final String DEX1 = System.getenv("DEX_LOCATION") + "/912-classes.jar"; |
| 439 | private static final String DEX2 = System.getenv("DEX_LOCATION") + "/912-classes-ex.jar"; |
| 440 | |
| 441 | private static ClassLoader create(ClassLoader parent, String... elements) throws Exception { |
| 442 | // Note: We use a PathClassLoader, as we do not care about code performance. We only load |
| 443 | // the classes, and they're empty. |
| 444 | Class<?> pathClassLoaderClass = Class.forName("dalvik.system.PathClassLoader"); |
| 445 | Constructor<?> pathClassLoaderInit = pathClassLoaderClass.getConstructor(String.class, |
| 446 | ClassLoader.class); |
| 447 | String path = String.join(":", elements); |
| 448 | return (ClassLoader) pathClassLoaderInit.newInstance(path, parent); |
| 449 | } |
| 450 | |
| 451 | private static class ClassNameComparator implements Comparator<Class<?>> { |
| 452 | public int compare(Class<?> c1, Class<?> c2) { |
| 453 | return c1.getName().compareTo(c2.getName()); |
| 454 | } |
| 455 | } |
| Andreas Gampe | e492ae3 | 2016-10-28 19:34:57 -0700 | [diff] [blame] | 456 | } |