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 { ...@@ -57,6 +57,7 @@ class OnHeapBytecodeArray final : public AbstractBytecodeArray {
BytecodeArrayAccessor::BytecodeArrayAccessor( BytecodeArrayAccessor::BytecodeArrayAccessor(
std::unique_ptr<AbstractBytecodeArray> bytecode_array, int initial_offset) std::unique_ptr<AbstractBytecodeArray> bytecode_array, int initial_offset)
: bytecode_array_(std::move(bytecode_array)), : bytecode_array_(std::move(bytecode_array)),
bytecode_length_(bytecode_array_->length()),
bytecode_offset_(initial_offset), bytecode_offset_(initial_offset),
operand_scale_(OperandScale::kSingle), operand_scale_(OperandScale::kSingle),
prefix_offset_(0) { prefix_offset_(0) {
...@@ -103,7 +104,7 @@ void BytecodeArrayAccessor::UpdateOperandScale() { ...@@ -103,7 +104,7 @@ void BytecodeArrayAccessor::UpdateOperandScale() {
} }
bool BytecodeArrayAccessor::OffsetInBounds() const { 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 { Bytecode BytecodeArrayAccessor::current_bytecode() const {
......
...@@ -147,6 +147,8 @@ class V8_EXPORT_PRIVATE BytecodeArrayAccessor { ...@@ -147,6 +147,8 @@ class V8_EXPORT_PRIVATE BytecodeArrayAccessor {
std::ostream& PrintTo(std::ostream& os) const; std::ostream& PrintTo(std::ostream& os) const;
int bytecode_length() const { return bytecode_length_; }
private: private:
bool OffsetInBounds() const; bool OffsetInBounds() const;
...@@ -157,6 +159,7 @@ class V8_EXPORT_PRIVATE BytecodeArrayAccessor { ...@@ -157,6 +159,7 @@ class V8_EXPORT_PRIVATE BytecodeArrayAccessor {
void UpdateOperandScale(); void UpdateOperandScale();
std::unique_ptr<AbstractBytecodeArray> bytecode_array_; std::unique_ptr<AbstractBytecodeArray> bytecode_array_;
const int bytecode_length_;
int bytecode_offset_; int bytecode_offset_;
OperandScale operand_scale_; OperandScale operand_scale_;
int prefix_offset_; int prefix_offset_;
......
...@@ -23,7 +23,7 @@ void BytecodeArrayIterator::Advance() { ...@@ -23,7 +23,7 @@ void BytecodeArrayIterator::Advance() {
} }
bool BytecodeArrayIterator::done() const { bool BytecodeArrayIterator::done() const {
return current_offset() >= bytecode_array()->length(); return current_offset() >= bytecode_length();
} }
} // namespace interpreter } // namespace interpreter
......
...@@ -13,6 +13,7 @@ namespace interpreter { ...@@ -13,6 +13,7 @@ namespace interpreter {
BytecodeArrayRandomIterator::BytecodeArrayRandomIterator( BytecodeArrayRandomIterator::BytecodeArrayRandomIterator(
Handle<BytecodeArray> bytecode_array, Zone* zone) Handle<BytecodeArray> bytecode_array, Zone* zone)
: BytecodeArrayAccessor(bytecode_array, 0), offsets_(zone) { : BytecodeArrayAccessor(bytecode_array, 0), offsets_(zone) {
offsets_.reserve(bytecode_array->length() / 2);
Initialize(); 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