Commit 4faf8b52 authored by Ross McIlroy's avatar Ross McIlroy Committed by Commit Bot

[TurboFan][TurboProp] Optimize bytecode iterator.

Optimize BytecodeArrayRandomIterator to reserve roughly the right
size index array based on bytecode array length. Also save the
bytecode length in BytecodeArrayAccessor to avoid a more expensive
heap read accessor on BytecodeArray.

BUG=v8:9684

Change-Id: I7f85439877dbfc5ccf5aacc9d4006bd285f1c891
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2593330
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Auto-Submit: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71772}
parent 13921eb7
......@@ -57,6 +57,7 @@ class OnHeapBytecodeArray final : public AbstractBytecodeArray {
BytecodeArrayAccessor::BytecodeArrayAccessor(
std::unique_ptr<AbstractBytecodeArray> bytecode_array, int initial_offset)
: bytecode_array_(std::move(bytecode_array)),
bytecode_length_(bytecode_array_->length()),
bytecode_offset_(initial_offset),
operand_scale_(OperandScale::kSingle),
prefix_offset_(0) {
......@@ -103,7 +104,7 @@ void BytecodeArrayAccessor::UpdateOperandScale() {
}
bool BytecodeArrayAccessor::OffsetInBounds() const {
return bytecode_offset_ >= 0 && bytecode_offset_ < bytecode_array()->length();
return bytecode_offset_ >= 0 && bytecode_offset_ < bytecode_length_;
}
Bytecode BytecodeArrayAccessor::current_bytecode() const {
......
......@@ -147,6 +147,8 @@ class V8_EXPORT_PRIVATE BytecodeArrayAccessor {
std::ostream& PrintTo(std::ostream& os) const;
int bytecode_length() const { return bytecode_length_; }
private:
bool OffsetInBounds() const;
......@@ -157,6 +159,7 @@ class V8_EXPORT_PRIVATE BytecodeArrayAccessor {
void UpdateOperandScale();
std::unique_ptr<AbstractBytecodeArray> bytecode_array_;
const int bytecode_length_;
int bytecode_offset_;
OperandScale operand_scale_;
int prefix_offset_;
......
......@@ -23,7 +23,7 @@ void BytecodeArrayIterator::Advance() {
}
bool BytecodeArrayIterator::done() const {
return current_offset() >= bytecode_array()->length();
return current_offset() >= bytecode_length();
}
} // namespace interpreter
......
......@@ -13,6 +13,7 @@ namespace interpreter {
BytecodeArrayRandomIterator::BytecodeArrayRandomIterator(
Handle<BytecodeArray> bytecode_array, Zone* zone)
: BytecodeArrayAccessor(bytecode_array, 0), offsets_(zone) {
offsets_.reserve(bytecode_array->length() / 2);
Initialize();
}
......
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