Commit f977ace2 authored by Patrick Thier's avatar Patrick Thier Committed by Commit Bot

Non-handlified BytecodeOffsetIterator

For use at locations where we know, that no GC can happen.
This avoids unnecessary handlifying of objects.

Bug: v8:11420
Change-Id: Ic549c56c4366060a6da3a3772dbd0aae23151eab
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2735394Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Patrick Thier <pthier@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73334}
parent 7f542d25
......@@ -21,12 +21,34 @@ BytecodeOffsetIterator::BytecodeOffsetIterator(Handle<ByteArray> mapping_table,
? LocalHeap::Current()
: Isolate::Current()->main_thread_local_heap()) {
local_heap_->AddGCEpilogueCallback(UpdatePointersCallback, this);
current_pc_start_offset_ = ReadPosition();
current_pc_end_offset_ = current_pc_start_offset_ + ReadPosition();
Initialize();
}
BytecodeOffsetIterator::BytecodeOffsetIterator(ByteArray mapping_table,
BytecodeArray bytecodes)
: data_start_address_(mapping_table.GetDataStartAddress()),
data_length_(mapping_table.length()),
current_index_(0),
bytecode_handle_storage_(bytecodes),
// In the non-handlified version, no GC is allowed. We use a "dummy"
// handle to pass the BytecodeArray to the BytecodeArrayIterator, which
// is fine since no objects will be moved.
bytecode_iterator_(Handle<BytecodeArray>(
reinterpret_cast<Address*>(&bytecode_handle_storage_))),
local_heap_(nullptr) {
no_gc.emplace();
Initialize();
}
BytecodeOffsetIterator::~BytecodeOffsetIterator() {
local_heap_->RemoveGCEpilogueCallback(UpdatePointersCallback, this);
if (local_heap_ != nullptr) {
local_heap_->RemoveGCEpilogueCallback(UpdatePointersCallback, this);
}
}
void BytecodeOffsetIterator::Initialize() {
current_pc_start_offset_ = ReadPosition();
current_pc_end_offset_ = current_pc_start_offset_ + ReadPosition();
}
void BytecodeOffsetIterator::UpdatePointers() {
......
......@@ -20,9 +20,11 @@ namespace baseline {
class V8_EXPORT_PRIVATE BytecodeOffsetIterator {
public:
// TODO(pthier): Create un-handlified version.
BytecodeOffsetIterator(Handle<ByteArray> mapping_table,
Handle<BytecodeArray> bytecodes);
explicit BytecodeOffsetIterator(Handle<ByteArray> mapping_table,
Handle<BytecodeArray> bytecodes);
// Non-handlified version for use when no GC can happen.
explicit BytecodeOffsetIterator(ByteArray mapping_table,
BytecodeArray bytecodes);
~BytecodeOffsetIterator();
inline void Advance() {
......@@ -53,7 +55,7 @@ class V8_EXPORT_PRIVATE BytecodeOffsetIterator {
DCHECK_LE(pc_offset, current_pc_end_offset());
}
// For this iterator, done() means that it is not safe to advance().
// For this iterator, done() means that it is not safe to Advance().
// Values are cached, so reads are always allowed.
inline bool done() const { return current_index_ >= data_length_; }
......@@ -76,6 +78,7 @@ class V8_EXPORT_PRIVATE BytecodeOffsetIterator {
void UpdatePointers();
private:
void Initialize();
inline int ReadPosition() {
return base::VLQDecodeUnsigned(data_start_address_, &current_index_);
}
......@@ -86,8 +89,10 @@ class V8_EXPORT_PRIVATE BytecodeOffsetIterator {
int current_index_;
Address current_pc_start_offset_;
Address current_pc_end_offset_;
BytecodeArray bytecode_handle_storage_;
interpreter::BytecodeArrayIterator bytecode_iterator_;
LocalHeap* local_heap_;
base::Optional<DisallowGarbageCollection> no_gc;
};
} // namespace baseline
......
......@@ -354,13 +354,8 @@ int Code::GetBytecodeOffsetForBaselinePC(Address baseline_pc,
CHECK(!is_baseline_prologue_builtin());
if (is_baseline_leave_frame_builtin()) return kFunctionExitBytecodeOffset;
CHECK_EQ(kind(), CodeKind::BASELINE);
// TODO(pthier): We should have an un-handlefied version of
// BytecodeOffsetIterator for uses like here, where no GC can happen.
Isolate* isolate = GetIsolate();
HandleScope scope(isolate);
baseline::BytecodeOffsetIterator offset_iterator(
handle(ByteArray::cast(bytecode_offset_table()), isolate),
handle(bytecodes, isolate));
ByteArray::cast(bytecode_offset_table()), bytecodes);
Address pc = baseline_pc - InstructionStart();
offset_iterator.AdvanceToPCOffset(pc);
return offset_iterator.current_bytecode_offset();
......@@ -370,13 +365,8 @@ uintptr_t Code::GetBaselinePCForBytecodeOffset(int bytecode_offset,
BytecodeArray bytecodes) {
DisallowGarbageCollection no_gc;
CHECK_EQ(kind(), CodeKind::BASELINE);
// TODO(pthier): We should have an un-handlefied version of
// BytecodeOffsetIterator for uses like here, where no GC can happen.
Isolate* isolate = GetIsolate();
HandleScope scope(isolate);
baseline::BytecodeOffsetIterator offset_iterator(
handle(ByteArray::cast(bytecode_offset_table()), isolate),
handle(bytecodes, isolate));
ByteArray::cast(bytecode_offset_table()), bytecodes);
offset_iterator.AdvanceToBytecodeOffset(bytecode_offset);
return offset_iterator.current_pc_start_offset();
}
......
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