diff --git a/core/lib/Drupal/Core/Config/ConfigImporter.php b/core/lib/Drupal/Core/Config/ConfigImporter.php
index 06fed4b1b0..9036b8dc58 100644
--- a/core/lib/Drupal/Core/Config/ConfigImporter.php
+++ b/core/lib/Drupal/Core/Config/ConfigImporter.php
@@ -1037,13 +1037,13 @@ public function alreadyImporting() {
    * keep the services used by the importer in sync.
    */
   protected function reInjectMe() {
-    $this->_serviceIds = [];
-    $vars = get_object_vars($this);
-    foreach ($vars as $key => $value) {
-      if (is_object($value) && isset($value->_serviceId)) {
-        $this->$key = \Drupal::service($value->_serviceId);
-      }
-    }
+    // When rebuilding the container,
+    // \Drupal\Core\DrupalKernel::initializeContainer() saves the hashes of the
+    // old container and passes them to the new one. So __sleep() will
+    // recognize the old services and then __wakeup() will restore them from
+    // the new container.
+    $this->__sleep();
+    $this->__wakeup();
   }
 
 }
diff --git a/core/lib/Drupal/Core/CoreServiceProvider.php b/core/lib/Drupal/Core/CoreServiceProvider.php
index 8a22bc50d4..8010421ac6 100644
--- a/core/lib/Drupal/Core/CoreServiceProvider.php
+++ b/core/lib/Drupal/Core/CoreServiceProvider.php
@@ -12,7 +12,6 @@
 use Drupal\Core\DependencyInjection\Compiler\ProxyServicesPass;
 use Drupal\Core\DependencyInjection\Compiler\RegisterLazyRouteEnhancers;
 use Drupal\Core\DependencyInjection\Compiler\RegisterLazyRouteFilters;
-use Drupal\Core\DependencyInjection\Compiler\DependencySerializationTraitPass;
 use Drupal\Core\DependencyInjection\Compiler\StackedKernelPass;
 use Drupal\Core\DependencyInjection\Compiler\StackedSessionHandlerPass;
 use Drupal\Core\DependencyInjection\Compiler\RegisterStreamWrappersPass;
@@ -98,8 +97,6 @@ public function register(ContainerBuilder $container) {
 
     // Register plugin managers.
     $container->addCompilerPass(new PluginManagerPass());
-
-    $container->addCompilerPass(new DependencySerializationTraitPass());
   }
 
   /**
diff --git a/core/lib/Drupal/Core/DependencyInjection/Compiler/DependencySerializationTraitPass.php b/core/lib/Drupal/Core/DependencyInjection/Compiler/DependencySerializationTraitPass.php
index 4952283967..e69de29bb2 100644
--- a/core/lib/Drupal/Core/DependencyInjection/Compiler/DependencySerializationTraitPass.php
+++ b/core/lib/Drupal/Core/DependencyInjection/Compiler/DependencySerializationTraitPass.php
@@ -1,28 +0,0 @@
-<?php
-
-namespace Drupal\Core\DependencyInjection\Compiler;
-
-use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
-use Symfony\Component\DependencyInjection\ContainerBuilder;
-
-/**
- * Sets the _serviceId property on all services.
- *
- * @see \Drupal\Core\DependencyInjection\DependencySerializationTrait
- */
-class DependencySerializationTraitPass implements CompilerPassInterface {
-
-  /**
-   * {@inheritdoc}
-   */
-  public function process(ContainerBuilder $container) {
-    foreach ($container->getDefinitions() as $service_id => $definition) {
-      // Only add the property to services that are public (as private services
-      // can not be reloaded through Container::get()) and are objects.
-      if (!$definition->hasTag('parameter_service') && $definition->isPublic()) {
-        $definition->setProperty('_serviceId', $service_id);
-      }
-    }
-  }
-
-}
diff --git a/core/lib/Drupal/Core/DependencyInjection/Container.php b/core/lib/Drupal/Core/DependencyInjection/Container.php
index 5643363316..349261052d 100644
--- a/core/lib/Drupal/Core/DependencyInjection/Container.php
+++ b/core/lib/Drupal/Core/DependencyInjection/Container.php
@@ -12,18 +12,6 @@ class Container extends DrupalContainer {
   /**
    * {@inheritdoc}
    */
-  public function set($id, $service) {
-    parent::set($id, $service);
-
-    // Ensure that the _serviceId property is set on synthetic services as well.
-    if (isset($this->services[$id]) && is_object($this->services[$id]) && !isset($this->services[$id]->_serviceId)) {
-      $this->services[$id]->_serviceId = $id;
-    }
-  }
-
-  /**
-   * {@inheritdoc}
-   */
   public function __sleep() {
     assert(FALSE, 'The container was serialized.');
     return array_keys(get_object_vars($this));
diff --git a/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php b/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php
index e0becc71e2..cebbdf6550 100644
--- a/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php
+++ b/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php
@@ -16,7 +16,7 @@
  *
  * @ingroup container
  */
-class ContainerBuilder extends SymfonyContainerBuilder {
+class ContainerBuilder extends SymfonyContainerBuilder implements ContainerInterface {
 
   /**
    * @var \Doctrine\Instantiator\InstantiatorInterface|null
@@ -71,11 +71,6 @@ public function set($id, $service) {
       throw new \InvalidArgumentException("Service ID names must be lowercase: $id");
     }
     SymfonyContainer::set($id, $service);
-
-    // Ensure that the _serviceId property is set on synthetic services as well.
-    if (isset($this->services[$id]) && is_object($this->services[$id]) && !isset($this->services[$id]->_serviceId)) {
-      $this->services[$id]->_serviceId = $id;
-    }
   }
 
   /**
diff --git a/core/lib/Drupal/Core/DependencyInjection/ContainerInterface.php b/core/lib/Drupal/Core/DependencyInjection/ContainerInterface.php
new file mode 100644
index 0000000000..8701427314
--- /dev/null
+++ b/core/lib/Drupal/Core/DependencyInjection/ContainerInterface.php
@@ -0,0 +1,19 @@
+<?php
+
+namespace Drupal\Core\DependencyInjection;
+
+use Symfony\Component\DependencyInjection\ContainerInterface as BaseContainerInterface;
+
+/**
+ * Documents the existing getServiceIds method.
+ */
+interface ContainerInterface extends BaseContainerInterface {
+
+  /**
+   * Gets all service ids.
+   *
+   * @return array An array of all defined service ids
+   */
+  public function getServiceIds();
+
+}
diff --git a/core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php b/core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php
index 7f3cb5d6f9..3f12d4eb22 100644
--- a/core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php
+++ b/core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php
@@ -3,6 +3,7 @@
 namespace Drupal\Core\DependencyInjection;
 
 use Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
 
 /**
  * Provides dependency injection friendly methods for serialization.
@@ -20,22 +21,38 @@
    * {@inheritdoc}
    */
   public function __sleep() {
-    $this->_serviceIds = [];
     $vars = get_object_vars($this);
-    foreach ($vars as $key => $value) {
-      if (is_object($value) && isset($value->_serviceId)) {
-        // If a class member was instantiated by the dependency injection
-        // container, only store its ID so it can be used to get a fresh object
-        // on unserialization.
-        $this->_serviceIds[$key] = $value->_serviceId;
-        unset($vars[$key]);
-      }
-      // Special case the container, which might not have a service ID.
-      elseif ($value instanceof ContainerInterface) {
-        $this->_serviceIds[$key] = 'service_container';
-        unset($vars[$key]);
+    try {
+      $mapping = \Drupal::service('kernel')->getServiceIdMapping();
+      foreach ($vars as $key => $value) {
+        if (is_object($value)) {
+          $service_id = FALSE;
+          // Special case the container.
+          if ($value instanceof ContainerInterface) {
+            $service_id = 'service_container';
+          }
+          else {
+            $hash = spl_object_hash($value);
+            if (isset($mapping[$hash])) {
+              $service_id = $mapping[$hash];
+            }
+          }
+          if ($service_id) {
+            // If a class member was instantiated by the dependency injection
+            // container, only store its ID so it can be used to get a fresh object
+            // on unserialization.
+            $this->_serviceIds[$key] = $service_id;
+            unset($vars[$key]);
+          }
+        }
       }
     }
+    catch (ContainerNotInitializedException $e) {
+      // No container, no problem.
+    }
+    catch (ServiceNotFoundException $e) {
+      // No kernel, very strange, but still no problem.
+    }
 
     return array_keys($vars);
   }
diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php
index 02c97f5edb..c293349007 100644
--- a/core/lib/Drupal/Core/DrupalKernel.php
+++ b/core/lib/Drupal/Core/DrupalKernel.php
@@ -103,7 +103,7 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface {
   /**
    * Holds the container instance.
    *
-   * @var \Symfony\Component\DependencyInjection\ContainerInterface
+   * @var \Drupal\Core\DependencyInjection\ContainerInterface
    */
   protected $container;
 
@@ -241,6 +241,11 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface {
   protected $root;
 
   /**
+   * A mapping from service hashes to service IDs.
+   */
+  protected $serviceIdMapping = [];
+
+  /**
    * Create a DrupalKernel object from a request.
    *
    * @param \Symfony\Component\HttpFoundation\Request $request
@@ -799,6 +804,14 @@ public function updateModules(array $module_list, array $module_filenames = [])
   }
 
   /**
+   * {@inheritdoc}
+   */
+  public function getServiceIdMapping() {
+    $this->collectServiceIdMapping();
+    return $this->serviceIdMapping;
+  }
+
+  /**
    * Returns the container cache key based on the environment.
    *
    * The 'environment' consists of:
@@ -842,6 +855,8 @@ protected function initializeContainer() {
       if ($this->container->initialized('current_user')) {
         $current_user_id = $this->container->get('current_user')->id();
       }
+      // Save the current services.
+      $this->collectServiceIdMapping();
 
       // If there is a session, close and save it.
       if ($this->container->initialized('session')) {
@@ -1578,6 +1593,24 @@ protected function addServiceFiles(array $service_yamls) {
   }
 
   /**
+   * Collect a mapping between service to ids.
+   */
+  protected function collectServiceIdMapping() {
+    if (isset($this->container)) {
+      foreach ($this->container->getServiceIds() as $service_id) {
+        if ($this->container->initialized($service_id)) {
+          $service = $this->container->get($service_id);
+          // @TODO remove after https://www.drupal.org/node/2536012
+          if (is_object($service)) {
+            $this->serviceIdMapping[spl_object_hash($service)] = $service_id;
+          }
+        }
+      }
+    }
+  }
+
+
+  /**
    * Gets the active install profile.
    *
    * @return string|null
diff --git a/core/lib/Drupal/Core/DrupalKernelInterface.php b/core/lib/Drupal/Core/DrupalKernelInterface.php
index c38fff5db9..d3376e8a15 100644
--- a/core/lib/Drupal/Core/DrupalKernelInterface.php
+++ b/core/lib/Drupal/Core/DrupalKernelInterface.php
@@ -140,4 +140,9 @@ public function preHandle(Request $request);
    */
   public function loadLegacyIncludes();
 
+  /**
+   * Get a mapping from service hashes to service IDs.
+   */
+  public function getServiceIdMapping();
+
 }
diff --git a/core/lib/Drupal/Core/Test/TestKernel.php b/core/lib/Drupal/Core/Test/TestKernel.php
index f7eed629d4..04850c4eda 100644
--- a/core/lib/Drupal/Core/Test/TestKernel.php
+++ b/core/lib/Drupal/Core/Test/TestKernel.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\Core\Test;
 
+use Drupal\Core\DependencyInjection\ContainerBuilder;
 use Drupal\Core\DrupalKernel;
 
 /**
@@ -25,4 +26,23 @@ public function __construct($environment, $class_loader, $allow_dumping = TRUE)
     parent::__construct($environment, $class_loader, $allow_dumping);
   }
 
+  /**
+   * Sets a container with a kernel service on the Drupal class.
+   *
+   * @return \Drupal\Core\DependencyInjection\ContainerInterface
+   *   A container with the kernel service set.
+   */
+  public static function setContainerWithKernel() {
+    $container = new ContainerBuilder();
+    $kernel = new DrupalKernel('test', NULL);
+    // Objects of the same type will have access to each others private and
+    // protected members even though they are not the same instances. This is
+    // because the implementation specific details are already known when
+    // inside those objects.
+    $kernel->container = $container;
+    $container->set('kernel', $kernel);
+    \Drupal::setContainer($container);
+    return $container;
+  }
+
 }
diff --git a/core/modules/system/src/Form/ModulesListForm.php b/core/modules/system/src/Form/ModulesListForm.php
index 28ff7ef4cc..2b59a5b450 100644
--- a/core/modules/system/src/Form/ModulesListForm.php
+++ b/core/modules/system/src/Form/ModulesListForm.php
@@ -64,6 +64,13 @@ class ModulesListForm extends FormBase {
   protected $permissionHandler;
 
   /**
+   * The access manager.
+   *
+   * @var \Drupal\Core\Access\AccessManagerInterface
+   */
+  protected $accessManager;
+
+  /**
    * {@inheritdoc}
    */
   public static function create(ContainerInterface $container) {
diff --git a/core/modules/views_ui/tests/src/Unit/ViewUIObjectTest.php b/core/modules/views_ui/tests/src/Unit/ViewUIObjectTest.php
index f49b25a9fc..b5eda983ae 100644
--- a/core/modules/views_ui/tests/src/Unit/ViewUIObjectTest.php
+++ b/core/modules/views_ui/tests/src/Unit/ViewUIObjectTest.php
@@ -3,6 +3,7 @@
 namespace Drupal\Tests\views_ui\Unit;
 
 use Drupal\Core\Language\LanguageInterface;
+use Drupal\Core\Test\TestKernel;
 use Drupal\Tests\UnitTestCase;
 use Drupal\views\Entity\View;
 use Drupal\views_ui\ViewUI;
@@ -114,8 +115,7 @@ public function testIsLocked() {
    */
   public function testSerialization() {
     // Set a container so the DependencySerializationTrait has it.
-    $container = new ContainerBuilder();
-    \Drupal::setContainer($container);
+    TestKernel::setContainerWithKernel();
 
     $storage = new View([], 'view');
     $executable = $this->getMockBuilder('Drupal\views\ViewExecutable')
diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php
index 026154da70..6631479e0a 100644
--- a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php
+++ b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php
@@ -24,26 +24,6 @@ public function testGet() {
   }
 
   /**
-   * @covers ::set
-   */
-  public function testSet() {
-    $container = new ContainerBuilder();
-    $class = new BarClass();
-    $container->set('bar', $class);
-    $this->assertEquals('bar', $class->_serviceId);
-  }
-
-  /**
-   * @covers ::set
-   */
-  public function testSetException() {
-    $container = new ContainerBuilder();
-    $class = new BarClass();
-    $this->setExpectedException(\InvalidArgumentException::class, 'Service ID names must be lowercase: Bar');
-    $container->set('Bar', $class);
-  }
-
-  /**
    * @covers ::setParameter
    */
   public function testSetParameterException() {
diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php
index 46f00bd2a5..a0c936f85c 100644
--- a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php
+++ b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php
@@ -4,7 +4,6 @@
 
 use Drupal\Core\DependencyInjection\Container;
 use Drupal\Tests\UnitTestCase;
-use Drupal\Tests\Core\DependencyInjection\Fixture\BarClass;
 
 /**
  * @coversDefaultClass \Drupal\Core\DependencyInjection\Container
@@ -21,15 +20,4 @@ public function testSerialize() {
     serialize($container);
   }
 
-  /**
-   * @covers ::set
-   */
-  public function testSet() {
-    $container = new Container();
-    $class = new BarClass();
-    $container->set('bar', $class);
-    // Ensure that _serviceId is set on the object.
-    $this->assertEquals('bar', $class->_serviceId);
-  }
-
 }
diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/DependencySerializationTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/DependencySerializationTest.php
index f5f9a849af..914ff0d683 100644
--- a/core/tests/Drupal/Tests/Core/DependencyInjection/DependencySerializationTest.php
+++ b/core/tests/Drupal/Tests/Core/DependencyInjection/DependencySerializationTest.php
@@ -7,8 +7,8 @@
 
 namespace Drupal\Tests\Core\DependencyInjection;
 
-use Drupal\Core\DependencyInjection\Container;
 use Drupal\Core\DependencyInjection\DependencySerializationTrait;
+use Drupal\Core\Test\TestKernel;
 use Drupal\Tests\UnitTestCase;
 use Symfony\Component\DependencyInjection\ContainerAwareInterface;
 use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -26,11 +26,9 @@ class DependencySerializationTest extends UnitTestCase {
   public function testSerialization() {
     // Create a pseudo service and dependency injected object.
     $service = new \stdClass();
-    $service->_serviceId = 'test_service';
-    $container = new Container();
+    $container = TestKernel::setContainerWithKernel();
     $container->set('test_service', $service);
-    $container->set('service_container', $container);
-    \Drupal::setContainer($container);
+    $this->assertSame($container, $container->get('service_container'));
 
     $dependencySerialization = new DependencySerializationTestDummy($service);
     $dependencySerialization->setContainer($container);
diff --git a/core/tests/Drupal/Tests/Core/DrupalKernel/DrupalKernelTest.php b/core/tests/Drupal/Tests/Core/DrupalKernel/DrupalKernelTest.php
index 7278fd6a98..cdec6038ec 100644
--- a/core/tests/Drupal/Tests/Core/DrupalKernel/DrupalKernelTest.php
+++ b/core/tests/Drupal/Tests/Core/DrupalKernel/DrupalKernelTest.php
@@ -2,7 +2,10 @@
 
 namespace Drupal\Tests\Core\DrupalKernel {
 
+  use Drupal\Core\DependencyInjection\Container;
   use Drupal\Core\DrupalKernel;
+  use Drupal\Core\Test\TestKernel;
+  use Drupal\Tests\Core\DependencyInjection\Fixture\BarClass;
   use Drupal\Tests\UnitTestCase;
   use org\bovigo\vfs\vfsStream;
   use Symfony\Component\ClassLoader\ApcClassLoader;
@@ -192,6 +195,16 @@ public function testFindSitePath() {
       $this->assertEquals('sites/example', DrupalKernel::findSitePath($request, FALSE, $vfs_root->url('drupal_root')));
     }
 
+    /**
+     * @covers ::getServiceIdMapping
+     */
+    public function testGetServiceIdMapping() {
+      $service = new BarClass();
+      $container = TestKernel::setContainerWithKernel();
+      $container->set('bar', $service);
+      $this->assertEquals($container->get('kernel')->getServiceIdMapping()[spl_object_hash($service)], 'bar');
+    }
+
   }
 
   /**
