From 8dd90ae77922eb05d46c797937620a4c69f758f7 Mon Sep 17 00:00:00 2001 From: Narayan Kamath Date: Fri, 9 Nov 2012 18:11:48 +0000 Subject: [PATCH 1/2] Lazy parsing of zip files for Java resources. Central directories of zip files should be read lazily. They are needed only to service calls to BaseDexClassLoader#findResouce(s). Most android processes don't use these methods since they use android resources. bug:6797061 Change-Id: I1a5b5d03572601707e1fb1fd4424c1ae2fd2217d --- .../main/java/dalvik/system/DexPathList.java | 58 +++++++++++++------ 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/dalvik/src/main/java/dalvik/system/DexPathList.java b/dalvik/src/main/java/dalvik/system/DexPathList.java index 12532238c..ba4bb1546 100644 --- a/dalvik/src/main/java/dalvik/system/DexPathList.java +++ b/dalvik/src/main/java/dalvik/system/DexPathList.java @@ -200,7 +200,7 @@ private static Element[] makeDexElements(ArrayList files, * up front. */ for (File file : files) { - ZipFile zip = null; + File zip = null; DexFile dex = null; String name = file.getName(); @@ -213,17 +213,7 @@ private static Element[] makeDexElements(ArrayList files, } } else if (name.endsWith(APK_SUFFIX) || name.endsWith(JAR_SUFFIX) || name.endsWith(ZIP_SUFFIX)) { - try { - zip = new ZipFile(file); - } catch (IOException ex) { - /* - * Note: ZipException (a subclass of IOException) - * might get thrown by the ZipFile constructor - * (e.g. if the file isn't actually a zip/jar - * file). - */ - System.logE("Unable to open zip file: " + file, ex); - } + zip = file; try { dex = loadDexFile(file, optimizedDirectory); @@ -385,23 +375,53 @@ public String findLibrary(String libraryName) { * Element of the dex/resource file path */ /*package*/ static class Element { - public final File file; - public final ZipFile zipFile; - public final DexFile dexFile; + private final File file; + private final File zip; + private final DexFile dexFile; - public Element(File file, ZipFile zipFile, DexFile dexFile) { + private ZipFile zipFile; + private boolean init; + + public Element(File file, File zip, DexFile dexFile) { this.file = file; - this.zipFile = zipFile; + this.zip = zip; this.dexFile = dexFile; } - public URL findResource(String name) { - if ((zipFile == null) || (zipFile.getEntry(name) == null)) { + public synchronized void maybeInit() { + if (init) { + return; + } + + init = true; + + if (zip == null) { /* * Either this element has no zip/jar file (first * clause), or the zip/jar file doesn't have an entry * for the given name (second clause). */ + return; + } + + try { + zipFile = new ZipFile(zip); + } catch (IOException ioe) { + /* + * Note: ZipException (a subclass of IOException) + * might get thrown by the ZipFile constructor + * (e.g. if the file isn't actually a zip/jar + * file). + */ + System.logE("Unable to open zip file: " + file, ioe); + zipFile = null; + } + } + + public URL findResource(String name) { + maybeInit(); + + if (zipFile == null || zipFile.getEntry(name) == null) { return null; } From d89df3c7f0f6223756aae8dc3123b7485e603924 Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Wed, 9 Jan 2013 23:43:49 -0800 Subject: [PATCH 2/2] Fix compilation of Enum on JDK 7 Change-Id: I2e58b6a527e4ef1fc7ed3359b8aea88d01a031fb --- luni/src/main/java/java/lang/Enum.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/luni/src/main/java/java/lang/Enum.java b/luni/src/main/java/java/lang/Enum.java index 7a0f514a2..7a20c866c 100644 --- a/luni/src/main/java/java/lang/Enum.java +++ b/luni/src/main/java/java/lang/Enum.java @@ -51,7 +51,7 @@ public abstract class Enum> implements Serializable, Comparabl private final String name; - private final int ordinal; + final int ordinal; /** * Constructor for constants of enum subtypes.