Skip to content

Commit b75b265

Browse files
alexmarkovCommit Queue
authored andcommitted
[vm,corelib] Change static type of _Hash*Base._data to match runtime type
VM uses _List<dynamic> for _HashVMBase._data, _HashVMImmutableBase._data and _uninitializedData at run time. Core library declares _data as List<Object?> and sometimes sets it to List<Object?>. This discrepancy between runtime type and static type sometimes causes performance regressions, because speculative exactness guard checks if runtime type arguments are exactly the same as type arguments of a static type, and deoptimization is triggered if they don't match. Since https://dart-review.googlesource.com/c/sdk/+/440064, VM evaluates type arguments of _HashVMBase._data and _HashVMImmutableBase._data as <dynamic> at compile time, so exactness guard against _data fails more often, which considerably affects performance in JIT mode. This change aligns runtime and static types of _data, making sure exactness guard against _data is always successful. TEST=ci, golem Change-Id: Ia842b57a372305001b5210ca59206992611c5fa7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/440681 Reviewed-by: Ryan Macnak <[email protected]> Commit-Queue: Alexander Markov <[email protected]>
1 parent 4e0e197 commit b75b265

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

runtime/vm/compiler/recognized_methods_list.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ namespace dart {
8080
V(CompactHashLibrary, _HashVMBase, set:_index, LinkedHashBase_setIndex, \
8181
0xcf36944c) \
8282
V(CompactHashLibrary, _HashVMBase, get:_data, LinkedHashBase_getData, \
83-
0x372bf7ad) \
83+
0x82aeadd7) \
8484
V(CompactHashLibrary, _HashVMBase, set:_data, LinkedHashBase_setData, \
85-
0x4b9888e9) \
85+
0xc1465c93) \
8686
V(CompactHashLibrary, _HashVMBase, get:_usedData, \
8787
LinkedHashBase_getUsedData, 0x74808f38) \
8888
V(CompactHashLibrary, _HashVMBase, set:_usedData, \
@@ -96,15 +96,15 @@ namespace dart {
9696
V(CompactHashLibrary, _HashVMBase, set:_deletedKeys, \
9797
LinkedHashBase_setDeletedKeys, 0xe2aeac51) \
9898
V(CompactHashLibrary, _HashVMImmutableBase, get:_data, \
99-
ImmutableLinkedHashBase_getData, 0x372bf7ad) \
99+
ImmutableLinkedHashBase_getData, 0x82aeadd7) \
100100
V(CompactHashLibrary, _HashVMImmutableBase, get:_indexNullable, \
101101
ImmutableLinkedHashBase_getIndex, 0xfe7649ae) \
102102
V(CompactHashLibrary, _HashVMImmutableBase, set:_index, \
103103
ImmutableLinkedHashBase_setIndexStoreRelease, 0xcf36944c) \
104104
V(CompactHashLibrary, ::, get:_uninitializedIndex, \
105105
CompactHash_uninitializedIndex, 0xa25a79e6) \
106106
V(CompactHashLibrary, ::, get:_uninitializedData, \
107-
CompactHash_uninitializedData, 0x06a56b3b) \
107+
CompactHash_uninitializedData, 0x52282165) \
108108
V(DeveloperLibrary, ::, get:extensionStreamHasListener, \
109109
ExtensionStreamHasListener, 0xfa975305) \
110110
V(DeveloperLibrary, ::, debugger, Debugger, 0xf0aaff14) \

sdk/lib/_internal/vm_shared/lib/compact_hash.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ abstract class _HashAbstractBase {
115115

116116
abstract int _hashMask;
117117

118-
abstract List<Object?> _data;
118+
abstract List _data;
119119

120120
abstract int _usedData;
121121

@@ -151,7 +151,7 @@ abstract class _HashFieldBase implements _HashAbstractImmutableBase {
151151
// Fixed-length list of keys (set) or key/value at even/odd indices (map).
152152
//
153153
// Can be either a mutable or immutable list.
154-
List<Object?> _data = _uninitializedData;
154+
List _data = _uninitializedData;
155155

156156
// Length of _data that is used (i.e., keys + values for a map).
157157
int _usedData = 0;
@@ -186,10 +186,10 @@ abstract class _HashVMBase implements _HashAbstractBase {
186186
@pragma("vm:recognized", "other")
187187
@pragma("vm:exact-result-type", "dart:core#_List")
188188
@pragma("vm:prefer-inline")
189-
external List<Object?> get _data;
189+
external List get _data;
190190
@pragma("vm:recognized", "other")
191191
@pragma("vm:prefer-inline")
192-
external void set _data(List<Object?> value);
192+
external void set _data(List value);
193193

194194
@pragma("vm:recognized", "other")
195195
@pragma("vm:exact-result-type", "dart:core#_Smi")
@@ -215,7 +215,7 @@ abstract class _HashVMImmutableBase extends _HashVMBase
215215
@pragma("vm:recognized", "other")
216216
@pragma("vm:exact-result-type", "dart:core#_ImmutableList")
217217
@pragma("vm:prefer-inline")
218-
external List<Object?> get _data;
218+
external List get _data;
219219

220220
// The index is nullable rather than not nullable.
221221
@pragma("vm:recognized", "other")
@@ -282,16 +282,16 @@ mixin _HashBase on _HashAbstractBase {
282282
static int _nextProbe(int i, int sizeMask) => (i + 1) & sizeMask;
283283

284284
// A self-loop is used to mark a deleted key or value.
285-
static bool _isDeleted(List<Object?> data, Object? keyOrValue) =>
285+
static bool _isDeleted(List data, Object? keyOrValue) =>
286286
identical(keyOrValue, data);
287-
static void _setDeletedAt(List<Object?> data, int d) {
287+
static void _setDeletedAt(List data, int d) {
288288
data[d] = data;
289289
}
290290

291291
// Concurrent modification detection relies on this checksum monotonically
292292
// increasing between reallocations of _data.
293293
int get _checkSum => _usedData + _deletedKeys;
294-
bool _isModifiedSince(List<Object?> oldData, int oldCheckSum) =>
294+
bool _isModifiedSince(List oldData, int oldCheckSum) =>
295295
!identical(_data, oldData) || (_checkSum != oldCheckSum);
296296

297297
int get length;
@@ -311,7 +311,7 @@ mixin _HashBase on _HashAbstractBase {
311311
assert(!identical(other._data, _uninitializedData));
312312
_index = Uint32List.fromList(other._index);
313313
_hashMask = other._hashMask;
314-
_data = List<Object?>.of(other._data, growable: false);
314+
_data = List.of(other._data, growable: false);
315315
_usedData = other._usedData;
316316
_deletedKeys = other._deletedKeys;
317317
return true;
@@ -371,7 +371,7 @@ external Uint32List get _uninitializedIndex;
371371
@pragma("vm:prefer-inline")
372372
@pragma("vm:recognized", "other")
373373
@pragma("vm:exact-result-type", "dart:core#_List")
374-
external List<Object?> get _uninitializedData;
374+
external List get _uninitializedData;
375375

376376
// VM-internalized implementation of a default-constructed LinkedHashMap. Map
377377
// literals also create instances of this class.
@@ -546,7 +546,7 @@ mixin _LinkedHashMapMixin<K, V> on _HashBase, _EqualsAndHashCode {
546546
/// This function is unsafe: it does not perform any type checking on
547547
/// keys and values assuming that caller has ensured that types are
548548
/// correct.
549-
void _populateUnsafe(List<Object?> keyValuePairs) {
549+
void _populateUnsafe(List keyValuePairs) {
550550
assert(keyValuePairs.length.isEven);
551551
int size = _roundUpToPowerOfTwo(keyValuePairs.length);
552552
if (size < _HashBase._INITIAL_INDEX_SIZE) {
@@ -1338,5 +1338,5 @@ typedef DefaultMap<K, V> = _Map<K, V>;
13381338
typedef DefaultSet<E> = _Set<E>;
13391339

13401340
@pragma('vm:prefer-inline')
1341-
Map<K, V> createMapFromKeyValueListUnsafe<K, V>(List<Object?> keyValuePairs) =>
1341+
Map<K, V> createMapFromKeyValueListUnsafe<K, V>(List keyValuePairs) =>
13421342
DefaultMap<K, V>().._populateUnsafe(keyValuePairs);

0 commit comments

Comments
 (0)