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 { ...@@ -69,7 +69,7 @@ class BuiltinDeserializerAllocator final {
// Builtin deserialization does not bake reservations into the snapshot, hence // Builtin deserialization does not bake reservations into the snapshot, hence
// this is a nop. // 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 // These methods are used to pre-allocate builtin objects prior to
// deserialization. // deserialization.
......
...@@ -432,11 +432,13 @@ ScriptData* SerializedCodeData::GetScriptData() { ...@@ -432,11 +432,13 @@ ScriptData* SerializedCodeData::GetScriptData() {
return result; return result;
} }
Vector<const SerializedData::Reservation> SerializedCodeData::Reservations() std::vector<SerializedData::Reservation> SerializedCodeData::Reservations()
const { const {
return Vector<const Reservation>( uint32_t size = GetHeaderValue(kNumReservationsOffset);
reinterpret_cast<const Reservation*>(data_ + kHeaderSize), std::vector<Reservation> reservations(size);
GetHeaderValue(kNumReservationsOffset)); memcpy(reservations.data(), data_ + kHeaderSize,
size * sizeof(SerializedData::Reservation));
return reservations;
} }
Vector<const byte> SerializedCodeData::Payload() const { Vector<const byte> SerializedCodeData::Payload() const {
......
...@@ -129,7 +129,7 @@ class SerializedCodeData : public SerializedData { ...@@ -129,7 +129,7 @@ class SerializedCodeData : public SerializedData {
// Return ScriptData object and relinquish ownership over it to the caller. // Return ScriptData object and relinquish ownership over it to the caller.
ScriptData* GetScriptData(); ScriptData* GetScriptData();
Vector<const Reservation> Reservations() const; std::vector<Reservation> Reservations() const;
Vector<const byte> Payload() const; Vector<const byte> Payload() const;
Vector<const uint32_t> CodeStubKeys() const; Vector<const uint32_t> CodeStubKeys() const;
......
...@@ -121,7 +121,7 @@ HeapObject* DefaultDeserializerAllocator::GetObject(AllocationSpace space, ...@@ -121,7 +121,7 @@ HeapObject* DefaultDeserializerAllocator::GetObject(AllocationSpace space,
} }
void DefaultDeserializerAllocator::DecodeReservation( void DefaultDeserializerAllocator::DecodeReservation(
Vector<const SerializedData::Reservation> res) { std::vector<SerializedData::Reservation> res) {
DCHECK_EQ(0, reservations_[NEW_SPACE].size()); DCHECK_EQ(0, reservations_[NEW_SPACE].size());
STATIC_ASSERT(NEW_SPACE == 0); STATIC_ASSERT(NEW_SPACE == 0);
int current_space = NEW_SPACE; int current_space = NEW_SPACE;
......
...@@ -44,7 +44,7 @@ class DefaultDeserializerAllocator final { ...@@ -44,7 +44,7 @@ class DefaultDeserializerAllocator final {
// ------- Reservation Methods ------- // ------- Reservation Methods -------
// Methods related to memory reservations (prior to deserialization). // Methods related to memory reservations (prior to deserialization).
void DecodeReservation(Vector<const SerializedData::Reservation> res); void DecodeReservation(std::vector<SerializedData::Reservation> res);
bool ReserveSpace(); bool ReserveSpace();
// Atomically reserves space for the two given deserializers. Guarantees // Atomically reserves space for the two given deserializers. Guarantees
......
...@@ -255,6 +255,7 @@ class SerializedData { ...@@ -255,6 +255,7 @@ class SerializedData {
public: public:
class Reservation { class Reservation {
public: public:
Reservation() : reservation_(0) {}
explicit Reservation(uint32_t size) explicit Reservation(uint32_t size)
: reservation_(ChunkSizeBits::encode(size)) {} : reservation_(ChunkSizeBits::encode(size)) {}
......
...@@ -358,10 +358,12 @@ SnapshotData::SnapshotData(const Serializer<AllocatorT>* serializer) { ...@@ -358,10 +358,12 @@ SnapshotData::SnapshotData(const Serializer<AllocatorT>* serializer) {
template SnapshotData::SnapshotData( template SnapshotData::SnapshotData(
const Serializer<DefaultSerializerAllocator>* serializer); const Serializer<DefaultSerializerAllocator>* serializer);
Vector<const SerializedData::Reservation> SnapshotData::Reservations() const { std::vector<SerializedData::Reservation> SnapshotData::Reservations() const {
return Vector<const Reservation>( uint32_t size = GetHeaderValue(kNumReservationsOffset);
reinterpret_cast<const Reservation*>(data_ + kHeaderSize), std::vector<SerializedData::Reservation> reservations(size);
GetHeaderValue(kNumReservationsOffset)); memcpy(reservations.data(), data_ + kHeaderSize,
size * sizeof(SerializedData::Reservation));
return reservations;
} }
Vector<const byte> SnapshotData::Payload() const { Vector<const byte> SnapshotData::Payload() const {
......
...@@ -31,7 +31,7 @@ class SnapshotData : public SerializedData { ...@@ -31,7 +31,7 @@ class SnapshotData : public SerializedData {
: SerializedData(const_cast<byte*>(snapshot.begin()), snapshot.length()) { : SerializedData(const_cast<byte*>(snapshot.begin()), snapshot.length()) {
} }
Vector<const Reservation> Reservations() const; std::vector<Reservation> Reservations() const;
virtual Vector<const byte> Payload() const; virtual Vector<const byte> Payload() const;
Vector<const byte> RawData() 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