Skip to content

Commit cabc717

Browse files
aamCommit Queue
authored andcommitted
[vm/shared] Ensure shared initial field table is used with shared fields.
Fixes flutter/flutter#170038 TEST=shared_static_final_test Change-Id: Ia242b5d9c661782e5a6018ba96211a75cc47c1a3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/436200 Reviewed-by: Slava Egorov <[email protected]> Commit-Queue: Alexander Aprelev <[email protected]>
1 parent c95dbcd commit cabc717

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
//
5+
// VMOptions=--experimental-shared-data
6+
//
7+
import 'package:expect/expect.dart';
8+
9+
@pragma('vm:shared')
10+
final int foo = 42;
11+
12+
main() {
13+
Expect.equals(42, foo);
14+
}

runtime/vm/object.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13085,11 +13085,12 @@ ObjectPtr Field::StaticConstFieldValue() const {
1308513085

1308613086
auto thread = Thread::Current();
1308713087
auto zone = thread->zone();
13088-
auto initial_field_table = thread->isolate_group()->initial_field_table();
13088+
auto initial_field_table =
13089+
is_shared() ? thread->isolate_group()->shared_initial_field_table()
13090+
: thread->isolate_group()->initial_field_table();
1308913091

1309013092
// We can safely cache the value of the static const field in the initial
1309113093
// field table.
13092-
ASSERT(!is_shared());
1309313094
auto& value = Object::Handle(
1309413095
zone, initial_field_table->At(field_id(), /*concurrent_use=*/true));
1309513096
if (value.ptr() == Object::sentinel().ptr()) {
@@ -13111,9 +13112,10 @@ ObjectPtr Field::StaticConstFieldValue() const {
1311113112
void Field::SetStaticConstFieldValue(const Instance& value,
1311213113
bool assert_initializing_store) const {
1311313114
ASSERT(is_static());
13114-
ASSERT(!is_shared());
1311513115
auto thread = Thread::Current();
13116-
auto initial_field_table = thread->isolate_group()->initial_field_table();
13116+
auto initial_field_table =
13117+
is_shared() ? thread->isolate_group()->shared_initial_field_table()
13118+
: thread->isolate_group()->initial_field_table();
1311713119

1311813120
SafepointWriteRwLocker ml(thread, thread->isolate_group()->program_lock());
1311913121
ASSERT(initial_field_table->At(field_id()) == Object::sentinel().ptr() ||

0 commit comments

Comments
 (0)