Commit 418926e0 authored by jarin's avatar jarin Committed by Commit bot

Introduce a handlified version of source position iterator.

This enables allocation in Turbofan's graph building (which is useful for
taking code dependencies there).

BUG=v8:6357
R=bmeurer@chromium.org

Review-Url: https://codereview.chromium.org/2860843003
Cr-Commit-Position: refs/heads/master@{#45089}
parent f9184045
......@@ -612,7 +612,7 @@ void BytecodeGraphBuilder::VisitBytecodes(bool stack_check) {
interpreter::BytecodeArrayIterator iterator(bytecode_array());
set_bytecode_iterator(&iterator);
SourcePositionTableIterator source_position_iterator(
bytecode_array()->SourcePositionTable());
handle(bytecode_array()->SourcePositionTable()));
if (FLAG_trace_environment_liveness) {
OFStream of(stdout);
......
......@@ -168,18 +168,27 @@ Handle<ByteArray> SourcePositionTableBuilder::ToSourcePositionTable(
}
SourcePositionTableIterator::SourcePositionTableIterator(ByteArray* byte_array)
: table_(byte_array), index_(0), current_() {
: raw_table_(byte_array) {
Advance();
}
SourcePositionTableIterator::SourcePositionTableIterator(
Handle<ByteArray> byte_array)
: table_(byte_array) {
Advance();
// We can enable allocation because we keep the table in a handle.
no_gc.Release();
}
void SourcePositionTableIterator::Advance() {
ByteArray* table = raw_table_ ? raw_table_ : *table_;
DCHECK(!done());
DCHECK(index_ >= 0 && index_ <= table_->length());
if (index_ >= table_->length()) {
DCHECK(index_ >= 0 && index_ <= table->length());
if (index_ >= table->length()) {
index_ = kDone;
} else {
PositionTableEntry tmp;
DecodeEntry(table_, &index_, &tmp);
DecodeEntry(table, &index_, &tmp);
AddAndSetEntry(current_, tmp);
}
}
......
......@@ -61,6 +61,16 @@ class V8_EXPORT_PRIVATE SourcePositionTableBuilder {
class V8_EXPORT_PRIVATE SourcePositionTableIterator {
public:
// We expose two flavours of the iterator, depending on the argument passed
// to the constructor:
// Handlified iterator allows allocation, but it needs a handle (and thus
// a handle scope). This is the preferred version.
explicit SourcePositionTableIterator(Handle<ByteArray> byte_array);
// Non-handlified iterator does not need a handle scope, but it disallows
// allocation during its lifetime. This is useful if there is no handle
// scope around.
explicit SourcePositionTableIterator(ByteArray* byte_array);
void Advance();
......@@ -82,8 +92,9 @@ class V8_EXPORT_PRIVATE SourcePositionTableIterator {
private:
static const int kDone = -1;
ByteArray* table_;
int index_;
ByteArray* raw_table_ = nullptr;
Handle<ByteArray> table_;
int index_ = 0;
PositionTableEntry current_;
DisallowHeapAllocation no_gc;
};
......
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