mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
![Alexander Aprelev](/assets/img/avatar_default.png)
This reverts commit 3d14b75f97
.
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 https://github.com/dart-lang/sdk/issues/36648
Issue https://github.com/dart-lang/sdk/issues/36097
Original review: https://dart-review.googlesource.com/c/sdk/+/105241
Difference to original review:
* Give each isolate it's own [Loader] (for now)
* Sort classes during initialization for spawned isolates if app-jit is used (to match main isolate)
* Fix IsolateData memory leak if isolate startup fails
Difference to first reland(Patchset 2):
* Fix typo where memory was freed twice.
Change-Id: Ib1c83fe83b629cd50ae6af90ee99fdd44da882d4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/108367
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
105 lines
2.9 KiB
C++
105 lines
2.9 KiB
C++
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#ifndef RUNTIME_VM_KERNEL_ISOLATE_H_
|
|
#define RUNTIME_VM_KERNEL_ISOLATE_H_
|
|
|
|
#include <vector>
|
|
|
|
#include "include/dart_api.h"
|
|
#include "include/dart_native_api.h"
|
|
|
|
#include "vm/allocation.h"
|
|
#include "vm/dart.h"
|
|
#include "vm/os_thread.h"
|
|
|
|
namespace dart {
|
|
|
|
// TODO(33433): The kernel service does not belong in the VM.
|
|
|
|
class KernelIsolate : public AllStatic {
|
|
public:
|
|
static const char* kName;
|
|
static const int kCompileTag;
|
|
static const int kUpdateSourcesTag;
|
|
static const int kAcceptTag;
|
|
static const int kTrainTag;
|
|
static const int kCompileExpressionTag;
|
|
static const int kListDependenciesTag;
|
|
static const int kNotifyIsolateShutdown;
|
|
|
|
static void Run();
|
|
static void Shutdown();
|
|
|
|
static bool NameEquals(const char* name);
|
|
static bool Exists();
|
|
static bool IsRunning();
|
|
static bool IsKernelIsolate(const Isolate* isolate);
|
|
static Dart_Port WaitForKernelPort();
|
|
static Dart_Port KernelPort() { return kernel_port_; }
|
|
|
|
static Dart_KernelCompilationResult CompileToKernel(
|
|
const char* script_uri,
|
|
const uint8_t* platform_kernel,
|
|
intptr_t platform_kernel_size,
|
|
int source_files_count = 0,
|
|
Dart_SourceFile source_files[] = NULL,
|
|
bool incremental_compile = true,
|
|
const char* package_config = NULL,
|
|
const char* multiroot_filepaths = NULL,
|
|
const char* multiroot_scheme = NULL);
|
|
|
|
static Dart_KernelCompilationResult AcceptCompilation();
|
|
static Dart_KernelCompilationResult UpdateInMemorySources(
|
|
int source_files_count,
|
|
Dart_SourceFile source_files[]);
|
|
|
|
static Dart_KernelCompilationResult CompileExpressionToKernel(
|
|
const char* expression,
|
|
const Array& definitions,
|
|
const Array& type_definitions,
|
|
const char* library_url,
|
|
const char* klass,
|
|
bool is_static);
|
|
|
|
static Dart_KernelCompilationResult ListDependencies();
|
|
|
|
static void NotifyAboutIsolateShutdown(const Isolate* isolate);
|
|
|
|
static void AddExperimentalFlag(const char* value);
|
|
|
|
protected:
|
|
static void InitCallback(Isolate* I);
|
|
static void SetKernelIsolate(Isolate* isolate);
|
|
static void SetLoadPort(Dart_Port port);
|
|
static void FinishedExiting();
|
|
static void FinishedInitializing();
|
|
static void InitializingFailed();
|
|
static Dart_IsolateGroupCreateCallback create_group_callback() {
|
|
return create_group_callback_;
|
|
}
|
|
|
|
static Dart_IsolateGroupCreateCallback create_group_callback_;
|
|
static Monitor* monitor_;
|
|
enum State {
|
|
kStopped,
|
|
kStarting,
|
|
kStarted,
|
|
kStopping,
|
|
};
|
|
static State state_;
|
|
static Isolate* isolate_;
|
|
static Dart_Port kernel_port_;
|
|
|
|
static MallocGrowableArray<char*>* experimental_flags_;
|
|
|
|
friend class Dart;
|
|
friend class Isolate;
|
|
friend class RunKernelTask;
|
|
};
|
|
|
|
} // namespace dart
|
|
|
|
#endif // RUNTIME_VM_KERNEL_ISOLATE_H_
|