bug 627591: backout preload in preparation for better one.

This commit is contained in:
Taras Glek 2011-05-20 11:32:23 -07:00
Родитель 11c05d2886 21801c8ad8
Коммит 19f7736ffc
3 изменённых файлов: 1 добавлений и 71 удалений

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

@ -185,8 +185,7 @@ endif
ifeq ($(OS_ARCH),WINNT)
OS_LIBS += $(call EXPAND_LIBNAME,comctl32 comdlg32 uuid shell32 ole32 oleaut32 version winspool)
OS_LIBS += $(call EXPAND_LIBNAME,usp10 msimg32 delayimp)
LDFLAGS += -delayload:xul.dll -delayload:xpcom.dll -delayload:plc4.dll -delayload:nspr4.dll -delayload:mozalloc.dll
OS_LIBS += $(call EXPAND_LIBNAME,usp10 msimg32)
endif
ifeq ($(OS_ARCH),WINNT)

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

@ -56,7 +56,6 @@
#ifdef XP_WIN
// we want to use the DLL blocklist if possible
#define XRE_WANT_DLL_BLOCKLIST
#define XRE_PRELOAD_XUL
// we want a wmain entry point
#include "nsWindowsWMain.cpp"
#endif

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

@ -73,76 +73,8 @@ FreeAllocStrings(int argc, char **argv)
delete [] argv;
}
#ifdef XRE_PRELOAD_XUL
static void preload(LPCWSTR dll)
{
HANDLE fd = CreateFileW(dll, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
char buf[64 * 1024];
if (fd == INVALID_HANDLE_VALUE)
return;
DWORD dwBytesRead;
// Do dummy reads to trigger kernel-side readhead via FILE_FLAG_SEQUENTIAL_SCAN.
// Abort when underfilling because during testing the buffers are read fully
// A buffer that's not keeping up would imply that readahead isn't working right
while (ReadFile(fd, buf, sizeof(buf), &dwBytesRead, NULL) && dwBytesRead == sizeof(buf))
/* Nothing */;
CloseHandle(fd);
}
/** Populate the windows page cache */
static void preload_libs(LPCWSTR appPath)
{
wchar_t buf[MAX_PATH];
size_t pathlen = wcslen(appPath);
// rewind until the last \
for(;pathlen && appPath[pathlen] != L'\\'; pathlen--);
// if there is a directory name present, keep the last \
if (pathlen)
pathlen++;
if (pathlen + 10 > MAX_PATH) {
return;
}
wcsncpy(buf, appPath, pathlen);
size_t remaining = sizeof(buf)/sizeof(buf[0]) - pathlen - 1;
// For now only preload only the most expensive libs.
// The rest cost a few magnitudes less.
LPCWSTR files[] = {L"xul.dll",
#ifndef MOZ_STATIC_JS
L"mozjs.dll",
#endif
0};
for(int i = 0; files[i]; i++) {
wcsncpy(buf + pathlen, files[i], remaining);
preload(buf);
}
return;
}
#endif
int wmain(int argc, WCHAR **argv)
{
#ifdef XRE_PRELOAD_XUL
// GetProcessIoCounters().ReadOperationCount seems to have little to
// do with actual read operations. It reports 0 or 1 at this stage
// in the program. Luckily 1 coincides with when prefetch is
// enabled. If Windows prefetch didn't happen we can do our own
// faster dll preloading.
IO_COUNTERS ioCounters;
if (GetProcessIoCounters(GetCurrentProcess(), &ioCounters)
&& !ioCounters.ReadOperationCount)
{
preload_libs(argv[0]);
}
#endif
#ifndef XRE_DONT_PROTECT_DLL_LOAD
mozilla::NS_SetDllDirectory(L"");
#endif