Back out bf4b1d3c624e (bug 732069) on suspicion of causing increased failure to start the browser during tests

This commit is contained in:
Phil Ringnalda 2012-03-17 12:32:44 -07:00
Родитель 9b15a69d3e
Коммит 6454be7a84
4 изменённых файлов: 155 добавлений и 12 удалений

Просмотреть файл

@ -114,8 +114,8 @@ public class GeckoAppShell
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);
public static native void loadNSSLibsNative(String apkName);
public static native void loadSQLiteLibsNative(String apkName, boolean shouldExtract);
public static native void loadNSSLibsNative(String apkName, boolean shouldExtract);
public static native void onChangeNetworkLinkStatus(String status);
public static native void reportJavaCrash(String stack);
@ -398,8 +398,8 @@ public class GeckoAppShell
}
}
}
loadSQLiteLibsNative(apkName);
loadNSSLibsNative(apkName);
loadSQLiteLibsNative(apkName, extractLibs);
loadNSSLibsNative(apkName, extractLibs);
loadGeckoLibsNative(apkName);
}

Просмотреть файл

@ -150,8 +150,8 @@ public class GeckoAppShell
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);
public static native void loadNSSLibsNative(String apkName);
public static native void loadSQLiteLibsNative(String apkName, boolean shouldExtract);
public static native void loadNSSLibsNative(String apkName, boolean shouldExtract);
public static native void onChangeNetworkLinkStatus(String status);
public static void registerGlobalExceptionHandler() {
@ -278,6 +278,15 @@ public class GeckoAppShell
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");
@ -370,7 +379,7 @@ public class GeckoAppShell
loadMozGlue();
// the extract libs parameter is being removed in bug 732069
loadLibsSetup(context);
loadSQLiteLibsNative(apkName);
loadSQLiteLibsNative(apkName, false);
sSQLiteLibsLoaded = true;
}
}
@ -383,7 +392,7 @@ public class GeckoAppShell
return;
loadMozGlue();
loadLibsSetup(context);
loadNSSLibsNative(apkName);
loadNSSLibsNative(apkName, false);
sNSSLibsLoaded = true;
}
}

Просмотреть файл

@ -357,6 +357,80 @@ static void * nspr_handle = NULL;
static void * plc_handle = NULL;
static bool simple_linker_initialized = false;
#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)
@ -480,6 +554,25 @@ static void * mozload(const char * path, Zip *zip)
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;
@ -597,6 +690,12 @@ 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;
@ -690,6 +789,10 @@ static int loadSQLiteLibs(const char *apkName)
simple_linker_init();
simple_linker_initialized = true;
}
struct stat status;
if (!stat(apkName, &status))
apk_mtime = status.st_mtime;
#endif
RefPtr<Zip> zip = new Zip(apkName);
@ -736,6 +839,10 @@ loadNSSLibs(const char *apkName)
simple_linker_init();
simple_linker_initialized = true;
}
struct stat status;
if (!stat(apkName, &status))
apk_mtime = status.st_mtime;
#endif
RefPtr<Zip> zip = new Zip(apkName);
@ -818,8 +925,15 @@ Java_org_mozilla_gecko_GeckoAppShell_loadGeckoLibsNative(JNIEnv *jenv, jclass jG
}
extern "C" NS_EXPORT void JNICALL
Java_org_mozilla_gecko_GeckoAppShell_loadSQLiteLibsNative(JNIEnv *jenv, jclass jGeckoAppShellClass, jstring jApkName) {
putenv("MOZ_LINKER_EXTRACT=1");
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
}
const char* str;
// XXX: java doesn't give us true UTF8, we should figure out something
// better to do here
@ -837,8 +951,15 @@ Java_org_mozilla_gecko_GeckoAppShell_loadSQLiteLibsNative(JNIEnv *jenv, jclass j
}
extern "C" NS_EXPORT void JNICALL
Java_org_mozilla_gecko_GeckoAppShell_loadNSSLibsNative(JNIEnv *jenv, jclass jGeckoAppShellClass, jstring jApkName) {
putenv("MOZ_LINKER_EXTRACT=1");
Java_org_mozilla_gecko_GeckoAppShell_loadNSSLibsNative(JNIEnv *jenv, jclass jGeckoAppShellClass, jstring jApkName, jboolean jShouldExtract) {
if (jShouldExtract) {
#ifdef MOZ_OLD_LINKER
extractLibs = 1;
#else
putenv("MOZ_LINKER_EXTRACT=1");
#endif
}
const char* str;
// XXX: java doesn't give us true UTF8, we should figure out something
// better to do here

Просмотреть файл

@ -43,6 +43,7 @@ static const char *dl_errors[] = {
#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)
{
@ -53,6 +54,9 @@ static void set_dlerror(int err)
void *__wrap_dlopen(const char *filename, int flag)
{
if (extractLibs)
return dlopen(filename, flag);
soinfo *ret;
pthread_mutex_lock(&dl_lock);
@ -84,6 +88,9 @@ void *moz_mapped_dlopen(const char *filename, int flag,
const char *__wrap_dlerror(void)
{
if (extractLibs)
return dlerror();
const char *tmp = dl_err_str;
dl_err_str = NULL;
return (const char *)tmp;
@ -91,6 +98,9 @@ const char *__wrap_dlerror(void)
void *__wrap_dlsym(void *handle, const char *symbol)
{
if (extractLibs)
return dlsym(handle, symbol);
soinfo *found;
Elf32_Sym *sym;
unsigned bind;
@ -173,6 +183,9 @@ int __wrap_dladdr(void *addr, Dl_info *info)
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);