diff options
Diffstat (limited to 'deps/v8/src/interpreter/bytecode-array-accessor.cc')
-rw-r--r-- | deps/v8/src/interpreter/bytecode-array-accessor.cc | 92 |
1 files changed, 72 insertions, 20 deletions
diff --git a/deps/v8/src/interpreter/bytecode-array-accessor.cc b/deps/v8/src/interpreter/bytecode-array-accessor.cc index d7232fcd4c..d460c1a45f 100644 --- a/deps/v8/src/interpreter/bytecode-array-accessor.cc +++ b/deps/v8/src/interpreter/bytecode-array-accessor.cc @@ -14,15 +14,61 @@ namespace v8 { namespace internal { namespace interpreter { +namespace { + +class OnHeapBytecodeArray final : public AbstractBytecodeArray { + public: + explicit OnHeapBytecodeArray(Handle<BytecodeArray> bytecode_array) + : array_(bytecode_array) {} + + int length() const override { return array_->length(); } + + int parameter_count() const override { return array_->parameter_count(); } + + uint8_t get(int index) const override { return array_->get(index); } + + void set(int index, uint8_t value) override { + return array_->set(index, value); + } + + Address GetFirstBytecodeAddress() const override { + return array_->GetFirstBytecodeAddress(); + } + + Handle<Object> GetConstantAtIndex(int index, + Isolate* isolate) const override { + return handle(array_->constant_pool().get(index), isolate); + } + + bool IsConstantAtIndexSmi(int index) const override { + return array_->constant_pool().get(index).IsSmi(); + } + + Smi GetConstantAtIndexAsSmi(int index) const override { + return Smi::cast(array_->constant_pool().get(index)); + } + + private: + Handle<BytecodeArray> array_; +}; + +} // namespace + BytecodeArrayAccessor::BytecodeArrayAccessor( - Handle<BytecodeArray> bytecode_array, int initial_offset) - : bytecode_array_(bytecode_array), + std::unique_ptr<AbstractBytecodeArray> bytecode_array, int initial_offset) + : bytecode_array_(std::move(bytecode_array)), bytecode_offset_(initial_offset), operand_scale_(OperandScale::kSingle), prefix_offset_(0) { UpdateOperandScale(); } +BytecodeArrayAccessor::BytecodeArrayAccessor( + Handle<BytecodeArray> bytecode_array, int initial_offset) + : BytecodeArrayAccessor( + base::make_unique<OnHeapBytecodeArray>(bytecode_array), + initial_offset) {} + void BytecodeArrayAccessor::SetOffset(int offset) { bytecode_offset_ = offset; UpdateOperandScale(); @@ -33,12 +79,12 @@ void BytecodeArrayAccessor::ApplyDebugBreak() { // scaling prefix, which we can patch with the matching debug-break // variant. interpreter::Bytecode bytecode = - interpreter::Bytecodes::FromByte(bytecode_array_->get(bytecode_offset_)); + interpreter::Bytecodes::FromByte(bytecode_array()->get(bytecode_offset_)); if (interpreter::Bytecodes::IsDebugBreak(bytecode)) return; interpreter::Bytecode debugbreak = interpreter::Bytecodes::GetDebugBreak(bytecode); - bytecode_array_->set(bytecode_offset_, - interpreter::Bytecodes::ToByte(debugbreak)); + bytecode_array()->set(bytecode_offset_, + interpreter::Bytecodes::ToByte(debugbreak)); } void BytecodeArrayAccessor::UpdateOperandScale() { @@ -197,13 +243,22 @@ Runtime::FunctionId BytecodeArrayAccessor::GetIntrinsicIdOperand( static_cast<IntrinsicsHelper::IntrinsicId>(raw_id)); } -Object BytecodeArrayAccessor::GetConstantAtIndex(int index) const { - return bytecode_array()->constant_pool().get(index); +Handle<Object> BytecodeArrayAccessor::GetConstantAtIndex( + int index, Isolate* isolate) const { + return bytecode_array()->GetConstantAtIndex(index, isolate); } -Object BytecodeArrayAccessor::GetConstantForIndexOperand( - int operand_index) const { - return GetConstantAtIndex(GetIndexOperand(operand_index)); +bool BytecodeArrayAccessor::IsConstantAtIndexSmi(int index) const { + return bytecode_array()->IsConstantAtIndexSmi(index); +} + +Smi BytecodeArrayAccessor::GetConstantAtIndexAsSmi(int index) const { + return bytecode_array()->GetConstantAtIndexAsSmi(index); +} + +Handle<Object> BytecodeArrayAccessor::GetConstantForIndexOperand( + int operand_index, Isolate* isolate) const { + return GetConstantAtIndex(GetIndexOperand(operand_index), isolate); } int BytecodeArrayAccessor::GetJumpTargetOffset() const { @@ -215,7 +270,7 @@ int BytecodeArrayAccessor::GetJumpTargetOffset() const { } return GetAbsoluteOffset(relative_offset); } else if (interpreter::Bytecodes::IsJumpConstant(bytecode)) { - Smi smi = Smi::cast(GetConstantForIndexOperand(0)); + Smi smi = GetConstantAtIndexAsSmi(GetIndexOperand(0)); return GetAbsoluteOffset(smi.value()); } else { UNREACHABLE(); @@ -315,19 +370,16 @@ bool JumpTableTargetOffsets::iterator::operator!=( } void JumpTableTargetOffsets::iterator::UpdateAndAdvanceToValid() { - if (table_offset_ >= table_end_) return; - - Object current = accessor_->GetConstantAtIndex(table_offset_); - while (!current.IsSmi()) { - DCHECK(current.IsTheHole()); + while (table_offset_ < table_end_ && + !accessor_->IsConstantAtIndexSmi(table_offset_)) { ++table_offset_; ++index_; - if (table_offset_ >= table_end_) break; - current = accessor_->GetConstantAtIndex(table_offset_); } + // Make sure we haven't reached the end of the table with a hole in current. - if (current.IsSmi()) { - current_ = Smi::cast(current); + if (table_offset_ < table_end_) { + DCHECK(accessor_->IsConstantAtIndexSmi(table_offset_)); + current_ = accessor_->GetConstantAtIndexAsSmi(table_offset_); } } |