Eliminate AbstractBytecodeArray and its concrete subclasses

AbstractBytecodeArray was introduced in order to let the bytecode
array accessor work on either a Handle<BytecodeArray> or a serialized
BytecodeArrayRef. We have since implemented direct heap access for
bytecode arrays, so we can now remove the abstraction again.

Note that this means that as far as bytecode iteration is concerned
we no longer access the bytecode array through the BytecodeArrayRef.
I will remove the obsolete methods from that class in a follow-up CL.
The downside is the loss of this explicit interface. The upside is
simplicity and less code. We can justify the downside with the fact
that the bytecode array data is immutable and thus the Ref indirection
less meaningful than in other cases.

Bug: v8:7790
Change-Id: I0fe87b4efd0f77785f5a0917ab213c6031d9cc74
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2707166
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72955}
This commit is contained in:
Georg Neis 2021-02-19 17:46:09 +01:00 committed by Commit Bot
parent b0230ead9d
commit 736d3448a3
7 changed files with 88 additions and 200 deletions

View File

@ -412,6 +412,12 @@ class BytecodeGraphBuilder {
int context_register_; // Index of register holding handler context.
};
Handle<Object> GetConstantForIndexOperand(int operand_index) const {
return broker_->CanonicalPersistentHandle(
bytecode_iterator().GetConstantForIndexOperand(operand_index,
local_isolate_));
}
Graph* graph() const { return jsgraph_->graph(); }
CommonOperatorBuilder* common() const { return jsgraph_->common(); }
Zone* graph_zone() const { return graph()->zone(); }
@ -435,6 +441,9 @@ class BytecodeGraphBuilder {
SourcePositionTableIterator& source_position_iterator() {
return *source_position_iterator_.get();
}
interpreter::BytecodeArrayIterator const& bytecode_iterator() const {
return bytecode_iterator_;
}
interpreter::BytecodeArrayIterator& bytecode_iterator() {
return bytecode_iterator_;
}
@ -465,6 +474,7 @@ class BytecodeGraphBuilder {
#undef DECLARE_VISIT_BYTECODE
JSHeapBroker* const broker_;
LocalIsolate* const local_isolate_;
Zone* const local_zone_;
JSGraph* const jsgraph_;
// The native context for which we optimize.
@ -1048,6 +1058,9 @@ BytecodeGraphBuilder::BytecodeGraphBuilder(
BytecodeGraphBuilderFlags flags, TickCounter* tick_counter,
ObserveNodeInfo const& observe_node_info)
: broker_(broker),
local_isolate_(broker_->local_isolate()
? broker_->local_isolate()
: broker_->isolate()->AsLocalIsolate()),
local_zone_(local_zone),
jsgraph_(jsgraph),
native_context_(native_context),
@ -1066,8 +1079,7 @@ BytecodeGraphBuilder::BytecodeGraphBuilder(
shared_info.object())),
source_position_iterator_(std::make_unique<SourcePositionTableIterator>(
bytecode_array().SourcePositionTable())),
bytecode_iterator_(
std::make_unique<OffHeapBytecodeArray>(bytecode_array())),
bytecode_iterator_(bytecode_array().object()),
bytecode_analysis_(
bytecode_array().object(), local_zone, osr_offset,
flags & BytecodeGraphBuilderFlag::kAnalyzeEnvironmentLiveness),
@ -1577,8 +1589,7 @@ void BytecodeGraphBuilder::VisitLdaSmi() {
}
void BytecodeGraphBuilder::VisitLdaConstant() {
ObjectRef object(broker(),
bytecode_iterator().GetConstantForIndexOperand(0, isolate()),
ObjectRef object(broker(), GetConstantForIndexOperand(0),
ObjectRef::BackgroundSerialization::kAllowed);
Node* node = jsgraph()->Constant(object);
environment()->BindAccumulator(node);
@ -1649,8 +1660,7 @@ Node* BytecodeGraphBuilder::BuildLoadGlobal(NameRef name,
void BytecodeGraphBuilder::VisitLdaGlobal() {
PrepareEagerCheckpoint();
NameRef name(broker(),
bytecode_iterator().GetConstantForIndexOperand(0, isolate()));
NameRef name(broker(), GetConstantForIndexOperand(0));
uint32_t feedback_slot_index = bytecode_iterator().GetIndexOperand(1);
Node* node =
BuildLoadGlobal(name, feedback_slot_index, TypeofMode::NOT_INSIDE_TYPEOF);
@ -1659,8 +1669,7 @@ void BytecodeGraphBuilder::VisitLdaGlobal() {
void BytecodeGraphBuilder::VisitLdaGlobalInsideTypeof() {
PrepareEagerCheckpoint();
NameRef name(broker(),
bytecode_iterator().GetConstantForIndexOperand(0, isolate()));
NameRef name(broker(), GetConstantForIndexOperand(0));
uint32_t feedback_slot_index = bytecode_iterator().GetIndexOperand(1);
Node* node =
BuildLoadGlobal(name, feedback_slot_index, TypeofMode::INSIDE_TYPEOF);
@ -1669,8 +1678,7 @@ void BytecodeGraphBuilder::VisitLdaGlobalInsideTypeof() {
void BytecodeGraphBuilder::VisitStaGlobal() {
PrepareEagerCheckpoint();
NameRef name(broker(),
bytecode_iterator().GetConstantForIndexOperand(0, isolate()));
NameRef name(broker(), GetConstantForIndexOperand(0));
FeedbackSource feedback =
CreateFeedbackSource(bytecode_iterator().GetIndexOperand(1));
Node* value = environment()->LookupAccumulator();
@ -1811,8 +1819,8 @@ void BytecodeGraphBuilder::VisitStaCurrentContextSlot() {
void BytecodeGraphBuilder::BuildLdaLookupSlot(TypeofMode typeof_mode) {
PrepareEagerCheckpoint();
Node* name = jsgraph()->Constant(ObjectRef(
broker(), bytecode_iterator().GetConstantForIndexOperand(0, isolate())));
Node* name =
jsgraph()->Constant(ObjectRef(broker(), GetConstantForIndexOperand(0)));
const Operator* op =
javascript()->CallRuntime(typeof_mode == TypeofMode::NOT_INSIDE_TYPEOF
? Runtime::kLoadLookupSlot
@ -1964,9 +1972,8 @@ void BytecodeGraphBuilder::BuildLdaLookupContextSlot(TypeofMode typeof_mode) {
// Slow path, do a runtime load lookup.
set_environment(slow_environment);
{
Node* name = jsgraph()->Constant(ObjectRef(
broker(),
bytecode_iterator().GetConstantForIndexOperand(0, isolate())));
Node* name = jsgraph()->Constant(
ObjectRef(broker(), GetConstantForIndexOperand(0)));
const Operator* op =
javascript()->CallRuntime(typeof_mode == TypeofMode::NOT_INSIDE_TYPEOF
@ -2001,8 +2008,7 @@ void BytecodeGraphBuilder::BuildLdaLookupGlobalSlot(TypeofMode typeof_mode) {
// Fast path, do a global load.
{
PrepareEagerCheckpoint();
NameRef name(broker(),
bytecode_iterator().GetConstantForIndexOperand(0, isolate()));
NameRef name(broker(), GetConstantForIndexOperand(0));
uint32_t feedback_slot_index = bytecode_iterator().GetIndexOperand(1);
Node* node = BuildLoadGlobal(name, feedback_slot_index, typeof_mode);
environment()->BindAccumulator(node, Environment::kAttachFrameState);
@ -2017,9 +2023,8 @@ void BytecodeGraphBuilder::BuildLdaLookupGlobalSlot(TypeofMode typeof_mode) {
// Slow path, do a runtime load lookup.
set_environment(slow_environment);
{
Node* name = jsgraph()->Constant(NameRef(
broker(),
bytecode_iterator().GetConstantForIndexOperand(0, isolate())));
Node* name =
jsgraph()->Constant(NameRef(broker(), GetConstantForIndexOperand(0)));
const Operator* op =
javascript()->CallRuntime(typeof_mode == TypeofMode::NOT_INSIDE_TYPEOF
@ -2048,8 +2053,8 @@ void BytecodeGraphBuilder::VisitLdaLookupGlobalSlotInsideTypeof() {
void BytecodeGraphBuilder::VisitStaLookupSlot() {
PrepareEagerCheckpoint();
Node* value = environment()->LookupAccumulator();
Node* name = jsgraph()->Constant(ObjectRef(
broker(), bytecode_iterator().GetConstantForIndexOperand(0, isolate())));
Node* name =
jsgraph()->Constant(ObjectRef(broker(), GetConstantForIndexOperand(0)));
int bytecode_flags = bytecode_iterator().GetFlagOperand(1);
LanguageMode language_mode = static_cast<LanguageMode>(
interpreter::StoreLookupSlotFlags::LanguageModeBit::decode(
@ -2073,8 +2078,7 @@ void BytecodeGraphBuilder::VisitLdaNamedProperty() {
PrepareEagerCheckpoint();
Node* object =
environment()->LookupRegister(bytecode_iterator().GetRegisterOperand(0));
NameRef name(broker(),
bytecode_iterator().GetConstantForIndexOperand(1, isolate()));
NameRef name(broker(), GetConstantForIndexOperand(1));
FeedbackSource feedback =
CreateFeedbackSource(bytecode_iterator().GetIndexOperand(2));
const Operator* op = javascript()->LoadNamed(name.object(), feedback);
@ -2098,8 +2102,7 @@ void BytecodeGraphBuilder::VisitLdaNamedPropertyNoFeedback() {
PrepareEagerCheckpoint();
Node* object =
environment()->LookupRegister(bytecode_iterator().GetRegisterOperand(0));
NameRef name(broker(),
bytecode_iterator().GetConstantForIndexOperand(1, isolate()));
NameRef name(broker(), GetConstantForIndexOperand(1));
const Operator* op = javascript()->LoadNamed(name.object(), FeedbackSource());
DCHECK(IrOpcode::IsFeedbackCollectingOpcode(op->opcode()));
Node* node = NewNode(op, object, feedback_vector_node());
@ -2111,8 +2114,7 @@ void BytecodeGraphBuilder::VisitLdaNamedPropertyFromSuper() {
Node* receiver =
environment()->LookupRegister(bytecode_iterator().GetRegisterOperand(0));
Node* home_object = environment()->LookupAccumulator();
NameRef name(broker(),
bytecode_iterator().GetConstantForIndexOperand(1, isolate()));
NameRef name(broker(), GetConstantForIndexOperand(1));
FeedbackSource feedback =
CreateFeedbackSource(bytecode_iterator().GetIndexOperand(2));
@ -2166,8 +2168,7 @@ void BytecodeGraphBuilder::BuildNamedStore(StoreMode store_mode) {
Node* value = environment()->LookupAccumulator();
Node* object =
environment()->LookupRegister(bytecode_iterator().GetRegisterOperand(0));
NameRef name(broker(),
bytecode_iterator().GetConstantForIndexOperand(1, isolate()));
NameRef name(broker(), GetConstantForIndexOperand(1));
FeedbackSource feedback =
CreateFeedbackSource(bytecode_iterator().GetIndexOperand(2));
@ -2208,8 +2209,7 @@ void BytecodeGraphBuilder::VisitStaNamedPropertyNoFeedback() {
Node* value = environment()->LookupAccumulator();
Node* object =
environment()->LookupRegister(bytecode_iterator().GetRegisterOperand(0));
NameRef name(broker(),
bytecode_iterator().GetConstantForIndexOperand(1, isolate()));
NameRef name(broker(), GetConstantForIndexOperand(1));
LanguageMode language_mode =
static_cast<LanguageMode>(bytecode_iterator().GetFlagOperand(2));
const Operator* op =
@ -2288,8 +2288,7 @@ void BytecodeGraphBuilder::VisitPopContext() {
}
void BytecodeGraphBuilder::VisitCreateClosure() {
SharedFunctionInfoRef shared_info(
broker(), bytecode_iterator().GetConstantForIndexOperand(0, isolate()));
SharedFunctionInfoRef shared_info(broker(), GetConstantForIndexOperand(0));
AllocationType allocation =
interpreter::CreateClosureFlags::PretenuredBit::decode(
bytecode_iterator().GetFlagOperand(2))
@ -2306,16 +2305,14 @@ void BytecodeGraphBuilder::VisitCreateClosure() {
}
void BytecodeGraphBuilder::VisitCreateBlockContext() {
ScopeInfoRef scope_info(
broker(), bytecode_iterator().GetConstantForIndexOperand(0, isolate()));
ScopeInfoRef scope_info(broker(), GetConstantForIndexOperand(0));
const Operator* op = javascript()->CreateBlockContext(scope_info.object());
Node* context = NewNode(op);
environment()->BindAccumulator(context);
}
void BytecodeGraphBuilder::VisitCreateFunctionContext() {
ScopeInfoRef scope_info(
broker(), bytecode_iterator().GetConstantForIndexOperand(0, isolate()));
ScopeInfoRef scope_info(broker(), GetConstantForIndexOperand(0));
uint32_t slots = bytecode_iterator().GetUnsignedImmediateOperand(1);
const Operator* op = javascript()->CreateFunctionContext(
scope_info.object(), slots, FUNCTION_SCOPE);
@ -2324,8 +2321,7 @@ void BytecodeGraphBuilder::VisitCreateFunctionContext() {
}
void BytecodeGraphBuilder::VisitCreateEvalContext() {
ScopeInfoRef scope_info(
broker(), bytecode_iterator().GetConstantForIndexOperand(0, isolate()));
ScopeInfoRef scope_info(broker(), GetConstantForIndexOperand(0));
uint32_t slots = bytecode_iterator().GetUnsignedImmediateOperand(1);
const Operator* op = javascript()->CreateFunctionContext(scope_info.object(),
slots, EVAL_SCOPE);
@ -2336,8 +2332,7 @@ void BytecodeGraphBuilder::VisitCreateEvalContext() {
void BytecodeGraphBuilder::VisitCreateCatchContext() {
interpreter::Register reg = bytecode_iterator().GetRegisterOperand(0);
Node* exception = environment()->LookupRegister(reg);
ScopeInfoRef scope_info(
broker(), bytecode_iterator().GetConstantForIndexOperand(1, isolate()));
ScopeInfoRef scope_info(broker(), GetConstantForIndexOperand(1));
const Operator* op = javascript()->CreateCatchContext(scope_info.object());
Node* context = NewNode(op, exception);
@ -2347,8 +2342,7 @@ void BytecodeGraphBuilder::VisitCreateCatchContext() {
void BytecodeGraphBuilder::VisitCreateWithContext() {
Node* object =
environment()->LookupRegister(bytecode_iterator().GetRegisterOperand(0));
ScopeInfoRef scope_info(
broker(), bytecode_iterator().GetConstantForIndexOperand(1, isolate()));
ScopeInfoRef scope_info(broker(), GetConstantForIndexOperand(1));
const Operator* op = javascript()->CreateWithContext(scope_info.object());
Node* context = NewNode(op, object);
@ -2374,8 +2368,7 @@ void BytecodeGraphBuilder::VisitCreateRestParameter() {
}
void BytecodeGraphBuilder::VisitCreateRegExpLiteral() {
StringRef constant_pattern(
broker(), bytecode_iterator().GetConstantForIndexOperand(0, isolate()));
StringRef constant_pattern(broker(), GetConstantForIndexOperand(0));
int const slot_id = bytecode_iterator().GetIndexOperand(1);
FeedbackSource pair = CreateFeedbackSource(slot_id);
int literal_flags = bytecode_iterator().GetFlagOperand(2);
@ -2389,7 +2382,7 @@ void BytecodeGraphBuilder::VisitCreateRegExpLiteral() {
void BytecodeGraphBuilder::VisitCreateArrayLiteral() {
ArrayBoilerplateDescriptionRef array_boilerplate_description(
broker(), bytecode_iterator().GetConstantForIndexOperand(0, isolate()));
broker(), GetConstantForIndexOperand(0));
int const slot_id = bytecode_iterator().GetIndexOperand(1);
FeedbackSource pair = CreateFeedbackSource(slot_id);
int bytecode_flags = bytecode_iterator().GetFlagOperand(2);
@ -2428,7 +2421,7 @@ void BytecodeGraphBuilder::VisitCreateArrayFromIterable() {
void BytecodeGraphBuilder::VisitCreateObjectLiteral() {
ObjectBoilerplateDescriptionRef constant_properties(
broker(), bytecode_iterator().GetConstantForIndexOperand(0, isolate()));
broker(), GetConstantForIndexOperand(0));
int const slot_id = bytecode_iterator().GetIndexOperand(1);
FeedbackSource pair = CreateFeedbackSource(slot_id);
int bytecode_flags = bytecode_iterator().GetFlagOperand(2);
@ -2466,8 +2459,8 @@ void BytecodeGraphBuilder::VisitCloneObject() {
void BytecodeGraphBuilder::VisitGetTemplateObject() {
FeedbackSource source =
CreateFeedbackSource(bytecode_iterator().GetIndexOperand(1));
TemplateObjectDescriptionRef description(
broker(), bytecode_iterator().GetConstantForIndexOperand(0, isolate()));
TemplateObjectDescriptionRef description(broker(),
GetConstantForIndexOperand(0));
STATIC_ASSERT(JSGetTemplateObjectNode::FeedbackVectorIndex() == 0);
const Operator* op = javascript()->GetTemplateObject(
description.object(), shared_info().object(), source);
@ -2962,8 +2955,8 @@ void BytecodeGraphBuilder::VisitThrowReferenceErrorIfHole() {
Node* accumulator = environment()->LookupAccumulator();
Node* check_for_hole = NewNode(simplified()->ReferenceEqual(), accumulator,
jsgraph()->TheHoleConstant());
Node* name = jsgraph()->Constant(ObjectRef(
broker(), bytecode_iterator().GetConstantForIndexOperand(0, isolate())));
Node* name =
jsgraph()->Constant(ObjectRef(broker(), GetConstantForIndexOperand(0)));
BuildHoleCheckAndThrow(check_for_hole,
Runtime::kThrowAccessedUninitializedVariable, name);
}

View File

@ -1766,7 +1766,7 @@ class BytecodeArrayData : public FixedArrayBaseData {
void SerializeForCompilation(JSHeapBroker* broker) {
if (is_serialized_for_compilation_) return;
// Convinience cast: object() is already a canonical persistent handle.
// Convenience cast: object() is already a canonical persistent handle.
Handle<BytecodeArray> bytecodes = Handle<BytecodeArray>::cast(object());
DCHECK(constant_pool_.empty());
@ -5567,32 +5567,6 @@ TemplateObjectFeedback const& ProcessedFeedback::AsTemplateObject() const {
return *static_cast<TemplateObjectFeedback const*>(this);
}
OffHeapBytecodeArray::OffHeapBytecodeArray(BytecodeArrayRef bytecode_array)
: AbstractBytecodeArray(), array_(bytecode_array) {}
int OffHeapBytecodeArray::length() const { return array_.length(); }
int OffHeapBytecodeArray::parameter_count() const {
return array_.parameter_count();
}
Address OffHeapBytecodeArray::GetFirstBytecodeAddress() const {
return array_.GetFirstBytecodeAddress();
}
Handle<Object> OffHeapBytecodeArray::GetConstantAtIndex(
int index, Isolate* isolate) const {
return array_.GetConstantAtIndex(index);
}
bool OffHeapBytecodeArray::IsConstantAtIndexSmi(int index) const {
return array_.IsConstantAtIndexSmi(index);
}
Smi OffHeapBytecodeArray::GetConstantAtIndexAsSmi(int index) const {
return array_.GetConstantAtIndexAsSmi(index);
}
#undef BIMODAL_ACCESSOR
#undef BIMODAL_ACCESSOR_B
#undef BIMODAL_ACCESSOR_C

View File

@ -467,21 +467,6 @@ Reduction NoChangeBecauseOfMissingData(JSHeapBroker* broker,
// compilation is finished.
bool CanInlineElementAccess(MapRef const& map);
class OffHeapBytecodeArray final : public interpreter::AbstractBytecodeArray {
public:
explicit OffHeapBytecodeArray(BytecodeArrayRef bytecode_array);
int length() const override;
int parameter_count() const override;
Address GetFirstBytecodeAddress() const override;
Handle<Object> GetConstantAtIndex(int index, Isolate* isolate) const override;
bool IsConstantAtIndexSmi(int index) const override;
Smi GetConstantAtIndexAsSmi(int index) const override;
private:
BytecodeArrayRef array_;
};
// Scope that unparks the LocalHeap, if:
// a) We have a JSHeapBroker,
// b) Said JSHeapBroker has a LocalIsolate and thus a LocalHeap,

View File

@ -14,71 +14,24 @@ namespace v8 {
namespace internal {
namespace interpreter {
namespace {
class OnHeapBytecodeArray final : public AbstractBytecodeArray {
public:
explicit OnHeapBytecodeArray(Handle<BytecodeArray> bytecode_array)
: AbstractBytecodeArray(), array_(bytecode_array) {}
int length() const override { return array_->length(); }
int parameter_count() const override { return array_->parameter_count(); }
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
// TODO(verwaest): Pass the LocalHeap into the constructor.
AbstractBytecodeArray::AbstractBytecodeArray()
: local_heap_(LocalHeap::Current()) {
if (!local_heap_) {
local_heap_ = Isolate::Current()->main_thread_local_heap();
}
}
BytecodeArrayAccessor::BytecodeArrayAccessor(
std::unique_ptr<AbstractBytecodeArray> bytecode_array, int initial_offset)
: bytecode_array_(std::move(bytecode_array)),
Handle<BytecodeArray> bytecode_array, int initial_offset)
: bytecode_array_(bytecode_array),
start_(reinterpret_cast<uint8_t*>(
bytecode_array_->GetFirstBytecodeAddress())),
end_(start_ + bytecode_array_->length()),
cursor_(start_ + initial_offset),
operand_scale_(OperandScale::kSingle),
prefix_size_(0) {
bytecode_array_->local_heap()->AddGCEpilogueCallback(UpdatePointersCallback,
this);
prefix_size_(0),
local_heap_(LocalHeap::Current()
? LocalHeap::Current()
: Isolate::Current()->main_thread_local_heap()) {
local_heap_->AddGCEpilogueCallback(UpdatePointersCallback, this);
UpdateOperandScale();
}
BytecodeArrayAccessor::BytecodeArrayAccessor(
Handle<BytecodeArray> bytecode_array, int initial_offset)
: BytecodeArrayAccessor(
std::make_unique<OnHeapBytecodeArray>(bytecode_array),
initial_offset) {}
BytecodeArrayAccessor::~BytecodeArrayAccessor() {
bytecode_array_->local_heap()->RemoveGCEpilogueCallback(
UpdatePointersCallback, this);
local_heap_->RemoveGCEpilogueCallback(UpdatePointersCallback, this);
}
void BytecodeArrayAccessor::SetOffset(int offset) {
@ -251,24 +204,32 @@ Runtime::FunctionId BytecodeArrayAccessor::GetIntrinsicIdOperand(
static_cast<IntrinsicsHelper::IntrinsicId>(raw_id));
}
template <typename LocalIsolate>
Handle<Object> BytecodeArrayAccessor::GetConstantAtIndex(
int index, Isolate* isolate) const {
return bytecode_array()->GetConstantAtIndex(index, isolate);
int index, LocalIsolate* isolate) const {
return handle(bytecode_array()->constant_pool().get(index), isolate);
}
bool BytecodeArrayAccessor::IsConstantAtIndexSmi(int index) const {
return bytecode_array()->IsConstantAtIndexSmi(index);
return bytecode_array()->constant_pool().get(index).IsSmi();
}
Smi BytecodeArrayAccessor::GetConstantAtIndexAsSmi(int index) const {
return bytecode_array()->GetConstantAtIndexAsSmi(index);
return Smi::cast(bytecode_array()->constant_pool().get(index));
}
template <typename LocalIsolate>
Handle<Object> BytecodeArrayAccessor::GetConstantForIndexOperand(
int operand_index, Isolate* isolate) const {
int operand_index, LocalIsolate* isolate) const {
return GetConstantAtIndex(GetIndexOperand(operand_index), isolate);
}
template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE)
Handle<Object> BytecodeArrayAccessor::GetConstantForIndexOperand(
int operand_index, Isolate* isolate) const;
template Handle<Object> BytecodeArrayAccessor::GetConstantForIndexOperand(
int operand_index, LocalIsolate* isolate) const;
int BytecodeArrayAccessor::GetRelativeJumpTargetOffset() const {
Bytecode bytecode = current_bytecode();
if (interpreter::Bytecodes::IsJumpImmediate(bytecode)) {
@ -315,6 +276,19 @@ std::ostream& BytecodeArrayAccessor::PrintTo(std::ostream& os) const {
bytecode_array()->parameter_count());
}
void BytecodeArrayAccessor::UpdatePointers() {
DisallowGarbageCollection no_gc;
uint8_t* start =
reinterpret_cast<uint8_t*>(bytecode_array_->GetFirstBytecodeAddress());
if (start != start_) {
start_ = start;
uint8_t* end = start + bytecode_array_->length();
size_t distance_to_end = end_ - cursor_;
cursor_ = end - distance_to_end;
end_ = end;
}
}
JumpTableTargetOffsets::JumpTableTargetOffsets(
const BytecodeArrayAccessor* accessor, int table_start, int table_size,
int case_value_base)

View File

@ -67,30 +67,8 @@ class V8_EXPORT_PRIVATE JumpTableTargetOffsets final {
int case_value_base_;
};
class V8_EXPORT_PRIVATE AbstractBytecodeArray {
public:
AbstractBytecodeArray();
virtual int length() const = 0;
virtual int parameter_count() const = 0;
virtual Address GetFirstBytecodeAddress() const = 0;
virtual Handle<Object> GetConstantAtIndex(int index,
Isolate* isolate) const = 0;
virtual bool IsConstantAtIndexSmi(int index) const = 0;
virtual Smi GetConstantAtIndexAsSmi(int index) const = 0;
virtual ~AbstractBytecodeArray() = default;
LocalHeap* local_heap() const { return local_heap_; }
private:
LocalHeap* local_heap_;
};
class V8_EXPORT_PRIVATE BytecodeArrayAccessor {
public:
BytecodeArrayAccessor(std::unique_ptr<AbstractBytecodeArray> bytecode_array,
int initial_offset);
BytecodeArrayAccessor(Handle<BytecodeArray> bytecode_array,
int initial_offset);
~BytecodeArrayAccessor();
@ -119,9 +97,7 @@ class V8_EXPORT_PRIVATE BytecodeArrayAccessor {
return static_cast<int>(cursor_ - start_ - prefix_size_);
}
OperandScale current_operand_scale() const { return operand_scale_; }
AbstractBytecodeArray* bytecode_array() const {
return bytecode_array_.get();
}
Handle<BytecodeArray> bytecode_array() const { return bytecode_array_; }
uint32_t GetFlagOperand(int operand_index) const;
uint32_t GetUnsignedImmediateOperand(int operand_index) const;
@ -138,11 +114,13 @@ class V8_EXPORT_PRIVATE BytecodeArrayAccessor {
Runtime::FunctionId GetRuntimeIdOperand(int operand_index) const;
Runtime::FunctionId GetIntrinsicIdOperand(int operand_index) const;
uint32_t GetNativeContextIndexOperand(int operand_index) const;
Handle<Object> GetConstantAtIndex(int offset, Isolate* isolate) const;
template <typename LocalIsolate>
Handle<Object> GetConstantAtIndex(int offset, LocalIsolate* isolate) const;
bool IsConstantAtIndexSmi(int offset) const;
Smi GetConstantAtIndexAsSmi(int offset) const;
template <typename LocalIsolate>
Handle<Object> GetConstantForIndexOperand(int operand_index,
Isolate* isolate) const;
LocalIsolate* isolate) const;
// Returns the relative offset of the branch target at the current bytecode.
// It is an error to call this method if the bytecode is not for a jump or
@ -167,18 +145,7 @@ class V8_EXPORT_PRIVATE BytecodeArrayAccessor {
reinterpret_cast<BytecodeArrayAccessor*>(accessor)->UpdatePointers();
}
void UpdatePointers() {
DisallowGarbageCollection no_gc;
uint8_t* start =
reinterpret_cast<uint8_t*>(bytecode_array_->GetFirstBytecodeAddress());
if (start != start_) {
start_ = start;
uint8_t* end = start + bytecode_array_->length();
size_t distance_to_end = end_ - cursor_;
cursor_ = end - distance_to_end;
end_ = end;
}
}
void UpdatePointers();
inline bool done() const { return cursor_ >= end_; }
@ -202,7 +169,7 @@ class V8_EXPORT_PRIVATE BytecodeArrayAccessor {
}
}
std::unique_ptr<AbstractBytecodeArray> bytecode_array_;
Handle<BytecodeArray> bytecode_array_;
uint8_t* start_;
uint8_t* end_;
// The cursor always points to the active bytecode. If there's a prefix, the
@ -210,6 +177,7 @@ class V8_EXPORT_PRIVATE BytecodeArrayAccessor {
uint8_t* cursor_;
OperandScale operand_scale_;
int prefix_size_;
LocalHeap* const local_heap_;
};
} // namespace interpreter

View File

@ -10,10 +10,6 @@ namespace v8 {
namespace internal {
namespace interpreter {
BytecodeArrayIterator::BytecodeArrayIterator(
std::unique_ptr<AbstractBytecodeArray> bytecode_array)
: BytecodeArrayAccessor(std::move(bytecode_array), 0) {}
BytecodeArrayIterator::BytecodeArrayIterator(
Handle<BytecodeArray> bytecode_array)
: BytecodeArrayAccessor(bytecode_array, 0) {}

View File

@ -16,8 +16,6 @@ namespace interpreter {
class V8_EXPORT_PRIVATE BytecodeArrayIterator final
: public BytecodeArrayAccessor {
public:
explicit BytecodeArrayIterator(std::unique_ptr<AbstractBytecodeArray> array);
explicit BytecodeArrayIterator(Handle<BytecodeArray> array);
BytecodeArrayIterator(const BytecodeArrayIterator&) = delete;