Skip to content

Commit 10bf1cf

Browse files
rmacnak-googleCommit Bot
authored and
Commit Bot
committed
Revert "[vm] Recognize unmodifiabled typed data views."
This reverts commit d1112d3. Reason for revert: b/242043014 Original change's description: > [vm] Recognize unmodifiabled typed data views. > > These types now work with Dart_TypedDataAcquireData. > > The presence of these types no longer degrades the performance of typed data indexed loads. > > The presence of these types degrades the performance of typed data indexed stores much less. The performance of indexed stores is somewhat regressed if these types were not used. > > TEST=ci > Bug: #32028 > Bug: #40924 > Bug: #42785 > Change-Id: I05ac5c9543f6f61ac37533b9efe511254778caed > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/253700 > Reviewed-by: Aske Simon Christensen <[email protected]> > Reviewed-by: Martin Kustermann <[email protected]> > Commit-Queue: Ryan Macnak <[email protected]> [email protected],[email protected],[email protected] TEST=ci Change-Id: I32c1c460fc30c51bc0d42e7cfaafe72bf5630069 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: #32028 Bug: #40924 Bug: #42785 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/254560 Reviewed-by: Siva Annamalai <[email protected]> Reviewed-by: Ryan Macnak <[email protected]> Commit-Queue: Ryan Macnak <[email protected]>
1 parent b7439ef commit 10bf1cf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+3006
-5886
lines changed

runtime/lib/typed_data.cc

+1-9
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ static bool IsClamped(intptr_t cid) {
9494
case kTypedDataUint8ClampedArrayCid:
9595
case kExternalTypedDataUint8ClampedArrayCid:
9696
case kTypedDataUint8ClampedArrayViewCid:
97-
case kUnmodifiableTypedDataUint8ClampedArrayViewCid:
9897
return true;
9998
default:
10099
return false;
@@ -106,11 +105,9 @@ static bool IsUint8(intptr_t cid) {
106105
case kTypedDataUint8ClampedArrayCid:
107106
case kExternalTypedDataUint8ClampedArrayCid:
108107
case kTypedDataUint8ClampedArrayViewCid:
109-
case kUnmodifiableTypedDataUint8ClampedArrayViewCid:
110108
case kTypedDataUint8ArrayCid:
111109
case kExternalTypedDataUint8ArrayCid:
112110
case kTypedDataUint8ArrayViewCid:
113-
case kUnmodifiableTypedDataUint8ArrayViewCid:
114111
return true;
115112
default:
116113
return false;
@@ -189,15 +186,10 @@ static InstancePtr NewTypedDataView(intptr_t cid,
189186
}
190187

191188
#define TYPED_DATA_NEW_NATIVE(name) \
192-
TYPED_DATA_VIEW_NEW(TypedDataView_##name##View_new, \
193-
kTypedData##name##ViewCid) \
194-
TYPED_DATA_VIEW_NEW(TypedDataView_Unmodifiable##name##View_new, \
195-
kUnmodifiableTypedData##name##ViewCid)
189+
TYPED_DATA_VIEW_NEW(TypedDataView_##name##View_new, kTypedData##name##ViewCid)
196190

197191
CLASS_LIST_TYPED_DATA(TYPED_DATA_NEW_NATIVE)
198192
TYPED_DATA_VIEW_NEW(TypedDataView_ByteDataView_new, kByteDataViewCid)
199-
TYPED_DATA_VIEW_NEW(TypedDataView_UnmodifiableByteDataView_new,
200-
kUnmodifiableByteDataViewCid)
201193
#undef TYPED_DATA_NEW_NATIVE
202194
#undef TYPED_DATA_VIEW_NEW
203195

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (c) 2021, 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+
// This test asserts that we are not inlining accesses to typed data interfaces
6+
// (e.g. Uint8List) if there are instantiated 3rd party classes (e.g.
7+
// UnmodifiableUint8ListView).
8+
9+
import 'dart:typed_data';
10+
import 'package:vm/testing/il_matchers.dart';
11+
12+
createThirdPartyUint8List() => UnmodifiableUint8ListView(Uint8List(10));
13+
14+
@pragma('vm:never-inline')
15+
@pragma('vm:testing:print-flow-graph')
16+
void foo(Uint8List list, int from) {
17+
if (from >= list.length) {
18+
list[from];
19+
}
20+
}
21+
22+
void matchIL$foo(FlowGraph graph) {
23+
graph.match([
24+
match.block('Graph'),
25+
match.block('Function', [
26+
'list' << match.Parameter(index: 0),
27+
'from' << match.Parameter(index: 1),
28+
'v13' << match.LoadClassId('list'),
29+
match.PushArgument('list'),
30+
match.DispatchTableCall('v13', selector_name: 'get:length'),
31+
match.Branch(match.RelationalOp(match.any, match.any, kind: '>='),
32+
ifTrue: 'B3'),
33+
]),
34+
'B3' <<
35+
match.block('Target', [
36+
'v15' << match.LoadClassId('list'),
37+
match.PushArgument('list'),
38+
match.PushArgument(/* BoxInt64(Parameter) or Parameter */),
39+
match.DispatchTableCall('v15', selector_name: '[]'),
40+
]),
41+
]);
42+
}
43+
44+
void main() {
45+
foo(int.parse('1') == 1 ? createThirdPartyUint8List() : Uint8List(1),
46+
int.parse('0'));
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (c) 2021, 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+
// This test asserts that we are not inlining accesses to typed data interfaces
6+
// (e.g. Uint8List) if there are instantiated 3rd party classes (e.g.
7+
// UnmodifiableUint8ListView).
8+
9+
import 'dart:typed_data';
10+
import 'package:vm/testing/il_matchers.dart';
11+
12+
createThirdPartyUint8List() => UnmodifiableUint8ListView(Uint8List(10));
13+
14+
@pragma('vm:never-inline')
15+
@pragma('vm:testing:print-flow-graph')
16+
void foo(Uint8List list, int from) {
17+
if (from >= list.length) {
18+
list[from];
19+
}
20+
}
21+
22+
void matchIL$foo(FlowGraph graph) {
23+
graph.match([
24+
match.block('Graph'),
25+
match.block('Function', [
26+
'list' << match.Parameter(index: 0),
27+
'from' << match.Parameter(index: 1),
28+
'v13' << match.LoadClassId('list'),
29+
match.PushArgument('list'),
30+
match.DispatchTableCall('v13', selector_name: 'get:length'),
31+
match.Branch(match.RelationalOp(match.any, match.any, kind: '>='),
32+
ifTrue: 'B3'),
33+
]),
34+
'B3' <<
35+
match.block('Target', [
36+
'v15' << match.LoadClassId('list'),
37+
match.PushArgument('list'),
38+
match.PushArgument(/* BoxInt64(Parameter) or Parameter */),
39+
match.DispatchTableCall('v15', selector_name: '[]'),
40+
]),
41+
]);
42+
}
43+
44+
void main() {
45+
foo(int.parse('1') == 1 ? createThirdPartyUint8List() : Uint8List(1),
46+
int.parse('0'));
47+
}

runtime/vm/bootstrap_natives.h

-15
Original file line numberDiff line numberDiff line change
@@ -217,21 +217,6 @@ namespace dart {
217217
V(TypedDataView_Float64x2ArrayView_new, 4) \
218218
V(TypedDataView_offsetInBytes, 1) \
219219
V(TypedDataView_typedData, 1) \
220-
V(TypedDataView_UnmodifiableByteDataView_new, 4) \
221-
V(TypedDataView_UnmodifiableInt8ArrayView_new, 4) \
222-
V(TypedDataView_UnmodifiableUint8ArrayView_new, 4) \
223-
V(TypedDataView_UnmodifiableUint8ClampedArrayView_new, 4) \
224-
V(TypedDataView_UnmodifiableInt16ArrayView_new, 4) \
225-
V(TypedDataView_UnmodifiableUint16ArrayView_new, 4) \
226-
V(TypedDataView_UnmodifiableInt32ArrayView_new, 4) \
227-
V(TypedDataView_UnmodifiableUint32ArrayView_new, 4) \
228-
V(TypedDataView_UnmodifiableInt64ArrayView_new, 4) \
229-
V(TypedDataView_UnmodifiableUint64ArrayView_new, 4) \
230-
V(TypedDataView_UnmodifiableFloat32ArrayView_new, 4) \
231-
V(TypedDataView_UnmodifiableFloat64ArrayView_new, 4) \
232-
V(TypedDataView_UnmodifiableFloat32x4ArrayView_new, 4) \
233-
V(TypedDataView_UnmodifiableInt32x4ArrayView_new, 4) \
234-
V(TypedDataView_UnmodifiableFloat64x2ArrayView_new, 4) \
235220
V(Float32x4_fromDoubles, 4) \
236221
V(Float32x4_splat, 1) \
237222
V(Float32x4_fromInt32x4Bits, 2) \

runtime/vm/class_id.h

+22-36
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,10 @@ enum ClassId : intptr_t {
233233
#define DEFINE_OBJECT_KIND(clazz) \
234234
kTypedData##clazz##Cid, \
235235
kTypedData##clazz##ViewCid, \
236-
kExternalTypedData##clazz##Cid, \
237-
kUnmodifiableTypedData##clazz##ViewCid,
236+
kExternalTypedData##clazz##Cid,
238237
CLASS_LIST_TYPED_DATA(DEFINE_OBJECT_KIND)
239238
#undef DEFINE_OBJECT_KIND
240239
kByteDataViewCid,
241-
kUnmodifiableByteDataViewCid,
242240

243241
kByteBufferCid,
244242
// clang-format on
@@ -257,7 +255,6 @@ enum ClassId : intptr_t {
257255
const int kTypedDataCidRemainderInternal = 0;
258256
const int kTypedDataCidRemainderView = 1;
259257
const int kTypedDataCidRemainderExternal = 2;
260-
const int kTypedDataCidRemainderUnmodifiable = 3;
261258

262259
// Class Id predicates.
263260

@@ -364,45 +361,34 @@ inline bool IsTypeClassId(intptr_t index) {
364361

365362
inline bool IsTypedDataBaseClassId(intptr_t index) {
366363
// Make sure this is updated when new TypedData types are added.
367-
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 4 == kTypedDataUint8ArrayCid);
364+
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 3 == kTypedDataUint8ArrayCid);
368365
return index >= kTypedDataInt8ArrayCid && index < kByteDataViewCid;
369366
}
370367

371368
inline bool IsTypedDataClassId(intptr_t index) {
372369
// Make sure this is updated when new TypedData types are added.
373-
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 4 == kTypedDataUint8ArrayCid);
370+
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 3 == kTypedDataUint8ArrayCid);
374371
return IsTypedDataBaseClassId(index) && ((index - kTypedDataInt8ArrayCid) %
375-
4) == kTypedDataCidRemainderInternal;
372+
3) == kTypedDataCidRemainderInternal;
376373
}
377374

378375
inline bool IsTypedDataViewClassId(intptr_t index) {
379376
// Make sure this is updated when new TypedData types are added.
380-
COMPILE_ASSERT(kTypedDataInt8ArrayViewCid + 4 == kTypedDataUint8ArrayViewCid);
377+
COMPILE_ASSERT(kTypedDataInt8ArrayViewCid + 3 == kTypedDataUint8ArrayViewCid);
381378

382379
const bool is_byte_data_view = index == kByteDataViewCid;
383380
return is_byte_data_view ||
384381
(IsTypedDataBaseClassId(index) &&
385-
((index - kTypedDataInt8ArrayCid) % 4) == kTypedDataCidRemainderView);
382+
((index - kTypedDataInt8ArrayCid) % 3) == kTypedDataCidRemainderView);
386383
}
387384

388385
inline bool IsExternalTypedDataClassId(intptr_t index) {
389386
// Make sure this is updated when new TypedData types are added.
390-
COMPILE_ASSERT(kExternalTypedDataInt8ArrayCid + 4 ==
387+
COMPILE_ASSERT(kExternalTypedDataInt8ArrayCid + 3 ==
391388
kExternalTypedDataUint8ArrayCid);
392389

393390
return IsTypedDataBaseClassId(index) && ((index - kTypedDataInt8ArrayCid) %
394-
4) == kTypedDataCidRemainderExternal;
395-
}
396-
397-
inline bool IsUnmodifiableTypedDataViewClassId(intptr_t index) {
398-
// Make sure this is updated when new TypedData types are added.
399-
COMPILE_ASSERT(kExternalTypedDataInt8ArrayCid + 4 ==
400-
kExternalTypedDataUint8ArrayCid);
401-
402-
const bool is_byte_data_view = index == kUnmodifiableByteDataViewCid;
403-
return is_byte_data_view || (IsTypedDataBaseClassId(index) &&
404-
((index - kTypedDataInt8ArrayCid) % 4) ==
405-
kTypedDataCidRemainderUnmodifiable);
391+
3) == kTypedDataCidRemainderExternal;
406392
}
407393

408394
inline bool IsFfiTypeClassId(intptr_t index) {
@@ -460,21 +446,21 @@ COMPILE_ASSERT(kTypedDataInt8ArrayCid + 1 == kTypedDataInt8ArrayViewCid);
460446
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 2 == kExternalTypedDataInt8ArrayCid);
461447

462448
// Ensure the order of the typed data members in 3-step.
463-
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 1 * 4 == kTypedDataUint8ArrayCid);
464-
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 2 * 4 ==
449+
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 1 * 3 == kTypedDataUint8ArrayCid);
450+
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 2 * 3 ==
465451
kTypedDataUint8ClampedArrayCid);
466-
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 3 * 4 == kTypedDataInt16ArrayCid);
467-
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 4 * 4 == kTypedDataUint16ArrayCid);
468-
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 5 * 4 == kTypedDataInt32ArrayCid);
469-
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 6 * 4 == kTypedDataUint32ArrayCid);
470-
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 7 * 4 == kTypedDataInt64ArrayCid);
471-
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 8 * 4 == kTypedDataUint64ArrayCid);
472-
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 9 * 4 == kTypedDataFloat32ArrayCid);
473-
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 10 * 4 == kTypedDataFloat64ArrayCid);
474-
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 11 * 4 == kTypedDataFloat32x4ArrayCid);
475-
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 12 * 4 == kTypedDataInt32x4ArrayCid);
476-
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 13 * 4 == kTypedDataFloat64x2ArrayCid);
477-
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 14 * 4 == kByteDataViewCid);
452+
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 3 * 3 == kTypedDataInt16ArrayCid);
453+
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 4 * 3 == kTypedDataUint16ArrayCid);
454+
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 5 * 3 == kTypedDataInt32ArrayCid);
455+
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 6 * 3 == kTypedDataUint32ArrayCid);
456+
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 7 * 3 == kTypedDataInt64ArrayCid);
457+
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 8 * 3 == kTypedDataUint64ArrayCid);
458+
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 9 * 3 == kTypedDataFloat32ArrayCid);
459+
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 10 * 3 == kTypedDataFloat64ArrayCid);
460+
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 11 * 3 == kTypedDataFloat32x4ArrayCid);
461+
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 12 * 3 == kTypedDataInt32x4ArrayCid);
462+
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 13 * 3 == kTypedDataFloat64x2ArrayCid);
463+
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 14 * 3 == kByteDataViewCid);
478464
COMPILE_ASSERT(kByteBufferCid + 1 == kNullCid);
479465

480466
} // namespace dart

runtime/vm/compiler/backend/constant_propagator.cc

-7
Original file line numberDiff line numberDiff line change
@@ -409,13 +409,6 @@ void ConstantPropagator::VisitGenericCheckBound(GenericCheckBoundInstr* instr) {
409409
SetValue(instr, non_constant_);
410410
}
411411

412-
void ConstantPropagator::VisitCheckWritable(CheckWritableInstr* instr) {
413-
// Don't propagate constants through check, since it would eliminate
414-
// the data dependence between the writable check and its use.
415-
// Graph finalization will expose the constant eventually.
416-
SetValue(instr, non_constant_);
417-
}
418-
419412
void ConstantPropagator::VisitCheckNull(CheckNullInstr* instr) {
420413
// Don't propagate constants through check, since it would eliminate
421414
// the data dependence between the null check and its use.

runtime/vm/compiler/backend/flow_graph_compiler.cc

-30
Original file line numberDiff line numberDiff line change
@@ -3405,36 +3405,6 @@ void RangeErrorSlowPath::PushArgumentsForRuntimeCall(
34053405
locs->in(CheckBoundBase::kLengthPos).reg());
34063406
}
34073407

3408-
void RangeErrorSlowPath::EmitSharedStubCall(FlowGraphCompiler* compiler,
3409-
bool save_fpu_registers) {
3410-
#if defined(TARGET_ARCH_IA32)
3411-
UNREACHABLE();
3412-
#else
3413-
auto object_store = compiler->isolate_group()->object_store();
3414-
const auto& stub = Code::ZoneHandle(
3415-
compiler->zone(),
3416-
save_fpu_registers
3417-
? object_store->range_error_stub_with_fpu_regs_stub()
3418-
: object_store->range_error_stub_without_fpu_regs_stub());
3419-
compiler->EmitCallToStub(stub);
3420-
#endif
3421-
}
3422-
3423-
void WriteErrorSlowPath::EmitSharedStubCall(FlowGraphCompiler* compiler,
3424-
bool save_fpu_registers) {
3425-
#if defined(TARGET_ARCH_IA32)
3426-
UNREACHABLE();
3427-
#else
3428-
auto object_store = compiler->isolate_group()->object_store();
3429-
const auto& stub = Code::ZoneHandle(
3430-
compiler->zone(),
3431-
save_fpu_registers
3432-
? object_store->write_error_stub_with_fpu_regs_stub()
3433-
: object_store->write_error_stub_without_fpu_regs_stub());
3434-
compiler->EmitCallToStub(stub);
3435-
#endif
3436-
}
3437-
34383408
void LateInitializationErrorSlowPath::PushArgumentsForRuntimeCall(
34393409
FlowGraphCompiler* compiler) {
34403410
__ PushObject(Field::ZoneHandle(OriginalField()));

runtime/vm/compiler/backend/flow_graph_compiler.h

-10
Original file line numberDiff line numberDiff line change
@@ -386,16 +386,6 @@ class RangeErrorSlowPath : public ThrowErrorSlowPathCode {
386386
bool save_fpu_registers);
387387
};
388388

389-
class WriteErrorSlowPath : public ThrowErrorSlowPathCode {
390-
public:
391-
explicit WriteErrorSlowPath(CheckWritableInstr* instruction)
392-
: ThrowErrorSlowPathCode(instruction, kWriteErrorRuntimeEntry) {}
393-
virtual const char* name() { return "check writable"; }
394-
395-
virtual void EmitSharedStubCall(FlowGraphCompiler* compiler,
396-
bool save_fpu_registers);
397-
};
398-
399389
class LateInitializationErrorSlowPath : public ThrowErrorSlowPathCode {
400390
public:
401391
explicit LateInitializationErrorSlowPath(Instruction* instruction)

0 commit comments

Comments
 (0)