Bug 1174725 - Fix GeckoLoader synchronization; r=snorp
authorJim Chen <nchen@mozilla.com>
Tue, 16 Jun 2015 19:45:29 -0400
changeset 280046 8c88a4ed79db4baf370f12f4cbc4f2e3aa8e7516
parent 280045 11f5871b0a22b7bab919f8565a2a7091eebd80ff
child 280047 291f44d1891d97f1c8263718f70980655cd4f5b8
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1174725
milestone41.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 1174725 - Fix GeckoLoader synchronization; r=snorp
mobile/android/base/mozglue/GeckoLoader.java
--- a/mobile/android/base/mozglue/GeckoLoader.java
+++ b/mobile/android/base/mozglue/GeckoLoader.java
@@ -26,22 +26,20 @@ import org.mozilla.gecko.mozglue.Context
 
 public final class GeckoLoader {
     private static final String LOGTAG = "GeckoLoader";
 
     private static volatile SafeIntent sIntent;
     private static File sCacheFile;
     private static File sGREDir;
 
-    private static final Object sLibLoadingLock = new Object();
-    // Must hold sLibLoadingLock while accessing the following boolean variables.
+    /* Synchronized on GeckoLoader.class. */
     private static boolean sSQLiteLibsLoaded;
     private static boolean sNSSLibsLoaded;
     private static boolean sMozGlueLoaded;
-    private static boolean sLibsSetup;
 
     private GeckoLoader() {
         // prevent instantiation
     }
 
     public static File getCacheDir(Context context) {
         if (sCacheFile == null) {
             sCacheFile = context.getCacheDir();
@@ -187,24 +185,17 @@ public final class GeckoLoader {
         }
 
         setupLocaleEnvironment();
 
         // We don't need this any more.
         sIntent = null;
     }
 
-    private static void loadLibsSetup(Context context) {
-        synchronized (sLibLoadingLock) {
-            if (sLibsSetup) {
-                return;
-            }
-            sLibsSetup = true;
-        }
-
+    private static void loadLibsSetupLocked(Context context) {
         // 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.
 
         File cacheFile = getCacheDir(context);
         putenv("GRE_HOME=" + getGREDir(context).getPath());
 
         // setup the libs cache
@@ -232,40 +223,36 @@ public final class GeckoLoader {
                 cacheDir.setWritable(true, false);
                 cacheDir.setExecutable(true, false);
                 cacheDir.setReadable(true, false);
             }
         }
     }
 
     @RobocopTarget
-    public static void loadSQLiteLibs(final Context context, final String apkName) {
-        synchronized (sLibLoadingLock) {
-            if (sSQLiteLibsLoaded) {
-                return;
-            }
-            sSQLiteLibsLoaded = true;
+    public synchronized static void loadSQLiteLibs(final Context context, final String apkName) {
+        if (sSQLiteLibsLoaded) {
+            return;
         }
 
         loadMozGlue(context);
-        loadLibsSetup(context);
+        loadLibsSetupLocked(context);
         loadSQLiteLibsNative(apkName);
+        sSQLiteLibsLoaded = true;
     }
 
-    public static void loadNSSLibs(final Context context, final String apkName) {
-        synchronized (sLibLoadingLock) {
-            if (sNSSLibsLoaded) {
-                return;
-            }
-            sNSSLibsLoaded = true;
+    public synchronized static void loadNSSLibs(final Context context, final String apkName) {
+        if (sNSSLibsLoaded) {
+            return;
         }
 
         loadMozGlue(context);
-        loadLibsSetup(context);
+        loadLibsSetupLocked(context);
         loadNSSLibsNative(apkName);
+        sNSSLibsLoaded = true;
     }
 
     @SuppressWarnings("deprecation")
     private static final String getCPUABI() {
         return android.os.Build.CPU_ABI;
     }
 
     /**
@@ -504,29 +491,27 @@ public final class GeckoLoader {
         final String message = getLoadDiagnostics(context, lib);
         Log.e(LOGTAG, "Load diagnostics: " + message);
 
         // Throw the descriptive message, using the original library load
         // failure as the cause.
         throw new RuntimeException(message, e);
     }
 
-    public static void loadMozGlue(final Context context) {
-        synchronized (sLibLoadingLock) {
-            if (sMozGlueLoaded) {
-                return;
-            }
-            sMozGlueLoaded = true;
+    public synchronized static void loadMozGlue(final Context context) {
+        if (sMozGlueLoaded) {
+            return;
         }
 
         doLoadLibrary(context, "mozglue");
+        sMozGlueLoaded = true;
     }
 
-    public static void loadGeckoLibs(final Context context, final String apkName) {
-        loadLibsSetup(context);
+    public synchronized static void loadGeckoLibs(final Context context, final String apkName) {
+        loadLibsSetupLocked(context);
         loadGeckoLibsNative(apkName);
     }
 
     private static void setupLocaleEnvironment() {
         putenv("LANG=" + Locale.getDefault().toString());
         NumberFormat nf = NumberFormat.getInstance();
         if (nf instanceof DecimalFormat) {
             DecimalFormat df = (DecimalFormat)nf;