Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Unified Diff: src/interpreter/constant-array-builder.cc

Issue 2226333002: [Interpreter] Avoid allocating handles in bytecode-array-writer (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@offheap_varchecks
Patch Set: [Interpreter] Avoid allocating handles in bytecode-array-writer Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/interpreter/constant-array-builder.cc
diff --git a/src/interpreter/constant-array-builder.cc b/src/interpreter/constant-array-builder.cc
index 425bfc6cbcb1856d515761c3da8e1c5c9c03da53..7c37586417601ed587c38c9830d041077c6b0517 100644
--- a/src/interpreter/constant-array-builder.cc
+++ b/src/interpreter/constant-array-builder.cc
@@ -71,7 +71,10 @@ STATIC_CONST_MEMBER_DEFINITION const size_t
ConstantArrayBuilder::k32BitCapacity;
ConstantArrayBuilder::ConstantArrayBuilder(Isolate* isolate, Zone* zone)
- : isolate_(isolate), constants_map_(zone) {
+ : isolate_(isolate),
+ constants_map_(zone),
+ smi_map_(zone),
+ smi_pairs_(zone) {
idx_slice_[0] =
new (zone) ConstantArraySlice(zone, 0, k8BitCapacity, OperandSize::kByte);
idx_slice_[1] = new (zone) ConstantArraySlice(
@@ -113,6 +116,12 @@ Handle<Object> ConstantArrayBuilder::At(size_t index) const {
}
Handle<FixedArray> ConstantArrayBuilder::ToFixedArray() {
+ // First insert reserved SMI values.
+ for (auto reserved_smi : smi_pairs_) {
+ InsertAllocatedEntry(reserved_smi.second,
+ handle(reserved_smi.first, isolate_));
+ }
+
Handle<FixedArray> fixed_array = isolate_->factory()->NewFixedArray(
static_cast<int>(size()), PretenureFlag::TENURED);
int array_index = 0;
@@ -209,13 +218,21 @@ OperandSize ConstantArrayBuilder::CreateReservedEntry() {
return OperandSize::kNone;
}
+ConstantArrayBuilder::index_t ConstantArrayBuilder::AllocateReservedEntry(
+ Smi* value) {
+ index_t index = static_cast<index_t>(AllocateEntry());
+ smi_map_[value] = index;
+ smi_pairs_.push_back(std::make_pair(value, index));
+ return index;
+}
+
size_t ConstantArrayBuilder::CommitReservedEntry(OperandSize operand_size,
- Handle<Object> object) {
+ Smi* value) {
DiscardReservedEntry(operand_size);
size_t index;
- auto entry = constants_map_.find(object.address());
- if (entry == constants_map_.end()) {
- index = AllocateEntry(object);
+ auto entry = smi_map_.find(value);
+ if (entry == smi_map_.end()) {
+ index = AllocateReservedEntry(value);
} else {
ConstantArraySlice* slice = OperandSizeToSlice(operand_size);
index = entry->second;
@@ -223,9 +240,9 @@ size_t ConstantArrayBuilder::CommitReservedEntry(OperandSize operand_size,
// The object is already in the constant array, but may have an
// index too big for the reserved operand_size. So, duplicate
// entry with the smaller operand size.
- index = slice->Allocate(object);
- constants_map_[object.address()] = static_cast<index_t>(index);
+ index = AllocateReservedEntry(value);
}
+ DCHECK_LE(index, slice->max_index());
}
return index;
}
« no previous file with comments | « src/interpreter/constant-array-builder.h ('k') | test/unittests/interpreter/constant-array-builder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698