Add VMRuntime.isBootClassPathOnDisk
Bug: 17679443
(cherry picked from commit 95a935415d44903b28326424beb4db5c013ef089)
Change-Id: Iba40291dead3f0b6715903c986370fd0cf1e41e1
diff --git a/test/118-noimage-dex2oat/src/Main.java b/test/118-noimage-dex2oat/src/Main.java
index 11c736a..c83b84d 100644
--- a/test/118-noimage-dex2oat/src/Main.java
+++ b/test/118-noimage-dex2oat/src/Main.java
@@ -14,18 +14,28 @@
* limitations under the License.
*/
+import java.lang.reflect.Method;
+
public class Main {
- public static void main(String[] args) {
+ public static void main(String[] args) throws Exception {
boolean hasImage = hasImage();
+ String instructionSet = VMRuntime.getCurrentInstructionSet();
+ boolean isBootClassPathOnDisk = VMRuntime.isBootClassPathOnDisk(instructionSet);
System.out.println(
"Has image is " + hasImage + ", is image dex2oat enabled is "
- + isImageDex2OatEnabled() + ".");
+ + isImageDex2OatEnabled() + ", is BOOTCLASSPATH on disk is "
+ + isBootClassPathOnDisk + ".");
if (hasImage && !isImageDex2OatEnabled()) {
throw new Error("Image with dex2oat disabled runs with an oat file");
} else if (!hasImage && isImageDex2OatEnabled()) {
throw new Error("Image with dex2oat enabled runs without an oat file");
}
+ if (hasImage && !isBootClassPathOnDisk) {
+ throw new Error("Image with dex2oat disabled runs with an image file");
+ } else if (!hasImage && isBootClassPathOnDisk) {
+ throw new Error("Image with dex2oat enabled runs without an image file");
+ }
}
static {
@@ -35,4 +45,26 @@
private native static boolean hasImage();
private native static boolean isImageDex2OatEnabled();
+
+ private static class VMRuntime {
+ private static final Method getCurrentInstructionSetMethod;
+ private static final Method isBootClassPathOnDiskMethod;
+ static {
+ try {
+ Class c = Class.forName("dalvik.system.VMRuntime");
+ getCurrentInstructionSetMethod = c.getDeclaredMethod("getCurrentInstructionSet");
+ isBootClassPathOnDiskMethod = c.getDeclaredMethod("isBootClassPathOnDisk",
+ String.class);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static String getCurrentInstructionSet() throws Exception {
+ return (String) getCurrentInstructionSetMethod.invoke(null);
+ }
+ public static boolean isBootClassPathOnDisk(String instructionSet) throws Exception {
+ return (boolean) isBootClassPathOnDiskMethod.invoke(null, instructionSet);
+ }
+ }
}