Bug 1284674 - Remove NUWA r=cyu
authorAlexandre Lissy <lissyx@lissyx.dyndns.org>
Tue, 02 Aug 2016 14:54:00 +0200
changeset 307976 c4de227304aa18ceb41047e222272f22fd99d5f9
parent 307975 f0e0cd618dde2988152a98cd4a285b0ae4afd964
child 307977 34cefe01d821d6795993d0047bcaa01206b6fecf
push id30526
push usercbook@mozilla.com
push dateThu, 04 Aug 2016 13:53:29 +0000
treeherdermozilla-central@62a983c56050 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscyu
bugs1284674
milestone51.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 1284674 - Remove NUWA r=cyu MozReview-Commit-ID: GyMRNzOBKw6
b2g/app/B2GLoader.cpp
b2g/app/moz.build
b2g/app/nsBrowserApp.cpp
b2g/confvars.sh
b2g/graphene/confvars.sh
dom/ipc/ContentChild.cpp
dom/ipc/ContentChild.h
dom/ipc/ContentParent.cpp
dom/ipc/ContentParent.h
dom/ipc/NuwaChild.cpp
dom/ipc/NuwaChild.h
dom/ipc/NuwaParent.cpp
dom/ipc/NuwaParent.h
dom/ipc/PNuwa.ipdl
dom/ipc/PreallocatedProcessManager.cpp
dom/ipc/PreallocatedProcessManager.h
dom/ipc/ProcessPriorityManager.cpp
dom/ipc/TabChild.cpp
dom/ipc/TabContext.h
dom/ipc/TabParent.cpp
dom/ipc/moz.build
dom/ipc/tests/mochitest.ini
dom/ipc/tests/test_NuwaProcessCreation.html
dom/ipc/tests/test_NuwaProcessDeadlock.html
dom/storage/DOMStorageIPC.cpp
dom/workers/RuntimeService.cpp
gfx/layers/ipc/ImageBridgeChild.cpp
gfx/layers/ipc/SharedBufferManagerChild.cpp
image/DecodePool.cpp
ipc/chromium/src/base/process_util_linux.cc
ipc/chromium/src/chrome/common/child_thread.cc
ipc/chromium/src/chrome/common/child_thread.h
ipc/contentproc/moz.build
ipc/contentproc/plugin-container.cpp
ipc/glue/BackgroundChildImpl.cpp
ipc/glue/BackgroundChildImpl.h
ipc/glue/BackgroundParentImpl.cpp
ipc/glue/BackgroundParentImpl.h
ipc/glue/GeckoChildProcessHost.cpp
ipc/glue/GeckoChildProcessHost.h
ipc/glue/MessageChannel.h
ipc/glue/MessageLink.cpp
ipc/glue/MessageLink.h
ipc/glue/MessagePump.cpp
ipc/glue/PBackground.ipdl
ipc/glue/ProcessUtils.h
ipc/glue/ProcessUtils_linux.cpp
js/src/old-configure.in
js/src/vm/HelperThreads.cpp
js/xpconnect/src/XPCJSRuntime.cpp
layout/base/nsRefreshDriver.cpp
memory/jemalloc/moz.build
memory/mozjemalloc/moz.build
memory/replace/dmd/DMD.cpp
memory/replace/logalloc/replay/Replay.cpp
mozglue/build/Nuwa.cpp
mozglue/build/Nuwa.h
mozglue/build/moz.build
netwerk/base/Predictor.cpp
netwerk/base/nsPACMan.cpp
netwerk/base/nsSocketTransportService2.cpp
netwerk/base/nsStreamTransportService.cpp
netwerk/system/linux/nsNotifyAddrListener_Linux.cpp
old-configure.in
security/sandbox/linux/Sandbox.cpp
security/sandbox/linux/Sandbox.h
toolkit/components/extensions/Extension.jsm
toolkit/modules/AppConstants.jsm
toolkit/xre/moz.build
toolkit/xre/nsAppRunner.cpp
toolkit/xre/nsEmbedFunctions.cpp
tools/profiler/core/ThreadInfo.h
tools/profiler/core/platform-linux.cc
widget/gonk/GonkMemoryPressureMonitoring.cpp
widget/gonk/nsAppShell.cpp
xpcom/base/nsCycleCollector.cpp
xpcom/base/nsMemoryReporterManager.cpp
xpcom/build/nsXULAppAPI.h
xpcom/components/ManifestParser.cpp
xpcom/components/nsComponentManager.cpp
xpcom/components/nsComponentManager.h
xpcom/threads/BackgroundHangMonitor.cpp
xpcom/threads/HangMonitor.cpp
xpcom/threads/TimerThread.cpp
xpcom/threads/nsThread.cpp
xpcom/threads/nsTimerImpl.cpp
deleted file mode 100644
--- a/b2g/app/B2GLoader.cpp
+++ /dev/null
@@ -1,300 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set sw=2 ts=2 autoindent cindent expandtab: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "nsXULAppAPI.h"
-#include "application.ini.h"
-#include "nsXPCOMGlue.h"
-#include "nsStringGlue.h"
-#include "nsCOMPtr.h"
-#include "nsIFile.h"
-#include "BinaryPath.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include <dlfcn.h>
-
-#include "nsXPCOMPrivate.h" // for MAXPATHLEN and XPCOM_DLL
-#include "mozilla/UniquePtr.h"
-
-#define ASSERT(x) if (!(x)) { MOZ_CRASH(); }
-
-// Functions being loaded by XPCOMGlue
-XRE_ProcLoaderServiceRunType XRE_ProcLoaderServiceRun;
-XRE_ProcLoaderClientInitType XRE_ProcLoaderClientInit;
-XRE_ProcLoaderPreloadType XRE_ProcLoaderPreload;
-extern XRE_CreateAppDataType XRE_CreateAppData;
-extern XRE_GetFileFromPathType XRE_GetFileFromPath;
-
-static const nsDynamicFunctionLoad kXULFuncs[] = {
-  { "XRE_ProcLoaderServiceRun", (NSFuncPtr*) &XRE_ProcLoaderServiceRun },
-  { "XRE_ProcLoaderClientInit", (NSFuncPtr*) &XRE_ProcLoaderClientInit },
-  { "XRE_ProcLoaderPreload", (NSFuncPtr*) &XRE_ProcLoaderPreload },
-  { "XRE_CreateAppData", (NSFuncPtr*) &XRE_CreateAppData },
-  { "XRE_GetFileFromPath", (NSFuncPtr*) &XRE_GetFileFromPath },
-  { nullptr, nullptr }
-};
-
-typedef mozilla::Vector<int> FdArray;
-static const int kReservedFileDescriptors = 5;
-static const int kBeginReserveFileDescriptor = STDERR_FILENO + 1;
-
-static int
-GetDirnameSlash(const char *aPath, char *aOutDir, int aMaxLen)
-{
-  char *lastSlash = strrchr(aPath, XPCOM_FILE_PATH_SEPARATOR[0]);
-  if (lastSlash == nullptr) {
-    return 0;
-  }
-  int cpsz = lastSlash - aPath + 1; // include slash
-  if (aMaxLen <= cpsz) {
-    return 0;
-  }
-  strncpy(aOutDir, aPath, cpsz);
-  aOutDir[cpsz] = 0;
-  return cpsz;
-}
-
-static bool
-GetXPCOMPath(const char *aProgram, char *aOutPath, int aMaxLen)
-{
-  auto progBuf = mozilla::MakeUnique<char[]>(aMaxLen);
-  nsresult rv = mozilla::BinaryPath::Get(aProgram, progBuf.get());
-  NS_ENSURE_SUCCESS(rv, false);
-
-  int len = GetDirnameSlash(progBuf.get(), aOutPath, aMaxLen);
-  NS_ENSURE_TRUE(!!len, false);
-
-  NS_ENSURE_TRUE((len + sizeof(XPCOM_DLL)) < (unsigned)aMaxLen, false);
-  char *afterSlash = aOutPath + len;
-  strcpy(afterSlash, XPCOM_DLL);
-  return true;
-}
-
-static bool
-LoadLibxul(const char *aXPCOMPath)
-{
-  nsresult rv;
-
-  XPCOMGlueEnablePreload();
-  rv = XPCOMGlueStartup(aXPCOMPath);
-  NS_ENSURE_SUCCESS(rv, false);
-
-  rv = XPCOMGlueLoadXULFunctions(kXULFuncs);
-  NS_ENSURE_SUCCESS(rv, false);
-
-  return true;
-}
-
-/**
- * Return true if |arg| matches the given argument name.
- */
-static bool
-IsArg(const char* arg, const char* s)
-{
-  if (*arg == '-') {
-    if (*++arg == '-') {
-      ++arg;
-    }
-    return !strcasecmp(arg, s);
-  }
-
-#if defined(XP_WIN)
-  if (*arg == '/') {
-    return !strcasecmp(++arg, s);
-  }
-#endif
-
-  return false;
-}
-
-static already_AddRefed<nsIFile>
-GetAppIni(int argc, const char *argv[])
-{
-  nsCOMPtr<nsIFile> appini;
-  nsresult rv;
-
-  // Allow firefox.exe to launch XULRunner apps via -app <application.ini>
-  // Note that -app must be the *first* argument.
-  const char *appDataFile = getenv("XUL_APP_FILE");
-  if (appDataFile && *appDataFile) {
-    rv = XRE_GetFileFromPath(appDataFile, getter_AddRefs(appini));
-    NS_ENSURE_SUCCESS(rv, nullptr);
-  } else if (argc > 1 && IsArg(argv[1], "app")) {
-    if (argc == 2) {
-      return nullptr;
-    }
-
-    rv = XRE_GetFileFromPath(argv[2], getter_AddRefs(appini));
-    NS_ENSURE_SUCCESS(rv, nullptr);
-
-    char appEnv[MAXPATHLEN];
-    snprintf(appEnv, MAXPATHLEN, "XUL_APP_FILE=%s", argv[2]);
-    if (putenv(strdup(appEnv))) {
-      return nullptr;
-    }
-  }
-
-  return appini.forget();
-}
-
-static bool
-LoadStaticData(int argc, const char *argv[])
-{
-  char xpcomPath[MAXPATHLEN];
-  bool ok = GetXPCOMPath(argv[0], xpcomPath, MAXPATHLEN);
-  NS_ENSURE_TRUE(ok, false);
-
-  ok = LoadLibxul(xpcomPath);
-  NS_ENSURE_TRUE(ok, false);
-
-  char progDir[MAXPATHLEN];
-  ok = GetDirnameSlash(xpcomPath, progDir, MAXPATHLEN);
-  NS_ENSURE_TRUE(ok, false);
-
-  nsCOMPtr<nsIFile> appini = GetAppIni(argc, argv);
-  const nsXREAppData *appData;
-  if (appini) {
-    nsresult rv =
-      XRE_CreateAppData(appini, const_cast<nsXREAppData**>(&appData));
-    NS_ENSURE_SUCCESS(rv, false);
-  } else {
-    appData = &sAppData;
-  }
-
-  XRE_ProcLoaderPreload(progDir, appData);
-
-  if (appini) {
-    XRE_FreeAppData(const_cast<nsXREAppData*>(appData));
-  }
-
-  return true;
-}
-
-/**
- * Fork and run parent and child process.
- *
- * The parent is the b2g process and child for Nuwa.
- */
-static int
-RunProcesses(int argc, const char *argv[], FdArray& aReservedFds)
-{
-  /*
-   * The original main() of the b2g process.  It is renamed to
-   * b2g_main() for the b2g loader.
-   */
-  int b2g_main(int argc, const char *argv[]);
-
-  int ipcSockets[2] = {-1, -1};
-  int r = socketpair(AF_LOCAL, SOCK_STREAM, 0, ipcSockets);
-  ASSERT(r == 0);
-  int parentSock = ipcSockets[0];
-  int childSock = ipcSockets[1];
-
-  r = fcntl(parentSock, F_SETFL, O_NONBLOCK);
-  ASSERT(r != -1);
-  r = fcntl(childSock, F_SETFL, O_NONBLOCK);
-  ASSERT(r != -1);
-
-  pid_t pid = fork();
-  ASSERT(pid >= 0);
-  bool isChildProcess = pid == 0;
-
-  close(isChildProcess ? parentSock : childSock);
-
-  if (isChildProcess) {
-    /* The Nuwa process */
-    /* This provides the IPC service of loading Nuwa at the process.
-     * The b2g process would send a IPC message of loading Nuwa
-     * as the replacement of forking and executing plugin-container.
-     */
-    return XRE_ProcLoaderServiceRun(getppid(), childSock, argc, argv,
-                                    aReservedFds);
-  }
-
-  // Reap zombie child process.
-  struct sigaction sa;
-  sa.sa_handler = SIG_IGN;
-  sigemptyset(&sa.sa_mask);
-  sa.sa_flags = 0;
-  sigaction(SIGCHLD, &sa, nullptr);
-
-  // The b2g process
-  int childPid = pid;
-  XRE_ProcLoaderClientInit(childPid, parentSock, aReservedFds);
-  return b2g_main(argc, argv);
-}
-
-/**
- * Reserve the file descriptors that shouldn't be taken for other use for the
- * child process.
- */
-static void
-ReserveFileDescriptors(FdArray& aReservedFds)
-{
-  for (int i = 0; i < kReservedFileDescriptors; i++) {
-    struct stat fileState;
-    int target = kBeginReserveFileDescriptor + i;
-    if (fstat(target, &fileState) == 0) {
-      MOZ_CRASH("ProcLoader error: a magic file descriptor is occupied.");
-    }
-
-    int fd = open("/dev/null", O_RDWR);
-    if (fd == -1) {
-      MOZ_CRASH("ProcLoader error: failed to reserve a magic file descriptor.");
-    }
-
-    if (!aReservedFds.append(target)) {
-      MOZ_CRASH("Failed to append to aReservedFds");
-    }
-
-    if (fd == target) {
-      // No need to call dup2(). We already occupy the desired file descriptor.
-      continue;
-    }
-
-    if (dup2(fd, target)) {
-      MOZ_CRASH("ProcLoader error: failed to reserve a magic file descriptor.");
-    }
-
-    close(fd);
-  }
-}
-
-/**
- * B2G Loader is responsible for loading the b2g process and the
- * Nuwa process.  It forks into the parent process, for the b2g
- * process, and the child process, for the Nuwa process.
- *
- * The loader loads libxul and performs initialization of static data
- * before forking, so relocation of libxul and static data can be
- * shared between the b2g process, the Nuwa process, and the content
- * processes.
- */
-int
-main(int argc, const char* argv[])
-{
-  /**
-   * Reserve file descriptors before loading static data.
-   */
-  FdArray reservedFds;
-  ReserveFileDescriptors(reservedFds);
-
-  /*
-   * Before fork(), libxul and static data of Gecko are loaded for
-   * sharing.
-   */
-  bool ok = LoadStaticData(argc, argv);
-  if (!ok) {
-    return 255;
-  }
-
-  return RunProcesses(argc, argv, reservedFds);
-}
--- a/b2g/app/moz.build
+++ b/b2g/app/moz.build
@@ -3,20 +3,16 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 if CONFIG['GAIADIR']:
     GeckoProgram(CONFIG['MOZ_APP_NAME'] + "-bin")
 else:
     GeckoProgram(CONFIG['MOZ_APP_NAME'])
-if CONFIG['MOZ_B2G_LOADER']:
-    SOURCES += [
-        'B2GLoader.cpp',
-    ]
 
 SOURCES += [
     'nsBrowserApp.cpp',
 ]
 if CONFIG['_MSC_VER']:
     # Always enter a Windows program through wmain, whether or not we're
     # a console application.
     WIN32_EXE_LDFLAGS += ['-ENTRY:wmainCRTStartup']
--- a/b2g/app/nsBrowserApp.cpp
+++ b/b2g/app/nsBrowserApp.cpp
@@ -158,83 +158,64 @@ static int do_main(int argc, char* argv[
     int result = XRE_main(argc, argv, appData, 0);
     XRE_FreeAppData(appData);
     return result;
   }
 
   return XRE_main(argc, argv, &sAppData, 0);
 }
 
-#ifdef MOZ_B2G_LOADER
-/*
- * The main() in B2GLoader.cpp is the new main function instead of the
- * main() here if it is enabled.  So, rename it to b2g_man().
- */
-#define main b2g_main
-#define _CONST const
-#else
-#define _CONST
-#endif
-
-int main(int argc, _CONST char* argv[])
+int main(int argc, char* argv[])
 {
-#ifndef MOZ_B2G_LOADER
   char exePath[MAXPATHLEN];
-#endif
 
 #ifdef MOZ_WIDGET_GONK
   // This creates a ThreadPool for binder ipc. A ThreadPool is necessary to
   // receive binder calls, though not necessary to send binder calls.
   // ProcessState::Self() also needs to be called once on the main thread to
   // register the main thread with the binder driver.
   android::ProcessState::self()->startThreadPool();
 #endif
 
   nsresult rv;
-#ifndef MOZ_B2G_LOADER
   rv = mozilla::BinaryPath::Get(argv[0], exePath);
   if (NS_FAILED(rv)) {
     Output("Couldn't calculate the application directory.\n");
     return 255;
   }
 
   char *lastSlash = strrchr(exePath, XPCOM_FILE_PATH_SEPARATOR[0]);
   if (!lastSlash || ((lastSlash - exePath) + sizeof(XPCOM_DLL) + 1 > MAXPATHLEN))
     return 255;
 
   strcpy(++lastSlash, XPCOM_DLL);
-#endif // MOZ_B2G_LOADER
 
 #if defined(XP_UNIX)
   // If the b2g app is launched from adb shell, then the shell will wind
   // up being the process group controller. This means that we can't send
   // signals to the process group (useful for profiling).
   // We ignore the return value since setsid() fails if we're already the
   // process group controller (the normal situation).
   (void)setsid();
 #endif
 
 #ifdef HAS_DLL_BLOCKLIST
   DllBlocklist_Initialize();
 #endif
 
-  // B2G loader has already initialized Gecko so we can't initialize
-  // it again here.
-#ifndef MOZ_B2G_LOADER
   // We do this because of data in bug 771745
   XPCOMGlueEnablePreload();
 
   rv = XPCOMGlueStartup(exePath);
   if (NS_FAILED(rv)) {
     Output("Couldn't load XPCOM.\n");
     return 255;
   }
   // Reset exePath so that it is the directory name and not the xpcom dll name
   *lastSlash = 0;
-#endif // MOZ_B2G_LOADER
 
   rv = XPCOMGlueLoadXULFunctions(kXULFuncs);
   if (NS_FAILED(rv)) {
     Output("Couldn't load XRE functions.\n");
     return 255;
   }
 
   int result;
--- a/b2g/confvars.sh
+++ b/b2g/confvars.sh
@@ -48,18 +48,16 @@ MOZ_APP_ID={3c2e2abc-06d4-11e1-ac3b-374f
 MOZ_TIME_MANAGER=1
 
 MOZ_SIMPLEPUSH=1
 MOZ_PAY=1
 MOZ_TOOLKIT_SEARCH=
 MOZ_B2G=1
 
 if test "$OS_TARGET" = "Android"; then
-MOZ_NUWA_PROCESS=1
-MOZ_B2G_LOADER=1
 MOZ_ENABLE_WARNINGS_AS_ERRORS=1
 fi
 
 MOZ_JSDOWNLOADS=1
 
 MOZ_BUNDLED_FONTS=1
 
 export JS_GC_SMALL_CHUNK_SIZE=1
--- a/b2g/graphene/confvars.sh
+++ b/b2g/graphene/confvars.sh
@@ -43,18 +43,16 @@ MOZ_APP_ID={d1bfe7d9-c01e-4237-998b-7b5f
 MOZ_TIME_MANAGER=1
 
 MOZ_PAY=1
 MOZ_TOOLKIT_SEARCH=
 MOZ_PLACES=
 MOZ_B2G=1
 
 if test "$OS_TARGET" = "Android"; then
-MOZ_NUWA_PROCESS=1
-MOZ_B2G_LOADER=1
 MOZ_ENABLE_WARNINGS_AS_ERRORS=1
 fi
 
 MOZ_JSDOWNLOADS=1
 
 MOZ_BUNDLED_FONTS=1
 
 export JS_GC_SMALL_CHUNK_SIZE=1
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -161,21 +161,16 @@
 #ifdef MOZ_X11
 #include "mozilla/X11Util.h"
 #endif
 
 #ifdef ACCESSIBILITY
 #include "nsIAccessibilityService.h"
 #endif
 
-#ifdef MOZ_NUWA_PROCESS
-#include "ipc/Nuwa.h"
-#endif
-#include "NuwaChild.h"
-
 #ifndef MOZ_SIMPLEPUSH
 #include "mozilla/dom/PushNotifier.h"
 #endif
 
 #include "mozilla/dom/File.h"
 #include "mozilla/dom/cellbroadcast/CellBroadcastIPCService.h"
 #include "mozilla/dom/icc/IccChild.h"
 #include "mozilla/dom/mobileconnection/MobileConnectionChild.h"
@@ -511,67 +506,16 @@ private:
     MOZ_CRASH("Failed to create a PBackgroundChild actor!");
   }
 };
 
 NS_IMPL_ISUPPORTS(BackgroundChildPrimer, nsIIPCBackgroundChildCreateCallback)
 
 ContentChild* ContentChild::sSingleton;
 
-// Performs initialization that is not fork-safe, i.e. that must be done after
-// forking from the Nuwa process.
-void
-InitOnContentProcessCreated()
-{
-#ifdef MOZ_NUWA_PROCESS
-  // Wait until we are forked from Nuwa
-  if (IsNuwaProcess()) {
-    return;
-  }
-
-  nsCOMPtr<nsIPermissionManager> permManager = services::GetPermissionManager();
-  MOZ_ASSERT(permManager, "Unable to get permission manager");
-  nsresult rv = permManager->RefreshPermission();
-  if (NS_FAILED(rv)) {
-    MOZ_ASSERT(false, "Failed updating permission in child process");
-  }
-#endif
-
-  // This will register cross-process observer.
-  mozilla::dom::time::InitializeDateCacheCleaner();
-}
-
-#ifdef MOZ_NUWA_PROCESS
-static void
-ResetTransports(void* aUnused)
-{
-  ContentChild* child = ContentChild::GetSingleton();
-  mozilla::ipc::Transport* transport = child->GetTransport();
-  int fd = transport->GetFileDescriptor();
-  transport->ResetFileDescriptor(fd);
-
-  nsTArray<IToplevelProtocol*> actors;
-  child->GetOpenedActors(actors);
-  for (size_t i = 0; i < actors.Length(); i++) {
-    IToplevelProtocol* toplevel = actors[i];
-    transport = toplevel->GetTransport();
-    fd = transport->GetFileDescriptor();
-    transport->ResetFileDescriptor(fd);
-  }
-}
-#endif
-
-#if defined(MOZ_TASK_TRACER) && defined(MOZ_NUWA_PROCESS)
-static void
-ReinitTaskTracer(void* /*aUnused*/)
-{
-  mozilla::tasktracer::InitTaskTracer(mozilla::tasktracer::FORKED_AFTER_NUWA);
-}
-#endif
-
 ContentChild::ContentChild()
  : mID(uint64_t(-1))
  , mCanOverrideProcessName(true)
  , mIsAlive(true)
 {
   // This process is a content process, so it's clearly running in
   // multiprocess mode!
   nsDebugImpl::SetMultiprocessMode("Child");
@@ -637,67 +581,46 @@ ContentChild::Init(MessageLoop* aIOLoop,
 
   if (!Open(aChannel, aParentPid, aIOLoop)) {
     return false;
   }
   sSingleton = this;
 
   // If communications with the parent have broken down, take the process
   // down so it's not hanging around.
-  bool abortOnError = true;
-#ifdef MOZ_NUWA_PROCESS
-  abortOnError &= !IsNuwaProcess();
-#endif
-  GetIPCChannel()->SetAbortOnError(abortOnError);
+  GetIPCChannel()->SetAbortOnError(true);
 
 #ifdef MOZ_X11
   // Send the parent our X socket to act as a proxy reference for our X
   // resources.
   int xSocketFd = ConnectionNumber(DefaultXDisplay());
   SendBackUpXResources(FileDescriptor(xSocketFd));
 #endif
 
 #ifdef MOZ_CRASHREPORTER
   SendPCrashReporterConstructor(CrashReporter::CurrentThreadId(),
                                 XRE_GetProcessType());
 #endif
 
   SendGetProcessAttributes(&mID, &mIsForApp, &mIsForBrowser);
   InitProcessAttributes();
 
-#if defined(MOZ_TASK_TRACER) && defined (MOZ_NUWA_PROCESS)
-  if (IsNuwaProcess()) {
-    NuwaAddConstructor(ReinitTaskTracer, nullptr);
-  }
-#endif
-
-#ifdef MOZ_NUWA_PROCESS
-  if (IsNuwaProcess()) {
-    NuwaAddConstructor(ResetTransports, nullptr);
-  }
-#endif
 #ifdef NS_PRINTING
   // Force the creation of the nsPrintingProxy so that it's IPC counterpart,
   // PrintingParent, is always available for printing initiated from the parent.
   RefPtr<nsPrintingProxy> printingProxy = nsPrintingProxy::GetInstance();
 #endif
 
   return true;
 }
 
 void
 ContentChild::InitProcessAttributes()
 {
 #ifdef MOZ_WIDGET_GONK
-#ifdef MOZ_NUWA_PROCESS
-  if (IsNuwaProcess()) {
-    SetProcessName(NS_LITERAL_STRING("(Nuwa)"), false);
-    return;
-  }
-#endif
   if (mIsForApp && !mIsForBrowser) {
     SetProcessName(NS_LITERAL_STRING("(Preallocated app)"), false);
   } else {
     SetProcessName(NS_LITERAL_STRING("Browser"), false);
   }
 #else
   SetProcessName(NS_LITERAL_STRING("Web Content"), true);
 #endif
@@ -1032,17 +955,18 @@ ContentChild::InitXPCOM()
     initialData.Read(jsapi.cx(), &data, rv);
     if (NS_WARN_IF(rv.Failed())) {
       MOZ_CRASH();
     }
     ProcessGlobal* global = ProcessGlobal::Get();
     global->SetInitialProcessData(data);
   }
 
-  InitOnContentProcessCreated();
+  // This will register cross-process observer.
+  mozilla::dom::time::InitializeDateCacheCleaner();
 }
 
 PMemoryReportRequestChild*
 ContentChild::AllocPMemoryReportRequestChild(const uint32_t& aGeneration,
                                              const bool &aAnonymize,
                                              const bool &aMinimizeMemoryUsage,
                                              const MaybeFileDesc& aDMDFile)
 {
@@ -2277,24 +2201,16 @@ ContentChild::ActorDestroy(ActorDestroyR
 
   nsCOMPtr<nsIConsoleService> svc(do_GetService(NS_CONSOLESERVICE_CONTRACTID));
   if (svc) {
     svc->UnregisterListener(mConsoleListener);
     mConsoleListener->mChild = nullptr;
   }
   mIsAlive = false;
 
-#ifdef MOZ_NUWA_PROCESS
-  if (IsNuwaProcess()) {
-    // The Nuwa cannot go through the full XPCOM shutdown path or deadlock
-    // will result.
-    ProcessChild::QuickExit();
-  }
-#endif
-
   XRE_ShutdownChildProcess();
 #endif // NS_FREE_PERMANENT_DATA
 }
 
 void
 ContentChild::ProcessingError(Result aCode, const char* aReason)
 {
   switch (aCode) {
@@ -2523,19 +2439,16 @@ ContentChild::RecvAddPermission(const IP
 #endif
 
   return true;
 }
 
 bool
 ContentChild::RecvFlushMemory(const nsString& reason)
 {
-#ifdef MOZ_NUWA_PROCESS
-  MOZ_ASSERT(!IsNuwaProcess() || !IsNuwaReady());
-#endif
   nsCOMPtr<nsIObserverService> os =
     mozilla::services::GetObserverService();
   if (os) {
     os->NotifyObservers(nullptr, "memory-pressure", reason.get());
   }
   return true;
 }
 
@@ -2570,41 +2483,16 @@ ContentChild::RecvCycleCollect()
   nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
   if (obs) {
     obs->NotifyObservers(nullptr, "child-cc-request", nullptr);
   }
   nsJSContext::CycleCollectNow();
   return true;
 }
 
-#ifdef MOZ_NUWA_PROCESS
-static void
-OnFinishNuwaPreparation()
-{
-  // We want to ensure that the PBackground actor gets cloned in the Nuwa
-  // process before we freeze. Also, we have to do this to avoid deadlock.
-  // Protocols that are "opened" (e.g. PBackground, PCompositorBridge) block
-  // the main thread to wait for the IPC thread during the open operation.
-  // NuwaSpawnWait() blocks the IPC thread to wait for the main thread when
-  // the Nuwa process is forked. Unless we ensure that the two cannot happen
-  // at the same time then we risk deadlock. Spinning the event loop here
-  // guarantees the ordering is safe for PBackground.
-  while (!BackgroundChild::GetForCurrentThread()) {
-    if (NS_WARN_IF(!NS_ProcessNextEvent())) {
-      return;
-    }
-  }
-
-  // This will create the actor.
-  Unused << mozilla::dom::NuwaChild::GetSingleton();
-
-  MakeNuwaProcess();
-}
-#endif
-
 static void
 PreloadSlowThings()
 {
   // This fetches and creates all the built-in stylesheets.
   //
   // XXXheycam In the future we might want to preload the Servo-flavoured
   // UA sheets too, but for now that will be a waste of time.
   nsLayoutStylesheetCache::For(StyleBackendType::Gecko)->UserContentSheet();
@@ -2639,23 +2527,16 @@ ContentChild::RecvAppInit()
   // preloading things.  We can only do this for mozbrowser because
   // PreloadSlowThings() may set the docshell of the first TabChild
   // inactive, and we can only safely restore it to active from
   // BrowserElementChild.js.
   if (mIsForApp || mIsForBrowser) {
     PreloadSlowThings();
   }
 
-#ifdef MOZ_NUWA_PROCESS
-  if (IsNuwaProcess()) {
-    ContentChild::GetSingleton()->RecvGarbageCollect();
-    MessageLoop::current()->PostTask(NewRunnableFunction(OnFinishNuwaPreparation));
-  }
-#endif
-
   return true;
 }
 
 bool
 ContentChild::RecvInitServiceWorkers(const ServiceWorkerConfiguration& aConfig)
 {
   RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
   MOZ_ASSERT(swm);
@@ -2791,19 +2672,16 @@ ContentChild::RecvNotifyProcessPriorityC
   os->NotifyObservers(static_cast<nsIPropertyBag2*>(props),
                       "ipc:process-priority-changed",  nullptr);
   return true;
 }
 
 bool
 ContentChild::RecvMinimizeMemoryUsage()
 {
-#ifdef MOZ_NUWA_PROCESS
-  MOZ_ASSERT(!IsNuwaProcess() || !IsNuwaReady());
-#endif
   nsCOMPtr<nsIMemoryReporterManager> mgr =
     do_GetService("@mozilla.org/memory-reporter-manager;1");
   NS_ENSURE_TRUE(mgr, true);
 
   mgr->MinimizeMemoryUsage(/* callback = */ nullptr);
   return true;
 }
 
--- a/dom/ipc/ContentChild.h
+++ b/dom/ipc/ContentChild.h
@@ -684,18 +684,15 @@ private:
   // Hashtable to keep track of the pending GetFilesHelper objects.
   // This GetFilesHelperChild objects are removed when RecvGetFilesResponse is
   // received.
  nsRefPtrHashtable<nsIDHashKey, GetFilesHelperChild> mGetFilesPendingRequests;
 
   DISALLOW_EVIL_CONSTRUCTORS(ContentChild);
 };
 
-void
-InitOnContentProcessCreated();
-
 uint64_t
 NextWindowID();
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_ContentChild_h
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -47,17 +47,16 @@
 #include "mozilla/dom/File.h"
 #include "mozilla/dom/ExternalHelperAppParent.h"
 #include "mozilla/dom/GetFilesHelper.h"
 #include "mozilla/dom/GeolocationBinding.h"
 #ifdef MOZ_EME
 #include "mozilla/dom/MediaKeySystemAccess.h"
 #endif
 #include "mozilla/dom/Notification.h"
-#include "mozilla/dom/NuwaParent.h"
 #include "mozilla/dom/PContentBridgeParent.h"
 #include "mozilla/dom/PContentPermissionRequestParent.h"
 #include "mozilla/dom/PCycleCollectWithLogsParent.h"
 #include "mozilla/dom/PFMRadioParent.h"
 #include "mozilla/dom/PMemoryReportRequestParent.h"
 #include "mozilla/dom/ServiceWorkerRegistrar.h"
 #include "mozilla/dom/bluetooth/PBluetoothParent.h"
 #include "mozilla/dom/cellbroadcast/CellBroadcastParent.h"
@@ -321,21 +320,16 @@ template<>
 struct nsIConsoleService::COMTypeInfo<nsConsoleService, void> {
   static const nsIID kIID;
 };
 const nsIID nsIConsoleService::COMTypeInfo<nsConsoleService, void>::kIID = NS_ICONSOLESERVICE_IID;
 
 namespace mozilla {
 namespace dom {
 
-#ifdef MOZ_NUWA_PROCESS
-int32_t ContentParent::sNuwaPid = 0;
-bool ContentParent::sNuwaReady = false;
-#endif
-
 #define NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC "ipc:network:set-offline"
 #define NS_IPC_IOSERVICE_SET_CONNECTIVITY_TOPIC "ipc:network:set-connectivity"
 
 class MemoryReportRequestParent : public PMemoryReportRequestParent
 {
 public:
   explicit MemoryReportRequestParent(uint32_t aGeneration);
 
@@ -544,21 +538,16 @@ ContentParentsMemoryReporter::CollectRep
 nsDataHashtable<nsStringHashKey, ContentParent*>* ContentParent::sAppContentParents;
 nsTArray<ContentParent*>* ContentParent::sNonAppContentParents;
 nsTArray<ContentParent*>* ContentParent::sPrivateContent;
 StaticAutoPtr<LinkedList<ContentParent> > ContentParent::sContentParents;
 #if defined(XP_LINUX) && defined(MOZ_CONTENT_SANDBOX)
 UniquePtr<SandboxBrokerPolicyFactory> ContentParent::sSandboxBrokerPolicyFactory;
 #endif
 
-#ifdef MOZ_NUWA_PROCESS
-// The pref updates sent to the Nuwa process.
-static nsTArray<PrefSetting>* sNuwaPrefUpdates;
-#endif
-
 // This is true when subprocess launching is enabled.  This is the
 // case between StartUp() and ShutDown() or JoinAllSubprocesses().
 static bool sCanLaunchSubprocesses;
 
 // Set to true if the DISABLE_UNSAFE_CPOW_WARNINGS environment variable is
 // set.
 static bool sDisableUnsafeCPOWWarnings = false;
 
@@ -596,55 +585,16 @@ static const char* sObserverTopics[] = {
   "profiler-paused",
   "profiler-resumed",
   "profiler-subprocess-gather",
   "profiler-subprocess",
 #endif
   "gmp-changed",
 };
 
-#ifdef MOZ_NUWA_PROCESS
-// Contains the observer topics that can be sent to the Nuwa process after it
-// becomes ready. The ContentParent instance will unregister sObserverTopics
-// if not listed in sNuwaSafeObserverTopics.
-static const char* sNuwaSafeObserverTopics[] = {
-  "xpcom-shutdown",
-  "profile-before-change",
-#ifdef MOZ_WIDGET_GONK
-  "phone-state-changed",
-#endif
-#ifdef ACCESSIBILITY
-  "a11y-init-or-shutdown",
-#endif
-  "nsPref:Changed"
-};
-#endif
-/* static */ already_AddRefed<ContentParent>
-ContentParent::RunNuwaProcess()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  RefPtr<ContentParent> nuwaProcess =
-    new ContentParent(/* aApp = */ nullptr,
-                      /* aOpener = */ nullptr,
-                      /* aIsForBrowser = */ false,
-                      /* aIsForPreallocated = */ true,
-                      /* aIsNuwaProcess = */ true);
-
-  if (!nuwaProcess->LaunchSubprocess(PROCESS_PRIORITY_BACKGROUND)) {
-    return nullptr;
-  }
-
-  nuwaProcess->Init();
-#ifdef MOZ_NUWA_PROCESS
-  sNuwaPid = nuwaProcess->Pid();
-  sNuwaReady = false;
-#endif
-  return nuwaProcess.forget();
-}
-
 // PreallocateAppProcess is called by the PreallocatedProcessManager.
 // ContentParent then takes this process back within
 // GetNewOrPreallocatedAppProcess.
 /*static*/ already_AddRefed<ContentParent>
 ContentParent::PreallocateAppProcess()
 {
   RefPtr<ContentParent> process =
     new ContentParent(/* app = */ nullptr,
@@ -686,18 +636,16 @@ ContentParent::GetNewOrPreallocatedAppPr
 
       if (aTookPreAllocated) {
         *aTookPreAllocated = true;
       }
       return process.forget();
     }
   }
 
-  // XXXkhuey Nuwa wants the frame loader to try again later, but the
-  // frame loader is really not set up to do that ...
   NS_WARNING("Unable to use pre-allocated app process");
   process = new ContentParent(aApp,
                               /* aOpener = */ aOpener,
                               /* isForBrowserElement = */ false,
                               /* isForPreallocated = */ false);
 
   if (!process->LaunchSubprocess(aInitialPriority)) {
     return nullptr;
@@ -907,21 +855,17 @@ ContentParent::SendAsyncUpdate(nsIWidget
     cp->SendUpdateWindow((uintptr_t)hwnd);
   }
 }
 #endif // defined(XP_WIN)
 
 bool
 ContentParent::PreallocatedProcessReady()
 {
-#ifdef MOZ_NUWA_PROCESS
-  return PreallocatedProcessManager::PreallocatedProcessReady();
-#else
   return true;
-#endif
 }
 
 bool
 ContentParent::RecvCreateChildProcess(const IPCTabContext& aContext,
                                       const hal::ProcessPriority& aPriority,
                                       const TabId& aOpenerTabId,
                                       ContentParentId* aCpId,
                                       bool* aIsForApp,
@@ -1529,20 +1473,17 @@ ContentParent::SetPriorityAndCheckIsAliv
   ProcessPriorityManager::SetProcessPriority(this, aPriority);
 
   // Now that we've set this process's priority, check whether the process is
   // still alive.  Hopefully we've set the priority to FOREGROUND*, so the
   // process won't unexpectedly crash after this point!
   //
   // Bug 943174: use waitid() with WNOWAIT so that, if the process
   // did exit, we won't consume its zombie and confuse the
-  // GeckoChildProcessHost dtor.  Also, if the process isn't a
-  // direct child because of Nuwa this will fail with ECHILD, and we
-  // need to assume the child is alive in that case rather than
-  // assuming it's dead (as is otherwise a reasonable fallback).
+  // GeckoChildProcessHost dtor.
 #ifdef MOZ_WIDGET_GONK
   siginfo_t info;
   info.si_pid = 0;
   if (waitid(P_PID, Pid(), &info, WNOWAIT | WNOHANG | WEXITED) == 0
     && info.si_pid != 0) {
     return false;
   }
 #endif
@@ -1593,24 +1534,16 @@ ContentParent::TransformPreallocatedInto
   mOpener = aOpener;
   mAppManifestURL.Truncate();
   mIsForBrowser = true;
 }
 
 void
 ContentParent::ShutDownProcess(ShutDownMethod aMethod)
 {
-#ifdef MOZ_NUWA_PROCESS
-  if (aMethod == SEND_SHUTDOWN_MESSAGE && IsNuwaProcess()) {
-    // We shouldn't send shutdown messages to frozen Nuwa processes,
-    // so just close the channel.
-    aMethod = CLOSE_CHANNEL;
-  }
-#endif
-
   // Shutting down by sending a shutdown message works differently than the
   // other methods. We first call Shutdown() in the child. After the child is
   // ready, it calls FinishShutdown() on us. Then we close the channel.
   if (aMethod == SEND_SHUTDOWN_MESSAGE) {
     if (mIPCOpen && !mShutdownPending && SendShutdown()) {
       mShutdownPending = true;
       // Start the force-kill timer if we haven't already.
       StartForceKillTimer();
@@ -1630,23 +1563,16 @@ ContentParent::ShutDownProcess(ShutDownM
   // If Close() fails with an error, we'll end up back in this function, but
   // with aMethod = CLOSE_CHANNEL_WITH_ERROR.
 
   if (aMethod == CLOSE_CHANNEL && !mCalledClose) {
     // Close() can only be called once: It kicks off the destruction
     // sequence.
     mCalledClose = true;
     Close();
-#ifdef MOZ_NUWA_PROCESS
-    // Kill Nuwa process forcibly to break its IPC channels and finalize
-    // corresponding parents.
-    if (IsNuwaProcess()) {
-      KillHard("ShutDownProcess");
-    }
-#endif
   }
 
   const ManagedContainer<POfflineCacheUpdateParent>& ocuParents =
     ManagedPOfflineCacheUpdateParent();
   for (auto iter = ocuParents.ConstIter(); !iter.Done(); iter.Next()) {
     RefPtr<mozilla::docshell::OfflineCacheUpdateParent> ocuParent =
       static_cast<mozilla::docshell::OfflineCacheUpdateParent*>(iter.Get()->GetKey());
     ocuParent->StopSendingMessagesToChild();
@@ -1719,20 +1645,16 @@ ContentParent::MarkAsDead()
 
   mIsAlive = false;
 }
 
 void
 ContentParent::OnChannelError()
 {
   RefPtr<ContentParent> content(this);
-#ifdef MOZ_NUWA_PROCESS
-  // Handle app or Nuwa process exit before normal channel error handling.
-  PreallocatedProcessManager::MaybeForgetSpare(this);
-#endif
   PContentParent::OnChannelError();
 }
 
 void
 ContentParent::OnChannelConnected(int32_t pid)
 {
   SetOtherProcessId(pid);
 
@@ -1924,24 +1846,16 @@ ContentParent::ActorDestroy(ActorDestroy
       obs->RemoveObserver(static_cast<nsIObserver*>(this),
                           sObserverTopics[i]);
     }
   }
 
   // remove the global remote preferences observers
   Preferences::RemoveObserver(this, "");
 
-#ifdef MOZ_NUWA_PROCESS
-  // Remove the pref update requests.
-  if (IsNuwaProcess() && sNuwaPrefUpdates) {
-    delete sNuwaPrefUpdates;
-    sNuwaPrefUpdates = nullptr;
-  }
-#endif
-
   RecvRemoveGeolocationListener();
 
   mConsoleService = nullptr;
 
 #ifdef MOZ_ENABLE_PROFILER_SPS
   if (mGatherer && !mProfile.IsEmpty()) {
     mGatherer->OOPExitProfile(mProfile);
   }
@@ -2193,20 +2107,16 @@ ContentParent::InitializeMembers()
 }
 
 bool
 ContentParent::LaunchSubprocess(ProcessPriority aInitialPriority /* = PROCESS_PRIORITY_FOREGROUND */)
 {
   PROFILER_LABEL_FUNC(js::ProfileEntry::Category::OTHER);
 
   std::vector<std::string> extraArgs;
-  if (mIsNuwaProcess) {
-    extraArgs.push_back("-nuwa");
-  }
-
   if (!mSubprocess->LaunchAndWaitForProcessHandle(extraArgs)) {
     MarkAsDead();
     return false;
   }
 
   Open(mSubprocess->GetChannel(),
      base::GetProcId(mSubprocess->GetChildProcessHandle()));
 
@@ -2222,43 +2132,34 @@ ContentParent::LaunchSubprocess(ProcessP
   SetReplyTimeoutMs(Preferences::GetInt("dom.ipc.cpow.timeout", 0));
 
   return true;
 }
 
 ContentParent::ContentParent(mozIApplication* aApp,
                              ContentParent* aOpener,
                              bool aIsForBrowser,
-                             bool aIsForPreallocated,
-                             bool aIsNuwaProcess /* = false */)
+                             bool aIsForPreallocated)
   : nsIContentParent()
   , mOpener(aOpener)
   , mIsForBrowser(aIsForBrowser)
-  , mIsNuwaProcess(aIsNuwaProcess)
 {
   InitializeMembers();  // Perform common initialization.
 
   // No more than one of !!aApp, aIsForBrowser, aIsForPreallocated should be
   // true.
   MOZ_ASSERT(!!aApp + aIsForBrowser + aIsForPreallocated <= 1);
 
-  // Only the preallocated process uses Nuwa.
-  MOZ_ASSERT_IF(aIsNuwaProcess, aIsForPreallocated);
-
-  if (!aIsNuwaProcess && !aIsForPreallocated) {
-    mMetamorphosed = true;
-  }
+  mMetamorphosed = true;
 
   // Insert ourselves into the global linked list of ContentParent objects.
   if (!sContentParents) {
     sContentParents = new LinkedList<ContentParent>();
   }
-  if (!aIsNuwaProcess) {
-    sContentParents->insertBack(this);
-  }
+  sContentParents->insertBack(this);
 
   if (aApp) {
     aApp->GetManifestURL(mAppManifestURL);
     aApp->GetName(mAppName);
   } else if (aIsForPreallocated) {
     mAppManifestURL = MAGIC_PREALLOCATED_APP_MANIFEST_URL;
   }
 
@@ -2269,93 +2170,20 @@ ContentParent::ContentParent(mozIApplica
 #if defined(XP_WIN) && !defined(MOZ_B2G)
   // Request Windows message deferral behavior on our side of the PContent
   // channel. Generally only applies to the situation where we get caught in
   // a deadlock with the plugin process when sending CPOWs.
   GetIPCChannel()->SetChannelFlags(MessageChannel::REQUIRE_DEFERRED_MESSAGE_PROTECTION);
 #endif
 
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
-  ChildPrivileges privs = aIsNuwaProcess
-    ? base::PRIVILEGES_INHERIT
-    : base::PRIVILEGES_DEFAULT;
+  ChildPrivileges privs = base::PRIVILEGES_DEFAULT;
   mSubprocess = new GeckoChildProcessHost(GeckoProcessType_Content, privs);
 }
 
-#ifdef MOZ_NUWA_PROCESS
-static const mozilla::ipc::FileDescriptor*
-FindFdProtocolFdMapping(const nsTArray<ProtocolFdMapping>& aFds,
-                        ProtocolId aProtoId)
-{
-  for (unsigned int i = 0; i < aFds.Length(); i++) {
-    if (aFds[i].protocolId() == aProtoId) {
-      return &aFds[i].fd();
-    }
-  }
-  return nullptr;
-}
-
-/**
- * This constructor is used for new content process cloned from a template.
- *
- * For Nuwa.
- */
-ContentParent::ContentParent(ContentParent* aTemplate,
-                             const nsAString& aAppManifestURL,
-                             base::ProcessHandle aPid,
-                             InfallibleTArray<ProtocolFdMapping>&& aFds)
-  : mAppManifestURL(aAppManifestURL)
-  , mIsForBrowser(false)
-  , mIsNuwaProcess(false)
-{
-  InitializeMembers();  // Perform common initialization.
-
-  sContentParents->insertBack(this);
-
-  // From this point on, NS_WARNING, NS_ASSERTION, etc. should print out the
-  // PID along with the warning.
-  nsDebugImpl::SetMultiprocessMode("Parent");
-
-  NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
-
-  const FileDescriptor* fd = FindFdProtocolFdMapping(aFds, GetProtocolId());
-
-  NS_ASSERTION(fd != nullptr, "IPC Channel for PContent is necessary!");
-  mSubprocess = new GeckoExistingProcessHost(GeckoProcessType_Content,
-                                             aPid, *fd);
-
-  mSubprocess->LaunchAndWaitForProcessHandle();
-
-  // Clone actors routed by aTemplate for this instance.
-  ProtocolCloneContext cloneContext;
-  cloneContext.SetContentParent(this);
-  CloneManagees(aTemplate, &cloneContext);
-  CloneOpenedToplevels(aTemplate, aFds, aPid, &cloneContext);
-
-  Open(mSubprocess->GetChannel(),
-     base::GetProcId(mSubprocess->GetChildProcessHandle()));
-
-  // Set the subprocess's priority (bg if we're a preallocated process, fg
-  // otherwise).  We do this first because we're likely /lowering/ its CPU and
-  // memory priority, which it has inherited from this process.
-  ProcessPriority priority;
-  if (IsPreallocated()) {
-    priority = PROCESS_PRIORITY_PREALLOC;
-  } else {
-    priority = PROCESS_PRIORITY_FOREGROUND;
-  }
-
-  InitInternal(priority,
-               false, /* Setup Off-main thread compositing */
-               false  /* Send registered chrome */);
-
-  ContentProcessManager::GetSingleton()->AddContentProcess(this);
-}
-#endif  // MOZ_NUWA_PROCESS
-
 ContentParent::~ContentParent()
 {
   if (mForceKillTimer) {
     mForceKillTimer->Cancel();
   }
 
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 
@@ -2367,23 +2195,16 @@ ContentParent::~ContentParent()
   } else {
     // In general, we expect sAppContentParents->Get(mAppManifestURL) to be
     // nullptr.  But it could be that we created another ContentParent for
     // this app after we did this->ActorDestroy(), so the right check is
     // that sAppContentParents->Get(mAppManifestURL) != this.
     MOZ_ASSERT(!sAppContentParents ||
                sAppContentParents->Get(mAppManifestURL) != this);
   }
-
-#ifdef MOZ_NUWA_PROCESS
-  if (IsNuwaProcess()) {
-    sNuwaReady = false;
-    sNuwaPid = 0;
-  }
-#endif
 }
 
 void
 ContentParent::InitInternal(ProcessPriority aInitialPriority,
                             bool aSetupOffMainThreadCompositing,
                             bool aSendRegisteredChrome)
 {
   if (aSendRegisteredChrome) {
@@ -2486,21 +2307,16 @@ ContentParent::InitInternal(ProcessPrior
       URIParams uri;
       SerializeURI(sheet->GetSheetURI(), uri);
       Unused << SendLoadAndRegisterSheet(uri, nsIStyleSheetService::AUTHOR_SHEET);
     }
   }
 
 #ifdef MOZ_CONTENT_SANDBOX
   bool shouldSandbox = true;
-#ifdef MOZ_NUWA_PROCESS
-  if (IsNuwaProcess()) {
-    shouldSandbox = false;
-  }
-#endif
   MaybeFileDesc brokerFd = void_t();
 #ifdef XP_LINUX
   // XXX: Checking the pref here makes it possible to enable/disable sandboxing
   // during an active session. Currently the pref is only used for testing
   // purpose. If the decision is made to permanently rely on the pref, this
   // should be changed so that it is required to restart firefox for the change
   // of value to take effect.
   shouldSandbox = (Preferences::GetInt("security.sandbox.content.level") > 0) &&
@@ -2561,24 +2377,16 @@ ContentParent::IsAlive() const
 }
 
 bool
 ContentParent::IsForApp() const
 {
   return !mAppManifestURL.IsEmpty();
 }
 
-#ifdef MOZ_NUWA_PROCESS
-bool
-ContentParent::IsNuwaProcess() const
-{
-  return mIsNuwaProcess;
-}
-#endif
-
 int32_t
 ContentParent::Pid() const
 {
   if (!mSubprocess || !mSubprocess->GetChildProcessHandle()) {
     return -1;
   }
   return base::GetProcId(mSubprocess->GetChildProcessHandle());
 }
@@ -2875,135 +2683,16 @@ ContentParent::RecvAudioChannelServiceSt
   RefPtr<AudioChannelService> service = AudioChannelService::GetOrCreate();
   MOZ_ASSERT(service);
 
   service->ChildStatusReceived(mChildID, aTelephonyChannel,
                                aContentOrNormalChannel, aAnyChannel);
   return true;
 }
 
-void
-ContentParent::ForkNewProcess(bool aBlocking)
-{
-#ifdef MOZ_NUWA_PROCESS
-  uint32_t pid;
-  auto fds = MakeUnique<nsTArray<ProtocolFdMapping>>();
-
-  MOZ_ASSERT(IsNuwaProcess() && mNuwaParent);
-
-  if (mNuwaParent->ForkNewProcess(pid, mozilla::Move(fds), aBlocking)) {
-    OnNewProcessCreated(pid, mozilla::Move(fds));
-  }
-#else
-  NS_ERROR("ContentParent::ForkNewProcess() not implemented!");
-#endif
-}
-
-#ifdef MOZ_NUWA_PROCESS
-// Keep only observer topics listed in sNuwaSafeObserverTopics and unregister
-// all the other registered topics.
-static void
-KeepNuwaSafeObserverTopics(ContentParent* aNuwaContentParent)
-{
-  MOZ_ASSERT(aNuwaContentParent && aNuwaContentParent->IsNuwaProcess());
-
-  nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
-  if (!obs) {
-      return;
-  }
-
-  size_t topicLength = ArrayLength(sObserverTopics);
-  for (size_t i = 0; i < topicLength; ++i) {
-      bool nuwaSafe = false;
-      size_t safeTopicLength = ArrayLength(sNuwaSafeObserverTopics);
-
-      for (size_t j = 0; j < safeTopicLength; j++) {
-          if (!nsCRT::strcmp(sObserverTopics[i],
-                            sNuwaSafeObserverTopics[j])) {
-              // In the whitelist: don't need to unregister.
-              nuwaSafe = true;
-              break;
-          }
-      }
-
-      if (!nuwaSafe) {
-          obs->RemoveObserver(aNuwaContentParent, sObserverTopics[i]);
-      }
-  }
-}
-#endif
-
-void
-ContentParent::OnNuwaReady()
-{
-#ifdef MOZ_NUWA_PROCESS
-  // Protection from unauthorized IPC message is done in PNuwa protocol.
-  // Just assert that this actor is really for the Nuwa process.
-  MOZ_ASSERT(IsNuwaProcess());
-
-  sNuwaReady = true;
-  KeepNuwaSafeObserverTopics(this);
-
-  PreallocatedProcessManager::OnNuwaReady();
-  return;
-#else
-  NS_ERROR("ContentParent::OnNuwaReady() not implemented!");
-  return;
-#endif
-}
-
-void
-ContentParent::OnNewProcessCreated(uint32_t aPid,
-                                   UniquePtr<nsTArray<ProtocolFdMapping>>&& aFds)
-{
-#ifdef MOZ_NUWA_PROCESS
-  // Protection from unauthorized IPC message is done in PNuwa protocol.
-  // Just assert that this actor is really for the Nuwa process.
-  MOZ_ASSERT(IsNuwaProcess());
-
-  RefPtr<ContentParent> content;
-  content = new ContentParent(this,
-                              MAGIC_PREALLOCATED_APP_MANIFEST_URL,
-                              aPid,
-                              Move(*aFds.get()));
-  content->Init();
-
-  size_t numNuwaPrefUpdates = sNuwaPrefUpdates ?
-                              sNuwaPrefUpdates->Length() : 0;
-  // Resend pref updates to the forked child.
-  for (size_t i = 0; i < numNuwaPrefUpdates; i++) {
-    mozilla::Unused << content->SendPreferenceUpdate(sNuwaPrefUpdates->ElementAt(i));
-  }
-
-  // Update offline settings.
-  bool isOffline, isLangRTL, haveBidiKeyboards;
-  bool isConnected;
-  InfallibleTArray<nsString> unusedDictionaries;
-  ClipboardCapabilities clipboardCaps;
-  DomainPolicyClone domainPolicy;
-  StructuredCloneData initialData;
-
-  RecvGetXPCOMProcessAttributes(&isOffline, &isConnected,
-                                &isLangRTL, &haveBidiKeyboards,
-                                &unusedDictionaries,
-                                &clipboardCaps, &domainPolicy, &initialData);
-  mozilla::Unused << content->SendSetOffline(isOffline);
-  mozilla::Unused << content->SendSetConnectivity(isConnected);
-  MOZ_ASSERT(!clipboardCaps.supportsSelectionClipboard() &&
-             !clipboardCaps.supportsFindClipboard(),
-             "Unexpected values");
-
-  PreallocatedProcessManager::PublishSpareProcess(content);
-  return;
-#else
-  NS_ERROR("ContentParent::OnNewProcessCreated() not implemented!");
-  return;
-#endif
-}
-
 // We want ContentParent to show up in CC logs for debugging purposes, but we
 // don't actually cycle collect it.
 NS_IMPL_CYCLE_COLLECTION_0(ContentParent)
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(ContentParent)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(ContentParent)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ContentParent)
@@ -3052,55 +2741,32 @@ ContentParent::Observe(nsISupports* aSub
       }
     }
   }
 #endif
 
   if (!mIsAlive || !mSubprocess)
     return NS_OK;
 
-  // The Nuwa process unregisters the topics after it becomes ready except for
-  // the ones listed in sNuwaSafeObserverTopics. If the topic needs to be
-  // observed by the Nuwa process, either for:
-  // 1. The topic is safe for the Nuwa process, either:
-  // 1.1 The state can safely happen (only run on the main thread) in the Nuwa
-  //   process (e.g. "a11y-init-or-shutdown"), or
-  // 1.2 The topic doesn't send an IPC message (e.g. "xpcom-shutdown").
-  // 2. The topic needs special handling (e.g. nsPref:Changed),
-  // add the topic to sNuwaSafeObserverTopics and then handle it if necessary.
-
   // listening for memory pressure event
   if (!strcmp(aTopic, "memory-pressure") &&
       !StringEndsWith(nsDependentString(aData),
                       NS_LITERAL_STRING("-no-forward"))) {
       Unused << SendFlushMemory(nsDependentString(aData));
   }
   // listening for remotePrefs...
   else if (!strcmp(aTopic, "nsPref:changed")) {
     // We know prefs are ASCII here.
     NS_LossyConvertUTF16toASCII strData(aData);
 
     PrefSetting pref(strData, null_t(), null_t());
     Preferences::GetPreference(&pref);
-#ifdef MOZ_NUWA_PROCESS
-    if (IsReadyNuwaProcess()) {
-      // Don't send the pref update to the Nuwa process. Save the update
-      // to send to the forked child.
-      if (!sNuwaPrefUpdates) {
-        sNuwaPrefUpdates = new nsTArray<PrefSetting>();
-      }
-      sNuwaPrefUpdates->AppendElement(pref);
-    } else if (!SendPreferenceUpdate(pref)) {
-      return NS_ERROR_NOT_AVAILABLE;
-    }
-#else
     if (!SendPreferenceUpdate(pref)) {
       return NS_ERROR_NOT_AVAILABLE;
     }
-#endif
   }
   else if (!strcmp(aTopic, NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC)) {
     NS_ConvertUTF16toUTF8 dataStr(aData);
     const char *offline = dataStr.get();
     if (!SendSetOffline(!strcmp(offline, "true") ? true : false)) {
       return NS_ERROR_NOT_AVAILABLE;
     }
   }
@@ -3519,21 +3185,16 @@ ContentParent::IsPreallocated() const
 {
   return mAppManifestURL == MAGIC_PREALLOCATED_APP_MANIFEST_URL;
 }
 
 void
 ContentParent::FriendlyName(nsAString& aName, bool aAnonymize)
 {
   aName.Truncate();
-#ifdef MOZ_NUWA_PROCESS
-  if (IsNuwaProcess()) {
-    aName.AssignLiteral("(Nuwa)");
-  } else
-#endif
   if (IsPreallocated()) {
     aName.AssignLiteral("(Preallocated)");
   } else if (mIsForBrowser) {
     aName.AssignLiteral("Browser");
   } else if (aAnonymize) {
     aName.AssignLiteral("<anonymized-name>");
   } else if (!mAppName.IsEmpty()) {
     aName = mAppName;
@@ -4637,20 +4298,16 @@ ContentParent::DoSendAsyncMessage(JSCont
   if (!BuildClonedMessageDataForParent(this, aHelper, data)) {
     return NS_ERROR_DOM_DATA_CLONE_ERR;
   }
   InfallibleTArray<CpowEntry> cpows;
   jsipc::CPOWManager* mgr = GetCPOWManager();
   if (aCpows && (!mgr || !mgr->Wrap(aCx, aCpows, &cpows))) {
     return NS_ERROR_UNEXPECTED;
   }
-  if (IsReadyNuwaProcess()) {
-    // Nuwa won't receive frame messages after it is frozen.
-    return NS_OK;
-  }
   if (!SendAsyncMessage(nsString(aMessage), cpows, Principal(aPrincipal), data)) {
     return NS_ERROR_UNEXPECTED;
   }
   return NS_OK;
 }
 
 bool
 ContentParent::CheckPermission(const nsAString& aPermission)
--- a/dom/ipc/ContentParent.h
+++ b/dom/ipc/ContentParent.h
@@ -2,17 +2,16 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_ContentParent_h
 #define mozilla_dom_ContentParent_h
 
-#include "mozilla/dom/NuwaParent.h"
 #include "mozilla/dom/PContentParent.h"
 #include "mozilla/dom/nsIContentParent.h"
 #include "mozilla/ipc/GeckoChildProcessHost.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/FileUtils.h"
 #include "mozilla/HalTypes.h"
 #include "mozilla/LinkedList.h"
 #include "mozilla/StaticPtr.h"
@@ -96,27 +95,16 @@ class ContentParent final : public PCont
   typedef mozilla::ipc::OptionalURIParams OptionalURIParams;
   typedef mozilla::ipc::PFileDescriptorSetParent PFileDescriptorSetParent;
   typedef mozilla::ipc::TestShellParent TestShellParent;
   typedef mozilla::ipc::URIParams URIParams;
   typedef mozilla::ipc::PrincipalInfo PrincipalInfo;
   typedef mozilla::dom::ClonedMessageData ClonedMessageData;
 
 public:
-#ifdef MOZ_NUWA_PROCESS
-  static int32_t NuwaPid()
-  {
-    return sNuwaPid;
-  }
-
-  static bool IsNuwaReady()
-  {
-    return sNuwaReady;
-  }
-#endif
 
   virtual bool IsContentParent() const override { return true; }
 
   /**
    * Start up the content-process machinery.  This might include
    * scheduling pre-launch tasks.
    */
   static void StartUp();
@@ -146,18 +134,16 @@ public:
                              hal::ProcessPriority::PROCESS_PRIORITY_FOREGROUND,
                              ContentParent* aOpener = nullptr);
 
   /**
    * Create a subprocess suitable for use as a preallocated app process.
    */
   static already_AddRefed<ContentParent> PreallocateAppProcess();
 
-  static already_AddRefed<ContentParent> RunNuwaProcess();
-
   /**
    * Get or create a content process for the given TabContext.  aFrameElement
    * should be the frame/iframe element with which this process will
    * associated.
    */
   static TabParent*
   CreateBrowserOrApp(const TabContext& aContext,
                      Element* aFrameElement,
@@ -362,30 +348,16 @@ public:
 
   virtual bool IsForApp() const override;
 
   virtual bool IsForBrowser() const override
   {
     return mIsForBrowser;
   }
 
-#ifdef MOZ_NUWA_PROCESS
-  bool IsNuwaProcess() const;
-#endif
-
-  // A shorthand for checking if the Nuwa process is ready.
-  bool IsReadyNuwaProcess() const
-  {
-#ifdef MOZ_NUWA_PROCESS
-    return IsNuwaProcess() && IsNuwaReady();
-#else
-    return false;
-#endif
-  }
-
   GeckoChildProcessHost* Process() const
   {
     return mSubprocess;
   }
 
   ContentParent* Opener() const
   {
     return mOpener;
@@ -542,18 +514,16 @@ public:
                                        const IPC::Principal& aPrincipal,
                                        const TabId& aTabId) override;
 
   virtual bool
   DeallocPContentPermissionRequestParent(PContentPermissionRequestParent* actor) override;
 
   virtual bool HandleWindowsMessages(const Message& aMsg) const override;
 
-  void SetNuwaParent(NuwaParent* aNuwaParent) { mNuwaParent = aNuwaParent; }
-
   void ForkNewProcess(bool aBlocking);
 
   virtual bool RecvCreateWindow(PBrowserParent* aThisTabParent,
                                 PBrowserParent* aOpener,
                                 layout::PRenderFrameParent* aRenderFrame,
                                 const uint32_t& aChromeFlags,
                                 const bool& aCalledFromJS,
                                 const bool& aPositionSpecified,
@@ -591,18 +561,16 @@ public:
 
   virtual int32_t Pid() const override;
 
 protected:
   void OnChannelConnected(int32_t pid) override;
 
   virtual void ActorDestroy(ActorDestroyReason why) override;
 
-  void OnNuwaForkTimeout();
-
   bool ShouldContinueFromReplyTimeout() override;
 
 private:
   static nsDataHashtable<nsStringHashKey, ContentParent*> *sAppContentParents;
   static nsTArray<ContentParent*>* sNonAppContentParents;
   static nsTArray<ContentParent*>* sPrivateContent;
   static StaticAutoPtr<LinkedList<ContentParent> > sContentParents;
 
@@ -639,25 +607,17 @@ private:
 
   FORWARD_SHMEM_ALLOCATOR_TO(PContentParent)
 
   // No more than one of !!aApp, aIsForBrowser, and aIsForPreallocated may be
   // true.
   ContentParent(mozIApplication* aApp,
                 ContentParent* aOpener,
                 bool aIsForBrowser,
-                bool aIsForPreallocated,
-                bool aIsNuwaProcess = false);
-
-#ifdef MOZ_NUWA_PROCESS
-  ContentParent(ContentParent* aTemplate,
-                const nsAString& aAppManifestURL,
-                base::ProcessHandle aPid,
-                InfallibleTArray<ProtocolFdMapping>&& aFds);
-#endif
+                bool aIsForPreallocated);
 
   // The common initialization for the constructors.
   void InitializeMembers();
 
   // Launch the subprocess and associated initialization.
   // Returns false if the process fails to start.
   bool LaunchSubprocess(hal::ProcessPriority aInitialPriority = hal::PROCESS_PRIORITY_FOREGROUND);
 
@@ -1056,21 +1016,16 @@ private:
   virtual bool RecvGetSystemMemory(const uint64_t& getterId) override;
 
   virtual bool RecvGetLookAndFeelCache(nsTArray<LookAndFeelInt>* aLookAndFeelIntCache) override;
 
   virtual bool RecvSpeakerManagerGetSpeakerStatus(bool* aValue) override;
 
   virtual bool RecvSpeakerManagerForceSpeaker(const bool& aEnable) override;
 
-  // Callbacks from NuwaParent.
-  void OnNuwaReady();
-  void OnNewProcessCreated(uint32_t aPid,
-                           UniquePtr<nsTArray<ProtocolFdMapping>>&& aFds);
-
   virtual bool RecvCreateFakeVolume(const nsString& aFsName,
                                     const nsString& aMountPoint) override;
 
   virtual bool RecvSetFakeVolumeState(const nsString& aFsName,
                                       const int32_t& aFsState) override;
 
   virtual bool RecvRemoveFakeVolume(const nsString& fsName) override;
 
@@ -1224,53 +1179,40 @@ private:
   bool mIsAlive;
 
   // True only the if process is already a browser or app or has
   // been transformed into one.
   bool mMetamorphosed;
 
   bool mSendPermissionUpdates;
   bool mIsForBrowser;
-  bool mIsNuwaProcess;
 
   // These variables track whether we've called Close() and KillHard() on our
   // channel.
   bool mCalledClose;
   bool mCalledKillHard;
   bool mCreatedPairedMinidumps;
   bool mShutdownPending;
   bool mIPCOpen;
 
   friend class CrashReporterParent;
 
-  // Allows NuwaParent to access OnNuwaReady() and OnNewProcessCreated().
-  friend class NuwaParent;
-
   RefPtr<nsConsoleService>  mConsoleService;
   nsConsoleService* GetConsoleService();
 
   nsTArray<nsCOMPtr<nsIObserver>> mIdleListeners;
 
 #ifdef MOZ_X11
   // Dup of child's X socket, used to scope its resources to this
   // object instead of the child process's lifetime.
   ScopedClose mChildXSocketFdDup;
 #endif
 
-#ifdef MOZ_NUWA_PROCESS
-  static int32_t sNuwaPid;
-  static bool sNuwaReady;
-#endif
-
   PProcessHangMonitorParent* mHangMonitorActor;
 
-  // NuwaParent and ContentParent hold strong references to each other. The
-  // cycle will be broken when either actor is destroyed.
-  RefPtr<NuwaParent> mNuwaParent;
-
 #ifdef MOZ_ENABLE_PROFILER_SPS
   RefPtr<mozilla::ProfileGatherer> mGatherer;
 #endif
   nsCString mProfile;
 
   UniquePtr<gfx::DriverCrashGuard> mDriverCrashGuard;
 
 #if defined(XP_LINUX) && defined(MOZ_CONTENT_SANDBOX)
deleted file mode 100644
--- a/dom/ipc/NuwaChild.cpp
+++ /dev/null
@@ -1,256 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "ContentChild.h"
-#ifdef MOZ_NUWA_PROCESS
-#include "ipc/Nuwa.h"
-#endif
-#include "mozilla/dom/ContentChild.h"
-#include "mozilla/ipc/BackgroundChild.h"
-#include "mozilla/ipc/PBackgroundChild.h"
-#include "mozilla/ipc/ProtocolUtils.h"
-#if defined(MOZ_CONTENT_SANDBOX)
-#if defined(XP_LINUX)
-#include "mozilla/Sandbox.h"
-#include "mozilla/SandboxInfo.h"
-#elif defined(XP_MACOSX)
-#include "mozilla/Sandbox.h"
-#endif
-#endif
-#include "mozilla/unused.h"
-#include "nsXULAppAPI.h"
-#include "NuwaChild.h"
-
-
-using namespace mozilla::ipc;
-using namespace mozilla::dom;
-
-namespace mozilla {
-namespace dom {
-
-#ifdef MOZ_NUWA_PROCESS
-
-namespace {
-
-class CallNuwaSpawn: public Runnable
-{
-public:
-  NS_IMETHOD Run()
-  {
-    NuwaSpawn();
-    if (IsNuwaProcess()) {
-      return NS_OK;
-    }
-
-    // In the new process.
-    ContentChild* child = ContentChild::GetSingleton();
-    child->InitProcessAttributes();
-
-    // Perform other after-fork initializations.
-    InitOnContentProcessCreated();
-
-    return NS_OK;
-  }
-};
-
-static void
-DoNuwaFork()
-{
-  NuwaSpawnPrepare(); // NuwaSpawn will be blocked.
-
-  {
-    nsCOMPtr<nsIRunnable> callSpawn(new CallNuwaSpawn());
-    NS_DispatchToMainThread(callSpawn);
-  }
-
-  // IOThread should be blocked here for waiting NuwaSpawn().
-  NuwaSpawnWait(); // Now! NuwaSpawn can go.
-  // Here, we can make sure the spawning was finished.
-}
-
-/**
- * This function should keep IO thread in a stable state and freeze it
- * until the spawning is finished.
- */
-static void
-RunNuwaFork()
-{
-  if (NuwaCheckpointCurrentThread()) {
-    DoNuwaFork();
-  }
-}
-
-static bool sNuwaForking = false;
-
-void
-NuwaFork()
-{
-  if (sNuwaForking) {           // No reentry.
-      return;
-  }
-  sNuwaForking = true;
-
-  MessageLoop* ioloop = XRE_GetIOMessageLoop();
-  ioloop->PostTask(NewRunnableFunction(RunNuwaFork));
-}
-
-} // Anonymous namespace.
-
-#endif
-
-NuwaChild* NuwaChild::sSingleton;
-
-NuwaChild*
-NuwaChild::GetSingleton()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (!sSingleton) {
-    PNuwaChild* nuwaChild =
-      BackgroundChild::GetForCurrentThread()->SendPNuwaConstructor();
-    MOZ_ASSERT(nuwaChild);
-
-    sSingleton = static_cast<NuwaChild*>(nuwaChild);
-  }
-
-  return sSingleton;
-}
-
-
-bool
-NuwaChild::RecvFork()
-{
-#ifdef MOZ_NUWA_PROCESS
-  if (!IsNuwaProcess()) {
-    NS_ERROR(
-      nsPrintfCString(
-        "Terminating child process %d for unauthorized IPC message: "
-          "RecvFork(%d)", getpid()).get());
-    return false;
-  }
-
-  nsCOMPtr<nsIRunnable> runnable =
-    NS_NewRunnableFunction(&NuwaFork);
-  MOZ_ASSERT(runnable);
-  MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(runnable));
-
-  return true;
-#else
-  NS_ERROR("NuwaChild::RecvFork() not implemented!");
-  return false;
-#endif
-}
-
-} // namespace dom
-} // namespace mozilla
-
-
-extern "C" {
-
-#if defined(MOZ_NUWA_PROCESS)
-NS_EXPORT void
-GetProtoFdInfos(NuwaProtoFdInfo* aInfoList,
-                size_t aInfoListSize,
-                size_t* aInfoSize)
-{
-  size_t i = 0;
-
-  mozilla::dom::ContentChild* content =
-    mozilla::dom::ContentChild::GetSingleton();
-  aInfoList[i].protoId = content->GetProtocolId();
-  aInfoList[i].originFd =
-    content->GetTransport()->GetFileDescriptor();
-  i++;
-
-  IToplevelProtocol* actors[NUWA_TOPLEVEL_MAX];
-  size_t count = content->GetOpenedActorsUnsafe(actors, ArrayLength(actors));
-  for (size_t j = 0; j < count; j++) {
-    IToplevelProtocol* actor = actors[j];
-    if (i >= aInfoListSize) {
-      NS_RUNTIMEABORT("Too many top level protocols!");
-    }
-
-    aInfoList[i].protoId = actor->GetProtocolId();
-    aInfoList[i].originFd =
-      actor->GetTransport()->GetFileDescriptor();
-    i++;
-  }
-
-  if (i > NUWA_TOPLEVEL_MAX) {
-    NS_RUNTIMEABORT("Too many top level protocols!");
-  }
-  *aInfoSize = i;
-}
-
-class RunAddNewIPCProcess : public mozilla::Runnable
-{
-public:
-  RunAddNewIPCProcess(pid_t aPid,
-                      nsTArray<mozilla::ipc::ProtocolFdMapping>& aMaps)
-      : mPid(aPid)
-  {
-    mMaps.SwapElements(aMaps);
-  }
-
-  NS_IMETHOD Run()
-  {
-    NuwaChild::GetSingleton()->SendAddNewProcess(mPid, mMaps);
-
-    MOZ_ASSERT(sNuwaForking);
-    sNuwaForking = false;
-
-    return NS_OK;
-  }
-
-private:
-  pid_t mPid;
-  nsTArray<mozilla::ipc::ProtocolFdMapping> mMaps;
-};
-
-/**
- * AddNewIPCProcess() is called by Nuwa process to tell the parent
- * process that a new process is created.
- *
- * In the newly created process, ResetContentChildTransport() is called to
- * reset fd for the IPC Channel and the session.
- */
-NS_EXPORT void
-AddNewIPCProcess(pid_t aPid, NuwaProtoFdInfo* aInfoList, size_t aInfoListSize)
-{
-  nsTArray<mozilla::ipc::ProtocolFdMapping> maps;
-
-  for (size_t i = 0; i < aInfoListSize; i++) {
-    int _fd = aInfoList[i].newFds[NUWA_NEWFD_PARENT];
-    mozilla::ipc::FileDescriptor fd(_fd);
-    mozilla::ipc::ProtocolFdMapping map(aInfoList[i].protoId, fd);
-    maps.AppendElement(map);
-  }
-
-  RefPtr<RunAddNewIPCProcess> runner = new RunAddNewIPCProcess(aPid, maps);
-  NS_DispatchToMainThread(runner);
-}
-
-NS_EXPORT void
-OnNuwaProcessReady()
-{
-  NuwaChild* nuwaChild = NuwaChild::GetSingleton();
-  MOZ_ASSERT(nuwaChild);
-
-  mozilla::Unused << nuwaChild->SendNotifyReady();
-}
-
-NS_EXPORT void
-AfterNuwaFork()
-{
-  SetCurrentProcessPrivileges(base::PRIVILEGES_DEFAULT);
-#if defined(XP_LINUX) && defined(MOZ_SANDBOX)
-  mozilla::SandboxEarlyInit(XRE_GetProcessType(), /* isNuwa: */ false);
-#endif
-}
-
-#endif // MOZ_NUWA_PROCESS
-
-}
deleted file mode 100644
--- a/dom/ipc/NuwaChild.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef mozilla_dom_NuwaChild_h
-#define mozilla_dom_NuwaChild_h
-
-#include "mozilla/Assertions.h"
-#include "mozilla/dom/PNuwaChild.h"
-#include "nsThreadUtils.h"
-
-namespace mozilla {
-namespace dom {
-class NuwaChild: public mozilla::dom::PNuwaChild
-{
-public:
-  virtual bool RecvFork() override;
-
-  virtual void ActorDestroy(ActorDestroyReason aWhy) override
-  { }
-
-  static NuwaChild* GetSingleton();
-
-private:
-  static NuwaChild* sSingleton;
-};
-
-} // namespace dom
-} // namespace mozilla
-
-#endif // mozilla_dom_NuwaChild_h
deleted file mode 100644
--- a/dom/ipc/NuwaParent.cpp
+++ /dev/null
@@ -1,260 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "mozilla/dom/ContentParent.h"
-#include "mozilla/ipc/BackgroundParent.h"
-#include "mozilla/ipc/PBackgroundParent.h"
-#include "mozilla/unused.h"
-#include "nsThreadUtils.h"
-#include "NuwaParent.h"
-
-using namespace mozilla::ipc;
-using namespace mozilla::dom;
-using namespace IPC;
-
-namespace mozilla {
-namespace dom {
-
-/*static*/ NuwaParent*
-NuwaParent::Alloc() {
-  RefPtr<NuwaParent> actor = new NuwaParent();
-  return actor.forget().take();
-}
-
-/*static*/ bool
-NuwaParent::ActorConstructed(mozilla::dom::PNuwaParent *aActor)
-{
-  NuwaParent* actor = static_cast<NuwaParent*>(aActor);
-  actor->ActorConstructed();
-
-  return true;
-}
-
-/*static*/ bool
-NuwaParent::Dealloc(mozilla::dom::PNuwaParent *aActor)
-{
-  RefPtr<NuwaParent> actor = dont_AddRef(static_cast<NuwaParent*>(aActor));
-  return true;
-}
-
-NuwaParent::NuwaParent()
-  : mBlocked(false)
-  , mMonitor("NuwaParent")
-  , mClonedActor(nullptr)
-  , mWorkerThread(do_GetCurrentThread())
-  , mNewProcessPid(0)
-{
-  AssertIsOnBackgroundThread();
-}
-
-NuwaParent::~NuwaParent()
-{
-  // Both the worker thread and the main thread (ContentParent) hold a ref to
-  // this. The instance may be destroyed on either thread.
-  MOZ_ASSERT(!mContentParent);
-}
-
-inline void
-NuwaParent::AssertIsOnWorkerThread()
-{
-  nsCOMPtr<nsIThread> currentThread = do_GetCurrentThread();
-  MOZ_ASSERT(currentThread ==  mWorkerThread);
-}
-
-bool
-NuwaParent::ActorConstructed()
-{
-  AssertIsOnWorkerThread();
-  MOZ_ASSERT(Manager());
-  MOZ_ASSERT(!mContentParent);
-
-  mContentParent = BackgroundParent::GetContentParent(Manager());
-  if (!mContentParent) {
-    return false;
-  }
-
-  // mContentParent is guaranteed to be alive. It's safe to set its backward ref
-  // to this.
-  mContentParent->SetNuwaParent(this);
-  return true;
-}
-
-mozilla::ipc::IProtocol*
-NuwaParent::CloneProtocol(Channel* aChannel,
-                          ProtocolCloneContext* aCtx)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  RefPtr<NuwaParent> self = this;
-
-  MonitorAutoLock lock(mMonitor);
-
-  // Alloc NuwaParent on the worker thread.
-  nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction([self] () -> void
-  {
-    MonitorAutoLock lock(self->mMonitor);
-    // XXX Calling NuwaParent::Alloc() leads to a compilation error. Use
-    // self->Alloc() as a workaround.
-    self->mClonedActor = self->Alloc();
-    lock.Notify();
-  });
-  MOZ_ASSERT(runnable);
-  MOZ_ALWAYS_SUCCEEDS(mWorkerThread->Dispatch(runnable, NS_DISPATCH_NORMAL));
-
-  while (!mClonedActor) {
-    lock.Wait();
-  }
-  RefPtr<NuwaParent> actor = mClonedActor;
-  mClonedActor = nullptr;
-
-  // mManager of the cloned actor is assigned after returning from this method.
-  // We can't call ActorConstructed() right after Alloc() in the above runnable.
-  // To be safe we dispatch a runnable to the current thread to do it.
-  runnable = NS_NewRunnableFunction([actor] () -> void
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    nsCOMPtr<nsIRunnable> nested = NS_NewRunnableFunction([actor] () -> void
-    {
-      AssertIsOnBackgroundThread();
-
-      // Call NuwaParent::ActorConstructed() on the worker thread.
-      actor->ActorConstructed();
-
-      // The actor can finally be deleted after fully constructed.
-      mozilla::Unused << actor->Send__delete__(actor);
-    });
-    MOZ_ASSERT(nested);
-    MOZ_ALWAYS_SUCCEEDS(actor->mWorkerThread->Dispatch(nested, NS_DISPATCH_NORMAL));
-  });
-
-  MOZ_ASSERT(runnable);
-  MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(runnable));
-
-  return actor;
-}
-
-void
-NuwaParent::ActorDestroy(ActorDestroyReason aWhy)
-{
-  AssertIsOnWorkerThread();
-
-  RefPtr<NuwaParent> self = this;
-  nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction([self] () -> void
-  {
-    // These extra nsRefPtr serve as kungFuDeathGrip to keep both objects from
-    // deletion in breaking the ref cycle.
-    RefPtr<ContentParent> contentParent = self->mContentParent;
-
-    contentParent->SetNuwaParent(nullptr);
-    // Need to clear the ref to ContentParent on the main thread.
-    self->mContentParent = nullptr;
-  });
-  MOZ_ASSERT(runnable);
-  MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(runnable));
-}
-
-bool
-NuwaParent::RecvNotifyReady()
-{
-#ifdef MOZ_NUWA_PROCESS
-  if (!mContentParent || !mContentParent->IsNuwaProcess()) {
-    NS_ERROR("Received NotifyReady() message from a non-Nuwa process.");
-    return false;
-  }
-
-  // Creating a NonOwningRunnableMethod here is safe because refcount changes of
-  // mContentParent have to go the the main thread. The mContentParent will
-  // be alive when the runnable runs.
-  nsCOMPtr<nsIRunnable> runnable =
-    NewNonOwningRunnableMethod(mContentParent.get(),
-                                  &ContentParent::OnNuwaReady);
-  MOZ_ASSERT(runnable);
-  MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(runnable));
-
-  return true;
-#else
-  NS_ERROR("NuwaParent::RecvNotifyReady() not implemented!");
-  return false;
-#endif
-}
-
-bool
-NuwaParent::RecvAddNewProcess(const uint32_t& aPid,
-                              nsTArray<ProtocolFdMapping>&& aFds)
-{
-#ifdef MOZ_NUWA_PROCESS
-  if (!mContentParent || !mContentParent->IsNuwaProcess()) {
-    NS_ERROR("Received AddNewProcess() message from a non-Nuwa process.");
-    return false;
-  }
-
-  mNewProcessPid = aPid;
-  mNewProcessFds->SwapElements(aFds);
-  MonitorAutoLock lock(mMonitor);
-  if (mBlocked) {
-    // Unblock ForkNewProcess().
-    mMonitor.Notify();
-    mBlocked = false;
-  } else {
-    nsCOMPtr<nsIRunnable> runnable =
-      NewNonOwningRunnableMethod<
-        uint32_t,
-        UniquePtr<nsTArray<ProtocolFdMapping>>&& >(
-          mContentParent.get(),
-          &ContentParent::OnNewProcessCreated,
-          mNewProcessPid,
-          Move(mNewProcessFds));
-    MOZ_ASSERT(runnable);
-    MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(runnable));
-  }
-  return true;
-#else
-  NS_ERROR("NuwaParent::RecvAddNewProcess() not implemented!");
-  return false;
-#endif
-}
-
-bool
-NuwaParent::ForkNewProcess(uint32_t& aPid,
-                           UniquePtr<nsTArray<ProtocolFdMapping>>&& aFds,
-                           bool aBlocking)
-{
-  MOZ_ASSERT(mWorkerThread);
-  MOZ_ASSERT(NS_IsMainThread());
-
-  mNewProcessFds = Move(aFds);
-
-  RefPtr<NuwaParent> self = this;
-  nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction([self] () -> void
-  {
-    mozilla::Unused << self->SendFork();
-  });
-  MOZ_ASSERT(runnable);
-  MOZ_ALWAYS_SUCCEEDS(mWorkerThread->Dispatch(runnable, NS_DISPATCH_NORMAL));
-  if (!aBlocking) {
-    return false;
-  }
-
-  MonitorAutoLock lock(mMonitor);
-  mBlocked = true;
-  while (mBlocked) {
-    // This will be notified in NuwaParent::RecvAddNewProcess().
-    lock.Wait();
-  }
-
-  if (!mNewProcessPid) {
-    return false;
-  }
-
-  aPid = mNewProcessPid;
-  aFds = Move(mNewProcessFds);
-
-  mNewProcessPid = 0;
-  return true;
-}
-
-} // namespace dom
-} // namespace mozilla
deleted file mode 100644
--- a/dom/ipc/NuwaParent.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef mozilla_dom_NuwaParent_h
-#define mozilla_dom_NuwaParent_h
-
-#include "base/message_loop.h"
-#include "mozilla/dom/PNuwaParent.h"
-#include "mozilla/Monitor.h"
-#include "mozilla/RefPtr.h"
-
-namespace mozilla {
-namespace dom {
-
-class ContentParent;
-
-class NuwaParent : public mozilla::dom::PNuwaParent
-{
-public:
-  explicit NuwaParent();
-
-  // Called on the main thread.
-  bool ForkNewProcess(uint32_t& aPid,
-                      UniquePtr<nsTArray<ProtocolFdMapping>>&& aFds,
-                      bool aBlocking);
-
-  // Called on the background thread.
-  bool ActorConstructed();
-
-  // Both the worker thread and the main thread hold a ref to this.
-  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(NuwaParent)
-
-  // Functions to be invoked by the manager of this actor to alloc/dealloc the
-  // actor.
-  static NuwaParent* Alloc();
-  static bool ActorConstructed(mozilla::dom::PNuwaParent *aActor);
-  static bool Dealloc(mozilla::dom::PNuwaParent *aActor);
-
-protected:
-  virtual ~NuwaParent();
-
-  virtual bool RecvNotifyReady() override;
-  virtual bool RecvAddNewProcess(const uint32_t& aPid,
-                                 nsTArray<ProtocolFdMapping>&& aFds) override;
-  virtual mozilla::ipc::IProtocol*
-  CloneProtocol(Channel* aChannel,
-                ProtocolCloneContext* aCtx) override;
-
-  virtual void ActorDestroy(ActorDestroyReason aWhy) override;
-
-private:
-  void AssertIsOnWorkerThread();
-
-  bool mBlocked;
-  mozilla::Monitor mMonitor;
-  NuwaParent* mClonedActor;
-
-  nsCOMPtr<nsIThread> mWorkerThread;
-
-  uint32_t mNewProcessPid;
-  UniquePtr<nsTArray<ProtocolFdMapping>> mNewProcessFds;
-
-  // The mutual reference will be broken on the main thread.
-  RefPtr<ContentParent> mContentParent;
-};
-
-} // namespace dom
-} // namespace mozilla
-
-#endif // mozilla_dom_NuwaParent_h
deleted file mode 100644
--- a/dom/ipc/PNuwa.ipdl
+++ /dev/null
@@ -1,31 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-include protocol PBackground;
-include ProtocolTypes;
-
-namespace mozilla {
-namespace dom {
-
-sync protocol PNuwa
-{
-  manager PBackground;
-
-child:
-  // Ask the Nuwa process to create a new child process.
-  async Fork();
-
-  // This message will be sent to non-Nuwa process, or to Nuwa process during
-  // test.
-  async __delete__();
-
-parent:
-  async NotifyReady();
-  sync AddNewProcess(uint32_t pid, ProtocolFdMapping[] aFds);
-};
-
-} // namespace layout
-} // namespace mozilla
-
--- a/dom/ipc/PreallocatedProcessManager.cpp
+++ b/dom/ipc/PreallocatedProcessManager.cpp
@@ -9,29 +9,20 @@
 #include "mozilla/Preferences.h"
 #include "mozilla/unused.h"
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/ScriptSettings.h"
 #include "nsIPropertyBag2.h"
 #include "ProcessPriorityManager.h"
 #include "nsServiceManagerUtils.h"
 
-#ifdef MOZ_NUWA_PROCESS
-#include "ipc/Nuwa.h"
-#endif
-
-#ifdef MOZ_B2G_LOADER
-#include "ProcessUtils.h"
-#endif
-
 // This number is fairly arbitrary ... the intention is to put off
 // launching another app process until the last one has finished
 // loading its content, to reduce CPU/memory/IO contention.
 #define DEFAULT_ALLOCATE_DELAY 1000
-#define NUWA_FORK_WAIT_DURATION_MS 2000 // 2 seconds.
 
 using namespace mozilla;
 using namespace mozilla::hal;
 using namespace mozilla::dom;
 
 namespace {
 
 /**
@@ -48,41 +39,16 @@ public:
   NS_DECL_NSIOBSERVER
 
   // See comments on PreallocatedProcessManager for these methods.
   void AllocateAfterDelay();
   void AllocateOnIdle();
   void AllocateNow();
   already_AddRefed<ContentParent> Take();
 
-#ifdef MOZ_NUWA_PROCESS
-public:
-  void ScheduleDelayedNuwaFork();
-  void DelayedNuwaFork();
-  void PublishSpareProcess(ContentParent* aContent);
-  void MaybeForgetSpare(ContentParent* aContent);
-  bool IsNuwaReady();
-  void OnNuwaReady();
-  bool PreallocatedProcessReady();
-  already_AddRefed<ContentParent> GetSpareProcess();
-
-private:
-  void NuwaFork();
-
-  // initialization off the critical path of app startup.
-  CancelableRunnable* mPreallocateAppProcessTask;
-
-  // The array containing the preallocated processes. 4 as the inline storage size
-  // should be enough so we don't need to grow the AutoTArray.
-  AutoTArray<RefPtr<ContentParent>, 4> mSpareProcesses;
-
-  // Nuwa process is ready for creating new process.
-  bool mIsNuwaReady;
-#endif
-
 private:
   static mozilla::StaticRefPtr<PreallocatedProcessManagerImpl> sSingleton;
 
   PreallocatedProcessManagerImpl();
   ~PreallocatedProcessManagerImpl() {}
   DISALLOW_EVIL_CONSTRUCTORS(PreallocatedProcessManagerImpl);
 
   void Init();
@@ -112,41 +78,31 @@ PreallocatedProcessManagerImpl::Singleto
 
   return sSingleton;
 }
 
 NS_IMPL_ISUPPORTS(PreallocatedProcessManagerImpl, nsIObserver)
 
 PreallocatedProcessManagerImpl::PreallocatedProcessManagerImpl()
   :
-#ifdef MOZ_NUWA_PROCESS
-    mPreallocateAppProcessTask(nullptr)
-  , mIsNuwaReady(false)
-  ,
-#endif
     mEnabled(false)
   , mShutdown(false)
 {}
 
 void
 PreallocatedProcessManagerImpl::Init()
 {
   Preferences::AddStrongObserver(this, "dom.ipc.processPrelaunch.enabled");
   nsCOMPtr<nsIObserverService> os = services::GetObserverService();
   if (os) {
     os->AddObserver(this, "ipc:content-shutdown",
                     /* weakRef = */ false);
     os->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID,
                     /* weakRef = */ false);
   }
-#ifdef MOZ_B2G_LOADER
-  if (!mozilla::ipc::ProcLoaderIsInitialized()) {
-    Disable();
-  } else
-#endif
   {
     RereadPrefs();
   }
 }
 
 NS_IMETHODIMP
 PreallocatedProcessManagerImpl::Observe(nsISupports* aSubject,
                                         const char* aTopic,
@@ -185,21 +141,17 @@ PreallocatedProcessManagerImpl::Take()
 void
 PreallocatedProcessManagerImpl::Enable()
 {
   if (mEnabled) {
     return;
   }
 
   mEnabled = true;
-#ifdef MOZ_NUWA_PROCESS
-  ScheduleDelayedNuwaFork();
-#else
   AllocateAfterDelay();
-#endif
 }
 
 void
 PreallocatedProcessManagerImpl::AllocateAfterDelay()
 {
   if (!mEnabled || mPreallocatedAppProcess) {
     return;
   }
@@ -225,210 +177,26 @@ PreallocatedProcessManagerImpl::Allocate
 {
   if (!mEnabled || mPreallocatedAppProcess) {
     return;
   }
 
   mPreallocatedAppProcess = ContentParent::PreallocateAppProcess();
 }
 
-#ifdef MOZ_NUWA_PROCESS
-
-void
-PreallocatedProcessManagerImpl::ScheduleDelayedNuwaFork()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (mPreallocateAppProcessTask) {
-    // Make sure there is only one request running.
-    return;
-  }
-
-  RefPtr<CancelableRunnable> task = NewCancelableRunnableMethod(
-    this, &PreallocatedProcessManagerImpl::DelayedNuwaFork);
-  mPreallocateAppProcessTask = task;
-  MessageLoop::current()->PostDelayedTask(task.forget(),
-    Preferences::GetUint("dom.ipc.processPrelaunch.delayMs",
-                         DEFAULT_ALLOCATE_DELAY));
-}
-
-void
-PreallocatedProcessManagerImpl::DelayedNuwaFork()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  mPreallocateAppProcessTask = nullptr;
-
-  if (!mIsNuwaReady) {
-    if (!mPreallocatedAppProcess && !mShutdown && mEnabled) {
-      mPreallocatedAppProcess = ContentParent::RunNuwaProcess();
-    }
-    // else mPreallocatedAppProcess is starting. It will NuwaFork() when ready.
-  } else if (mSpareProcesses.IsEmpty()) {
-    NuwaFork();
-  }
-}
-
-/**
- * Get a spare ContentParent from mSpareProcesses list.
- */
-already_AddRefed<ContentParent>
-PreallocatedProcessManagerImpl::GetSpareProcess()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (!mIsNuwaReady) {
-    return nullptr;
-  }
-
-  if (mSpareProcesses.IsEmpty()) {
-    // After this call, there should be a spare process.
-    mPreallocatedAppProcess->ForkNewProcess(true);
-  }
-
-  RefPtr<ContentParent> process = mSpareProcesses.LastElement();
-  mSpareProcesses.RemoveElementAt(mSpareProcesses.Length() - 1);
-
-  if (mSpareProcesses.IsEmpty() && mIsNuwaReady) {
-    NS_ASSERTION(mPreallocatedAppProcess != nullptr,
-                 "Nuwa process is not present!");
-    ScheduleDelayedNuwaFork();
-  }
-
-  return process.forget();
-}
-
-static bool
-TestCaseEnabled()
-{
-  return Preferences::GetBool("dom.ipc.preallocatedProcessManager.testMode");
-}
-
-static void
-SendTestOnlyNotification(const char* aMessage)
-{
-  if (!TestCaseEnabled()) {
-    return;
-  }
-
-  AutoSafeJSContext cx;
-  nsString message;
-  message.AppendPrintf("%s", aMessage);
-
-  nsCOMPtr<nsIMessageBroadcaster> ppmm =
-    do_GetService("@mozilla.org/parentprocessmessagemanager;1");
-
-  mozilla::Unused << ppmm->BroadcastAsyncMessage(
-      message, JS::NullHandleValue, JS::NullHandleValue, cx, 1);
-}
-
-static void
-KillOrCloseProcess(ContentParent* aProcess)
-{
-  if (TestCaseEnabled()) {
-    // KillHard() the process because we don't want the process to abort when we
-    // close the IPC channel while it's still running and creating actors.
-    aProcess->KillHard("Killed by test case.");
-  }
-  else {
-    aProcess->Close();
-  }
-}
-
-/**
- * Publish a ContentParent to spare process list.
- */
-void
-PreallocatedProcessManagerImpl::PublishSpareProcess(ContentParent* aContent)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  SendTestOnlyNotification("TEST-ONLY:nuwa-add-new-process");
-
-  mSpareProcesses.AppendElement(aContent);
-}
-
-void
-PreallocatedProcessManagerImpl::MaybeForgetSpare(ContentParent* aContent)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (mSpareProcesses.RemoveElement(aContent)) {
-    return;
-  }
-
-  if (aContent == mPreallocatedAppProcess) {
-    mPreallocatedAppProcess = nullptr;
-    mIsNuwaReady = false;
-    while (mSpareProcesses.Length() > 0) {
-      RefPtr<ContentParent> process = mSpareProcesses[mSpareProcesses.Length() - 1];
-      KillOrCloseProcess(aContent);
-      mSpareProcesses.RemoveElementAt(mSpareProcesses.Length() - 1);
-    }
-    ScheduleDelayedNuwaFork();
-  }
-}
-
-bool
-PreallocatedProcessManagerImpl::IsNuwaReady()
-{
-  return mIsNuwaReady;
-}
-
-void
-PreallocatedProcessManagerImpl::OnNuwaReady()
-{
-  NS_ASSERTION(!mIsNuwaReady, "Multiple Nuwa processes created!");
-  ProcessPriorityManager::SetProcessPriority(mPreallocatedAppProcess,
-                                             hal::PROCESS_PRIORITY_MASTER);
-  mIsNuwaReady = true;
-  SendTestOnlyNotification("TEST-ONLY:nuwa-ready");
-
-  NuwaFork();
-}
-
-bool
-PreallocatedProcessManagerImpl::PreallocatedProcessReady()
-{
-  return !mSpareProcesses.IsEmpty();
-}
-
-void
-PreallocatedProcessManagerImpl::NuwaFork()
-{
-  mPreallocatedAppProcess->ForkNewProcess(false);
-}
-#endif
-
 void
 PreallocatedProcessManagerImpl::Disable()
 {
   if (!mEnabled) {
     return;
   }
 
   mEnabled = false;
 
-#ifdef MOZ_NUWA_PROCESS
-  // Cancel pending fork.
-  if (mPreallocateAppProcessTask) {
-    mPreallocateAppProcessTask->Cancel();
-    mPreallocateAppProcessTask = nullptr;
-  }
-#endif
-
   if (mPreallocatedAppProcess) {
-#ifdef MOZ_NUWA_PROCESS
-    while (mSpareProcesses.Length() > 0){
-      RefPtr<ContentParent> process = mSpareProcesses[0];
-      KillOrCloseProcess(process);
-      mSpareProcesses.RemoveElementAt(0);
-    }
-    mIsNuwaReady = false;
-#endif
     mPreallocatedAppProcess->Close();
     mPreallocatedAppProcess = nullptr;
   }
 }
 
 void
 PreallocatedProcessManagerImpl::ObserveProcessShutdown(nsISupports* aSubject)
 {
@@ -455,21 +223,17 @@ inline PreallocatedProcessManagerImpl* G
 
 } // namespace
 
 namespace mozilla {
 
 /* static */ void
 PreallocatedProcessManager::AllocateAfterDelay()
 {
-#ifdef MOZ_NUWA_PROCESS
-  GetPPMImpl()->ScheduleDelayedNuwaFork();
-#else
   GetPPMImpl()->AllocateAfterDelay();
-#endif
 }
 
 /* static */ void
 PreallocatedProcessManager::AllocateOnIdle()
 {
   GetPPMImpl()->AllocateOnIdle();
 }
 
@@ -477,49 +241,12 @@ PreallocatedProcessManager::AllocateOnId
 PreallocatedProcessManager::AllocateNow()
 {
   GetPPMImpl()->AllocateNow();
 }
 
 /* static */ already_AddRefed<ContentParent>
 PreallocatedProcessManager::Take()
 {
-#ifdef MOZ_NUWA_PROCESS
-  return GetPPMImpl()->GetSpareProcess();
-#else
   return GetPPMImpl()->Take();
-#endif
-}
-
-#ifdef MOZ_NUWA_PROCESS
-/* static */ void
-PreallocatedProcessManager::PublishSpareProcess(ContentParent* aContent)
-{
-  GetPPMImpl()->PublishSpareProcess(aContent);
-}
-
-/* static */ void
-PreallocatedProcessManager::MaybeForgetSpare(ContentParent* aContent)
-{
-  GetPPMImpl()->MaybeForgetSpare(aContent);
 }
 
-/* static */ void
-PreallocatedProcessManager::OnNuwaReady()
-{
-  GetPPMImpl()->OnNuwaReady();
-}
-
-/* static */ bool
-PreallocatedProcessManager::IsNuwaReady()
-{
-  return GetPPMImpl()->IsNuwaReady();
-}
-
-/*static */ bool
-PreallocatedProcessManager::PreallocatedProcessReady()
-{
-  return GetPPMImpl()->PreallocatedProcessReady();
-}
-
-#endif
-
 } // namespace mozilla
--- a/dom/ipc/PreallocatedProcessManager.h
+++ b/dom/ipc/PreallocatedProcessManager.h
@@ -73,24 +73,16 @@ public:
    * null.
    *
    * After you Take() the preallocated process, you need to call one of the
    * Allocate* functions (or change the dom.ipc.processPrelaunch pref from
    * false to true) before we'll create a new process.
    */
   static already_AddRefed<ContentParent> Take();
 
-#ifdef MOZ_NUWA_PROCESS
-  static void PublishSpareProcess(ContentParent* aContent);
-  static void MaybeForgetSpare(ContentParent* aContent);
-  static bool IsNuwaReady();
-  static void OnNuwaReady();
-  static bool PreallocatedProcessReady();
-#endif
-
 private:
   PreallocatedProcessManager();
   DISALLOW_EVIL_CONSTRUCTORS(PreallocatedProcessManager);
 };
 
 } // namespace mozilla
 
 #endif // defined mozilla_PreallocatedProcessManager_h
--- a/dom/ipc/ProcessPriorityManager.cpp
+++ b/dom/ipc/ProcessPriorityManager.cpp
@@ -521,23 +521,16 @@ ProcessPriorityManagerImpl::Observe(
 
   return NS_OK;
 }
 
 already_AddRefed<ParticularProcessPriorityManager>
 ProcessPriorityManagerImpl::GetParticularProcessPriorityManager(
   ContentParent* aContentParent)
 {
-#ifdef MOZ_NUWA_PROCESS
-  // Do not attempt to change the priority of the Nuwa process
-  if (aContentParent->IsNuwaProcess()) {
-    return nullptr;
-  }
-#endif
-
   RefPtr<ParticularProcessPriorityManager> pppm;
   uint64_t cpId = aContentParent->ChildID();
   mParticularManagers.Get(cpId, &pppm);
   if (!pppm) {
     pppm = new ParticularProcessPriorityManager(aContentParent, sFrozen);
     pppm->Init();
     mParticularManagers.Put(cpId, pppm);
 
--- a/dom/ipc/TabChild.cpp
+++ b/dom/ipc/TabChild.cpp
@@ -19,19 +19,16 @@
 #include "mozilla/BrowserElementParent.h"
 #include "mozilla/ClearOnShutdown.h"
 #include "mozilla/EventListenerManager.h"
 #include "mozilla/dom/indexedDB/PIndexedDBPermissionRequestChild.h"
 #include "mozilla/plugins/PluginWidgetChild.h"
 #include "mozilla/IMEStateManager.h"
 #include "mozilla/ipc/DocumentRendererChild.h"
 #include "mozilla/ipc/URIUtils.h"
-#ifdef MOZ_NUWA_PROCESS
-#include "ipc/Nuwa.h"
-#endif
 #include "mozilla/ipc/FileDescriptorUtils.h"
 #include "mozilla/layers/APZChild.h"
 #include "mozilla/layers/APZCCallbackHelper.h"
 #include "mozilla/layers/APZCTreeManager.h"
 #include "mozilla/layers/APZEventState.h"
 #include "mozilla/layers/CompositorBridgeChild.h"
 #include "mozilla/layers/DoubleTapToZoom.h"
 #include "mozilla/layers/ImageBridgeChild.h"
@@ -451,51 +448,16 @@ PreloadSlowThingsPostFork(void* aUnused)
         doc->FlushPendingNotifications(Flush_Layout);
         // ... but after it's done, make sure it doesn't do any more
         // work.
         presShell->MakeZombie();
     }
 
 }
 
-#ifdef MOZ_NUWA_PROCESS
-class MessageChannelAutoBlock MOZ_STACK_CLASS
-{
-public:
-    MessageChannelAutoBlock()
-    {
-        SetMessageChannelBlocked(true);
-    }
-
-    ~MessageChannelAutoBlock()
-    {
-        SetMessageChannelBlocked(false);
-    }
-
-private:
-    void SetMessageChannelBlocked(bool aBlock)
-    {
-        if (!IsNuwaProcess()) {
-            return;
-        }
-
-        mozilla::dom::ContentChild* content =
-            mozilla::dom::ContentChild::GetSingleton();
-        if (aBlock) {
-            content->GetIPCChannel()->Block();
-        } else {
-            content->GetIPCChannel()->Unblock();
-        }
-
-        // Other IPC channels do not perform the checks through Block() and
-        // Unblock().
-    }
-};
-#endif
-
 static bool sPreloaded = false;
 
 /*static*/ void
 TabChild::PreloadSlowThings()
 {
     if (sPreloaded) {
         // If we are alredy initialized in Nuwa, don't redo preloading.
         return;
@@ -508,41 +470,27 @@ TabChild::PreloadSlowThings()
     RefPtr<TabChild> tab(new TabChild(nullptr,
                                         TabId(0),
                                         TabContext(), /* chromeFlags */ 0));
     if (!NS_SUCCEEDED(tab->Init()) ||
         !tab->InitTabChildGlobal(DONT_LOAD_SCRIPTS)) {
         return;
     }
 
-#ifdef MOZ_NUWA_PROCESS
-    // Temporarily block the IPC channels to the chrome process when we are
-    // preloading.
-    MessageChannelAutoBlock autoblock;
-#endif
-
     // Just load and compile these scripts, but don't run them.
     tab->TryCacheLoadAndCompileScript(BROWSER_ELEMENT_CHILD_SCRIPT, true);
     // Load, compile, and run these scripts.
     tab->RecvLoadRemoteScript(
         NS_LITERAL_STRING("chrome://global/content/preload.js"),
         true);
 
     sPreallocatedTab = tab;
     ClearOnShutdown(&sPreallocatedTab);
 
-#ifdef MOZ_NUWA_PROCESS
-    if (IsNuwaProcess()) {
-        NuwaAddFinalConstructor(PreloadSlowThingsPostFork, nullptr);
-    } else {
-        PreloadSlowThingsPostFork(nullptr);
-    }
-#else
     PreloadSlowThingsPostFork(nullptr);
-#endif
 }
 
 /*static*/ already_AddRefed<TabChild>
 TabChild::Create(nsIContentChild* aManager,
                  const TabId& aTabId,
                  const TabContext &aContext,
                  uint32_t aChromeFlags)
 {
--- a/dom/ipc/TabContext.h
+++ b/dom/ipc/TabContext.h
@@ -5,16 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_TabContext_h
 #define mozilla_dom_TabContext_h
 
 #include "mozIApplication.h"
 #include "nsCOMPtr.h"
 #include "mozilla/BasePrincipal.h"
+#include "nsPIDOMWindow.h"
 #include "nsPIWindowRoot.h"
 
 namespace mozilla {
 namespace dom {
 
 class IPCTabContext;
 
 /**
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -56,16 +56,17 @@
 #include "nsIDOMEvent.h"
 #include "nsIDOMWindow.h"
 #include "nsIDOMWindowUtils.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsILoadInfo.h"
 #include "nsPrincipal.h"
 #include "nsIPromptFactory.h"
 #include "nsIURI.h"
+#include "nsIWindowWatcher.h"
 #include "nsIWebBrowserChrome.h"
 #include "nsIXULBrowserWindow.h"
 #include "nsIXULWindow.h"
 #include "nsIRemoteBrowser.h"
 #include "nsViewManager.h"
 #include "nsVariant.h"
 #include "nsIWidget.h"
 #ifndef XP_WIN
@@ -103,16 +104,18 @@ using namespace mozilla::dom;
 using namespace mozilla::ipc;
 using namespace mozilla::layers;
 using namespace mozilla::layout;
 using namespace mozilla::services;
 using namespace mozilla::widget;
 using namespace mozilla::jsipc;
 using namespace mozilla::gfx;
 
+using mozilla::Unused;
+
 // The flags passed by the webProgress notifications are 16 bits shifted
 // from the ones registered by webProgressListeners.
 #define NOTIFY_FLAG_SHIFT 16
 
 class OpenFileAndSendFDRunnable : public mozilla::Runnable
 {
     const nsString mPath;
     RefPtr<TabParent> mTabParent;
--- a/dom/ipc/moz.build
+++ b/dom/ipc/moz.build
@@ -30,18 +30,16 @@ EXPORTS.mozilla.dom += [
     'ContentProcess.h',
     'ContentProcessManager.h',
     'CPOWManagerGetter.h',
     'CrashReporterChild.h',
     'CrashReporterParent.h',
     'FilePickerParent.h',
     'nsIContentChild.h',
     'nsIContentParent.h',
-    'NuwaChild.h',
-    'NuwaParent.h',
     'PermissionMessageUtils.h',
     'TabChild.h',
     'TabContext.h',
     'TabMessageUtils.h',
     'TabParent.h',
 ]
 
 EXPORTS.mozilla += [
@@ -60,18 +58,16 @@ UNIFIED_SOURCES += [
     'ContentParent.cpp',
     'ContentProcess.cpp',
     'ContentProcessManager.cpp',
     'CrashReporterParent.cpp',
     'DatePickerParent.cpp',
     'FilePickerParent.cpp',
     'nsIContentChild.cpp',
     'nsIContentParent.cpp',
-    'NuwaChild.cpp',
-    'NuwaParent.cpp',
     'PermissionMessageUtils.cpp',
     'PreallocatedProcessManager.cpp',
     'ProcessPriorityManager.cpp',
     'ScreenManagerParent.cpp',
     'StructuredCloneData.cpp',
     'TabChild.cpp',
     'TabContext.cpp',
     'TabMessageUtils.cpp',
@@ -102,17 +98,16 @@ IPDL_SOURCES += [
     'PContentPermission.ipdlh',
     'PContentPermissionRequest.ipdl',
     'PCrashReporter.ipdl',
     'PCycleCollectWithLogs.ipdl',
     'PDatePicker.ipdl',
     'PDocumentRenderer.ipdl',
     'PFilePicker.ipdl',
     'PMemoryReportRequest.ipdl',
-    'PNuwa.ipdl',
     'PPluginWidget.ipdl',
     'PProcessHangMonitor.ipdl',
     'PScreenManager.ipdl',
     'PTabContext.ipdlh',
     'ServiceWorkerConfiguration.ipdlh',
 ]
 
 include('/ipc/chromium/chromium-config.mozbuild')
--- a/dom/ipc/tests/mochitest.ini
+++ b/dom/ipc/tests/mochitest.ini
@@ -8,20 +8,16 @@ skip-if = buildapp == 'b2g' || e10s
 [test_blob_sliced_from_parent_process.html]
 # This test is only supposed to run in the main process.
 skip-if = buildapp == 'b2g' || buildapp == 'mulet' || e10s
 [test_bug1086684.html]
 # This test is only supposed to run in the main process
 skip-if = buildapp == 'b2g' || e10s || toolkit == 'android'
 [test_cpow_cookies.html]
 skip-if = buildapp == 'b2g' || buildapp == 'mulet'
-[test_NuwaProcessCreation.html]
-skip-if = toolkit != 'gonk'
-[test_NuwaProcessDeadlock.html]
-skip-if = toolkit != 'gonk'
 [test_child_docshell.html]
 skip-if = toolkit == 'cocoa' # disabled due to hangs, see changeset 6852e7c47edf
 [test_CrashService_crash.html]
 skip-if = !(crashreporter && !e10s && (toolkit == 'gtk2' || toolkit == 'gtk3' || toolkit == 'cocoa' || toolkit == 'windows') && (buildapp != 'b2g' || toolkit == 'gonk') && (buildapp != 'mulet')) # TC: Bug 1144079 - Re-enable Mulet mochitests and reftests taskcluster-specific disables.
 [test_permission_for_in_process_app.html]
 skip-if = e10s || true || os == "android" || toolkit == "gonk" # embed-apps doesn't work in mochitest app  ### Bug 1255339: blacklist because no more mozApps
 support-files =
   test_permission_helper.js
deleted file mode 100644
--- a/dom/ipc/tests/test_NuwaProcessCreation.html
+++ /dev/null
@@ -1,68 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-<!--
-Test if Nuwa process created successfully.
--->
-<head>
-  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
-</head>
-<body onload="setup()">
-
-<script type="application/javascript;version=1.7">
-"use strict";
-
-function runTest()
-{
-  info("Shut down processes by disabling process prelaunch");
-  SpecialPowers.setBoolPref('dom.ipc.processPrelaunch.enabled', false);
-
-  info("Launch the Nuwa process");
-  let cpmm = SpecialPowers.Cc["@mozilla.org/childprocessmessagemanager;1"]
-                          .getService(SpecialPowers.Ci.nsISyncMessageSender);
-  let seenNuwaReady = false;
-  let msgHandler = {
-    receiveMessage: function receiveMessage(msg) {
-      msg = SpecialPowers.wrap(msg);
-      if (msg.name == 'TEST-ONLY:nuwa-ready') {
-        is(seenNuwaReady, false, "The Nuwa process is launched");
-        seenNuwaReady = true;
-      } else if (msg.name == 'TEST-ONLY:nuwa-add-new-process') {
-        ok(true, "Got nuwa-add-new-process");
-        is(seenNuwaReady, true, "The preallocated process is launched from the Nuwa process");
-        shutdown();
-      }
-    }
-  };
-
-  function shutdown() {
-    info("Shut down the test case");
-    cpmm.removeMessageListener("TEST-ONLY:nuwa-ready", msgHandler);
-    cpmm.removeMessageListener("TEST-ONLY:nuwa-add-new-process", msgHandler);
-
-    SimpleTest.finish();
-  }
-
-  cpmm.addMessageListener("TEST-ONLY:nuwa-ready", msgHandler);
-  cpmm.addMessageListener("TEST-ONLY:nuwa-add-new-process", msgHandler);
-
-
-  // Setting this pref to true should cause us to prelaunch a process.
-  SpecialPowers.setBoolPref('dom.ipc.processPrelaunch.enabled', true);
-}
-
-function setup()
-{
-  info("Set up preferences for testing the Nuwa process.");
-  SimpleTest.waitForExplicitFinish();
-
-  SpecialPowers.pushPrefEnv({
-    'set': [
-      ['dom.ipc.preallocatedProcessManager.testMode', true]
-    ]
-  }, runTest);
-}
-
-</script>
-</body>
-</html>
deleted file mode 100644
--- a/dom/ipc/tests/test_NuwaProcessDeadlock.html
+++ /dev/null
@@ -1,69 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-<!--
-Test if Nuwa process created successfully.
--->
-<head>
-  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
-</head>
-<body onload="setup()">
-
-<script type="application/javascript;version=1.7">
-"use strict";
-
-function runTest()
-{
-  info("Shut down processes by disabling process prelaunch");
-  SpecialPowers.setBoolPref('dom.ipc.processPrelaunch.enabled', false);
-
-  info("Launch the Nuwa process");
-  let cpmm = SpecialPowers.Cc["@mozilla.org/childprocessmessagemanager;1"]
-                          .getService(SpecialPowers.Ci.nsISyncMessageSender);
-  let seenNuwaReady = false;
-  let msgHandler = {
-    receiveMessage: function receiveMessage(msg) {
-      msg = SpecialPowers.wrap(msg);
-      if (msg.name == 'TEST-ONLY:nuwa-ready') {
-        is(seenNuwaReady, false, "The Nuwa process is launched");
-        seenNuwaReady = true;
-      } else if (msg.name == 'TEST-ONLY:nuwa-add-new-process') {
-        ok(true, "Got nuwa-add-new-process");
-        is(seenNuwaReady, true, "The preallocated process is launched from the Nuwa process");
-        shutdown();
-      }
-    }
-  };
-
-  function shutdown() {
-    info("Shut down the test case");
-    cpmm.removeMessageListener("TEST-ONLY:nuwa-ready", msgHandler);
-    cpmm.removeMessageListener("TEST-ONLY:nuwa-add-new-process", msgHandler);
-
-    SimpleTest.finish();
-  }
-
-  cpmm.addMessageListener("TEST-ONLY:nuwa-ready", msgHandler);
-  cpmm.addMessageListener("TEST-ONLY:nuwa-add-new-process", msgHandler);
-
-
-  // Setting this pref to true should cause us to prelaunch a process.
-  SpecialPowers.setBoolPref('dom.ipc.processPrelaunch.enabled', true);
-}
-
-function setup()
-{
-  info("Set up preferences for testing the Nuwa process.");
-  SimpleTest.waitForExplicitFinish();
-
-  SpecialPowers.pushPrefEnv({
-    'set': [
-      ['dom.ipc.preallocatedProcessManager.testMode', true],
-      ['dom.ipc.processPrelaunch.testMode', true]  // For testing deadlock
-    ]
-  }, runTest);
-}
-
-</script>
-</body>
-</html>
--- a/dom/storage/DOMStorageIPC.cpp
+++ b/dom/storage/DOMStorageIPC.cpp
@@ -610,26 +610,19 @@ DOMStorageDBParent::RecvAsyncFlush()
 // DOMStorageObserverSink
 
 nsresult
 DOMStorageDBParent::Observe(const char* aTopic,
                             const nsAString& aOriginAttributesPattern,
                             const nsACString& aOriginScope)
 {
   if (mIPCOpen) {
-#ifdef MOZ_NUWA_PROCESS
-    if (!(static_cast<ContentParent*>(Manager())->IsNuwaProcess() &&
-          ContentParent::IsNuwaReady())) {
-#endif
       mozilla::Unused << SendObserve(nsDependentCString(aTopic),
                                      nsString(aOriginAttributesPattern),
                                      nsCString(aOriginScope));
-#ifdef MOZ_NUWA_PROCESS
-    }
-#endif
   }
 
   return NS_OK;
 }
 
 namespace {
 
 // Results must be sent back on the main thread
--- a/dom/workers/RuntimeService.cpp
+++ b/dom/workers/RuntimeService.cpp
@@ -54,20 +54,16 @@
 #include "nsNetUtil.h"
 #include "nsServiceManagerUtils.h"
 #include "nsThreadUtils.h"
 #include "nsXPCOM.h"
 #include "nsXPCOMPrivate.h"
 #include "OSFileConstants.h"
 #include "xpcpublic.h"
 
-#ifdef MOZ_NUWA_PROCESS
-#include "ipc/Nuwa.h"
-#endif
-
 #include "Principal.h"
 #include "SharedWorker.h"
 #include "WorkerDebuggerManager.h"
 #include "WorkerPrivate.h"
 #include "WorkerRunnable.h"
 #include "WorkerScope.h"
 #include "WorkerThread.h"
 #include "prsystem.h"
@@ -2489,23 +2485,16 @@ LogViolationDetailsRunnable::MainThreadR
 
 NS_IMPL_ISUPPORTS_INHERITED0(WorkerThreadPrimaryRunnable, Runnable)
 
 NS_IMETHODIMP
 WorkerThreadPrimaryRunnable::Run()
 {
   using mozilla::ipc::BackgroundChild;
 
-#ifdef MOZ_NUWA_PROCESS
-  if (IsNuwaProcess()) {
-    NuwaMarkCurrentThread(nullptr, nullptr);
-    NuwaFreezeCurrentThread();
-  }
-#endif
-
   char stackBaseGuess;
 
   PR_SetCurrentThreadName("DOM Worker");
 
   nsAutoCString threadName;
   threadName.AssignLiteral("DOM Worker '");
   threadName.Append(NS_LossyConvertUTF16toASCII(mWorkerPrivate->ScriptURL()));
   threadName.Append('\'');
--- a/gfx/layers/ipc/ImageBridgeChild.cpp
+++ b/gfx/layers/ipc/ImageBridgeChild.cpp
@@ -559,20 +559,16 @@ ImageBridgeChild* ImageBridgeChild::GetS
   return sImageBridgeChildSingleton;
 }
 
 bool ImageBridgeChild::IsCreated()
 {
   return GetSingleton() != nullptr;
 }
 
-#ifdef MOZ_NUWA_PROCESS
-#include "ipc/Nuwa.h"
-#endif
-
 static void ReleaseImageClientNow(ImageClient* aClient,
                                   PImageContainerChild* aChild)
 {
   MOZ_ASSERT(InImageBridgeChildThread());
   if (aClient) {
     aClient->Release();
   }
 
--- a/gfx/layers/ipc/SharedBufferManagerChild.cpp
+++ b/gfx/layers/ipc/SharedBufferManagerChild.cpp
@@ -9,20 +9,16 @@
 #include "base/thread.h"                // for Thread
 #include "mozilla/gfx/Logging.h"        // for gfxDebug
 #include "mozilla/layers/SharedBufferManagerChild.h"
 #include "mozilla/layers/SharedBufferManagerParent.h"
 #include "mozilla/StaticPtr.h"          // for StaticRefPtr
 #include "mozilla/ReentrantMonitor.h"   // for ReentrantMonitor, etc
 #include "nsThreadUtils.h"              // fo NS_IsMainThread
 
-#ifdef MOZ_NUWA_PROCESS
-#include "ipc/Nuwa.h"
-#endif
-
 #ifdef MOZ_WIDGET_GONK
 #define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "SBMChild", ## args)
 #endif
 
 namespace mozilla {
 namespace layers {
 
 using namespace mozilla::gfx;
@@ -98,24 +94,16 @@ ConnectSharedBufferManagerInChildProcess
                                          base::ProcessId aOtherPid)
 {
   // Bind the IPC channel to the shared buffer manager thread.
   SharedBufferManagerChild::sSharedBufferManagerChildSingleton->Open(aTransport,
                                                                      aOtherPid,
                                                                      XRE_GetIOMessageLoop(),
                                                                      ipc::ChildSide);
 
-#ifdef MOZ_NUWA_PROCESS
-  if (IsNuwaProcess()) {
-    SharedBufferManagerChild::sSharedBufferManagerChildThread
-      ->message_loop()->PostTask(NewRunnableFunction(NuwaMarkCurrentThread,
-                                                     (void (*)(void *))nullptr,
-                                                     (void *)nullptr));
-  }
-#endif
 }
 
 PSharedBufferManagerChild*
 SharedBufferManagerChild::StartUpInChildProcess(Transport* aTransport,
                                                 base::ProcessId aOtherPid)
 {
   NS_ASSERTION(NS_IsMainThread(), "Should be on the main Thread!");
 
--- a/image/DecodePool.cpp
+++ b/image/DecodePool.cpp
@@ -12,20 +12,16 @@
 #include "nsCOMPtr.h"
 #include "nsIObserverService.h"
 #include "nsIThreadPool.h"
 #include "nsThreadManager.h"
 #include "nsThreadUtils.h"
 #include "nsXPCOMCIDInternal.h"
 #include "prsystem.h"
 
-#ifdef MOZ_NUWA_PROCESS
-#include "ipc/Nuwa.h"
-#endif
-
 #include "gfxPrefs.h"
 
 #include "Decoder.h"
 #include "IDecodingTask.h"
 #include "RasterImage.h"
 
 using std::max;
 using std::min;
@@ -64,22 +60,16 @@ public:
   { }
 
   /// Initialize the current thread for use by the decode pool.
   void InitCurrentThread()
   {
     MOZ_ASSERT(!NS_IsMainThread());
 
     mThreadNaming.SetThreadPoolName(NS_LITERAL_CSTRING("ImgDecoder"));
-
-#ifdef MOZ_NUWA_PROCESS
-    if (IsNuwaProcess()) {
-      NuwaMarkCurrentThread(static_cast<void(*)(void*)>(nullptr), nullptr);
-    }
-#endif // MOZ_NUWA_PROCESS
   }
 
   /// Shut down the provided decode pool thread.
   static void ShutdownThread(nsIThread* aThisThread)
   {
     // Threads have to be shut down from another thread, so we'll ask the
     // main thread to do it for us.
     NS_DispatchToMainThread(NewRunnableMethod(aThisThread, &nsIThread::Shutdown));
@@ -266,25 +256,16 @@ DecodePool::DecodePool()
     mThreads.AppendElement(Move(thread));
   }
 
   // Initialize the I/O thread.
   nsresult rv = NS_NewNamedThread("ImageIO", getter_AddRefs(mIOThread));
   MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv) && mIOThread,
                      "Should successfully create image I/O thread");
 
-#ifdef MOZ_NUWA_PROCESS
-  rv = mIOThread->Dispatch(NS_NewRunnableFunction([]() -> void {
-    NuwaMarkCurrentThread(static_cast<void(*)(void*)>(nullptr), nullptr);
-  }), NS_DISPATCH_NORMAL);
-
-  MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv),
-                     "Should register decode IO thread with Nuwa process");
-#endif
-
   nsCOMPtr<nsIObserverService> obsSvc = services::GetObserverService();
   if (obsSvc) {
     obsSvc->AddObserver(this, "xpcom-shutdown-threads", false);
   }
 }
 
 DecodePool::~DecodePool()
 {
--- a/ipc/chromium/src/base/process_util_linux.cc
+++ b/ipc/chromium/src/base/process_util_linux.cc
@@ -19,22 +19,16 @@
 #include "base/logging.h"
 #include "base/string_util.h"
 #include "nsLiteralString.h"
 #include "mozilla/UniquePtr.h"
 
 #include "prenv.h"
 #include "prmem.h"
 
-#ifdef MOZ_B2G_LOADER
-#include "ProcessUtils.h"
-
-using namespace mozilla::ipc;
-#endif	// MOZ_B2G_LOADER
-
 #ifdef MOZ_WIDGET_GONK
 /*
  * AID_APP is the first application UID used by Android. We're using
  * it as our unprivilegied UID.  This ensure the UID used is not
  * shared with any other processes than our own childs.
  */
 # include <private/android_filesystem_config.h>
 # define CHILD_UNPRIVILEGED_UID AID_APP
@@ -155,81 +149,22 @@ bool LaunchApp(const std::vector<std::st
                const environment_map& env_vars_to_set,
                bool wait, ProcessHandle* process_handle,
                ProcessArchitecture arch) {
   return LaunchApp(argv, fds_to_remap, env_vars_to_set,
                    PRIVILEGES_INHERIT,
                    wait, process_handle);
 }
 
-#ifdef MOZ_B2G_LOADER
-/**
- * Launch an app using B2g Loader.
- */
-static bool
-LaunchAppProcLoader(const std::vector<std::string>& argv,
-                    const file_handle_mapping_vector& fds_to_remap,
-                    const environment_map& env_vars_to_set,
-                    ChildPrivileges privs,
-                    ProcessHandle* process_handle) {
-  size_t i;
-  mozilla::UniquePtr<char*[]> argv_cstr(new char*[argv.size() + 1]);
-  for (i = 0; i < argv.size(); i++) {
-    argv_cstr[i] = const_cast<char*>(argv[i].c_str());
-  }
-  argv_cstr[argv.size()] = nullptr;
-
-  mozilla::UniquePtr<char*[]> env_cstr(new char*[env_vars_to_set.size() + 1]);
-  i = 0;
-  for (environment_map::const_iterator it = env_vars_to_set.begin();
-       it != env_vars_to_set.end(); ++it) {
-    env_cstr[i++] = strdup((it->first + "=" + it->second).c_str());
-  }
-  env_cstr[env_vars_to_set.size()] = nullptr;
-
-  bool ok = ProcLoaderLoad((const char **)argv_cstr.get(),
-                           (const char **)env_cstr.get(),
-                           fds_to_remap, privs,
-                           process_handle);
-  MOZ_ASSERT(ok, "ProcLoaderLoad() failed");
-
-  for (size_t i = 0; i < env_vars_to_set.size(); i++) {
-    free(env_cstr[i]);
-  }
-
-  return ok;
-}
-
-static bool
-IsLaunchingNuwa(const std::vector<std::string>& argv) {
-  std::vector<std::string>::const_iterator it;
-  for (it = argv.begin(); it != argv.end(); ++it) {
-    if (*it == std::string("-nuwa")) {
-      return true;
-    }
-  }
-  return false;
-}
-#endif // MOZ_B2G_LOADER
-
 bool LaunchApp(const std::vector<std::string>& argv,
                const file_handle_mapping_vector& fds_to_remap,
                const environment_map& env_vars_to_set,
                ChildPrivileges privs,
                bool wait, ProcessHandle* process_handle,
                ProcessArchitecture arch) {
-#ifdef MOZ_B2G_LOADER
-  static bool beforeFirstNuwaLaunch = true;
-  if (!wait && beforeFirstNuwaLaunch && IsLaunchingNuwa(argv)) {
-    beforeFirstNuwaLaunch = false;
-    return LaunchAppProcLoader(argv, fds_to_remap, env_vars_to_set,
-                               privs, process_handle);
-  }
-#endif // MOZ_B2G_LOADER
-
   mozilla::UniquePtr<char*[]> argv_cstr(new char*[argv.size() + 1]);
   // Illegal to allocate memory after fork and before execvp
   InjectiveMultimap fd_shuffle1, fd_shuffle2;
   fd_shuffle1.reserve(fds_to_remap.size());
   fd_shuffle2.reserve(fds_to_remap.size());
 
   Environment env;
   env.Merge(env_vars_to_set);
--- a/ipc/chromium/src/chrome/common/child_thread.cc
+++ b/ipc/chromium/src/chrome/common/child_thread.cc
@@ -18,44 +18,26 @@ ChildThread::ChildThread(Thread::Options
   DCHECK(owner_loop_);
   channel_name_ = CommandLine::ForCurrentProcess()->GetSwitchValue(
       switches::kProcessChannelID);
 }
 
 ChildThread::~ChildThread() {
 }
 
-#ifdef MOZ_NUWA_PROCESS
-#include "ipc/Nuwa.h"
-#endif
-
 bool ChildThread::Run() {
   bool r = StartWithOptions(options_);
-#ifdef MOZ_NUWA_PROCESS
-  if (IsNuwaProcess()) {
-      message_loop()->PostTask(NewRunnableFunction(&ChildThread::MarkThread));
-  }
-#endif
   return r;
 }
 
 void ChildThread::OnChannelError() {
   RefPtr<mozilla::Runnable> task = new MessageLoop::QuitTask();
   owner_loop_->PostTask(task.forget());
 }
 
-#ifdef MOZ_NUWA_PROCESS
-void ChildThread::MarkThread() {
-    NuwaMarkCurrentThread(nullptr, nullptr);
-    if (!NuwaCheckpointCurrentThread()) {
-        NS_RUNTIMEABORT("Should not be here!");
-    }
-}
-#endif
-
 void ChildThread::OnMessageReceived(IPC::Message&& msg) {
 }
 
 ChildThread* ChildThread::current() {
   return ChildProcess::current()->child_thread();
 }
 
 void ChildThread::Init() {
--- a/ipc/chromium/src/chrome/common/child_thread.h
+++ b/ipc/chromium/src/chrome/common/child_thread.h
@@ -37,20 +37,16 @@ class ChildThread : public IPC::Channel:
   virtual void Init();
   virtual void CleanUp();
 
  private:
   // IPC::Channel::Listener implementation:
   virtual void OnMessageReceived(IPC::Message&& msg);
   virtual void OnChannelError();
 
-#ifdef MOZ_NUWA_PROCESS
-  static void MarkThread();
-#endif
-
   // The message loop used to run tasks on the thread that started this thread.
   MessageLoop* owner_loop_;
 
   std::wstring channel_name_;
   mozilla::UniquePtr<IPC::Channel> channel_;
 
   Thread::Options options_;
 
--- a/ipc/contentproc/moz.build
+++ b/ipc/contentproc/moz.build
@@ -1,17 +1,15 @@
 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 Library('plugin-container')
-if CONFIG['MOZ_B2G_LOADER']:
-    FINAL_LIBRARY = 'xul'
 
 SOURCES += [
     'plugin-container.cpp',
 ]
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 if CONFIG['OS_ARCH'] == 'WINNT':
--- a/ipc/contentproc/plugin-container.cpp
+++ b/ipc/contentproc/plugin-container.cpp
@@ -50,21 +50,16 @@
      : (void)0 )
 
 # ifdef MOZ_CONTENT_SANDBOX
 # include "mozilla/Sandbox.h"
 # endif
 
 #endif // MOZ_WIDGET_GONK
 
-#ifdef MOZ_NUWA_PROCESS
-#include <binder/ProcessState.h>
-#include "ipc/Nuwa.h"
-#endif
-
 #ifdef MOZ_WIDGET_GONK
 static void
 InitializeBinder(void *aDummy) {
     // Change thread priority to 0 only during calling ProcessState::self().
     // The priority is registered to binder driver and used for default Binder
     // Thread's priority. 
     // To change the process's priority to small value need's root permission.
     int curPrio = getpriority(PRIO_PROCESS, 0);
@@ -145,69 +140,47 @@ int
 content_process_main(int argc, char* argv[])
 {
     // Check for the absolute minimum number of args we need to move
     // forward here. We expect the last arg to be the child process type.
     if (argc < 1) {
       return 3;
     }
 
-    bool isNuwa = false;
-    for (int i = 1; i < argc; i++) {
-        isNuwa |= strcmp(argv[i], "-nuwa") == 0;
-    }
-
     XREChildData childData;
 
 #if defined(XP_WIN) && defined(MOZ_SANDBOX)
     if (IsSandboxedProcess()) {
         childData.sandboxTargetServices =
             mozilla::sandboxing::GetInitializedTargetServices();
         if (!childData.sandboxTargetServices) {
             return 1;
         }
 
         childData.ProvideLogFunction = mozilla::sandboxing::ProvideLogFunction;
     }
 #endif
 
     XRE_SetProcessType(argv[--argc]);
 
-#ifdef MOZ_NUWA_PROCESS
-    if (isNuwa) {
-        PrepareNuwaProcess();
-    }
-#endif
-
 #if defined(XP_LINUX) && defined(MOZ_SANDBOX)
     // This has to happen while we're still single-threaded, and on
     // B2G that means before the Android Binder library is
-    // initialized.  Additional special handling is needed for Nuwa:
-    // the Nuwa process itself needs to be unsandboxed, and the same
-    // single-threadedness condition applies to its children; see also
-    // AfterNuwaFork().
-    mozilla::SandboxEarlyInit(XRE_GetProcessType(), isNuwa);
+    // initialized.
+    mozilla::SandboxEarlyInit(XRE_GetProcessType());
 #endif
 
 #ifdef MOZ_WIDGET_GONK
     // This creates a ThreadPool for binder ipc. A ThreadPool is necessary to
     // receive binder calls, though not necessary to send binder calls.
     // ProcessState::Self() also needs to be called once on the main thread to
     // register the main thread with the binder driver.
 
-#ifdef MOZ_NUWA_PROCESS
-    if (!isNuwa) {
-        InitializeBinder(nullptr);
-    } else {
-        NuwaAddFinalConstructor(&InitializeBinder, nullptr);
-    }
-#else
     InitializeBinder(nullptr);
 #endif
-#endif
 
 #ifdef XP_WIN
     // For plugins, this is done in PluginProcessChild::Init, as we need to
     // avoid it for unsupported plugins.  See PluginProcessChild::Init for
     // the details.
     if (XRE_GetProcessType() != GeckoProcessType_Plugin) {
         mozilla::SanitizeEnvironmentVariables();
         SetDllDirectoryW(L"");
--- a/ipc/glue/BackgroundChildImpl.cpp
+++ b/ipc/glue/BackgroundChildImpl.cpp
@@ -24,17 +24,16 @@
 #include "mozilla/dom/indexedDB/PBackgroundIndexedDBUtilsChild.h"
 #include "mozilla/dom/ipc/BlobChild.h"
 #include "mozilla/dom/quota/PQuotaChild.h"
 #ifdef MOZ_GAMEPAD
 #include "mozilla/dom/GamepadEventChannelChild.h"
 #include "mozilla/dom/GamepadTestChannelChild.h"
 #endif
 #include "mozilla/dom/MessagePortChild.h"
-#include "mozilla/dom/NuwaChild.h"
 #include "mozilla/ipc/PBackgroundTestChild.h"
 #include "mozilla/ipc/PSendStreamChild.h"
 #include "mozilla/layout/VsyncChild.h"
 #include "mozilla/net/PUDPSocketChild.h"
 #include "mozilla/dom/network/UDPSocketChild.h"
 #include "nsID.h"
 #include "nsTraceRefcnt.h"
 
@@ -70,17 +69,16 @@ namespace ipc {
 
 using mozilla::dom::UDPSocketChild;
 using mozilla::net::PUDPSocketChild;
 
 using mozilla::dom::asmjscache::PAsmJSCacheEntryChild;
 using mozilla::dom::cache::PCacheChild;
 using mozilla::dom::cache::PCacheStorageChild;
 using mozilla::dom::cache::PCacheStreamControlChild;
-using mozilla::dom::PNuwaChild;
 
 // -----------------------------------------------------------------------------
 // BackgroundChildImpl::ThreadLocal
 // -----------------------------------------------------------------------------
 
 BackgroundChildImpl::
 ThreadLocal::ThreadLocal()
   : mCurrentFileHandle(nullptr)
@@ -404,31 +402,16 @@ bool
 BackgroundChildImpl::DeallocPMessagePortChild(PMessagePortChild* aActor)
 {
   RefPtr<dom::MessagePortChild> child =
     dont_AddRef(static_cast<dom::MessagePortChild*>(aActor));
   MOZ_ASSERT(child);
   return true;
 }
 
-PNuwaChild*
-BackgroundChildImpl::AllocPNuwaChild()
-{
-  return new mozilla::dom::NuwaChild();
-}
-
-bool
-BackgroundChildImpl::DeallocPNuwaChild(PNuwaChild* aActor)
-{
-  MOZ_ASSERT(aActor);
-
-  delete aActor;
-  return true;
-}
-
 PSendStreamChild*
 BackgroundChildImpl::AllocPSendStreamChild()
 {
   MOZ_CRASH("PSendStreamChild actors should be manually constructed!");
 }
 
 bool
 BackgroundChildImpl::DeallocPSendStreamChild(PSendStreamChild* aActor)
--- a/ipc/glue/BackgroundChildImpl.h
+++ b/ipc/glue/BackgroundChildImpl.h
@@ -135,22 +135,16 @@ protected:
 
   virtual PMessagePortChild*
   AllocPMessagePortChild(const nsID& aUUID, const nsID& aDestinationUUID,
                          const uint32_t& aSequenceID) override;
 
   virtual bool
   DeallocPMessagePortChild(PMessagePortChild* aActor) override;
 
-  virtual PNuwaChild*
-  AllocPNuwaChild() override;
-
-  virtual bool
-  DeallocPNuwaChild(PNuwaChild* aActor) override;
-
   virtual PSendStreamChild*
   AllocPSendStreamChild() override;
 
   virtual bool
   DeallocPSendStreamChild(PSendStreamChild* aActor) override;
 
   virtual PAsmJSCacheEntryChild*
   AllocPAsmJSCacheEntryChild(const dom::asmjscache::OpenMode& aOpenMode,
--- a/ipc/glue/BackgroundParentImpl.cpp
+++ b/ipc/glue/BackgroundParentImpl.cpp
@@ -17,17 +17,16 @@
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/DOMTypes.h"
 #include "mozilla/dom/FileSystemBase.h"
 #include "mozilla/dom/FileSystemRequestParent.h"
 #ifdef MOZ_GAMEPAD
 #include "mozilla/dom/GamepadEventChannelParent.h"
 #include "mozilla/dom/GamepadTestChannelParent.h"
 #endif
-#include "mozilla/dom/NuwaParent.h"
 #include "mozilla/dom/PBlobParent.h"
 #include "mozilla/dom/PGamepadEventChannelParent.h"
 #include "mozilla/dom/PGamepadTestChannelParent.h"
 #include "mozilla/dom/MessagePortParent.h"
 #include "mozilla/dom/ServiceWorkerRegistrar.h"
 #include "mozilla/dom/asmjscache/AsmJSCache.h"
 #include "mozilla/dom/cache/ActorUtils.h"
 #include "mozilla/dom/indexedDB/ActorsParent.h"
@@ -61,19 +60,17 @@
 using mozilla::ipc::AssertIsOnBackgroundThread;
 using mozilla::dom::asmjscache::PAsmJSCacheEntryParent;
 using mozilla::dom::cache::PCacheParent;
 using mozilla::dom::cache::PCacheStorageParent;
 using mozilla::dom::cache::PCacheStreamControlParent;
 using mozilla::dom::FileSystemBase;
 using mozilla::dom::FileSystemRequestParent;
 using mozilla::dom::MessagePortParent;
-using mozilla::dom::NuwaParent;
 using mozilla::dom::PMessagePortParent;
-using mozilla::dom::PNuwaParent;
 using mozilla::dom::UDPSocketParent;
 
 namespace {
 
 void
 AssertIsOnMainThread()
 {
   MOZ_ASSERT(NS_IsMainThread());
@@ -292,34 +289,16 @@ BackgroundParentImpl::DeallocPFileDescri
   AssertIsInMainProcess();
   AssertIsOnBackgroundThread();
   MOZ_ASSERT(aActor);
 
   delete static_cast<FileDescriptorSetParent*>(aActor);
   return true;
 }
 
-PNuwaParent*
-BackgroundParentImpl::AllocPNuwaParent()
-{
-  return mozilla::dom::NuwaParent::Alloc();
-}
-
-bool
-BackgroundParentImpl::RecvPNuwaConstructor(PNuwaParent* aActor)
-{
-  return mozilla::dom::NuwaParent::ActorConstructed(aActor);
-}
-
-bool
-BackgroundParentImpl::DeallocPNuwaParent(PNuwaParent *aActor)
-{
-  return mozilla::dom::NuwaParent::Dealloc(aActor);
-}
-
 PSendStreamParent*
 BackgroundParentImpl::AllocPSendStreamParent()
 {
   return mozilla::ipc::AllocPSendStreamParent();
 }
 
 bool
 BackgroundParentImpl::DeallocPSendStreamParent(PSendStreamParent* aActor)
--- a/ipc/glue/BackgroundParentImpl.h
+++ b/ipc/glue/BackgroundParentImpl.h
@@ -96,25 +96,16 @@ protected:
   RecvPBroadcastChannelConstructor(PBroadcastChannelParent* actor,
                                    const PrincipalInfo& aPrincipalInfo,
                                    const nsCString& origin,
                                    const nsString& channel) override;
 
   virtual bool
   DeallocPBroadcastChannelParent(PBroadcastChannelParent* aActor) override;
 
-  virtual PNuwaParent*
-  AllocPNuwaParent() override;
-
-  virtual bool
-  RecvPNuwaConstructor(PNuwaParent* aActor) override;
-
-  virtual bool
-  DeallocPNuwaParent(PNuwaParent* aActor) override;
-
   virtual PSendStreamParent*
   AllocPSendStreamParent() override;
 
   virtual bool
   DeallocPSendStreamParent(PSendStreamParent* aActor) override;
 
   virtual PServiceWorkerManagerParent*
   AllocPServiceWorkerManagerParent() override;
--- a/ipc/glue/GeckoChildProcessHost.cpp
+++ b/ipc/glue/GeckoChildProcessHost.cpp
@@ -1222,61 +1222,8 @@ GeckoChildProcessHost::GetQueuedMessages
 {
   // If this is called off the IO thread, bad things will happen.
   DCHECK(MessageLoopForIO::current());
   swap(queue, mQueue);
   // We expect the next listener to take over processing of our queue.
 }
 
 bool GeckoChildProcessHost::sRunSelfAsContentProc(false);
-
-#ifdef MOZ_NUWA_PROCESS
-
-using mozilla::ipc::GeckoExistingProcessHost;
-using mozilla::ipc::FileDescriptor;
-
-GeckoExistingProcessHost::
-GeckoExistingProcessHost(GeckoProcessType aProcessType,
-                         base::ProcessHandle aProcess,
-                         const FileDescriptor& aFileDescriptor,
-                         ChildPrivileges aPrivileges)
-  : GeckoChildProcessHost(aProcessType, aPrivileges)
-  , mExistingProcessHandle(aProcess)
-  , mExistingFileDescriptor(aFileDescriptor)
-{
-  NS_ASSERTION(aFileDescriptor.IsValid(),
-               "Expected file descriptor to be valid");
-}
-
-GeckoExistingProcessHost::~GeckoExistingProcessHost()
-{
-  // Bug 943174: If we don't do this, ~GeckoChildProcessHost will try
-  // to wait on a process that isn't a direct child, and bad things
-  // will happen.
-  SetAlreadyDead();
-}
-
-bool
-GeckoExistingProcessHost::PerformAsyncLaunch(StringVector aExtraOpts,
-                                             base::ProcessArchitecture aArch)
-{
-  if (!OpenPrivilegedHandle(base::GetProcId(mExistingProcessHandle))) {
-    NS_RUNTIMEABORT("can't open handle to child process");
-  }
-
-  MonitorAutoLock lock(mMonitor);
-  mProcessState = PROCESS_CREATED;
-  lock.Notify();
-
-  return true;
-}
-
-void
-GeckoExistingProcessHost::InitializeChannel()
-{
-  CreateChannel(mExistingFileDescriptor);
-
-  MonitorAutoLock lock(mMonitor);
-  mProcessState = CHANNEL_INITIALIZED;
-  lock.Notify();
-}
-
-#endif /* MOZ_NUWA_PROCESS */
--- a/ipc/glue/GeckoChildProcessHost.h
+++ b/ipc/glue/GeckoChildProcessHost.h
@@ -207,34 +207,12 @@ private:
   nsCString mRestoreOrigNSPRLogName;
   nsCString mRestoreOrigMozLogName;
 
   static uint32_t sNextUniqueID;
 
   static bool sRunSelfAsContentProc;
 };
 
-#ifdef MOZ_NUWA_PROCESS
-class GeckoExistingProcessHost final : public GeckoChildProcessHost
-{
-public:
-  GeckoExistingProcessHost(GeckoProcessType aProcessType,
-                           base::ProcessHandle aProcess,
-                           const FileDescriptor& aFileDescriptor,
-                           ChildPrivileges aPrivileges=base::PRIVILEGES_DEFAULT);
-
-  ~GeckoExistingProcessHost();
-
-  virtual bool PerformAsyncLaunch(StringVector aExtraOpts=StringVector(),
-          base::ProcessArchitecture aArch=base::GetCurrentProcessArchitecture()) override;
-
-  virtual void InitializeChannel() override;
-
-private:
-  base::ProcessHandle mExistingProcessHandle;
-  mozilla::ipc::FileDescriptor mExistingFileDescriptor;
-};
-#endif /* MOZ_NUWA_PROCESS */
-
 } /* namespace ipc */
 } /* namespace mozilla */
 
 #endif /* __IPC_GLUE_GECKOCHILDPROCESSHOST_H__ */
--- a/ipc/glue/MessageChannel.h
+++ b/ipc/glue/MessageChannel.h
@@ -196,28 +196,16 @@ class MessageChannel : HasResultCodes
 
     static bool IsPumpingMessages() {
         return sIsPumpingMessages;
     }
     static void SetIsPumpingMessages(bool aIsPumping) {
         sIsPumpingMessages = aIsPumping;
     }
 
-#ifdef MOZ_NUWA_PROCESS
-    void Block() {
-        MOZ_ASSERT(mLink);
-        mLink->Block();
-    }
-
-    void Unblock() {
-        MOZ_ASSERT(mLink);
-        mLink->Unblock();
-    }
-#endif
-
 #ifdef OS_WIN
     struct MOZ_STACK_CLASS SyncStackFrame
     {
         SyncStackFrame(MessageChannel* channel, bool interrupt);
         ~SyncStackFrame();
 
         bool mInterrupt;
         bool mSpinNestedEvents;
--- a/ipc/glue/MessageLink.cpp
+++ b/ipc/glue/MessageLink.cpp
@@ -6,28 +6,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/ipc/MessageLink.h"
 #include "mozilla/ipc/MessageChannel.h"
 #include "mozilla/ipc/BrowserProcessSubThread.h"
 #include "mozilla/ipc/ProtocolUtils.h"
 #include "chrome/common/ipc_channel.h"
 
-#ifdef MOZ_NUWA_PROCESS
-#include "ipc/Nuwa.h"
-#include "mozilla/Preferences.h"
-#include "mozilla/dom/ContentParent.h"
-#include "mozilla/dom/PNuwa.h"
-#include "mozilla/hal_sandbox/PHal.h"
-#ifdef DEBUG
-#include "jsprf.h"
-extern "C" char* PrintJSStack();
-#endif
-#endif
-
 #include "mozilla/Assertions.h"
 #include "mozilla/DebugOnly.h"
 #include "nsDebug.h"
 #ifdef MOZ_CRASHREPORTER
 #include "nsExceptionHandler.h"
 #endif
 #include "nsISupportsImpl.h"
 #include "nsXULAppAPI.h"
@@ -63,20 +51,16 @@ MessageLink::~MessageLink()
 #endif
 }
 
 ProcessLink::ProcessLink(MessageChannel *aChan)
   : MessageLink(aChan)
   , mTransport(nullptr)
   , mIOLoop(nullptr)
   , mExistingListener(nullptr)
-#ifdef MOZ_NUWA_PROCESS
-  , mIsToNuwaProcess(false)
-  , mIsBlocked(false)
-#endif
 {
 }
 
 ProcessLink::~ProcessLink()
 {
 #ifdef DEBUG
     mTransport = nullptr;
     mIOLoop = nullptr;
@@ -125,27 +109,16 @@ ProcessLink::Open(mozilla::ipc::Transpor
             mIOLoop->PostTask(NewNonOwningRunnableMethod(this, &ProcessLink::OnChannelOpened));
         } else {
             // Transport::Connect() has already been called.  Take
             // over the channel from the previous listener and process
             // any queued messages.
             mIOLoop->PostTask(NewNonOwningRunnableMethod(this, &ProcessLink::OnTakeConnectedChannel));
         }
 
-#ifdef MOZ_NUWA_PROCESS
-        if (IsNuwaProcess() && NS_IsMainThread() &&
-            Preferences::GetBool("dom.ipc.processPrelaunch.testMode")) {
-            // The pref value is turned on in a deadlock test against the Nuwa
-            // process. The sleep here makes it easy to trigger the deadlock
-            // that an IPC channel is still opening but the worker loop is
-            // already frozen.
-            sleep(5);
-        }
-#endif
-
         // Should not wait here if something goes wrong with the channel.
         while (!mChan->Connected() && mChan->mChannelState != ChannelError) {
             mChan->mMonitor->Wait();
         }
     }
 }
 
 void
@@ -167,52 +140,16 @@ ProcessLink::SendMessage(Message *msg)
       CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("IPCMessageSize"), nsPrintfCString("%d", msg->size()));
 #endif
       MOZ_CRASH("IPC message size is too large");
     }
 
     mChan->AssertWorkerThread();
     mChan->mMonitor->AssertCurrentThreadOwns();
 
-#ifdef MOZ_NUWA_PROCESS
-    // Parent to child: check whether we are sending some unexpected message to
-    // the Nuwa process.
-    if (mIsToNuwaProcess && mozilla::dom::ContentParent::IsNuwaReady()) {
-        switch (msg->type()) {
-        case mozilla::dom::PNuwa::Msg_Fork__ID:
-        case mozilla::dom::PNuwa::Reply_AddNewProcess__ID:
-        case mozilla::dom::PContent::Msg_NotifyPhoneStateChange__ID:
-        case mozilla::dom::PContent::Msg_ActivateA11y__ID:
-        case mozilla::hal_sandbox::PHal::Msg_NotifyNetworkChange__ID:
-        case GOODBYE_MESSAGE_TYPE:
-            break;
-        default:
-#ifdef DEBUG
-            MOZ_CRASH();
-#else
-            // In optimized build, message will be dropped.
-            printf_stderr("Sending message to frozen Nuwa");
-            return;
-#endif
-        }
-    }
-
-#if defined(DEBUG)
-    // Nuwa to parent: check whether we are currently blocked.
-    if (IsNuwaProcess() && mIsBlocked) {
-        char* jsstack = PrintJSStack();
-        printf_stderr("Fatal error: sending a message to the chrome process"
-                      "with a blocked IPC channel from \n%s",
-                      jsstack ? jsstack : "<no JS stack>");
-        JS_smprintf_free(jsstack);
-        MOZ_CRASH();
-    }
-#endif
-#endif
-
     mIOLoop->PostTask(NewNonOwningRunnableMethod<Message*>(mTransport, &Transport::Send, msg));
 }
 
 void
 ProcessLink::SendClose()
 {
     mChan->AssertWorkerThread();
     mChan->mMonitor->AssertCurrentThreadOwns();
@@ -392,20 +329,16 @@ ProcessLink::OnChannelConnected(int32_t 
           mChan->mMonitor->Notify();
           notifyChannel = true;
         }
     }
 
     if (mExistingListener)
         mExistingListener->OnChannelConnected(peer_pid);
 
-#ifdef MOZ_NUWA_PROCESS
-    mIsToNuwaProcess = (peer_pid == mozilla::dom::ContentParent::NuwaPid());
-#endif
-
     if (notifyChannel) {
       mChan->OnChannelConnected(peer_pid);
     }
 }
 
 void
 ProcessLink::OnChannelError()
 {
--- a/ipc/glue/MessageLink.h
+++ b/ipc/glue/MessageLink.h
@@ -158,22 +158,16 @@ class MessageLink
     // held when they are invoked.
     virtual void EchoMessage(Message *msg) = 0;
     virtual void SendMessage(Message *msg) = 0;
     virtual void SendClose() = 0;
 
     virtual bool Unsound_IsClosed() const = 0;
     virtual uint32_t Unsound_NumQueuedMessages() const = 0;
 
-#ifdef MOZ_NUWA_PROCESS
-    // To be overridden by ProcessLink.
-    virtual void Block() {}
-    virtual void Unblock() {}
-#endif
-
   protected:
     MessageChannel *mChan;
 };
 
 class ProcessLink
   : public MessageLink,
     public Transport::Listener
 {
@@ -211,33 +205,20 @@ class ProcessLink
 
     virtual void EchoMessage(Message *msg) override;
     virtual void SendMessage(Message *msg) override;
     virtual void SendClose() override;
 
     virtual bool Unsound_IsClosed() const override;
     virtual uint32_t Unsound_NumQueuedMessages() const override;
 
-#ifdef MOZ_NUWA_PROCESS
-    void Block() override {
-        mIsBlocked = true;
-    }
-    void Unblock() override {
-        mIsBlocked = false;
-    }
-#endif
-
   protected:
     Transport* mTransport;
     MessageLoop* mIOLoop;       // thread where IO happens
     Transport::Listener* mExistingListener; // channel's previous listener
-#ifdef MOZ_NUWA_PROCESS
-    bool mIsToNuwaProcess;
-    bool mIsBlocked;
-#endif
 };
 
 class ThreadLink : public MessageLink
 {
   public:
     ThreadLink(MessageChannel *aChan, MessageChannel *aTargetChan);
     virtual ~ThreadLink();
 
--- a/ipc/glue/MessagePump.cpp
+++ b/ipc/glue/MessagePump.cpp
@@ -20,20 +20,16 @@
 #include "nsDebug.h"
 #include "nsServiceManagerUtils.h"
 #include "nsString.h"
 #include "nsThreadUtils.h"
 #include "nsTimerImpl.h"
 #include "nsXULAppAPI.h"
 #include "prthread.h"
 
-#ifdef MOZ_NUWA_PROCESS
-#include "ipc/Nuwa.h"
-#endif
-
 using base::TimeTicks;
 using namespace mozilla::ipc;
 
 NS_DEFINE_NAMED_CID(NS_TIMER_CID);
 
 #ifdef DEBUG
 static MessagePump::Delegate* gFirstDelegate;
 #endif
@@ -103,21 +99,17 @@ MessagePump::Run(MessagePump::Delegate* 
 
     // NB: it is crucial *not* to directly call |aDelegate->DoWork()|
     // here.  To ensure that MessageLoop tasks and XPCOM events have
     // equal priority, we sensitively rely on processing exactly one
     // Task per DoWorkRunnable XPCOM event.
 
     did_work |= aDelegate->DoDelayedWork(&delayed_work_time_);
 
-if (did_work && delayed_work_time_.is_null()
-#ifdef MOZ_NUWA_PROCESS
-    && (!IsNuwaReady() || !IsNuwaProcess())
-#endif
-   )
+if (did_work && delayed_work_time_.is_null())
       mDelayedWorkTimer->Cancel();
 
     if (!keep_running_)
       break;
 
     if (did_work)
       continue;
 
@@ -127,19 +119,16 @@ if (did_work && delayed_work_time_.is_nu
 
     if (did_work)
       continue;
 
     // This will either sleep or process an event.
     NS_ProcessNextEvent(thisThread, true);
   }
 
-#ifdef MOZ_NUWA_PROCESS
-  if (!IsNuwaReady() || !IsNuwaProcess())
-#endif
     mDelayedWorkTimer->Cancel();
 
   keep_running_ = true;
 }
 
 void
 MessagePump::ScheduleWork()
 {
@@ -161,21 +150,16 @@ MessagePump::ScheduleWorkForNestedLoop()
   // nested tasks.  In our setup, whenever that happens we know that
   // DoWork() will be called "soon", so there's no need to pay the
   // cost of what will be a no-op nsThread::Dispatch(mDoWorkEvent).
 }
 
 void
 MessagePump::ScheduleDelayedWork(const base::TimeTicks& aDelayedTime)
 {
-#ifdef MOZ_NUWA_PROCESS
-  if (IsNuwaReady() && IsNuwaProcess())
-    return;
-#endif
-
   // To avoid racing on mDelayedWorkTimer, we need to be on the same thread as
   // ::Run().
   MOZ_RELEASE_ASSERT(NS_GetCurrentThread() == mThread ||
                      (!mThread && NS_IsMainThread()));
 
   if (!mDelayedWorkTimer) {
     mDelayedWorkTimer = do_CreateInstance(kNS_TIMER_CID);
     if (!mDelayedWorkTimer) {
--- a/ipc/glue/PBackground.ipdl
+++ b/ipc/glue/PBackground.ipdl
@@ -12,17 +12,16 @@ include protocol PCache;
 include protocol PCacheStorage;
 include protocol PCacheStreamControl;
 include protocol PFileDescriptorSet;
 include protocol PFileSystemRequest;
 include protocol PGamepadEventChannel;
 include protocol PGamepadTestChannel;
 include protocol PMessagePort;
 include protocol PCameras;
-include protocol PNuwa;
 include protocol PQuota;
 include protocol PSendStream;
 include protocol PServiceWorkerManager;
 include protocol PUDPSocket;
 include protocol PVsync;
 
 include DOMTypes;
 include PBackgroundSharedTypes;
@@ -56,17 +55,16 @@ sync protocol PBackground
   manages PCacheStorage;
   manages PCacheStreamControl;
   manages PFileDescriptorSet;
   manages PFileSystemRequest;
   manages PGamepadEventChannel;
   manages PGamepadTestChannel;
   manages PMessagePort;
   manages PCameras;
-  manages PNuwa;
   manages PQuota;
   manages PSendStream;
   manages PServiceWorkerManager;
   manages PUDPSocket;
   manages PVsync;
 
 parent:
   // Only called at startup during mochitests to check the basic infrastructure.
@@ -89,18 +87,16 @@ parent:
   async PServiceWorkerManager();
 
   async ShutdownServiceWorkerRegistrar();
 
   async PCacheStorage(Namespace aNamespace, PrincipalInfo aPrincipalInfo);
 
   async PMessagePort(nsID uuid, nsID destinationUuid, uint32_t sequenceId);
 
-  async PNuwa();
-
   async PSendStream();
 
   async MessagePortForceClose(nsID uuid, nsID destinationUuid, uint32_t sequenceId);
 
   async PAsmJSCacheEntry(OpenMode openMode,
                          WriteParams write,
                          PrincipalInfo principalInfo);
 
--- a/ipc/glue/ProcessUtils.h
+++ b/ipc/glue/ProcessUtils.h
@@ -2,35 +2,20 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_ipc_ProcessUtils_h
 #define mozilla_ipc_ProcessUtils_h
 
-#ifdef MOZ_B2G_LOADER
-#include "base/process_util.h"
-#endif
-
 namespace mozilla {
 namespace ipc {
 
 // You probably should call ContentChild::SetProcessName instead of calling
 // this directly.
 void SetThisProcessName(const char *aName);
 
-#ifdef MOZ_B2G_LOADER
-// see ProcessUtils_linux.cpp for explaination.
-void ProcLoaderClientGeckoInit();
-bool ProcLoaderIsInitialized();
-bool ProcLoaderLoad(const char *aArgv[],
-                    const char *aEnvp[],
-                    const base::file_handle_mapping_vector &aFdsRemap,
-                    const base::ChildPrivileges aPrivs,
-                    base::ProcessHandle *aProcessHandle);
-#endif /* MOZ_B2G_LOADER */
-
 } // namespace ipc
 } // namespace mozilla
 
 #endif // ifndef mozilla_ipc_ProcessUtils_h
 
--- a/ipc/glue/ProcessUtils_linux.cpp
+++ b/ipc/glue/ProcessUtils_linux.cpp
@@ -5,623 +5,20 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "ProcessUtils.h"
 
 #include "nsString.h"
 
 #include <sys/prctl.h>
 
-#ifdef MOZ_B2G_LOADER
-
-#include <sys/types.h>
-#include <unistd.h>
-
-#include "nsAutoPtr.h"
-
-#include "mozilla/Assertions.h"
-#include "mozilla/ipc/PProcLoaderParent.h"
-#include "mozilla/ipc/PProcLoaderChild.h"
-#include "mozilla/ipc/Transport.h"
-#include "mozilla/ipc/FileDescriptorUtils.h"
-#include "mozilla/ipc/IOThreadChild.h"
-#include "mozilla/dom/ContentProcess.h"
-#include "base/file_descriptor_shuffle.h"
-#include "mozilla/BackgroundHangMonitor.h"
-#include "mozilla/DebugOnly.h"
-#include "mozilla/UniquePtr.h"
-#include "mozilla/unused.h"
-#include "base/process_util.h"
-#include "base/eintr_wrapper.h"
-#include "mozilla/Preferences.h"
-
-#include "prenv.h"
-
-#include "nsXULAppAPI.h" // export XRE_* functions
-
-#include "nsAppRunner.h"
-
-int content_process_main(int argc, char *argv[]);
-
-typedef mozilla::Vector<int> FdArray;
-
-#endif /* MOZ_B2G_LOADER */
-
 namespace mozilla {
 
 namespace ipc {
 
 void SetThisProcessName(const char *aName)
 {
   prctl(PR_SET_NAME, (unsigned long)aName, 0uL, 0uL, 0uL);
 }
 
-#ifdef MOZ_B2G_LOADER
-/**
- * How does B2G Loader Work?
- *
- *  <<parent process>>      <<child process>>
- *   ProcLoaderParent -----> ProcLoaderChild
- *         ^                       |
- *         | load()                | content_process_main()
- *         |                       V
- *     ProcLoaderClient      Nuwa/plugin-container
- *         ^
- *         | ProcLoaderLoad()
- *        ...
- *     ContentParent
- *
- *
- * B2G loader includes an IPC protocol PProcLoader for communication
- * between client (parent) and server (child).  The b2g process is the
- * client.  It requests the server to load/start the Nuwa process with
- * the given arguments, env variables, and file descriptors.
- *
- * ProcLoaderClientInit() is called by B2G loader to initialize the
- * client side, the b2g process.  Then the b2g_main() is called to
- * start b2g process.
- *
- * ProcLoaderClientGeckoInit() is called by XRE_main() to create the
- * parent actor, |ProcLoaderParent|, of PProcLoader for servicing the
- * request to run Nuwa process later once Gecko has been initialized.
- *
- * ProcLoaderServiceRun() is called by the server process.  It starts
- * an IOThread and event loop to serve the |ProcLoaderChild|
- * implmentation of PProcLoader protocol as the child actor.  Once it
- * recieves a load() request, it stops the IOThread and event loop,
- * then starts running the main function of the content process with
- * the given arguments.
- *
- * NOTE: The server process serves at most one load() request.
- */
-
-using namespace mozilla::dom;
-
-using base::ChildPrivileges;
-using base::InjectionArc;
-using base::InjectiveMultimap;
-using base::ProcessHandle;
-using base::ProcessId;
-using base::SetCurrentProcessPrivileges;
-using base::ShuffleFileDescriptors;
-using base::file_handle_mapping_vector;
-
-static bool sProcLoaderClientOnDeinit = false;
-static DebugOnly<bool> sProcLoaderClientInitialized = false;
-static DebugOnly<bool> sProcLoaderClientGeckoInitialized = false;
-static pid_t sProcLoaderPid = 0;
-static int sProcLoaderChannelFd = -1;
-static PProcLoaderParent *sProcLoaderParent = nullptr;
-static MessageLoop *sProcLoaderLoop = nullptr;
-static mozilla::UniquePtr<FdArray> sReservedFds;
-
-static void ProcLoaderClientDeinit();
-
-/**
- * Some file descriptors, like the child IPC channel FD, must be opened at
- * specific numbers. To ensure this, we pre-reserve kReservedFileDescriptors FDs
- * starting from kBeginReserveFileDescriptor so that operations like
- * __android_log_print() won't take these magic FDs.
- */
-static const size_t kReservedFileDescriptors = 5;
-static const int kBeginReserveFileDescriptor = STDERR_FILENO + 1;
-
-class ProcLoaderParent : public PProcLoaderParent
-{
-public:
-  ProcLoaderParent() {}
-  virtual ~ProcLoaderParent() {}
-
-  virtual void ActorDestroy(ActorDestroyReason aWhy) override;
-
-  virtual bool RecvLoadComplete(const int32_t &aPid,
-                                const int32_t &aCookie) override;
-};
-
-void
-ProcLoaderParent::ActorDestroy(ActorDestroyReason aWhy)
-{
-  if (aWhy == AbnormalShutdown) {
-    NS_WARNING("ProcLoaderParent is destroyed abnormally.");
-  }
-
-  if (sProcLoaderClientOnDeinit) {
-    // Get error for closing while the channel is already error.
-    return;
-  }
-
-  // Destroy self asynchronously.
-  ProcLoaderClientDeinit();
-}
-
-static void
-_ProcLoaderParentDestroy(PProcLoaderParent *aLoader)
-{
-  delete aLoader;
-  sProcLoaderClientOnDeinit = false;
-}
-
-bool
-ProcLoaderParent::RecvLoadComplete(const int32_t &aPid,
-                                   const int32_t &aCookie)
-{
-  return true;
-}
-
-static void
-CloseFileDescriptors(FdArray& aFds)
-{
-  for (size_t i = 0; i < aFds.length(); i++) {
-    Unused << HANDLE_EINTR(close(aFds[i]));
-  }
-}
-
-/**
- * Initialize the client of B2G loader for loader itself.
- *
- * The initialization of B2G loader are divided into two stages. First
- * stage is to collect child info passed from the main program of the
- * loader.  Second stage is to initialize Gecko according to info from the
- * first stage and make the client of loader service ready.
- *
- * \param aPeerPid is the pid of the child.
- * \param aChannelFd is the file descriptor of the socket used for IPC.
- */
-static void
-ProcLoaderClientInit(pid_t aPeerPid, int aChannelFd)
-{
-  MOZ_ASSERT(!sProcLoaderClientInitialized, "call ProcLoaderClientInit() more than once");
-  MOZ_ASSERT(aPeerPid != 0 && aChannelFd != -1, "invalid argument");
-  sProcLoaderPid = aPeerPid;
-  sProcLoaderChannelFd = aChannelFd;
-  sProcLoaderClientInitialized = true;
-}
-
-/**
- * Initialize the client of B2G loader for Gecko.
- */
-void
-ProcLoaderClientGeckoInit()
-{
-  MOZ_ASSERT(sProcLoaderClientInitialized, "call ProcLoaderClientInit() at first");
-  MOZ_ASSERT(!sProcLoaderClientGeckoInitialized,
-             "call ProcLoaderClientGeckoInit() more than once");
-
-  if (!Preferences::GetBool("dom.ipc.processPrelaunch.enabled", false)) {
-    kill(sProcLoaderPid, SIGKILL);
-    sProcLoaderPid = 0;
-    close(sProcLoaderChannelFd);
-    sProcLoaderChannelFd = -1;
-    return;
-  }
-
-  sProcLoaderClientGeckoInitialized = true;
-
-  TransportDescriptor fd;
-  fd.mFd = base::FileDescriptor(sProcLoaderChannelFd, /*auto_close=*/ false);
-  sProcLoaderChannelFd = -1;
-  UniquePtr<Transport> transport = OpenDescriptor(fd, Transport::MODE_CLIENT);
-  sProcLoaderParent = new ProcLoaderParent();
-  sProcLoaderParent->Open(transport.get(),
-                          sProcLoaderPid,
-                          XRE_GetIOMessageLoop(),
-                          ParentSide);
-  sProcLoaderLoop = MessageLoop::current();
-}
-
-bool ProcLoaderIsInitialized()
-{
-  return sProcLoaderPid != 0;
-}
-
-/**
- * Shutdown and destroy the client of B2G loader service.
- */
-static void
-ProcLoaderClientDeinit()
-{
-  MOZ_ASSERT(sProcLoaderClientGeckoInitialized && sProcLoaderClientInitialized);
-  sProcLoaderClientGeckoInitialized = false;
-  sProcLoaderClientInitialized = false;
-
-  sProcLoaderClientOnDeinit = true;
-
-  MOZ_ASSERT(sProcLoaderParent != nullptr);
-  PProcLoaderParent *procLoaderParent = sProcLoaderParent;
-  sProcLoaderParent = nullptr;
-  sProcLoaderLoop = nullptr;
-
-  MessageLoop::current()->
-    PostTask(NewRunnableFunction(&_ProcLoaderParentDestroy,
-                                 procLoaderParent));
-}
-
-struct AsyncSendLoadData
-{
-  nsTArray<nsCString> mArgv;
-  nsTArray<nsCString> mEnv;
-  nsTArray<FDRemap> mFdsremap;
-  ChildPrivileges mPrivs;
-  int mCookie;
-};
-
-static void
-AsyncSendLoad(AsyncSendLoadData *aLoad)
-{
-  PProcLoaderParent *loader = sProcLoaderParent;
-  DebugOnly<bool> ok =
-    loader->SendLoad(aLoad->mArgv, aLoad->mEnv, aLoad->mFdsremap,
-                     aLoad->mPrivs, aLoad->mCookie);
-  MOZ_ASSERT(ok);
-  delete aLoad;
-}
-
-/**
- * Request the loader service, the server, to load Nuwa.
- */
-bool
-ProcLoaderLoad(const char *aArgv[],
-               const char *aEnvp[],
-               const file_handle_mapping_vector &aFdsRemap,
-               const ChildPrivileges aPrivs,
-               ProcessHandle *aProcessHandle)
-{
-  static int cookie=0;
-  int i;
-
-  if (sProcLoaderParent == nullptr || sProcLoaderPid == 0) {
-    return false;
-  }
-
-  AsyncSendLoadData *load = new AsyncSendLoadData();
-  nsTArray<nsCString> &argv = load->mArgv;
-  for (i = 0; aArgv[i] != nullptr; i++) {
-    argv.AppendElement(nsCString(aArgv[i]));
-  }
-  nsTArray<nsCString> &env = load->mEnv;
-  for (i = 0; aEnvp[i] != nullptr; i++) {
-    env.AppendElement(nsCString(aEnvp[i]));
-  }
-  nsTArray<FDRemap> &fdsremap = load->mFdsremap;
-  for (file_handle_mapping_vector::const_iterator fdmap =
-         aFdsRemap.begin();
-       fdmap != aFdsRemap.end();
-       fdmap++) {
-    fdsremap.AppendElement(FDRemap(FileDescriptor(fdmap->first), fdmap->second));
-  }
-  load->mPrivs = aPrivs;
-  load->mCookie = cookie++;
-
-  *aProcessHandle = sProcLoaderPid;
-  sProcLoaderPid = 0;
-
-  sProcLoaderLoop->PostTask(NewRunnableFunction(AsyncSendLoad, load));
-  return true;
-}
-
-
-class ProcLoaderRunnerBase;
-
-static bool sProcLoaderServing = false;
-static ProcLoaderRunnerBase *sProcLoaderDispatchedTask = nullptr;
-
-class ProcLoaderRunnerBase
-{
-public:
-  virtual int DoWork() = 0;
-  virtual ~ProcLoaderRunnerBase() {}
-};
-
-
-class ProcLoaderNoopRunner : public ProcLoaderRunnerBase {
-public:
-  virtual int DoWork();
-};
-
-int
-ProcLoaderNoopRunner::DoWork() {
-  return 0;
-}
-
-/**
- * The runner to load Nuwa at the current process.
- */
-class ProcLoaderLoadRunner : public ProcLoaderRunnerBase {
-private:
-  const nsTArray<nsCString> mArgv;
-  const nsTArray<nsCString> mEnv;
-  const nsTArray<FDRemap> mFdsRemap;
-  const ChildPrivileges mPrivs;
-
-  void ShuffleFds();
-
-public:
-  ProcLoaderLoadRunner(const InfallibleTArray<nsCString>& aArgv,
-                       const InfallibleTArray<nsCString>& aEnv,
-                       const InfallibleTArray<FDRemap>& aFdsRemap,
-                       const ChildPrivileges aPrivs)
-    : mArgv(aArgv)
-    , mEnv(aEnv)
-    , mFdsRemap(aFdsRemap)
-    , mPrivs(aPrivs) {}
-
-  int DoWork();
-};
-
-void
-ProcLoaderLoadRunner::ShuffleFds()
-{
-  unsigned int i;
-
-  MOZ_ASSERT(mFdsRemap.Length() <= kReservedFileDescriptors);
-
-  InjectiveMultimap fd_shuffle;
-  fd_shuffle.reserve(mFdsRemap.Length());
-
-  for (i = 0; i < mFdsRemap.Length(); i++) {
-    const FDRemap *map = &mFdsRemap[i];
-    auto rawFD = map->fd().ClonePlatformHandle();
-    int tofd = map->mapto();
-
-    // The FD that is dup2()'d from needs to be closed after shuffling.
-    fd_shuffle.push_back(InjectionArc(rawFD.get(), tofd, /*in_close=*/true));
-
-    // Erase from sReservedFds we will use.
-    for (int* toErase = sReservedFds->begin();
-         toErase < sReservedFds->end();
-         toErase++) {
-      if (tofd == *toErase) {
-        sReservedFds->erase(toErase);
-        break;
-      }
-    }
-  }
-
-  DebugOnly<bool> ok = ShuffleFileDescriptors(&fd_shuffle);
-
-  // Close the FDs that are reserved but not used after
-  // ShuffleFileDescriptors().
-  MOZ_ASSERT(sReservedFds);
-  CloseFileDescriptors(*sReservedFds);
-  sReservedFds = nullptr;
-
-  // Note that we don'e call ::base::CloseSuperfluousFds() here, assuming that
-  // The file descriptor inherited from the parent are also necessary for us.
-}
-
-int
-ProcLoaderLoadRunner::DoWork()
-{
-  unsigned int i;
-
-  ShuffleFds();
-
-  unsigned int argc = mArgv.Length();
-  char **argv = new char *[argc + 1];
-  for (i = 0; i < argc; i++) {
-    argv[i] = ::strdup(mArgv[i].get());
-  }
-  argv[argc] = nullptr;
-
-  unsigned int envc = mEnv.Length();
-  for (i = 0; i < envc; i++) {
-    PR_SetEnv(mEnv[i].get());
-  }
-
-  SetCurrentProcessPrivileges(mPrivs);
-
-  // Start Nuwa (main function)
-  int ret = content_process_main(argc, argv);
-
-  for (i = 0; i < argc; i++) {
-    free(argv[i]);
-  }
-  delete[] argv;
-
-  return ret;
-}
-
-
-class ProcLoaderChild : public PProcLoaderChild
-{
-  pid_t mPeerPid;
-
-public:
-  ProcLoaderChild(pid_t aPeerPid) : mPeerPid(aPeerPid) {}
-
-  virtual void ActorDestroy(ActorDestroyReason aWhy) override;
-
-  virtual bool RecvLoad(InfallibleTArray<nsCString>&& aArgv,
-                        InfallibleTArray<nsCString>&& aEnv,
-                        InfallibleTArray<FDRemap>&& aFdsremap,
-                        const uint32_t& aPrivs,
-                        const int32_t& aCookie);
-
-  virtual void OnChannelError();
-};
-
-void
-ProcLoaderChild::ActorDestroy(ActorDestroyReason aWhy)
-{
-}
-
-static void
-_ProcLoaderChildDestroy(ProcLoaderChild *aChild)
-{
-  aChild->Close();
-  delete aChild;
-  MessageLoop::current()->Quit();
-}
-
-bool
-ProcLoaderChild::RecvLoad(InfallibleTArray<nsCString>&& aArgv,
-                          InfallibleTArray<nsCString>&& aEnv,
-                          InfallibleTArray<FDRemap>&& aFdsRemap,
-                          const uint32_t& aPrivs,
-                          const int32_t& aCookie) {
-  if (!sProcLoaderServing) {
-    return true;
-  }
-  sProcLoaderServing = false;
-
-  MOZ_ASSERT(sProcLoaderDispatchedTask == nullptr);
-  ChildPrivileges privs = static_cast<ChildPrivileges>(aPrivs);
-  sProcLoaderDispatchedTask =
-    new ProcLoaderLoadRunner(aArgv, aEnv, aFdsRemap, privs);
-
-  SendLoadComplete(mPeerPid, aCookie);
-
-  MessageLoop::current()->PostTask(
-    NewRunnableFunction(_ProcLoaderChildDestroy, this));
-  return true;
-}
-
-void
-ProcLoaderChild::OnChannelError()
-{
-  if (!sProcLoaderServing) {
-    return;
-  }
-  sProcLoaderServing = false;
-
-  PProcLoaderChild::OnChannelError();
-
-  MOZ_ASSERT(sProcLoaderDispatchedTask == nullptr);
-  sProcLoaderDispatchedTask = new ProcLoaderNoopRunner();
-
-  MessageLoop::current()->PostTask(
-    NewRunnableFunction(_ProcLoaderChildDestroy, this));
-}
-
-/**
- * A helper class which calls NS_LogInit/NS_LogTerm in its scope.
- */
-class ScopedLogging
-{
-public:
-  ScopedLogging() { NS_LogInit(); }
-  ~ScopedLogging() { NS_LogTerm(); }
-};
-
-/**
- * Run service of ProcLoader.
- *
- * \param aPeerPid is the pid of the parent.
- * \param aFd is the file descriptor of the socket for IPC.
- *
- * See the comment near the head of this file.
- */
-static int
-ProcLoaderServiceRun(pid_t aPeerPid, int aFd,
-                     int aArgc, const char *aArgv[],
-                     FdArray& aReservedFds)
-{
-  // Make a copy of aReservedFds. It will be used when we dup() the magic file
-  // descriptors when ProcLoaderChild::RecvLoad() runs.
-  sReservedFds = MakeUnique<FdArray>(mozilla::Move(aReservedFds));
-
-  ScopedLogging logging;
-
-  char **_argv;
-  _argv = new char *[aArgc + 1];
-  for (int i = 0; i < aArgc; i++) {
-    _argv[i] = ::strdup(aArgv[i]);
-    MOZ_ASSERT(_argv[i] != nullptr);
-  }
-  _argv[aArgc] = nullptr;
-
-  gArgv = _argv;
-  gArgc = aArgc;
-
-  {
-    nsresult rv = XRE_InitCommandLine(aArgc, _argv);
-    if (NS_FAILED(rv)) {
-      MOZ_CRASH();
-    }
-
-    mozilla::LogModule::Init();
-
-    TransportDescriptor fd;
-    fd.mFd = base::FileDescriptor(aFd, /*auto_close =*/false);
-
-    MOZ_ASSERT(!sProcLoaderServing);
-    MessageLoop loop;
-
-    nsAutoPtr<ContentProcess> process;
-    process = new ContentProcess(aPeerPid);
-    ChildThread *iothread = process->child_thread();
-
-    UniquePtr<Transport> transport = OpenDescriptor(fd, Transport::MODE_CLIENT);
-    ProcLoaderChild *loaderChild = new ProcLoaderChild(aPeerPid);
-    // Pass a message loop to initialize (connect) the channel
-    // (connection).
-    loaderChild->Open(transport.get(), aPeerPid, iothread->message_loop());
-
-    BackgroundHangMonitor::Prohibit();
-
-    sProcLoaderServing = true;
-    loop.Run();
-
-    BackgroundHangMonitor::Allow();
-
-    XRE_DeinitCommandLine();
-  }
-
-  MOZ_ASSERT(sProcLoaderDispatchedTask != nullptr);
-  ProcLoaderRunnerBase *task = sProcLoaderDispatchedTask;
-  sProcLoaderDispatchedTask = nullptr;
-  int ret = task->DoWork();
-  delete task;
-
-  for (int i = 0; i < aArgc; i++) {
-    free(_argv[i]);
-  }
-  delete[] _argv;
-
-  return ret;
-}
-
-#endif /* MOZ_B2G_LOADER */
 
 } // namespace ipc
 } // namespace mozilla
-
-#ifdef MOZ_B2G_LOADER
-void
-XRE_ProcLoaderClientInit(pid_t aPeerPid, int aChannelFd, FdArray& aReservedFds)
-{
-  // We already performed fork(). It's safe to free the "danger zone" of file
-  // descriptors .
-  mozilla::ipc::CloseFileDescriptors(aReservedFds);
-
-  mozilla::ipc::ProcLoaderClientInit(aPeerPid, aChannelFd);
-}
-
-int
-XRE_ProcLoaderServiceRun(pid_t aPeerPid, int aFd,
-                         int aArgc, const char *aArgv[],
-                         FdArray& aReservedFds)
-{
-  return mozilla::ipc::ProcLoaderServiceRun(aPeerPid, aFd,
-                                            aArgc, aArgv,
-                                            aReservedFds);
-}
-#endif /* MOZ_B2G_LOADER */
--- a/js/src/old-configure.in
+++ b/js/src/old-configure.in
@@ -2352,20 +2352,16 @@ HOST_CFLAGS=`echo \
     $HOST_CFLAGS`
 
 HOST_CXXFLAGS=`echo \
     $HOST_CXXFLAGS`
 
 AC_SUBST(_DEPEND_CFLAGS)
 AC_SUBST(MOZ_SYSTEM_NSPR)
 
-if test -n "$MOZ_NUWA_PROCESS"; then
-    AC_DEFINE(MOZ_NUWA_PROCESS)
-fi
-
 OS_CFLAGS="$CFLAGS"
 OS_CXXFLAGS="$CXXFLAGS"
 OS_CPPFLAGS="$CPPFLAGS"
 OS_COMPILE_CFLAGS="$COMPILE_CFLAGS"
 OS_COMPILE_CXXFLAGS="$COMPILE_CXXFLAGS"
 OS_LDFLAGS="$LDFLAGS"
 OS_LIBS="$LIBS"
 AC_SUBST(OS_CFLAGS)
--- a/js/src/vm/HelperThreads.cpp
+++ b/js/src/vm/HelperThreads.cpp
@@ -1291,36 +1291,22 @@ HelperThread::destroy()
 
         thread->join();
         thread.reset();
     }
 
     threadData.reset();
 }
 
-#ifdef MOZ_NUWA_PROCESS
-extern "C" {
-MFBT_API bool IsNuwaProcess();
-MFBT_API void NuwaMarkCurrentThread(void (*recreate)(void*), void* arg);
-}
-#endif
-
 /* static */
 void
 HelperThread::ThreadMain(void* arg)
 {
     PR_SetCurrentThreadName("JS Helper");
 
-#ifdef MOZ_NUWA_PROCESS
-    if (IsNuwaProcess()) {
-        MOZ_ASSERT(NuwaMarkCurrentThread != nullptr);
-        NuwaMarkCurrentThread(nullptr, nullptr);
-    }
-#endif
-
     //See bug 1104658.
     //Set the FPU control word to be the same as the main thread's, or math
     //computations on this thread may use incorrect precision rules during
     //Ion compilation.
     FIX_FPU();
 
     static_cast<HelperThread*>(arg)->threadLoop();
 }
--- a/js/xpconnect/src/XPCJSRuntime.cpp
+++ b/js/xpconnect/src/XPCJSRuntime.cpp
@@ -1116,20 +1116,16 @@ class Watchdog
     bool mShuttingDown;
 
     // See the comment in WatchdogMain.
     uint32_t mSlowScriptSecondHalfCount;
 
     mozilla::Atomic<int32_t> mMinScriptRunTimeSeconds;
 };
 
-#ifdef MOZ_NUWA_PROCESS
-#include "ipc/Nuwa.h"
-#endif
-
 #define PREF_MAX_SCRIPT_RUN_TIME_CONTENT "dom.max_script_run_time"
 #define PREF_MAX_SCRIPT_RUN_TIME_CHROME "dom.max_chrome_script_run_time"
 
 class WatchdogManager : public nsIObserver
 {
   public:
 
     NS_DECL_ISUPPORTS
@@ -1277,23 +1273,16 @@ AutoLockWatchdog::~AutoLockWatchdog()
     PR_Unlock(mWatchdog->GetLock());
 }
 
 static void
 WatchdogMain(void* arg)
 {
     PR_SetCurrentThreadName("JS Watchdog");
 
-#ifdef MOZ_NUWA_PROCESS
-    if (IsNuwaProcess()) {
-        NuwaMarkCurrentThread(nullptr, nullptr);
-        NuwaFreezeCurrentThread();
-    }
-#endif
-
     Watchdog* self = static_cast<Watchdog*>(arg);
     WatchdogManager* manager = self->Manager();
 
     // Lock lasts until we return
     AutoLockWatchdog lock(self);
 
     MOZ_ASSERT(self->Initialized());
     MOZ_ASSERT(!self->ShuttingDown());
--- a/layout/base/nsRefreshDriver.cpp
+++ b/layout/base/nsRefreshDriver.cpp
@@ -64,20 +64,16 @@
 #include "VsyncSource.h"
 #include "mozilla/VsyncDispatcher.h"
 #include "nsThreadUtils.h"
 #include "mozilla/unused.h"
 #include "mozilla/TimelineConsumers.h"
 #include "nsAnimationManager.h"
 #include "nsIDOMEvent.h"
 
-#ifdef MOZ_NUWA_PROCESS
-#include "ipc/Nuwa.h"
-#endif
-
 using namespace mozilla;
 using namespace mozilla::widget;
 using namespace mozilla::ipc;
 using namespace mozilla::layout;
 
 static mozilla::LazyLogModule sRefreshDriverLog("nsRefreshDriver");
 #define LOG(...) MOZ_LOG(sRefreshDriverLog, mozilla::LogLevel::Debug, (__VA_ARGS__))
 
@@ -860,25 +856,16 @@ CreateVsyncRefreshTimer()
     // Make sure all vsync systems are ready.
     gfxPlatform::GetPlatform();
     // In parent process, we don't need to use ipc. We can create the
     // VsyncRefreshDriverTimer directly.
     sRegularRateTimer = new VsyncRefreshDriverTimer();
     return;
   }
 
-#ifdef MOZ_NUWA_PROCESS
-  // NUWA process will just use software timer. Use NuwaAddFinalConstructor()
-  // to register a callback to create the vsync-base refresh timer after a
-  // process is created.
-  if (IsNuwaProcess()) {
-    NuwaAddFinalConstructor(&CreateContentVsyncRefreshTimer, nullptr);
-    return;
-  }
-#endif
   // If this process is not created by NUWA, just create the vsync timer here.
   CreateContentVsyncRefreshTimer(nullptr);
 }
 
 static uint32_t
 GetFirstFrameDelay(imgIRequest* req)
 {
   nsCOMPtr<imgIContainer> container;
--- a/memory/jemalloc/moz.build
+++ b/memory/jemalloc/moz.build
@@ -59,19 +59,16 @@ if CONFIG['_MSC_VER']:
     LOCAL_INCLUDES += ['src/include/msvc_compat']
     if not CONFIG['HAVE_INTTYPES_H']:
         LOCAL_INCLUDES += ['src/include/msvc_compat/C99']
 
 if CONFIG['OS_TARGET'] == 'Linux':
     # For mremap
     DEFINES['_GNU_SOURCE'] = True
 
-if CONFIG['MOZ_NUWA_PROCESS'] and CONFIG['MOZ_JEMALLOC4']:
-    DEFINES['pthread_mutex_lock'] = '__real_pthread_mutex_lock'
-
 if CONFIG['GNU_CC']:
     CFLAGS += ['-std=gnu99']
 
 DEFINES['abort'] = 'moz_abort'
 
 LOCAL_INCLUDES += [
     '!src/include',
     'src/include',
--- a/memory/mozjemalloc/moz.build
+++ b/memory/mozjemalloc/moz.build
@@ -30,19 +30,16 @@ DEFINES['abort'] = 'moz_abort'
 
 DEFINES['MOZ_JEMALLOC_IMPL'] = True
 
 #XXX: PGO on Linux causes problems here
 # See bug 419470
 if CONFIG['OS_TARGET'] == 'Linux':
     NO_PGO = True
 
-if CONFIG['MOZ_NUWA_PROCESS']:
-    DEFINES['pthread_mutex_lock'] = '__real_pthread_mutex_lock';
-
 LOCAL_INCLUDES += [
     '/memory/build',
 ]
 
 if CONFIG['GNU_CC']:
     CFLAGS += ['-Wno-unused'] # too many annoying warnings from mfbt/ headers
 
 if CONFIG['_MSC_VER']:
--- a/memory/replace/dmd/DMD.cpp
+++ b/memory/replace/dmd/DMD.cpp
@@ -254,21 +254,16 @@ MallocSizeOf(const void* aPtr)
 {
   return gMallocTable->malloc_usable_size(const_cast<void*>(aPtr));
 }
 
 void
 DMDFuncs::StatusMsg(const char* aFmt, va_list aAp)
 {
 #ifdef ANDROID
-#ifdef MOZ_B2G_LOADER
-  // Don't call __android_log_vprint() during initialization, or the magic file
-  // descriptors will be occupied by android logcat.
-  if (gIsDMDInitialized)
-#endif
     __android_log_vprint(ANDROID_LOG_INFO, "DMD", aFmt, aAp);
 #else
   // The +64 is easily enough for the "DMD[<pid>] " prefix and the NUL.
   char* fmt = (char*) InfallibleAllocPolicy::malloc_(strlen(aFmt) + 64);
   sprintf(fmt, "DMD[%d] %s", getpid(), aFmt);
   vfprintf(stderr, fmt, aAp);
   InfallibleAllocPolicy::free_(fmt);
 #endif
--- a/memory/replace/logalloc/replay/Replay.cpp
+++ b/memory/replace/logalloc/replay/Replay.cpp
@@ -302,28 +302,16 @@ MozTagAnonymousMemory(const void* aPtr, 
 int
 pthread_atfork(void (*aPrepare)(void), void (*aParent)(void),
                void (*aChild)(void))
 {
   return 0;
 }
 #endif
 
-#ifdef MOZ_NUWA_PROCESS
-#include <pthread.h>
-
-/* NUWA builds have jemalloc built with
- * -Dpthread_mutex_lock=__real_pthread_mutex_lock */
-int
-__real_pthread_mutex_lock(pthread_mutex_t* aMutex)
-{
-  return pthread_mutex_lock(aMutex);
-}
-#endif
-
 MOZ_END_EXTERN_C
 
 size_t parseNumber(Buffer aBuf)
 {
   if (!aBuf) {
     die("Malformed input");
   }
 
deleted file mode 100644
--- a/mozglue/build/Nuwa.cpp
+++ /dev/null
@@ -1,2104 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <map>
-#include <memory>
-
-#include <dlfcn.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <setjmp.h>
-#include <signal.h>
-#include <poll.h>
-#include <pthread.h>
-#include <alloca.h>
-#include <sys/epoll.h>
-#include <sys/mman.h>
-#include <sys/prctl.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/stat.h>
-#include <sys/syscall.h>
-#include <vector>
-
-#include "mozilla/Alignment.h"
-#include "mozilla/LinkedList.h"
-#include "mozilla/TaggedAnonymousMemory.h"
-#include "Nuwa.h"
-
-
-/* Support for telling Valgrind about the stack pointer changes that
-   Nuwa makes.  Without this, Valgrind is unusable in Nuwa child
-   processes due to the large number of false positives resulting from
-   Nuwa's stack pointer changes.  See bug 1125091.
-*/
-
-#if defined(MOZ_VALGRIND)
-# include <valgrind/memcheck.h>
-#endif
-
-#define DEBUG_VALGRIND_ANNOTATIONS 1
-
-/* Call this as soon as possible after a setjmp() that has returned
-   non-locally (that is, it is restoring some previous context).  This
-   paints a small area -- half a page -- above SP as containing
-   defined data in any area which is currently marked accessible.
-
-   Note that in fact there are a few memory references to the stack
-   after the setjmp but before the use of this macro, even when they
-   appear consecutively in the source code.  But those accesses all
-   appear to be stores, and since that part of the stack -- before we
-   get to the VALGRIND_MAKE_MEM_DEFINED_IF_ADDRESSABLE client request
-   -- is marked as accessible-but-undefined, Memcheck doesn't
-   complain.  Of course, once we get past the client request then even
-   reading from the stack is "safe".
-
-   VALGRIND_MAKE_MEM_DEFINED_IF_ADDRESSABLE and VALGRIND_PRINTF each
-   require 6 words of stack space.  In the worst case, in which the
-   compiler allocates two different pieces of stack, the required
-   extra stack is therefore 12 words, that is, 48 bytes on arm32.
-*/
-#if defined(MOZ_VALGRIND) && defined(VALGRIND_MAKE_MEM_DEFINED_IF_ADDRESSABLE) \
-    && defined(__arm__) && !defined(__aarch64__)
-# define POST_SETJMP_RESTORE(_who) \
-    do { \
-      /* setjmp returned 1 (meaning "restored").  Paint the area */ \
-      /* immediately above SP as "defined where it is accessible". */ \
-      register unsigned long int sp; \
-      __asm__ __volatile__("mov %0, sp" : "=r"(sp)); \
-      unsigned long int len = 1024*2; \
-      VALGRIND_MAKE_MEM_DEFINED_IF_ADDRESSABLE(sp, len); \
-      if (DEBUG_VALGRIND_ANNOTATIONS) { \
-        VALGRIND_PRINTF("Nuwa: POST_SETJMP_RESTORE: marking [0x%lx, +%ld) as " \
-                        "Defined-if-Addressible, called by %s\n", \
-                        sp, len, (_who)); \
-      } \
-    } while (0)
-#else
-# define POST_SETJMP_RESTORE(_who) /* */
-#endif
-
-
-using namespace mozilla;
-
-/**
- * Provides the wrappers to a selected set of pthread and system-level functions
- * as the basis for implementing Zygote-like preforking mechanism.
- */
-
-/**
- * Real functions for the wrappers.
- */
-extern "C" {
-#pragma GCC visibility push(default)
-int __real_pthread_create(pthread_t *thread,
-                          const pthread_attr_t *attr,
-                          void *(*start_routine) (void *),
-                          void *arg);
-int __real_pthread_key_create(pthread_key_t *key, void (*destructor)(void*));
-int __real_pthread_key_delete(pthread_key_t key);
-pthread_t __real_pthread_self();
-int __real_pthread_join(pthread_t thread, void **retval);
-int __real_epoll_wait(int epfd,
-                      struct epoll_event *events,
-                      int maxevents,
-                      int timeout);
-int __real_pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mtx);
-int __real_pthread_cond_timedwait(pthread_cond_t *cond,
-                                  pthread_mutex_t *mtx,
-                                  const struct timespec *abstime);
-int __real_pthread_mutex_lock(pthread_mutex_t *mtx);
-int __real_pthread_mutex_trylock(pthread_mutex_t *mtx);
-int __real_poll(struct pollfd *fds, nfds_t nfds, int timeout);
-int __real_epoll_create(int size);
-int __real_socketpair(int domain, int type, int protocol, int sv[2]);
-int __real_pipe2(int __pipedes[2], int flags);
-int __real_pipe(int __pipedes[2]);
-int __real_epoll_ctl(int aEpollFd, int aOp, int aFd, struct epoll_event *aEvent);
-int __real_close(int aFd);
-#pragma GCC visibility pop
-}
-
-#define REAL(s) __real_##s
-
-/**
- * A Nuwa process is started by preparing.  After preparing, it waits
- * for all threads becoming frozen. Then, it is ready while all
- * threads are frozen.
- */
-static bool sIsNuwaProcess = false; // This process is a Nuwa process.
-static bool sIsNuwaChildProcess = false; // This process is spawned from Nuwa.
-static bool sIsFreezing = false; // Waiting for all threads getting frozen.
-static bool sNuwaReady = false;  // Nuwa process is ready.
-static bool sNuwaPendingSpawn = false; // Are there any pending spawn requests?
-static bool sNuwaForking = false;
-
-// Fds of transports of top level protocols.
-static NuwaProtoFdInfo sProtoFdInfos[NUWA_TOPLEVEL_MAX];
-static int sProtoFdInfosSize = 0;
-
-typedef std::vector<std::pair<pthread_key_t, void *> >
-TLSInfoList;
-
-/**
- * Return the system's page size
- */
-static size_t getPageSize(void) {
-#ifdef HAVE_GETPAGESIZE
-  return getpagesize();
-#elif defined(_SC_PAGESIZE)
-  return sysconf(_SC_PAGESIZE);
-#elif defined(PAGE_SIZE)
-  return PAGE_SIZE;
-#else
-  #warning "Hard-coding page size to 4096 bytes"
-  return 4096
-#endif
-}
-
-/**
- * Use 1 MiB stack size as Android does.
- */
-#ifndef NUWA_STACK_SIZE
-#define NUWA_STACK_SIZE (1024 * 1024)
-#endif
-
-#define NATIVE_THREAD_NAME_LENGTH 16
-
-typedef struct nuwa_construct {
-  typedef void(*construct_t)(void*);
-
-  construct_t construct;
-  void *arg;
-
-  nuwa_construct(construct_t aConstruct, void *aArg)
-    : construct(aConstruct)
-    , arg(aArg)
-  { }
-
-  nuwa_construct(const nuwa_construct&) = default;
-  nuwa_construct& operator=(const nuwa_construct&) = default;
-
-} nuwa_construct_t;
-
-struct thread_info : public mozilla::LinkedListElement<thread_info> {
-  pthread_t origThreadID;
-  pthread_t recreatedThreadID;
-  pthread_attr_t threadAttr;
-  jmp_buf jmpEnv;
-  jmp_buf retEnv;
-
-  int flags;
-
-  void *(*startupFunc)(void *arg);
-  void *startupArg;
-
-  // The thread specific function to recreate the new thread. It's executed
-  // after the thread is recreated.
-
-  std::vector<nuwa_construct_t> *recrFunctions;
-  void addThreadConstructor(const nuwa_construct_t *construct) {
-    if (!recrFunctions) {
-      recrFunctions = new std::vector<nuwa_construct_t>();
-    }
-
-    recrFunctions->push_back(*construct);
-  }
-
-  TLSInfoList tlsInfo;
-
-  /**
-   * We must ensure that the recreated thread has entered pthread_cond_wait() or
-   * similar functions before proceeding to recreate the next one. Otherwise, if
-   * the next thread depends on the same mutex, it may be used in an incorrect
-   * state.  To do this, the main thread must unconditionally acquire the mutex.
-   * The mutex is unconditionally released when the recreated thread enters
-   * pthread_cond_wait().  The recreated thread may have locked the mutex itself
-   * (if the pthread_mutex_trylock succeeded) or another thread may have already
-   * held the lock.  If the recreated thread did lock the mutex we must balance
-   * that with another unlock on the main thread, which is signaled by
-   * condMutexNeedsBalancing.
-   */
-  pthread_mutex_t *condMutex;
-  bool condMutexNeedsBalancing;
-
-  size_t stackSize;
-  size_t guardSize;
-  void *stk;
-
-  pid_t origNativeThreadID;
-  pid_t recreatedNativeThreadID;
-  char nativeThreadName[NATIVE_THREAD_NAME_LENGTH];
-};
-
-typedef struct thread_info thread_info_t;
-
-static thread_info_t *sCurrentRecreatingThread = nullptr;
-
-/**
- * This function runs the custom recreation function registered when calling
- * NuwaMarkCurrentThread() after thread stack is restored.
- */
-static void
-RunCustomRecreation() {
-  thread_info_t *tinfo = sCurrentRecreatingThread;
-  if (tinfo->recrFunctions) {
-    for (auto iter = tinfo->recrFunctions->begin();
-         iter != tinfo->recrFunctions->end();
-         iter++) {
-      iter->construct(iter->arg);
-    }
-  }
-}
-
-/**
- * Every thread should be marked as either TINFO_FLAG_NUWA_SUPPORT or
- * TINFO_FLAG_NUWA_SKIP, or it means a potential error.  We force
- * Gecko code to mark every single thread to make sure there are no accidents
- * when recreating threads with Nuwa.
- *
- * Threads marked as TINFO_FLAG_NUWA_SUPPORT can be checkpointed explicitly, by
- * calling NuwaCheckpointCurrentThread(), or implicitly when they call into wrapped
- * functions like pthread_mutex_lock(), epoll_wait(), etc.
- * TINFO_FLAG_NUWA_EXPLICIT_CHECKPOINT denotes the explicitly checkpointed thread.
- */
-#define TINFO_FLAG_NUWA_SUPPORT 0x1
-#define TINFO_FLAG_NUWA_SKIP 0x2
-#define TINFO_FLAG_NUWA_EXPLICIT_CHECKPOINT 0x4
-
-static std::vector<nuwa_construct_t> sConstructors;
-static std::vector<nuwa_construct_t> sFinalConstructors;
-
-class TLSKey
-: public std::pair<pthread_key_t, void (*)(void*)>
-, public LinkedListElement<TLSKey>
-{
-public:
-  TLSKey() {}
-
-  TLSKey(pthread_key_t aKey, void (*aDestructor)(void*))
-  : std::pair<pthread_key_t, void (*)(void*)>(aKey, aDestructor)
-  {}
-
-  static void* operator new(size_t size) {
-    if (sUsed)
-      return ::operator new(size);
-    sUsed = true;
-    return sFirstElement.addr();
-  }
-
-  static void operator delete(void* ptr) {
-    if (ptr == sFirstElement.addr()) {
-      sUsed = false;
-      return;
-    }
-    ::operator delete(ptr);
-  }
-
-private:
-  static bool sUsed;
-  static AlignedStorage2<TLSKey> sFirstElement;
-};
-
-bool TLSKey::sUsed = false;
-AlignedStorage2<TLSKey> TLSKey::sFirstElement;
-
-static AutoCleanLinkedList<TLSKey> sTLSKeys;
-
-/**
- * This mutex is used to block the running threads and freeze their contexts.
- * PrepareNuwaProcess() is the first one to acquire the lock. Further attempts
- * to acquire this mutex (in the freeze point macros) will block and freeze the
- * calling thread.
- */
-static pthread_mutex_t sThreadFreezeLock = PTHREAD_MUTEX_INITIALIZER;
-
-static thread_info_t sMainThread;
-static int sThreadCount = 0;
-static int sThreadFreezeCount = 0;
-
-// Bug 1008254: LinkedList's destructor asserts that the list is empty.
-// But here, on exit, when the global sAllThreads list
-// is destroyed, it may or may not be empty. Bug 1008254 comment 395 has a log
-// when there were 8 threads remaining on exit. So this assertion was
-// intermittently (almost every second time) failing.
-// As a work-around to avoid this intermittent failure, we clear the list on
-// exit just before it gets destroyed. This is the only purpose of that
-// AllThreadsListType subclass.
-struct AllThreadsListType : public AutoCleanLinkedList<thread_info_t>
-{
-  ~AllThreadsListType()
-  {
-    if (!isEmpty()) {
-      __android_log_print(ANDROID_LOG_WARN, "Nuwa",
-                          "Threads remaining at exit:\n");
-      int n = 0;
-      for (const thread_info_t* t = getFirst(); t; t = t->getNext()) {
-        __android_log_print(ANDROID_LOG_WARN, "Nuwa",
-                            "  %.*s (origNativeThreadID=%d recreatedNativeThreadID=%d)\n",
-                            NATIVE_THREAD_NAME_LENGTH,
-                            t->nativeThreadName,
-                            t->origNativeThreadID,
-                            t->recreatedNativeThreadID);
-        n++;
-      }
-      __android_log_print(ANDROID_LOG_WARN, "Nuwa",
-                          "total: %d outstanding threads. "
-                          "Please fix them so they're destroyed before this point!\n", n);
-      __android_log_print(ANDROID_LOG_WARN, "Nuwa",
-                          "note: sThreadCount=%d, sThreadFreezeCount=%d\n",
-                          sThreadCount,
-                          sThreadFreezeCount);
-    }
-  }
-};
-static AllThreadsListType sAllThreads;
-static AllThreadsListType sExitingThreads;
-
-/**
- * This mutex protects the access to thread info:
- * sAllThreads, sThreadCount, sThreadFreezeCount, sRecreateVIPCount.
- */
-static pthread_mutex_t sThreadCountLock = PTHREAD_MUTEX_INITIALIZER;
-/**
- * This condition variable lets MakeNuwaProcess() wait until all recreated
- * threads are frozen.
- */
-static pthread_cond_t sThreadChangeCond = PTHREAD_COND_INITIALIZER;
-
-/**
- * This mutex and condition variable is used to serialize the fork requests
- * from the parent process.
- */
-static pthread_mutex_t sForkLock = PTHREAD_MUTEX_INITIALIZER;
-static pthread_cond_t sForkWaitCond = PTHREAD_COND_INITIALIZER;
-
-/**
- * sForkWaitCondChanged will be reset to false on the IPC thread before
- * and will be changed to true on the main thread to indicate that the condition
- * that the IPC thread is waiting for has already changed.
- */
-static bool sForkWaitCondChanged = false;
-
-/**
- * This mutex protects the access to sTLSKeys, which keeps track of existing
- * TLS Keys.
- */
-static pthread_mutex_t sTLSKeyLock = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER;
-static int sThreadSkipCount = 0;
-
-static thread_info_t *
-GetThreadInfoInner(pthread_t threadID) {
-  for (thread_info_t *tinfo = sAllThreads.getFirst();
-       tinfo;
-       tinfo = tinfo->getNext()) {
-    if (pthread_equal(tinfo->origThreadID, threadID)) {
-      return tinfo;
-    }
-  }
-
-  for (thread_info_t *tinfo = sExitingThreads.getFirst();
-       tinfo;
-       tinfo = tinfo->getNext()) {
-    if (pthread_equal(tinfo->origThreadID, threadID)) {
-      return tinfo;
-    }
-  }
-
-  return nullptr;
-}
-
-/**
- * Get thread info using the specified thread ID.
- *
- * @return thread_info_t which has threadID == specified threadID
- */
-static thread_info_t *
-GetThreadInfo(pthread_t threadID) {
-  REAL(pthread_mutex_lock)(&sThreadCountLock);
-
-  thread_info_t *tinfo = GetThreadInfoInner(threadID);
-
-  pthread_mutex_unlock(&sThreadCountLock);
-  return tinfo;
-}
-
-#if !defined(HAVE_THREAD_TLS_KEYWORD)
-/**
- * Get thread info of the current thread.
- *
- * @return thread_info_t for the current thread.
- */
-static thread_info_t *
-GetCurThreadInfo() {
-  pthread_t threadID = REAL(pthread_self)();
-  pthread_t thread_info_t::*threadIDptr =
-      (sIsNuwaProcess ?
-         &thread_info_t::origThreadID :
-         &thread_info_t::recreatedThreadID);
-
-  REAL(pthread_mutex_lock)(&sThreadCountLock);
-  thread_info_t *tinfo;
-  for (tinfo = sAllThreads.getFirst();
-       tinfo;
-       tinfo = tinfo->getNext()) {
-    if (pthread_equal(tinfo->*threadIDptr, threadID)) {
-      break;
-    }
-  }
-  pthread_mutex_unlock(&sThreadCountLock);
-  return tinfo;
-}
-#define CUR_THREAD_INFO GetCurThreadInfo()
-#define SET_THREAD_INFO(x) /* Nothing to do. */
-#else
-// Is not nullptr only for threads created by pthread_create() in an Nuwa process.
-// It is always nullptr for the main thread.
-static __thread thread_info_t *sCurThreadInfo = nullptr;
-#define CUR_THREAD_INFO sCurThreadInfo
-#define SET_THREAD_INFO(x) do { sCurThreadInfo = (x); } while(0)
-#endif  // HAVE_THREAD_TLS_KEYWORD
-
-/*
- * Track all epoll fds and handling events.
- */
-class EpollManager {
-public:
-  class EpollInfo {
-  public:
-    typedef struct epoll_event Events;
-    typedef std::map<int, Events> EpollEventsMap;
-    typedef EpollEventsMap::iterator iterator;
-    typedef EpollEventsMap::const_iterator const_iterator;
-
-    EpollInfo(): mBackSize(0) {}
-    EpollInfo(int aBackSize): mBackSize(aBackSize) {}
-    EpollInfo(const EpollInfo &aOther): mEvents(aOther.mEvents)
-                                      , mBackSize(aOther.mBackSize) {
-    }
-    ~EpollInfo() {
-      mEvents.clear();
-    }
-
-    void AddEvents(int aFd, Events &aEvents) {
-      std::pair<iterator, bool> pair =
-        mEvents.insert(std::make_pair(aFd, aEvents));
-      if (!pair.second) {
-        abort();
-      }
-    }
-
-    void RemoveEvents(int aFd) {
-      if (!mEvents.erase(aFd)) {
-        abort();
-      }
-    }
-
-    void ModifyEvents(int aFd, Events &aEvents) {
-      iterator it = mEvents.find(aFd);
-      if (it == mEvents.end()) {
-        abort();
-      }
-      it->second = aEvents;
-    }
-
-    const Events &FindEvents(int aFd) const {
-      const_iterator it = mEvents.find(aFd);
-      if (it == mEvents.end()) {
-        abort();
-      }
-      return it->second;
-    }
-
-    int Size() const { return mEvents.size(); }
-
-    // Iterator with values of <fd, Events> pairs.
-    const_iterator begin() const { return mEvents.begin(); }
-    const_iterator end() const { return mEvents.end(); }
-
-    int BackSize() const { return mBackSize; }
-
-  private:
-    EpollEventsMap mEvents;
-    int mBackSize;
-
-    friend class EpollManager;
-  };
-
-  typedef std::map<int, EpollInfo> EpollInfoMap;
-  typedef EpollInfoMap::iterator iterator;
-  typedef EpollInfoMap::const_iterator const_iterator;
-
-public:
-  void AddEpollInfo(int aEpollFd, int aBackSize) {
-    EpollInfo *oldinfo = FindEpollInfo(aEpollFd);
-    if (oldinfo != nullptr) {
-      abort();
-    }
-    mEpollFdsInfo[aEpollFd] = EpollInfo(aBackSize);
-  }
-
-  EpollInfo *FindEpollInfo(int aEpollFd) {
-    iterator it = mEpollFdsInfo.find(aEpollFd);
-    if (it == mEpollFdsInfo.end()) {
-      return nullptr;
-    }
-    return &it->second;
-  }
-
-  void RemoveEpollInfo(int aEpollFd) {
-    if (!mEpollFdsInfo.erase(aEpollFd)) {
-      abort();
-    }
-  }
-
-  int Size() const { return mEpollFdsInfo.size(); }
-
-  // Iterator of <epollfd, EpollInfo> pairs.
-  const_iterator begin() const { return mEpollFdsInfo.begin(); }
-  const_iterator end() const { return mEpollFdsInfo.end(); }
-
-  static EpollManager *Singleton() {
-    if (!sInstance) {
-      sInstance = new EpollManager();
-    }
-    return sInstance;
-  }
-
-  static void Shutdown() {
-    if (!sInstance) {
-      abort();
-    }
-
-    delete sInstance;
-    sInstance = nullptr;
-  }
-
-private:
-  static EpollManager *sInstance;
-  ~EpollManager() {
-    mEpollFdsInfo.clear();
-  }
-
-  EpollInfoMap mEpollFdsInfo;
-
-  EpollManager() {}
-};
-
-EpollManager* EpollManager::sInstance;
-
-static thread_info_t *
-thread_info_new(void) {
-  /* link tinfo to sAllThreads */
-  thread_info_t *tinfo = new thread_info_t();
-  tinfo->flags = 0;
-  tinfo->recrFunctions = nullptr;
-  tinfo->recreatedThreadID = 0;
-  tinfo->recreatedNativeThreadID = 0;
-  tinfo->condMutex = nullptr;
-  tinfo->condMutexNeedsBalancing = false;
-
-  // Default stack and guard size.
-  tinfo->stackSize = NUWA_STACK_SIZE;
-  tinfo->guardSize = getPageSize();
-
-  REAL(pthread_mutex_lock)(&sThreadCountLock);
-  // Insert to the tail.
-  sAllThreads.insertBack(tinfo);
-
-  sThreadCount++;
-  pthread_cond_signal(&sThreadChangeCond);
-  pthread_mutex_unlock(&sThreadCountLock);
-
-  return tinfo;
-}
-
-static void
-thread_attr_init(thread_info_t *tinfo, const pthread_attr_t *tattr)
-{
-  pthread_attr_init(&tinfo->threadAttr);
-
-  if (tattr) {
-    // Override default thread stack and guard size with tattr.
-    pthread_attr_getstacksize(tattr, &tinfo->stackSize);
-    pthread_attr_getguardsize(tattr, &tinfo->guardSize);
-
-    size_t pageSize = getPageSize();
-
-    tinfo->stackSize = (tinfo->stackSize + pageSize - 1) % pageSize;
-    tinfo->guardSize = (tinfo->guardSize + pageSize - 1) % pageSize;
-
-    int detachState = 0;
-    pthread_attr_getdetachstate(tattr, &detachState);
-    pthread_attr_setdetachstate(&tinfo->threadAttr, detachState);
-  }
-
-  tinfo->stk = MozTaggedAnonymousMmap(nullptr,
-                                      tinfo->stackSize + tinfo->guardSize,
-                                      PROT_READ | PROT_WRITE,
-                                      MAP_PRIVATE | MAP_ANONYMOUS,
-                                      /* fd */ -1,
-                                      /* offset */ 0,
-                                      "nuwa-thread-stack");
-
-  // Add protection to stack overflow: mprotect() stack top (the page at the
-  // lowest address) so we crash instead of corrupt other content that is
-  // malloc()'d.
-  mprotect(tinfo->stk, tinfo->guardSize, PROT_NONE);
-
-  pthread_attr_setstack(&tinfo->threadAttr,
-                        (char*)tinfo->stk + tinfo->guardSize,
-                        tinfo->stackSize);
-}
-
-static void
-thread_info_cleanup(void *arg) {
-  if (sNuwaForking) {
-    // We shouldn't have any thread exiting when we are forking a new process.
-    abort();
-  }
-
-  thread_info_t *tinfo = (thread_info_t *)arg;
-  pthread_attr_destroy(&tinfo->threadAttr);
-
-  munmap(tinfo->stk, tinfo->stackSize + tinfo->guardSize);
-
-  REAL(pthread_mutex_lock)(&sThreadCountLock);
-  /* unlink tinfo from sAllThreads */
-  tinfo->remove();
-  pthread_mutex_unlock(&sThreadCountLock);
-
-  if (tinfo->recrFunctions) {
-    delete tinfo->recrFunctions;
-  }
-
-  // while sThreadCountLock is held, since delete calls wrapped functions
-  // which try to lock sThreadCountLock. This results in deadlock. And we
-  // need to delete |tinfo| before decreasing sThreadCount, so Nuwa won't
-  // get ready before tinfo is cleaned.
-  delete tinfo;
-
-  REAL(pthread_mutex_lock)(&sThreadCountLock);
-  sThreadCount--;
-  pthread_cond_signal(&sThreadChangeCond);
-  pthread_mutex_unlock(&sThreadCountLock);
-}
-
-static void
-EnsureThreadExited(thread_info_t *tinfo) {
-  pid_t thread = sIsNuwaProcess ? tinfo->origNativeThreadID
-                                     : tinfo->recreatedNativeThreadID;
-  // Wait until the target thread exits. Note that we use tgkill() instead of
-  // pthread_kill() because of:
-  // 1. Use after free inside pthread implementation.
-  // 2. Race due to pthread_t reuse when a thread is created.
-  while (!syscall(__NR_tgkill, getpid(), thread, 0)) {
-    sched_yield();
-  }
-}
-
-static void*
-safe_thread_info_cleanup(void *arg)
-{
-  thread_info_t *tinfo = (thread_info_t *)arg;
-
-  // We need to ensure the thread is really dead before cleaning up tinfo.
-  EnsureThreadExited(tinfo);
-  thread_info_cleanup(tinfo);
-
-  return nullptr;
-}
-
-static void
-MaybeCleanUpDetachedThread(thread_info_t *tinfo)
-{
-  if (pthread_getattr_np(REAL(pthread_self()), &tinfo->threadAttr)) {
-    return;
-  }
-
-  int detachState = 0;
-  if (pthread_attr_getdetachstate(&tinfo->threadAttr, &detachState) ||
-      detachState == PTHREAD_CREATE_JOINABLE) {
-    // We only clean up tinfo of a detached thread. A joinable thread
-    // will be cleaned up in __wrap_pthread_join().
-    return;
-  }
-
-  // Create a detached thread to safely clean up the current thread.
-  pthread_t thread;
-  if (!REAL(pthread_create)(&thread,
-                            nullptr,
-                            safe_thread_info_cleanup,
-                            tinfo)) {
-    pthread_detach(thread);
-  }
-}
-
-static void
-invalidate_thread_info(void *arg) {
-  REAL(pthread_mutex_lock)(&sThreadCountLock);
-
-  // Unlink tinfo from sAllThreads to make it invisible from CUR_THREAD_INFO so
-  // it won't be misused by a newly created thread.
-  thread_info_t *tinfo = (thread_info_t*) arg;
-  tinfo->remove();
-  sExitingThreads.insertBack(tinfo);
-
-  pthread_mutex_unlock(&sThreadCountLock);
-
-  MaybeCleanUpDetachedThread(tinfo);
-}
-
-static void *
-_thread_create_startup(void *arg) {
-  thread_info_t *tinfo = (thread_info_t *)arg;
-  void *r;
-
-  // Save thread info; especially, stackaddr & stacksize.
-  // Reuse the stack in the new thread.
-  pthread_getattr_np(REAL(pthread_self)(), &tinfo->threadAttr);
-
-  SET_THREAD_INFO(tinfo);
-  tinfo->origThreadID = REAL(pthread_self)();
-  tinfo->origNativeThreadID = gettid();
-
-  r = tinfo->startupFunc(tinfo->startupArg);
-
-  return r;
-}
-
-// reserve STACK_RESERVED_SZ * 4 bytes for thread_recreate_startup().
-#define STACK_RESERVED_SZ 96
-#define STACK_SENTINEL(v) ((v)[0])
-#define STACK_SENTINEL_VALUE(v) ((uint32_t)(v) ^ 0xdeadbeef)
-
-static void *
-thread_create_startup(void *arg) {
-  /*
-   * Dark Art!! Never try to do the same unless you are ABSOLUTELY sure of
-   * what you are doing!
-   *
-   * This function is here for reserving stack space before calling
-   * _thread_create_startup().  see also thread_create_startup();
-   */
-  void *r;
-  volatile uint32_t reserved[STACK_RESERVED_SZ];
-
-  // Reserve stack space.
-  STACK_SENTINEL(reserved) = STACK_SENTINEL_VALUE(reserved);
-
-  r = _thread_create_startup(arg);
-
-  // Check if the reservation is enough.
-  if (STACK_SENTINEL(reserved) != STACK_SENTINEL_VALUE(reserved)) {
-    abort();                    // Did not reserve enough stack space.
-  }
-
-  // Get tinfo before invalidating it. Note that we cannot use arg directly here
-  // because thread_recreate_startup() also runs on the same stack area and
-  // could corrupt the value.
-  thread_info_t *tinfo = CUR_THREAD_INFO;
-  invalidate_thread_info(tinfo);
-
-  if (!sIsNuwaProcess) {
-    longjmp(tinfo->retEnv, 1);
-
-    // Never go here!
-    abort();
-  }
-
-  return r;
-}
-
-extern "C" MFBT_API int
-__wrap_pthread_create(pthread_t *thread,
-                      const pthread_attr_t *attr,
-                      void *(*start_routine) (void *),
-                      void *arg) {
-  if (!sIsNuwaProcess) {
-    return REAL(pthread_create)(thread, attr, start_routine, arg);
-  }
-
-  thread_info_t *tinfo = thread_info_new();
-  thread_attr_init(tinfo, attr);
-  tinfo->startupFunc = start_routine;
-  tinfo->startupArg = arg;
-
-  int rv = REAL(pthread_create)(thread,
-                                &tinfo->threadAttr,
-                                thread_create_startup,
-                                tinfo);
-  if (rv) {
-    thread_info_cleanup(tinfo);
-  } else {
-    tinfo->origThreadID = *thread;
-  }
-
-  return rv;
-}
-
-// TLS related
-
-/**
- * Iterates over the existing TLS keys and store the TLS data for the current
- * thread in tinfo.
- */
-static void
-SaveTLSInfo(thread_info_t *tinfo) {
-  MOZ_RELEASE_ASSERT(REAL(pthread_mutex_lock)(&sTLSKeyLock) == 0);
-  tinfo->tlsInfo.clear();
-  for (TLSKey *it = sTLSKeys.getFirst(); it != nullptr; it = it->getNext()) {
-    void *value = pthread_getspecific(it->first);
-    if (value == nullptr) {
-      continue;
-    }
-
-    pthread_key_t key = it->first;
-    tinfo->tlsInfo.push_back(TLSInfoList::value_type(key, value));
-  }
-  MOZ_RELEASE_ASSERT(pthread_mutex_unlock(&sTLSKeyLock) == 0);
-}
-
-/**
- * Restores the TLS data for the current thread from tinfo.
- */
-static void
-RestoreTLSInfo(thread_info_t *tinfo) {
-  for (TLSInfoList::const_iterator it = tinfo->tlsInfo.begin();
-       it != tinfo->tlsInfo.end();
-       it++) {
-    pthread_key_t key = it->first;
-    const void *value = it->second;
-    if (pthread_setspecific(key, value)) {
-      abort();
-    }
-  }
-
-  SET_THREAD_INFO(tinfo);
-  tinfo->recreatedThreadID = REAL(pthread_self)();
-  tinfo->recreatedNativeThreadID = gettid();
-}
-
-extern "C" MFBT_API int
-__wrap_pthread_key_create(pthread_key_t *key, void (*destructor)(void*)) {
-  int rv = REAL(pthread_key_create)(key, destructor);
-  if (rv != 0) {
-    return rv;
-  }
-  MOZ_RELEASE_ASSERT(REAL(pthread_mutex_lock)(&sTLSKeyLock) == 0);
-  sTLSKeys.insertBack(new TLSKey(*key, destructor));
-  MOZ_RELEASE_ASSERT(pthread_mutex_unlock(&sTLSKeyLock) == 0);
-  return 0;
-}
-
-extern "C" MFBT_API int
-__wrap_pthread_key_delete(pthread_key_t key) {
-  // Don't call pthread_key_delete() for Nuwa-forked processes because bionic's
-  // pthread_key_delete() implementation can touch the thread stack that was
-  // freed in thread_info_cleanup().
-  int rv = sIsNuwaChildProcess ?
-             0 : REAL(pthread_key_delete)(key);
-  if (rv != 0) {
-    return rv;
-  }
-  MOZ_RELEASE_ASSERT(REAL(pthread_mutex_lock)(&sTLSKeyLock) == 0);
-  for (TLSKey *it = sTLSKeys.getFirst(); it != nullptr; it = it->getNext()) {
-    if (key == it->first) {
-      delete it;
-      break;
-    }
-  }
-  MOZ_RELEASE_ASSERT(pthread_mutex_unlock(&sTLSKeyLock) == 0);
-  return 0;
-}
-
-extern "C" MFBT_API pthread_t
-__wrap_pthread_self() {
-  thread_info_t *tinfo = CUR_THREAD_INFO;
-  if (tinfo) {
-    // For recreated thread, masquerade as the original thread in the Nuwa
-    // process.
-    return tinfo->origThreadID;
-  }
-  return REAL(pthread_self)();
-}
-
-extern "C" MFBT_API int
-__wrap_pthread_join(pthread_t thread, void **retval) {
-  thread_info_t *tinfo = GetThreadInfo(thread);
-  if (tinfo == nullptr) {
-    return REAL(pthread_join)(thread, retval);
-  }
-
-  pthread_t thread_info_t::*threadIDptr =
-        (sIsNuwaProcess ?
-           &thread_info_t::origThreadID :
-           &thread_info_t::recreatedThreadID);
-
-  // pthread_join() uses the origThreadID or recreatedThreadID depending on
-  // whether we are in Nuwa or forked processes.
-  int rc = REAL(pthread_join)(tinfo->*threadIDptr, retval);
-
-  // Before Android L, bionic wakes up the caller of pthread_join() with
-  // pthread_cond_signal() so the thread can still use the stack for some while.
-  // Call safe_thread_info_cleanup() to destroy tinfo after the thread really
-  // exits.
-  safe_thread_info_cleanup(tinfo);
-
-  return rc;
-}
-
-/**
- * The following are used to synchronize between the main thread and the
- * thread being recreated. The main thread will wait until the thread is woken
- * up from the freeze points or the blocking intercepted functions and then
- * proceed to recreate the next frozen thread.
- *
- * In thread recreation, the main thread recreates the frozen threads one by
- * one. The recreated threads will be "gated" until the main thread "opens the
- * gate" to let them run freely as if they were created from scratch. The VIP
- * threads gets the chance to run first after their thread stacks are recreated
- * (using longjmp()) so they can adjust their contexts to a valid, consistent
- * state. The threads frozen waiting for pthread condition variables are VIP
- * threads. After woken up they need to run first to make the associated mutex
- * in a valid state to maintain the semantics of the intercepted function calls
- * (like pthread_cond_wait()).
- */
-
-// Used to synchronize the main thread and the thread being recreated so that
-// only one thread is allowed to be recreated at a time.
-static pthread_mutex_t sRecreateWaitLock = PTHREAD_MUTEX_INITIALIZER;
-// Used to block recreated threads until the main thread "opens the gate".
-static pthread_mutex_t sRecreateGateLock = PTHREAD_MUTEX_INITIALIZER;
-// Used to block the main thread from "opening the gate" until all VIP threads
-// have been recreated.
-static pthread_mutex_t sRecreateVIPGateLock = PTHREAD_MUTEX_INITIALIZER;
-static pthread_cond_t sRecreateVIPCond = PTHREAD_COND_INITIALIZER;
-static int sRecreateVIPCount = 0;
-static int sRecreateGatePassed = 0;
-
-/**
- * Thread recreation macros.
- *
- * The following macros are used in the forked process to synchronize and
- * control the progress of thread recreation.
- *
- * 1. RECREATE_START() is first called in the beginning of thread
- *    recreation to set sRecreateWaitLock and sRecreateGateLock in locked
- *    state.
- * 2. For each frozen thread:
- *    2.1. RECREATE_BEFORE() to set the thread being recreated.
- *    2.2. thread_recreate() to recreate the frozen thread.
- *    2.3. Main thread calls RECREATE_WAIT() to wait on sRecreateWaitLock until
- *         the thread is recreated from the freeze point and calls
- *         RECREATE_CONTINUE() to release sRecreateWaitLock.
- *    2.3. Non-VIP threads are blocked on RECREATE_GATE(). VIP threads calls
- *         RECREATE_PASS_VIP() to mark that a VIP thread is successfully
- *         recreated and then is blocked by calling RECREATE_GATE_VIP().
- * 3. RECREATE_WAIT_ALL_VIP() to wait until all VIP threads passed, that is,
- *    VIP threads already has their contexts (mainly pthread mutex) in a valid
- *    state.
- * 4. RECREATE_OPEN_GATE() to unblock threads blocked by sRecreateGateLock.
- * 5. RECREATE_FINISH() to complete thread recreation.
- */
-#define RECREATE_START()                          \
-  do {                                            \
-    REAL(pthread_mutex_lock)(&sRecreateWaitLock); \
-    REAL(pthread_mutex_lock)(&sRecreateGateLock); \
-  } while(0)
-#define RECREATE_BEFORE(info) do { sCurrentRecreatingThread = info; } while(0)
-#define RECREATE_WAIT() REAL(pthread_mutex_lock)(&sRecreateWaitLock)
-#define RECREATE_CONTINUE() do {                \
-    RunCustomRecreation();                      \
-    pthread_mutex_unlock(&sRecreateWaitLock);   \
-  } while(0)
-#define RECREATE_FINISH() pthread_mutex_unlock(&sRecreateWaitLock)
-#define RECREATE_GATE()                           \
-  do {                                            \
-    REAL(pthread_mutex_lock)(&sRecreateGateLock); \
-    sRecreateGatePassed++;                        \
-    pthread_mutex_unlock(&sRecreateGateLock);     \
-  } while(0)
-#define RECREATE_OPEN_GATE() pthread_mutex_unlock(&sRecreateGateLock)
-#define RECREATE_GATE_VIP()                       \
-  do {                                            \
-    REAL(pthread_mutex_lock)(&sRecreateGateLock); \
-    pthread_mutex_unlock(&sRecreateGateLock);     \
-  } while(0)
-#define RECREATE_PASS_VIP()                          \
-  do {                                               \
-    REAL(pthread_mutex_lock)(&sRecreateVIPGateLock); \
-    sRecreateGatePassed++;                           \
-    pthread_cond_signal(&sRecreateVIPCond);          \
-    pthread_mutex_unlock(&sRecreateVIPGateLock);     \
-  } while(0)
-#define RECREATE_WAIT_ALL_VIP()                        \
-  do {                                                 \
-    REAL(pthread_mutex_lock)(&sRecreateVIPGateLock);   \
-    while(sRecreateGatePassed < sRecreateVIPCount) {   \
-      REAL(pthread_cond_wait)(&sRecreateVIPCond,       \
-                        &sRecreateVIPGateLock);        \
-    }                                                  \
-    pthread_mutex_unlock(&sRecreateVIPGateLock);       \
-  } while(0)
-
-/**
- * Thread freeze points. Note that the freeze points are implemented as macros
- * so as not to garble the content of the stack after setjmp().
- *
- * In the nuwa process, when a thread supporting nuwa calls a wrapper
- * function, freeze point 1 setjmp()s to save the state. We only allow the
- * thread to be frozen in the wrapper functions. If thread freezing is not
- * enabled yet, the wrapper functions act like their wrapped counterparts,
- * except for the extra actions in the freeze points. If thread freezing is
- * enabled, the thread will be frozen by calling one of the wrapper functions.
- * The threads can be frozen in any of the following points:
- *
- * 1) Freeze point 1: this is the point where we setjmp() in the nuwa process
- *    and longjmp() in the spawned process. If freezing is enabled, then the
- *    current thread blocks by acquiring an already locked mutex,
- *    sThreadFreezeLock.
- * 2) The wrapped function: the function that might block waiting for some
- *    resource or condition.
- * 3) Freeze point 2: blocks the current thread by acquiring sThreadFreezeLock.
- *    If freezing is not enabled then revert the counter change in freeze
- *    point 1.
- *
- * Note: the purpose of the '(void) variable;' statements is to avoid
- *       -Wunused-but-set-variable warnings.
- */
-#define THREAD_FREEZE_POINT1()                                 \
-  bool freezeCountChg = false;                                 \
-  bool recreated = false;                                      \
-  (void) recreated;                                            \
-  volatile bool freezePoint2 = false;                          \
-  (void) freezePoint2;                                         \
-  thread_info_t *tinfo;                                        \
-  if (sIsNuwaProcess &&                                        \
-      (tinfo = CUR_THREAD_INFO) &&                             \
-      (tinfo->flags & TINFO_FLAG_NUWA_SUPPORT) &&              \
-      !(tinfo->flags & TINFO_FLAG_NUWA_EXPLICIT_CHECKPOINT)) { \
-    if (!setjmp(tinfo->jmpEnv)) {                              \
-      REAL(pthread_mutex_lock)(&sThreadCountLock);             \
-      SaveTLSInfo(tinfo);                                      \
-      sThreadFreezeCount++;                                    \
-      freezeCountChg = true;                                   \
-      pthread_cond_signal(&sThreadChangeCond);                 \
-      pthread_mutex_unlock(&sThreadCountLock);                 \
-                                                               \
-      if (sIsFreezing) {                                       \
-        REAL(pthread_mutex_lock)(&sThreadFreezeLock);          \
-        /* Never return from the pthread_mutex_lock() call. */ \
-        abort();                                               \
-      }                                                        \
-    } else {                                                   \
-      POST_SETJMP_RESTORE("THREAD_FREEZE_POINT1");             \
-      RECREATE_CONTINUE();                                     \
-      RECREATE_GATE();                                         \
-      freezeCountChg = false;                                  \
-      recreated = true;                                        \
-    }                                                          \
-  }
-
-#define THREAD_FREEZE_POINT1_VIP()                             \
-  bool freezeCountChg = false;                                 \
-  bool recreated = false;                                      \
-  volatile bool freezePoint1 = false;                          \
-  volatile bool freezePoint2 = false;                          \
-  thread_info_t *tinfo;                                        \
-  if (sIsNuwaProcess &&                                        \
-      (tinfo = CUR_THREAD_INFO) &&                             \
-      (tinfo->flags & TINFO_FLAG_NUWA_SUPPORT) &&              \
-      !(tinfo->flags & TINFO_FLAG_NUWA_EXPLICIT_CHECKPOINT)) { \
-    if (!setjmp(tinfo->jmpEnv)) {                              \
-      REAL(pthread_mutex_lock)(&sThreadCountLock);             \
-      SaveTLSInfo(tinfo);                                      \
-      sThreadFreezeCount++;                                    \
-      sRecreateVIPCount++;                                     \
-      freezeCountChg = true;                                   \
-      pthread_cond_signal(&sThreadChangeCond);                 \
-      pthread_mutex_unlock(&sThreadCountLock);                 \
-                                                               \
-      if (sIsFreezing) {                                       \
-        freezePoint1 = true;                                   \
-        REAL(pthread_mutex_lock)(&sThreadFreezeLock);          \
-        /* Never return from the pthread_mutex_lock() call. */ \
-        abort();                                               \
-      }                                                        \
-    } else {                                                   \
-      POST_SETJMP_RESTORE("THREAD_FREEZE_POINT1_VIP");         \
-      freezeCountChg = false;                                  \
-      recreated = true;                                        \
-    }                                                          \
-  }
-
-#define THREAD_FREEZE_POINT2()                               \
-  if (freezeCountChg) {                                      \
-    REAL(pthread_mutex_lock)(&sThreadCountLock);             \
-    if (sNuwaReady && sIsNuwaProcess) {                      \
-      pthread_mutex_unlock(&sThreadCountLock);               \
-      freezePoint2 = true;                                   \
-      REAL(pthread_mutex_lock)(&sThreadFreezeLock);          \
-      /* Never return from the pthread_mutex_lock() call. */ \
-      abort();                                               \
-    }                                                        \
-    sThreadFreezeCount--;                                    \
-    pthread_cond_signal(&sThreadChangeCond);                 \
-    pthread_mutex_unlock(&sThreadCountLock);                 \
-  }
-
-#define THREAD_FREEZE_POINT2_VIP()                           \
-  if (freezeCountChg) {                                      \
-    REAL(pthread_mutex_lock)(&sThreadCountLock);             \
-    if (sNuwaReady && sIsNuwaProcess) {                      \
-      pthread_mutex_unlock(&sThreadCountLock);               \
-      freezePoint2 = true;                                   \
-      REAL(pthread_mutex_lock)(&sThreadFreezeLock);          \
-      /* Never return from the pthread_mutex_lock() call. */ \
-      abort();                                               \
-    }                                                        \
-    sThreadFreezeCount--;                                    \
-    sRecreateVIPCount--;                                     \
-    pthread_cond_signal(&sThreadChangeCond);                 \
-    pthread_mutex_unlock(&sThreadCountLock);                 \
-  }
-
-/**
- * Wrapping the blocking functions: epoll_wait(), poll(), pthread_mutex_lock(),
- * pthread_cond_wait() and pthread_cond_timedwait():
- *
- * These functions are wrapped by the above freeze point macros. Once a new
- * process is forked, the recreated thread will be blocked in one of the wrapper
- * functions. When recreating the thread, we longjmp() to
- * THREAD_FREEZE_POINT1() to recover the thread stack. Care must be taken to
- * maintain the semantics of the wrapped function:
- *
- * - epoll_wait() and poll(): just retry the function.
- * - pthread_mutex_lock(): don't lock if frozen at freeze point 2 (lock is
- *   already acquired).
- * - pthread_cond_wait() and pthread_cond_timedwait(): if the thread is frozen
- *   waiting the condition variable, the mutex is already released, we need to
- *   reacquire the mutex before calling the wrapped function again so the mutex
- *   will be in a valid state.
- */
-
-extern "C" MFBT_API int
-__wrap_epoll_wait(int epfd,
-                  struct epoll_event *events,
-                  int maxevents,
-                  int timeout) {
-  int rv;
-
-  THREAD_FREEZE_POINT1();
-  rv = REAL(epoll_wait)(epfd, events, maxevents, timeout);
-  THREAD_FREEZE_POINT2();
-
-  return rv;
-}
-
-extern "C" MFBT_API int
-__wrap_pthread_cond_wait(pthread_cond_t *cond,
-                         pthread_mutex_t *mtx) {
-  int rv = 0;
-
-  THREAD_FREEZE_POINT1_VIP();
-  if (freezePoint2) {
-    RECREATE_CONTINUE();
-    RECREATE_PASS_VIP();
-    RECREATE_GATE_VIP();
-    return rv;
-  }
-  if (recreated && mtx) {
-    if (!freezePoint1) {
-      tinfo->condMutex = mtx;
-      // The thread was frozen in pthread_cond_wait() after releasing mtx in the
-      // Nuwa process. In recreating this thread, We failed to reacquire mtx
-      // with the pthread_mutex_trylock() call, that is, mtx was acquired by
-      // another thread. Because of this, we need the main thread's help to
-      // reacquire mtx so that it will be in a valid state.
-      if (!pthread_mutex_trylock(mtx)) {
-        tinfo->condMutexNeedsBalancing = true;
-      }
-    }
-    RECREATE_CONTINUE();
-    RECREATE_PASS_VIP();
-  }
-  rv = REAL(pthread_cond_wait)(cond, mtx);
-  if (recreated && mtx) {
-    // We have reacquired mtx. The main thread also wants to acquire mtx to
-    // synchronize with us. If the main thread didn't get a chance to acquire
-    // mtx let it do that now. The main thread clears condMutex after acquiring
-    // it to signal us.
-    if (tinfo->condMutex) {
-      // We need mtx to end up locked, so tell the main thread not to unlock
-      // mtx after it locks it.
-      tinfo->condMutexNeedsBalancing = false;
-      pthread_mutex_unlock(mtx);
-    }
-    // We still need to be gated as not to acquire another mutex associated with
-    // another VIP thread and interfere with it.
-    RECREATE_GATE_VIP();
-  }
-  THREAD_FREEZE_POINT2_VIP();
-
-  return rv;
-}
-
-extern "C" MFBT_API int
-__wrap_pthread_cond_timedwait(pthread_cond_t *cond,
-                              pthread_mutex_t *mtx,
-                              const struct timespec *abstime) {
-  int rv = 0;
-
-  THREAD_FREEZE_POINT1_VIP();
-  if (freezePoint2) {
-    RECREATE_CONTINUE();
-    RECREATE_PASS_VIP();
-    RECREATE_GATE_VIP();
-    return rv;
-  }
-  if (recreated && mtx) {
-    if (!freezePoint1) {
-      tinfo->condMutex = mtx;
-      if (!pthread_mutex_trylock(mtx)) {
-        tinfo->condMutexNeedsBalancing = true;
-      }
-    }
-    RECREATE_CONTINUE();
-    RECREATE_PASS_VIP();
-  }
-  rv = REAL(pthread_cond_timedwait)(cond, mtx, abstime);
-  if (recreated && mtx) {
-    if (tinfo->condMutex) {
-      tinfo->condMutexNeedsBalancing = false;
-      pthread_mutex_unlock(mtx);
-    }
-    RECREATE_GATE_VIP();
-  }
-  THREAD_FREEZE_POINT2_VIP();
-
-  return rv;
-}
-
-
-extern "C" MFBT_API int
-__wrap_pthread_mutex_trylock(pthread_mutex_t *mtx) {
-  int rv = 0;
-
-  THREAD_FREEZE_POINT1();
-  if (freezePoint2) {
-    return rv;
-  }
-  rv = REAL(pthread_mutex_trylock)(mtx);
-  THREAD_FREEZE_POINT2();
-
-  return rv;
-}
-
-extern "C" MFBT_API int
-__wrap_pthread_mutex_lock(pthread_mutex_t *mtx) {
-  int rv = 0;
-
-  THREAD_FREEZE_POINT1();
-  if (freezePoint2) {
-    return rv;
-  }
-  rv = REAL(pthread_mutex_lock)(mtx);
-  THREAD_FREEZE_POINT2();
-
-  return rv;
-}
-
-extern "C" MFBT_API int
-__wrap_poll(struct pollfd *fds, nfds_t nfds, int timeout) {
-  int rv;
-
-  THREAD_FREEZE_POINT1();
-  rv = REAL(poll)(fds, nfds, timeout);
-  THREAD_FREEZE_POINT2();
-
-  return rv;
-}
-
-extern "C" MFBT_API int
-__wrap_epoll_create(int size) {
-  int epollfd = REAL(epoll_create)(size);
-
-  if (!sIsNuwaProcess) {
-    return epollfd;
-  }
-
-  if (epollfd >= 0) {
-    EpollManager::Singleton()->AddEpollInfo(epollfd, size);
-  }
-
-  return epollfd;
-}
-
-/**
- * Wrapping the functions to create file descriptor pairs. In the child process
- * FD pairs are created for intra-process signaling. The generation of FD pairs
- * need to be tracked in the nuwa process so they can be recreated in the
- * spawned process.
- */
-struct FdPairInfo {
-  enum {
-    kPipe,
-    kSocketpair
-  } call;
-
-  int FDs[2];
-  int flags;
-  int domain;
-  int type;
-  int protocol;
-};
-
-/**
- * Protects the access to sSingalFds.
- */
-static pthread_mutex_t  sSignalFdLock = PTHREAD_MUTEX_INITIALIZER;
-static std::vector<FdPairInfo> sSignalFds;
-
-extern "C" MFBT_API int
-__wrap_socketpair(int domain, int type, int protocol, int sv[2])
-{
-  int rv = REAL(socketpair)(domain, type, protocol, sv);
-
-  if (!sIsNuwaProcess || rv < 0) {
-    return rv;
-  }
-
-  REAL(pthread_mutex_lock)(&sSignalFdLock);
-  FdPairInfo signalFd;
-  signalFd.call = FdPairInfo::kSocketpair;
-  signalFd.FDs[0] = sv[0];
-  signalFd.FDs[1] = sv[1];
-  signalFd.domain = domain;
-  signalFd.type = type;
-  signalFd.protocol = protocol;
-
-  sSignalFds.push_back(signalFd);
-  pthread_mutex_unlock(&sSignalFdLock);
-
-  return rv;
-}
-
-extern "C" MFBT_API int
-__wrap_pipe2(int __pipedes[2], int flags)
-{
-  int rv = REAL(pipe2)(__pipedes, flags);
-  if (!sIsNuwaProcess || rv < 0) {
-    return rv;
-  }
-
-  REAL(pthread_mutex_lock)(&sSignalFdLock);
-  FdPairInfo signalFd;
-  signalFd.call = FdPairInfo::kPipe;
-  signalFd.FDs[0] = __pipedes[0];
-  signalFd.FDs[1] = __pipedes[1];
-  signalFd.flags = flags;
-  sSignalFds.push_back(signalFd);
-  pthread_mutex_unlock(&sSignalFdLock);
-  return rv;
-}
-
-extern "C" MFBT_API int
-__wrap_pipe(int __pipedes[2])
-{
-  return __wrap_pipe2(__pipedes, 0);
-}
-
-static void
-DupeSingleFd(int newFd, int origFd)
-{
-  struct stat sb;
-  if (fstat(origFd, &sb)) {
-    // Maybe the original FD is closed.
-    return;
-  }
-  int fd = fcntl(origFd, F_GETFD);
-  int fl = fcntl(origFd, F_GETFL);
-  dup2(newFd, origFd);
-  fcntl(origFd, F_SETFD, fd);
-  fcntl(origFd, F_SETFL, fl);
-  REAL(close)(newFd);
-}
-
-extern "C" MFBT_API void
-ReplaceSignalFds()
-{
-  for (std::vector<FdPairInfo>::iterator it = sSignalFds.begin();
-       it < sSignalFds.end(); ++it) {
-    int fds[2];
-    int rc = 0;
-    switch (it->call) {
-    case FdPairInfo::kPipe:
-      rc = REAL(pipe2)(fds, it->flags);
-      break;
-    case FdPairInfo::kSocketpair:
-      rc = REAL(socketpair)(it->domain, it->type, it->protocol, fds);
-      break;
-    default:
-      continue;
-    }
-
-    if (rc == 0) {
-      DupeSingleFd(fds[0], it->FDs[0]);
-      DupeSingleFd(fds[1], it->FDs[1]);
-    }
-  }
-}
-
-extern "C" MFBT_API int
-__wrap_epoll_ctl(int aEpollFd, int aOp, int aFd, struct epoll_event *aEvent) {
-  int rv = REAL(epoll_ctl)(aEpollFd, aOp, aFd, aEvent);
-
-  if (!sIsNuwaProcess || rv == -1) {
-    return rv;
-  }
-
-  EpollManager::EpollInfo *info =
-    EpollManager::Singleton()->FindEpollInfo(aEpollFd);
-  if (info == nullptr) {
-    abort();
-  }
-
-  switch(aOp) {
-  case EPOLL_CTL_ADD:
-    info->AddEvents(aFd, *aEvent);
-    break;
-
-  case EPOLL_CTL_MOD:
-    info->ModifyEvents(aFd, *aEvent);
-    break;
-
-  case EPOLL_CTL_DEL:
-    info->RemoveEvents(aFd);
-    break;
-
-  default:
-    abort();
-  }
-
-  return rv;
-}
-
-// XXX: thinker: Maybe, we should also track dup, dup2, and other functions.
-extern "C" MFBT_API int
-__wrap_close(int aFd) {
-  int rv = REAL(close)(aFd);
-  if (!sIsNuwaProcess || rv == -1) {
-    return rv;
-  }
-
-  EpollManager::EpollInfo *info =
-    EpollManager::Singleton()->FindEpollInfo(aFd);
-  if (info) {
-    EpollManager::Singleton()->RemoveEpollInfo(aFd);
-  }
-
-  return rv;
-}
-
-static void *
-thread_recreate_startup(void *arg) {
-  /*
-   * Dark Art!! Never do the same unless you are ABSOLUTELY sure what you are
-   * doing!
-   *
-   * The stack space collapsed by this frame had been reserved by
-   * thread_create_startup().  And thread_create_startup() will
-   * return immediately after returning from real start routine, so
-   * all collapsed values does not affect the result.
-   *
-   * All outer frames of thread_create_startup() and
-   * thread_recreate_startup() are equivalent, so
-   * thread_create_startup() will return successfully.
-   */
-  thread_info_t *tinfo = (thread_info_t *)arg;
-
-  prctl(PR_SET_NAME, (unsigned long)&tinfo->nativeThreadName, 0, 0, 0);
-  RestoreTLSInfo(tinfo);
-
-  if (setjmp(tinfo->retEnv) != 0) {
-    POST_SETJMP_RESTORE("thread_recreate_startup");
-    return nullptr;
-  }
-
-  // longjump() to recreate the stack on the new thread.
-  longjmp(tinfo->jmpEnv, 1);
-
-  // Never go here!
-  abort();
-
-  return nullptr;
-}
-
-/**
- * Recreate the context given by tinfo at a new thread.
- */
-static void
-thread_recreate(thread_info_t *tinfo) {
-  pthread_t thread;
-
-  // Note that the thread_recreate_startup() runs on the stack specified by
-  // tinfo.
-  pthread_create(&thread, &tinfo->threadAttr, thread_recreate_startup, tinfo);
-}
-
-/**
- * Recreate all threads in a process forked from an Nuwa process.
- */
-static void
-RecreateThreads() {
-  sIsNuwaProcess = false;
-  sIsFreezing = false;
-
-  sMainThread.recreatedThreadID = pthread_self();
-  sMainThread.recreatedNativeThreadID = gettid();
-
-  // Run registered constructors.
-  for (std::vector<nuwa_construct_t>::iterator ctr = sConstructors.begin();
-       ctr != sConstructors.end();
-       ctr++) {
-    (*ctr).construct((*ctr).arg);
-  }
-  sConstructors.clear();
-
-  REAL(pthread_mutex_lock)(&sThreadCountLock);
-  thread_info_t *tinfo = sAllThreads.getFirst();
-  pthread_mutex_unlock(&sThreadCountLock);
-
-  RECREATE_START();
-  while (tinfo != nullptr) {
-    if (tinfo->flags & TINFO_FLAG_NUWA_SUPPORT) {
-      RECREATE_BEFORE(tinfo);
-      thread_recreate(tinfo);
-      RECREATE_WAIT();
-      if (tinfo->condMutex) {
-        // Synchronize with the recreated thread in pthread_cond_wait().
-        REAL(pthread_mutex_lock)(tinfo->condMutex);
-        // Tell the other thread that we have successfully locked the mutex.
-        // NB: condMutex can only be touched while it is held, so we must clear
-        // it here and store the mutex locally.
-        pthread_mutex_t *mtx = tinfo->condMutex;
-        tinfo->condMutex = nullptr;
-        if (tinfo->condMutexNeedsBalancing) {
-          pthread_mutex_unlock(mtx);
-        }
-      }
-    } else if(!(tinfo->flags & TINFO_FLAG_NUWA_SKIP)) {
-      // An unmarked thread is found other than the main thread.
-
-      // All threads should be marked as one of SUPPORT or SKIP, or
-      // abort the process to make sure all threads in the Nuwa
-      // process are Nuwa-aware.
-      abort();
-    }
-
-    tinfo = tinfo->getNext();
-  }
-  RECREATE_WAIT_ALL_VIP();
-  RECREATE_OPEN_GATE();
-
-  RECREATE_FINISH();
-
-  // Run registered final constructors.
-  for (std::vector<nuwa_construct_t>::iterator ctr = sFinalConstructors.begin();
-       ctr != sFinalConstructors.end();
-       ctr++) {
-    (*ctr).construct((*ctr).arg);
-  }
-  sFinalConstructors.clear();
-}
-
-extern "C" {
-
-/**
- * Recreate all epoll fds and restore status; include all events.
- */
-static void
-RecreateEpollFds() {
-  EpollManager *man = EpollManager::Singleton();
-
-  for (EpollManager::const_iterator info_it = man->begin();
-       info_it != man->end();
-       info_it++) {
-    int epollfd = info_it->first;
-    const EpollManager::EpollInfo *info = &info_it->second;
-
-    int fdflags = fcntl(epollfd, F_GETFD);
-    if (fdflags == -1) {
-      abort();
-    }
-    int fl = fcntl(epollfd, F_GETFL);
-    if (fl == -1) {
-      abort();
-    }
-
-    int newepollfd = REAL(epoll_create)(info->BackSize());
-    if (newepollfd == -1) {
-      abort();
-    }
-    int rv = REAL(close)(epollfd);
-    if (rv == -1) {
-      abort();
-    }
-    rv = dup2(newepollfd, epollfd);
-    if (rv == -1) {
-      abort();
-    }
-    rv = REAL(close)(newepollfd);
-    if (rv == -1) {
-      abort();
-    }
-
-    rv = fcntl(epollfd, F_SETFD, fdflags);
-    if (rv == -1) {
-      abort();
-    }
-    rv = fcntl(epollfd, F_SETFL, fl);
-    if (rv == -1) {
-      abort();
-    }
-
-    for (EpollManager::EpollInfo::const_iterator events_it = info->begin();
-         events_it != info->end();
-         events_it++) {
-      int fd = events_it->first;
-      epoll_event events;
-      events = events_it->second;
-      rv = REAL(epoll_ctl)(epollfd, EPOLL_CTL_ADD, fd, &events);
-      if (rv == -1) {
-        abort();
-      }
-    }
-  }
-
-  // Shutdown EpollManager. It won't be needed in the spawned process.
-  EpollManager::Shutdown();
-}
-
-/**
- * Fix IPC to make it ready.
- *
- * Especially, fix ContentChild.
- */
-static void
-ReplaceIPC(NuwaProtoFdInfo *aInfoList, int aInfoSize) {
-  int i;
-  int rv;
-
-  for (i = 0; i < aInfoSize; i++) {
-    int fd = fcntl(aInfoList[i].originFd, F_GETFD);
-    if (fd == -1) {
-      abort();
-    }
-
-    int fl = fcntl(aInfoList[i].originFd, F_GETFL);
-    if (fl == -1) {
-      abort();
-    }
-
-    rv = dup2(aInfoList[i].newFds[NUWA_NEWFD_CHILD], aInfoList[i].originFd);
-    if (rv == -1) {
-      abort();
-    }
-
-    rv = fcntl(aInfoList[i].originFd, F_SETFD, fd);
-    if (rv == -1) {
-      abort();
-    }
-
-    rv = fcntl(aInfoList[i].originFd, F_SETFL, fl);
-    if (rv == -1) {
-      abort();
-    }
-  }
-}
-
-/**
- * Add a new content process at the chrome process.
- */
-static void
-AddNewProcess(pid_t pid, NuwaProtoFdInfo *aInfoList, int aInfoSize) {
-  static bool (*AddNewIPCProcess)(pid_t, NuwaProtoFdInfo *, int) = nullptr;
-
-  if (AddNewIPCProcess == nullptr) {
-    AddNewIPCProcess = (bool (*)(pid_t, NuwaProtoFdInfo *, int))
-      dlsym(RTLD_DEFAULT, "AddNewIPCProcess");
-  }
-  AddNewIPCProcess(pid, aInfoList, aInfoSize);
-}
-
-static void
-PrepareProtoSockets(NuwaProtoFdInfo *aInfoList, int aInfoSize) {
-  int i;
-  int rv;
-
-  for (i = 0; i < aInfoSize; i++) {
-    rv = REAL(socketpair)(PF_UNIX, SOCK_STREAM, 0, aInfoList[i].newFds);
-    if (rv == -1) {
-      abort();
-    }
-  }
-}
-
-static void
-CloseAllProtoSockets(NuwaProtoFdInfo *aInfoList, int aInfoSize) {
-  int i;
-
-  for (i = 0; i < aInfoSize; i++) {
-    REAL(close)(aInfoList[i].newFds[0]);
-    REAL(close)(aInfoList[i].newFds[1]);
-  }
-}
-
-static void
-AfterForkHook()
-{
-  void (*AfterNuwaFork)();
-
-  // This is defined in dom/ipc/ContentChild.cpp
-  AfterNuwaFork = (void (*)())
-    dlsym(RTLD_DEFAULT, "AfterNuwaFork");
-  AfterNuwaFork();
-}
-
-/**
- * Fork a new process that is ready for running IPC.
- *
- * @return the PID of the new process.
- */
-static int
-ForkIPCProcess() {
-  int pid;
-
-  REAL(pthread_mutex_lock)(&sForkLock);
-
-  PrepareProtoSockets(sProtoFdInfos, sProtoFdInfosSize);
-
-  sNuwaForking = true;
-  pid = fork();
-  sNuwaForking = false;
-  if (pid == -1) {
-    abort();
-  }
-
-  if (pid > 0) {
-    // in the parent
-    AddNewProcess(pid, sProtoFdInfos, sProtoFdInfosSize);
-    CloseAllProtoSockets(sProtoFdInfos, sProtoFdInfosSize);
-  } else {
-    // in the child
-    sIsNuwaChildProcess = true;
-    if (getenv("MOZ_DEBUG_CHILD_PROCESS")) {
-      printf("\n\nNUWA CHILDCHILDCHILDCHILD\n  debug me @ %d\n\n", getpid());
-      sleep(30);
-    }
-    AfterForkHook();
-    ReplaceSignalFds();
-    ReplaceIPC(sProtoFdInfos, sProtoFdInfosSize);
-    RecreateEpollFds();
-    RecreateThreads();
-    CloseAllProtoSockets(sProtoFdInfos, sProtoFdInfosSize);
-  }
-
-  sForkWaitCondChanged = true;
-  pthread_cond_signal(&sForkWaitCond);
-  pthread_mutex_unlock(&sForkLock);
-
-  return pid;
-}
-
-/**
- * Prepare for spawning a new process. Called on the IPC thread.
- */
-MFBT_API void
-NuwaSpawnPrepare() {
-  REAL(pthread_mutex_lock)(&sForkLock);
-
-  sForkWaitCondChanged = false; // Will be modified on the main thread.
-}
-
-/**
- * Let IPC thread wait until fork action on the main thread has completed.
- */
-MFBT_API void
-NuwaSpawnWait() {
-  while (!sForkWaitCondChanged) {
-    REAL(pthread_cond_wait)(&sForkWaitCond, &sForkLock);
-  }
-  pthread_mutex_unlock(&sForkLock);
-}
-
-/**
- * Spawn a new process. If not ready for spawn (still waiting for some threads
- * to freeze), postpone the spawn request until ready.
- *
- * @return the pid of the new process, or 0 if not ready.
- */
-MFBT_API pid_t
-NuwaSpawn() {
-  if (gettid() != getpid()) {
-    // Not the main thread.
-    abort();
-  }
-
-  pid_t pid = 0;
-
-  if (sNuwaReady) {
-    pid = ForkIPCProcess();
-  } else {
-    sNuwaPendingSpawn = true;
-  }
-
-  return pid;
-}
-
-/**
- * Prepare to freeze the Nuwa-supporting threads.
- */
-MFBT_API void
-PrepareNuwaProcess() {
-  sIsNuwaProcess = true;
-  // Explicitly ignore SIGCHLD so we don't have to call watpid() to reap
-  // dead child processes.
-  signal(SIGCHLD, SIG_IGN);
-
-  // Make marked threads block in one freeze point.
-  REAL(pthread_mutex_lock)(&sThreadFreezeLock);
-
-  // Populate sMainThread for mapping of tgkill.
-  sMainThread.origThreadID = pthread_self();
-  sMainThread.origNativeThreadID = gettid();
-}
-
-// Make current process as a Nuwa process.
-MFBT_API void
-MakeNuwaProcess() {
-  void (*GetProtoFdInfos)(NuwaProtoFdInfo *, int, int *) = nullptr;
-  void (*OnNuwaProcessReady)() = nullptr;
-  sIsFreezing = true;
-
-  REAL(pthread_mutex_lock)(&sThreadCountLock);
-
-  // wait until all threads are frozen.
-  while ((sThreadFreezeCount + sThreadSkipCount) != sThreadCount) {
-    REAL(pthread_cond_wait)(&sThreadChangeCond, &sThreadCountLock);
-  }
-
-  GetProtoFdInfos = (void (*)(NuwaProtoFdInfo *, int, int *))
-    dlsym(RTLD_DEFAULT, "GetProtoFdInfos");
-  GetProtoFdInfos(sProtoFdInfos, NUWA_TOPLEVEL_MAX, &sProtoFdInfosSize);
-
-  sNuwaReady = true;
-
-  pthread_mutex_unlock(&sThreadCountLock);
-
-  OnNuwaProcessReady = (void (*)())dlsym(RTLD_DEFAULT, "OnNuwaProcessReady");
-  OnNuwaProcessReady();
-
-  if (sNuwaPendingSpawn) {
-    sNuwaPendingSpawn = false;
-    NuwaSpawn();
-  }
-}
-
-/**
- * Mark the current thread as supporting Nuwa. The thread will be recreated in
- * the spawned process.
- */
-MFBT_API void
-NuwaMarkCurrentThread(void (*recreate)(void *), void *arg) {
-  if (!sIsNuwaProcess) {
-    return;
-  }
-
-  thread_info_t *tinfo = CUR_THREAD_INFO;
-  if (tinfo == nullptr) {
-    abort();
-  }
-
-  tinfo->flags |= TINFO_FLAG_NUWA_SUPPORT;
-  if (recreate) {
-    nuwa_construct_t construct(recreate, arg);
-    tinfo->addThreadConstructor(&construct);
-  }
-
-  // XXX Thread name might be set later than this call. If this is the case, we
-  // might need to delay getting the thread name.
-  prctl(PR_GET_NAME, (unsigned long)&tinfo->nativeThreadName, 0, 0, 0);
-}
-
-/**
- * Mark the current thread as not supporting Nuwa. Don't recreate this thread in
- * the spawned process.
- */
-MFBT_API void
-NuwaSkipCurrentThread() {
-  if (!sIsNuwaProcess) return;
-
-  thread_info_t *tinfo = CUR_THREAD_INFO;
-  if (tinfo == nullptr) {
-    abort();
-  }
-
-  if (!(tinfo->flags & TINFO_FLAG_NUWA_SKIP)) {
-    sThreadSkipCount++;
-  }
-  tinfo->flags |= TINFO_FLAG_NUWA_SKIP;
-}
-
-/**
- * Force to freeze the current thread.
- *
- * This method does not return in Nuwa process.  It returns for the
- * recreated thread.
- */
-MFBT_API void
-NuwaFreezeCurrentThread() {
-  thread_info_t *tinfo = CUR_THREAD_INFO;
-  if (sIsNuwaProcess &&
-      (tinfo = CUR_THREAD_INFO) &&
-      (tinfo->flags & TINFO_FLAG_NUWA_SUPPORT)) {
-    if (!setjmp(tinfo->jmpEnv)) {
-      REAL(pthread_mutex_lock)(&sThreadCountLock);
-      SaveTLSInfo(tinfo);
-      sThreadFreezeCount++;
-      pthread_cond_signal(&sThreadChangeCond);
-      pthread_mutex_unlock(&sThreadCountLock);
-
-      REAL(pthread_mutex_lock)(&sThreadFreezeLock);
-    } else {
-      POST_SETJMP_RESTORE("NuwaFreezeCurrentThread");
-      RECREATE_CONTINUE();
-      RECREATE_GATE();
-    }
-  }
-}
-
-/**
- * The caller of NuwaCheckpointCurrentThread() is at the line it wishes to
- * return after the thread is recreated.
- *
- * The checkpointed thread will restart at the calling line of
- * NuwaCheckpointCurrentThread(). This macro returns true in the Nuwa process
- * and false on the recreated thread in the forked process.
- *
- * NuwaCheckpointCurrentThread() is implemented as a macro so we can place the
- * setjmp() call in the calling method without changing its stack pointer. This
- * is essential for not corrupting the stack when the calling thread continues
- * to request the main thread for forking a new process. The caller of
- * NuwaCheckpointCurrentThread() should not return before the process forking
- * finishes.
- *
- * @return true for Nuwa process, and false in the forked process.
- */
-MFBT_API jmp_buf*
-NuwaCheckpointCurrentThread1() {
-  thread_info_t *tinfo = CUR_THREAD_INFO;
-  if (sIsNuwaProcess &&
-      (tinfo = CUR_THREAD_INFO) &&
-      (tinfo->flags & TINFO_FLAG_NUWA_SUPPORT)) {
-    return &tinfo->jmpEnv;
-  }
-  abort();
-  return nullptr;
-}
-
-MFBT_API bool
-NuwaCheckpointCurrentThread2(int setjmpCond) {
-  thread_info_t *tinfo = CUR_THREAD_INFO;
-  if (setjmpCond == 0) {
-    REAL(pthread_mutex_lock)(&sThreadCountLock);
-    if (!(tinfo->flags & TINFO_FLAG_NUWA_EXPLICIT_CHECKPOINT)) {
-      tinfo->flags |= TINFO_FLAG_NUWA_EXPLICIT_CHECKPOINT;
-      SaveTLSInfo(tinfo);
-      sThreadFreezeCount++;
-    }
-    pthread_cond_signal(&sThreadChangeCond);
-    pthread_mutex_unlock(&sThreadCountLock);
-    return true;
-  }
-  POST_SETJMP_RESTORE("NuwaCheckpointCurrentThread2");
-  RECREATE_CONTINUE();
-  RECREATE_GATE();
-  return false;               // Recreated thread.
-}
-
-/**
- * Register methods to be invoked before recreating threads in the spawned
- * process.
- */
-MFBT_API void
-NuwaAddConstructor(void (*construct)(void *), void *arg) {
-  nuwa_construct_t ctr(construct, arg);
-  sConstructors.push_back(ctr);
-}
-
-/**
- * Register methods to be invoked after recreating threads in the spawned
- * process.
- */
-MFBT_API void
-NuwaAddFinalConstructor(void (*construct)(void *), void *arg) {
-  nuwa_construct_t ctr(construct, arg);
-  sFinalConstructors.push_back(ctr);
-}
-
-MFBT_API void
-NuwaAddThreadConstructor(void (*aConstruct)(void *), void *aArg) {
-  thread_info *tinfo = CUR_THREAD_INFO;
-  if (!tinfo || !aConstruct) {
-    return;
-  }
-
-  nuwa_construct_t construct(aConstruct, aArg);
-  tinfo->addThreadConstructor(&construct);
-}
-
-/**
- * @return if the current process is the nuwa process.
- */
-MFBT_API bool
-IsNuwaProcess() {
-  return sIsNuwaProcess;
-}
-
-/**
- * @return if the nuwa process is ready for spawning new processes.
- */
-MFBT_API bool
-IsNuwaReady() {
-  return sNuwaReady;
-}
-
-#if defined(DEBUG)
-MFBT_API void
-NuwaAssertNotFrozen(unsigned int aThread, const char* aThreadName) {
-  if (!sIsNuwaProcess || !sIsFreezing) {
-    return;
-  }
-
-  thread_info_t *tinfo = GetThreadInfo(static_cast<pthread_t>(aThread));
-  if (!tinfo) {
-    return;
-  }
-
-  if ((tinfo->flags & TINFO_FLAG_NUWA_SUPPORT) &&
-      !(tinfo->flags & TINFO_FLAG_NUWA_EXPLICIT_CHECKPOINT)) {
-    __android_log_print(ANDROID_LOG_FATAL, "Nuwa",
-                        "Fatal error: the Nuwa process is about to deadlock in "
-                        "accessing a frozen thread (%s, tid=%d).",
-                        aThreadName ? aThreadName : "(unnamed)",
-                        tinfo->origNativeThreadID);
-    abort();
-  }
-}
-#endif
-
-}      // extern "C"
deleted file mode 100644
--- a/mozglue/build/Nuwa.h
+++ /dev/null
@@ -1,201 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set sw=2 ts=2 autoindent cindent expandtab: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef __NUWA_H_
-#define __NUWA_H_
-
-#include <setjmp.h>
-#include <unistd.h>
-
-#include "mozilla/Types.h"
-
-/**
- * Nuwa is a goddess who created mankind according to her figure in the
- * ancient Chinese mythology.
- */
-
-// Max number of top level protocol that can be handled by Nuwa process.
-#ifndef NUWA_TOPLEVEL_MAX
-#define NUWA_TOPLEVEL_MAX 8
-#endif
-
-struct NuwaProtoFdInfo {
-    int protoId;
-    int originFd;
-    int newFds[2];
-};
-
-#define NUWA_NEWFD_PARENT 0
-#define NUWA_NEWFD_CHILD 1
-
-extern "C" {
-
-/**
- * The following 3 methods are used to synchronously spawn the Nuwa process.
- * The typical usage is:
- *
- *   The IPC thread                                The main thread
- *   1. Receives the request.
- *   2. NuwaSpawnPrepare().
- *   3. Request main thread to
- *      spawn. --------------------------------------+
- *   4. NuwaSpawnWait().                             V
- *                                                 5. NuwaSpawn() to clone all
- *                                                    the threads in the Nuwa
- *                                                    process (including main
- *                                                    & IPC threads).
- *                                                 6. NuwaSpawn() finishes and
- *            +-------------------------------------- signals NuwaSpawnWait().
- *            V
- *   7. NuwaSpawnWait() returns.
- */
-
-/**
- * Prepare for spawning a new process. The calling thread (typically the IPC
- * thread) will block further requests to spawn a new process.
- */
-MFBT_API void NuwaSpawnPrepare();
-
-/**
- * Called on the thread that receives the request. Used to wait until
- * NuwaSpawn() finishes and maintain the stack of the calling thread.
- */
-MFBT_API void NuwaSpawnWait();
-
-/**
- * Spawn a new content process, called in the Nuwa process. This has to run on
- * the main thread.
- *
- * @return The process ID of the new process.
- */
-MFBT_API pid_t NuwaSpawn();
-
-/**
- * The following methods are for marking threads created in the Nuwa process so
- * they can be frozen and then recreated in the spawned process. All threads
- * except the main thread must be marked by one of the following 4 methods;
- * otherwise, we have a thread that is created but unknown to us. The Nuwa
- * process will never become ready and this needs to be fixed.
- */
-
-/**
- * Mark the current thread as supporting Nuwa. The thread will implicitly freeze
- * by calling a blocking method such as pthread_mutex_lock() or epoll_wait().
- *
- * @param recreate The custom function that will be called in the spawned
- *                 process, after the thread is recreated. Can be nullptr if no
- *                 custom function to be called after the thread is recreated.
- *                 Note that this function is called duing thread recreation
- *                 while other threads are frozen. It must not perform any
- *                 action (e.g. acquiring a mutex) that might depend on another
- *                 thread that is still blocked.
- * @param arg The argument passed to the custom function. Can be nullptr.
- */
-MFBT_API void NuwaMarkCurrentThread(void (*recreate)(void *), void *arg);
-
-/**
- * Mark the current thread as not supporting Nuwa. The calling thread will not
- * be automatically cloned from the Nuwa process to spawned process. If this
- * thread needs to be created in the spawned process, use NuwaAddConstructor()
- * or NuwaAddFinalConstructor() to do it.
- */
-MFBT_API void NuwaSkipCurrentThread();
-
-/**
- * Force the current thread to freeze explicitly at the current point.
- */
-MFBT_API void NuwaFreezeCurrentThread();
-
-/**
- * Helper functions for the NuwaCheckpointCurrentThread() macro.
- */
-MFBT_API jmp_buf* NuwaCheckpointCurrentThread1();
-
-MFBT_API bool NuwaCheckpointCurrentThread2(int setjmpCond);
-
-/**
- * Set the point to recover after thread recreation. The calling thread is not
- * blocked. This is used for the thread that cannot freeze (i.e. the IPC
- * thread).
- */
-#define NuwaCheckpointCurrentThread() \
-  NuwaCheckpointCurrentThread2(setjmp(*NuwaCheckpointCurrentThread1()))
-
-/**
- * The following methods are called in the initialization stage of the Nuwa
- * process.
- */
-
-/**
- * Prepare for making the Nuwa process.
- */
-MFBT_API void PrepareNuwaProcess();
-
-/**
- * Make the current process a Nuwa process. Start to freeze the threads.
- */
-MFBT_API void MakeNuwaProcess();
-
-/**
- * Register a method to be invoked after a new process is spawned. The method
- * will be invoked on the main thread *before* recreating the other threads.
- * The registered method must not perform any action (e.g. acquiring a mutex)
- * that might depend on another thread that has not yet been recreated.
- *
- * @param construct The method to be invoked.
- * @param arg The argument passed to the method.
- */
-MFBT_API void NuwaAddConstructor(void (*construct)(void *), void *arg);
-
-
-/**
- * Register a method to be invoked after a new process is spawned and threads
- * are recreated. The method will be invoked on the main thread *after*
- * the other threads are recreated and fully functional.
- *
- * @param construct The method to be invoked.
- * @param arg The argument passed to the method.
- */
-MFBT_API void NuwaAddFinalConstructor(void (*construct)(void *), void *arg);
-
-
-/**
- * Register a method to be invoked after the current thread is recreated in the
- * spawned process. Note that this function is called while other threads are
- * frozen. It must not perform any action (e.g. acquiring a mutex) that might
- * depend on another thread that is still blocked.
- *
- * @param construct The method to be invoked.
- * @param arg The argument passed to the method.
- */
-MFBT_API void NuwaAddThreadConstructor(void (*construct)(void *), void *arg);
-
-/**
- * The methods to query the Nuwa-related states.
- */
-
-/**
- * @return If the current process is the Nuwa process.
- */
-MFBT_API bool IsNuwaProcess();
-
-/**
- * @return If the Nuwa process is ready for spawning new processes.
- */
-MFBT_API bool IsNuwaReady();
-
-#if defined(DEBUG)
-/**
- * Asserts that aThread is not frozen.
- */
-MFBT_API void NuwaAssertNotFrozen(unsigned int aThread,
-                                  const char* aThreadName);
-#else
-#define NuwaAssertNotFrozen(aThread, aThreadName) do {} while(0);
-#endif
-};
-
-#endif /* __NUWA_H_ */
--- a/mozglue/build/moz.build
+++ b/mozglue/build/moz.build
@@ -49,24 +49,16 @@ if not CONFIG['JS_STANDALONE']:
         SOURCES += [
             'WindowsDllBlocklist.cpp',
         ]
         DISABLE_STL_WRAPPING = True
         OS_LIBS += [
             'version',
         ]
 
-    if CONFIG['MOZ_NUWA_PROCESS']:
-        EXPORTS.ipc += [
-            'Nuwa.h',
-        ]
-        SOURCES += [
-            'Nuwa.cpp',
-        ]
-
     EXPORTS.mozilla += [
         'arm.h',
         'mips.h',
         'SSE.h',
         'WindowsDllBlocklist.h',
     ]
 
     if CONFIG['CPU_ARCH'].startswith('x86'):
--- a/netwerk/base/Predictor.cpp
+++ b/netwerk/base/Predictor.cpp
@@ -30,19 +30,16 @@
 #include "nsISpeculativeConnect.h"
 #include "nsITimer.h"
 #include "nsIURI.h"
 #include "nsNetUtil.h"
 #include "nsServiceManagerUtils.h"
 #include "nsStreamUtils.h"
 #include "nsString.h"
 #include "nsThreadUtils.h"
-#ifdef MOZ_NUWA_PROCESS
-#include "ipc/Nuwa.h"
-#endif
 #include "mozilla/Logging.h"
 
 #include "mozilla/Preferences.h"
 #include "mozilla/Telemetry.h"
 
 #include "mozilla/net/NeckoCommon.h"
 #include "mozilla/net/NeckoParent.h"
 
@@ -540,33 +537,16 @@ Predictor::GetAllow1918(bool *allow1918)
 // Predictor::nsIInterfaceRequestor
 
 NS_IMETHODIMP
 Predictor::GetInterface(const nsIID &iid, void **result)
 {
   return QueryInterface(iid, result);
 }
 
-#ifdef MOZ_NUWA_PROCESS
-namespace {
-class NuwaMarkPredictorThreadRunner : public Runnable
-{
-  NS_IMETHODIMP Run() override
-  {
-    MOZ_ASSERT(!NS_IsMainThread());
-
-    if (IsNuwaProcess()) {
-      NuwaMarkCurrentThread(nullptr, nullptr);
-    }
-    return NS_OK;
-  }
-};
-} // namespace
-#endif
-
 // Predictor::nsICacheEntryMetaDataVisitor
 
 #define SEEN_META_DATA "predictor::seen"
 #define RESOURCE_META_DATA "predictor::resource-count"
 #define META_DATA_PREFIX "predictor::"
 
 static bool
 IsURIMetadataElement(const char *key)
@@ -765,21 +745,16 @@ Predictor::MaybeCleanupOldDBFiles()
   RETURN_IF_FAILED(rv);
   rv = dbFile->AppendNative(NS_LITERAL_CSTRING("netpredictions.sqlite"));
   RETURN_IF_FAILED(rv);
 
   nsCOMPtr<nsIThread> ioThread;
   rv = NS_NewNamedThread("NetPredictClean", getter_AddRefs(ioThread));
   RETURN_IF_FAILED(rv);
 
-#ifdef MOZ_NUWA_PROCESS
-  nsCOMPtr<nsIRunnable> nuwaRunner = new NuwaMarkPredictorThreadRunner();
-  ioThread->Dispatch(nuwaRunner, NS_DISPATCH_NORMAL);
-#endif
-
   RefPtr<PredictorOldCleanupRunner> runner =
     new PredictorOldCleanupRunner(ioThread, dbFile);
   ioThread->Dispatch(runner, NS_DISPATCH_NORMAL);
 }
 
 void
 Predictor::Shutdown()
 {
--- a/netwerk/base/nsPACMan.cpp
+++ b/netwerk/base/nsPACMan.cpp
@@ -12,19 +12,16 @@
 #include "nsIPromptFactory.h"
 #include "nsIHttpChannel.h"
 #include "nsIPrefService.h"
 #include "nsIPrefBranch.h"
 #include "nsNetUtil.h"
 #include "nsIAsyncVerifyRedirectCallback.h"
 #include "nsISystemProxySettings.h"
 #include "nsContentUtils.h"
-#ifdef MOZ_NUWA_PROCESS
-#include "ipc/Nuwa.h"
-#endif
 
 //-----------------------------------------------------------------------------
 
 namespace mozilla {
 namespace net {
 
 LazyLogModule gProxyLog("proxy");
 
@@ -759,21 +756,16 @@ nsPACMan::AsyncOnChannelRedirect(nsIChan
   return NS_OK;
 }
 
 void
 nsPACMan::NamePACThread()
 {
   MOZ_ASSERT(!NS_IsMainThread(), "wrong thread");
   PR_SetCurrentThreadName("Proxy Resolution");
-#ifdef MOZ_NUWA_PROCESS
-  if (IsNuwaProcess()) {
-    NuwaMarkCurrentThread(nullptr, nullptr);
-  }
-#endif
 }
 
 nsresult
 nsPACMan::Init(nsISystemProxySettings *systemProxySettings)
 {
   mSystemProxySettings = systemProxySettings;
 
   nsresult rv = NS_NewThread(getter_AddRefs(mPACThread), nullptr);
--- a/netwerk/base/nsSocketTransportService2.cpp
+++ b/netwerk/base/nsSocketTransportService2.cpp
@@ -778,29 +778,19 @@ nsSocketTransportService::AfterProcessNe
 }
 
 void
 nsSocketTransportService::MarkTheLastElementOfPendingQueue()
 {
     mServingPendingQueue = false;
 }
 
-#ifdef MOZ_NUWA_PROCESS
-#include "ipc/Nuwa.h"
-#endif
-
 NS_IMETHODIMP
 nsSocketTransportService::Run()
 {
-#ifdef MOZ_NUWA_PROCESS
-    if (IsNuwaProcess()) {
-        NuwaMarkCurrentThread(nullptr, nullptr);
-    }
-#endif
-
     SOCKET_LOG(("STS thread init %d sockets\n", gMaxCount));
 
     psm::InitializeSSLServerCertVerificationThreads();
 
     gSocketThread = PR_GetCurrentThread();
 
     {
         MutexAutoLock lock(mLock);
--- a/netwerk/base/nsStreamTransportService.cpp
+++ b/netwerk/base/nsStreamTransportService.cpp
@@ -429,50 +429,16 @@ nsOutputStreamTransport::WriteFrom(nsIIn
 
 NS_IMETHODIMP
 nsOutputStreamTransport::IsNonBlocking(bool *result)
 {
     *result = false;
     return NS_OK;
 }
 
-#ifdef MOZ_NUWA_PROCESS
-#include "ipc/Nuwa.h"
-
-class STSThreadPoolListener final : public nsIThreadPoolListener
-{
-public:
-    NS_DECL_THREADSAFE_ISUPPORTS
-    NS_DECL_NSITHREADPOOLLISTENER
-
-    STSThreadPoolListener() {}
-
-protected:
-    ~STSThreadPoolListener() {}
-};
-
-NS_IMPL_ISUPPORTS(STSThreadPoolListener, nsIThreadPoolListener)
-
-NS_IMETHODIMP
-STSThreadPoolListener::OnThreadCreated()
-{
-    if (IsNuwaProcess()) {
-        NuwaMarkCurrentThread(nullptr, nullptr);
-    }
-    return NS_OK;
-}
-
-NS_IMETHODIMP
-STSThreadPoolListener::OnThreadShuttingDown()
-{
-    return NS_OK;
-}
-
-#endif	// MOZ_NUWA_PROCESS
-
 //-----------------------------------------------------------------------------
 // nsStreamTransportService
 //-----------------------------------------------------------------------------
 
 nsStreamTransportService::~nsStreamTransportService()
 {
     NS_ASSERTION(!mPool, "thread pool wasn't shutdown");
 }
@@ -483,21 +449,16 @@ nsStreamTransportService::Init()
     mPool = do_CreateInstance(NS_THREADPOOL_CONTRACTID);
     NS_ENSURE_STATE(mPool);
 
     // Configure the pool
     mPool->SetName(NS_LITERAL_CSTRING("StreamTrans"));
     mPool->SetThreadLimit(25);
     mPool->SetIdleThreadLimit(1);
     mPool->SetIdleThreadTimeout(PR_SecondsToInterval(30));
-#ifdef MOZ_NUWA_PROCESS
-    if (IsNuwaProcess()) {
-	mPool->SetListener(new STSThreadPoolListener());
-    }
-#endif
 
     nsCOMPtr<nsIObserverService> obsSvc =
         mozilla::services::GetObserverService();
     if (obsSvc)
         obsSvc->AddObserver(this, "xpcom-shutdown-threads", false);
     return NS_OK;
 }
 
--- a/netwerk/system/linux/nsNotifyAddrListener_Linux.cpp
+++ b/netwerk/system/linux/nsNotifyAddrListener_Linux.cpp
@@ -22,20 +22,16 @@
 
 #include "mozilla/Services.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/FileUtils.h"
 #include "mozilla/SHA1.h"
 #include "mozilla/Base64.h"
 #include "mozilla/Telemetry.h"
 
-#ifdef MOZ_NUWA_PROCESS
-#include "ipc/Nuwa.h"
-#endif
-
 #ifdef MOZ_WIDGET_GONK
 #include <cutils/properties.h>
 #endif
 
 /* a shorter name that better explains what it does */
 #define EINTR_RETRY(x) MOZ_TEMP_FAILURE_RETRY(x)
 
 // period during which to absorb subsequent network change events, in
@@ -446,29 +442,16 @@ nsNotifyAddrListener::Observe(nsISupport
 {
     if (!strcmp("xpcom-shutdown-threads", topic)) {
         Shutdown();
     }
 
     return NS_OK;
 }
 
-#ifdef MOZ_NUWA_PROCESS
-class NuwaMarkLinkMonitorThreadRunner : public Runnable
-{
-    NS_IMETHODIMP Run() override
-    {
-        if (IsNuwaProcess()) {
-            NuwaMarkCurrentThread(nullptr, nullptr);
-        }
-        return NS_OK;
-    }
-};
-#endif
-
 nsresult
 nsNotifyAddrListener::Init(void)
 {
     nsCOMPtr<nsIObserverService> observerService =
         mozilla::services::GetObserverService();
     if (!observerService)
         return NS_ERROR_FAILURE;
 
@@ -481,21 +464,16 @@ nsNotifyAddrListener::Init(void)
 
     if (-1 == pipe(mShutdownPipe)) {
         return NS_ERROR_FAILURE;
     }
 
     rv = NS_NewNamedThread("Link Monitor", getter_AddRefs(mThread), this);
     NS_ENSURE_SUCCESS(rv, rv);
 
-#ifdef MOZ_NUWA_PROCESS
-    nsCOMPtr<nsIRunnable> runner = new NuwaMarkLinkMonitorThreadRunner();
-    mThread->Dispatch(runner, NS_DISPATCH_NORMAL);
-#endif
-
     return NS_OK;
 }
 
 nsresult
 nsNotifyAddrListener::Shutdown(void)
 {
     // remove xpcom shutdown observer
     nsCOMPtr<nsIObserverService> observerService =
--- a/old-configure.in
+++ b/old-configure.in
@@ -4986,25 +4986,16 @@ if test -f "${srcdir}/${MOZ_BUILD_APP}/c
   tmpscript=`$PYTHON -c 'import os, tempfile; print tempfile.mktemp(prefix="subscript.").replace(os.sep, "/")'` || exit 1
   m4 "${srcdir}/build/autoconf/subconfigure.m4" \
      "${srcdir}/build/autoconf/altoptions.m4" \
      "${srcdir}/${MOZ_BUILD_APP}/configure.in" > $tmpscript
   . $tmpscript
   rm -f $tmpscript
 fi
 
-dnl We need to wrap dlopen and related functions on Android because we use
-dnl our own linker.
-dnl This configuration will only work on Android SDK 11 and above: Bug 1220184.
-if test "$OS_TARGET" = Android; then
-    if test "$MOZ_WIDGET_TOOLKIT" = gonk -a -n "$MOZ_NUWA_PROCESS"; then
-        MOZ_GLUE_WRAP_LDFLAGS="${MOZ_GLUE_WRAP_LDFLAGS} -Wl,--wrap=pthread_create,--wrap=epoll_wait,--wrap=poll,--wrap=pthread_cond_timedwait,--wrap=pthread_cond_wait,--wrap=epoll_create,--wrap=epoll_ctl,--wrap=close,--wrap=pthread_key_create,--wrap=pthread_key_delete,--wrap=socketpair,--wrap=pthread_self,--wrap=pthread_mutex_lock,--wrap=pthread_mutex_trylock,--wrap=pthread_join,--wrap=pipe,--wrap=pipe2"
-    fi
-fi
-
 AC_SUBST_LIST(MOZ_GLUE_WRAP_LDFLAGS)
 export MOZ_GLUE_WRAP_LDFLAGS
 
 dnl ========================================================
 dnl = Enable using the clang plugin to build
 dnl ========================================================
 
 MOZ_CONFIG_CLANG_PLUGIN
@@ -6301,30 +6292,16 @@ AC_SUBST(MOZ_SYSTEM_BZ2)
 
 AC_SUBST_LIST(MOZ_JPEG_CFLAGS)
 AC_SUBST_LIST(MOZ_JPEG_LIBS)
 AC_SUBST_LIST(MOZ_BZ2_CFLAGS)
 AC_SUBST_LIST(MOZ_BZ2_LIBS)
 AC_SUBST_LIST(MOZ_PNG_CFLAGS)
 AC_SUBST_LIST(MOZ_PNG_LIBS)
 
-if test "$MOZ_WIDGET_TOOLKIT" = gonk -a -n "$MOZ_NUWA_PROCESS"; then
-    export MOZ_NUWA_PROCESS
-    AC_DEFINE(MOZ_NUWA_PROCESS)
-fi
-AC_SUBST(MOZ_NUWA_PROCESS)
-if test "$MOZ_WIDGET_TOOLKIT" = gonk -a -n "$MOZ_B2G_LOADER"; then
-    if test -z "$MOZ_NUWA_PROCESS"; then
-       AC_MSG_ERROR([B2G loader works with Nuwa]);
-    fi
-    export MOZ_B2G_LOADER
-    AC_DEFINE(MOZ_B2G_LOADER)
-fi
-AC_SUBST(MOZ_B2G_LOADER)
-
 AC_SUBST(MOZ_SYSTEM_NSPR)
 
 AC_SUBST(MOZ_SYSTEM_NSS)
 AC_SUBST(NSS_DISABLE_DBM)
 
 HOST_CMFLAGS=-fobjc-exceptions
 HOST_CMMFLAGS=-fobjc-exceptions
 OS_COMPILE_CMFLAGS=-fobjc-exceptions
--- a/security/sandbox/linux/Sandbox.cpp
+++ b/security/sandbox/linux/Sandbox.cpp
@@ -501,29 +501,18 @@ SetCurrentProcessSandbox(UniquePtr<sandb
       SANDBOX_LOG_ERROR("no tsync support; using signal broadcast");
     }
     BroadcastSetThreadSandbox(&fprog);
   }
   MOZ_RELEASE_ASSERT(!gChrootHelper, "forgot to chroot");
 }
 
 void
-SandboxEarlyInit(GeckoProcessType aType, bool aIsNuwa)
+SandboxEarlyInit(GeckoProcessType aType)
 {
-  // Bug 1168555: Nuwa isn't reliably single-threaded at this point;
-  // it starts an IPC I/O thread and then shuts it down before calling
-  // the plugin-container entry point, but that thread may not have
-  // finished exiting.  If/when any type of sandboxing is used for the
-  // Nuwa process (e.g., unsharing the network namespace there instead
-  // of for each content process, to save memory), this will need to be
-  // changed by moving the SandboxEarlyInit call to an earlier point.
-  if (aIsNuwa) {
-    return;
-  }
-
   const SandboxInfo info = SandboxInfo::Get();
   if (info.Test(SandboxInfo::kUnexpectedThreads)) {
     return;
   }
   MOZ_RELEASE_ASSERT(IsSingleThreaded());
 
   // Which kinds of resource isolation (of those that need to be set
   // up at this point) can be used by this process?
--- a/security/sandbox/linux/Sandbox.h
+++ b/security/sandbox/linux/Sandbox.h
@@ -20,17 +20,17 @@
 #else
 // Defined in plugin-container and referenced by libraries it loads.
 #define MOZ_SANDBOX_EXPORT MOZ_EXPORT __attribute__((weak))
 #endif
 
 namespace mozilla {
 
 // This must be called early, while the process is still single-threaded.
-MOZ_SANDBOX_EXPORT void SandboxEarlyInit(GeckoProcessType aType, bool aIsNuwa);
+MOZ_SANDBOX_EXPORT void SandboxEarlyInit(GeckoProcessType aType);
 
 #ifdef MOZ_CONTENT_SANDBOX
 // Call only if SandboxInfo::CanSandboxContent() returns true.
 // (No-op if MOZ_DISABLE_CONTENT_SANDBOX is set.)
 // aBrokerFd is the filesystem broker client file descriptor,
 // or -1 to allow direct filesystem access.
 MOZ_SANDBOX_EXPORT bool SetContentProcessSandbox(int aBrokerFd);
 #endif
--- a/toolkit/components/extensions/Extension.jsm
+++ b/toolkit/components/extensions/Extension.jsm
@@ -1409,20 +1409,16 @@ Extension.prototype = extend(Object.crea
       localeData: this.localeData.serialize(),
       permissions: this.permissions,
     };
   },
 
   broadcast(msg, data) {
     return new Promise(resolve => {
       let count = Services.ppmm.childCount;
-      if (AppConstants.MOZ_NUWA_PROCESS) {
-        // The nuwa process is frozen, so don't expect it to answer.
-        count--;
-      }
       Services.ppmm.addMessageListener(msg + "Complete", function listener() {
         count--;
         if (count == 0) {
           Services.ppmm.removeMessageListener(msg + "Complete", listener);
           resolve();
         }
       });
       Services.ppmm.broadcastAsyncMessage(msg, data);
--- a/toolkit/modules/AppConstants.jsm
+++ b/toolkit/modules/AppConstants.jsm
@@ -314,22 +314,15 @@ this.AppConstants = Object.freeze({
   // URL to the hg revision this was built from (e.g.
   // "https://hg.mozilla.org/mozilla-central/rev/6256ec9113c1")
   // On unofficial builds, this is an empty string.
 #ifndef MOZ_SOURCE_URL
 #define MOZ_SOURCE_URL
 #endif
   SOURCE_REVISION_URL: "@MOZ_SOURCE_URL@",
 
-  MOZ_NUWA_PROCESS:
-#ifdef MOZ_NUWA_PROCESS
-    true,
-#else
-    false,
-#endif
-
   HAVE_USR_LIB64_DIR:
 #ifdef HAVE_USR_LIB64_DIR
     true,
 #else
     false,
 #endif
 });
--- a/toolkit/xre/moz.build
+++ b/toolkit/xre/moz.build
@@ -162,19 +162,16 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'coco
         '/widget/cocoa',
     ]
 
 if CONFIG['MOZ_ENABLE_XREMOTE']:
     LOCAL_INCLUDES += [
         '/widget/xremoteclient',
     ]
 
-if CONFIG['MOZ_B2G_LOADER']:
-    DEFINES['OMNIJAR_NAME'] = CONFIG['OMNIJAR_NAME']
-
 CXXFLAGS += CONFIG['TK_CFLAGS']
 CXXFLAGS += CONFIG['MOZ_DBUS_CFLAGS']
 CXXFLAGS += CONFIG['MOZ_DBUS_GLIB_CFLAGS']
 
 if 'gtk' in CONFIG['MOZ_WIDGET_TOOLKIT']:
     CXXFLAGS += CONFIG['MOZ_PANGO_CFLAGS']
 
 DEFINES['TOPOBJDIR'] = TOPOBJDIR
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -190,20 +190,16 @@
 #define NS_CRASHREPORTER_CONTRACTID "@mozilla.org/toolkit/crash-reporter;1"
 #include "nsIPrefService.h"
 #include "nsIMemoryInfoDumper.h"
 #endif
 
 #include "base/command_line.h"
 #include "GTestRunner.h"
 
-#ifdef MOZ_B2G_LOADER
-#include "ProcessUtils.h"
-#endif
-
 #ifdef MOZ_WIDGET_ANDROID
 #include "GeneratedJNIWrappers.h"
 #endif
 
 #if defined(MOZ_SANDBOX)
 #if defined(XP_LINUX) && !defined(ANDROID)
 #include "mozilla/SandboxInfo.h"
 #elif defined(XP_WIN)
@@ -3949,20 +3945,16 @@ void AddSandboxAnnotations()
  * the calling of appStartup->Run().
  */
 nsresult
 XREMain::XRE_mainRun()
 {
   nsresult rv = NS_OK;
   NS_ASSERTION(mScopedXPCOM, "Scoped xpcom not initialized.");
 
-#ifdef MOZ_B2G_LOADER
-  mozilla::ipc::ProcLoaderClientGeckoInit();
-#endif
-
 #ifdef NS_FUNCTION_TIMER
   // initialize some common services, so we don't pay the cost for these at odd times later on;
   // SetWindowCreator -> ChromeRegistry -> IOService -> SocketTransportService -> (nspr wspm init), Prefs
   {
     nsCOMPtr<nsISupports> comp;
 
     comp = do_GetService("@mozilla.org/preferences-service;1");
 
--- a/toolkit/xre/nsEmbedFunctions.cpp
+++ b/toolkit/xre/nsEmbedFunctions.cpp
@@ -85,21 +85,16 @@
 
 #ifdef MOZ_IPDL_TESTS
 #include "mozilla/_ipdltest/IPDLUnitTests.h"
 #include "mozilla/_ipdltest/IPDLUnitTestProcessChild.h"
 
 using mozilla::_ipdltest::IPDLUnitTestProcessChild;
 #endif  // ifdef MOZ_IPDL_TESTS
 
-#ifdef MOZ_B2G_LOADER
-#include "nsLocalFile.h"
-#include "nsXREAppData.h"
-#endif
-
 #ifdef MOZ_JPROF
 #include "jprof.h"
 #endif
 
 using namespace mozilla;
 
 using mozilla::ipc::BrowserProcessSubThread;
 using mozilla::ipc::GeckoChildProcessHost;
@@ -944,45 +939,8 @@ XRE_InstallX11ErrorHandler()
 {
 #if (MOZ_WIDGET_GTK == 3)
   InstallGdkErrorHandler();
 #else
   InstallX11ErrorHandler();
 #endif
 }
 #endif
-
-#ifdef MOZ_B2G_LOADER
-extern const nsXREAppData* gAppData;
-
-/**
- * Preload static data of Gecko for B2G loader.
- *
- * This function is supposed to be called before XPCOM is initialized.
- * For now, this function preloads
- *  - XPT interface Information
- */
-void
-XRE_ProcLoaderPreload(const char* aProgramDir, const nsXREAppData* aAppData)
-{
-    void PreloadXPT(nsIFile *);
-
-    nsresult rv;
-    nsCOMPtr<nsIFile> omnijarFile;
-    rv = NS_NewNativeLocalFile(nsCString(aProgramDir),
-			       true,
-			       getter_AddRefs(omnijarFile));
-    MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
-
-    rv = omnijarFile->AppendNative(NS_LITERAL_CSTRING(NS_STRINGIFY(OMNIJAR_NAME)));
-    MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
-
-    /*
-     * gAppData is required by nsXULAppInfo.  The manifest parser
-     * evaluate flags with the information from nsXULAppInfo.
-     */
-    gAppData = aAppData;
-
-    PreloadXPT(omnijarFile);
-
-    gAppData = nullptr;
-}
-#endif /* MOZ_B2G_LOADER */
--- a/tools/profiler/core/ThreadInfo.h
+++ b/tools/profiler/core/ThreadInfo.h
@@ -25,20 +25,16 @@ class ThreadInfo {
   ThreadProfile* Profile() const { return mProfile; }
 
   PlatformData* GetPlatformData() const { return mPlatformData; }
   void* StackTop() const { return mStackTop; }
 
   virtual void SetPendingDelete();
   bool IsPendingDelete() const { return mPendingDelete; }
 
-#ifdef MOZ_NUWA_PROCESS
-  void SetThreadId(int aThreadId) { mThreadId = aThreadId; }
-#endif
-
 #ifndef SPS_STANDALONE
   /**
    * May be null for the main thread if the profiler was started during startup
    */
   nsIThread* GetThread() const { return mThread.get(); }
 #endif
  private:
   char* mName;
--- a/tools/profiler/core/platform-linux.cc
+++ b/tools/profiler/core/platform-linux.cc
@@ -87,20 +87,16 @@
 #endif
 
 // Memory profile
 #include "nsMemoryReporterManager.h"
 
 #include <string.h>
 #include <list>
 
-#ifdef MOZ_NUWA_PROCESS
-#include "ipc/Nuwa.h"
-#endif
-
 #define SIGNAL_SAVE_PROFILE SIGUSR2
 
 using namespace mozilla;
 
 #if defined(USE_LUL_STACKWALK)
 // A singleton instance of the library.  It is initialised at first
 // use.  Currently only the main thread can call Sampler::Start, so
 // there is no need for a mechanism to ensure that it is only
@@ -295,28 +291,16 @@ Sampler::FreePlatformData(PlatformData* 
 {
   delete aData;
 }
 
 static void* SignalSender(void* arg) {
   // Taken from platform_thread_posix.cc
   prctl(PR_SET_NAME, "SamplerThread", 0, 0, 0);
 
-#ifdef MOZ_NUWA_PROCESS
-  // If the Nuwa process is enabled, we need to mark and freeze the sampler
-  // thread in the Nuwa process and have this thread recreated in the spawned
-  // child.
-  if(IsNuwaProcess()) {
-    NuwaMarkCurrentThread(nullptr, nullptr);
-    // Freeze the thread here so the spawned child will get the correct tgid
-    // from the getpid() call below.
-    NuwaFreezeCurrentThread();
-  }
-#endif
-
   int vm_tgid_ = getpid();
   DebugOnly<int> my_tid = gettid();
 
   unsigned int nSignalsSent = 0;
 
   TimeDuration lastSleepOverhead = 0;
   TimeStamp sampleStart = TimeStamp::Now();
   while (SamplerRegistry::sampler->IsActive()) {
@@ -495,28 +479,16 @@ void Sampler::Stop() {
   // Restore old signal handler
   if (signal_handler_installed_) {
     sigaction(SIGNAL_SAVE_PROFILE, &old_sigsave_signal_handler_, 0);
     sigaction(SIGPROF, &old_sigprof_signal_handler_, 0);
     signal_handler_installed_ = false;
   }
 }
 
-#ifdef MOZ_NUWA_PROCESS
-static void
-UpdateThreadId(void* aThreadInfo) {
-  ThreadInfo* info = static_cast<ThreadInfo*>(aThreadInfo);
-  // Note that this function is called during thread recreation. Only the thread
-  // calling this method is running. We can't try to acquire
-  // Sampler::sRegisteredThreadsMutex because it could be held by another
-  // thread.
-  info->SetThreadId(gettid());
-}
-#endif
-
 bool Sampler::RegisterCurrentThread(const char* aName,
                                     PseudoStack* aPseudoStack,
                                     bool aIsMainThread, void* stackTop)
 {
   if (!Sampler::sRegisteredThreadsMutex)
     return false;
 
   ::MutexAutoLock lock(*Sampler::sRegisteredThreadsMutex);
@@ -538,30 +510,16 @@ bool Sampler::RegisterCurrentThread(cons
     aIsMainThread, aPseudoStack, stackTop);
 
   if (sActiveSampler) {
     sActiveSampler->RegisterThread(info);
   }
 
   sRegisteredThreads->push_back(info);
 
-#ifdef MOZ_NUWA_PROCESS
-  if (IsNuwaProcess()) {
-    if (info->IsMainThread()) {
-      // Main thread isn't a marked thread. Register UpdateThreadId() to
-      // NuwaAddConstructor(), which runs before all other threads are
-      // recreated.
-      NuwaAddConstructor(UpdateThreadId, info);
-    } else {
-      // Register UpdateThreadInfo() to be run when the thread is recreated.
-      NuwaAddThreadConstructor(UpdateThreadId, info);
-    }
-  }
-#endif
-
   return true;
 }
 
 void Sampler::UnregisterCurrentThread()
 {
   if (!Sampler::sRegisteredThreadsMutex)
     return;
 
--- a/widget/gonk/GonkMemoryPressureMonitoring.cpp
+++ b/widget/gonk/GonkMemoryPressureMonitoring.cpp
@@ -21,20 +21,16 @@
 #include "nsIObserverService.h"
 #include "nsMemoryPressure.h"
 #include "nsPrintfCString.h"
 #include "nsThreadUtils.h"
 
 #define LOG(args...)  \
   __android_log_print(ANDROID_LOG_INFO, "GonkMemoryPressure" , ## args)
 
-#ifdef MOZ_NUWA_PROCESS
-#include "ipc/Nuwa.h"
-#endif
-
 using namespace mozilla;
 
 namespace {
 
 /**
  * MemoryPressureWatcher watches sysfs from its own thread to notice when the
  * system is under memory pressure.  When we observe memory pressure, we use
  * MemoryPressureRunnable to notify observers that they should release memory.
@@ -118,22 +114,16 @@ public:
 
     return NS_OK;
   }
 
   NS_IMETHOD Run()
   {
     MOZ_ASSERT(!NS_IsMainThread());
 
-#ifdef MOZ_NUWA_PROCESS
-    if (IsNuwaProcess()) {
-      NuwaMarkCurrentThread(nullptr, nullptr);
-    }
-#endif
-
     int triggerResetTimeout = -1;
     bool memoryPressure;
     nsresult rv = CheckForMemoryPressure(&memoryPressure);
     NS_ENSURE_SUCCESS(rv, rv);
 
     while (true) {
       // Wait for a notification on mTriggerFd or for data to be written to
       // mShutdownPipeWrite.  (poll(mTriggerFd, POLLPRI) blocks until we're
--- a/widget/gonk/nsAppShell.cpp
+++ b/widget/gonk/nsAppShell.cpp
@@ -58,20 +58,16 @@
 #include "OrientationObserver.h"
 #include "GonkMemoryPressureMonitoring.h"
 
 #include "android/log.h"
 #include "libui/EventHub.h"
 #include "libui/InputReader.h"
 #include "libui/InputDispatcher.h"
 
-#ifdef MOZ_NUWA_PROCESS
-#include "ipc/Nuwa.h"
-#endif
-
 #include "mozilla/Preferences.h"
 #include "GeckoProfiler.h"
 
 // Defines kKeyMapping and GetKeyNameIndex()
 #include "GonkKeyMapping.h"
 #include "mozilla/layers/CompositorBridgeParent.h"
 #include "GeckoTouchDispatcher.h"
 
@@ -904,21 +900,16 @@ nsAppShell::Init()
     }
 
     nsCOMPtr<nsIObserverService> obsServ = GetObserverService();
     if (obsServ) {
         obsServ->AddObserver(this, "browser-ui-startup-complete", false);
         obsServ->AddObserver(this, "network-connection-state-changed", false);
     }
 
-#ifdef MOZ_NUWA_PROCESS
-    // Make sure main thread was woken up after Nuwa fork.
-    NuwaAddConstructor((void (*)(void *))&NotifyEvent, nullptr);
-#endif
-
     // Delay initializing input devices until the screen has been
     // initialized (and we know the resolution).
     return rv;
 }
 
 void
 nsAppShell::CheckPowerKey()
 {
--- a/xpcom/base/nsCycleCollector.cpp
+++ b/xpcom/base/nsCycleCollector.cpp
@@ -1241,20 +1241,16 @@ enum ccPhase
 
 enum ccType
 {
   SliceCC,     /* If a CC is in progress, continue it. Otherwise, start a new one. */
   ManualCC,    /* Explicitly triggered. */
   ShutdownCC   /* Shutdown CC, used for finding leaks. */
 };
 
-#ifdef MOZ_NUWA_PROCESS
-#include "ipc/Nuwa.h"
-#endif
-
 ////////////////////////////////////////////////////////////////////////
 // Top level structure for the cycle collector.
 ////////////////////////////////////////////////////////////////////////
 
 using js::SliceBudget;
 
 class JSPurpleBuffer;
 
--- a/xpcom/base/nsMemoryReporterManager.cpp
+++ b/xpcom/base/nsMemoryReporterManager.cpp
@@ -1921,22 +1921,16 @@ nsMemoryReporterManager::HandleChildRepo
                              aChildReport.desc(),
                              s->mHandleReportData);
 }
 
 /* static */ bool
 nsMemoryReporterManager::StartChildReport(mozilla::dom::ContentParent* aChild,
                                           const PendingProcessesState* aState)
 {
-#ifdef MOZ_NUWA_PROCESS
-  if (aChild->IsNuwaProcess()) {
-    return false;
-  }
-#endif
-
   if (!aChild->IsAlive()) {
     MEMORY_REPORTING_LOG("StartChildReports (gen=%u): child exited before"
                          " its report was started\n",
                          aState->mGeneration);
     return false;
   }
 
   mozilla::dom::MaybeFileDesc dmdFileDesc = void_t();
@@ -1979,17 +1973,17 @@ nsMemoryReporterManager::EndProcessRepor
 
   // Start pending children up to the concurrency limit.
   while (s->mNumProcessesRunning < s->mConcurrencyLimit &&
          !s->mChildrenPending.IsEmpty()) {
     // Pop last element from s->mChildrenPending
     RefPtr<ContentParent> nextChild;
     nextChild.swap(s->mChildrenPending.LastElement());
     s->mChildrenPending.TruncateLength(s->mChildrenPending.Length() - 1);
-    // Start report (if the child is still alive and not Nuwa).
+    // Start report (if the child is still alive).
     if (StartChildReport(nextChild, s)) {
       ++s->mNumProcessesRunning;
       MEMORY_REPORTING_LOG("HandleChildReports (aGen=%u): started child report"
                            " (%u running, %u pending)\n",
                            aGeneration, s->mNumProcessesRunning,
                            static_cast<unsigned>(s->mChildrenPending.Length()));
     }
   }
--- a/xpcom/build/nsXULAppAPI.h
+++ b/xpcom/build/nsXULAppAPI.h
@@ -503,28 +503,16 @@ XRE_API(void,
         XRE_StartupTimelineRecord, (int aEvent, mozilla::TimeStamp aWhen))
 
 XRE_API(void,
         XRE_InitOmnijar, (nsIFile* aGreOmni,
                           nsIFile* aAppOmni))
 XRE_API(void,
         XRE_StopLateWriteChecks, (void))
 
-#ifdef MOZ_B2G_LOADER
-XRE_API(int,
-        XRE_ProcLoaderServiceRun, (pid_t, int, int argc, const char* argv[],
-                                   mozilla::Vector<int>& aReservedFds));
-XRE_API(void,
-        XRE_ProcLoaderClientInit, (pid_t, int,
-                                   mozilla::Vector<int>& aReservedFds));
-XRE_API(void,
-        XRE_ProcLoaderPreload, (const char* aProgramDir,
-                                const nsXREAppData* aAppData));
-#endif // MOZ_B2G_LOADER
-
 XRE_API(void,
         XRE_EnableSameExecutableForContentProc, ())
 
 XRE_API(int,
         XRE_XPCShellMain, (int argc, char** argv, char** envp,
                            const XREShellData* aShellData))
 
 #if MOZ_WIDGET_GTK == 2
--- a/xpcom/components/ManifestParser.cpp
+++ b/xpcom/components/ManifestParser.cpp
@@ -32,28 +32,16 @@
 #include "nsTextFormatter.h"
 #include "nsVersionComparator.h"
 #include "nsXPCOMCIDInternal.h"
 
 #include "nsIConsoleService.h"
 #include "nsIScriptError.h"
 #include "nsIXULAppInfo.h"
 #include "nsIXULRuntime.h"
-#ifdef MOZ_B2G_LOADER
-#include "mozilla/XPTInterfaceInfoManager.h"
-#endif
-
-#ifdef MOZ_B2G_LOADER
-#define XPTONLY_MANIFEST &nsComponentManagerImpl::XPTOnlyManifestManifest
-#define XPTONLY_XPT &nsComponentManagerImpl::XPTOnlyManifestXPT
-#else
-#define XPTONLY_MANIFEST nullptr
-#define XPTONLY_XPT nullptr
-#endif
-
 
 using namespace mozilla;
 
 struct ManifestDirective
 {
   const char* directive;
   int argc;
 
@@ -73,39 +61,32 @@ struct ManifestDirective
   // Function to handle this directive. This isn't a union because C++ still
   // hasn't learned how to initialize unions in a sane way.
   void (nsComponentManagerImpl::*mgrfunc)(
     nsComponentManagerImpl::ManifestProcessingContext& aCx,
     int aLineNo, char* const* aArgv);
   void (nsChromeRegistry::*regfunc)(
     nsChromeRegistry::ManifestProcessingContext& aCx,
     int aLineNo, char* const* aArgv, int aFlags);
-#ifdef MOZ_B2G_LOADER
-  // The function to handle the directive for XPT Only parsing.
-  void (*xptonlyfunc)(
-    nsComponentManagerImpl::XPTOnlyManifestProcessingContext& aCx,
-    int aLineNo, char* const* aArgv);
-#else
   void* xptonlyfunc;
-#endif
 
   bool isContract;
 };
 static const ManifestDirective kParsingTable[] = {
   {
     "manifest",         1, false, false, true, true, false,
-    &nsComponentManagerImpl::ManifestManifest, nullptr, XPTONLY_MANIFEST
+    &nsComponentManagerImpl::ManifestManifest, nullptr, nullptr
   },
   {
     "binary-component", 1, true, true, false, false, false,
     &nsComponentManagerImpl::ManifestBinaryComponent, nullptr, nullptr
   },
   {
     "interfaces",       1, false, true, false, false, false,
-    &nsComponentManagerImpl::ManifestXPT, nullptr, XPTONLY_XPT
+    &nsComponentManagerImpl::ManifestXPT, nullptr, nullptr
   },
   {
     "component",        2, false, true, false, false, false,
     &nsComponentManagerImpl::ManifestComponent, nullptr, nullptr
   },
   {
     "contract",         2, false, true, false, false, false,
     &nsComponentManagerImpl::ManifestContract, nullptr, nullptr, true
@@ -479,19 +460,16 @@ struct CachedDirective
  */
 void
 ParseManifest(NSLocationType aType, FileLocation& aFile, char* aBuf,
               bool aChromeOnly, bool aXPTOnly)
 {
   nsComponentManagerImpl::ManifestProcessingContext mgrcx(aType, aFile,
                                                           aChromeOnly);
   nsChromeRegistry::ManifestProcessingContext chromecx(aType, aFile);
-#ifdef MOZ_B2G_LOADER
-  nsComponentManagerImpl::XPTOnlyManifestProcessingContext xptonlycx(aFile);
-#endif
   nsresult rv;
 
   NS_NAMED_LITERAL_STRING(kPlatform, "platform");
   NS_NAMED_LITERAL_STRING(kContentAccessible, "contentaccessible");
   NS_NAMED_LITERAL_STRING(kRemoteEnabled, "remoteenabled");
   NS_NAMED_LITERAL_STRING(kRemoteRequired, "remoterequired");
   NS_NAMED_LITERAL_STRING(kApplication, "application");
   NS_NAMED_LITERAL_STRING(kAppVersion, "appversion");
@@ -770,21 +748,16 @@ ParseManifest(NSLocationType aType, File
 #ifdef MOZ_WIDGET_ANDROID
         stTablet == eBad ||
 #endif
         stABI == eBad ||
         stProcess == eBad) {
       continue;
     }
 
-#ifdef MOZ_B2G_LOADER
-    if (aXPTOnly) {
-      directive->xptonlyfunc(xptonlycx, line, argv);
-    } else
-#endif /* MOZ_B2G_LOADER */
     if (directive->regfunc) {
       if (GeckoProcessType_Default != XRE_GetProcessType()) {
         continue;
       }
 
       if (!nsChromeRegistry::gChromeRegistry) {
         nsCOMPtr<nsIChromeRegistry> cr =
           mozilla::services::GetChromeRegistryService();
--- a/xpcom/components/nsComponentManager.cpp
+++ b/xpcom/components/nsComponentManager.cpp
@@ -102,46 +102,16 @@ const char fileSizeValueName[] = "FileSi
 const char lastModValueName[] = "LastModTimeStamp";
 const char nativeComponentType[] = "application/x-mozilla-native";
 const char staticComponentType[] = "application/x-mozilla-static";
 
 NS_DEFINE_CID(kCategoryManagerCID, NS_CATEGORYMANAGER_CID);
 
 #define UID_STRING_LENGTH 39
 
-#ifdef MOZ_B2G_LOADER
-typedef nsDataHashtable<nsCStringHashKey, bool> XPTIInfosBookType;
-static XPTIInfosBookType* sXPTIInfosBook = nullptr;
-
-static XPTIInfosBookType*
-GetXPTIInfosBook()
-{
-  if (!sXPTIInfosBook) {
-    sXPTIInfosBook = new XPTIInfosBookType;
-  }
-  return sXPTIInfosBook;
-}
-
-static bool
-IsRegisteredXPTIInfo(FileLocation& aFile)
-{
-  nsAutoCString uri;
-  aFile.GetURIString(uri);
-  return GetXPTIInfosBook()->Get(uri);
-}
-
-static void
-MarkRegisteredXPTIInfo(FileLocation& aFile)
-{
-  nsAutoCString uri;
-  aFile.GetURIString(uri);
-  GetXPTIInfosBook()->Put(uri, true);
-}
-#endif /* MOZ_B2G_LOADER */
-
 nsresult
 nsGetServiceFromCategory::operator()(const nsIID& aIID,
                                      void** aInstancePtr) const
 {
   nsresult rv;
   nsXPIDLCString value;
   nsCOMPtr<nsICategoryManager> catman;
   nsComponentManagerImpl* compMgr = nsComponentManagerImpl::gComponentManager;
@@ -677,38 +647,29 @@ nsComponentManagerImpl::ManifestBinaryCo
   }
 
   RegisterModule(m, &f);
 }
 
 static void
 DoRegisterXPT(FileLocation& aFile)
 {
-#ifdef MOZ_B2G_LOADER
-  if (IsRegisteredXPTIInfo(aFile)) {
-    return;
-  }
-#endif
-
   uint32_t len;
   FileLocation::Data data;
   UniquePtr<char[]> buf;
   nsresult rv = aFile.GetData(data);
   if (NS_SUCCEEDED(rv)) {
     rv = data.GetSize(&len);
   }
   if (NS_SUCCEEDED(rv)) {
     buf = MakeUnique<char[]>(len);
     rv = data.Copy(buf.get(), len);
   }
   if (NS_SUCCEEDED(rv)) {
     XPTInterfaceInfoManager::GetSingleton()->RegisterBuffer(buf.get(), len);
-#ifdef MOZ_B2G_LOADER
-    MarkRegisteredXPTIInfo(aFile);
-#endif
   } else {
     nsCString uri;
     aFile.GetURIString(uri);
     LogMessage("Could not read '%s'.", uri.get());
   }
 }
 
 void
@@ -906,20 +867,16 @@ nsresult nsComponentManagerImpl::Shutdow
   mContractIDs.Clear();
   mFactories.Clear(); // XXX release the objects, don't just clear
   mLoaderMap.Clear();
   mKnownModules.Clear();
   mKnownStaticModules.Clear();
 
   delete sStaticModules;
   delete sModuleLocations;
-#ifdef MOZ_B2G_LOADER
-  delete sXPTIInfosBook;
-  sXPTIInfosBook = nullptr;
-#endif
 
   // Unload libraries
   mNativeModuleLoader.UnloadLibraries();
 
   // delete arena for strings and small objects
   PL_FinishArenaPool(&mArena);
 
   mStatus = SHUTDOWN_COMPLETE;
@@ -2067,62 +2024,16 @@ nsComponentManagerImpl::GetManifestLocat
       locations->AppendElement(uri, false);
     }
   }
 
   locations.forget(aLocations);
   return NS_OK;
 }
 
-#ifdef MOZ_B2G_LOADER
-
-/* static */
-void
-nsComponentManagerImpl::XPTOnlyManifestManifest(
-    XPTOnlyManifestProcessingContext&  aCx, int aLineNo, char* const* aArgv)
-{
-  char* file = aArgv[0];
-  FileLocation f(aCx.mFile, file);
-
-  DoRegisterManifest(NS_APP_LOCATION, f, false, true);
-}
-
-/* static */
-void
-nsComponentManagerImpl::XPTOnlyManifestXPT(
-    XPTOnlyManifestProcessingContext& aCx, int aLineNo, char* const* aArgv)
-{
-  FileLocation f(aCx.mFile, aArgv[0]);
-  DoRegisterXPT(f);
-}
-
-/**
- * To load XPT Interface Information before the component manager is ready.
- *
- * With this function, B2G loader could XPT interface info. as earier
- * as possible to gain benefit of shared memory model of the kernel.
- */
-/* static */ void
-nsComponentManagerImpl::PreloadXPT(nsIFile* aFile)
-{
-  MOZ_ASSERT(!nsComponentManagerImpl::gComponentManager);
-  FileLocation location(aFile, "chrome.manifest");
-
-  DoRegisterManifest(NS_APP_LOCATION, location,
-                     false, true /* aXPTOnly */);
-}
-
-void
-PreloadXPT(nsIFile* aOmnijarFile)
-{
-  nsComponentManagerImpl::PreloadXPT(aOmnijarFile);
-}
-
-#endif /* MOZ_B2G_LOADER */
-
 EXPORT_XPCOM_API(nsresult)
 XRE_AddManifestLocation(NSLocationType aType, nsIFile* aLocation)
 {
   nsComponentManagerImpl::InitializeModuleLocations();
   nsComponentManagerImpl::ComponentLocation* c =
     nsComponentManagerImpl::sModuleLocations->AppendElement();
   c->type = aType;
   c->location.Init(aLocation);
--- a/xpcom/components/nsComponentManager.h
+++ b/xpcom/components/nsComponentManager.h
@@ -35,20 +35,16 @@
 #include "nsDataHashtable.h"
 #include "nsInterfaceHashtable.h"
 #include "nsClassHashtable.h"
 #include "nsTArray.h"
 
 #include "mozilla/Omnijar.h"
 #include "mozilla/Attributes.h"
 
-#ifdef MOZ_B2G_LOADER
-#include "mozilla/FileLocation.h"
-#endif
-
 struct nsFactoryEntry;
 class nsIServiceManager;
 struct PRThread;
 
 #define NS_COMPONENTMANAGER_CID                      \
 { /* 91775d60-d5dc-11d2-92fb-00e09805570f */         \
     0x91775d60,                                      \
     0xd5dc,                                          \
@@ -329,41 +325,16 @@ public:
                                                PRThread* aThread);
   inline void RemovePendingService(const nsCID& aServiceCID);
   inline PRThread* GetPendingServiceThread(const nsCID& aServiceCID) const;
 
   nsTArray<PendingServiceInfo> mPendingServices;
 
   size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
 
-#ifdef MOZ_B2G_LOADER
-  // Preload XPT interface info for B2G loader.
-  // This function is called before XPCOM has been initialized.
-  static void PreloadXPT(nsIFile* aFile);
-#endif
-
-#ifdef MOZ_B2G_LOADER
-  // Parsing functions of directives of manifest for XPT only parsing.
-  struct XPTOnlyManifestProcessingContext
-  {
-    XPTOnlyManifestProcessingContext(mozilla::FileLocation& aFile)
-      : mFile(aFile)
-    {
-    }
-
-    ~XPTOnlyManifestProcessingContext() {}
-
-    mozilla::FileLocation mFile;
-  };
-  static void XPTOnlyManifestManifest(XPTOnlyManifestProcessingContext& aCx,
-                                      int aLineNo, char* const* aArgv);
-  static void XPTOnlyManifestXPT(XPTOnlyManifestProcessingContext& aCx,
-                                 int aLineNo, char* const* aArgv);
-#endif
-
 private:
   ~nsComponentManagerImpl();
 };
 
 
 #define NS_MAX_FILENAME_LEN     1024
 
 #define NS_ERROR_IS_DIR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_XPCOM, 24)
--- a/xpcom/threads/BackgroundHangMonitor.cpp
+++ b/xpcom/threads/BackgroundHangMonitor.cpp
@@ -9,19 +9,16 @@
 #include "mozilla/LinkedList.h"
 #include "mozilla/Monitor.h"
 #include "mozilla/Move.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/StaticPtr.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/ThreadHangStats.h"
 #include "mozilla/ThreadLocal.h"
-#ifdef MOZ_NUWA_PROCESS
-#include "ipc/Nuwa.h"
-#endif
 
 #include "prinrval.h"
 #include "prthread.h"
 #include "ThreadStackHelper.h"
 #include "nsIObserverService.h"
 #include "nsIObserver.h"
 #include "mozilla/Services.h"
 #include "nsXULAppAPI.h"
@@ -54,22 +51,16 @@ namespace mozilla {
 class BackgroundHangManager : public nsIObserver
 {
 private:
   // Background hang monitor thread function
   static void MonitorThread(void* aData)
   {
     PR_SetCurrentThreadName("BgHangManager");
 
-#ifdef MOZ_NUWA_PROCESS
-    if (IsNuwaProcess()) {
-      NuwaMarkCurrentThread(nullptr, nullptr);
-    }
-#endif
-
     /* We do not hold a reference to BackgroundHangManager here
        because the monitor thread only exists as long as the
        BackgroundHangManager instance exists. We stop the monitor
        thread in the BackgroundHangManager destructor, and we can
        only get to the destructor if we don't hold a reference here. */
     static_cast<BackgroundHangManager*>(aData)->RunMonitorThread();
   }
 
--- a/xpcom/threads/HangMonitor.cpp
+++ b/xpcom/threads/HangMonitor.cpp
@@ -18,20 +18,16 @@
 #include "mozilla/StackWalk.h"
 #include "nsThreadUtils.h"
 #include "nsXULAppAPI.h"
 
 #ifdef MOZ_CRASHREPORTER
 #include "nsExceptionHandler.h"
 #endif
 
-#ifdef MOZ_NUWA_PROCESS
-#include "ipc/Nuwa.h"
-#endif
-
 #ifdef XP_WIN
 #include <windows.h>
 #endif
 
 #if defined(MOZ_ENABLE_PROFILER_SPS) && defined(MOZ_PROFILING) && defined(XP_WIN)
   #define REPORT_CHROME_HANGS
 #endif
 
@@ -179,22 +175,16 @@ GetChromeHangReport(Telemetry::Processed
 
 #endif
 
 void
 ThreadMain(void*)
 {
   PR_SetCurrentThreadName("Hang Monitor");
 
-#ifdef MOZ_NUWA_PROCESS
-  if (IsNuwaProcess()) {
-    NuwaMarkCurrentThread(nullptr, nullptr);
-  }
-#endif
-
   MonitorAutoLock lock(*gMonitor);
 
   // In order to avoid issues with the hang monitor incorrectly triggering
   // during a general system stop such as sleeping, the monitor thread must
   // run twice to trigger hang protection.
   PRIntervalTime lastTimestamp = 0;
   int waitCount = 0;
 
--- a/xpcom/threads/TimerThread.cpp
+++ b/xpcom/threads/TimerThread.cpp
@@ -381,20 +381,16 @@ TimerThread::Shutdown()
   mThread->Shutdown();    // wait for the thread to die
 
   nsTimerEvent::Shutdown();
 
   MOZ_LOG(GetTimerLog(), LogLevel::Debug, ("TimerThread::Shutdown end\n"));
   return NS_OK;
 }
 
-#ifdef MOZ_NUWA_PROCESS
-#include "ipc/Nuwa.h"
-#endif
-
 namespace {
 
 struct MicrosecondsToInterval
 {
   PRIntervalTime operator[](size_t aMs) const {
     return PR_MicrosecondsToInterval(aMs);
   }
 };
@@ -408,22 +404,16 @@ struct IntervalComparator
 
 } // namespace
 
 NS_IMETHODIMP
 TimerThread::Run()
 {
   PR_SetCurrentThreadName("Timer");
 
-#ifdef MOZ_NUWA_PROCESS
-  if (IsNuwaProcess()) {
-    NuwaMarkCurrentThread(nullptr, nullptr);
-  }
-#endif
-
   MonitorAutoLock lock(mMonitor);
 
   // We need to know how many microseconds give a positive PRIntervalTime. This
   // is platform-dependent and we calculate it at runtime, finding a value |v|
   // such that |PR_MicrosecondsToInterval(v) > 0| and then binary-searching in
   // the range [0, v) to find the ms-to-interval scale.
   uint32_t usForPosInterval = 1;
   while (PR_MicrosecondsToInterval(usForPosInterval) == 0) {
@@ -441,21 +431,17 @@ TimerThread::Run()
   bool forceRunNextTimer = false;
 
   while (!mShutdown) {
     // Have to use PRIntervalTime here, since PR_WaitCondVar takes it
     PRIntervalTime waitFor;
     bool forceRunThisTimer = forceRunNextTimer;
     forceRunNextTimer = false;
 
-    if (mSleeping
-#ifdef MOZ_NUWA_PROCESS
-        || IsNuwaProcess() // Don't fire timers or deadlock will result.
-#endif
-        ) {
+    if (mSleeping) {
       // Sleep for 0.1 seconds while not firing timers.
       uint32_t milliseconds = 100;
       if (ChaosMode::isActive(ChaosFeature::TimerScheduling)) {
         milliseconds = ChaosMode::randomUint32LessThan(200);
       }
       waitFor = PR_MillisecondsToInterval(milliseconds);
     } else {
       waitFor = PR_INTERVAL_NO_TIMEOUT;
--- a/xpcom/threads/nsThread.cpp
+++ b/xpcom/threads/nsThread.cpp
@@ -38,20 +38,16 @@
 #include "LeakRefPtr.h"
 
 #ifdef MOZ_CRASHREPORTER
 #include "nsServiceManagerUtils.h"
 #include "nsICrashReporter.h"
 #include "mozilla/dom/ContentChild.h"
 #endif
 
-#ifdef MOZ_NUWA_PROCESS
-#include "private/pprthred.h"
-#endif
-
 #ifdef XP_LINUX
 #include <sys/time.h>
 #include <sys/resource.h>
 #include <sched.h>
 #endif
 
 #define HAVE_UALARM _BSD_SOURCE || (_XOPEN_SOURCE >= 500 ||                 \
                       _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) &&           \
@@ -672,22 +668,16 @@ nsThread::PutEvent(nsIRunnable* aEvent, 
 nsresult
 nsThread::PutEvent(already_AddRefed<nsIRunnable> aEvent, nsNestedEventTarget* aTarget)
 {
   // We want to leak the reference when we fail to dispatch it, so that
   // we won't release the event in a wrong thread.
   LeakRefPtr<nsIRunnable> event(Move(aEvent));
   nsCOMPtr<nsIThreadObserver> obs;
 
-#ifdef MOZ_NUWA_PROCESS
-  // On debug build or when tests are enabled, assert that we are not about to
-  // create a deadlock in the Nuwa process.
-  NuwaAssertNotFrozen(PR_GetThreadID(mThread), PR_GetThreadName(mThread));
-#endif
-
   {
     MutexAutoLock lock(mLock);
     nsChainedEventQueue* queue = aTarget ? aTarget->mQueue : &mEventsRoot;
     if (!queue || (queue == &mEventsRoot && mEventsAreDoomed)) {
       NS_WARNING("An event was posted to a thread that will never run it (rejected)");
       return NS_ERROR_UNEXPECTED;
     }
     queue->PutEvent(event.take(), lock);
--- a/xpcom/threads/nsTimerImpl.cpp
+++ b/xpcom/threads/nsTimerImpl.cpp
@@ -9,19 +9,16 @@
 #include "nsAutoPtr.h"
 #include "nsThreadManager.h"
 #include "nsThreadUtils.h"
 #include "pratom.h"
 #include "GeckoProfiler.h"
 #include "mozilla/Atomics.h"
 #include "mozilla/IntegerPrintfMacros.h"
 #include "mozilla/Logging.h"
-#ifdef MOZ_NUWA_PROCESS
-#include "ipc/Nuwa.h"
-#endif
 #ifdef MOZ_TASK_TRACER
 #include "GeckoTaskTracerImpl.h"
 using namespace mozilla::tasktracer;
 #endif
 
 #ifdef XP_WIN
 #include <process.h>
 #ifndef getpid