anchor.diff:          cancelOnError: true,
         );
   
  -      // Prepare a temporary directory to store the Dart file that will talk to us.
  +      printTrace('test $ourTestCount: starting shell process${previewDart2? " in preview-dart-2 mode":""}');
  +
  +      // [precompiledDillPath] can be set only if [previewDart2] is [true].
  +      assert(precompiledDillPath == null || previewDart2);
         // If a kernel file is given, then use that to launch the test.
  -      File listenerFile;
  -      if (dillFilePath == null) {
  -        final Directory temporaryDirectory = fs.systemTempDirectory
  -            .createTempSync('dart_test_listener');
  -        finalizers.add(() async {
  -          printTrace('test $ourTestCount: deleting temporary directory');
  -          temporaryDirectory.deleteSync(recursive: true);
  -        });
  -
  -        // Prepare the Dart file that will talk to us and start the test.
  -        listenerFile = fs.file(
  -            '${temporaryDirectory.path}/listener.dart');
  -        listenerFile.createSync();
  -        listenerFile.writeAsStringSync(_generateTestMain(
  -          testUrl: fs.path.toUri(fs.path.absolute(testPath)).toString(),
  -          encodedWebsocketUrl: Uri.encodeComponent(_getWebSocketUrl(server)),
  -        ));
  -      }
  -      // Start the engine subprocess.
  -      printTrace('test $ourTestCount: starting shell process${previewDart2? " in preview-dart-2 mode":""}');
  -
  -      String mainDart = listenerFile?.path ?? testPath;
  -      String bundlePath;
  -
  -      if (previewDart2) {
  -        if (dillFilePath == null) {
  -          final Completer<String> completer = new Completer<String>();
  -          compilerController.add(
  -              new CompilationRequest(listenerFile.path, completer));
  -          mainDart = await completer.future;
  -
  -          if (mainDart == null) {
  -            controller.sink.addError(
  -                _getErrorMessage('Compilation failed', testPath, shellPath));
  -            return null;
  -          }
  -
  -          // bundlePath needs to point to a folder with `platform.dill` file.
  -          final Directory tempBundleDirectory = fs.systemTempDirectory
  -              .createTempSync('flutter_bundle_directory');
  -          finalizers.add(() async {
  -            printTrace(
  -                'test $ourTestCount: deleting temporary bundle directory');
  -            tempBundleDirectory.deleteSync(recursive: true);
  -          });
  -
  -          // copy 'vm_platform_strong.dill' into 'platform.dill'
  -          final File vmPlatformStrongDill = fs.file(
  -            artifacts.getArtifactPath(Artifact.platformKernelDill),
  -          );
  -          final File platformDill = vmPlatformStrongDill.copySync(
  -            tempBundleDirectory
  -                .childFile('platform.dill')
  -                .path,
  -          );
  -          if (!platformDill.existsSync()) {
  -            printError('unexpected error copying platform kernel file');
  -          }
  -
  -          bundlePath = tempBundleDirectory.path;
  -        } else {
  -          mainDart = dillFilePath;
  -          bundlePath = artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath);
  +      // Otherwise create a "listener" dart that invokes actual test.
  +      String mainDart = precompiledDillPath != null
  +          ? precompiledDillPath
  +          : _createListenerDart(finalizers, ourTestCount, testPath, server);
  +
  +      if (previewDart2 && precompiledDillPath == null) {
  +        // Lazily instantiate compiler so it is built only if it is actually used.
  +        compiler ??= new _Compiler();
  +        mainDart = await compiler.compile(mainDart);
  +
  +        if (mainDart == null) {
  +          controller.sink.addError(
  +              _getErrorMessage('Compilation failed', testPath, shellPath));
  +          return null;
           }
         }
   
  
positive.code:       if (explicitObservatoryPort != null)
          throwToolExit('installHook() was called with an observatory port or debugger mode enabled, but then more than one test suite was run.');
        // Fail if we're passing in a precompiled entry-point.
        if (dillFilePath != null)
          throwToolExit('installHook() was called with a precompiled test entry-point, but then more than one test suite was run.');
      }
      final int ourTestCount = _testCount;
  
negative.code: enum _TestResult { crashed, harnessBailed, testBailed }
  typedef Future<Null> _Finalizer();
  
  class _CompilationRequest {
    String path;
    Completer<String> result;
  
    _CompilationRequest(this.path, this.result);
  }
  
  // This class is a wrapper around compiler that allows multiple isolates to
  // enqueue compilation requests, but ensures only one compilation at a time.
  class _Compiler {
    _Compiler() {
      // Compiler maintains and updates single incremental dill file.
      // Incremental compilation requests done for each test copy that file away
      // for independent execution.
      final Directory outputDillDirectory = fs.systemTempDirectory
          .createTempSync('output_dill');
      final File outputDill = outputDillDirectory.childFile('output.dill');
  
      compilerController.stream.listen((_CompilationRequest request) async {
        final bool isEmpty = compilationQueue.isEmpty;
        compilationQueue.add(request);
        // Only trigger processing if queue was empty - i.e. no other requests
        // are currently being processed. This effectively enforces "one
        // compilation request at a time".
        if (isEmpty) {
          while (compilationQueue.isNotEmpty) {
            final _CompilationRequest request = compilationQueue.first;
            printTrace('Compiling ${request.path}');
            final String outputPath = await compiler.recompile(request.path,
              <String>[request.path],
              outputPath: outputDill.path,
            );
            // Copy output dill next to the source file.
            await outputDill.copy(request.path + '.dill');
            compiler.accept();
            compiler.reset();
            request.result.complete(outputPath);
            // Only remove now when we finished processing the element
            compilationQueue.removeAt(0);
          }
        }
      }, onDone: () {
        outputDillDirectory.deleteSync(recursive: true);
      });
  
      compiler = new ResidentCompiler(
          artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath),
          packagesPath: PackageMap.globalPackagesPath);
    }
  
    final StreamController<_CompilationRequest> compilerController =
        new StreamController<_CompilationRequest>();
    final List<_CompilationRequest> compilationQueue = <_CompilationRequest>[];
    ResidentCompiler compiler;
  
    Future<String> compile(String mainDart) {
      final Completer<String> completer = new Completer<String>();
      compilerController.add(new _CompilationRequest(mainDart, completer));
      return completer.future;
    }
  }
  
  class _FlutterPlatform extends PlatformPlugin {
  