Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit f9760fc

Browse files
author
Dart CI
committed
Version 2.12.0-118.0.dev
Merge commit '16f163157aa2b3d6f39a8dae4ce96d9c663e8f0c' into 'dev'
2 parents f5437c5 + 16f1631 commit f9760fc

File tree

13 files changed

+145
-53
lines changed

13 files changed

+145
-53
lines changed

pkg/analysis_server/lib/src/edit/edit_domain.dart

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -759,30 +759,26 @@ error.errorCode: ${error.errorCode}
759759
);
760760

761761
try {
762-
List<Assist> assists;
763-
try {
764-
var processor = AssistProcessor(context);
765-
assists = await processor.compute();
766-
} on InconsistentAnalysisException {
767-
assists = [];
768-
} catch (exception, stackTrace) {
769-
var parametersFile = '''
770-
offset: $offset
771-
length: $length
772-
''';
773-
throw CaughtExceptionWithFiles(exception, stackTrace, {
774-
file: result.content,
775-
'parameters': parametersFile,
776-
});
777-
}
778-
762+
var processor = AssistProcessor(context);
763+
var assists = await processor.compute();
779764
assists.sort(Assist.SORT_BY_RELEVANCE);
780765
for (var assist in assists) {
781766
changes.add(assist.change);
782767
}
768+
} on InconsistentAnalysisException {
769+
// ignore
770+
} catch (exception, stackTrace) {
771+
var parametersFile = '''
772+
offset: $offset
773+
length: $length
774+
''';
775+
throw CaughtExceptionWithFiles(exception, stackTrace, {
776+
file: result.content,
777+
'parameters': parametersFile,
778+
});
779+
}
783780

784-
server.requestStatistics?.addItemTimeNow(request, 'computedAssists');
785-
} catch (_) {}
781+
server.requestStatistics?.addItemTimeNow(request, 'computedAssists');
786782
}
787783

788784
return changes;

runtime/platform/atomic.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,18 @@ class AcqRelAtomic {
100100
bool compare_exchange_weak(
101101
T& expected, // NOLINT
102102
T desired,
103-
std::memory_order order = std::memory_order_acq_rel) {
104-
return value_.compare_exchange_weak(expected, desired, order, order);
103+
std::memory_order success_order = std::memory_order_acq_rel,
104+
std::memory_order failure_order = std::memory_order_seq_cst) {
105+
return value_.compare_exchange_weak(expected, desired, success_order,
106+
failure_order);
105107
}
106108
bool compare_exchange_strong(
107109
T& expected, // NOLINT
108110
T desired,
109-
std::memory_order order = std::memory_order_acq_rel) {
110-
return value_.compare_exchange_strong(expected, desired, order, order);
111+
std::memory_order success_order = std::memory_order_acq_rel,
112+
std::memory_order failure_order = std::memory_order_seq_cst) {
113+
return value_.compare_exchange_strong(expected, desired, success_order,
114+
failure_order);
111115
}
112116

113117
// Require explicit loads and stores.

runtime/vm/compiler/backend/type_propagator_test.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,11 @@ ISOLATE_UNIT_TEST_CASE(TypePropagator_Refinement) {
187187
/*is_reflectable=*/true,
188188
/*is_late=*/false, object_class, Object::dynamic_type(),
189189
TokenPosition::kNoSource, TokenPosition::kNoSource));
190-
thread->isolate_group()->RegisterStaticField(field, Instance::Handle());
190+
{
191+
SafepointWriteRwLocker locker(thread,
192+
thread->isolate_group()->program_lock());
193+
thread->isolate_group()->RegisterStaticField(field, Instance::Handle());
194+
}
191195

192196
FlowGraphBuilderHelper H;
193197

runtime/vm/dart.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -697,8 +697,7 @@ static bool CloneIntoChildIsolateAOT(Thread* T,
697697
}
698698
I->isolate_object_store()->Init();
699699
I->isolate_object_store()->PreallocateObjects();
700-
I->set_field_table(T, source_isolate_group->initial_field_table()->Clone(
701-
/*is_isolate_field_table=*/true));
700+
I->set_field_table(T, source_isolate_group->initial_field_table()->Clone(I));
702701

703702
return true;
704703
}
@@ -743,8 +742,7 @@ ErrorPtr Dart::InitIsolateFromSnapshot(Thread* T,
743742
return error.raw();
744743
}
745744

746-
I->set_field_table(T, I->group()->initial_field_table()->Clone(
747-
/*is_isolate_field_table=*/true));
745+
I->set_field_table(T, I->group()->initial_field_table()->Clone(I));
748746

749747
#if defined(SUPPORT_TIMELINE)
750748
if (tbes.enabled()) {

runtime/vm/field_table.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ void FieldTable::Grow(intptr_t new_capacity) {
9898
// via store to table_.
9999
std::atomic_thread_fence(std::memory_order_release);
100100
table_ = new_table;
101-
if (is_isolate_field_table_) {
102-
Thread::Current()->field_table_values_ = table_;
101+
if (isolate_ != nullptr) {
102+
isolate_->mutator_thread()->field_table_values_ = table_;
103103
}
104104
}
105105

106-
FieldTable* FieldTable::Clone(bool is_isolate_field_table) {
107-
FieldTable* clone = new FieldTable(is_isolate_field_table);
106+
FieldTable* FieldTable::Clone(Isolate* for_isolate) {
107+
FieldTable* clone = new FieldTable(for_isolate);
108108
auto new_table = static_cast<InstancePtr*>(
109109
malloc(capacity_ * sizeof(InstancePtr))); // NOLINT
110110
memmove(new_table, table_, capacity_ * sizeof(InstancePtr));

runtime/vm/field_table.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@
1616

1717
namespace dart {
1818

19+
class Isolate;
1920
class Field;
2021

2122
class FieldTable {
2223
public:
23-
explicit FieldTable(bool is_isolate_field_table)
24+
explicit FieldTable(Isolate* isolate)
2425
: top_(0),
2526
capacity_(0),
2627
free_head_(-1),
2728
table_(nullptr),
2829
old_tables_(new MallocGrowableArray<InstancePtr*>()),
29-
is_isolate_field_table_(is_isolate_field_table) {}
30+
isolate_(isolate) {}
3031

3132
~FieldTable();
3233

@@ -56,7 +57,7 @@ class FieldTable {
5657
}
5758
void SetAt(intptr_t index, InstancePtr raw_instance);
5859

59-
FieldTable* Clone(bool is_isolate_field_table);
60+
FieldTable* Clone(Isolate* for_isolate);
6061

6162
void VisitObjectPointers(ObjectPointerVisitor* visitor);
6263

@@ -83,10 +84,10 @@ class FieldTable {
8384
// so it will get freed when its are no longer in use.
8485
MallocGrowableArray<InstancePtr*>* old_tables_;
8586

86-
// Whether this table is used as a isolate-specific table of it's global field
87-
// values and therefore needs to keep the cached field table in the `Thread`
88-
// object up-to-date.
89-
bool is_isolate_field_table_;
87+
// If non-NULL, it will specify the isolate this field table belongs to.
88+
// Growing the field table will keep the cached field table on the isolate's
89+
// mutator thread up-to-date.
90+
Isolate* isolate_;
9091

9192
DISALLOW_COPY_AND_ASSIGN(FieldTable);
9293
};

runtime/vm/isolate.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ IsolateGroup::IsolateGroup(std::shared_ptr<IsolateGroupSource> source,
353353
store_buffer_(new StoreBuffer()),
354354
heap_(nullptr),
355355
saved_unlinked_calls_(Array::null()),
356-
initial_field_table_(new FieldTable(/*is_isolate_field_table=*/false)),
356+
initial_field_table_(new FieldTable(/*isolate=*/nullptr)),
357357
symbols_lock_(new SafepointRwLock()),
358358
type_canonicalization_mutex_(
359359
NOT_IN_PRODUCT("IsolateGroup::type_canonicalization_mutex_")),
@@ -907,6 +907,8 @@ void Isolate::ValidateClassTable() {
907907

908908
void IsolateGroup::RegisterStaticField(const Field& field,
909909
const Instance& initial_value) {
910+
ASSERT(program_lock()->IsCurrentThreadWriter());
911+
910912
ASSERT(field.is_static());
911913
initial_field_table()->Register(field);
912914
initial_field_table()->SetAt(field.field_id(), initial_value.raw());
@@ -1631,7 +1633,7 @@ Isolate::Isolate(IsolateGroup* isolate_group,
16311633
default_tag_(UserTag::null()),
16321634
ic_miss_code_(Code::null()),
16331635
shared_class_table_(isolate_group->shared_class_table()),
1634-
field_table_(new FieldTable(/*is_isolate_field_table=*/true)),
1636+
field_table_(new FieldTable(/*isolate=*/this)),
16351637
isolate_group_(isolate_group),
16361638
isolate_object_store_(
16371639
new IsolateObjectStore(isolate_group->object_store())),

runtime/vm/object_test.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3065,7 +3065,11 @@ static FieldPtr CreateTestField(const char* name) {
30653065
const Field& field = Field::Handle(Field::New(
30663066
field_name, true, false, false, true, false, cls, Object::dynamic_type(),
30673067
TokenPosition::kMinSource, TokenPosition::kMinSource));
3068-
thread->isolate_group()->RegisterStaticField(field, Instance::sentinel());
3068+
{
3069+
SafepointWriteRwLocker locker(thread,
3070+
thread->isolate_group()->program_lock());
3071+
thread->isolate_group()->RegisterStaticField(field, Instance::sentinel());
3072+
}
30693073
return field.raw();
30703074
}
30713075

sdk/lib/_internal/vm/lib/growable_array.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ class _GrowableList<T> extends ListBase<T> {
261261
void add(T value) {
262262
var len = length;
263263
if (len == _capacity) {
264-
_grow(_nextCapacity(len));
264+
_growToNextCapacity();
265265
}
266266
_setLength(len + 1);
267267
this[len] = value;
@@ -310,7 +310,7 @@ class _GrowableList<T> extends ListBase<T> {
310310
if (this.length != newLen) throw new ConcurrentModificationError(this);
311311
len = newLen;
312312
}
313-
_grow(_nextCapacity(_capacity));
313+
_growToNextCapacity();
314314
} while (true);
315315
}
316316

@@ -370,6 +370,14 @@ class _GrowableList<T> extends ListBase<T> {
370370
_setData(newData);
371371
}
372372

373+
// This method is marked as never-inline to conserve code size.
374+
// It is called in rare cases, but used in the add() which is
375+
// used very often and always inlined.
376+
@pragma("vm:never-inline")
377+
void _growToNextCapacity() {
378+
_grow(_nextCapacity(_capacity));
379+
}
380+
373381
void _shrink(int new_capacity, int new_length) {
374382
var newData = _allocateData(new_capacity);
375383
// This is a work-around for dartbug.com/30090. See the comment in _grow.

sdk/lib/ffi/struct.dart

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,48 @@
44

55
part of dart.ffi;
66

7-
/// This class is extended to define structs.
7+
/// The supertype of all FFI struct types.
88
///
9-
/// Fields in a struct, annotated with a subtype of [NativeType], are
10-
/// automatically transformed into wrappers to access the fields of the struct
11-
/// in native memory.
9+
/// FFI struct types should extend this class and declare fields corresponding
10+
/// to the underlying native structure.
1211
///
13-
/// All fields in a struct must either have a type which extends [NativeType] or
14-
/// else have an annotation indicating the corresponding native type (e.g.
15-
/// "@Int32()" for "int").
12+
/// Field declarations in a [Struct] subclass declaration are automatically
13+
/// given a setter and getter implementation which accesses the native struct's
14+
/// field in memory.
15+
///
16+
/// All field declarations in a [Struct] subclass declaration must either have
17+
/// type [int] or [float] and be annotated with a [NativeType] representing the
18+
/// native type, or must be of type [Pointer]. For example:
19+
///
20+
/// ```
21+
/// typedef struct {
22+
/// int a;
23+
/// float b;
24+
/// void* c;
25+
/// } my_struct;
26+
/// ```
27+
///
28+
/// ```
29+
/// class MyStruct extends Struct {
30+
/// @Int32
31+
/// external int a;
32+
///
33+
/// @Float
34+
/// external double b;
35+
///
36+
/// external Pointer<Void> c;
37+
/// }
38+
/// ```
39+
///
40+
/// All field declarations in a [Struct] subclass declaration must be marked
41+
/// `external`. You cannot create instances of the class, only have it point to
42+
/// existing native memory, so there is no memory in which to store non-native
43+
/// fields. External fields also cannot be initialized by constructors since no
44+
/// Dart object is being created.
1645
///
1746
/// Instances of a subclass of [Struct] have reference semantics and are backed
1847
/// by native memory. The may allocated via allocation or loaded from a
19-
/// [Pointer], but not by a generative constructor.
48+
/// [Pointer], but cannot be created by a generative constructor.
2049
abstract class Struct extends NativeType {
2150
final Object _addressOf;
2251

0 commit comments

Comments
 (0)