Commit c6ffff9d authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[parser] Minor cleanup PreParsedScopeDataBuilder

- Mark Serialize method as non-virtual
- Use simple scheme to mask out bytes when de-/serializing Uint32

- Improve ByteArray::ByteArrayPrint method

Drive-by-fix: 
Change-Id: I9a6779587c0a031bcf23e4f431d17026b83a808d
Reviewed-on: https://chromium-review.googlesource.com/c/1387493Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58428}
parent 6679fd2e
...@@ -444,8 +444,10 @@ void HeapObject::HeapObjectPrint(std::ostream& os) { // NOLINT ...@@ -444,8 +444,10 @@ void HeapObject::HeapObjectPrint(std::ostream& os) { // NOLINT
} }
void ByteArray::ByteArrayPrint(std::ostream& os) { // NOLINT void ByteArray::ByteArrayPrint(std::ostream& os) { // NOLINT
os << "byte array, data starts at " PrintHeader(os, "ByteArray");
<< static_cast<void*>(GetDataStartAddress()); os << "\n - length: " << length()
<< "\n - data-start: " << static_cast<void*>(GetDataStartAddress())
<< "\n";
} }
void BytecodeArray::BytecodeArrayPrint(std::ostream& os) { // NOLINT void BytecodeArray::BytecodeArrayPrint(std::ostream& os) { // NOLINT
......
...@@ -105,11 +105,10 @@ class BaseConsumedPreParsedScopeData : public ConsumedPreParsedScopeData { ...@@ -105,11 +105,10 @@ class BaseConsumedPreParsedScopeData : public ConsumedPreParsedScopeData {
DCHECK_GE(RemainingBytes(), kUint32Size); DCHECK_GE(RemainingBytes(), kUint32Size);
// Check that there indeed is an integer following. // Check that there indeed is an integer following.
DCHECK_EQ(data_.get(index_++), kUint32Size); DCHECK_EQ(data_.get(index_++), kUint32Size);
int32_t result = 0; int32_t result = data_.get(index_) + (data_.get(index_ + 1) << 8) +
byte* p = reinterpret_cast<byte*>(&result); (data_.get(index_ + 2) << 16) +
for (int i = 0; i < 4; ++i) { (data_.get(index_ + 3) << 24);
*p++ = data_.get(index_++); index_ += 4;
}
stored_quarters_ = 0; stored_quarters_ = 0;
return result; return result;
} }
...@@ -216,8 +215,7 @@ class ZoneVectorWrapper { ...@@ -216,8 +215,7 @@ class ZoneVectorWrapper {
class ZonePreParsedScopeData : public ZoneObject { class ZonePreParsedScopeData : public ZoneObject {
public: public:
ZonePreParsedScopeData(Zone* zone, ZonePreParsedScopeData(Zone* zone,
ZoneChunkList<uint8_t>::iterator byte_data_begin, PreParsedScopeDataBuilder::ByteData* byte_data,
ZoneChunkList<uint8_t>::iterator byte_data_end,
int child_length); int child_length);
Handle<PreParsedScopeData> Serialize(Isolate* isolate); Handle<PreParsedScopeData> Serialize(Isolate* isolate);
......
...@@ -83,10 +83,10 @@ void PreParsedScopeDataBuilder::ByteData::WriteUint32(uint32_t data) { ...@@ -83,10 +83,10 @@ void PreParsedScopeDataBuilder::ByteData::WriteUint32(uint32_t data) {
// Save expected item size in debug mode. // Save expected item size in debug mode.
backing_store_.push_back(kUint32Size); backing_store_.push_back(kUint32Size);
#endif #endif
const uint8_t* d = reinterpret_cast<uint8_t*>(&data); backing_store_.push_back(data & 0xFF);
for (int i = 0; i < 4; ++i) { backing_store_.push_back((data >> 8) & 0xFF);
backing_store_.push_back(*d++); backing_store_.push_back((data >> 16) & 0xFF);
} backing_store_.push_back((data >> 24) & 0xFF);
free_quarters_in_last_byte_ = 0; free_quarters_in_last_byte_ = 0;
} }
...@@ -97,10 +97,10 @@ void PreParsedScopeDataBuilder::ByteData::OverwriteFirstUint32(uint32_t data) { ...@@ -97,10 +97,10 @@ void PreParsedScopeDataBuilder::ByteData::OverwriteFirstUint32(uint32_t data) {
DCHECK_GE(backing_store_.size(), kUint32Size); DCHECK_GE(backing_store_.size(), kUint32Size);
DCHECK_EQ(*it, kUint32Size); DCHECK_EQ(*it, kUint32Size);
++it; ++it;
const uint8_t* d = reinterpret_cast<uint8_t*>(&data); *it++ = data & 0xFF;
for (size_t i = 0; i < 4; ++i) { *it++ = (data >> 8) & 0xFF;
*it++ = *d++; *it++ = (data >> 16) & 0xFF;
} *it++ = (data >> 24) & 0xFF;
} }
#endif #endif
...@@ -209,14 +209,12 @@ void PreParsedScopeDataBuilder::SaveScopeAllocationData( ...@@ -209,14 +209,12 @@ void PreParsedScopeDataBuilder::SaveScopeAllocationData(
if (bailed_out_) return; if (bailed_out_) return;
uint32_t scope_data_start = static_cast<uint32_t>(byte_data_->size());
// If there are no skippable inner functions, we don't need to save anything. // If there are no skippable inner functions, we don't need to save anything.
if (scope_data_start == ByteData::kPlaceholderSize) { if (!ContainsInnerFunctions()) return;
return;
}
#ifdef DEBUG #ifdef DEBUG
uint32_t scope_data_start = static_cast<uint32_t>(byte_data_->size());
byte_data_->OverwriteFirstUint32(scope_data_start); byte_data_->OverwriteFirstUint32(scope_data_start);
// For a data integrity check, write a value between data about skipped inner // For a data integrity check, write a value between data about skipped inner
...@@ -239,7 +237,7 @@ MaybeHandle<PreParsedScopeData> PreParsedScopeDataBuilder::Serialize( ...@@ -239,7 +237,7 @@ MaybeHandle<PreParsedScopeData> PreParsedScopeDataBuilder::Serialize(
DCHECK(!ThisOrParentBailedOut()); DCHECK(!ThisOrParentBailedOut());
if (byte_data_->size() <= ByteData::kPlaceholderSize) { if (!ContainsInnerFunctions()) {
// The data contains only the placeholder. // The data contains only the placeholder.
return MaybeHandle<PreParsedScopeData>(); return MaybeHandle<PreParsedScopeData>();
} }
...@@ -270,14 +268,11 @@ ZonePreParsedScopeData* PreParsedScopeDataBuilder::Serialize(Zone* zone) { ...@@ -270,14 +268,11 @@ ZonePreParsedScopeData* PreParsedScopeDataBuilder::Serialize(Zone* zone) {
DCHECK(!ThisOrParentBailedOut()); DCHECK(!ThisOrParentBailedOut());
if (byte_data_->size() <= ByteData::kPlaceholderSize) { if (!ContainsInnerFunctions()) return nullptr;
// The data contains only the placeholder.
return nullptr;
}
int child_length = static_cast<int>(data_for_inner_functions_.size()); int child_length = static_cast<int>(data_for_inner_functions_.size());
ZonePreParsedScopeData* result = new (zone) ZonePreParsedScopeData( ZonePreParsedScopeData* result =
zone, byte_data_->begin(), byte_data_->end(), child_length); new (zone) ZonePreParsedScopeData(zone, byte_data_, child_length);
int i = 0; int i = 0;
for (const auto& item : data_for_inner_functions_) { for (const auto& item : data_for_inner_functions_) {
...@@ -628,9 +623,9 @@ OnHeapConsumedPreParsedScopeData::OnHeapConsumedPreParsedScopeData( ...@@ -628,9 +623,9 @@ OnHeapConsumedPreParsedScopeData::OnHeapConsumedPreParsedScopeData(
} }
ZonePreParsedScopeData::ZonePreParsedScopeData( ZonePreParsedScopeData::ZonePreParsedScopeData(
Zone* zone, ZoneChunkList<uint8_t>::iterator byte_data_begin, Zone* zone, PreParsedScopeDataBuilder::ByteData* byte_data,
ZoneChunkList<uint8_t>::iterator byte_data_end, int child_length) int child_length)
: byte_data_(byte_data_begin, byte_data_end, zone), : byte_data_(byte_data->begin(), byte_data->end(), zone),
children_(child_length, zone) {} children_(child_length, zone) {}
Handle<PreParsedScopeData> ZonePreParsedScopeData::Serialize(Isolate* isolate) { Handle<PreParsedScopeData> ZonePreParsedScopeData::Serialize(Isolate* isolate) {
......
...@@ -126,8 +126,8 @@ class PreParsedScopeDataBuilder : public ZoneObject { ...@@ -126,8 +126,8 @@ class PreParsedScopeDataBuilder : public ZoneObject {
private: private:
friend class BuilderProducedPreParsedScopeData; friend class BuilderProducedPreParsedScopeData;
virtual MaybeHandle<PreParsedScopeData> Serialize(Isolate* isolate); MaybeHandle<PreParsedScopeData> Serialize(Isolate* isolate);
virtual ZonePreParsedScopeData* Serialize(Zone* zone); ZonePreParsedScopeData* Serialize(Zone* zone);
void SaveDataForScope(Scope* scope); void SaveDataForScope(Scope* scope);
void SaveDataForVariable(Variable* var); void SaveDataForVariable(Variable* var);
......
...@@ -840,8 +840,7 @@ TEST(ProducingAndConsumingByteData) { ...@@ -840,8 +840,7 @@ TEST(ProducingAndConsumingByteData) {
{ {
// Serialize as a ZoneConsumedPreParsedScopeData, and read back data. // Serialize as a ZoneConsumedPreParsedScopeData, and read back data.
i::ZonePreParsedScopeData zone_serialized(&zone, bytes.begin(), bytes.end(), i::ZonePreParsedScopeData zone_serialized(&zone, &bytes, 0);
0);
i::ZoneConsumedPreParsedScopeData::ByteData bytes_for_reading; i::ZoneConsumedPreParsedScopeData::ByteData bytes_for_reading;
i::ZoneVectorWrapper wrapper(zone_serialized.byte_data()); i::ZoneVectorWrapper wrapper(zone_serialized.byte_data());
i::ZoneConsumedPreParsedScopeData::ByteData::ReadingScope reading_scope( i::ZoneConsumedPreParsedScopeData::ByteData::ReadingScope reading_scope(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment