Revert "[ VM / dart:isolate ] Added ability to set names for spawned isolates."

This reverts commit 59525264e82f46a1146ffea79748043ca20fe905.

Reason for revert: causes Flutter test observatory and protocol to deadlock.
Issue: https://github.com/dart-lang/sdk/issues/36232

Original change's description:
> [ VM / dart:isolate ] Added ability to set names for spawned isolates.
> 
> Fixes issue #34059
> 
> Change-Id: I315498b02edc184e9e408c93eddb78aa1a5a8a1d
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/90341
> Commit-Queue: Ben Konyi <bkonyi@google.com>
> Reviewed-by: Sigmund Cherem <sigmund@google.com>
> Reviewed-by: Ryan Macnak <rmacnak@google.com>

TBR=bkonyi@google.com,rmacnak@google.com,asiva@google.com,sigmund@google.com

Change-Id: I5f2115a2ac394a8d4c7c175bc97f2b88b65fcb49
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/97107
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 458fe3d..266cce2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,12 +6,6 @@
 
 ### Core library changes
 
-#### `dart:isolate`
-
-* Added `debugName` property to `Isolate`.
-* Added `debugName` optional parameter to `Isolate.spawn` and
-  `Isolate.spawnUri`.
-
 ### Dart VM
 
 * RegExp patterns can now use lookbehind assertions.
diff --git a/pkg/dev_compiler/tool/input_sdk/patch/isolate_patch.dart b/pkg/dev_compiler/tool/input_sdk/patch/isolate_patch.dart
index 9ccdada..999f518 100644
--- a/pkg/dev_compiler/tool/input_sdk/patch/isolate_patch.dart
+++ b/pkg/dev_compiler/tool/input_sdk/patch/isolate_patch.dart
@@ -15,9 +15,6 @@
   static Isolate get current => _unsupported();
 
   @patch
-  String get debugName => _unsupported();
-
-  @patch
   static Future<Uri> get packageRoot => _unsupported();
 
   @patch
diff --git a/runtime/bin/main.cc b/runtime/bin/main.cc
index 15f3382..f572e20 100644
--- a/runtime/bin/main.cc
+++ b/runtime/bin/main.cc
@@ -379,6 +379,7 @@
 // For now we only support the kernel isolate coming up from an
 // application snapshot or from a .dill file.
 static Dart_Isolate CreateAndSetupKernelIsolate(const char* script_uri,
+                                                const char* main,
                                                 const char* package_root,
                                                 const char* packages_config,
                                                 Dart_IsolateFlags* flags,
@@ -423,10 +424,9 @@
     isolate_data =
         new IsolateData(uri, package_root, packages_config, app_snapshot);
     isolate = Dart_CreateIsolate(
-        DART_KERNEL_ISOLATE_NAME, DART_KERNEL_ISOLATE_NAME,
-        isolate_snapshot_data, isolate_snapshot_instructions,
-        app_isolate_shared_data, app_isolate_shared_instructions, flags,
-        isolate_data, error);
+        DART_KERNEL_ISOLATE_NAME, main, isolate_snapshot_data,
+        isolate_snapshot_instructions, app_isolate_shared_data,
+        app_isolate_shared_instructions, flags, isolate_data, error);
   }
   if (isolate == NULL) {
     // Clear error from app snapshot and re-trying from kernel file.
@@ -443,9 +443,8 @@
         const_cast<uint8_t*>(kernel_service_buffer),
         kernel_service_buffer_size);
     isolate = Dart_CreateIsolateFromKernel(
-        DART_KERNEL_ISOLATE_NAME, DART_KERNEL_ISOLATE_NAME,
-        kernel_service_buffer, kernel_service_buffer_size, flags, isolate_data,
-        error);
+        DART_KERNEL_ISOLATE_NAME, main, kernel_service_buffer,
+        kernel_service_buffer_size, flags, isolate_data, error);
   }
 
   if (isolate == NULL) {
@@ -464,6 +463,7 @@
 // For now we only support the service isolate coming up from sources
 // which are compiled by the VM parser.
 static Dart_Isolate CreateAndSetupServiceIsolate(const char* script_uri,
+                                                 const char* main,
                                                  const char* package_root,
                                                  const char* packages_config,
                                                  Dart_IsolateFlags* flags,
@@ -480,9 +480,9 @@
   const uint8_t* isolate_snapshot_instructions =
       app_isolate_snapshot_instructions;
   isolate = Dart_CreateIsolate(
-      script_uri, DART_VM_SERVICE_ISOLATE_NAME, isolate_snapshot_data,
-      isolate_snapshot_instructions, app_isolate_shared_data,
-      app_isolate_shared_instructions, flags, isolate_data, error);
+      script_uri, main, isolate_snapshot_data, isolate_snapshot_instructions,
+      app_isolate_shared_data, app_isolate_shared_instructions, flags,
+      isolate_data, error);
 #else
   // JIT: Service isolate uses the core libraries snapshot.
 
@@ -493,9 +493,9 @@
   const uint8_t* isolate_snapshot_instructions =
       core_isolate_snapshot_instructions;
   isolate = Dart_CreateIsolate(
-      script_uri, DART_VM_SERVICE_ISOLATE_NAME, isolate_snapshot_data,
-      isolate_snapshot_instructions, app_isolate_shared_data,
-      app_isolate_shared_instructions, flags, isolate_data, error);
+      script_uri, NULL, isolate_snapshot_data, isolate_snapshot_instructions,
+      app_isolate_shared_data, app_isolate_shared_instructions, flags,
+      isolate_data, error);
 #endif  // !defined(DART_PRECOMPILED_RUNTIME)
   if (isolate == NULL) {
     delete isolate_data;
@@ -529,7 +529,7 @@
 // Returns newly created Isolate on success, NULL on failure.
 static Dart_Isolate CreateIsolateAndSetupHelper(bool is_main_isolate,
                                                 const char* script_uri,
-                                                const char* name,
+                                                const char* main,
                                                 const char* package_root,
                                                 const char* packages_config,
                                                 Dart_IsolateFlags* flags,
@@ -626,17 +626,17 @@
     // application kernel binary is self contained or an incremental binary.
     // Isolate should be created only if it is a self contained kernel binary.
     isolate = Dart_CreateIsolateFromKernel(
-        script_uri, name, platform_kernel_buffer, platform_kernel_buffer_size,
+        script_uri, main, platform_kernel_buffer, platform_kernel_buffer_size,
         flags, isolate_data, error);
   } else {
     isolate = Dart_CreateIsolate(
-        script_uri, name, isolate_snapshot_data, isolate_snapshot_instructions,
+        script_uri, main, isolate_snapshot_data, isolate_snapshot_instructions,
         app_isolate_shared_data, app_isolate_shared_instructions, flags,
         isolate_data, error);
   }
 #else
   isolate = Dart_CreateIsolate(
-      script_uri, name, isolate_snapshot_data, isolate_snapshot_instructions,
+      script_uri, main, isolate_snapshot_data, isolate_snapshot_instructions,
       app_isolate_shared_data, app_isolate_shared_instructions, flags,
       isolate_data, error);
 #endif  // !defined(DART_PRECOMPILED_RUNTIME)
@@ -677,13 +677,15 @@
   int exit_code = 0;
 #if !defined(EXCLUDE_CFE_AND_KERNEL_PLATFORM)
   if (strcmp(script_uri, DART_KERNEL_ISOLATE_NAME) == 0) {
-    return CreateAndSetupKernelIsolate(script_uri, package_root, package_config,
-                                       flags, error, &exit_code);
+    return CreateAndSetupKernelIsolate(script_uri, main, package_root,
+                                       package_config, flags, error,
+                                       &exit_code);
   }
 #endif  // !defined(EXCLUDE_CFE_AND_KERNEL_PLATFORM)
   if (strcmp(script_uri, DART_VM_SERVICE_ISOLATE_NAME) == 0) {
-    return CreateAndSetupServiceIsolate(
-        script_uri, package_root, package_config, flags, error, &exit_code);
+    return CreateAndSetupServiceIsolate(script_uri, main, package_root,
+                                        package_config, flags, error,
+                                        &exit_code);
   }
   bool is_main_isolate = false;
   return CreateIsolateAndSetupHelper(is_main_isolate, script_uri, main,
@@ -691,6 +693,21 @@
                                      callback_data, error, &exit_code);
 }
 
+char* BuildIsolateName(const char* script_name, const char* func_name) {
+  // Skip past any slashes in the script name.
+  const char* last_slash = strrchr(script_name, '/');
+  if (last_slash != NULL) {
+    script_name = last_slash + 1;
+  }
+
+  const char* kFormat = "%s/%s";
+  intptr_t len = strlen(script_name) + strlen(func_name) + 2;
+  char* buffer = new char[len];
+  ASSERT(buffer != NULL);
+  snprintf(buffer, len, kFormat, script_name, func_name);
+  return buffer;
+}
+
 static void OnIsolateShutdown(void* callback_data) {
   Dart_EnterScope();
 
@@ -801,6 +818,7 @@
   char* error = NULL;
   bool is_main_isolate = true;
   int exit_code = 0;
+  char* isolate_name = BuildIsolateName(script_name, "main");
   Dart_IsolateFlags flags;
   Dart_IsolateFlagsInitialize(&flags);
 
@@ -810,6 +828,7 @@
       &exit_code);
 
   if (isolate == NULL) {
+    delete[] isolate_name;
     Log::PrintErr("%s\n", error);
     free(error);
     error = NULL;
@@ -824,6 +843,7 @@
     Platform::Exit((exit_code != 0) ? exit_code : kErrorExitCode);
   }
   main_isolate = isolate;
+  delete[] isolate_name;
 
   Dart_EnterIsolate(isolate);
   ASSERT(isolate == Dart_CurrentIsolate());
diff --git a/runtime/bin/run_vm_tests.cc b/runtime/bin/run_vm_tests.cc
index 4eb653e..f024c4d 100644
--- a/runtime/bin/run_vm_tests.cc
+++ b/runtime/bin/run_vm_tests.cc
@@ -148,10 +148,9 @@
         &isolate_snapshot_data, &isolate_snapshot_instructions);
     isolate_data = new bin::IsolateData(script_uri, package_root,
                                         packages_config, app_snapshot);
-    isolate =
-        Dart_CreateIsolate(DART_KERNEL_ISOLATE_NAME, DART_KERNEL_ISOLATE_NAME,
-                           isolate_snapshot_data, isolate_snapshot_instructions,
-                           NULL, NULL, flags, isolate_data, error);
+    isolate = Dart_CreateIsolate(
+        DART_KERNEL_ISOLATE_NAME, main, isolate_snapshot_data,
+        isolate_snapshot_instructions, NULL, NULL, flags, isolate_data, error);
     if (*error != NULL) {
       free(*error);
       *error = NULL;
diff --git a/runtime/include/dart_api.h b/runtime/include/dart_api.h
index 51a1f80..1c4c151 100644
--- a/runtime/include/dart_api.h
+++ b/runtime/include/dart_api.h
@@ -836,8 +836,9 @@
  *   The VM will provide this URI to the Dart_IsolateCreateCallback when a child
  *   isolate is created by Isolate.spawn. The embedder should use a URI that
  *   allows it to load the same program into such a child isolate.
- * \param name A short name for the isolate to improve debugging messages.
- *   Typically of the format 'foo.dart:main()'.
+ * \param main The name of the main entry point this isolate will run. Provided
+ *   only for advisory purposes to improve debugging messages. Typically either
+ *   'main' or the name of the function passed to Isolate.spawn.
  * \param isolate_snapshot_data
  * \param isolate_snapshot_instructions Buffers containing a snapshot of the
  *   isolate or NULL if no snapshot is provided. If provided, the buffers must
@@ -854,7 +855,7 @@
  */
 DART_EXPORT Dart_Isolate
 Dart_CreateIsolate(const char* script_uri,
-                   const char* name,
+                   const char* main,
                    const uint8_t* isolate_snapshot_data,
                    const uint8_t* isolate_snapshot_instructions,
                    const uint8_t* shared_data,
@@ -875,8 +876,9 @@
  *   The VM will provide this URI to the Dart_IsolateCreateCallback when a child
  *   isolate is created by Isolate.spawn. The embedder should use a URI that
  *   allows it to load the same program into such a child isolate.
- * \param name A short name for the isolate to improve debugging messages.
- *   Typically of the format 'foo.dart:main()'.
+ * \param main The name of the main entry point this isolate will run. Provided
+ *   only for advisory purposes to improve debugging messages. Typically either
+ *   'main' or the name of the function passed to Isolate.spawn.
  * \param kernel_buffer
  * \param kernel_buffer_size A buffer which contains a kernel/DIL program. Must
  *   remain valid until isolate shutdown.
@@ -892,7 +894,7 @@
  */
 DART_EXPORT Dart_Isolate
 Dart_CreateIsolateFromKernel(const char* script_uri,
-                             const char* name,
+                             const char* main,
                              const uint8_t* kernel_buffer,
                              intptr_t kernel_buffer_size,
                              Dart_IsolateFlags* flags,
diff --git a/runtime/lib/isolate.cc b/runtime/lib/isolate.cc
index d0031d7..b925147 100644
--- a/runtime/lib/isolate.cc
+++ b/runtime/lib/isolate.cc
@@ -130,12 +130,9 @@
 
     // Make a copy of the state's isolate flags and hand it to the callback.
     Dart_IsolateFlags api_flags = *(state_->isolate_flags());
-    const char* name = (state_->debug_name() == NULL) ? state_->function_name()
-                                                      : state_->debug_name();
-    ASSERT(name != NULL);
 
     Isolate* isolate = reinterpret_cast<Isolate*>((callback)(
-        state_->script_url(), name, state_->package_root(),
+        state_->script_url(), state_->function_name(), state_->package_root(),
         state_->package_config(), &api_flags, state_->init_data(), &error));
     state_->DecrementSpawnCount();
     if (isolate == NULL) {
@@ -185,7 +182,7 @@
   return result;
 }
 
-DEFINE_NATIVE_ENTRY(Isolate_spawnFunction, 0, 11) {
+DEFINE_NATIVE_ENTRY(Isolate_spawnFunction, 0, 10) {
   GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0));
   GET_NON_NULL_NATIVE_ARGUMENT(String, script_uri, arguments->NativeArgAt(1));
   GET_NON_NULL_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(2));
@@ -196,7 +193,6 @@
   GET_NATIVE_ARGUMENT(SendPort, onError, arguments->NativeArgAt(7));
   GET_NATIVE_ARGUMENT(String, packageRoot, arguments->NativeArgAt(8));
   GET_NATIVE_ARGUMENT(String, packageConfig, arguments->NativeArgAt(9));
-  GET_NATIVE_ARGUMENT(String, debugName, arguments->NativeArgAt(10));
 
   if (closure.IsClosure()) {
     Function& func = Function::Handle();
@@ -227,15 +223,13 @@
       const char* utf8_package_root = NULL;
       const char* utf8_package_config =
           packageConfig.IsNull() ? NULL : String2UTF8(packageConfig);
-      const char* utf8_debug_name =
-          debugName.IsNull() ? NULL : String2UTF8(debugName);
 
       IsolateSpawnState* state = new IsolateSpawnState(
           port.Id(), isolate->origin_id(), isolate->init_callback_data(),
           String2UTF8(script_uri), func, &message_buffer,
           isolate->spawn_count_monitor(), isolate->spawn_count(),
           utf8_package_root, utf8_package_config, paused.value(), fatal_errors,
-          on_exit_port, on_error_port, utf8_debug_name);
+          on_exit_port, on_error_port);
 
       // Since this is a call to Isolate.spawn, copy the parent isolate's code.
       state->isolate_flags()->copy_parent_code = true;
@@ -291,7 +285,7 @@
   return result;
 }
 
-DEFINE_NATIVE_ENTRY(Isolate_spawnUri, 0, 13) {
+DEFINE_NATIVE_ENTRY(Isolate_spawnUri, 0, 12) {
   GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0));
   GET_NON_NULL_NATIVE_ARGUMENT(String, uri, arguments->NativeArgAt(1));
 
@@ -310,8 +304,6 @@
   GET_NATIVE_ARGUMENT(String, packageRoot, arguments->NativeArgAt(10));
   GET_NATIVE_ARGUMENT(String, packageConfig, arguments->NativeArgAt(11));
 
-  GET_NATIVE_ARGUMENT(String, debugName, arguments->NativeArgAt(12));
-
   if (Dart::vm_snapshot_kind() == Snapshot::kFullAOT) {
     const Array& args = Array::Handle(Array::New(1));
     args.SetAt(
@@ -355,15 +347,12 @@
   const char* utf8_package_root = NULL;
   const char* utf8_package_config =
       packageConfig.IsNull() ? NULL : String2UTF8(packageConfig);
-  const char* utf8_debug_name =
-      debugName.IsNull() ? NULL : String2UTF8(debugName);
 
   IsolateSpawnState* state = new IsolateSpawnState(
       port.Id(), isolate->init_callback_data(), canonical_uri,
       utf8_package_root, utf8_package_config, &arguments_buffer,
       &message_buffer, isolate->spawn_count_monitor(), isolate->spawn_count(),
-      paused.value(), fatal_errors, on_exit_port, on_error_port,
-      utf8_debug_name);
+      paused.value(), fatal_errors, on_exit_port, on_error_port);
 
   // If we were passed a value then override the default flags state for
   // checked mode.
@@ -389,15 +378,6 @@
   return Object::null();
 }
 
-DEFINE_NATIVE_ENTRY(Isolate_getDebugName, 0, 1) {
-  GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0));
-  Isolate* isolate_lookup = Isolate::LookupIsolateByPort(port.Id());
-  if (isolate_lookup == NULL) {
-    return Object::null();
-  }
-  return String::New(isolate_lookup->name());
-}
-
 DEFINE_NATIVE_ENTRY(Isolate_getPortAndCapabilitiesOfCurrentIsolate, 0, 0) {
   const Array& result = Array::Handle(Array::New(3));
   result.SetAt(0, SendPort::Handle(SendPort::New(isolate->main_port())));
diff --git a/runtime/lib/isolate_patch.dart b/runtime/lib/isolate_patch.dart
index cdd5394..5e5c235 100644
--- a/runtime/lib/isolate_patch.dart
+++ b/runtime/lib/isolate_patch.dart
@@ -316,9 +316,6 @@
   static Isolate get current => _currentIsolate;
 
   @patch
-  String get debugName => _getDebugName(controlPort);
-
-  @patch
   static Future<Uri> get packageRoot {
     var hook = VMLibraryHooks.packageRootUriFuture;
     if (hook == null) {
@@ -355,8 +352,7 @@
       {bool paused: false,
       bool errorsAreFatal,
       SendPort onExit,
-      SendPort onError,
-      String debugName}) async {
+      SendPort onError}) async {
     // `paused` isn't handled yet.
     RawReceivePort readyPort;
     try {
@@ -381,18 +377,8 @@
         script = await Isolate.resolvePackageUri(script);
       }
 
-      _spawnFunction(
-          readyPort.sendPort,
-          script.toString(),
-          entryPoint,
-          message,
-          paused,
-          errorsAreFatal,
-          onExit,
-          onError,
-          null,
-          packageConfig,
-          debugName);
+      _spawnFunction(readyPort.sendPort, script.toString(), entryPoint, message,
+          paused, errorsAreFatal, onExit, onError, null, packageConfig);
       return await _spawnCommon(readyPort);
     } catch (e, st) {
       if (readyPort != null) {
@@ -412,8 +398,7 @@
       Map<String, String> environment,
       Uri packageRoot,
       Uri packageConfig,
-      bool automaticPackageResolution: false,
-      String debugName}) async {
+      bool automaticPackageResolution: false}) async {
     RawReceivePort readyPort;
     if (environment != null) {
       throw new UnimplementedError("environment");
@@ -482,8 +467,7 @@
           null,
           /* environment */
           packageRootString,
-          packageConfigString,
-          debugName);
+          packageConfigString);
       return await _spawnCommon(readyPort);
     } catch (e) {
       if (readyPort != null) {
@@ -540,8 +524,7 @@
       SendPort onExit,
       SendPort onError,
       String packageRoot,
-      String packageConfig,
-      String debugName) native "Isolate_spawnFunction";
+      String packageConfig) native "Isolate_spawnFunction";
 
   static void _spawnUri(
       SendPort readyPort,
@@ -555,14 +538,10 @@
       bool checked,
       List environment,
       String packageRoot,
-      String packageConfig,
-      String debugName) native "Isolate_spawnUri";
+      String packageConfig) native "Isolate_spawnUri";
 
   static void _sendOOB(port, msg) native "Isolate_sendOOB";
 
-  static String _getDebugName(SendPort controlPort)
-      native "Isolate_getDebugName";
-
   @patch
   void _pause(Capability resumeCapability) {
     var msg = new List(4)
diff --git a/runtime/observatory/tests/service/dev_fs_spawn_test.dart b/runtime/observatory/tests/service/dev_fs_spawn_test.dart
index 1221a58..c0a182e 100644
--- a/runtime/observatory/tests/service/dev_fs_spawn_test.dart
+++ b/runtime/observatory/tests/service/dev_fs_spawn_test.dart
@@ -118,7 +118,7 @@
       if (event.kind == ServiceEvent.kIsolateSpawn) {
         expect(event.spawnToken, equals('mySpawnToken0'));
         expect(event.isolate, isNotNull);
-        expect(event.isolate.name, equals('main'));
+        expect(event.isolate.name, equals('devfs_file0.dart:main()'));
         completer.complete(event.isolate);
         sub.cancel();
       }
@@ -147,7 +147,7 @@
       if (event.kind == ServiceEvent.kIsolateSpawn) {
         expect(event.spawnToken, equals('mySpawnToken1'));
         expect(event.isolate, isNotNull);
-        expect(event.isolate.name, equals('main'));
+        expect(event.isolate.name, equals('devfs_file1.dart:main()'));
         completer.complete(event.isolate);
         sub.cancel();
       }
@@ -177,7 +177,7 @@
       if (event.kind == ServiceEvent.kIsolateSpawn) {
         expect(event.spawnToken, equals('mySpawnToken2'));
         expect(event.isolate, isNotNull);
-        expect(event.isolate.name, equals('main'));
+        expect(event.isolate.name, equals('devfs_file2.dart:main()'));
         completer.complete(event.isolate);
         sub.cancel();
       }
diff --git a/runtime/observatory/tests/service/set_name_rpc_test.dart b/runtime/observatory/tests/service/set_name_rpc_test.dart
index 186e4e0..1d743cc 100644
--- a/runtime/observatory/tests/service/set_name_rpc_test.dart
+++ b/runtime/observatory/tests/service/set_name_rpc_test.dart
@@ -10,7 +10,11 @@
 
 var tests = <IsolateTest>[
   (Isolate isolate) async {
-    expect(isolate.name == 'main', isTrue);
+    expect(
+        ((isolate.name == 'set_name_rpc_test.dart:main()') ||
+            (isolate.name == 'out.jitsnapshot:main()')),
+        isTrue);
+
     Completer completer = new Completer();
     var stream = await isolate.vm.getEventStream(VM.kIsolateStream);
     var subscription;
diff --git a/runtime/vm/bootstrap_natives.h b/runtime/vm/bootstrap_natives.h
index bedb991..194a86c 100644
--- a/runtime/vm/bootstrap_natives.h
+++ b/runtime/vm/bootstrap_natives.h
@@ -294,12 +294,11 @@
   V(Int32x4_setFlagZ, 2)                                                       \
   V(Int32x4_setFlagW, 2)                                                       \
   V(Int32x4_select, 3)                                                         \
-  V(Isolate_spawnFunction, 11)                                                 \
-  V(Isolate_spawnUri, 13)                                                      \
+  V(Isolate_spawnFunction, 10)                                                 \
+  V(Isolate_spawnUri, 12)                                                      \
   V(Isolate_getPortAndCapabilitiesOfCurrentIsolate, 0)                         \
   V(Isolate_getCurrentRootUriStr, 0)                                           \
   V(Isolate_sendOOB, 2)                                                        \
-  V(Isolate_getDebugName, 1)                                                   \
   V(GrowableList_allocate, 2)                                                  \
   V(GrowableList_getIndexed, 2)                                                \
   V(GrowableList_setIndexed, 3)                                                \
diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc
index f407d71..0939522 100644
--- a/runtime/vm/dart_api_impl.cc
+++ b/runtime/vm/dart_api_impl.cc
@@ -1075,8 +1075,43 @@
 
 // --- Isolates ---
 
+static char* BuildIsolateName(const char* script_uri, const char* main) {
+  if (script_uri == NULL) {
+    // Just use the main as the name.
+    if (main == NULL) {
+      return strdup("isolate");
+    } else {
+      return strdup(main);
+    }
+  }
+
+  if (ServiceIsolate::NameEquals(script_uri) ||
+      (strcmp(script_uri, DART_KERNEL_ISOLATE_NAME) == 0)) {
+    return strdup(script_uri);
+  }
+
+  // Skip past any slashes and backslashes in the script uri.
+  const char* last_slash = strrchr(script_uri, '/');
+  if (last_slash != NULL) {
+    script_uri = last_slash + 1;
+  }
+  const char* last_backslash = strrchr(script_uri, '\\');
+  if (last_backslash != NULL) {
+    script_uri = last_backslash + 1;
+  }
+  if (main == NULL) {
+    main = "main";
+  }
+
+  char* chars = NULL;
+  intptr_t len = Utils::SNPrint(NULL, 0, "%s:%s()", script_uri, main) + 1;
+  chars = reinterpret_cast<char*>(malloc(len));
+  Utils::SNPrint(chars, len, "%s:%s()", script_uri, main);
+  return chars;
+}
+
 static Dart_Isolate CreateIsolate(const char* script_uri,
-                                  const char* name,
+                                  const char* main,
                                   const uint8_t* snapshot_data,
                                   const uint8_t* snapshot_instructions,
                                   const uint8_t* shared_data,
@@ -1087,6 +1122,7 @@
                                   void* callback_data,
                                   char** error) {
   CHECK_NO_ISOLATE(Isolate::Current());
+  char* isolate_name = BuildIsolateName(script_uri, main);
 
   // Setup default flags in case none were passed.
   Dart_IsolateFlags api_flags;
@@ -1094,7 +1130,8 @@
     Isolate::FlagsInitialize(&api_flags);
     flags = &api_flags;
   }
-  Isolate* I = Dart::CreateIsolate((name == NULL) ? "isolate" : name, *flags);
+  Isolate* I = Dart::CreateIsolate(isolate_name, *flags);
+  free(isolate_name);
   if (I == NULL) {
     if (error != NULL) {
       *error = strdup("Isolate creation failed");
@@ -1149,7 +1186,7 @@
 
 DART_EXPORT Dart_Isolate
 Dart_CreateIsolate(const char* script_uri,
-                   const char* name,
+                   const char* main,
                    const uint8_t* snapshot_data,
                    const uint8_t* snapshot_instructions,
                    const uint8_t* shared_data,
@@ -1158,21 +1195,21 @@
                    void* callback_data,
                    char** error) {
   API_TIMELINE_DURATION(Thread::Current());
-  return CreateIsolate(script_uri, name, snapshot_data, snapshot_instructions,
+  return CreateIsolate(script_uri, main, snapshot_data, snapshot_instructions,
                        shared_data, shared_instructions, NULL, 0, flags,
                        callback_data, error);
 }
 
 DART_EXPORT Dart_Isolate
 Dart_CreateIsolateFromKernel(const char* script_uri,
-                             const char* name,
+                             const char* main,
                              const uint8_t* kernel_buffer,
                              intptr_t kernel_buffer_size,
                              Dart_IsolateFlags* flags,
                              void* callback_data,
                              char** error) {
   API_TIMELINE_DURATION(Thread::Current());
-  return CreateIsolate(script_uri, name, NULL, NULL, NULL, NULL, kernel_buffer,
+  return CreateIsolate(script_uri, main, NULL, NULL, NULL, NULL, kernel_buffer,
                        kernel_buffer_size, flags, callback_data, error);
 }
 
diff --git a/runtime/vm/isolate.cc b/runtime/vm/isolate.cc
index a72736e..ce8ed3f 100644
--- a/runtime/vm/isolate.cc
+++ b/runtime/vm/isolate.cc
@@ -2641,18 +2641,6 @@
   return count;
 }
 
-Isolate* Isolate::LookupIsolateByPort(Dart_Port port) {
-  MonitorLocker ml(isolates_list_monitor_);
-  Isolate* current = isolates_list_head_;
-  while (current != NULL) {
-    if (current->main_port() == port) {
-      return current;
-    }
-    current = current->next_;
-  }
-  return NULL;
-}
-
 bool Isolate::AddIsolateToList(Isolate* isolate) {
   MonitorLocker ml(isolates_list_monitor_);
   if (!creation_enabled_) {
@@ -2938,8 +2926,7 @@
                                      bool paused,
                                      bool errors_are_fatal,
                                      Dart_Port on_exit_port,
-                                     Dart_Port on_error_port,
-                                     const char* debug_name)
+                                     Dart_Port on_error_port)
     : isolate_(NULL),
       parent_port_(parent_port),
       origin_id_(origin_id),
@@ -2952,7 +2939,6 @@
       library_url_(NULL),
       class_name_(NULL),
       function_name_(NULL),
-      debug_name_(debug_name),
       serialized_args_(NULL),
       serialized_message_(message_buffer->StealMessage()),
       spawn_count_monitor_(spawn_count_monitor),
@@ -2989,8 +2975,7 @@
                                      bool paused,
                                      bool errors_are_fatal,
                                      Dart_Port on_exit_port,
-                                     Dart_Port on_error_port,
-                                     const char* debug_name)
+                                     Dart_Port on_error_port)
     : isolate_(NULL),
       parent_port_(parent_port),
       origin_id_(ILLEGAL_PORT),
@@ -3003,7 +2988,6 @@
       library_url_(NULL),
       class_name_(NULL),
       function_name_(NULL),
-      debug_name_(debug_name),
       serialized_args_(args_buffer->StealMessage()),
       serialized_message_(message_buffer->StealMessage()),
       spawn_count_monitor_(spawn_count_monitor),
@@ -3025,7 +3009,6 @@
   delete[] library_url_;
   delete[] class_name_;
   delete[] function_name_;
-  delete[] debug_name_;
   delete serialized_args_;
   delete serialized_message_;
 }
diff --git a/runtime/vm/isolate.h b/runtime/vm/isolate.h
index c4dd373..40f0c6f 100644
--- a/runtime/vm/isolate.h
+++ b/runtime/vm/isolate.h
@@ -772,10 +772,6 @@
   static void KillAllIsolates(LibMsgId msg_id);
   static void KillIfExists(Isolate* isolate, LibMsgId msg_id);
 
-  // Lookup an isolate by its main port. Returns NULL if no matching isolate is
-  // found.
-  static Isolate* LookupIsolateByPort(Dart_Port port);
-
   static void DisableIsolateCreation();
   static void EnableIsolateCreation();
   static bool IsolateCreationEnabled();
@@ -1124,8 +1120,7 @@
                     bool paused,
                     bool errorsAreFatal,
                     Dart_Port onExit,
-                    Dart_Port onError,
-                    const char* debug_name);
+                    Dart_Port onError);
   IsolateSpawnState(Dart_Port parent_port,
                     void* init_data,
                     const char* script_url,
@@ -1138,8 +1133,7 @@
                     bool paused,
                     bool errorsAreFatal,
                     Dart_Port onExit,
-                    Dart_Port onError,
-                    const char* debug_name);
+                    Dart_Port onError);
   ~IsolateSpawnState();
 
   Isolate* isolate() const { return isolate_; }
@@ -1156,7 +1150,6 @@
   const char* library_url() const { return library_url_; }
   const char* class_name() const { return class_name_; }
   const char* function_name() const { return function_name_; }
-  const char* debug_name() const { return debug_name_; }
   bool is_spawn_uri() const { return library_url_ == NULL; }
   bool paused() const { return paused_; }
   bool errors_are_fatal() const { return errors_are_fatal_; }
@@ -1181,7 +1174,6 @@
   const char* library_url_;
   const char* class_name_;
   const char* function_name_;
-  const char* debug_name_;
   Message* serialized_args_;
   Message* serialized_message_;
 
diff --git a/runtime/vm/kernel_isolate.cc b/runtime/vm/kernel_isolate.cc
index 79fb581..ab90491 100644
--- a/runtime/vm/kernel_isolate.cc
+++ b/runtime/vm/kernel_isolate.cc
@@ -98,9 +98,8 @@
     api_flags.use_osr = true;
 #endif
 
-    isolate = reinterpret_cast<Isolate*>(
-        create_callback(KernelIsolate::kName, KernelIsolate::kName, NULL, NULL,
-                        &api_flags, NULL, &error));
+    isolate = reinterpret_cast<Isolate*>(create_callback(
+        KernelIsolate::kName, NULL, NULL, NULL, &api_flags, NULL, &error));
     if (isolate == NULL) {
       if (FLAG_trace_kernel) {
         OS::PrintErr(DART_KERNEL_ISOLATE_NAME ": Isolate creation error: %s\n",
diff --git a/sdk/lib/_internal/js_runtime/lib/isolate_patch.dart b/sdk/lib/_internal/js_runtime/lib/isolate_patch.dart
index 56bab4c..78cbf61 100644
--- a/sdk/lib/_internal/js_runtime/lib/isolate_patch.dart
+++ b/sdk/lib/_internal/js_runtime/lib/isolate_patch.dart
@@ -16,11 +16,6 @@
   }
 
   @patch
-  String get debugName {
-    throw new UnsupportedError("Isolate.debugName");
-  }
-
-  @patch
   static Future<Uri> get packageRoot {
     throw new UnsupportedError("Isolate.packageRoot");
   }
diff --git a/sdk/lib/isolate/isolate.dart b/sdk/lib/isolate/isolate.dart
index 5c5883d..6a737fe 100644
--- a/sdk/lib/isolate/isolate.dart
+++ b/sdk/lib/isolate/isolate.dart
@@ -112,20 +112,6 @@
   final Capability terminateCapability;
 
   /**
-   * The name of the [Isolate] displayed for debug purposes.
-   *
-   * This can be set using the `debugName` parameter in [spawn] and [spawnUri].
-   *
-   * This name does not uniquely identify an isolate. Multiple isolates in the
-   * same process may have the same `debugName`.
-   *
-   * For a given isolate, this value will be the same as the values returned by
-   * `Dart_DebugName` in the C embedding API and the `debugName` property in
-   * [IsolateMirror].
-   */
-  external String get debugName;
-
-  /**
    * Create a new [Isolate] object with a restricted set of capabilities.
    *
    * The port should be a control port for an isolate, as taken from
@@ -229,9 +215,6 @@
    * corresponding parameter and was processed before the isolate starts
    * running.
    *
-   * If [debugName] is provided, the spawned [Isolate] will be identifiable by
-   * this name in debuggers and logging.
-   *
    * If [errorsAreFatal] is omitted, the platform may choose a default behavior
    * or inherit the current isolate's behavior.
    *
@@ -248,8 +231,7 @@
       {bool paused: false,
       bool errorsAreFatal,
       SendPort onExit,
-      SendPort onError,
-      String debugName});
+      SendPort onError});
 
   /**
    * Creates and spawns an isolate that runs the code from the library with
@@ -317,9 +299,6 @@
    * WARNING: The [environment] parameter is not implemented on all
    * platforms yet.
    *
-   * If [debugName] is provided, the spawned [Isolate] will be identifiable by
-   * this name in debuggers and logging.
-   *
    * Returns a future that will complete with an [Isolate] instance if the
    * spawning succeeded. It will complete with an error otherwise.
    */
@@ -336,8 +315,7 @@
       @Deprecated('The packages/ dir is not supported in Dart 2')
           Uri packageRoot,
       Uri packageConfig,
-      bool automaticPackageResolution: false,
-      String debugName});
+      bool automaticPackageResolution: false});
 
   /**
    * Requests the isolate to pause.
diff --git a/tests/lib_2/isolate/spawn_function_test.dart b/tests/lib_2/isolate/spawn_function_test.dart
index 7a2a193..eba1bfa 100644
--- a/tests/lib_2/isolate/spawn_function_test.dart
+++ b/tests/lib_2/isolate/spawn_function_test.dart
@@ -17,15 +17,12 @@
 
 void main([args, port]) {
   if (testRemote(main, port)) return;
-  test('message - reply chain', () async {
+  test('message - reply chain', () {
     ReceivePort port = new ReceivePort();
+    Isolate.spawn(child, ['hi', port.sendPort]);
     port.listen(expectAsync((msg) {
       port.close();
       expect(msg, equals('re: hi'));
     }));
-    const String debugName = 'spawnedIsolate';
-    final i =
-        await Isolate.spawn(child, ['hi', port.sendPort], debugName: debugName);
-    expect(i.debugName, debugName);
   });
 }
diff --git a/tests/lib_2/isolate/spawn_uri_test.dart b/tests/lib_2/isolate/spawn_uri_test.dart
index a4d89c3..650bafa 100644
--- a/tests/lib_2/isolate/spawn_uri_test.dart
+++ b/tests/lib_2/isolate/spawn_uri_test.dart
@@ -12,17 +12,14 @@
 import 'package:expect/async_minitest.dart';
 
 main() {
-  test('isolate fromUri - send and reply', () async {
+  test('isolate fromUri - send and reply', () {
     ReceivePort port = new ReceivePort();
     port.listen(expectAsync((msg) {
       expect(msg, equals('re: hi'));
       port.close();
     }));
 
-    const String debugName = 'spawnedIsolate';
-    final i = await Isolate.spawnUri(
-        Uri.parse('spawn_uri_child_isolate.dart'), ['hi'], port.sendPort,
-        debugName: debugName);
-    expect(i.debugName, debugName);
+    Isolate.spawnUri(
+        Uri.parse('spawn_uri_child_isolate.dart'), ['hi'], port.sendPort);
   });
 }