Bug 732069 - Remove library extraction from APKOpen. r=glandium,blassey
authorWes Johnston <wjohnston@mozilla.com>
Thu, 08 Mar 2012 10:25:44 -0800
changeset 91438 3689bb4199d85060c1ecd481fe3e9c1dc5ac764e
parent 91437 32220d7085e049de7aa02e6f47793b0101a208d1
child 91439 d0c82cb6eb28a8a4e67b00817ef358d98ed6b960
push id783
push userlsblakk@mozilla.com
push dateTue, 24 Apr 2012 17:33:42 +0000
treeherdermozilla-beta@11faed19f136 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium, blassey
bugs732069
milestone13.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 732069 - Remove library extraction from APKOpen. r=glandium,blassey
mobile/android/base/GeckoAppShell.java
mozglue/android/APKOpen.cpp
other-licenses/android/dlfcn.c
--- a/mobile/android/base/GeckoAppShell.java
+++ b/mobile/android/base/GeckoAppShell.java
@@ -135,17 +135,17 @@ public class GeckoAppShell
     //    public static native void setSurfaceView(GeckoSurfaceView sv);
     public static native void setSoftwareLayerClient(GeckoSoftwareLayerClient client);
     public static native void putenv(String map);
     public static native void onResume();
     public static native void onLowMemory();
     public static native void callObserver(String observerKey, String topic, String data);
     public static native void removeObserver(String observerKey);
     public static native void loadGeckoLibsNative(String apkName);
-    public static native void loadSQLiteLibsNative(String apkName, boolean shouldExtract);
+    public static native void loadSQLiteLibsNative(String apkName);
     public static native void onChangeNetworkLinkStatus(String status);
 
     public static void reportJavaCrash(Throwable e) {
         Log.e(LOGTAG, "top level exception", e);
         StringWriter sw = new StringWriter();
         PrintWriter pw = new PrintWriter(sw);
         e.printStackTrace(pw);
         pw.flush();
@@ -251,25 +251,16 @@ public class GeckoAppShell
 
         // The package data lib directory isn't placed in ld.so's
         // search path, so we have to manually load libraries that
         // libxul will depend on.  Not ideal.
         GeckoProfile profile = GeckoProfile.get(context);
 
         File cacheFile = getCacheDir(context);
         putenv("GRE_HOME=" + getGREDir(context).getPath());
-        File[] files = cacheFile.listFiles();
-        if (files != null) {
-            Iterator<File> cacheFiles = Arrays.asList(files).iterator();
-            while (cacheFiles.hasNext()) {
-                File libFile = cacheFiles.next();
-                if (libFile.getName().endsWith(".so"))
-                    libFile.delete();
-            }
-        }
 
         // setup the libs cache
         String linkerCache = System.getenv("MOZ_LINKER_CACHE");
         if (System.getenv("MOZ_LINKER_CACHE") == null) {
             GeckoAppShell.putenv("MOZ_LINKER_CACHE=" + cacheFile.getPath());
         }
         sLibsSetup = true;
     }
@@ -351,17 +342,18 @@ public class GeckoAppShell
     public static void loadSQLiteLibs(Context context, String apkName) {
         if (sSQLiteLibsLoaded)
             return;
         synchronized(sSQLiteLibsLoaded) {
             if (sSQLiteLibsLoaded)
                 return;
             loadMozGlue();
             // the extract libs parameter is being removed in bug 732069
-            loadSQLiteLibsNative(apkName, false);
+            loadLibsSetup(context);
+            loadSQLiteLibsNative(apkName);
             sSQLiteLibsLoaded = true;
         }
     }
 
     public static void loadMozGlue() {
         System.loadLibrary("mozglue");
     }
 
--- a/mozglue/android/APKOpen.cpp
+++ b/mozglue/android/APKOpen.cpp
@@ -308,89 +308,16 @@ SHELL_WRAPPER3(notifySmsDeleted, jboolea
 SHELL_WRAPPER3(notifySmsDeleteFailed, jint, jint, jlong)
 SHELL_WRAPPER2(notifyNoMessageInList, jint, jlong)
 SHELL_WRAPPER8(notifyListCreated, jint, jint, jstring, jstring, jstring, jlong, jint, jlong)
 SHELL_WRAPPER7(notifyGotNextMessage, jint, jstring, jstring, jstring, jlong, jint, jlong)
 SHELL_WRAPPER3(notifyReadingMessageListFailed, jint, jint, jlong)
 
 static void * xul_handle = NULL;
 static void * sqlite_handle = NULL;
-#ifdef MOZ_OLD_LINKER
-static time_t apk_mtime = 0;
-#ifdef DEBUG
-extern "C" int extractLibs = 1;
-#else
-extern "C" int extractLibs = 0;
-#endif
-
-static void
-extractFile(const char * path, Zip::Stream &s)
-{
-  uint32_t size = s.GetUncompressedSize();
-
-  struct stat status;
-  if (!stat(path, &status) &&
-      status.st_size == size &&
-      apk_mtime < status.st_mtime)
-    return;
-
-  int fd = open(path, O_CREAT | O_NOATIME | O_TRUNC | O_RDWR, S_IRWXU);
-  if (fd == -1) {
-    __android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Couldn't open %s to decompress library", path);
-    return;
-  }
-
-  if (ftruncate(fd, size) == -1) {
-    __android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Couldn't ftruncate %s to decompress library", path);
-    close(fd);
-    return;
-  }
-
-  void * buf = mmap(NULL, size, PROT_READ | PROT_WRITE,
-                    MAP_SHARED, fd, 0);
-  if (buf == (void *)-1) {
-    __android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Couldn't mmap decompression buffer");
-    close(fd);
-    return;
-  }
-
-  z_stream strm = {
-    next_in: (Bytef *)s.GetBuffer(),
-    avail_in: s.GetSize(),
-    total_in: 0,
-
-    next_out: (Bytef *)buf,
-    avail_out: size,
-    total_out: 0
-  };
-
-  int ret;
-  ret = inflateInit2(&strm, -MAX_WBITS);
-  if (ret != Z_OK)
-    __android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "inflateInit failed: %s", strm.msg);
-
-  if (inflate(&strm, Z_FINISH) != Z_STREAM_END)
-    __android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "inflate failed: %s", strm.msg);
-
-  if (strm.total_out != size)
-    __android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "extracted %d, expected %d!", strm.total_out, size);
-
-  ret = inflateEnd(&strm);
-  if (ret != Z_OK)
-    __android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "inflateEnd failed: %s", strm.msg);
-
-  close(fd);
-#ifdef ANDROID_ARM_LINKER
-  /* We just extracted data that is going to be executed in the future.
-   * We thus need to ensure Instruction and Data cache coherency. */
-  cacheflush((unsigned) buf, (unsigned) buf + size, 0);
-#endif
-  munmap(buf, size);
-}
-#endif
 
 #if defined(MOZ_CRASHREPORTER) || defined(MOZ_OLD_LINKER)
 static void
 extractLib(Zip::Stream &s, void * dest)
 {
   z_stream strm = {
     next_in: (Bytef *)s.GetBuffer(),
     avail_in: s.GetSize(),
@@ -505,35 +432,16 @@ static void * mozload(const char * path,
   gettimeofday(&t0, 0);
 #endif
 
   void *handle;
   Zip::Stream s;
   if (!zip->GetStream(path, &s))
     return NULL;
 
-  if (extractLibs) {
-    char fullpath[PATH_MAX];
-    snprintf(fullpath, PATH_MAX, "%s/%s", getenv("MOZ_LINKER_CACHE"), path);
-    __android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "resolved %s to %s", path, fullpath);
-    extractFile(fullpath, s);
-    handle = __wrap_dlopen(fullpath, RTLD_LAZY);
-    if (!handle)
-      __android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Couldn't load %s because %s", fullpath, __wrap_dlerror());
-#ifdef DEBUG
-    gettimeofday(&t1, 0);
-    __android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "%s: spent %d", path,
-                        (((long long)t1.tv_sec * 1000000LL) +
-                          (long long)t1.tv_usec) -
-                        (((long long)t0.tv_sec * 1000000LL) +
-                          (long long)t0.tv_usec));
-#endif
-    return handle;
-  }
-
   bool skipLibCache = false;
   int fd;
   void * buf = NULL;
   uint32_t lib_size = s.GetUncompressedSize();
   int cache_fd = 0;
   if (s.GetType() == Zip::Stream::DEFLATE) {
     cache_fd = lookupLibCacheFd(path);
     fd = cache_fd;
@@ -641,22 +549,16 @@ report_mapping(char *name, void *base, u
 extern "C" void simple_linker_init(void);
 #endif
 
 static void
 loadGeckoLibs(const char *apkName)
 {
   chdir(getenv("GRE_HOME"));
 
-#ifdef MOZ_OLD_LINKER
-  struct stat status;
-  if (!stat(apkName, &status))
-    apk_mtime = status.st_mtime;
-#endif
-
   struct timeval t0, t1;
   gettimeofday(&t0, 0);
   struct rusage usage1;
   getrusage(RUSAGE_THREAD, &usage1);
   
   RefPtr<Zip> zip = new Zip(apkName);
 
 #ifdef MOZ_CRASHREPORTER
@@ -741,20 +643,16 @@ loadGeckoLibs(const char *apkName)
 }
 
 static void loadSQLiteLibs(const char *apkName)
 {
   chdir(getenv("GRE_HOME"));
 
 #ifdef MOZ_OLD_LINKER
   simple_linker_init();
-
-  struct stat status;
-  if (!stat(apkName, &status))
-    apk_mtime = status.st_mtime;
 #endif
 
   RefPtr<Zip> zip = new Zip(apkName);
   lib_mapping = (struct mapping_info *)calloc(MAX_MAPPING_INFO, sizeof(*lib_mapping));
 
 #ifdef MOZ_CRASHREPORTER
   file_ids = (char *)extractBuf("lib.id", zip);
 #endif
@@ -792,24 +690,17 @@ Java_org_mozilla_gecko_GeckoAppShell_loa
     return;
 
   loadGeckoLibs(str);
   jenv->ReleaseStringUTFChars(jApkName, str);
 }
 
 extern "C" NS_EXPORT void JNICALL
 Java_org_mozilla_gecko_GeckoAppShell_loadSQLiteLibsNative(JNIEnv *jenv, jclass jGeckoAppShellClass, jstring jApkName, jboolean jShouldExtract) {
-  if (jShouldExtract) {
-#ifdef MOZ_OLD_LINKER
-    extractLibs = 1;
-#else
-    putenv("MOZ_LINKER_EXTRACT=1");
-#endif
-  }
-
+  putenv("MOZ_LINKER_EXTRACT=1");
   const char* str;
   // XXX: java doesn't give us true UTF8, we should figure out something
   // better to do here
   str = jenv->GetStringUTFChars(jApkName, NULL);
   if (str == NULL)
     return;
 
   loadSQLiteLibs(str);
--- a/other-licenses/android/dlfcn.c
+++ b/other-licenses/android/dlfcn.c
@@ -38,30 +38,26 @@ static const char *dl_errors[] = {
     [DL_ERR_SYMBOL_NOT_FOUND] = "Symbol not found",
     [DL_ERR_SYMBOL_NOT_GLOBAL] = "Symbol is not global",
 };
 
 #define likely(expr)   __builtin_expect (expr, 1)
 #define unlikely(expr) __builtin_expect (expr, 0)
 
 static pthread_mutex_t dl_lock = PTHREAD_MUTEX_INITIALIZER;
-extern int extractLibs;
 
 static void set_dlerror(int err)
 {
     format_buffer(dl_err_buf, sizeof(dl_err_buf), "%s: %s", dl_errors[err],
              linker_get_error());
     dl_err_str = (const char *)&dl_err_buf[0];
 }
 
 void *__wrap_dlopen(const char *filename, int flag)
 {
-    if (extractLibs)
-        return dlopen(filename, flag);
-
     soinfo *ret;
 
     pthread_mutex_lock(&dl_lock);
     ret = find_library(filename);
     if (unlikely(ret == NULL)) {
         set_dlerror(DL_ERR_CANNOT_LOAD_LIBRARY);
     } else {
         ret->refcount++;
@@ -83,29 +79,23 @@ void *moz_mapped_dlopen(const char *file
         ret->refcount++;
     }
     pthread_mutex_unlock(&dl_lock);
     return ret;
 }
 
 const char *__wrap_dlerror(void)
 {
-    if (extractLibs)
-        return dlerror();
-
     const char *tmp = dl_err_str;
     dl_err_str = NULL;
     return (const char *)tmp;
 }
 
 void *__wrap_dlsym(void *handle, const char *symbol)
 {
-    if (extractLibs)
-        return dlsym(handle, symbol);
-
     soinfo *found;
     Elf32_Sym *sym;
     unsigned bind;
 
     pthread_mutex_lock(&dl_lock);
 
     if(unlikely(handle == 0)) { 
         set_dlerror(DL_ERR_INVALID_LIBRARY_HANDLE);
@@ -178,19 +168,16 @@ int __wrap_dladdr(void *addr, Dl_info *i
 
     pthread_mutex_unlock(&dl_lock);
 
     return ret;
 }
 
 int __wrap_dlclose(void *handle)
 {
-    if (extractLibs)
-        return dlclose(handle);
-
     pthread_mutex_lock(&dl_lock);
     (void)unload_library((soinfo*)handle);
     pthread_mutex_unlock(&dl_lock);
     return 0;
 }
 
 #if defined(ANDROID_ARM_LINKER)
 //                     0000000 00011111 111112 22222222 2333333 333344444444445555555