Commit 1a7584fe authored by Victor Gomes's avatar Victor Gomes Committed by V8 LUCI CQ

[baseline] Minor perfomance improvements SP-on-heap

Minor improvements for on heap reference vectors:
- Use emplace_back instead of push_back.
- Reserve initial capacity.

Bug: v8:11993
Change-Id: Ie2f9ad9cc48d1b48a76419459a9ac721f4079175
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3124802
Commit-Queue: Victor Gomes <victorgomes@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#76538}
parent aed61ff4
...@@ -5472,8 +5472,7 @@ void Assembler::CheckConstPool(bool force_emit, bool require_jump) { ...@@ -5472,8 +5472,7 @@ void Assembler::CheckConstPool(bool force_emit, bool require_jump) {
if (!entry.is_merged()) { if (!entry.is_merged()) {
if (IsOnHeap() && RelocInfo::IsEmbeddedObjectMode(entry.rmode())) { if (IsOnHeap() && RelocInfo::IsEmbeddedObjectMode(entry.rmode())) {
int offset = pc_offset(); int offset = pc_offset();
saved_handles_for_raw_object_ptr_.push_back( saved_handles_for_raw_object_ptr_.emplace_back(offset, entry.value());
std::make_pair(offset, entry.value()));
Handle<HeapObject> object(reinterpret_cast<Address*>(entry.value())); Handle<HeapObject> object(reinterpret_cast<Address*>(entry.value()));
emit(object->ptr()); emit(object->ptr());
DCHECK(EmbeddedObjectMatches(offset, object)); DCHECK(EmbeddedObjectMatches(offset, object));
......
...@@ -1846,8 +1846,7 @@ void TurboAssembler::Jump(Address target, RelocInfo::Mode rmode, ...@@ -1846,8 +1846,7 @@ void TurboAssembler::Jump(Address target, RelocInfo::Mode rmode,
Condition cond) { Condition cond) {
int64_t offset = CalculateTargetOffset(target, rmode, pc_); int64_t offset = CalculateTargetOffset(target, rmode, pc_);
if (RelocInfo::IsRuntimeEntry(rmode) && IsOnHeap()) { if (RelocInfo::IsRuntimeEntry(rmode) && IsOnHeap()) {
saved_offsets_for_runtime_entries_.push_back( saved_offsets_for_runtime_entries_.emplace_back(pc_offset(), offset);
std::make_pair(pc_offset(), offset));
offset = CalculateTargetOffset(target, RelocInfo::NONE, pc_); offset = CalculateTargetOffset(target, RelocInfo::NONE, pc_);
} }
JumpHelper(offset, rmode, cond); JumpHelper(offset, rmode, cond);
...@@ -1895,8 +1894,7 @@ void TurboAssembler::Call(Address target, RelocInfo::Mode rmode) { ...@@ -1895,8 +1894,7 @@ void TurboAssembler::Call(Address target, RelocInfo::Mode rmode) {
if (CanUseNearCallOrJump(rmode)) { if (CanUseNearCallOrJump(rmode)) {
int64_t offset = CalculateTargetOffset(target, rmode, pc_); int64_t offset = CalculateTargetOffset(target, rmode, pc_);
if (IsOnHeap() && RelocInfo::IsRuntimeEntry(rmode)) { if (IsOnHeap() && RelocInfo::IsRuntimeEntry(rmode)) {
saved_offsets_for_runtime_entries_.push_back( saved_offsets_for_runtime_entries_.emplace_back(pc_offset(), offset);
std::make_pair(pc_offset(), offset));
offset = CalculateTargetOffset(target, RelocInfo::NONE, pc_); offset = CalculateTargetOffset(target, RelocInfo::NONE, pc_);
} }
DCHECK(IsNearCallOffset(offset)); DCHECK(IsNearCallOffset(offset));
......
...@@ -248,6 +248,12 @@ AssemblerBase::AssemblerBase(const AssemblerOptions& options, ...@@ -248,6 +248,12 @@ AssemblerBase::AssemblerBase(const AssemblerOptions& options,
if (!buffer_) buffer_ = NewAssemblerBuffer(kDefaultBufferSize); if (!buffer_) buffer_ = NewAssemblerBuffer(kDefaultBufferSize);
buffer_start_ = buffer_->start(); buffer_start_ = buffer_->start();
pc_ = buffer_start_; pc_ = buffer_start_;
if (IsOnHeap()) {
saved_handles_for_raw_object_ptr_.reserve(
kSavedHandleForRawObjectsInitialSize);
saved_offsets_for_runtime_entries_.reserve(
kSavedOffsetForRuntimeEntriesInitialSize);
}
} }
AssemblerBase::~AssemblerBase() = default; AssemblerBase::~AssemblerBase() = default;
......
...@@ -420,6 +420,10 @@ class V8_EXPORT_PRIVATE AssemblerBase : public Malloced { ...@@ -420,6 +420,10 @@ class V8_EXPORT_PRIVATE AssemblerBase : public Malloced {
CodeCommentsWriter code_comments_writer_; CodeCommentsWriter code_comments_writer_;
// Relocation information when code allocated directly on heap. // Relocation information when code allocated directly on heap.
// These constants correspond to the 99% percentile of a selected number of JS
// frameworks and benchmarks, including jquery, lodash, d3 and speedometer3.
const int kSavedHandleForRawObjectsInitialSize = 60;
const int kSavedOffsetForRuntimeEntriesInitialSize = 100;
std::vector<std::pair<uint32_t, Address>> saved_handles_for_raw_object_ptr_; std::vector<std::pair<uint32_t, Address>> saved_handles_for_raw_object_ptr_;
std::vector<std::pair<uint32_t, uint32_t>> saved_offsets_for_runtime_entries_; std::vector<std::pair<uint32_t, uint32_t>> saved_offsets_for_runtime_entries_;
......
...@@ -356,8 +356,7 @@ void ConstantPool::Emit(const ConstantPoolKey& key) { ...@@ -356,8 +356,7 @@ void ConstantPool::Emit(const ConstantPoolKey& key) {
if (assm_->IsOnHeap() && RelocInfo::IsEmbeddedObjectMode(key.rmode())) { if (assm_->IsOnHeap() && RelocInfo::IsEmbeddedObjectMode(key.rmode())) {
int offset = assm_->pc_offset(); int offset = assm_->pc_offset();
Assembler::EmbeddedObjectIndex index = key.value64(); Assembler::EmbeddedObjectIndex index = key.value64();
assm_->saved_handles_for_raw_object_ptr_.push_back( assm_->saved_handles_for_raw_object_ptr_.emplace_back(offset, index);
std::make_pair(offset, index));
Handle<Object> object = assm_->GetEmbeddedObject(index); Handle<Object> object = assm_->GetEmbeddedObject(index);
assm_->dq(object->ptr()); assm_->dq(object->ptr());
DCHECK(assm_->EmbeddedObjectMatches(offset, object, index)); DCHECK(assm_->EmbeddedObjectMatches(offset, object, index));
......
...@@ -1398,8 +1398,7 @@ void TurboAssembler::li(Register rd, Operand j, LiFlags mode) { ...@@ -1398,8 +1398,7 @@ void TurboAssembler::li(Register rd, Operand j, LiFlags mode) {
BlockGrowBufferScope block_growbuffer(this); BlockGrowBufferScope block_growbuffer(this);
int offset = pc_offset(); int offset = pc_offset();
Address address = j.immediate(); Address address = j.immediate();
saved_handles_for_raw_object_ptr_.push_back( saved_handles_for_raw_object_ptr_.emplace_back(offset, address);
std::make_pair(offset, address));
Handle<HeapObject> object(reinterpret_cast<Address*>(address)); Handle<HeapObject> object(reinterpret_cast<Address*>(address));
int32_t immediate = object->ptr(); int32_t immediate = object->ptr();
RecordRelocInfo(j.rmode(), immediate); RecordRelocInfo(j.rmode(), immediate);
......
...@@ -1918,8 +1918,7 @@ void TurboAssembler::li(Register rd, Operand j, LiFlags mode) { ...@@ -1918,8 +1918,7 @@ void TurboAssembler::li(Register rd, Operand j, LiFlags mode) {
BlockGrowBufferScope block_growbuffer(this); BlockGrowBufferScope block_growbuffer(this);
int offset = pc_offset(); int offset = pc_offset();
Address address = j.immediate(); Address address = j.immediate();
saved_handles_for_raw_object_ptr_.push_back( saved_handles_for_raw_object_ptr_.emplace_back(offset, address);
std::make_pair(offset, address));
Handle<HeapObject> object(reinterpret_cast<Address*>(address)); Handle<HeapObject> object(reinterpret_cast<Address*>(address));
int64_t immediate = object->ptr(); int64_t immediate = object->ptr();
RecordRelocInfo(j.rmode(), immediate); RecordRelocInfo(j.rmode(), immediate);
......
...@@ -1674,8 +1674,7 @@ void TurboAssembler::li(Register rd, Operand j, LiFlags mode) { ...@@ -1674,8 +1674,7 @@ void TurboAssembler::li(Register rd, Operand j, LiFlags mode) {
BlockGrowBufferScope block_growbuffer(this); BlockGrowBufferScope block_growbuffer(this);
int offset = pc_offset(); int offset = pc_offset();
Address address = j.immediate(); Address address = j.immediate();
saved_handles_for_raw_object_ptr_.push_back( saved_handles_for_raw_object_ptr_.emplace_back(offset, address);
std::make_pair(offset, address));
Handle<HeapObject> object(reinterpret_cast<Address*>(address)); Handle<HeapObject> object(reinterpret_cast<Address*>(address));
int64_t immediate = object->ptr(); int64_t immediate = object->ptr();
RecordRelocInfo(j.rmode(), immediate); RecordRelocInfo(j.rmode(), immediate);
......
...@@ -42,8 +42,7 @@ void Assembler::emit_runtime_entry(Address entry, RelocInfo::Mode rmode) { ...@@ -42,8 +42,7 @@ void Assembler::emit_runtime_entry(Address entry, RelocInfo::Mode rmode) {
RecordRelocInfo(rmode); RecordRelocInfo(rmode);
uint32_t offset = static_cast<uint32_t>(entry - options().code_range_start); uint32_t offset = static_cast<uint32_t>(entry - options().code_range_start);
if (IsOnHeap()) { if (IsOnHeap()) {
saved_offsets_for_runtime_entries_.push_back( saved_offsets_for_runtime_entries_.emplace_back(pc_offset(), offset);
std::make_pair(pc_offset(), offset));
emitl(relative_target_offset(entry, reinterpret_cast<Address>(pc_))); emitl(relative_target_offset(entry, reinterpret_cast<Address>(pc_)));
// We must ensure that `emitl` is not growing the assembler buffer // We must ensure that `emitl` is not growing the assembler buffer
// and falling back to off-heap compilation. // and falling back to off-heap compilation.
...@@ -66,8 +65,7 @@ void Assembler::emit(Immediate64 x) { ...@@ -66,8 +65,7 @@ void Assembler::emit(Immediate64 x) {
if (x.rmode_ == RelocInfo::FULL_EMBEDDED_OBJECT && IsOnHeap()) { if (x.rmode_ == RelocInfo::FULL_EMBEDDED_OBJECT && IsOnHeap()) {
int offset = pc_offset(); int offset = pc_offset();
Handle<HeapObject> object(reinterpret_cast<Address*>(x.value_)); Handle<HeapObject> object(reinterpret_cast<Address*>(x.value_));
saved_handles_for_raw_object_ptr_.push_back( saved_handles_for_raw_object_ptr_.emplace_back(offset, x.value_);
std::make_pair(offset, x.value_));
emitq(static_cast<uint64_t>(object->ptr())); emitq(static_cast<uint64_t>(object->ptr()));
DCHECK(EmbeddedObjectMatches(offset, object)); DCHECK(EmbeddedObjectMatches(offset, object));
return; return;
......
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