[XL] Change in dart/sdk[main]: [vm] Add graph intrinsics for ThreadLocal hasValue and getValue methods.

0 views
Skip to first unread message

Alexander Aprelev (Gerrit)

unread,
Nov 24, 2025, 4:19:08 PM (5 days ago) Nov 24
to Alexander Aprelev, Slava Egorov, Commit Queue, dart-vm-compil...@google.com, rev...@dartlang.org, vm-...@dartlang.org
Attention needed from Slava Egorov

Alexander Aprelev added 1 comment

Patchset-level comments
File-level comment, Patchset 5 (Latest):
Alexander Aprelev . resolved

this is what I had in mind regarding graph intrinsics implementation for ThreadLocal getValue/hasValue.

Open in Gerrit

Related details

Attention is currently required from:
  • Slava Egorov
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I3cdbaf085dfc23fcad4544be8a299b7520c7d825
Gerrit-Change-Number: 464320
Gerrit-PatchSet: 5
Gerrit-Owner: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Slava Egorov <veg...@google.com>
Gerrit-Attention: Slava Egorov <veg...@google.com>
Gerrit-Comment-Date: Mon, 24 Nov 2025 21:19:03 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Slava Egorov (Gerrit)

unread,
Nov 25, 2025, 3:12:40 PM (4 days ago) Nov 25
to Alexander Aprelev, Commit Queue, dart-vm-compil...@google.com, rev...@dartlang.org, vm-...@dartlang.org
Attention needed from Alexander Aprelev

Slava Egorov added 3 comments

File runtime/vm/compiler/backend/slot.h
Line 288, Patchset 9 (Latest): V(Thread, _, thread_locals, false, FINAL)
Slava Egorov . unresolved

Supposedly this is a list of _untagged_ fields (e.g. fields which contain some raw pointers - rather than pointers to Dart objects). But `thread_locals` is a tagged pointer.

Also 4th parameter is `gc_may_move` and it can't be `false` because GC certainly can move `thread_locals`.

File runtime/vm/compiler/graph_intrinsifier.cc
Line 735, Patchset 9 (Latest): builder->AddInstruction(new CheckClassInstr(new Value(array), DeoptId::kNone,
Slava Egorov . unresolved

`CheckClassInstr` implies some sort of speculative optimization. It is not speculative here - we know it is `GrowableArray`, this should be encoded in the type information on the `Slot::Thread_thread_locals()`.

File sdk/lib/_vm/_vm.dart
Line 86, Patchset 9 (Latest): bool had_value = variable.hasValue;
Slava Egorov . unresolved

nit: names in Dart should be `camelCase` not `snake_case`.

Open in Gerrit

Related details

Attention is currently required from:
  • Alexander Aprelev
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I3cdbaf085dfc23fcad4544be8a299b7520c7d825
Gerrit-Change-Number: 464320
Gerrit-PatchSet: 9
Gerrit-Owner: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Slava Egorov <veg...@google.com>
Gerrit-Attention: Alexander Aprelev <a...@google.com>
Gerrit-Comment-Date: Tue, 25 Nov 2025 20:12:35 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Alexander Aprelev (Gerrit)

unread,
Nov 26, 2025, 1:39:40 AM (3 days ago) Nov 26
to Alexander Aprelev, Slava Egorov, Commit Queue, dart-vm-compil...@google.com, rev...@dartlang.org, vm-...@dartlang.org
Attention needed from Slava Egorov

Alexander Aprelev voted and added 4 comments

Votes added by Alexander Aprelev

Commit-Queue+1

4 comments

Patchset-level comments
File-level comment, Patchset 10 (Latest):
Alexander Aprelev . resolved

thank you Slava!

File runtime/vm/compiler/backend/slot.h
Line 288, Patchset 9: V(Thread, _, thread_locals, false, FINAL)
Slava Egorov . resolved

Supposedly this is a list of _untagged_ fields (e.g. fields which contain some raw pointers - rather than pointers to Dart objects). But `thread_locals` is a tagged pointer.

Also 4th parameter is `gc_may_move` and it can't be `false` because GC certainly can move `thread_locals`.

Alexander Aprelev

Done

File runtime/vm/compiler/graph_intrinsifier.cc
Line 735, Patchset 9: builder->AddInstruction(new CheckClassInstr(new Value(array), DeoptId::kNone,
Slava Egorov . resolved

`CheckClassInstr` implies some sort of speculative optimization. It is not speculative here - we know it is `GrowableArray`, this should be encoded in the type information on the `Slot::Thread_thread_locals()`.

Alexander Aprelev

Done

File sdk/lib/_vm/_vm.dart
Line 86, Patchset 9: bool had_value = variable.hasValue;
Slava Egorov . resolved

nit: names in Dart should be `camelCase` not `snake_case`.

Alexander Aprelev

Done

Open in Gerrit

Related details

Attention is currently required from:
  • Slava Egorov
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I3cdbaf085dfc23fcad4544be8a299b7520c7d825
Gerrit-Change-Number: 464320
Gerrit-PatchSet: 10
Gerrit-Owner: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Slava Egorov <veg...@google.com>
Gerrit-Attention: Slava Egorov <veg...@google.com>
Gerrit-Comment-Date: Wed, 26 Nov 2025 06:39:37 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: Slava Egorov <veg...@google.com>
satisfied_requirement
unsatisfied_requirement
open
diffy

Slava Egorov (Gerrit)

unread,
Nov 26, 2025, 8:26:23 AM (3 days ago) Nov 26
to Alexander Aprelev, Commit Queue, dart-vm-compil...@google.com, rev...@dartlang.org, vm-...@dartlang.org
Attention needed from Alexander Aprelev

Slava Egorov added 2 comments

Patchset-level comments
Slava Egorov . resolved

Are failing tests caused by this change?

File runtime/vm/compiler/graph_intrinsifier.cc
Line 766, Patchset 10 (Latest): Definition* result = builder.AddDefinition(new StrictCompareInstr(
Slava Egorov . unresolved

Normally `LoadIndexedInstr::ComputeType(...)` would return a type which says that the value can't be sentinel. (See `ComputeArrayElementType` in `type_propagator.cc`). This means there is a high chance that this sort of comparison will be optimized away.

You need to fix the type of `LoadIndexedInstr` to prevent this from happening.

Open in Gerrit

Related details

Attention is currently required from:
  • Alexander Aprelev
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I3cdbaf085dfc23fcad4544be8a299b7520c7d825
Gerrit-Change-Number: 464320
Gerrit-PatchSet: 10
Gerrit-Owner: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Slava Egorov <veg...@google.com>
Gerrit-Attention: Alexander Aprelev <a...@google.com>
Gerrit-Comment-Date: Wed, 26 Nov 2025 13:26:16 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Alexander Aprelev (Gerrit)

unread,
Nov 26, 2025, 11:28:50 AM (3 days ago) Nov 26
to Alexander Aprelev, Slava Egorov, Commit Queue, dart-vm-compil...@google.com, rev...@dartlang.org, vm-...@dartlang.org
Attention needed from Slava Egorov

Alexander Aprelev added 1 comment

Patchset-level comments
Slava Egorov . unresolved

Are failing tests caused by this change?

Alexander Aprelev

Yeah, CheckClassInstr that I removed in latest patchset used to catch and send to runtime cases when thread_locals array is null, was not initialized yet.

Open in Gerrit

Related details

Attention is currently required from:
  • Slava Egorov
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I3cdbaf085dfc23fcad4544be8a299b7520c7d825
Gerrit-Change-Number: 464320
Gerrit-PatchSet: 10
Gerrit-Owner: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Slava Egorov <veg...@google.com>
Gerrit-Attention: Slava Egorov <veg...@google.com>
Gerrit-Comment-Date: Wed, 26 Nov 2025 16:28:44 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Slava Egorov <veg...@google.com>
satisfied_requirement
unsatisfied_requirement
open
diffy

Alexander Aprelev (Gerrit)

unread,
Nov 26, 2025, 12:42:47 PM (3 days ago) Nov 26
to Alexander Aprelev, Slava Egorov, Commit Queue, dart-vm-compil...@google.com, rev...@dartlang.org, vm-...@dartlang.org
Attention needed from Slava Egorov

Alexander Aprelev voted and added 3 comments

Votes added by Alexander Aprelev

Commit-Queue+1

3 comments

Patchset-level comments
Slava Egorov . resolved

Are failing tests caused by this change?

Alexander Aprelev

Yeah, CheckClassInstr that I removed in latest patchset used to catch and send to runtime cases when thread_locals array is null, was not initialized yet.

Alexander Aprelev

Done

File runtime/vm/compiler/graph_intrinsifier.cc
Line 735, Patchset 9: builder->AddInstruction(new CheckClassInstr(new Value(array), DeoptId::kNone,
Slava Egorov . resolved

`CheckClassInstr` implies some sort of speculative optimization. It is not speculative here - we know it is `GrowableArray`, this should be encoded in the type information on the `Slot::Thread_thread_locals()`.

Alexander Aprelev

Done

Alexander Aprelev

It can be null as well, in which case we do want to fall back to runtime implementation.

Line 766, Patchset 10 (Latest): Definition* result = builder.AddDefinition(new StrictCompareInstr(
Slava Egorov . resolved

Normally `LoadIndexedInstr::ComputeType(...)` would return a type which says that the value can't be sentinel. (See `ComputeArrayElementType` in `type_propagator.cc`). This means there is a high chance that this sort of comparison will be optimized away.

You need to fix the type of `LoadIndexedInstr` to prevent this from happening.

Alexander Aprelev

Done

Open in Gerrit

Related details

Attention is currently required from:
  • Slava Egorov
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I3cdbaf085dfc23fcad4544be8a299b7520c7d825
Gerrit-Change-Number: 464320
Gerrit-PatchSet: 10
Gerrit-Owner: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Slava Egorov <veg...@google.com>
Gerrit-Attention: Slava Egorov <veg...@google.com>
Gerrit-Comment-Date: Wed, 26 Nov 2025 17:42:44 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: Alexander Aprelev <a...@google.com>
Comment-In-Reply-To: Slava Egorov <veg...@google.com>
satisfied_requirement
unsatisfied_requirement
open
diffy

Slava Egorov (Gerrit)

unread,
Nov 28, 2025, 7:30:09 AM (yesterday) Nov 28
to Alexander Aprelev, Commit Queue, dart-vm-compil...@google.com, rev...@dartlang.org, vm-...@dartlang.org
Attention needed from Alexander Aprelev

Slava Egorov added 1 comment

File runtime/vm/compiler/graph_intrinsifier.cc
Line 727, Patchset 11 (Latest): Definition* array = builder->AddDefinition(
Slava Egorov . unresolved

On the deeper thought: I am not sure why `thread_locals` are even represented as a growable array. it's Length is always set equal to Capacity.

So I suggest representing it as a non-nullable Array instead, then you don't need any of this. You can initialize it to Object::empty_array which becomes available after VM isolate bootstrap is complete.

Open in Gerrit

Related details

Attention is currently required from:
  • Alexander Aprelev
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I3cdbaf085dfc23fcad4544be8a299b7520c7d825
Gerrit-Change-Number: 464320
Gerrit-PatchSet: 11
Gerrit-Owner: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Slava Egorov <veg...@google.com>
Gerrit-Attention: Alexander Aprelev <a...@google.com>
Gerrit-Comment-Date: Fri, 28 Nov 2025 12:30:01 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Alexander Aprelev (Gerrit)

unread,
Nov 28, 2025, 3:30:56 PM (19 hours ago) Nov 28
to Alexander Aprelev, Slava Egorov, Commit Queue, dart-vm-compil...@google.com, rev...@dartlang.org, vm-...@dartlang.org
Attention needed from Slava Egorov

Alexander Aprelev voted and added 1 comment

Votes added by Alexander Aprelev

Commit-Queue+1

1 comment

File runtime/vm/compiler/graph_intrinsifier.cc
Line 727, Patchset 11: Definition* array = builder->AddDefinition(
Slava Egorov . resolved

On the deeper thought: I am not sure why `thread_locals` are even represented as a growable array. it's Length is always set equal to Capacity.

So I suggest representing it as a non-nullable Array instead, then you don't need any of this. You can initialize it to Object::empty_array which becomes available after VM isolate bootstrap is complete.

Alexander Aprelev

Done

Open in Gerrit

Related details

Attention is currently required from:
  • Slava Egorov
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I3cdbaf085dfc23fcad4544be8a299b7520c7d825
Gerrit-Change-Number: 464320
Gerrit-PatchSet: 12
Gerrit-Owner: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Slava Egorov <veg...@google.com>
Gerrit-Attention: Slava Egorov <veg...@google.com>
Gerrit-Comment-Date: Fri, 28 Nov 2025 20:30:53 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: Slava Egorov <veg...@google.com>
satisfied_requirement
unsatisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages