diff --git a/app/code/Magento/Deploy/Model/Filesystem.php b/app/code/Magento/Deploy/Model/Filesystem.php
index 83de641c4442a445cceb020cad060ce2c4809f5b..7918207934759bd1cb003e676c3b74a41330777c 100644
--- a/app/code/Magento/Deploy/Model/Filesystem.php
+++ b/app/code/Magento/Deploy/Model/Filesystem.php
@@ -13,7 +13,8 @@ use Magento\Framework\Exception\LocalizedException;
 use Magento\User\Model\ResourceModel\User\Collection as UserCollection;
 
 /**
- * Generate static files, compile; clear var/generation, var/di/, var/view_preprocessed and pub/static directories
+ * Generate static files, compile
+ * Сlear generated/code, generated/metadata/, var/view_preprocessed and pub/static directories
  *
  * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  */
@@ -129,7 +130,7 @@ class Filesystem
     public function regenerateStatic(
         OutputInterface $output
     ) {
-        // Сlear var/generation, var/di/, var/view_preprocessed and pub/static directories
+        // Сlear generated/code, generated/metadata/, var/view_preprocessed and pub/static directories
         $this->cleanupFilesystem(
             [
                 DirectoryList::CACHE,
@@ -315,7 +316,7 @@ class Filesystem
      */
     public function lockStaticResources()
     {
-        // Lock /var/generation, /var/di/ and /var/view_preprocessed directories
+        // Lock /generated/code, /generated/metadata/ and /var/view_preprocessed directories
         $this->changePermissions(
             [
                 DirectoryList::GENERATION,
diff --git a/composer.json b/composer.json
index 11fe00b7ed45add98a8996bea8a480403d44a53c..16c73d23ef6d8a743ed69cfa53e890e8e2642a7f 100644
--- a/composer.json
+++ b/composer.json
@@ -226,7 +226,7 @@
         "psr-0": {
             "": [
                 "app/code/",
-                "var/generation"
+                "generated/code"
             ]
         },
         "files": [
diff --git a/composer.lock b/composer.lock
index e69e12953fea2c150e1e063ddb9502148aad38ec..43c927cb95a1d5eb07b272dda0b018be12c73fbe 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
         "This file is @generated automatically"
     ],
-    "hash": "01335ef9c76fd6d77bf6bd9236b84d03",
+    "hash": "e5946b0500f46fab5f05e46957258ed4",
     "content-hash": "07be52ec4880d0390acff2dd605a194d",
     "packages": [
         {
@@ -554,16 +554,16 @@
         },
         {
             "name": "magento/magento-composer-installer",
-            "version": "0.1.11",
+            "version": "0.1.12",
             "source": {
                 "type": "git",
                 "url": "https://github.com/magento/magento-composer-installer.git",
-                "reference": "a12b9577cd9859af67d2365ae38d23ddfc57cf4d"
+                "reference": "10c600e88ad34fec71bb6b435ea8415ce92d51de"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/magento/magento-composer-installer/zipball/a12b9577cd9859af67d2365ae38d23ddfc57cf4d",
-                "reference": "a12b9577cd9859af67d2365ae38d23ddfc57cf4d",
+                "url": "https://api.github.com/repos/magento/magento-composer-installer/zipball/10c600e88ad34fec71bb6b435ea8415ce92d51de",
+                "reference": "10c600e88ad34fec71bb6b435ea8415ce92d51de",
                 "shasum": ""
             },
             "require": {
@@ -629,7 +629,7 @@
                 "composer-installer",
                 "magento"
             ],
-            "time": "2016-06-15 04:02:25"
+            "time": "2016-10-06 16:05:07"
         },
         {
             "name": "magento/zendframework1",
@@ -1687,7 +1687,7 @@
         },
         {
             "name": "zendframework/zend-code",
-            "version": "2.4.10",
+            "version": "2.4.11",
             "source": {
                 "type": "git",
                 "url": "https://github.com/zendframework/zend-code.git",
@@ -1740,7 +1740,7 @@
         },
         {
             "name": "zendframework/zend-config",
-            "version": "2.4.10",
+            "version": "2.4.11",
             "source": {
                 "type": "git",
                 "url": "https://github.com/zendframework/zend-config.git",
@@ -1797,7 +1797,7 @@
         },
         {
             "name": "zendframework/zend-console",
-            "version": "2.4.10",
+            "version": "2.4.11",
             "source": {
                 "type": "git",
                 "url": "https://github.com/zendframework/zend-console.git",
@@ -1847,7 +1847,7 @@
         },
         {
             "name": "zendframework/zend-crypt",
-            "version": "2.4.10",
+            "version": "2.4.11",
             "source": {
                 "type": "git",
                 "url": "https://github.com/zendframework/zend-crypt.git",
@@ -1899,7 +1899,7 @@
         },
         {
             "name": "zendframework/zend-di",
-            "version": "2.4.10",
+            "version": "2.4.11",
             "source": {
                 "type": "git",
                 "url": "https://github.com/zendframework/zend-di.git",
@@ -1950,7 +1950,7 @@
         },
         {
             "name": "zendframework/zend-escaper",
-            "version": "2.4.10",
+            "version": "2.4.11",
             "source": {
                 "type": "git",
                 "url": "https://github.com/zendframework/zend-escaper.git",
@@ -1995,7 +1995,7 @@
         },
         {
             "name": "zendframework/zend-eventmanager",
-            "version": "2.4.10",
+            "version": "2.4.11",
             "source": {
                 "type": "git",
                 "url": "https://github.com/zendframework/zend-eventmanager.git",
@@ -2041,7 +2041,7 @@
         },
         {
             "name": "zendframework/zend-filter",
-            "version": "2.4.10",
+            "version": "2.4.11",
             "source": {
                 "type": "git",
                 "url": "https://github.com/zendframework/zend-filter.git",
@@ -2097,7 +2097,7 @@
         },
         {
             "name": "zendframework/zend-form",
-            "version": "2.4.10",
+            "version": "2.4.11",
             "source": {
                 "type": "git",
                 "url": "https://github.com/zendframework/zend-form.git",
@@ -2168,7 +2168,7 @@
         },
         {
             "name": "zendframework/zend-http",
-            "version": "2.4.10",
+            "version": "2.4.11",
             "source": {
                 "type": "git",
                 "url": "https://github.com/zendframework/zend-http.git",
@@ -2219,7 +2219,7 @@
         },
         {
             "name": "zendframework/zend-i18n",
-            "version": "2.4.10",
+            "version": "2.4.11",
             "source": {
                 "type": "git",
                 "url": "https://github.com/zendframework/zend-i18n.git",
@@ -2283,7 +2283,7 @@
         },
         {
             "name": "zendframework/zend-inputfilter",
-            "version": "2.4.10",
+            "version": "2.4.11",
             "source": {
                 "type": "git",
                 "url": "https://github.com/zendframework/zend-inputfilter.git",
@@ -2334,7 +2334,7 @@
         },
         {
             "name": "zendframework/zend-json",
-            "version": "2.4.10",
+            "version": "2.4.11",
             "source": {
                 "type": "git",
                 "url": "https://github.com/zendframework/zend-json.git",
@@ -2388,7 +2388,7 @@
         },
         {
             "name": "zendframework/zend-loader",
-            "version": "2.4.10",
+            "version": "2.4.11",
             "source": {
                 "type": "git",
                 "url": "https://github.com/zendframework/zend-loader.git",
@@ -2433,7 +2433,7 @@
         },
         {
             "name": "zendframework/zend-log",
-            "version": "2.4.10",
+            "version": "2.4.11",
             "source": {
                 "type": "git",
                 "url": "https://github.com/zendframework/zend-log.git",
@@ -2495,7 +2495,7 @@
         },
         {
             "name": "zendframework/zend-math",
-            "version": "2.4.10",
+            "version": "2.4.11",
             "source": {
                 "type": "git",
                 "url": "https://github.com/zendframework/zend-math.git",
@@ -2546,7 +2546,7 @@
         },
         {
             "name": "zendframework/zend-modulemanager",
-            "version": "2.4.10",
+            "version": "2.4.11",
             "source": {
                 "type": "git",
                 "url": "https://github.com/zendframework/zend-modulemanager.git",
@@ -2604,7 +2604,7 @@
         },
         {
             "name": "zendframework/zend-mvc",
-            "version": "2.4.10",
+            "version": "2.4.11",
             "source": {
                 "type": "git",
                 "url": "https://github.com/zendframework/zend-mvc.git",
@@ -2692,7 +2692,7 @@
         },
         {
             "name": "zendframework/zend-serializer",
-            "version": "2.4.10",
+            "version": "2.4.11",
             "source": {
                 "type": "git",
                 "url": "https://github.com/zendframework/zend-serializer.git",
@@ -2745,7 +2745,7 @@
         },
         {
             "name": "zendframework/zend-server",
-            "version": "2.4.10",
+            "version": "2.4.11",
             "source": {
                 "type": "git",
                 "url": "https://github.com/zendframework/zend-server.git",
@@ -2792,7 +2792,7 @@
         },
         {
             "name": "zendframework/zend-servicemanager",
-            "version": "2.4.10",
+            "version": "2.4.11",
             "source": {
                 "type": "git",
                 "url": "https://github.com/zendframework/zend-servicemanager.git",
@@ -2842,7 +2842,7 @@
         },
         {
             "name": "zendframework/zend-soap",
-            "version": "2.4.10",
+            "version": "2.4.11",
             "source": {
                 "type": "git",
                 "url": "https://github.com/zendframework/zend-soap.git",
@@ -2894,7 +2894,7 @@
         },
         {
             "name": "zendframework/zend-stdlib",
-            "version": "2.4.10",
+            "version": "2.4.11",
             "source": {
                 "type": "git",
                 "url": "https://github.com/zendframework/zend-stdlib.git",
@@ -2949,7 +2949,7 @@
         },
         {
             "name": "zendframework/zend-text",
-            "version": "2.4.10",
+            "version": "2.4.11",
             "source": {
                 "type": "git",
                 "url": "https://github.com/zendframework/zend-text.git",
@@ -2996,7 +2996,7 @@
         },
         {
             "name": "zendframework/zend-uri",
-            "version": "2.4.10",
+            "version": "2.4.11",
             "source": {
                 "type": "git",
                 "url": "https://github.com/zendframework/zend-uri.git",
@@ -3044,7 +3044,7 @@
         },
         {
             "name": "zendframework/zend-validator",
-            "version": "2.4.10",
+            "version": "2.4.11",
             "source": {
                 "type": "git",
                 "url": "https://github.com/zendframework/zend-validator.git",
@@ -3109,7 +3109,7 @@
         },
         {
             "name": "zendframework/zend-view",
-            "version": "2.4.10",
+            "version": "2.4.11",
             "source": {
                 "type": "git",
                 "url": "https://github.com/zendframework/zend-view.git",
diff --git a/dev/tests/functional/.htaccess.sample b/dev/tests/functional/.htaccess.sample
index f1e60cf9b67e91779153e4c9d9f780c8f7bc9438..c1fcc7c278c8aa0e79bd372c89ed6ef6e8ec2f0f 100644
--- a/dev/tests/functional/.htaccess.sample
+++ b/dev/tests/functional/.htaccess.sample
@@ -1,6 +1,6 @@
 ##############################################
 ## Allow access to command.php and website.php
-    <FilesMatch "command.php|website.php|export.php">
+    <FilesMatch "command.php|website.php|export.php|pathChecker.php|deleteMagentoGeneratedCode.php">
          order allow,deny
          allow from all
     </FilesMatch>
diff --git a/dev/tests/functional/lib/Magento/Mtf/Util/Command/Cli/Setup.php b/dev/tests/functional/lib/Magento/Mtf/Util/Command/Cli/Setup.php
index 385c11cd74f82e4adbc78f5e26b14e1e03931dae..5f5fe66d96cef6cc25689b315a31d91214e01719 100644
--- a/dev/tests/functional/lib/Magento/Mtf/Util/Command/Cli/Setup.php
+++ b/dev/tests/functional/lib/Magento/Mtf/Util/Command/Cli/Setup.php
@@ -18,6 +18,11 @@ class Setup extends Cli
      */
     const PARAM_SETUP_UNINSTALL = 'setup:uninstall';
 
+    /**
+     * Parameter for DI compile Magento command.
+     */
+    const PARAM_SETUP_DI_COMPILE = 'setup:di:compile';
+
     /**
      * Options for uninstall Magento command.
      *
@@ -34,4 +39,14 @@ class Setup extends Cli
     {
         parent::execute(Setup::PARAM_SETUP_UNINSTALL, $this->options);
     }
+
+    /**
+     * DI Compile.
+     *
+     * @return void
+     */
+    public function diCompile()
+    {
+        parent::execute(Setup::PARAM_SETUP_DI_COMPILE);
+    }
 }
diff --git a/dev/tests/functional/lib/Magento/Mtf/Util/Command/GeneratedCode.php b/dev/tests/functional/lib/Magento/Mtf/Util/Command/GeneratedCode.php
new file mode 100644
index 0000000000000000000000000000000000000000..c82231a9e38f1a10dab7cc822bb4bed2f092cb2d
--- /dev/null
+++ b/dev/tests/functional/lib/Magento/Mtf/Util/Command/GeneratedCode.php
@@ -0,0 +1,49 @@
+<?php
+/**
+ * Copyright © 2013-2017 Magento, Inc. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+namespace Magento\Mtf\Util\Command;
+
+use Magento\Mtf\Util\Protocol\CurlInterface;
+use Magento\Mtf\Util\Protocol\CurlTransport;
+
+/**
+ * GeneratedCode removes generated code of Magento (like generated/code and generated/metadata).
+ */
+class GeneratedCode
+{
+    /**
+     * Url to deleteMagentoGeneratedCode.php.
+     */
+    const URL = 'dev/tests/functional/utils/deleteMagentoGeneratedCode.php';
+
+    /**
+     * Curl transport protocol.
+     *
+     * @var CurlTransport
+     */
+    private $transport;
+
+    /**
+     * @param CurlTransport $transport
+     */
+    public function __construct(CurlTransport $transport)
+    {
+        $this->transport = $transport;
+    }
+
+    /**
+     * Remove generated code.
+     *
+     * @return void
+     */
+    public function delete()
+    {
+        $url = $_ENV['app_frontend_url'] . self::URL;
+        $curl = $this->transport;
+        $curl->write($url, [], CurlInterface::GET);
+        $curl->read();
+        $curl->close();
+    }
+}
diff --git a/dev/tests/functional/lib/Magento/Mtf/Util/Command/PathChecker.php b/dev/tests/functional/lib/Magento/Mtf/Util/Command/PathChecker.php
new file mode 100644
index 0000000000000000000000000000000000000000..f61210dc554efc910d4d44b2f5f7bed875d4955d
--- /dev/null
+++ b/dev/tests/functional/lib/Magento/Mtf/Util/Command/PathChecker.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * Copyright © 2013-2017 Magento, Inc. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+namespace Magento\Mtf\Util\Command;
+
+use Magento\Mtf\Util\Protocol\CurlInterface;
+use Magento\Mtf\Util\Protocol\CurlTransport;
+
+/**
+ * PathChecker checks that path to file or directory exists.
+ */
+class PathChecker
+{
+    /**
+     * Url to checkPath.php.
+     */
+    const URL = 'dev/tests/functional/utils/pathChecker.php';
+
+    /**
+     * Curl transport protocol.
+     *
+     * @var CurlTransport
+     */
+    private $transport;
+
+    /**
+     * @param CurlTransport $transport
+     */
+    public function __construct(CurlTransport $transport)
+    {
+        $this->transport = $transport;
+    }
+
+    /**
+     * Check that $path exists.
+     *
+     * @param string $path
+     * @return bool
+     */
+    public function pathExists($path)
+    {
+        $url = $_ENV['app_frontend_url'] . self::URL . '?path=' . urlencode($path);
+        $curl = $this->transport;
+        $curl->write($url, [], CurlInterface::GET);
+        $result = $curl->read();
+        $curl->close();
+
+        return strpos($result, 'path exists: true') !== false;
+    }
+}
diff --git a/dev/tests/functional/tests/app/Magento/Install/Test/Constraint/AssertGenerationFilePathCheck.php b/dev/tests/functional/tests/app/Magento/Install/Test/Constraint/AssertGenerationFilePathCheck.php
new file mode 100644
index 0000000000000000000000000000000000000000..64e46ac9b0289f6d0ee265339eff208c35fe7c3f
--- /dev/null
+++ b/dev/tests/functional/tests/app/Magento/Install/Test/Constraint/AssertGenerationFilePathCheck.php
@@ -0,0 +1,64 @@
+<?php
+/**
+ * Copyright © 2013-2017 Magento, Inc. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+namespace Magento\Install\Test\Constraint;
+
+use Magento\Mtf\Constraint\AbstractConstraint;
+use Magento\Mtf\Util\Command\PathChecker;
+
+/**
+ * Assert that path of generated files is correct.
+ */
+class AssertGenerationFilePathCheck extends AbstractConstraint
+{
+    /**
+     * Assert that path of generated files is correct.
+     *
+     * @param PathChecker $pathChecker
+     * @return void
+     */
+    public function processAssert(PathChecker $pathChecker)
+    {
+        $existsPaths = [
+            'generated/code',
+            'generated/metadata',
+            'generated/metadata/global.ser',
+            'generated/metadata/adminhtml.ser',
+            'generated/metadata/crontab.ser',
+            'generated/metadata/frontend.ser',
+            'generated/metadata/webapi_rest.ser',
+            'generated/metadata/webapi_soap.ser',
+        ];
+
+        $nonExistsPaths = [
+            'var/di',
+            'var/generation'
+        ];
+
+        foreach ($existsPaths as $path) {
+            \PHPUnit_Framework_Assert::assertTrue(
+                $pathChecker->pathExists($path),
+                'Path "' . $path . '" does not exist.'
+            );
+        }
+
+        foreach ($nonExistsPaths as $path) {
+            \PHPUnit_Framework_Assert::assertFalse(
+                $pathChecker->pathExists($path),
+                'Path "' . $path . '" exists.'
+            );
+        }
+    }
+
+    /**
+     * Returns a string representation of the object.
+     *
+     * @return string
+     */
+    public function toString()
+    {
+        return 'Path of generated files is correct.';
+    }
+}
diff --git a/dev/tests/functional/tests/app/Magento/Install/Test/TestCase/InstallTest.php b/dev/tests/functional/tests/app/Magento/Install/Test/TestCase/InstallTest.php
index 657ea4379b46e8d106e93cdddfc978c7c4d7159a..32594facd3a1bce7a6ae59f04840c8fd8e0e0421 100644
--- a/dev/tests/functional/tests/app/Magento/Install/Test/TestCase/InstallTest.php
+++ b/dev/tests/functional/tests/app/Magento/Install/Test/TestCase/InstallTest.php
@@ -17,6 +17,7 @@ use Magento\Install\Test\Constraint\AssertSuccessfulReadinessCheck;
 use Magento\Install\Test\Constraint\AssertAdminUriAutogenerated;
 use Magento\Install\Test\Constraint\AssertDevdocsLink;
 use Magento\Mtf\Util\Command\Cli\Setup;
+use Magento\Mtf\Util\Command\GeneratedCode;
 use Magento\Mtf\Client\BrowserInterface;
 
 /**
@@ -76,6 +77,13 @@ class InstallTest extends Injectable
      */
     protected $installPage;
 
+    /**
+     * Setup Magento for tests executions.
+     *
+     * @var Setup
+     */
+    private $magentoSetup;
+
     /**
      * Uninstall Magento before test.
      *
@@ -101,12 +109,17 @@ class InstallTest extends Injectable
      * @param Install $installPage
      * @param Setup $magentoSetup
      * @param DevdocsInstall $devdocsInstallPage
+     * @param GeneratedCode $generatedCode
      * @return void
      */
-    public function __inject(Install $installPage, Setup $magentoSetup, DevdocsInstall $devdocsInstallPage)
-    {
-        // Uninstall Magento.
-        $magentoSetup->uninstall();
+    public function __inject(
+        Install $installPage,
+        Setup $magentoSetup,
+        DevdocsInstall $devdocsInstallPage,
+        GeneratedCode $generatedCode
+    ) {
+        $generatedCode->delete();
+        $this->magentoSetup = $magentoSetup;
         $this->installPage = $installPage;
         $this->devdocsInstallPage = $devdocsInstallPage;
     }
@@ -122,8 +135,10 @@ class InstallTest extends Injectable
      * @param AssertAdminUriAutogenerated $assertAdminUri
      * @param AssertDevdocsLink $assertDevdocsLink
      * @param BrowserInterface $browser
+     * @param bool $diCompile
      * @param array $install [optional]
      * @return array
+     * @SuppressWarnings(PHPMD.ExcessiveParameterList)
      */
     public function test(
         User $user,
@@ -134,8 +149,10 @@ class InstallTest extends Injectable
         AssertAdminUriAutogenerated $assertAdminUri,
         AssertDevdocsLink $assertDevdocsLink,
         BrowserInterface $browser,
+        $diCompile = false,
         array $install = []
     ) {
+        $this->magentoSetup->uninstall();
         $dataConfig = array_merge($install, $configData);
         if (isset($dataConfig['httpsFront'])) {
             $dataConfig['https'] = str_replace('http', 'https', $dataConfig['baseUrl']);
@@ -178,6 +195,10 @@ class InstallTest extends Injectable
         // Step 6: Install.
         $this->installPage->getInstallBlock()->clickInstallNow();
 
+        if ($diCompile) {
+            $this->magentoSetup->diCompile();
+        }
+
         return ['installConfig' => $installConfig];
     }
 
diff --git a/dev/tests/functional/tests/app/Magento/Install/Test/TestCase/InstallTest.xml b/dev/tests/functional/tests/app/Magento/Install/Test/TestCase/InstallTest.xml
index cdfc018346b56dad265044131f6719fb3c48ef78..0a2b502ce3da6b98f18c3adfbc6b90fac39c43bd 100644
--- a/dev/tests/functional/tests/app/Magento/Install/Test/TestCase/InstallTest.xml
+++ b/dev/tests/functional/tests/app/Magento/Install/Test/TestCase/InstallTest.xml
@@ -48,10 +48,12 @@
             <constraint name="Magento\User\Test\Constraint\AssertUserSuccessLogin" />
             <constraint name="Magento\Install\Test\Constraint\AssertSecureUrlEnabled" />
         </variation>
-        <variation name="InstallTestVariation6" summary="Install with default values">
+        <variation name="InstallTestVariation6" summary="Install with default values and check DI compile">
             <data name="user/dataset" xsi:type="string">default</data>
+            <data name="diCompile" xsi:type="boolean">true</data>
             <constraint name="Magento\Install\Test\Constraint\AssertSuccessInstall" />
             <constraint name="Magento\User\Test\Constraint\AssertUserSuccessLogin" />
+            <constraint name="Magento\Install\Test\Constraint\AssertGenerationFilePathCheck" />
         </variation>
     </testCase>
 </config>
diff --git a/dev/tests/functional/utils/deleteMagentoGeneratedCode.php b/dev/tests/functional/utils/deleteMagentoGeneratedCode.php
new file mode 100644
index 0000000000000000000000000000000000000000..b90269a9a21f68a8f2601eb409a4c7c5e912ff87
--- /dev/null
+++ b/dev/tests/functional/utils/deleteMagentoGeneratedCode.php
@@ -0,0 +1,7 @@
+<?php
+/**
+ * Copyright © 2013-2017 Magento, Inc. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+
+exec('rm -rf ../../../../generated/*');
diff --git a/dev/tests/functional/utils/pathChecker.php b/dev/tests/functional/utils/pathChecker.php
new file mode 100644
index 0000000000000000000000000000000000000000..a57ac8d3e07b1d82f777e64dddba3518cf281a94
--- /dev/null
+++ b/dev/tests/functional/utils/pathChecker.php
@@ -0,0 +1,17 @@
+<?php
+/**
+ * Copyright © 2013-2017 Magento, Inc. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+
+if (isset($_GET['path'])) {
+    $path = urldecode($_GET['path']);
+
+    if (file_exists('../../../../' . $path)) {
+        echo 'path exists: true';
+    } else {
+        echo 'path exists: false';
+    }
+} else {
+    throw new \InvalidArgumentException("GET parameter 'path' is not set.");
+}
diff --git a/dev/tests/integration/framework/Magento/TestFramework/Application.php b/dev/tests/integration/framework/Magento/TestFramework/Application.php
index 3d76b9774d50976e1f74cab4979f39e1cbd86064..e52976f505710a226e4cf008b8e21341a08fecce 100644
--- a/dev/tests/integration/framework/Magento/TestFramework/Application.php
+++ b/dev/tests/integration/framework/Magento/TestFramework/Application.php
@@ -630,12 +630,13 @@ class Application
     {
         $path = DirectoryList::PATH;
         $var = "{$this->installDir}/var";
+        $generated = "{$this->installDir}/generated";
         $customDirs = [
             DirectoryList::CONFIG => [$path => "{$this->installDir}/etc"],
             DirectoryList::VAR_DIR => [$path => $var],
             DirectoryList::MEDIA => [$path => "{$this->installDir}/pub/media"],
             DirectoryList::STATIC_VIEW => [$path => "{$this->installDir}/pub/static"],
-            DirectoryList::GENERATION => [$path => "{$var}/generation"],
+            DirectoryList::GENERATION => [$path => "{$generated}/code"],
             DirectoryList::CACHE => [$path => "{$var}/cache"],
             DirectoryList::LOG => [$path => "{$var}/log"],
             DirectoryList::SESSION => [$path => "{$var}/session"],
diff --git a/dev/tests/static/framework/autoload.php b/dev/tests/static/framework/autoload.php
index a5750d9303c945e6f831c23b88d919b96d50cd44..fc3b62fc97287d9be6d6f72db106436c4ab7f84f 100644
--- a/dev/tests/static/framework/autoload.php
+++ b/dev/tests/static/framework/autoload.php
@@ -4,6 +4,8 @@
  * See COPYING.txt for license details.
  */
 
+use \Magento\Framework\App\Filesystem\DirectoryList;
+
 $baseDir = realpath(__DIR__ . '/../../../../');
 require $baseDir . '/app/autoload.php';
 $testsBaseDir = $baseDir . '/dev/tests/static';
@@ -16,4 +18,6 @@ $autoloadWrapper->addPsr4(
         $testsBaseDir . '/../integration/framework/Magento/TestFramework/',
     ]
 );
-$autoloadWrapper->addPsr4('Magento\\', $baseDir . '/var/generation/Magento/');
+
+$generatedCode = DirectoryList::getDefaultConfig()[DirectoryList::GENERATION][DirectoryList::PATH];
+$autoloadWrapper->addPsr4('Magento\\', $baseDir . '/' . $generatedCode . '/Magento/');
diff --git a/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcpd/blacklist/common.txt b/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcpd/blacklist/common.txt
index 3afe3af79b14ff3177a0dc1c5ea9fe42e93b6331..ebe8501337efff410bba83f4f291b3433247a893 100644
--- a/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcpd/blacklist/common.txt
+++ b/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcpd/blacklist/common.txt
@@ -109,7 +109,7 @@ Magento/SalesRule/Model/Resource/Report/Rule
 Magento/SalesRule/Model/Resource/Rule
 Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit
 Magento/User/Block/User/Edit
-var/generation
+generated/code
 Magento/Newsletter/Block/Adminhtml/Template/Grid/Renderer
 Magento/Newsletter/Model/Template/Filter
 Magento/Newsletter/Model/Resource/Subscriber
diff --git a/dev/tests/unit/framework/autoload.php b/dev/tests/unit/framework/autoload.php
index 4b2adbe17673fb7f33a60f7183ffd190833d2904..b4987145872d44c854c993fad60cb6ce02422bf0 100644
--- a/dev/tests/unit/framework/autoload.php
+++ b/dev/tests/unit/framework/autoload.php
@@ -4,10 +4,12 @@
  * See COPYING.txt for license details.
  */
 
+use Magento\Framework\App\Filesystem\DirectoryList;
+
 $autoloader = new \Magento\Framework\TestFramework\Unit\Autoloader\ExtensionGeneratorAutoloader(
     new \Magento\Framework\Code\Generator\Io(
         new \Magento\Framework\Filesystem\Driver\File(),
-        TESTS_TEMP_DIR . '/var/generation'
+        TESTS_TEMP_DIR . '/'. DirectoryList::getDefaultConfig()[DirectoryList::GENERATION][DirectoryList::PATH]
     )
 );
 spl_autoload_register([$autoloader, 'load']);
diff --git a/generated/.htaccess b/generated/.htaccess
new file mode 100644
index 0000000000000000000000000000000000000000..896fbc5a341ea313ff3abd503808842757678c1d
--- /dev/null
+++ b/generated/.htaccess
@@ -0,0 +1,2 @@
+Order deny,allow
+Deny from all
\ No newline at end of file
diff --git a/lib/internal/Magento/Framework/App/Filesystem/DirectoryList.php b/lib/internal/Magento/Framework/App/Filesystem/DirectoryList.php
index ae1a6544ef2cbf05ef8bd4de84188472113ffa9c..57c903b49198cb5b4c99c8b6dcb2fcd8bcb3ed94 100644
--- a/lib/internal/Magento/Framework/App/Filesystem/DirectoryList.php
+++ b/lib/internal/Magento/Framework/App/Filesystem/DirectoryList.php
@@ -5,6 +5,8 @@
  */
 namespace Magento\Framework\App\Filesystem;
 
+use Magento\Framework\Code\Generator\Io;
+
 /**
  * A Magento application specific list of directories
  */
@@ -120,8 +122,8 @@ class DirectoryList extends \Magento\Framework\Filesystem\DirectoryList
             self::VAR_DIR => [parent::PATH => 'var'],
             self::CACHE => [parent::PATH => 'var/cache'],
             self::LOG => [parent::PATH => 'var/log'],
-            self::DI => [parent::PATH => 'var/di'],
-            self::GENERATION => [parent::PATH => 'var/generation'],
+            self::DI => [parent::PATH => 'generated/metadata'],
+            self::GENERATION => [parent::PATH => Io::DEFAULT_DIRECTORY],
             self::SESSION => [parent::PATH => 'var/session'],
             self::MEDIA => [parent::PATH => 'pub/media', parent::URL_PATH => 'pub/media'],
             self::STATIC_VIEW => [parent::PATH => 'pub/static', parent::URL_PATH => 'pub/static'],
diff --git a/lib/internal/Magento/Framework/Code/GeneratedFiles.php b/lib/internal/Magento/Framework/Code/GeneratedFiles.php
index e33b311e74c629735d60485874c42769ad12a11e..9656ef6c4b9fe794b4ca6f915027905f106c1e3d 100644
--- a/lib/internal/Magento/Framework/Code/GeneratedFiles.php
+++ b/lib/internal/Magento/Framework/Code/GeneratedFiles.php
@@ -57,7 +57,7 @@ class GeneratedFiles
     }
 
     /**
-     * Clean var/generation, var/di and var/cache
+     * Clean generated/code, generated/metadata and var/cache
      *
      * @return void
      */
@@ -81,12 +81,12 @@ class GeneratedFiles
             $generationPath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::GENERATION));
             $diPath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::DI));
 
-            // Clean var/generation dir
+            // Clean generated/code dir
             if ($this->write->isDirectory($generationPath)) {
                 $this->write->delete($generationPath);
             }
 
-            // Clean var/di
+            // Clean generated/metadata
             if ($this->write->isDirectory($diPath)) {
                 $this->write->delete($diPath);
             }
@@ -101,7 +101,7 @@ class GeneratedFiles
     }
 
     /**
-     * Create flag for cleaning up var/generation, var/di and var/cache directories for subsequent
+     * Create flag for cleaning up generated/code, generated/metadata and var/cache directories for subsequent
      * regeneration of this content
      *
      * @return void
diff --git a/lib/internal/Magento/Framework/Code/Generator/Io.php b/lib/internal/Magento/Framework/Code/Generator/Io.php
index 05ddb46e948325eaba29f91a570ddb8412948e40..85449fe61749fa6dcdbb941a5b28c436cf663e90 100644
--- a/lib/internal/Magento/Framework/Code/Generator/Io.php
+++ b/lib/internal/Magento/Framework/Code/Generator/Io.php
@@ -14,7 +14,7 @@ class Io
      * Default code generation directory
      * Should correspond the value from \Magento\Framework\Filesystem
      */
-    const DEFAULT_DIRECTORY = 'var/generation';
+    const DEFAULT_DIRECTORY = 'generated/code';
 
     /**
      * Path to directory where new file must be created
diff --git a/lib/internal/Magento/Framework/Console/Cli.php b/lib/internal/Magento/Framework/Console/Cli.php
index 30242b488b14c3ce838d957a56c431828388bb2a..9c6fbb0276d856e002a0cd1459fa02841416f4ec 100644
--- a/lib/internal/Magento/Framework/Console/Cli.php
+++ b/lib/internal/Magento/Framework/Console/Cli.php
@@ -8,7 +8,6 @@ namespace Magento\Framework\Console;
 use Magento\Framework\App\DeploymentConfig;
 use Magento\Framework\App\Filesystem\DirectoryList;
 use Magento\Framework\App\State;
-use Magento\Framework\Code\Generator\Io;
 use Magento\Framework\Composer\ComposerJsonFinder;
 use Magento\Framework\Exception\FileSystemException;
 use Magento\Setup\Model\ObjectManagerProvider;
@@ -98,7 +97,9 @@ class Cli extends Console\Application
         if ($this->initException) {
             $output->writeln(
                 "<error>We're sorry, an error occurred. Try clearing the cache and code generation directories. "
-                . "By default, they are: var/cache, var/di, var/generation, and var/page_cache.</error>"
+                . "By default, they are: " . $this->getDefaultDirectoryPath(DirectoryList::CACHE) . ", "
+                . $this->getDefaultDirectoryPath(DirectoryList::DI) . ", "
+                . $this->getDefaultDirectoryPath(DirectoryList::GENERATION) . ", and var/page_cache.</error>"
             );
 
             throw $this->initException;
@@ -239,7 +240,8 @@ class Cli extends Console\Application
         $output = new Console\Output\ConsoleOutput();
         $output->writeln(
             '<error>'
-            . 'Command line user does not have read and write permissions on ' . Io::DEFAULT_DIRECTORY . ' directory. '
+            . 'Command line user does not have read and write permissions on '
+            . $this->getDefaultDirectoryPath(DirectoryList::GENERATION) . ' directory. '
             . 'Please address this issue before using Magento command line.'
             . '</error>'
         );
@@ -266,4 +268,22 @@ class Cli extends Console\Application
 
         return $commands;
     }
+
+    /**
+     * Get default directory path by code
+     *
+     * @param string $code
+     * @return string
+     */
+    private function getDefaultDirectoryPath($code)
+    {
+        $config = DirectoryList::getDefaultConfig();
+        $result = '';
+
+        if (isset($config[$code][DirectoryList::PATH])) {
+            $result = $config[$code][DirectoryList::PATH];
+        }
+
+        return $result;
+    }
 }
diff --git a/lib/internal/Magento/Framework/Console/GenerationDirectoryAccess.php b/lib/internal/Magento/Framework/Console/GenerationDirectoryAccess.php
index b0baf410d669f16eab5899e07b9e6103a274bd82..a2a1fc9be20e0a4702734cb7065011aab63ab564 100644
--- a/lib/internal/Magento/Framework/Console/GenerationDirectoryAccess.php
+++ b/lib/internal/Magento/Framework/Console/GenerationDirectoryAccess.php
@@ -14,7 +14,7 @@ use Zend\ServiceManager\ServiceManager;
 use Magento\Setup\Mvc\Bootstrap\InitParamListener;
 
 /**
- * Check var/generation read and write access
+ * Check generated/code read and write access
  */
 class GenerationDirectoryAccess
 {
@@ -33,7 +33,7 @@ class GenerationDirectoryAccess
     }
 
     /**
-     * Check var/generation read and write access
+     * Check generated/code read and write access
      *
      * @return bool
      */
diff --git a/lib/internal/Magento/Framework/Setup/FilePermissions.php b/lib/internal/Magento/Framework/Setup/FilePermissions.php
index 1ca91b57e2e90ab38afcfecd53dee6f7268ccac6..4cc4a1852f0d725e324e4d18a5a53d7bf2f458a3 100644
--- a/lib/internal/Magento/Framework/Setup/FilePermissions.php
+++ b/lib/internal/Magento/Framework/Setup/FilePermissions.php
@@ -130,7 +130,7 @@ class FilePermissions
     }
 
     /**
-     * Check all sub-directories and files except for var/generation and var/di
+     * Check all sub-directories and files except for generated/code and generated/metadata
      *
      * @param string $directory
      * @return bool
diff --git a/setup/src/Magento/Setup/Console/Command/UpgradeCommand.php b/setup/src/Magento/Setup/Console/Command/UpgradeCommand.php
index 4734b99f19247e8763aa29ee0c19f6ae8fdce129..e652bb4d1183481b7c66230eacd7a0013bef3492 100644
--- a/setup/src/Magento/Setup/Console/Command/UpgradeCommand.php
+++ b/setup/src/Magento/Setup/Console/Command/UpgradeCommand.php
@@ -17,7 +17,7 @@ use Symfony\Component\Console\Output\OutputInterface;
 class UpgradeCommand extends AbstractSetupCommand
 {
     /**
-     * Option to skip deletion of var/generation directory
+     * Option to skip deletion of generated/code directory
      */
     const INPUT_KEY_KEEP_GENERATED = 'keep-generated';
 
diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php
index 0918ee66fbb684e5553a857cda7e5807c417d6b8..088b40aa4decbf24fb11ab65dca17c7ca726e445 100644
--- a/setup/src/Magento/Setup/Model/Installer.php
+++ b/setup/src/Magento/Setup/Model/Installer.php
@@ -1262,7 +1262,7 @@ class Installer
     }
 
     /**
-     * Clear var/generation and reset object manager
+     * Clear generated/code and reset object manager
      *
      * @return void
      */
diff --git a/setup/src/Magento/Setup/Module/Di/Code/Reader/Decorator/Interceptions.php b/setup/src/Magento/Setup/Module/Di/Code/Reader/Decorator/Interceptions.php
index 8a415dd65e43f4221abfd90d414dcc44fab617f3..5480a5953ce583fb50b27f6bbcd872acdcfdf0f7 100644
--- a/setup/src/Magento/Setup/Module/Di/Code/Reader/Decorator/Interceptions.php
+++ b/setup/src/Magento/Setup/Module/Di/Code/Reader/Decorator/Interceptions.php
@@ -6,6 +6,7 @@
 namespace Magento\Setup\Module\Di\Code\Reader\Decorator;
 
 use Magento\Setup\Module\Di\Compiler\Log\Log;
+use Magento\Framework\App\Filesystem\DirectoryList;
 
 /**
  * Class Interceptions
@@ -71,7 +72,8 @@ class Interceptions implements \Magento\Setup\Module\Di\Code\Reader\ClassesScann
         $nameList = [];
         foreach ($this->classesScanner->getList($path) as $className) {
             try {
-                if (!strpos($path, 'generation')) { // validate all classes except classes in var/generation dir
+                // validate all classes except classes in generated/code dir
+                if (!strpos($path, DirectoryList::getDefaultConfig()[DirectoryList::GENERATION][DirectoryList::PATH])) {
                     $this->validator->validate($className);
                 }
                 $nameList[] = $className;
diff --git a/setup/src/Magento/Setup/Test/Unit/Module/Di/Code/Reader/InstancesNamesList/DirectoryTest.php b/setup/src/Magento/Setup/Test/Unit/Module/Di/Code/Reader/InstancesNamesList/DirectoryTest.php
index b34322ec9992a650f87ad973f94bb07a27c858fb..0ccc4d9f9b35fe82e3775d2934c27dfecb10c382 100644
--- a/setup/src/Magento/Setup/Test/Unit/Module/Di/Code/Reader/InstancesNamesList/DirectoryTest.php
+++ b/setup/src/Magento/Setup/Test/Unit/Module/Di/Code/Reader/InstancesNamesList/DirectoryTest.php
@@ -66,7 +66,7 @@ class DirectoryTest extends \PHPUnit_Framework_TestCase
             $this->classReaderMock,
             $this->classesScanner,
             $this->validatorMock,
-            '/var/generation'
+            '/generated/code'
         );
     }
 
@@ -111,7 +111,7 @@ class DirectoryTest extends \PHPUnit_Framework_TestCase
 
     public function testGetListNoValidation()
     {
-        $path = '/var/generation';
+        $path = '/generated/code';
 
         $classes = ['NameSpace1\ClassName1', 'NameSpace1\ClassName2'];
 
diff --git a/setup/src/Magento/Setup/Test/Unit/Module/Di/Code/Reader/InstancesNamesList/InterceptionsTest.php b/setup/src/Magento/Setup/Test/Unit/Module/Di/Code/Reader/InstancesNamesList/InterceptionsTest.php
index 0591b11b9628c0117ede3b88201722ed6d86da2a..733ba0b85866e38d24f17e6b2d031e75bab17ce3 100644
--- a/setup/src/Magento/Setup/Test/Unit/Module/Di/Code/Reader/InstancesNamesList/InterceptionsTest.php
+++ b/setup/src/Magento/Setup/Test/Unit/Module/Di/Code/Reader/InstancesNamesList/InterceptionsTest.php
@@ -97,7 +97,7 @@ class InterceptionsTest extends \PHPUnit_Framework_TestCase
 
     public function testGetListNoValidation()
     {
-        $path = '/var/generation';
+        $path = '/generated/code';
 
         $classes = ['NameSpace1\ClassName1', 'NameSpace1\ClassName2'];