Commit 495354ff authored by heimbuef's avatar heimbuef Committed by Commit bot

Used ZoneChunkList in deoptimizer to conserve memory.

Exchanged the ZoneList for a ZoneChunkList to avoid
unnecessary growing.

Review-Url: https://codereview.chromium.org/2468183004
Cr-Commit-Position: refs/heads/master@{#40736}
parent 9377226a
...@@ -2281,7 +2281,7 @@ FrameDescription::FrameDescription(uint32_t frame_size, int parameter_count) ...@@ -2281,7 +2281,7 @@ FrameDescription::FrameDescription(uint32_t frame_size, int parameter_count)
} }
} }
void TranslationBuffer::Add(int32_t value, Zone* zone) { void TranslationBuffer::Add(int32_t value) {
// This wouldn't handle kMinInt correctly if it ever encountered it. // This wouldn't handle kMinInt correctly if it ever encountered it.
DCHECK(value != kMinInt); DCHECK(value != kMinInt);
// Encode the sign bit in the least significant bit. // Encode the sign bit in the least significant bit.
...@@ -2292,7 +2292,7 @@ void TranslationBuffer::Add(int32_t value, Zone* zone) { ...@@ -2292,7 +2292,7 @@ void TranslationBuffer::Add(int32_t value, Zone* zone) {
// each byte to indicate whether or not more bytes follow. // each byte to indicate whether or not more bytes follow.
do { do {
uint32_t next = bits >> 7; uint32_t next = bits >> 7;
contents_.Add(((bits << 1) & 0xFF) | (next != 0), zone); contents_.push_back(((bits << 1) & 0xFF) | (next != 0));
bits = next; bits = next;
} while (bits != 0); } while (bits != 0);
} }
...@@ -2316,167 +2316,166 @@ int32_t TranslationIterator::Next() { ...@@ -2316,167 +2316,166 @@ int32_t TranslationIterator::Next() {
Handle<ByteArray> TranslationBuffer::CreateByteArray(Factory* factory) { Handle<ByteArray> TranslationBuffer::CreateByteArray(Factory* factory) {
int length = contents_.length(); Handle<ByteArray> result = factory->NewByteArray(CurrentIndex(), TENURED);
Handle<ByteArray> result = factory->NewByteArray(length, TENURED); contents_.CopyTo(result->GetDataStartAddress());
MemCopy(result->GetDataStartAddress(), contents_.ToVector().start(), length);
return result; return result;
} }
void Translation::BeginConstructStubFrame(int literal_id, unsigned height) { void Translation::BeginConstructStubFrame(int literal_id, unsigned height) {
buffer_->Add(CONSTRUCT_STUB_FRAME, zone()); buffer_->Add(CONSTRUCT_STUB_FRAME);
buffer_->Add(literal_id, zone()); buffer_->Add(literal_id);
buffer_->Add(height, zone()); buffer_->Add(height);
} }
void Translation::BeginGetterStubFrame(int literal_id) { void Translation::BeginGetterStubFrame(int literal_id) {
buffer_->Add(GETTER_STUB_FRAME, zone()); buffer_->Add(GETTER_STUB_FRAME);
buffer_->Add(literal_id, zone()); buffer_->Add(literal_id);
} }
void Translation::BeginSetterStubFrame(int literal_id) { void Translation::BeginSetterStubFrame(int literal_id) {
buffer_->Add(SETTER_STUB_FRAME, zone()); buffer_->Add(SETTER_STUB_FRAME);
buffer_->Add(literal_id, zone()); buffer_->Add(literal_id);
} }
void Translation::BeginArgumentsAdaptorFrame(int literal_id, unsigned height) { void Translation::BeginArgumentsAdaptorFrame(int literal_id, unsigned height) {
buffer_->Add(ARGUMENTS_ADAPTOR_FRAME, zone()); buffer_->Add(ARGUMENTS_ADAPTOR_FRAME);
buffer_->Add(literal_id, zone()); buffer_->Add(literal_id);
buffer_->Add(height, zone()); buffer_->Add(height);
} }
void Translation::BeginTailCallerFrame(int literal_id) { void Translation::BeginTailCallerFrame(int literal_id) {
buffer_->Add(TAIL_CALLER_FRAME, zone()); buffer_->Add(TAIL_CALLER_FRAME);
buffer_->Add(literal_id, zone()); buffer_->Add(literal_id);
} }
void Translation::BeginJSFrame(BailoutId node_id, void Translation::BeginJSFrame(BailoutId node_id,
int literal_id, int literal_id,
unsigned height) { unsigned height) {
buffer_->Add(JS_FRAME, zone()); buffer_->Add(JS_FRAME);
buffer_->Add(node_id.ToInt(), zone()); buffer_->Add(node_id.ToInt());
buffer_->Add(literal_id, zone()); buffer_->Add(literal_id);
buffer_->Add(height, zone()); buffer_->Add(height);
} }
void Translation::BeginInterpretedFrame(BailoutId bytecode_offset, void Translation::BeginInterpretedFrame(BailoutId bytecode_offset,
int literal_id, unsigned height) { int literal_id, unsigned height) {
buffer_->Add(INTERPRETED_FRAME, zone()); buffer_->Add(INTERPRETED_FRAME);
buffer_->Add(bytecode_offset.ToInt(), zone()); buffer_->Add(bytecode_offset.ToInt());
buffer_->Add(literal_id, zone()); buffer_->Add(literal_id);
buffer_->Add(height, zone()); buffer_->Add(height);
} }
void Translation::BeginCompiledStubFrame(int height) { void Translation::BeginCompiledStubFrame(int height) {
buffer_->Add(COMPILED_STUB_FRAME, zone()); buffer_->Add(COMPILED_STUB_FRAME);
buffer_->Add(height, zone()); buffer_->Add(height);
} }
void Translation::BeginArgumentsObject(int args_length) { void Translation::BeginArgumentsObject(int args_length) {
buffer_->Add(ARGUMENTS_OBJECT, zone()); buffer_->Add(ARGUMENTS_OBJECT);
buffer_->Add(args_length, zone()); buffer_->Add(args_length);
} }
void Translation::BeginCapturedObject(int length) { void Translation::BeginCapturedObject(int length) {
buffer_->Add(CAPTURED_OBJECT, zone()); buffer_->Add(CAPTURED_OBJECT);
buffer_->Add(length, zone()); buffer_->Add(length);
} }
void Translation::DuplicateObject(int object_index) { void Translation::DuplicateObject(int object_index) {
buffer_->Add(DUPLICATED_OBJECT, zone()); buffer_->Add(DUPLICATED_OBJECT);
buffer_->Add(object_index, zone()); buffer_->Add(object_index);
} }
void Translation::StoreRegister(Register reg) { void Translation::StoreRegister(Register reg) {
buffer_->Add(REGISTER, zone()); buffer_->Add(REGISTER);
buffer_->Add(reg.code(), zone()); buffer_->Add(reg.code());
} }
void Translation::StoreInt32Register(Register reg) { void Translation::StoreInt32Register(Register reg) {
buffer_->Add(INT32_REGISTER, zone()); buffer_->Add(INT32_REGISTER);
buffer_->Add(reg.code(), zone()); buffer_->Add(reg.code());
} }
void Translation::StoreUint32Register(Register reg) { void Translation::StoreUint32Register(Register reg) {
buffer_->Add(UINT32_REGISTER, zone()); buffer_->Add(UINT32_REGISTER);
buffer_->Add(reg.code(), zone()); buffer_->Add(reg.code());
} }
void Translation::StoreBoolRegister(Register reg) { void Translation::StoreBoolRegister(Register reg) {
buffer_->Add(BOOL_REGISTER, zone()); buffer_->Add(BOOL_REGISTER);
buffer_->Add(reg.code(), zone()); buffer_->Add(reg.code());
} }
void Translation::StoreFloatRegister(FloatRegister reg) { void Translation::StoreFloatRegister(FloatRegister reg) {
buffer_->Add(FLOAT_REGISTER, zone()); buffer_->Add(FLOAT_REGISTER);
buffer_->Add(reg.code(), zone()); buffer_->Add(reg.code());
} }
void Translation::StoreDoubleRegister(DoubleRegister reg) { void Translation::StoreDoubleRegister(DoubleRegister reg) {
buffer_->Add(DOUBLE_REGISTER, zone()); buffer_->Add(DOUBLE_REGISTER);
buffer_->Add(reg.code(), zone()); buffer_->Add(reg.code());
} }
void Translation::StoreStackSlot(int index) { void Translation::StoreStackSlot(int index) {
buffer_->Add(STACK_SLOT, zone()); buffer_->Add(STACK_SLOT);
buffer_->Add(index, zone()); buffer_->Add(index);
} }
void Translation::StoreInt32StackSlot(int index) { void Translation::StoreInt32StackSlot(int index) {
buffer_->Add(INT32_STACK_SLOT, zone()); buffer_->Add(INT32_STACK_SLOT);
buffer_->Add(index, zone()); buffer_->Add(index);
} }
void Translation::StoreUint32StackSlot(int index) { void Translation::StoreUint32StackSlot(int index) {
buffer_->Add(UINT32_STACK_SLOT, zone()); buffer_->Add(UINT32_STACK_SLOT);
buffer_->Add(index, zone()); buffer_->Add(index);
} }
void Translation::StoreBoolStackSlot(int index) { void Translation::StoreBoolStackSlot(int index) {
buffer_->Add(BOOL_STACK_SLOT, zone()); buffer_->Add(BOOL_STACK_SLOT);
buffer_->Add(index, zone()); buffer_->Add(index);
} }
void Translation::StoreFloatStackSlot(int index) { void Translation::StoreFloatStackSlot(int index) {
buffer_->Add(FLOAT_STACK_SLOT, zone()); buffer_->Add(FLOAT_STACK_SLOT);
buffer_->Add(index, zone()); buffer_->Add(index);
} }
void Translation::StoreDoubleStackSlot(int index) { void Translation::StoreDoubleStackSlot(int index) {
buffer_->Add(DOUBLE_STACK_SLOT, zone()); buffer_->Add(DOUBLE_STACK_SLOT);
buffer_->Add(index, zone()); buffer_->Add(index);
} }
void Translation::StoreLiteral(int literal_id) { void Translation::StoreLiteral(int literal_id) {
buffer_->Add(LITERAL, zone()); buffer_->Add(LITERAL);
buffer_->Add(literal_id, zone()); buffer_->Add(literal_id);
} }
void Translation::StoreArgumentsObject(bool args_known, void Translation::StoreArgumentsObject(bool args_known,
int args_index, int args_index,
int args_length) { int args_length) {
buffer_->Add(ARGUMENTS_OBJECT, zone()); buffer_->Add(ARGUMENTS_OBJECT);
buffer_->Add(args_known, zone()); buffer_->Add(args_known);
buffer_->Add(args_index, zone()); buffer_->Add(args_index);
buffer_->Add(args_length, zone()); buffer_->Add(args_length);
} }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "src/deoptimize-reason.h" #include "src/deoptimize-reason.h"
#include "src/macro-assembler.h" #include "src/macro-assembler.h"
#include "src/source-position.h" #include "src/source-position.h"
#include "src/zone/zone-chunk-list.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
...@@ -844,15 +845,15 @@ class DeoptimizerData { ...@@ -844,15 +845,15 @@ class DeoptimizerData {
class TranslationBuffer BASE_EMBEDDED { class TranslationBuffer BASE_EMBEDDED {
public: public:
explicit TranslationBuffer(Zone* zone) : contents_(256, zone) { } explicit TranslationBuffer(Zone* zone) : contents_(zone) {}
int CurrentIndex() const { return contents_.length(); } int CurrentIndex() const { return static_cast<int>(contents_.size()); }
void Add(int32_t value, Zone* zone); void Add(int32_t value);
Handle<ByteArray> CreateByteArray(Factory* factory); Handle<ByteArray> CreateByteArray(Factory* factory);
private: private:
ZoneList<uint8_t> contents_; ZoneChunkList<uint8_t> contents_;
}; };
...@@ -917,9 +918,9 @@ class Translation BASE_EMBEDDED { ...@@ -917,9 +918,9 @@ class Translation BASE_EMBEDDED {
: buffer_(buffer), : buffer_(buffer),
index_(buffer->CurrentIndex()), index_(buffer->CurrentIndex()),
zone_(zone) { zone_(zone) {
buffer_->Add(BEGIN, zone); buffer_->Add(BEGIN);
buffer_->Add(frame_count, zone); buffer_->Add(frame_count);
buffer_->Add(jsframe_count, zone); buffer_->Add(jsframe_count);
} }
int index() const { return index_; } int index() const { return index_; }
......
...@@ -82,6 +82,8 @@ class ZoneChunkList : public ZoneObject { ...@@ -82,6 +82,8 @@ class ZoneChunkList : public ZoneObject {
// TODO(heimbuef): Add 'rFind', seeking from the end and returning a // TODO(heimbuef): Add 'rFind', seeking from the end and returning a
// reverse iterator. // reverse iterator.
void CopyTo(T* ptr);
ForwardZoneChunkListIterator<T> begin(); ForwardZoneChunkListIterator<T> begin();
ForwardZoneChunkListIterator<T> end(); ForwardZoneChunkListIterator<T> end();
ReverseZoneChunkListIterator<T> rbegin(); ReverseZoneChunkListIterator<T> rbegin();
...@@ -391,6 +393,19 @@ ForwardZoneChunkListIterator<const T> ZoneChunkList<T>::Find( ...@@ -391,6 +393,19 @@ ForwardZoneChunkListIterator<const T> ZoneChunkList<T>::Find(
seek_result.chunk_index_); seek_result.chunk_index_);
} }
template <typename T>
void ZoneChunkList<T>::CopyTo(T* ptr) {
for (Chunk* current = front_; current != nullptr; current = current->next_) {
void* start = current->items();
void* end = current->items() + current->position_;
size_t bytes = static_cast<size_t>(reinterpret_cast<uintptr_t>(end) -
reinterpret_cast<uintptr_t>(start));
MemCopy(ptr, current->items(), bytes);
ptr += current->position_;
}
}
template <typename T> template <typename T>
ForwardZoneChunkListIterator<T> ZoneChunkList<T>::begin() { ForwardZoneChunkListIterator<T> ZoneChunkList<T>::begin() {
return ForwardZoneChunkListIterator<T>::Begin(this); return ForwardZoneChunkListIterator<T>::Begin(this);
......
...@@ -140,5 +140,68 @@ TEST(ZoneChunkList, FindTest) { ...@@ -140,5 +140,68 @@ TEST(ZoneChunkList, FindTest) {
EXPECT_EQ(*zone_chunk_list.Find(index), 42); EXPECT_EQ(*zone_chunk_list.Find(index), 42);
} }
TEST(ZoneChunkList, CopyToTest) {
AccountingAllocator allocator;
Zone zone(&allocator, ZONE_NAME);
ZoneChunkList<uintptr_t> zone_chunk_list(&zone);
for (size_t i = 0; i < kItemCount; ++i) {
zone_chunk_list.push_back(static_cast<uintptr_t>(i));
}
uintptr_t* array = zone.NewArray<uintptr_t>(kItemCount);
zone_chunk_list.CopyTo(array);
for (size_t i = 0; i < kItemCount; ++i) {
EXPECT_EQ(array[i], static_cast<uintptr_t>(i));
}
}
TEST(ZoneChunkList, SmallCopyToTest) {
AccountingAllocator allocator;
Zone zone(&allocator, ZONE_NAME);
ZoneChunkList<uint8_t> zone_chunk_list(&zone);
for (size_t i = 0; i < kItemCount; ++i) {
zone_chunk_list.push_back(static_cast<uint8_t>(i & 0xFF));
}
uint8_t* array = zone.NewArray<uint8_t>(kItemCount);
zone_chunk_list.CopyTo(array);
for (size_t i = 0; i < kItemCount; ++i) {
EXPECT_EQ(array[i], static_cast<uint8_t>(i & 0xFF));
}
}
struct Fubar {
size_t a_;
size_t b_;
};
TEST(ZoneChunkList, BigCopyToTest) {
AccountingAllocator allocator;
Zone zone(&allocator, ZONE_NAME);
ZoneChunkList<Fubar> zone_chunk_list(&zone);
for (size_t i = 0; i < kItemCount; ++i) {
zone_chunk_list.push_back({i, i + 5});
}
Fubar* array = zone.NewArray<Fubar>(kItemCount);
zone_chunk_list.CopyTo(array);
for (size_t i = 0; i < kItemCount; ++i) {
EXPECT_EQ(array[i].a_, i);
EXPECT_EQ(array[i].b_, i + 5);
}
}
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
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