Skip to content

Commit

Permalink
[vm] Recognize unmodifiabled typed data views.
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
rmacnak-google authored and Commit Bot committed Aug 9, 2022
1 parent 709b878 commit d1112d3
Show file tree
Hide file tree
Showing 57 changed files with 5,886 additions and 3,006 deletions.
10 changes: 9 additions & 1 deletion runtime/lib/typed_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ static bool IsClamped(intptr_t cid) {
case kTypedDataUint8ClampedArrayCid:
case kExternalTypedDataUint8ClampedArrayCid:
case kTypedDataUint8ClampedArrayViewCid:
case kUnmodifiableTypedDataUint8ClampedArrayViewCid:
return true;
default:
return false;
Expand All @@ -105,9 +106,11 @@ static bool IsUint8(intptr_t cid) {
case kTypedDataUint8ClampedArrayCid:
case kExternalTypedDataUint8ClampedArrayCid:
case kTypedDataUint8ClampedArrayViewCid:
case kUnmodifiableTypedDataUint8ClampedArrayViewCid:
case kTypedDataUint8ArrayCid:
case kExternalTypedDataUint8ArrayCid:
case kTypedDataUint8ArrayViewCid:
case kUnmodifiableTypedDataUint8ArrayViewCid:
return true;
default:
return false;
Expand Down Expand Up @@ -186,10 +189,15 @@ static InstancePtr NewTypedDataView(intptr_t cid,
}

#define TYPED_DATA_NEW_NATIVE(name) \
TYPED_DATA_VIEW_NEW(TypedDataView_##name##View_new, kTypedData##name##ViewCid)
TYPED_DATA_VIEW_NEW(TypedDataView_##name##View_new, \
kTypedData##name##ViewCid) \
TYPED_DATA_VIEW_NEW(TypedDataView_Unmodifiable##name##View_new, \
kUnmodifiableTypedData##name##ViewCid)

CLASS_LIST_TYPED_DATA(TYPED_DATA_NEW_NATIVE)
TYPED_DATA_VIEW_NEW(TypedDataView_ByteDataView_new, kByteDataViewCid)
TYPED_DATA_VIEW_NEW(TypedDataView_UnmodifiableByteDataView_new,
kUnmodifiableByteDataViewCid)
#undef TYPED_DATA_NEW_NATIVE
#undef TYPED_DATA_VIEW_NEW

Expand Down
47 changes: 0 additions & 47 deletions runtime/tests/vm/dart/typed_data_aot_not_inlining_il_test.dart

This file was deleted.

47 changes: 0 additions & 47 deletions runtime/tests/vm/dart_2/typed_data_aot_not_inlining_il_test.dart

This file was deleted.

15 changes: 15 additions & 0 deletions runtime/vm/bootstrap_natives.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,21 @@ namespace dart {
V(TypedDataView_Float64x2ArrayView_new, 4) \
V(TypedDataView_offsetInBytes, 1) \
V(TypedDataView_typedData, 1) \
V(TypedDataView_UnmodifiableByteDataView_new, 4) \
V(TypedDataView_UnmodifiableInt8ArrayView_new, 4) \
V(TypedDataView_UnmodifiableUint8ArrayView_new, 4) \
V(TypedDataView_UnmodifiableUint8ClampedArrayView_new, 4) \
V(TypedDataView_UnmodifiableInt16ArrayView_new, 4) \
V(TypedDataView_UnmodifiableUint16ArrayView_new, 4) \
V(TypedDataView_UnmodifiableInt32ArrayView_new, 4) \
V(TypedDataView_UnmodifiableUint32ArrayView_new, 4) \
V(TypedDataView_UnmodifiableInt64ArrayView_new, 4) \
V(TypedDataView_UnmodifiableUint64ArrayView_new, 4) \
V(TypedDataView_UnmodifiableFloat32ArrayView_new, 4) \
V(TypedDataView_UnmodifiableFloat64ArrayView_new, 4) \
V(TypedDataView_UnmodifiableFloat32x4ArrayView_new, 4) \
V(TypedDataView_UnmodifiableInt32x4ArrayView_new, 4) \
V(TypedDataView_UnmodifiableFloat64x2ArrayView_new, 4) \
V(Float32x4_fromDoubles, 4) \
V(Float32x4_splat, 1) \
V(Float32x4_fromInt32x4Bits, 2) \
Expand Down
58 changes: 36 additions & 22 deletions runtime/vm/class_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,12 @@ enum ClassId : intptr_t {
#define DEFINE_OBJECT_KIND(clazz) \
kTypedData##clazz##Cid, \
kTypedData##clazz##ViewCid, \
kExternalTypedData##clazz##Cid,
kExternalTypedData##clazz##Cid, \
kUnmodifiableTypedData##clazz##ViewCid,
CLASS_LIST_TYPED_DATA(DEFINE_OBJECT_KIND)
#undef DEFINE_OBJECT_KIND
kByteDataViewCid,
kUnmodifiableByteDataViewCid,

kByteBufferCid,
// clang-format on
Expand All @@ -255,6 +257,7 @@ enum ClassId : intptr_t {
const int kTypedDataCidRemainderInternal = 0;
const int kTypedDataCidRemainderView = 1;
const int kTypedDataCidRemainderExternal = 2;
const int kTypedDataCidRemainderUnmodifiable = 3;

// Class Id predicates.

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

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

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

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

const bool is_byte_data_view = index == kByteDataViewCid;
return is_byte_data_view ||
(IsTypedDataBaseClassId(index) &&
((index - kTypedDataInt8ArrayCid) % 3) == kTypedDataCidRemainderView);
((index - kTypedDataInt8ArrayCid) % 4) == kTypedDataCidRemainderView);
}

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

return IsTypedDataBaseClassId(index) && ((index - kTypedDataInt8ArrayCid) %
3) == kTypedDataCidRemainderExternal;
4) == kTypedDataCidRemainderExternal;
}

inline bool IsUnmodifiableTypedDataViewClassId(intptr_t index) {
// Make sure this is updated when new TypedData types are added.
COMPILE_ASSERT(kExternalTypedDataInt8ArrayCid + 4 ==
kExternalTypedDataUint8ArrayCid);

const bool is_byte_data_view = index == kUnmodifiableByteDataViewCid;
return is_byte_data_view || (IsTypedDataBaseClassId(index) &&
((index - kTypedDataInt8ArrayCid) % 4) ==
kTypedDataCidRemainderUnmodifiable);
}

inline bool IsFfiTypeClassId(intptr_t index) {
Expand Down Expand Up @@ -446,21 +460,21 @@ COMPILE_ASSERT(kTypedDataInt8ArrayCid + 1 == kTypedDataInt8ArrayViewCid);
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 2 == kExternalTypedDataInt8ArrayCid);

// Ensure the order of the typed data members in 3-step.
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 1 * 3 == kTypedDataUint8ArrayCid);
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 2 * 3 ==
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 1 * 4 == kTypedDataUint8ArrayCid);
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 2 * 4 ==
kTypedDataUint8ClampedArrayCid);
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 3 * 3 == kTypedDataInt16ArrayCid);
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 4 * 3 == kTypedDataUint16ArrayCid);
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 5 * 3 == kTypedDataInt32ArrayCid);
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 6 * 3 == kTypedDataUint32ArrayCid);
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 7 * 3 == kTypedDataInt64ArrayCid);
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 8 * 3 == kTypedDataUint64ArrayCid);
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 9 * 3 == kTypedDataFloat32ArrayCid);
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 10 * 3 == kTypedDataFloat64ArrayCid);
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 11 * 3 == kTypedDataFloat32x4ArrayCid);
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 12 * 3 == kTypedDataInt32x4ArrayCid);
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 13 * 3 == kTypedDataFloat64x2ArrayCid);
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 14 * 3 == kByteDataViewCid);
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 3 * 4 == kTypedDataInt16ArrayCid);
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 4 * 4 == kTypedDataUint16ArrayCid);
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 5 * 4 == kTypedDataInt32ArrayCid);
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 6 * 4 == kTypedDataUint32ArrayCid);
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 7 * 4 == kTypedDataInt64ArrayCid);
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 8 * 4 == kTypedDataUint64ArrayCid);
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 9 * 4 == kTypedDataFloat32ArrayCid);
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 10 * 4 == kTypedDataFloat64ArrayCid);
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 11 * 4 == kTypedDataFloat32x4ArrayCid);
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 12 * 4 == kTypedDataInt32x4ArrayCid);
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 13 * 4 == kTypedDataFloat64x2ArrayCid);
COMPILE_ASSERT(kTypedDataInt8ArrayCid + 14 * 4 == kByteDataViewCid);
COMPILE_ASSERT(kByteBufferCid + 1 == kNullCid);

} // namespace dart
Expand Down
7 changes: 7 additions & 0 deletions runtime/vm/compiler/backend/constant_propagator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,13 @@ void ConstantPropagator::VisitGenericCheckBound(GenericCheckBoundInstr* instr) {
SetValue(instr, non_constant_);
}

void ConstantPropagator::VisitCheckWritable(CheckWritableInstr* instr) {
// Don't propagate constants through check, since it would eliminate
// the data dependence between the writable check and its use.
// Graph finalization will expose the constant eventually.
SetValue(instr, non_constant_);
}

void ConstantPropagator::VisitCheckNull(CheckNullInstr* instr) {
// Don't propagate constants through check, since it would eliminate
// the data dependence between the null check and its use.
Expand Down
30 changes: 30 additions & 0 deletions runtime/vm/compiler/backend/flow_graph_compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3405,6 +3405,36 @@ void RangeErrorSlowPath::PushArgumentsForRuntimeCall(
locs->in(CheckBoundBase::kLengthPos).reg());
}

void RangeErrorSlowPath::EmitSharedStubCall(FlowGraphCompiler* compiler,
bool save_fpu_registers) {
#if defined(TARGET_ARCH_IA32)
UNREACHABLE();
#else
auto object_store = compiler->isolate_group()->object_store();
const auto& stub = Code::ZoneHandle(
compiler->zone(),
save_fpu_registers
? object_store->range_error_stub_with_fpu_regs_stub()
: object_store->range_error_stub_without_fpu_regs_stub());
compiler->EmitCallToStub(stub);
#endif
}

void WriteErrorSlowPath::EmitSharedStubCall(FlowGraphCompiler* compiler,
bool save_fpu_registers) {
#if defined(TARGET_ARCH_IA32)
UNREACHABLE();
#else
auto object_store = compiler->isolate_group()->object_store();
const auto& stub = Code::ZoneHandle(
compiler->zone(),
save_fpu_registers
? object_store->write_error_stub_with_fpu_regs_stub()
: object_store->write_error_stub_without_fpu_regs_stub());
compiler->EmitCallToStub(stub);
#endif
}

void LateInitializationErrorSlowPath::PushArgumentsForRuntimeCall(
FlowGraphCompiler* compiler) {
__ PushObject(Field::ZoneHandle(OriginalField()));
Expand Down
10 changes: 10 additions & 0 deletions runtime/vm/compiler/backend/flow_graph_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,16 @@ class RangeErrorSlowPath : public ThrowErrorSlowPathCode {
bool save_fpu_registers);
};

class WriteErrorSlowPath : public ThrowErrorSlowPathCode {
public:
explicit WriteErrorSlowPath(CheckWritableInstr* instruction)
: ThrowErrorSlowPathCode(instruction, kWriteErrorRuntimeEntry) {}
virtual const char* name() { return "check writable"; }

virtual void EmitSharedStubCall(FlowGraphCompiler* compiler,
bool save_fpu_registers);
};

class LateInitializationErrorSlowPath : public ThrowErrorSlowPathCode {
public:
explicit LateInitializationErrorSlowPath(Instruction* instruction)
Expand Down
Loading

0 comments on commit d1112d3

Please sign in to comment.