Alex Light | 64ad14d | 2014-08-19 14:23:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | |
Brian Carlstrom | be6fa5e | 2014-12-09 20:15:42 -0800 | [diff] [blame] | 17 | import java.lang.reflect.InvocationTargetException; |
Brian Carlstrom | 31d8f52 | 2014-09-29 11:22:54 -0700 | [diff] [blame] | 18 | import java.lang.reflect.Method; |
| 19 | |
Alex Light | 64ad14d | 2014-08-19 14:23:13 -0700 | [diff] [blame] | 20 | public class Main { |
Brian Carlstrom | 31d8f52 | 2014-09-29 11:22:54 -0700 | [diff] [blame] | 21 | public static void main(String[] args) throws Exception { |
Alex Light | 64ad14d | 2014-08-19 14:23:13 -0700 | [diff] [blame] | 22 | boolean hasImage = hasImage(); |
Brian Carlstrom | 31d8f52 | 2014-09-29 11:22:54 -0700 | [diff] [blame] | 23 | String instructionSet = VMRuntime.getCurrentInstructionSet(); |
| 24 | boolean isBootClassPathOnDisk = VMRuntime.isBootClassPathOnDisk(instructionSet); |
Alex Light | 64ad14d | 2014-08-19 14:23:13 -0700 | [diff] [blame] | 25 | System.out.println( |
| 26 | "Has image is " + hasImage + ", is image dex2oat enabled is " |
Brian Carlstrom | 31d8f52 | 2014-09-29 11:22:54 -0700 | [diff] [blame] | 27 | + isImageDex2OatEnabled() + ", is BOOTCLASSPATH on disk is " |
| 28 | + isBootClassPathOnDisk + "."); |
Alex Light | 64ad14d | 2014-08-19 14:23:13 -0700 | [diff] [blame] | 29 | |
| 30 | if (hasImage && !isImageDex2OatEnabled()) { |
| 31 | throw new Error("Image with dex2oat disabled runs with an oat file"); |
| 32 | } else if (!hasImage && isImageDex2OatEnabled()) { |
| 33 | throw new Error("Image with dex2oat enabled runs without an oat file"); |
| 34 | } |
Brian Carlstrom | 31d8f52 | 2014-09-29 11:22:54 -0700 | [diff] [blame] | 35 | if (hasImage && !isBootClassPathOnDisk) { |
| 36 | throw new Error("Image with dex2oat disabled runs with an image file"); |
| 37 | } else if (!hasImage && isBootClassPathOnDisk) { |
| 38 | throw new Error("Image with dex2oat enabled runs without an image file"); |
| 39 | } |
Brian Carlstrom | be6fa5e | 2014-12-09 20:15:42 -0800 | [diff] [blame] | 40 | |
| 41 | testB18485243(); |
Alex Light | 64ad14d | 2014-08-19 14:23:13 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | static { |
| 45 | System.loadLibrary("arttest"); |
| 46 | } |
| 47 | |
| 48 | private native static boolean hasImage(); |
| 49 | |
| 50 | private native static boolean isImageDex2OatEnabled(); |
Brian Carlstrom | 31d8f52 | 2014-09-29 11:22:54 -0700 | [diff] [blame] | 51 | |
| 52 | private static class VMRuntime { |
| 53 | private static final Method getCurrentInstructionSetMethod; |
| 54 | private static final Method isBootClassPathOnDiskMethod; |
| 55 | static { |
| 56 | try { |
| 57 | Class c = Class.forName("dalvik.system.VMRuntime"); |
| 58 | getCurrentInstructionSetMethod = c.getDeclaredMethod("getCurrentInstructionSet"); |
| 59 | isBootClassPathOnDiskMethod = c.getDeclaredMethod("isBootClassPathOnDisk", |
| 60 | String.class); |
| 61 | } catch (Exception e) { |
| 62 | throw new RuntimeException(e); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | public static String getCurrentInstructionSet() throws Exception { |
| 67 | return (String) getCurrentInstructionSetMethod.invoke(null); |
| 68 | } |
| 69 | public static boolean isBootClassPathOnDisk(String instructionSet) throws Exception { |
| 70 | return (boolean) isBootClassPathOnDiskMethod.invoke(null, instructionSet); |
| 71 | } |
| 72 | } |
Brian Carlstrom | be6fa5e | 2014-12-09 20:15:42 -0800 | [diff] [blame] | 73 | |
| 74 | private static void testB18485243() throws Exception { |
| 75 | Class<?> k = Class.forName("B18485243"); |
| 76 | Object o = k.newInstance(); |
| 77 | Method m = k.getDeclaredMethod("run"); |
| 78 | try { |
| 79 | m.invoke(o); |
| 80 | } catch (InvocationTargetException e) { |
| 81 | Throwable actual = e.getTargetException(); |
| 82 | if (!(actual instanceof IncompatibleClassChangeError)) { |
| 83 | throw new AssertionError("Expected IncompatibleClassChangeError", actual); |
| 84 | } |
| 85 | } |
| 86 | System.out.println("testB18485243 PASS"); |
| 87 | } |
Alex Light | 64ad14d | 2014-08-19 14:23:13 -0700 | [diff] [blame] | 88 | } |