Skip to content

Commit

Permalink
Revert "[ VM / dart:isolate ] Added ability to set names for spawned …
Browse files Browse the repository at this point in the history
…isolates."

This reverts commit 5952526.

Reason for revert: causes Flutter test observatory and protocol to deadlock.
Issue: #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>
  • Loading branch information
dcharkes authored and commit-bot@chromium.org committed Mar 15, 2019
1 parent af63353 commit 638f13f
Show file tree
Hide file tree
Showing 18 changed files with 130 additions and 178 deletions.
6 changes: 0 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 0 additions & 3 deletions pkg/dev_compiler/tool/input_sdk/patch/isolate_patch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ class Isolate {
@patch
static Isolate get current => _unsupported();

@patch
String get debugName => _unsupported();

@patch
static Future<Uri> get packageRoot => _unsupported();

Expand Down
62 changes: 41 additions & 21 deletions runtime/bin/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ static Dart_Isolate IsolateSetupHelper(Dart_Isolate isolate,
// 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,
Expand Down Expand Up @@ -423,10 +424,9 @@ static Dart_Isolate CreateAndSetupKernelIsolate(const char* script_uri,
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.
Expand All @@ -443,9 +443,8 @@ static Dart_Isolate CreateAndSetupKernelIsolate(const char* script_uri,
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) {
Expand All @@ -464,6 +463,7 @@ static Dart_Isolate CreateAndSetupKernelIsolate(const char* script_uri,
// 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,
Expand All @@ -480,9 +480,9 @@ static Dart_Isolate CreateAndSetupServiceIsolate(const char* script_uri,
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.

Expand All @@ -493,9 +493,9 @@ static Dart_Isolate CreateAndSetupServiceIsolate(const char* script_uri,
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;
Expand Down Expand Up @@ -529,7 +529,7 @@ static Dart_Isolate CreateAndSetupServiceIsolate(const char* script_uri,
// 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,
Expand Down Expand Up @@ -626,17 +626,17 @@ static Dart_Isolate CreateIsolateAndSetupHelper(bool is_main_isolate,
// 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)
Expand Down Expand Up @@ -677,20 +677,37 @@ static Dart_Isolate CreateIsolateAndSetup(const char* script_uri,
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,
package_root, package_config, flags,
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();

Expand Down Expand Up @@ -801,6 +818,7 @@ bool RunMainIsolate(const char* script_name, CommandLineOptions* dart_options) {
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);

Expand All @@ -810,6 +828,7 @@ bool RunMainIsolate(const char* script_name, CommandLineOptions* dart_options) {
&exit_code);

if (isolate == NULL) {
delete[] isolate_name;
Log::PrintErr("%s\n", error);
free(error);
error = NULL;
Expand All @@ -824,6 +843,7 @@ bool RunMainIsolate(const char* script_name, CommandLineOptions* dart_options) {
Platform::Exit((exit_code != 0) ? exit_code : kErrorExitCode);
}
main_isolate = isolate;
delete[] isolate_name;

Dart_EnterIsolate(isolate);
ASSERT(isolate == Dart_CurrentIsolate());
Expand Down
7 changes: 3 additions & 4 deletions runtime/bin/run_vm_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,9 @@ static Dart_Isolate CreateIsolateAndSetup(const char* script_uri,
&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;
Expand Down
14 changes: 8 additions & 6 deletions runtime/include/dart_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -836,8 +836,9 @@ DART_EXPORT bool Dart_IsVMFlagSet(const char* flag_name);
* 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
Expand All @@ -854,7 +855,7 @@ DART_EXPORT bool Dart_IsVMFlagSet(const char* flag_name);
*/
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,
Expand All @@ -875,8 +876,9 @@ Dart_CreateIsolate(const char* script_uri,
* 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.
Expand All @@ -892,7 +894,7 @@ Dart_CreateIsolate(const char* script_uri,
*/
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,
Expand Down
30 changes: 5 additions & 25 deletions runtime/lib/isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,9 @@ class SpawnIsolateTask : public ThreadPool::Task {

// 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) {
Expand Down Expand Up @@ -185,7 +182,7 @@ static const char* String2UTF8(const String& str) {
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));
Expand All @@ -196,7 +193,6 @@ DEFINE_NATIVE_ENTRY(Isolate_spawnFunction, 0, 11) {
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();
Expand Down Expand Up @@ -227,15 +223,13 @@ DEFINE_NATIVE_ENTRY(Isolate_spawnFunction, 0, 11) {
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;
Expand Down Expand Up @@ -291,7 +285,7 @@ static const char* CanonicalizeUri(Thread* thread,
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));

Expand All @@ -310,8 +304,6 @@ DEFINE_NATIVE_ENTRY(Isolate_spawnUri, 0, 13) {
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(
Expand Down Expand Up @@ -355,15 +347,12 @@ DEFINE_NATIVE_ENTRY(Isolate_spawnUri, 0, 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->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.
Expand All @@ -389,15 +378,6 @@ DEFINE_NATIVE_ENTRY(Isolate_spawnUri, 0, 13) {
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())));
Expand Down
Loading

0 comments on commit 638f13f

Please sign in to comment.