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) {
if (!entry.is_merged()) {
if (IsOnHeap() && RelocInfo::IsEmbeddedObjectMode(entry.rmode())) {
int offset = pc_offset();
saved_handles_for_raw_object_ptr_.push_back(
std::make_pair(offset, entry.value()));
saved_handles_for_raw_object_ptr_.emplace_back(offset, entry.value());
Handle<HeapObject> object(reinterpret_cast<Address*>(entry.value()));
emit(object->ptr());
DCHECK(EmbeddedObjectMatches(offset, object));
......
......@@ -1846,8 +1846,7 @@ void TurboAssembler::Jump(Address target, RelocInfo::Mode rmode,
Condition cond) {
int64_t offset = CalculateTargetOffset(target, rmode, pc_);
if (RelocInfo::IsRuntimeEntry(rmode) && IsOnHeap()) {
saved_offsets_for_runtime_entries_.push_back(
std::make_pair(pc_offset(), offset));
saved_offsets_for_runtime_entries_.emplace_back(pc_offset(), offset);
offset = CalculateTargetOffset(target, RelocInfo::NONE, pc_);
}
JumpHelper(offset, rmode, cond);
......@@ -1895,8 +1894,7 @@ void TurboAssembler::Call(Address target, RelocInfo::Mode rmode) {
if (CanUseNearCallOrJump(rmode)) {
int64_t offset = CalculateTargetOffset(target, rmode, pc_);
if (IsOnHeap() && RelocInfo::IsRuntimeEntry(rmode)) {
saved_offsets_for_runtime_entries_.push_back(
std::make_pair(pc_offset(), offset));
saved_offsets_for_runtime_entries_.emplace_back(pc_offset(), offset);
offset = CalculateTargetOffset(target, RelocInfo::NONE, pc_);
}
DCHECK(IsNearCallOffset(offset));
......
......@@ -248,6 +248,12 @@ AssemblerBase::AssemblerBase(const AssemblerOptions& options,
if (!buffer_) buffer_ = NewAssemblerBuffer(kDefaultBufferSize);
buffer_start_ = 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;
......
......@@ -420,6 +420,10 @@ class V8_EXPORT_PRIVATE AssemblerBase : public Malloced {
CodeCommentsWriter code_comments_writer_;
// 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, uint32_t>> saved_offsets_for_runtime_entries_;
......
......@@ -356,8 +356,7 @@ void ConstantPool::Emit(const ConstantPoolKey& key) {
if (assm_->IsOnHeap() && RelocInfo::IsEmbeddedObjectMode(key.rmode())) {
int offset = assm_->pc_offset();
Assembler::EmbeddedObjectIndex index = key.value64();
assm_->saved_handles_for_raw_object_ptr_.push_back(
std::make_pair(offset, index));
assm_->saved_handles_for_raw_object_ptr_.emplace_back(offset, index);
Handle<Object> object = assm_->GetEmbeddedObject(index);
assm_->dq(object->ptr());
DCHECK(assm_->EmbeddedObjectMatches(offset, object, index));
......
......@@ -1398,8 +1398,7 @@ void TurboAssembler::li(Register rd, Operand j, LiFlags mode) {
BlockGrowBufferScope block_growbuffer(this);
int offset = pc_offset();
Address address = j.immediate();
saved_handles_for_raw_object_ptr_.push_back(
std::make_pair(offset, address));
saved_handles_for_raw_object_ptr_.emplace_back(offset, address);
Handle<HeapObject> object(reinterpret_cast<Address*>(address));
int32_t immediate = object->ptr();
RecordRelocInfo(j.rmode(), immediate);
......
......@@ -1918,8 +1918,7 @@ void TurboAssembler::li(Register rd, Operand j, LiFlags mode) {
BlockGrowBufferScope block_growbuffer(this);
int offset = pc_offset();
Address address = j.immediate();
saved_handles_for_raw_object_ptr_.push_back(
std::make_pair(offset, address));
saved_handles_for_raw_object_ptr_.emplace_back(offset, address);
Handle<HeapObject> object(reinterpret_cast<Address*>(address));
int64_t immediate = object->ptr();
RecordRelocInfo(j.rmode(), immediate);
......
......@@ -1674,8 +1674,7 @@ void TurboAssembler::li(Register rd, Operand j, LiFlags mode) {
BlockGrowBufferScope block_growbuffer(this);
int offset = pc_offset();
Address address = j.immediate();
saved_handles_for_raw_object_ptr_.push_back(
std::make_pair(offset, address));
saved_handles_for_raw_object_ptr_.emplace_back(offset, address);
Handle<HeapObject> object(reinterpret_cast<Address*>(address));
int64_t immediate = object->ptr();
RecordRelocInfo(j.rmode(), immediate);
......
......@@ -42,8 +42,7 @@ void Assembler::emit_runtime_entry(Address entry, RelocInfo::Mode rmode) {
RecordRelocInfo(rmode);
uint32_t offset = static_cast<uint32_t>(entry - options().code_range_start);
if (IsOnHeap()) {
saved_offsets_for_runtime_entries_.push_back(
std::make_pair(pc_offset(), offset));
saved_offsets_for_runtime_entries_.emplace_back(pc_offset(), offset);
emitl(relative_target_offset(entry, reinterpret_cast<Address>(pc_)));
// We must ensure that `emitl` is not growing the assembler buffer
// and falling back to off-heap compilation.
......@@ -66,8 +65,7 @@ void Assembler::emit(Immediate64 x) {
if (x.rmode_ == RelocInfo::FULL_EMBEDDED_OBJECT && IsOnHeap()) {
int offset = pc_offset();
Handle<HeapObject> object(reinterpret_cast<Address*>(x.value_));
saved_handles_for_raw_object_ptr_.push_back(
std::make_pair(offset, x.value_));
saved_handles_for_raw_object_ptr_.emplace_back(offset, x.value_);
emitq(static_cast<uint64_t>(object->ptr()));
DCHECK(EmbeddedObjectMatches(offset, object));
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