Commit 2fffcaa1 authored by jgruber's avatar jgruber Committed by Commit Bot

[builtins] Introduce metadata structs in embedded blob

This is a refactoring-only CL that packs builtin offsets and lengths
into a metadata struct. The struct should make future modifications to
metadata simpler.

Bug: v8:6666
Change-Id: Iae8070c2aa24d7e803cd75da3dea09e437ef275e
Reviewed-on: https://chromium-review.googlesource.com/1145069
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarSigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54729}
parent ad06f37c
......@@ -377,8 +377,7 @@ EmbeddedData EmbeddedData::FromIsolate(Isolate* isolate) {
Builtins* builtins = isolate->builtins();
// Store instruction stream lengths and offsets.
std::vector<uint32_t> lengths(kTableSize);
std::vector<uint32_t> offsets(kTableSize);
std::vector<struct Metadata> metadata(kTableSize);
bool saw_unsafe_builtin = false;
uint32_t raw_data_size = 0;
......@@ -403,14 +402,13 @@ EmbeddedData EmbeddedData::FromIsolate(Isolate* isolate) {
uint32_t length = static_cast<uint32_t>(code->raw_instruction_size());
DCHECK_EQ(0, raw_data_size % kCodeAlignment);
offsets[i] = raw_data_size;
lengths[i] = length;
metadata[i].instructions_offset = raw_data_size;
metadata[i].instructions_length = length;
// Align the start of each instruction stream.
raw_data_size += RoundUp<kCodeAlignment>(length);
} else {
offsets[i] = raw_data_size;
lengths[i] = 0;
metadata[i].instructions_offset = raw_data_size;
}
}
CHECK_WITH_MSG(
......@@ -423,18 +421,15 @@ EmbeddedData EmbeddedData::FromIsolate(Isolate* isolate) {
uint8_t* blob = new uint8_t[blob_size];
std::memset(blob, 0, blob_size);
// Write the offsets and length tables.
DCHECK_EQ(OffsetsSize(), sizeof(offsets[0]) * offsets.size());
std::memcpy(blob + OffsetsOffset(), offsets.data(), OffsetsSize());
DCHECK_EQ(LengthsSize(), sizeof(lengths[0]) * lengths.size());
std::memcpy(blob + LengthsOffset(), lengths.data(), LengthsSize());
// Write the metadata tables.
DCHECK_EQ(MetadataSize(), sizeof(metadata[0]) * metadata.size());
std::memcpy(blob + MetadataOffset(), metadata.data(), MetadataSize());
// Write the raw data section.
for (int i = 0; i < Builtins::builtin_count; i++) {
if (!Builtins::IsIsolateIndependent(i)) continue;
Code* code = builtins->builtin(i);
uint32_t offset = offsets[i];
uint32_t offset = metadata[i].instructions_offset;
uint8_t* dst = blob + RawDataOffset() + offset;
DCHECK_LE(RawDataOffset() + offset + code->raw_instruction_size(),
blob_size);
......@@ -470,8 +465,8 @@ EmbeddedData EmbeddedData::FromBlob() {
Address EmbeddedData::InstructionStartOfBuiltin(int i) const {
DCHECK(Builtins::IsBuiltinId(i));
const uint32_t* offsets = Offsets();
const uint8_t* result = RawData() + offsets[i];
const struct Metadata* metadata = Metadata();
const uint8_t* result = RawData() + metadata[i].instructions_offset;
DCHECK_LE(result, data_ + size_);
DCHECK_IMPLIES(result == data_ + size_, InstructionSizeOfBuiltin(i) == 0);
return reinterpret_cast<Address>(result);
......@@ -479,8 +474,8 @@ Address EmbeddedData::InstructionStartOfBuiltin(int i) const {
uint32_t EmbeddedData::InstructionSizeOfBuiltin(int i) const {
DCHECK(Builtins::IsBuiltinId(i));
const uint32_t* lengths = Lengths();
return lengths[i];
const struct Metadata* metadata = Metadata();
return metadata[i].instructions_length;
}
size_t EmbeddedData::CreateHash() const {
......@@ -519,8 +514,7 @@ void EmbeddedData::PrintStatistics() const {
const int k90th = embedded_count * 0.90;
const int k99th = embedded_count * 0.99;
const int metadata_size =
static_cast<int>(HashSize() + OffsetsSize() + LengthsSize());
const int metadata_size = static_cast<int>(HashSize() + MetadataSize());
PrintF("EmbeddedData:\n");
PrintF(" Total size: %d\n",
......
......@@ -104,38 +104,40 @@ class EmbeddedData final {
return *reinterpret_cast<const size_t*>(data_ + HashOffset());
}
struct Metadata {
// Blob layout information.
uint32_t instructions_offset;
uint32_t instructions_length;
};
STATIC_ASSERT(offsetof(Metadata, instructions_offset) == 0);
STATIC_ASSERT(offsetof(Metadata, instructions_length) == kUInt32Size);
STATIC_ASSERT(sizeof(Metadata) == kUInt32Size + kUInt32Size);
// The layout of the blob is as follows:
//
// [0] hash of the remaining blob
// [1] offset of instruction stream 0
// ... offsets
// [N + 1] length of instruction stream 0
// ... lengths
// ... instruction streams
// [0] hash of the remaining blob
// [1] metadata of instruction stream 0
// ... metadata
// ... instruction streams
static constexpr uint32_t kTableSize = Builtins::builtin_count;
static constexpr uint32_t HashOffset() { return 0; }
static constexpr uint32_t HashSize() { return kSizetSize; }
static constexpr uint32_t OffsetsOffset() {
static constexpr uint32_t MetadataOffset() {
return HashOffset() + HashSize();
}
static constexpr uint32_t OffsetsSize() { return kUInt32Size * kTableSize; }
static constexpr uint32_t LengthsOffset() {
return OffsetsOffset() + OffsetsSize();
static constexpr uint32_t MetadataSize() {
return sizeof(struct Metadata) * kTableSize;
}
static constexpr uint32_t LengthsSize() { return kUInt32Size * kTableSize; }
static constexpr uint32_t RawDataOffset() {
return RoundUp<kCodeAlignment>(LengthsOffset() + LengthsSize());
return RoundUp<kCodeAlignment>(MetadataOffset() + MetadataSize());
}
private:
EmbeddedData(const uint8_t* data, uint32_t size) : data_(data), size_(size) {}
const uint32_t* Offsets() const {
return reinterpret_cast<const uint32_t*>(data_ + OffsetsOffset());
}
const uint32_t* Lengths() const {
return reinterpret_cast<const uint32_t*>(data_ + LengthsOffset());
const Metadata* Metadata() const {
return reinterpret_cast<const struct Metadata*>(data_ + MetadataOffset());
}
const uint8_t* RawData() const { return data_ + RawDataOffset(); }
......
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