Commit 4d40e867 authored by Mike Stanton's avatar Mike Stanton Committed by Commit Bot

[turbofan] Serialize source position table

... for concurrent graph building.

This is a reland of jarin@chromium.org's CL
https://chromium-review.googlesource.com/c/v8/v8/+/1682027

with support to access the source positions through a handle
when running without concurrent inlining, because the positions
may move due to GC allocation.

Bug: v8:7790
Change-Id: I1b2cc84c8cb801cb82f1a527fce736c74c156c1d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1683726Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Reviewed-by: 's avatarMaya Lekova <mslekova@chromium.org>
Commit-Queue: Michael Stanton <mvstanton@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62593}
parent c52eefe9
......@@ -331,7 +331,7 @@ class BytecodeGraphBuilder {
}
SourcePositionTableIterator& source_position_iterator() {
return source_position_iterator_;
return *source_position_iterator_.get();
}
interpreter::BytecodeArrayIterator& bytecode_iterator() {
......@@ -385,7 +385,7 @@ class BytecodeGraphBuilder {
Handle<FeedbackVector> const feedback_vector_;
JSTypeHintLowering const type_hint_lowering_;
const FrameStateFunctionInfo* const frame_state_function_info_;
SourcePositionTableIterator source_position_iterator_;
std::unique_ptr<SourcePositionTableIterator> source_position_iterator_;
interpreter::BytecodeArrayIterator bytecode_iterator_;
BytecodeAnalysis bytecode_analysis_;
Environment* environment_;
......@@ -958,9 +958,6 @@ BytecodeGraphBuilder::BytecodeGraphBuilder(
FrameStateType::kInterpretedFunction,
bytecode_array.parameter_count(), bytecode_array.register_count(),
shared_info)),
source_position_iterator_(
handle(bytecode_array.object()->SourcePositionTableIfCollected(),
isolate())),
bytecode_iterator_(
base::make_unique<OffHeapBytecodeArray>(bytecode_array)),
bytecode_analysis_(
......@@ -983,7 +980,20 @@ BytecodeGraphBuilder::BytecodeGraphBuilder(
source_positions_(source_positions),
start_position_(shared_info->StartPosition(), inlining_id),
shared_info_(shared_info),
native_context_(native_context) {}
native_context_(native_context) {
if (FLAG_concurrent_inlining) {
// With concurrent inlining on, the source position address doesn't change
// because it's been copied from the heap.
source_position_iterator_ = base::make_unique<SourcePositionTableIterator>(
Vector<const byte>(bytecode_array.source_positions_address(),
bytecode_array.source_positions_size()));
} else {
// Otherwise, we need to access the table through a handle.
source_position_iterator_ = base::make_unique<SourcePositionTableIterator>(
handle(bytecode_array.object()->SourcePositionTableIfCollected(),
isolate()));
}
}
Node* BytecodeGraphBuilder::GetFunctionClosure() {
if (!function_closure_.is_set()) {
......
......@@ -612,6 +612,10 @@ class BytecodeArrayRef : public FixedArrayBaseRef {
uint8_t get(int index) const;
Address GetFirstBytecodeAddress() const;
// Source position table.
const byte* source_positions_address() const;
int source_positions_size() const;
// Constant pool access.
Handle<Object> GetConstantAtIndex(int index) const;
bool IsConstantAtIndexSmi(int index) const;
......
......@@ -1359,9 +1359,22 @@ class BytecodeArrayData : public FixedArrayBaseData {
constant_pool_.push_back(broker->GetOrCreateData(constant_pool->get(i)));
}
Handle<ByteArray> source_position_table(
bytecode_array->SourcePositionTableIfCollected(), broker->isolate());
source_positions_.reserve(source_position_table->length());
for (int i = 0; i < source_position_table->length(); i++) {
source_positions_.push_back(source_position_table->get(i));
}
is_serialized_for_compilation_ = true;
}
const byte* source_positions_address() const {
return source_positions_.data();
}
size_t source_positions_size() const { return source_positions_.size(); }
BytecodeArrayData(JSHeapBroker* broker, ObjectData** storage,
Handle<BytecodeArray> object)
: FixedArrayBaseData(broker, storage, object),
......@@ -1370,6 +1383,7 @@ class BytecodeArrayData : public FixedArrayBaseData {
incoming_new_target_or_generator_register_(
object->incoming_new_target_or_generator_register()),
bytecodes_(broker->zone()),
source_positions_(broker->zone()),
constant_pool_(broker->zone()) {}
private:
......@@ -1379,6 +1393,7 @@ class BytecodeArrayData : public FixedArrayBaseData {
bool is_serialized_for_compilation_ = false;
ZoneVector<uint8_t> bytecodes_;
ZoneVector<uint8_t> source_positions_;
ZoneVector<ObjectData*> constant_pool_;
};
......@@ -2753,6 +2768,22 @@ void BytecodeArrayRef::SerializeForCompilation() {
data()->AsBytecodeArray()->SerializeForCompilation(broker());
}
const byte* BytecodeArrayRef::source_positions_address() const {
if (broker()->mode() == JSHeapBroker::kDisabled) {
AllowHandleDereference allow_handle_dereference;
return object()->SourcePositionTableIfCollected().GetDataStartAddress();
}
return data()->AsBytecodeArray()->source_positions_address();
}
int BytecodeArrayRef::source_positions_size() const {
if (broker()->mode() == JSHeapBroker::kDisabled) {
AllowHandleDereference allow_handle_dereference;
return object()->SourcePositionTableIfCollected().length();
}
return static_cast<int>(data()->AsBytecodeArray()->source_positions_size());
}
#define IF_BROKER_DISABLED_ACCESS_HANDLE_C(holder, name) \
if (broker()->mode() == JSHeapBroker::kDisabled) { \
AllowHandleAllocation handle_allocation; \
......
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