Commit 968a2f66 authored by Yang Guo's avatar Yang Guo Committed by Commit Bot

[snapshot] avoid aliasing for snapshot reservations.

R=ulan@chromium.org

Bug: v8:7141
Change-Id: I21b82f5c3f6a2cd5f6e525d267d6c6819b1370fb
Reviewed-on: https://chromium-review.googlesource.com/796370
Commit-Queue: Yang Guo <yangguo@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49784}
parent 73210c7f
......@@ -69,7 +69,7 @@ class BuiltinDeserializerAllocator final {
// Builtin deserialization does not bake reservations into the snapshot, hence
// this is a nop.
void DecodeReservation(Vector<const SerializedData::Reservation> res) {}
void DecodeReservation(std::vector<SerializedData::Reservation> res) {}
// These methods are used to pre-allocate builtin objects prior to
// deserialization.
......
......@@ -432,11 +432,13 @@ ScriptData* SerializedCodeData::GetScriptData() {
return result;
}
Vector<const SerializedData::Reservation> SerializedCodeData::Reservations()
std::vector<SerializedData::Reservation> SerializedCodeData::Reservations()
const {
return Vector<const Reservation>(
reinterpret_cast<const Reservation*>(data_ + kHeaderSize),
GetHeaderValue(kNumReservationsOffset));
uint32_t size = GetHeaderValue(kNumReservationsOffset);
std::vector<Reservation> reservations(size);
memcpy(reservations.data(), data_ + kHeaderSize,
size * sizeof(SerializedData::Reservation));
return reservations;
}
Vector<const byte> SerializedCodeData::Payload() const {
......
......@@ -129,7 +129,7 @@ class SerializedCodeData : public SerializedData {
// Return ScriptData object and relinquish ownership over it to the caller.
ScriptData* GetScriptData();
Vector<const Reservation> Reservations() const;
std::vector<Reservation> Reservations() const;
Vector<const byte> Payload() const;
Vector<const uint32_t> CodeStubKeys() const;
......
......@@ -121,7 +121,7 @@ HeapObject* DefaultDeserializerAllocator::GetObject(AllocationSpace space,
}
void DefaultDeserializerAllocator::DecodeReservation(
Vector<const SerializedData::Reservation> res) {
std::vector<SerializedData::Reservation> res) {
DCHECK_EQ(0, reservations_[NEW_SPACE].size());
STATIC_ASSERT(NEW_SPACE == 0);
int current_space = NEW_SPACE;
......
......@@ -44,7 +44,7 @@ class DefaultDeserializerAllocator final {
// ------- Reservation Methods -------
// Methods related to memory reservations (prior to deserialization).
void DecodeReservation(Vector<const SerializedData::Reservation> res);
void DecodeReservation(std::vector<SerializedData::Reservation> res);
bool ReserveSpace();
// Atomically reserves space for the two given deserializers. Guarantees
......
......@@ -255,6 +255,7 @@ class SerializedData {
public:
class Reservation {
public:
Reservation() : reservation_(0) {}
explicit Reservation(uint32_t size)
: reservation_(ChunkSizeBits::encode(size)) {}
......
......@@ -358,10 +358,12 @@ SnapshotData::SnapshotData(const Serializer<AllocatorT>* serializer) {
template SnapshotData::SnapshotData(
const Serializer<DefaultSerializerAllocator>* serializer);
Vector<const SerializedData::Reservation> SnapshotData::Reservations() const {
return Vector<const Reservation>(
reinterpret_cast<const Reservation*>(data_ + kHeaderSize),
GetHeaderValue(kNumReservationsOffset));
std::vector<SerializedData::Reservation> SnapshotData::Reservations() const {
uint32_t size = GetHeaderValue(kNumReservationsOffset);
std::vector<SerializedData::Reservation> reservations(size);
memcpy(reservations.data(), data_ + kHeaderSize,
size * sizeof(SerializedData::Reservation));
return reservations;
}
Vector<const byte> SnapshotData::Payload() const {
......
......@@ -31,7 +31,7 @@ class SnapshotData : public SerializedData {
: SerializedData(const_cast<byte*>(snapshot.begin()), snapshot.length()) {
}
Vector<const Reservation> Reservations() const;
std::vector<Reservation> Reservations() const;
virtual Vector<const byte> Payload() const;
Vector<const byte> RawData() const {
......
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