Bug 1338179 - Disable W^X JIT code page switching when running on Valgrind on Linux/Mac. r=nicolas.b.pierron.
authorJulian Seward <jseward@acm.org>
Tue, 14 Feb 2017 20:41:23 +0100
changeset 342972 1de058eb82318ee656c7162dc9516a9db9defc0c
parent 342971 b17eeee93d22d89e99355b72c5b46b6125ff99f1
child 342973 c0807d6938c13e43add377d5838df7168a59971e
child 343063 3d5437e759b4e938ee95763f39a8b42fa6328dca
push id31366
push usercbook@mozilla.com
push dateWed, 15 Feb 2017 11:25:19 +0000
treeherdermozilla-central@c0807d6938c1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnicolas.b.pierron
bugs1338179
milestone54.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 1338179 - Disable W^X JIT code page switching when running on Valgrind on Linux/Mac. r=nicolas.b.pierron.
js/src/jit/ProcessExecutableMemory.cpp
--- a/js/src/jit/ProcessExecutableMemory.cpp
+++ b/js/src/jit/ProcessExecutableMemory.cpp
@@ -28,16 +28,20 @@
 #ifdef XP_WIN
 # include "mozilla/StackWalk_windows.h"
 # include "mozilla/WindowsVersion.h"
 #else
 # include <sys/mman.h>
 # include <unistd.h>
 #endif
 
+#ifdef MOZ_VALGRIND
+# include <valgrind/valgrind.h>
+#endif
+
 using namespace js;
 using namespace js::jit;
 
 #ifdef XP_WIN
 static void*
 ComputeRandomAllocationAddress()
 {
     /*
@@ -300,16 +304,32 @@ DeallocateProcessExecutableMemory(void* 
 {
     mozilla::DebugOnly<int> result = munmap(addr, bytes);
     MOZ_ASSERT(!result || errno == ENOMEM);
 }
 
 static unsigned
 ProtectionSettingToFlags(ProtectionSetting protection)
 {
+#ifdef MOZ_VALGRIND
+    // If we're configured for Valgrind and running on it, use a slacker
+    // scheme that doesn't change execute permissions, since doing so causes
+    // Valgrind a lot of extra overhead re-JITting code that loses and later
+    // regains execute permission.  See bug 1338179.
+    if (RUNNING_ON_VALGRIND) {
+      switch (protection) {
+        case ProtectionSetting::Protected:  return PROT_NONE;
+        case ProtectionSetting::Writable:   return PROT_READ | PROT_WRITE | PROT_EXEC;
+        case ProtectionSetting::Executable: return PROT_READ | PROT_EXEC;
+      }
+      MOZ_CRASH();
+    }
+    // If we get here, we're configured for Valgrind but not running on
+    // it, so use the standard scheme.
+#endif
     switch (protection) {
       case ProtectionSetting::Protected:  return PROT_NONE;
       case ProtectionSetting::Writable:   return PROT_READ | PROT_WRITE;
       case ProtectionSetting::Executable: return PROT_READ | PROT_EXEC;
     }
     MOZ_CRASH();
 }