Skip to content

Commit b2171f1

Browse files
mkustermanncommit-bot@chromium.org
authored and
commit-bot@chromium.org
committed
Revert "[vm/concurrency] Introduce concept of Isolate Groups"
This reverts commit b75057b. Reason for revert: Caused some failures on app-jit builders Original change's description: > [vm/concurrency] Introduce concept of Isolate Groups > > An Isolate Group (IG) is a collection of isolates which were spawned from the > same source. This allows the VM to: > > * have a guarantee that all isolates within one IG can safely exchange > structured objects (currently we rely on embedder for this > guarantee) > > * hot-reload all isolates together (currently we only reload one > isolate, leaving same-source isolates in inconsistent state) > > * make a shared heap for all isolates from the same IG, which paves > the way for faster communication and sharing of immutable objects. > > All isolates within one IG will share the same IsolateGroupSource. > > **Embedder changes** > > This change makes breaking embedder API changes to support this new > concept of Isolate Groups: The existing isolate lifecycle callbacks > given to Dart_Initialize will become Isolate Group lifecycle callbacks. > A new callback `initialize_isolate` callback will be added which can > initialize a new isolate within an existing IG. > > Existing embedders can be updated by performing the following renames > > Dart_CreateIsolate -> Dart_CreateIsolateGroup > Dart_IsolateCreateCallback -> Dart_IsolateGroupCreateCallback > Dart_IsolateCleanupCallback -> Dart_IsolateGroupShutdownCallback > Dart_CreateIsolateFromKernel -> Dart_CreateIsolateGroupFromKernel > Dart_CurrentIsolateData -> Dart_CurrentIsolateGroupData > Dart_IsolateData -> Dart_IsolateGroupData > Dart_GetNativeIsolateData -> Dart_GetNativeIsolateGroupData > Dart_InitializeParams.create -> Dart_InitializeParams.create_group > Dart_InitializeParams.cleanup -> Dart_InitializeParams.shutdown_group > Dart_InitializeParams.shutdown -> Dart_InitializeParams.shutdown_isolate > > By default `Isolate.spawn` will cause the creation of a new IG. > > Though an embedder can opt-into supporting multiple isolates within one IG by > providing a callback to the newly added `Dart_InitializeParams.initialize_isolate`. > The responsibility of this new callback is to initialize an existing > isolate (which was setup by re-using source code from the spawning > isolate - i.e. the one which used `Isolate.spawn`) by setting native > resolvers, initializing global state, etc. > > Issue #36648 > Issue #36097 > > Change-Id: I82437ac017ca33018d45e02f353b0672db155f6a > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/105241 > Commit-Queue: Martin Kustermann <kustermann@google.com> > Reviewed-by: Ryan Macnak <rmacnak@google.com> > Reviewed-by: Alexander Aprelev <aam@google.com> TBR=kustermann@google.com,aam@google.com,rmacnak@google.com Change-Id: Ibd90992a01d61188f27b445c21532e0c46f996ea No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107405 Reviewed-by: Martin Kustermann <kustermann@google.com> Commit-Queue: Martin Kustermann <kustermann@google.com>
1 parent 8ff506b commit b2171f1

27 files changed

+459
-1122
lines changed

runtime/bin/dart_embedder_api_impl.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ Dart_Isolate CreateKernelServiceIsolate(const IsolateCreationData& data,
4545
const uint8_t* buffer,
4646
intptr_t buffer_size,
4747
char** error) {
48-
Dart_Isolate kernel_isolate = Dart_CreateIsolateGroupFromKernel(
48+
Dart_Isolate kernel_isolate = Dart_CreateIsolateFromKernel(
4949
data.script_uri, data.main, buffer, buffer_size, data.flags,
50-
data.isolate_group_data, data.isolate_data, error);
50+
data.callback_data, error);
5151
if (kernel_isolate == nullptr) {
5252
return nullptr;
5353
}
@@ -78,9 +78,9 @@ Dart_Isolate CreateVmServiceIsolate(const IsolateCreationData& data,
7878
}
7979
data.flags->load_vmservice_library = true;
8080

81-
Dart_Isolate service_isolate = Dart_CreateIsolateGroupFromKernel(
81+
Dart_Isolate service_isolate = Dart_CreateIsolateFromKernel(
8282
data.script_uri, data.main, kernel_buffer, kernel_buffer_size, data.flags,
83-
data.isolate_group_data, data.isolate_data, error);
83+
data.callback_data, error);
8484
if (service_isolate == nullptr) {
8585
return nullptr;
8686
}

runtime/bin/gen_snapshot.cc

+11-12
Original file line numberDiff line numberDiff line change
@@ -745,24 +745,23 @@ static int CreateIsolateAndSnapshot(const CommandLineOptions& inputs) {
745745
isolate_flags.entry_points = no_entry_points;
746746
}
747747

748-
auto isolate_group_data = new IsolateGroupData(NULL, NULL, NULL, NULL);
748+
IsolateData* isolate_data = new IsolateData(NULL, NULL, NULL, NULL);
749749
Dart_Isolate isolate;
750750
char* error = NULL;
751751
if (isolate_snapshot_data == NULL) {
752752
// We need to capture the vmservice library in the core snapshot, so load it
753753
// in the main isolate as well.
754754
isolate_flags.load_vmservice_library = true;
755-
isolate = Dart_CreateIsolateGroupFromKernel(
756-
NULL, NULL, kernel_buffer, kernel_buffer_size, &isolate_flags,
757-
isolate_group_data, /*isolate_data=*/nullptr, &error);
755+
isolate = Dart_CreateIsolateFromKernel(NULL, NULL, kernel_buffer,
756+
kernel_buffer_size, &isolate_flags,
757+
isolate_data, &error);
758758
} else {
759-
isolate = Dart_CreateIsolateGroup(NULL, NULL, isolate_snapshot_data,
760-
isolate_snapshot_instructions, NULL, NULL,
761-
&isolate_flags, isolate_group_data,
762-
/*isolate_data=*/nullptr, &error);
759+
isolate = Dart_CreateIsolate(NULL, NULL, isolate_snapshot_data,
760+
isolate_snapshot_instructions, NULL, NULL,
761+
&isolate_flags, isolate_data, &error);
763762
}
764763
if (isolate == NULL) {
765-
delete isolate_group_data;
764+
delete isolate_data;
766765
Syslog::PrintErr("%s\n", error);
767766
free(error);
768767
return kErrorExitCode;
@@ -784,9 +783,9 @@ static int CreateIsolateAndSnapshot(const CommandLineOptions& inputs) {
784783
// If the input dill file does not have a root library, then
785784
// Dart_LoadScript will error.
786785
//
787-
// TODO(kernel): Dart_CreateIsolateGroupFromKernel should respect the root
788-
// library in the kernel file, though this requires auditing the other
789-
// loading paths in the embedders that had to work around this.
786+
// TODO(kernel): Dart_CreateIsolateFromKernel should respect the root library
787+
// in the kernel file, though this requires auditing the other loading paths
788+
// in the embedders that had to work around this.
790789
result = Dart_SetRootLibrary(
791790
Dart_LoadLibraryFromKernel(kernel_buffer, kernel_buffer_size));
792791
CHECK_RESULT(result);

runtime/bin/isolate_data.cc

+8-5
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
namespace dart {
1010
namespace bin {
1111

12-
IsolateGroupData::IsolateGroupData(const char* url,
13-
const char* package_root,
14-
const char* packages_file,
15-
AppSnapshot* app_snapshot)
12+
IsolateData::IsolateData(const char* url,
13+
const char* package_root,
14+
const char* packages_file,
15+
AppSnapshot* app_snapshot)
1616
: script_url((url != NULL) ? strdup(url) : NULL),
1717
package_root(NULL),
1818
packages_file(NULL),
@@ -30,7 +30,10 @@ IsolateGroupData::IsolateGroupData(const char* url,
3030
}
3131
}
3232

33-
IsolateGroupData::~IsolateGroupData() {
33+
void IsolateData::OnIsolateShutdown() {
34+
}
35+
36+
IsolateData::~IsolateData() {
3437
free(script_url);
3538
script_url = NULL;
3639
free(package_root);

runtime/bin/isolate_data.h

+14-14
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ class Loader;
3131
// Data associated with every isolate in the standalone VM
3232
// embedding. This is used to free external resources for each isolate
3333
// when the isolate shuts down.
34-
class IsolateGroupData {
34+
class IsolateData {
3535
public:
36-
IsolateGroupData(const char* url,
37-
const char* package_root,
38-
const char* packages_file,
39-
AppSnapshot* app_snapshot);
40-
~IsolateGroupData();
36+
IsolateData(const char* url,
37+
const char* package_root,
38+
const char* packages_file,
39+
AppSnapshot* app_snapshot);
40+
~IsolateData();
4141

4242
char* script_url;
4343
char* package_root;
@@ -49,26 +49,26 @@ class IsolateGroupData {
4949

5050
intptr_t kernel_buffer_size() const { return kernel_buffer_size_; }
5151

52-
// Associate the given kernel buffer with this IsolateGroupData without
53-
// giving it ownership of the buffer.
52+
// Associate the given kernel buffer with this IsolateData without giving it
53+
// ownership of the buffer.
5454
void SetKernelBufferUnowned(uint8_t* buffer, intptr_t size) {
5555
ASSERT(kernel_buffer_.get() == NULL);
5656
kernel_buffer_ = std::shared_ptr<uint8_t>(buffer, FreeUnownedKernelBuffer);
5757
kernel_buffer_size_ = size;
5858
}
5959

60-
// Associate the given kernel buffer with this IsolateGroupData and give it
61-
// ownership of the buffer. This IsolateGroupData is the first one to own the
60+
// Associate the given kernel buffer with this IsolateData and give it
61+
// ownership of the buffer. This IsolateData is the first one to own the
6262
// buffer.
6363
void SetKernelBufferNewlyOwned(uint8_t* buffer, intptr_t size) {
6464
ASSERT(kernel_buffer_.get() == NULL);
6565
kernel_buffer_ = std::shared_ptr<uint8_t>(buffer, free);
6666
kernel_buffer_size_ = size;
6767
}
6868

69-
// Associate the given kernel buffer with this IsolateGroupData and give it
69+
// Associate the given kernel buffer with this IsolateData and give it
7070
// ownership of the buffer. The buffer is already owned by another
71-
// IsolateGroupData.
71+
// IsolateData.
7272
void SetKernelBufferAlreadyOwned(std::shared_ptr<uint8_t> buffer,
7373
intptr_t size) {
7474
ASSERT(kernel_buffer_.get() == NULL);
@@ -111,7 +111,7 @@ class IsolateGroupData {
111111
dependencies_ = deps;
112112
}
113113

114-
bool RunFromAppSnapshot() const { return app_snapshot_ != nullptr; }
114+
void OnIsolateShutdown();
115115

116116
private:
117117
Loader* loader_;
@@ -123,7 +123,7 @@ class IsolateGroupData {
123123

124124
static void FreeUnownedKernelBuffer(uint8_t*) {}
125125

126-
DISALLOW_COPY_AND_ASSIGN(IsolateGroupData);
126+
DISALLOW_COPY_AND_ASSIGN(IsolateData);
127127
};
128128

129129
} // namespace bin

runtime/bin/loader.cc

+40-43
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ extern DFE dfe;
2929
static const intptr_t _Dart_kImportExtension = 9;
3030
static const intptr_t _Dart_kResolveAsFilePath = 10;
3131

32-
Loader::Loader(IsolateGroupData* isolate_group_data)
32+
Loader::Loader(IsolateData* isolate_data)
3333
: port_(ILLEGAL_PORT),
34-
isolate_group_data_(isolate_group_data),
34+
isolate_data_(isolate_data),
3535
error_(Dart_Null()),
3636
monitor_(),
3737
pending_operations_(0),
@@ -40,10 +40,10 @@ Loader::Loader(IsolateGroupData* isolate_group_data)
4040
results_capacity_(0),
4141
payload_(NULL),
4242
payload_length_(0) {
43-
ASSERT(isolate_group_data_ != NULL);
43+
ASSERT(isolate_data_ != NULL);
4444
port_ = Dart_NewNativePort("Loader", Loader::NativeMessageHandler, false);
45-
isolate_group_data_->set_loader(this);
46-
AddLoader(port_, isolate_group_data_);
45+
isolate_data_->set_loader(this);
46+
AddLoader(port_, isolate_data_);
4747
}
4848

4949
Loader::~Loader() {
@@ -55,8 +55,8 @@ Loader::~Loader() {
5555
monitor_.Exit();
5656
RemoveLoader(port_);
5757
port_ = ILLEGAL_PORT;
58-
isolate_group_data_->set_loader(NULL);
59-
isolate_group_data_ = NULL;
58+
isolate_data_->set_loader(NULL);
59+
isolate_data_ = NULL;
6060
for (intptr_t i = 0; i < results_length_; i++) {
6161
results_[i].Cleanup();
6262
}
@@ -263,18 +263,18 @@ static bool PathContainsSeparator(const char* path) {
263263

264264
void Loader::AddDependencyLocked(Loader* loader, const char* resolved_uri) {
265265
MallocGrowableArray<char*>* dependencies =
266-
loader->isolate_group_data_->dependencies();
266+
loader->isolate_data_->dependencies();
267267
if (dependencies == NULL) {
268268
return;
269269
}
270270
dependencies->Add(strdup(resolved_uri));
271271
}
272272

273273
void Loader::ResolveDependenciesAsFilePaths() {
274-
IsolateGroupData* isolate_group_data =
275-
reinterpret_cast<IsolateGroupData*>(Dart_CurrentIsolateGroupData());
276-
ASSERT(isolate_group_data != NULL);
277-
MallocGrowableArray<char*>* dependencies = isolate_group_data->dependencies();
274+
IsolateData* isolate_data =
275+
reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData());
276+
ASSERT(isolate_data != NULL);
277+
MallocGrowableArray<char*>* dependencies = isolate_data->dependencies();
278278
if (dependencies == NULL) {
279279
return;
280280
}
@@ -455,15 +455,14 @@ bool Loader::ProcessQueueLocked(ProcessResult process_result) {
455455
}
456456

457457
void Loader::InitForSnapshot(const char* snapshot_uri) {
458-
IsolateGroupData* isolate_group_data =
459-
reinterpret_cast<IsolateGroupData*>(Dart_CurrentIsolateGroupData());
460-
ASSERT(isolate_group_data != NULL);
461-
ASSERT(!isolate_group_data->HasLoader());
458+
IsolateData* isolate_data =
459+
reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData());
460+
ASSERT(isolate_data != NULL);
461+
ASSERT(!isolate_data->HasLoader());
462462
// Setup a loader. The constructor does a bunch of leg work.
463-
Loader* loader = new Loader(isolate_group_data);
463+
Loader* loader = new Loader(isolate_data);
464464
// Send the init message.
465-
loader->Init(isolate_group_data->package_root,
466-
isolate_group_data->packages_file,
465+
loader->Init(isolate_data->package_root, isolate_data->packages_file,
467466
DartUtils::original_working_directory, snapshot_uri);
468467
// Destroy the loader. The destructor does a bunch of leg work.
469468
delete loader;
@@ -517,19 +516,18 @@ Dart_Handle Loader::SendAndProcessReply(intptr_t tag,
517516
Dart_Handle url,
518517
uint8_t** payload,
519518
intptr_t* payload_length) {
520-
IsolateGroupData* isolate_group_data =
521-
reinterpret_cast<IsolateGroupData*>(Dart_CurrentIsolateGroupData());
522-
ASSERT(isolate_group_data != NULL);
523-
ASSERT(!isolate_group_data->HasLoader());
519+
IsolateData* isolate_data =
520+
reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData());
521+
ASSERT(isolate_data != NULL);
522+
ASSERT(!isolate_data->HasLoader());
524523
Loader* loader = NULL;
525524

526525
// Setup the loader. The constructor does a bunch of leg work.
527-
loader = new Loader(isolate_group_data);
528-
loader->Init(isolate_group_data->package_root,
529-
isolate_group_data->packages_file,
526+
loader = new Loader(isolate_data);
527+
loader->Init(isolate_data->package_root, isolate_data->packages_file,
530528
DartUtils::original_working_directory, NULL);
531529
ASSERT(loader != NULL);
532-
ASSERT(isolate_group_data->HasLoader());
530+
ASSERT(isolate_data->HasLoader());
533531

534532
// Now send a load request to the service isolate.
535533
loader->SendRequest(tag, url, Dart_Null());
@@ -681,47 +679,46 @@ Dart_Handle Loader::LibraryTagHandler(Dart_LibraryTag tag,
681679
}
682680
}
683681

684-
IsolateGroupData* isolate_group_data =
685-
reinterpret_cast<IsolateGroupData*>(Dart_CurrentIsolateGroupData());
686-
ASSERT(isolate_group_data != NULL);
682+
IsolateData* isolate_data =
683+
reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData());
684+
ASSERT(isolate_data != NULL);
687685
if ((tag == Dart_kScriptTag) && Dart_IsString(library)) {
688686
// Update packages file for isolate.
689687
const char* packages_file = NULL;
690688
Dart_Handle result = Dart_StringToCString(library, &packages_file);
691689
if (Dart_IsError(result)) {
692690
return result;
693691
}
694-
isolate_group_data->UpdatePackagesFile(packages_file);
692+
isolate_data->UpdatePackagesFile(packages_file);
695693
}
696694
// Grab this isolate's loader.
697695
Loader* loader = NULL;
698696

699697
// The outer invocation of the tag handler for this isolate. We make the outer
700698
// invocation block and allow any nested invocations to operate in parallel.
701-
const bool blocking_call = !isolate_group_data->HasLoader();
699+
const bool blocking_call = !isolate_data->HasLoader();
702700

703701
// If we are the outer invocation of the tag handler and the tag is an import
704702
// this means that we are starting a deferred library load.
705703
const bool is_deferred_import = blocking_call && (tag == Dart_kImportTag);
706-
if (!isolate_group_data->HasLoader()) {
704+
if (!isolate_data->HasLoader()) {
707705
// The isolate doesn't have a loader -- this is the outer invocation which
708706
// will block.
709707

710708
// Setup the loader. The constructor does a bunch of leg work.
711-
loader = new Loader(isolate_group_data);
712-
loader->Init(isolate_group_data->package_root,
713-
isolate_group_data->packages_file,
709+
loader = new Loader(isolate_data);
710+
loader->Init(isolate_data->package_root, isolate_data->packages_file,
714711
DartUtils::original_working_directory,
715712
(tag == Dart_kScriptTag) ? url_string : NULL);
716713
} else {
717714
ASSERT(tag != Dart_kScriptTag);
718715
// The isolate has a loader -- this is an inner invocation that will queue
719716
// work with the service isolate.
720717
// Use the existing loader.
721-
loader = isolate_group_data->loader();
718+
loader = isolate_data->loader();
722719
}
723720
ASSERT(loader != NULL);
724-
ASSERT(isolate_group_data->HasLoader());
721+
ASSERT(isolate_data->HasLoader());
725722

726723
if (DartUtils::IsDartExtensionSchemeURL(url_string)) {
727724
loader->SendImportExtensionRequest(url, Dart_LibraryUrl(library));
@@ -818,11 +815,11 @@ Loader::LoaderInfo* Loader::loader_infos_ = NULL;
818815
intptr_t Loader::loader_infos_length_ = 0;
819816
intptr_t Loader::loader_infos_capacity_ = 0;
820817

821-
// Add a mapping from |port| to |isolate_group_data| (really the loader). When a
818+
// Add a mapping from |port| to |isolate_data| (really the loader). When a
822819
// native message arrives, we use this map to report the I/O result to the
823820
// correct loader.
824821
// This happens whenever an isolate begins loading.
825-
void Loader::AddLoader(Dart_Port port, IsolateGroupData* isolate_group_data) {
822+
void Loader::AddLoader(Dart_Port port, IsolateData* isolate_data) {
826823
MutexLocker ml(loader_infos_lock_);
827824
ASSERT(LoaderForLocked(port) == NULL);
828825
if (loader_infos_length_ == loader_infos_capacity_) {
@@ -835,12 +832,12 @@ void Loader::AddLoader(Dart_Port port, IsolateGroupData* isolate_group_data) {
835832
// Initialize new entries.
836833
for (intptr_t i = loader_infos_length_; i < loader_infos_capacity_; i++) {
837834
loader_infos_[i].port = ILLEGAL_PORT;
838-
loader_infos_[i].isolate_group_data = NULL;
835+
loader_infos_[i].isolate_data = NULL;
839836
}
840837
}
841838
ASSERT(loader_infos_length_ < loader_infos_capacity_);
842839
loader_infos_[loader_infos_length_].port = port;
843-
loader_infos_[loader_infos_length_].isolate_group_data = isolate_group_data;
840+
loader_infos_[loader_infos_length_].isolate_data = isolate_data;
844841
loader_infos_length_++;
845842
ASSERT(LoaderForLocked(port) != NULL);
846843
}
@@ -874,7 +871,7 @@ Loader* Loader::LoaderForLocked(Dart_Port port) {
874871
if (index < 0) {
875872
return NULL;
876873
}
877-
return loader_infos_[index].isolate_group_data->loader();
874+
return loader_infos_[index].isolate_data->loader();
878875
}
879876

880877
Loader* Loader::LoaderFor(Dart_Port port) {

0 commit comments

Comments
 (0)