1*795d594fSAndroid Build Coastguard Worker /* 2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2014 The Android Open Source Project 3*795d594fSAndroid Build Coastguard Worker * 4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*795d594fSAndroid Build Coastguard Worker * 8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*795d594fSAndroid Build Coastguard Worker * 10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*795d594fSAndroid Build Coastguard Worker * limitations under the License. 15*795d594fSAndroid Build Coastguard Worker */ 16*795d594fSAndroid Build Coastguard Worker 17*795d594fSAndroid Build Coastguard Worker import java.lang.reflect.InvocationTargetException; 18*795d594fSAndroid Build Coastguard Worker import java.lang.reflect.Method; 19*795d594fSAndroid Build Coastguard Worker 20*795d594fSAndroid Build Coastguard Worker public class Main { main(String[] args)21*795d594fSAndroid Build Coastguard Worker public static void main(String[] args) throws Exception { 22*795d594fSAndroid Build Coastguard Worker System.loadLibrary(args[0]); 23*795d594fSAndroid Build Coastguard Worker boolean hasImage = hasImage(); 24*795d594fSAndroid Build Coastguard Worker String instructionSet = VMRuntime.getCurrentInstructionSet(); 25*795d594fSAndroid Build Coastguard Worker boolean isBootClassPathOnDisk = VMRuntime.isBootClassPathOnDisk(instructionSet); 26*795d594fSAndroid Build Coastguard Worker System.out.println( 27*795d594fSAndroid Build Coastguard Worker "Has image is " + hasImage + ", is image dex2oat enabled is " 28*795d594fSAndroid Build Coastguard Worker + isImageDex2OatEnabled() + ", is BOOTCLASSPATH on disk is " 29*795d594fSAndroid Build Coastguard Worker + isBootClassPathOnDisk + "."); 30*795d594fSAndroid Build Coastguard Worker 31*795d594fSAndroid Build Coastguard Worker if (hasImage && !isImageDex2OatEnabled()) { 32*795d594fSAndroid Build Coastguard Worker throw new Error("Image with dex2oat disabled runs with an oat file"); 33*795d594fSAndroid Build Coastguard Worker } else if (!hasImage && isImageDex2OatEnabled()) { 34*795d594fSAndroid Build Coastguard Worker throw new Error("Image with dex2oat enabled runs without an oat file"); 35*795d594fSAndroid Build Coastguard Worker } 36*795d594fSAndroid Build Coastguard Worker if (hasImage && !isBootClassPathOnDisk) { 37*795d594fSAndroid Build Coastguard Worker throw new Error("Image with dex2oat disabled runs with an image file"); 38*795d594fSAndroid Build Coastguard Worker } else if (!hasImage && isBootClassPathOnDisk) { 39*795d594fSAndroid Build Coastguard Worker throw new Error("Image with dex2oat enabled runs without an image file"); 40*795d594fSAndroid Build Coastguard Worker } 41*795d594fSAndroid Build Coastguard Worker 42*795d594fSAndroid Build Coastguard Worker testB18485243(); 43*795d594fSAndroid Build Coastguard Worker } 44*795d594fSAndroid Build Coastguard Worker hasImage()45*795d594fSAndroid Build Coastguard Worker private native static boolean hasImage(); 46*795d594fSAndroid Build Coastguard Worker isImageDex2OatEnabled()47*795d594fSAndroid Build Coastguard Worker private native static boolean isImageDex2OatEnabled(); 48*795d594fSAndroid Build Coastguard Worker 49*795d594fSAndroid Build Coastguard Worker private static class VMRuntime { 50*795d594fSAndroid Build Coastguard Worker private static final Method getCurrentInstructionSetMethod; 51*795d594fSAndroid Build Coastguard Worker private static final Method isBootClassPathOnDiskMethod; 52*795d594fSAndroid Build Coastguard Worker static { 53*795d594fSAndroid Build Coastguard Worker try { 54*795d594fSAndroid Build Coastguard Worker Class<?> c = Class.forName("dalvik.system.VMRuntime"); 55*795d594fSAndroid Build Coastguard Worker getCurrentInstructionSetMethod = c.getDeclaredMethod("getCurrentInstructionSet"); 56*795d594fSAndroid Build Coastguard Worker isBootClassPathOnDiskMethod = 57*795d594fSAndroid Build Coastguard Worker c.getDeclaredMethod("isBootClassPathOnDisk", String.class); 58*795d594fSAndroid Build Coastguard Worker } catch (Exception e) { 59*795d594fSAndroid Build Coastguard Worker throw new RuntimeException(e); 60*795d594fSAndroid Build Coastguard Worker } 61*795d594fSAndroid Build Coastguard Worker } 62*795d594fSAndroid Build Coastguard Worker getCurrentInstructionSet()63*795d594fSAndroid Build Coastguard Worker public static String getCurrentInstructionSet() throws Exception { 64*795d594fSAndroid Build Coastguard Worker return (String) getCurrentInstructionSetMethod.invoke(null); 65*795d594fSAndroid Build Coastguard Worker } isBootClassPathOnDisk(String instructionSet)66*795d594fSAndroid Build Coastguard Worker public static boolean isBootClassPathOnDisk(String instructionSet) throws Exception { 67*795d594fSAndroid Build Coastguard Worker return (boolean) isBootClassPathOnDiskMethod.invoke(null, instructionSet); 68*795d594fSAndroid Build Coastguard Worker } 69*795d594fSAndroid Build Coastguard Worker } 70*795d594fSAndroid Build Coastguard Worker testB18485243()71*795d594fSAndroid Build Coastguard Worker private static void testB18485243() throws Exception { 72*795d594fSAndroid Build Coastguard Worker Class<?> k = Class.forName("B18485243"); 73*795d594fSAndroid Build Coastguard Worker Object o = k.newInstance(); 74*795d594fSAndroid Build Coastguard Worker Method m = k.getDeclaredMethod("run"); 75*795d594fSAndroid Build Coastguard Worker try { 76*795d594fSAndroid Build Coastguard Worker m.invoke(o); 77*795d594fSAndroid Build Coastguard Worker } catch (InvocationTargetException e) { 78*795d594fSAndroid Build Coastguard Worker Throwable actual = e.getTargetException(); 79*795d594fSAndroid Build Coastguard Worker if (!(actual instanceof IncompatibleClassChangeError)) { 80*795d594fSAndroid Build Coastguard Worker throw new AssertionError("Expected IncompatibleClassChangeError", actual); 81*795d594fSAndroid Build Coastguard Worker } 82*795d594fSAndroid Build Coastguard Worker } 83*795d594fSAndroid Build Coastguard Worker System.out.println("testB18485243 PASS"); 84*795d594fSAndroid Build Coastguard Worker } 85*795d594fSAndroid Build Coastguard Worker } 86