Commit 24886f2d authored by Sigurd Schneider's avatar Sigurd Schneider Committed by Commit Bot

[arm64,x64] Deduplicate entries in constant pools on arm64 and x64

This CL deduplicates entries in constant pools based on handle
location. This works well because we already use CanonicalHandleScope
in the right places.

The CL gives a ~2% speed-up on octane for arm64. The code size is
reduced significantly as well: Before the change all generated code
spend on constant pools during an Octane run on arm64 was 723kb
(90398 64bit words) before this change, and after this change only
spend 189kb (23615 64bit words) were spend on constant pools. This
is a 73.8% reduction.


Change-Id: If0bb83453a45c0df0d1b0fee591c04c621341af1
Bug: v8:8054, v8:8977, v8:7703
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1672924
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62324}
parent b1638b08
......@@ -226,9 +226,22 @@ int AssemblerBase::AddCodeTarget(Handle<Code> target) {
}
}
Handle<Code> AssemblerBase::GetCodeTarget(intptr_t code_target_index) const {
DCHECK_LT(static_cast<size_t>(code_target_index), code_targets_.size());
return code_targets_[code_target_index];
}
AssemblerBase::EmbeddedObjectIndex AssemblerBase::AddEmbeddedObject(
Handle<HeapObject> object) {
EmbeddedObjectIndex current = embedded_objects_.size();
// Do not deduplicate invalid handles, they are to heap object requests.
if (!object.is_null()) {
auto entry = embedded_objects_map_.find(object);
if (entry != embedded_objects_map_.end()) {
return entry->second;
}
embedded_objects_map_[object] = current;
}
embedded_objects_.push_back(object);
return current;
}
......@@ -239,10 +252,6 @@ Handle<HeapObject> AssemblerBase::GetEmbeddedObject(
return embedded_objects_[index];
}
Handle<Code> AssemblerBase::GetCodeTarget(intptr_t code_target_index) const {
DCHECK_LT(static_cast<size_t>(code_target_index), code_targets_.size());
return code_targets_[code_target_index];
}
int Assembler::WriteCodeComments() {
if (!FLAG_code_comments || code_comments_writer_.entry_count() == 0) return 0;
......
......@@ -36,6 +36,7 @@
#define V8_CODEGEN_ASSEMBLER_H_
#include <forward_list>
#include <unordered_map>
#include "src/base/memory.h"
#include "src/codegen/code-comments.h"
......@@ -335,6 +336,13 @@ class V8_EXPORT_PRIVATE AssemblerBase : public Malloced {
// may then refer to the heap object using the handle's index in this vector.
std::vector<Handle<HeapObject>> embedded_objects_;
// Embedded objects are deduplicated based on handle location. This is a
// compromise that is almost as effective as deduplication based on actual
// heap object addresses maintains GC safety.
std::unordered_map<Handle<HeapObject>, EmbeddedObjectIndex,
Handle<HeapObject>::hash, Handle<HeapObject>::equal_to>
embedded_objects_map_;
const AssemblerOptions options_;
uint64_t enabled_cpu_features_;
bool emit_debug_code_;
......
......@@ -200,7 +200,9 @@ class ConstantPoolKey {
bool is_sharable_code_target =
rmode_ == RelocInfo::CODE_TARGET &&
(is_value32() ? (value32() != 0) : (value64() != 0));
return RelocInfo::IsShareableRelocMode(rmode_) || is_sharable_code_target;
bool is_sharable_embedded_object = RelocInfo::IsEmbeddedObjectMode(rmode_);
return RelocInfo::IsShareableRelocMode(rmode_) || is_sharable_code_target ||
is_sharable_embedded_object;
}
private:
......
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