Skip to content

Commit fc16a52

Browse files
aamCommit Queue
authored andcommitted
[vm/shared] Replace static final _emptyList with getter.
static final _emptyList can't be used in isolategroup mutator code, so the code that uses lists didn't work in that setting neither. Having natively-implemented _emptyList getter fixes this issue. TEST=run_isolate_group_run_test Change-Id: Iad422231829d1dc0994863632521f50f2f8247ab Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/443146 Reviewed-by: Alexander Markov <[email protected]> Commit-Queue: Alexander Aprelev <[email protected]>
1 parent a483a5a commit fc16a52

File tree

6 files changed

+32
-1
lines changed

6 files changed

+32
-1
lines changed

runtime/vm/compiler/frontend/kernel_to_il.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,7 @@ bool FlowGraphBuilder::IsRecognizedMethodForFlowGraph(
11031103
case MethodRecognizer::kClassIDgetID:
11041104
case MethodRecognizer::kGrowableArrayAllocateWithData:
11051105
case MethodRecognizer::kGrowableArrayCapacity:
1106+
case MethodRecognizer::kGrowableArrayGetEmptyList:
11061107
case MethodRecognizer::kObjectArrayAllocate:
11071108
case MethodRecognizer::kCopyRangeFromUint8ListToOneByteString:
11081109
case MethodRecognizer::kImmutableLinkedHashBase_setIndexStoreRelease:
@@ -1482,6 +1483,9 @@ FlowGraph* FlowGraphBuilder::BuildGraphOfRecognizedMethod(
14821483
body += LoadNativeField(Slot::GrowableObjectArray_data());
14831484
body += LoadNativeField(Slot::Array_length());
14841485
break;
1486+
case MethodRecognizer::kGrowableArrayGetEmptyList:
1487+
body += Constant(Object::mutable_empty_array());
1488+
break;
14851489
case MethodRecognizer::kObjectArrayAllocate:
14861490
ASSERT(function.IsFactory() && (function.NumParameters() == 2));
14871491
body += LoadLocal(parsed_function_->RawParameterVariable(0));

runtime/vm/compiler/recognized_methods_list.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ namespace dart {
3838
V(CoreLibrary, _GrowableList, ._withData, GrowableArrayAllocateWithData, \
3939
0x192ac0e1) \
4040
V(CoreLibrary, _GrowableList, []=, GrowableArraySetIndexed, 0x3a23c6fa) \
41+
V(CoreLibrary, _GrowableList, get:_emptyList, GrowableArrayGetEmptyList, \
42+
0x735785f0) \
4143
V(CoreLibrary, _Record, get:_fieldNames, Record_fieldNames, 0x68c8319e) \
4244
V(CoreLibrary, _Record, get:_numFields, Record_numFields, 0x7ba4f393) \
4345
V(CoreLibrary, _Record, get:_shape, Record_shape, 0x70c40933) \

runtime/vm/object.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,7 @@ void Object::Init(IsolateGroup* isolate_group) {
781781
*empty_array_ = Array::null();
782782
*empty_instantiations_cache_array_ = Array::null();
783783
*empty_subtype_test_cache_array_ = Array::null();
784+
*mutable_empty_array_ = Array::null();
784785

785786
Class& cls = Class::Handle();
786787

@@ -1036,6 +1037,14 @@ void Object::Init(IsolateGroup* isolate_group) {
10361037
empty_array_->untag()->set_length(Smi::New(0));
10371038
empty_array_->SetCanonical();
10381039
}
1040+
{
1041+
uword address = heap->Allocate(thread, Array::InstanceSize(0), Heap::kOld);
1042+
InitializeObjectVariant<Array>(address, kArrayCid, 0);
1043+
Array::initializeHandle(mutable_empty_array_,
1044+
static_cast<ArrayPtr>(address + kHeapObjectTag));
1045+
mutable_empty_array_->untag()->set_length(Smi::New(0));
1046+
mutable_empty_array_->SetCanonical();
1047+
}
10391048

10401049
Smi& smi = Smi::Handle();
10411050
// Allocate and initialize the empty instantiations cache array instance,

runtime/vm/object.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ class Object {
514514
V(Array, empty_array) \
515515
V(Array, empty_instantiations_cache_array) \
516516
V(Array, empty_subtype_test_cache_array) \
517+
V(Array, mutable_empty_array) \
517518
V(ContextScope, empty_context_scope) \
518519
V(ObjectPool, empty_object_pool) \
519520
V(CompressedStackMaps, empty_compressed_stackmaps) \

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,10 @@ class _GrowableList<T> extends ListBase<T> {
364364
}
365365

366366
// Shared array used as backing for new empty growable arrays.
367-
static final _List _emptyList = _List(0);
367+
@pragma("vm:prefer-inline")
368+
@pragma("vm:recognized", "other")
369+
@pragma("vm:exact-result-type", "dart:core#_List")
370+
external static _List get _emptyList;
368371

369372
static _List _allocateData(int capacity) {
370373
if (capacity == 0) {

tests/ffi/run_isolate_group_run_test.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,19 @@ bar() {
4444
Baz.foo = 42;
4545
}
4646

47+
@pragma('vm:shared')
48+
var list_length = 0;
49+
4750
main() {
51+
IsolateGroup.runSync(() {
52+
final l = <int>[];
53+
for (int i = 0; i < 100; i++) {
54+
l.add(i);
55+
}
56+
list_length = l.length;
57+
});
58+
Expect.equals(100, list_length);
59+
4860
Expect.equals(42, IsolateGroup.runSync(() => 42));
4961

5062
Expect.listEquals([1, 2, 3], IsolateGroup.runSync(() => [1, 2, 3]));

0 commit comments

Comments
 (0)