[vm/compiler] Speed up the compiler part which deals with kernel reading up in DEBUG mode

This reduces our AOT compiler's time - gen_snapshot -  by half in DEBUG mode.

Issue https://github.com/dart-lang/sdk/issues/32603

Change-Id: I235afc40acba32036d4127c31c93f3b22f522314
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/103441
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
This commit is contained in:
Martin Kustermann
2019-05-22 22:16:30 +00:00
committed by commit-bot@chromium.org
parent 0c891451a8
commit b316210d94
3 changed files with 41 additions and 16 deletions
+17 -16
View File
@@ -177,15 +177,7 @@ class Reader : public ValueObject {
offset_(0) {
// The reader expects that the actual data is external, though allows
// having a view into this external typed data.
#if defined(DEBUG)
if (typed_data_->IsTypedDataView()) {
const auto& backing_store =
TypedDataBase::Handle(TypedDataView::Cast(*typed_data_).typed_data());
ASSERT(backing_store.IsExternalTypedData());
} else {
ASSERT(typed_data_->IsExternalTypedData());
}
#endif
DEBUG_ASSERT(typed_data_->IsBackedByExternalTypedData());
}
uint32_t ReadFromIndex(intptr_t end_offset,
@@ -199,10 +191,15 @@ class Reader : public ValueObject {
return result;
}
uint32_t ReadUInt32At(intptr_t offset) const {
ASSERT((size_ >= 4) && (offset >= 0) && (offset <= size_ - 4));
uint32_t value;
value = typed_data_->GetUint32(offset);
DART_FORCE_INLINE uint32_t ReadUInt32At(intptr_t offset) const {
ASSERT(size_ >= 4 && offset >= 0 && (offset <= size_ - 4));
// We validated in the [Reader] constructor that we have either an
// ExternalTypedData or a view on top of an ExternalTypedData.
//
// This means the data pointer will not change and we can use
// [DataAddrUnsafe].
const uint32_t value =
*static_cast<uint32_t*>(typed_data_->DataAddrUnsafe(offset));
return Utils::BigEndianToHost32(value);
}
@@ -358,9 +355,13 @@ class Reader : public ValueObject {
}
private:
const uint8_t* buffer() const {
NoSafepointScope no_safepoint(thread_);
return reinterpret_cast<uint8_t*>(typed_data_->DataAddr(0));
DART_FORCE_INLINE const uint8_t* buffer() const {
// We validated in the [Reader] constructor that we have either an
// ExternalTypedData or a view on top of an ExternalTypedData.
//
// This means the data pointer will not change and we can use
// [DataAddrUnsafe].
return reinterpret_cast<uint8_t*>(typed_data_->DataAddrUnsafe(0));
}
Thread* thread_;
+13
View File
@@ -21169,6 +21169,19 @@ RawTypedDataView* TypedDataBase::CreateUint8View(intptr_t offset_in_bytes,
offset_in_bytes, length_in_bytes, space);
}
#if defined(DEBUG)
bool TypedDataBase::IsBackedByExternalTypedData() const {
if (IsExternalTypedData()) {
return true;
}
if (IsTypedDataView()) {
const auto& view = TypedDataView::Cast(*this);
return TypedDataBase::Handle(view.typed_data()).IsExternalTypedData();
}
return false;
}
#endif
const char* TypedDataView::ToCString() const {
auto zone = Thread::Current()->zone();
return OS::SCreate(zone, "TypedDataView(cid: %" Pd ")", GetClassId());
+11
View File
@@ -8410,6 +8410,13 @@ class TypedDataBase : public Instance {
#if defined(DEBUG)
ValidateInvariant();
#endif
return DataAddrUnsafe(byte_offset);
}
// To speed up debug mode (e.g. for kernel reading - which uses typed data
// for kernel buffers) we expose the data pointer without asserts for bounds
// checks and invariants.
DART_FORCE_INLINE void* DataAddrUnsafe(intptr_t byte_offset) const {
return reinterpret_cast<void*>(raw_ptr()->data_ + byte_offset);
}
@@ -8471,6 +8478,10 @@ class TypedDataBase : public Instance {
#undef TYPED_GETTER_SETTER
#if defined(DEBUG)
bool IsBackedByExternalTypedData() const;
#endif
protected:
void SetLength(intptr_t value) const {
ASSERT(value <= Smi::kMaxValue);