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