Skip to content

Commit 69485e9

Browse files
aamCommit Queue
authored andcommitted
[vm] Move origin_id from isolate to isolate group.
Isolates in one group share same origin_id anyway, so it makes sense to store it on the group too. Remove isolate's _originNumber from service api - isolate group should be used instead. Based on feedback from https://dart-review.git.corp.google.com/c/sdk/+/418503/21/runtime/lib/isolate.cc#107 TEST=ci Change-Id: Iab4b6393a042c9302e911a276a6afc6dab63e70d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/424140 Commit-Queue: Alexander Aprelev <[email protected]> Reviewed-by: Ryan Macnak <[email protected]>
1 parent 0452ea6 commit 69485e9

File tree

14 files changed

+20
-60
lines changed

14 files changed

+20
-60
lines changed

pkg/vm_service/test/get_isolate_rpc_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ final tests = <IsolateTest>[
1717
expect(result.isolateFlags, isNotNull);
1818
expect(result.isolateFlags!.length, isPositive);
1919
expect(result.isSystemIsolate, isFalse);
20-
expect(result.json!['_originNumber'], result.number);
2120
expect(result.startTime, isPositive);
2221
expect(result.livePorts, isPositive);
2322
expect(result.pauseOnExit, isFalse);

pkg/vm_service/test/http_invocations/http_get_isolate_rpc_common.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ final httpGetIsolateRpcTests = <IsolateTest>[
3939
)! as Isolate;
4040
Expect.isTrue(result.id!.startsWith('isolates/'));
4141
Expect.isNotNull(result.number);
42-
Expect.equals(result.json!['_originNumber'], result.number);
4342
Expect.isTrue(result.startTime! > 0);
4443
Expect.isTrue(result.livePorts! > 0);
4544
Expect.isFalse(result.pauseOnExit);

runtime/lib/isolate.cc

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,18 @@ DEFINE_NATIVE_ENTRY(SendPort_get_hashcode, 0, 1) {
102102
return Smi::New(hash);
103103
}
104104

105-
static bool InSameGroup(Isolate* sender, const SendPort& receiver) {
106-
// Cannot determine whether sender is in same group (yet).
107-
if (sender->origin_id() == ILLEGAL_PORT) return false;
108-
105+
static bool InSameGroup(IsolateGroup* sender, const SendPort& receiver) {
109106
// Only allow arbitrary messages between isolates of the same IG.
110-
return sender->origin_id() == receiver.origin_id();
107+
return sender->id() == receiver.origin_id();
111108
}
112109

113110
DEFINE_NATIVE_ENTRY(SendPort_sendInternal_, 0, 2) {
114111
GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0));
115112
GET_NON_NULL_NATIVE_ARGUMENT(Instance, obj, arguments->NativeArgAt(1));
116113

117114
const Dart_Port destination_port_id = port.Id();
118-
const bool same_group = InSameGroup(isolate, port);
115+
IsolateGroup* group = thread->isolate_group();
116+
const bool same_group = InSameGroup(group, port);
119117
#if defined(DEBUG)
120118
if (same_group) {
121119
ASSERT(PortMap::IsReceiverInThisIsolateGroupOrClosed(destination_port_id,
@@ -505,11 +503,11 @@ DEFINE_NATIVE_ENTRY(Isolate_exit_, 0, 2) {
505503
if (!port.IsNull()) {
506504
GET_NATIVE_ARGUMENT(Instance, obj, arguments->NativeArgAt(1));
507505

508-
const bool same_group = InSameGroup(isolate, port);
506+
IsolateGroup* group = thread->isolate_group();
507+
const bool same_group = InSameGroup(group, port);
509508
#if defined(DEBUG)
510509
if (same_group) {
511-
ASSERT(PortMap::IsReceiverInThisIsolateGroupOrClosed(port.Id(),
512-
isolate->group()));
510+
ASSERT(PortMap::IsReceiverInThisIsolateGroupOrClosed(port.Id(), group));
513511
}
514512
#endif
515513
if (!same_group) {
@@ -557,7 +555,6 @@ DEFINE_NATIVE_ENTRY(Isolate_exit_, 0, 2) {
557555
class IsolateSpawnState {
558556
public:
559557
IsolateSpawnState(Dart_Port parent_port,
560-
Dart_Port origin_id,
561558
const char* script_url,
562559
PersistentHandle* closure_tuple_handle,
563560
SerializedObjectBuffer* message_buffer,
@@ -582,7 +579,6 @@ class IsolateSpawnState {
582579
~IsolateSpawnState();
583580

584581
Dart_Port parent_port() const { return parent_port_; }
585-
Dart_Port origin_id() const { return origin_id_; }
586582
Dart_Port on_exit_port() const { return on_exit_port_; }
587583
Dart_Port on_error_port() const { return on_error_port_; }
588584
const char* script_url() const { return script_url_; }
@@ -606,7 +602,6 @@ class IsolateSpawnState {
606602

607603
private:
608604
Dart_Port parent_port_;
609-
Dart_Port origin_id_ = ILLEGAL_PORT;
610605
Dart_Port on_exit_port_;
611606
Dart_Port on_error_port_;
612607
const char* script_url_;
@@ -630,7 +625,6 @@ static const char* NewConstChar(const char* chars) {
630625
}
631626

632627
IsolateSpawnState::IsolateSpawnState(Dart_Port parent_port,
633-
Dart_Port origin_id,
634628
const char* script_url,
635629
PersistentHandle* closure_tuple_handle,
636630
SerializedObjectBuffer* message_buffer,
@@ -642,7 +636,6 @@ IsolateSpawnState::IsolateSpawnState(Dart_Port parent_port,
642636
const char* debug_name,
643637
IsolateGroup* isolate_group)
644638
: parent_port_(parent_port),
645-
origin_id_(origin_id),
646639
on_exit_port_(on_exit_port),
647640
on_error_port_(on_error_port),
648641
script_url_(script_url),
@@ -876,11 +869,6 @@ class SpawnIsolateTask : public ThreadPool::Task {
876869
return;
877870
}
878871

879-
if (state_->origin_id() != ILLEGAL_PORT) {
880-
// origin_id is set to parent isolate main port id when spawning via
881-
// spawnFunction.
882-
child->set_origin_id(state_->origin_id());
883-
}
884872
bool errors_are_fatal = state_->errors_are_fatal();
885873
Dart_Port on_error_port = state_->on_error_port();
886874
Dart_Port on_exit_port = state_->on_exit_port();
@@ -1119,10 +1107,9 @@ DEFINE_NATIVE_ENTRY(Isolate_spawnFunction, 0, 10) {
11191107
}
11201108

11211109
std::unique_ptr<IsolateSpawnState> state(new IsolateSpawnState(
1122-
port.Id(), isolate->origin_id(), String2UTF8(script_uri),
1123-
closure_tuple_handle, &message_buffer, utf8_package_config,
1124-
paused.value(), fatal_errors, on_exit_port, on_error_port,
1125-
utf8_debug_name, isolate->group()));
1110+
port.Id(), String2UTF8(script_uri), closure_tuple_handle, &message_buffer,
1111+
utf8_package_config, paused.value(), fatal_errors, on_exit_port,
1112+
on_error_port, utf8_debug_name, isolate->group()));
11261113

11271114
isolate->group()->thread_pool()->Run<SpawnIsolateTask>(isolate,
11281115
std::move(state));

runtime/observatory/lib/src/elements/debugger.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,6 @@ class IsolateListCommand extends DebuggerCommand {
11081108
String current = (isolate == debugger.isolate ? '*' : '');
11091109
debugger.console
11101110
.print("${isolate.number.toString().padLeft(maxIdLen, ' ')} "
1111-
"${isolate.originNumber.toString().padLeft(maxIdLen, ' ')} "
11121111
"${isolate.name!.padRight(maxNameLen, ' ')} "
11131112
"${_isolateRunState(isolate).padRight(maxRunStateLen, ' ')} "
11141113
"${current}");

runtime/observatory/lib/src/service/object.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,6 @@ class Isolate extends ServiceObjectOwner implements M.Isolate {
14041404
VM get vm => owner as VM;
14051405
Isolate get isolate => this;
14061406
int? number;
1407-
int? originNumber;
14081407
DateTime? startTime;
14091408
Duration? get upTime {
14101409
if (startTime == null) {
@@ -1681,7 +1680,6 @@ class Isolate extends ServiceObjectOwner implements M.Isolate {
16811680
loading = false;
16821681
runnable = map['runnable'] == true;
16831682
_upgradeCollection(map, isolate);
1684-
originNumber = int.tryParse(map['_originNumber']);
16851683
if (map['rootLib'] != null) {
16861684
rootLibrary = map['rootLib'];
16871685
}

runtime/observatory/tests/service/get_isolate_rpc_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ var tests = <VMTest>[
2020
expect(result['isolateFlags'].length, isPositive);
2121
expect(result['isSystemIsolate'], isFalse);
2222
expect(result['isolateGroupId'], startsWith('isolateGroups/'));
23-
expect(result['_originNumber'], equals(result['number']));
2423
expect(result['startTime'], isPositive);
2524
expect(result['livePorts'], isPositive);
2625
expect(result['pauseOnExit'], isFalse);

runtime/observatory/tests/service/http_get_isolate_rpc_common.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ Future<Null> testeeBefore() async {
6464
Expect.equals(result['type'], 'Isolate');
6565
Expect.isTrue(result['id'].startsWith('isolates/'));
6666
Expect.type<String>(result['number']);
67-
Expect.equals(result['_originNumber'], result['number']);
6867
Expect.isTrue(result['startTime'] > 0);
6968
Expect.isTrue(result['livePorts'] > 0);
7069
Expect.isFalse(result['pauseOnExit']);

runtime/vm/dart_api_impl.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,6 @@ Dart_CreateIsolateInGroup(Dart_Isolate group_member,
14031403
Isolate* isolate;
14041404
isolate = CreateWithinExistingIsolateGroup(member->group(), name, error);
14051405
if (isolate != nullptr) {
1406-
isolate->set_origin_id(member->origin_id());
14071406
isolate->set_init_callback_data(child_isolate_data);
14081407
isolate->set_on_shutdown_callback(shutdown_callback);
14091408
isolate->set_on_cleanup_callback(cleanup_callback);

runtime/vm/isolate.cc

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class VerifyOriginId : public IsolateVisitor {
110110
public:
111111
explicit VerifyOriginId(Dart_Port id) : id_(id) {}
112112

113-
void VisitIsolate(Isolate* isolate) { ASSERT(isolate->origin_id() != id_); }
113+
void VisitIsolate(Isolate* isolate) { ASSERT(isolate->group()->id() != id_); }
114114

115115
private:
116116
Dart_Port id_;
@@ -733,7 +733,7 @@ void IsolateGroup::ForEach(std::function<void(IsolateGroup*)> action) {
733733
}
734734

735735
void IsolateGroup::RunWithIsolateGroup(
736-
uint64_t id,
736+
Dart_Port id,
737737
std::function<void(IsolateGroup*)> action,
738738
std::function<void()> not_found) {
739739
ReadRwLocker wl(Thread::Current(), isolate_groups_rwlock_);
@@ -1944,7 +1944,6 @@ Isolate* Isolate::InitIsolate(const char* name_prefix,
19441944
VerifyOriginId id_verifier(result->main_port());
19451945
Isolate::VisitIsolates(&id_verifier);
19461946
#endif
1947-
result->set_origin_id(result->main_port());
19481947

19491948
// First we ensure we enter the isolate. This will ensure we're participating
19501949
// in any safepointing requests from this point on. Other threads requesting a
@@ -2062,17 +2061,6 @@ int64_t Isolate::UptimeMicros() const {
20622061
return OS::GetCurrentMonotonicMicros() - start_time_micros_;
20632062
}
20642063

2065-
Dart_Port Isolate::origin_id() {
2066-
MutexLocker ml(&origin_id_mutex_);
2067-
return origin_id_;
2068-
}
2069-
2070-
void Isolate::set_origin_id(Dart_Port id) {
2071-
MutexLocker ml(&origin_id_mutex_);
2072-
ASSERT((id == main_port_ && origin_id_ == 0) || (origin_id_ == main_port_));
2073-
origin_id_ = id;
2074-
}
2075-
20762064
void Isolate::set_finalizers(const GrowableObjectArray& value) {
20772065
finalizers_ = value.ptr();
20782066
}
@@ -3217,8 +3205,6 @@ void Isolate::PrintJSON(JSONStream* stream, bool ref) {
32173205
if (ref) {
32183206
return;
32193207
}
3220-
jsobj.AddPropertyF("_originNumber", "%" Pd64 "",
3221-
static_cast<int64_t>(origin_id()));
32223208
int64_t uptime_millis = UptimeMicros() / kMicrosecondsPerMillisecond;
32233209
int64_t start_time = OS::GetCurrentTimeMillis() - uptime_millis;
32243210
jsobj.AddPropertyTimeMillis("startTime", start_time);

runtime/vm/isolate.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -679,13 +679,13 @@ class IsolateGroup : public IntrusiveDListEntry<IsolateGroup> {
679679
Become* become() const { return become_; }
680680
void set_become(Become* become) { become_ = become; }
681681

682-
uint64_t id() const { return id_; }
682+
Dart_Port id() const { return id_; }
683683

684684
static void Init();
685685
static void Cleanup();
686686

687687
static void ForEach(std::function<void(IsolateGroup*)> action);
688-
static void RunWithIsolateGroup(uint64_t id,
688+
static void RunWithIsolateGroup(Dart_Port id,
689689
std::function<void(IsolateGroup*)> action,
690690
std::function<void()> not_found);
691691

@@ -886,7 +886,7 @@ class IsolateGroup : public IntrusiveDListEntry<IsolateGroup> {
886886
static IntrusiveDList<IsolateGroup>* isolate_groups_;
887887
static Random* isolate_group_random_;
888888

889-
uint64_t id_ = 0;
889+
Dart_Port id_ = 0;
890890

891891
std::unique_ptr<StoreBuffer> store_buffer_;
892892
std::unique_ptr<Heap> heap_;
@@ -1065,8 +1065,6 @@ class Isolate : public IntrusiveDListEntry<Isolate> {
10651065
ASSERT(main_port_ == 0); // Only set main port once.
10661066
main_port_ = port;
10671067
}
1068-
Dart_Port origin_id();
1069-
void set_origin_id(Dart_Port id);
10701068
void set_pause_capability(uint64_t value) { pause_capability_ = value; }
10711069
uint64_t pause_capability() const { return pause_capability_; }
10721070
void set_terminate_capability(uint64_t value) {
@@ -1665,9 +1663,6 @@ class Isolate : public IntrusiveDListEntry<Isolate> {
16651663
Dart_IsolateCleanupCallback on_cleanup_callback_ = nullptr;
16661664
char* name_ = nullptr;
16671665
Dart_Port main_port_ = 0;
1668-
// Isolates created by Isolate.spawn have the same origin id.
1669-
Dart_Port origin_id_ = 0;
1670-
Mutex origin_id_mutex_;
16711666
uint64_t pause_capability_ = 0;
16721667
uint64_t terminate_capability_ = 0;
16731668
void* init_callback_data_ = nullptr;

0 commit comments

Comments
 (0)