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 | 31d8f52 | 2014-09-29 11:22:54 -0700 | [diff] [blame^] | 17 | import java.lang.reflect.Method; |
| 18 | |
Alex Light | 64ad14d | 2014-08-19 14:23:13 -0700 | [diff] [blame] | 19 | public class Main { |
Brian Carlstrom | 31d8f52 | 2014-09-29 11:22:54 -0700 | [diff] [blame^] | 20 | public static void main(String[] args) throws Exception { |
Alex Light | 64ad14d | 2014-08-19 14:23:13 -0700 | [diff] [blame] | 21 | boolean hasImage = hasImage(); |
Brian Carlstrom | 31d8f52 | 2014-09-29 11:22:54 -0700 | [diff] [blame^] | 22 | String instructionSet = VMRuntime.getCurrentInstructionSet(); |
| 23 | boolean isBootClassPathOnDisk = VMRuntime.isBootClassPathOnDisk(instructionSet); |
Alex Light | 64ad14d | 2014-08-19 14:23:13 -0700 | [diff] [blame] | 24 | System.out.println( |
| 25 | "Has image is " + hasImage + ", is image dex2oat enabled is " |
Brian Carlstrom | 31d8f52 | 2014-09-29 11:22:54 -0700 | [diff] [blame^] | 26 | + isImageDex2OatEnabled() + ", is BOOTCLASSPATH on disk is " |
| 27 | + isBootClassPathOnDisk + "."); |
Alex Light | 64ad14d | 2014-08-19 14:23:13 -0700 | [diff] [blame] | 28 | |
| 29 | if (hasImage && !isImageDex2OatEnabled()) { |
| 30 | throw new Error("Image with dex2oat disabled runs with an oat file"); |
| 31 | } else if (!hasImage && isImageDex2OatEnabled()) { |
| 32 | throw new Error("Image with dex2oat enabled runs without an oat file"); |
| 33 | } |
Brian Carlstrom | 31d8f52 | 2014-09-29 11:22:54 -0700 | [diff] [blame^] | 34 | if (hasImage && !isBootClassPathOnDisk) { |
| 35 | throw new Error("Image with dex2oat disabled runs with an image file"); |
| 36 | } else if (!hasImage && isBootClassPathOnDisk) { |
| 37 | throw new Error("Image with dex2oat enabled runs without an image file"); |
| 38 | } |
Alex Light | 64ad14d | 2014-08-19 14:23:13 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | static { |
| 42 | System.loadLibrary("arttest"); |
| 43 | } |
| 44 | |
| 45 | private native static boolean hasImage(); |
| 46 | |
| 47 | private native static boolean isImageDex2OatEnabled(); |
Brian Carlstrom | 31d8f52 | 2014-09-29 11:22:54 -0700 | [diff] [blame^] | 48 | |
| 49 | private static class VMRuntime { |
| 50 | private static final Method getCurrentInstructionSetMethod; |
| 51 | private static final Method isBootClassPathOnDiskMethod; |
| 52 | static { |
| 53 | try { |
| 54 | Class c = Class.forName("dalvik.system.VMRuntime"); |
| 55 | getCurrentInstructionSetMethod = c.getDeclaredMethod("getCurrentInstructionSet"); |
| 56 | isBootClassPathOnDiskMethod = c.getDeclaredMethod("isBootClassPathOnDisk", |
| 57 | String.class); |
| 58 | } catch (Exception e) { |
| 59 | throw new RuntimeException(e); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | public static String getCurrentInstructionSet() throws Exception { |
| 64 | return (String) getCurrentInstructionSetMethod.invoke(null); |
| 65 | } |
| 66 | public static boolean isBootClassPathOnDisk(String instructionSet) throws Exception { |
| 67 | return (boolean) isBootClassPathOnDiskMethod.invoke(null, instructionSet); |
| 68 | } |
| 69 | } |
Alex Light | 64ad14d | 2014-08-19 14:23:13 -0700 | [diff] [blame] | 70 | } |