Commit 63db7615 authored by Georg Neis's avatar Georg Neis Committed by Commit Bot

[turbofan] Prepare broker and serializer for CreateClosure support

When inlining based on CreateClosure, we don't have a JSFunction but
only the SharedFunctionInfo and FeedbackVector.

Bug: v8:7790
Change-Id: I7a3cf50710273c7175e43e969d2364cff11c3d93
Reviewed-on: https://chromium-review.googlesource.com/c/1421357Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Reviewed-by: 's avatarMaya Lekova <mslekova@chromium.org>
Commit-Queue: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58977}
parent effb7ad7
...@@ -318,14 +318,6 @@ class JSFunctionData : public JSObjectData { ...@@ -318,14 +318,6 @@ class JSFunctionData : public JSObjectData {
void Serialize(JSHeapBroker* broker); void Serialize(JSHeapBroker* broker);
void SetSerializedForCompilation(JSHeapBroker* broker) {
CHECK(!serialized_for_compilation_);
serialized_for_compilation_ = true;
}
bool serialized_for_compilation() const {
return serialized_for_compilation_;
}
ContextData* context() const { return context_; } ContextData* context() const { return context_; }
NativeContextData* native_context() const { return native_context_; } NativeContextData* native_context() const { return native_context_; }
MapData* initial_map() const { return initial_map_; } MapData* initial_map() const { return initial_map_; }
...@@ -342,7 +334,6 @@ class JSFunctionData : public JSObjectData { ...@@ -342,7 +334,6 @@ class JSFunctionData : public JSObjectData {
bool PrototypeRequiresRuntimeLookup_; bool PrototypeRequiresRuntimeLookup_;
bool serialized_ = false; bool serialized_ = false;
bool serialized_for_compilation_ = false;
ContextData* context_ = nullptr; ContextData* context_ = nullptr;
NativeContextData* native_context_ = nullptr; NativeContextData* native_context_ = nullptr;
...@@ -1142,14 +1133,31 @@ ScopeInfoData::ScopeInfoData(JSHeapBroker* broker, ObjectData** storage, ...@@ -1142,14 +1133,31 @@ ScopeInfoData::ScopeInfoData(JSHeapBroker* broker, ObjectData** storage,
class SharedFunctionInfoData : public HeapObjectData { class SharedFunctionInfoData : public HeapObjectData {
public: public:
SharedFunctionInfoData(JSHeapBroker* broker, ObjectData** storage,
Handle<SharedFunctionInfo> object);
int builtin_id() const { return builtin_id_; } int builtin_id() const { return builtin_id_; }
BytecodeArrayData* GetBytecodeArray() const { return GetBytecodeArray_; } BytecodeArrayData* GetBytecodeArray() const { return GetBytecodeArray_; }
void SetSerializedForCompilation(FeedbackVectorRef feedback);
bool IsSerializedForCompilation(FeedbackVectorRef feedback) const;
#define DECL_ACCESSOR(type, name) \ #define DECL_ACCESSOR(type, name) \
type name() const { return name##_; } type name() const { return name##_; }
BROKER_SFI_FIELDS(DECL_ACCESSOR) BROKER_SFI_FIELDS(DECL_ACCESSOR)
#undef DECL_ACCESSOR #undef DECL_ACCESSOR
SharedFunctionInfoData(JSHeapBroker* broker, ObjectData** storage, private:
int const builtin_id_;
BytecodeArrayData* const GetBytecodeArray_;
ZoneUnorderedSet<Handle<FeedbackVector>, Handle<FeedbackVector>::hash,
Handle<FeedbackVector>::equal_to>
serialized_for_compilation_;
#define DECL_MEMBER(type, name) type const name##_;
BROKER_SFI_FIELDS(DECL_MEMBER)
#undef DECL_MEMBER
};
SharedFunctionInfoData::SharedFunctionInfoData(
JSHeapBroker* broker, ObjectData** storage,
Handle<SharedFunctionInfo> object) Handle<SharedFunctionInfo> object)
: HeapObjectData(broker, storage, object), : HeapObjectData(broker, storage, object),
builtin_id_(object->HasBuiltinId() ? object->builtin_id() builtin_id_(object->HasBuiltinId() ? object->builtin_id()
...@@ -1158,22 +1166,26 @@ class SharedFunctionInfoData : public HeapObjectData { ...@@ -1158,22 +1166,26 @@ class SharedFunctionInfoData : public HeapObjectData {
object->HasBytecodeArray() object->HasBytecodeArray()
? broker->GetOrCreateData(object->GetBytecodeArray()) ? broker->GetOrCreateData(object->GetBytecodeArray())
->AsBytecodeArray() ->AsBytecodeArray()
: nullptr) : nullptr),
serialized_for_compilation_(broker->zone())
#define INIT_MEMBER(type, name) , name##_(object->name()) #define INIT_MEMBER(type, name) , name##_(object->name())
BROKER_SFI_FIELDS(INIT_MEMBER) BROKER_SFI_FIELDS(INIT_MEMBER)
#undef INIT_MEMBER #undef INIT_MEMBER
{ {
DCHECK_EQ(HasBuiltinId_, builtin_id_ != Builtins::kNoBuiltinId); DCHECK_EQ(HasBuiltinId_, builtin_id_ != Builtins::kNoBuiltinId);
DCHECK_EQ(HasBytecodeArray_, GetBytecodeArray_ != nullptr); DCHECK_EQ(HasBytecodeArray_, GetBytecodeArray_ != nullptr);
} }
private: void SharedFunctionInfoData::SetSerializedForCompilation(
int const builtin_id_; FeedbackVectorRef feedback) {
BytecodeArrayData* const GetBytecodeArray_; CHECK(serialized_for_compilation_.insert(feedback.object()).second);
#define DECL_MEMBER(type, name) type const name##_; }
BROKER_SFI_FIELDS(DECL_MEMBER)
#undef DECL_MEMBER bool SharedFunctionInfoData::IsSerializedForCompilation(
}; FeedbackVectorRef feedback) const {
return serialized_for_compilation_.find(feedback.object()) !=
serialized_for_compilation_.end();
}
class ModuleData : public HeapObjectData { class ModuleData : public HeapObjectData {
public: public:
...@@ -2663,14 +2675,16 @@ void JSFunctionRef::Serialize() { ...@@ -2663,14 +2675,16 @@ void JSFunctionRef::Serialize() {
data()->AsJSFunction()->Serialize(broker()); data()->AsJSFunction()->Serialize(broker());
} }
void JSFunctionRef::SetSerializedForCompilation() { void SharedFunctionInfoRef::SetSerializedForCompilation(
FeedbackVectorRef feedback) {
CHECK_EQ(broker()->mode(), JSHeapBroker::kSerializing); CHECK_EQ(broker()->mode(), JSHeapBroker::kSerializing);
data()->AsJSFunction()->SetSerializedForCompilation(broker()); data()->AsSharedFunctionInfo()->SetSerializedForCompilation(feedback);
} }
bool JSFunctionRef::serialized_for_compilation() const { bool SharedFunctionInfoRef::IsSerializedForCompilation(
CHECK_EQ(broker()->mode(), JSHeapBroker::kSerializing); FeedbackVectorRef feedback) const {
return data()->AsJSFunction()->serialized_for_compilation(); CHECK_NE(broker()->mode(), JSHeapBroker::kDisabled);
return data()->AsSharedFunctionInfo()->IsSerializedForCompilation(feedback);
} }
void JSObjectRef::SerializeObjectCreateMap() { void JSObjectRef::SerializeObjectCreateMap() {
......
...@@ -235,9 +235,6 @@ class JSFunctionRef : public JSObjectRef { ...@@ -235,9 +235,6 @@ class JSFunctionRef : public JSObjectRef {
bool PrototypeRequiresRuntimeLookup() const; bool PrototypeRequiresRuntimeLookup() const;
void Serialize(); void Serialize();
void SetSerializedForCompilation();
bool serialized_for_compilation() const;
// The following are available only after calling Serialize(). // The following are available only after calling Serialize().
ObjectRef prototype() const; ObjectRef prototype() const;
...@@ -536,6 +533,9 @@ class SharedFunctionInfoRef : public HeapObjectRef { ...@@ -536,6 +533,9 @@ class SharedFunctionInfoRef : public HeapObjectRef {
#define DECL_ACCESSOR(type, name) type name() const; #define DECL_ACCESSOR(type, name) type name() const;
BROKER_SFI_FIELDS(DECL_ACCESSOR) BROKER_SFI_FIELDS(DECL_ACCESSOR)
#undef DECL_ACCESSOR #undef DECL_ACCESSOR
bool IsSerializedForCompilation(FeedbackVectorRef feedback) const;
void SetSerializedForCompilation(FeedbackVectorRef feedback);
}; };
class StringRef : public NameRef { class StringRef : public NameRef {
......
...@@ -304,12 +304,6 @@ bool JSInliner::DetermineCallTarget( ...@@ -304,12 +304,6 @@ bool JSInliner::DetermineCallTarget(
return false; return false;
} }
JSFunctionRef ref(broker(), function);
if (FLAG_concurrent_inlining && !ref.serialized_for_compilation()) {
TRACE_BROKER(broker(), "Missed opportunity to inline a function ("
<< Brief(*match.Value()) << ")");
}
shared_info_out = handle(function->shared(), isolate()); shared_info_out = handle(function->shared(), isolate());
return true; return true;
} }
...@@ -480,6 +474,17 @@ Reduction JSInliner::ReduceJSCall(Node* node) { ...@@ -480,6 +474,17 @@ Reduction JSInliner::ReduceJSCall(Node* node) {
Handle<FeedbackVector> feedback_vector; Handle<FeedbackVector> feedback_vector;
DetermineCallContext(node, context, feedback_vector); DetermineCallContext(node, context, feedback_vector);
if (FLAG_concurrent_inlining) {
SharedFunctionInfoRef sfi(broker(), shared_info);
FeedbackVectorRef feedback(broker(), feedback_vector);
if (!sfi.IsSerializedForCompilation(feedback)) {
TRACE_BROKER(broker(),
"Would have missed opportunity to inline a function ("
<< Brief(*sfi.object()) << " with "
<< Brief(*feedback.object()) << ")");
}
}
// Remember that we inlined this function. // Remember that we inlined this function.
int inlining_id = info_->AddInlinedFunction( int inlining_id = info_->AddInlinedFunction(
shared_info, bytecode_array, source_positions_->GetSourcePosition(node)); shared_info, bytecode_array, source_positions_->GetSourcePosition(node));
......
...@@ -182,52 +182,45 @@ void SerializerForBackgroundCompilation::Environment::SetRegisterHints( ...@@ -182,52 +182,45 @@ void SerializerForBackgroundCompilation::Environment::SetRegisterHints(
} }
SerializerForBackgroundCompilation::SerializerForBackgroundCompilation( SerializerForBackgroundCompilation::SerializerForBackgroundCompilation(
JSHeapBroker* broker, Zone* zone, Handle<JSFunction> closure) JSHeapBroker* broker, Zone* zone, Handle<JSFunction> function)
: broker_(broker), : broker_(broker),
zone_(zone), zone_(zone),
sfi_(function->shared(), broker->isolate()),
feedback_(function->feedback_vector(), broker->isolate()),
environment_(new (zone) Environment( environment_(new (zone) Environment(
zone, broker_->isolate(), zone, broker_->isolate(), sfi_->GetBytecodeArray()->register_count(),
closure->shared()->GetBytecodeArray()->register_count(), sfi_->GetBytecodeArray()->parameter_count())) {
closure->shared()->GetBytecodeArray()->parameter_count())), JSFunctionRef(broker, function).Serialize();
closure_(closure) {} }
SerializerForBackgroundCompilation::SerializerForBackgroundCompilation( SerializerForBackgroundCompilation::SerializerForBackgroundCompilation(
JSHeapBroker* broker, Zone* zone, Handle<JSFunction> closure, JSHeapBroker* broker, Zone* zone, Handle<SharedFunctionInfo> sfi,
const Hints& receiver, const HintsVector& arguments) Handle<FeedbackVector> feedback, const Hints& receiver,
const HintsVector& arguments)
: broker_(broker), : broker_(broker),
zone_(zone), zone_(zone),
sfi_(sfi),
feedback_(feedback),
environment_(new (zone) Environment( environment_(new (zone) Environment(
this, broker->isolate(), this, broker->isolate(), sfi->GetBytecodeArray()->register_count(),
closure->shared()->GetBytecodeArray()->register_count(), sfi->GetBytecodeArray()->parameter_count(), receiver, arguments)) {}
closure->shared()->GetBytecodeArray()->parameter_count(), receiver,
arguments)),
closure_(closure) {}
Hints SerializerForBackgroundCompilation::Run() { Hints SerializerForBackgroundCompilation::Run() {
JSFunctionRef closure_ref(broker(), closure_); SharedFunctionInfoRef sfi(broker(), sfi_);
if (closure_ref.serialized_for_compilation()) { FeedbackVectorRef feedback(broker(), feedback_);
if (sfi.IsSerializedForCompilation(feedback)) {
return Hints(zone()); return Hints(zone());
} }
closure_ref.SetSerializedForCompilation(); sfi.SetSerializedForCompilation(feedback);
feedback.SerializeSlots();
FeedbackVectorRef fv(
broker(), handle(closure_->feedback_vector(), broker()->isolate()));
fv.SerializeSlots();
BytecodeArrayRef bytecode_array(
broker(),
handle(closure_->shared()->GetBytecodeArray(), broker()->isolate()));
closure_ref.Serialize();
TraverseBytecode(); TraverseBytecode();
return environment()->LookupReturnValue(); return environment()->LookupReturnValue();
} }
void SerializerForBackgroundCompilation::TraverseBytecode() { void SerializerForBackgroundCompilation::TraverseBytecode() {
interpreter::BytecodeArrayIterator iterator( BytecodeArrayRef bytecode_array(
handle(closure_->shared()->GetBytecodeArray(), broker()->isolate())); broker(), handle(sfi_->GetBytecodeArray(), broker()->isolate()));
interpreter::BytecodeArrayIterator iterator(bytecode_array.object());
for (; !iterator.done(); iterator.Advance()) { for (; !iterator.done(); iterator.Advance()) {
switch (iterator.current_bytecode()) { switch (iterator.current_bytecode()) {
...@@ -431,17 +424,19 @@ void SerializerForBackgroundCompilation::ProcessCallOrConstruct( ...@@ -431,17 +424,19 @@ void SerializerForBackgroundCompilation::ProcessCallOrConstruct(
const Hints& callee, const Hints& receiver, const HintsVector& arguments) { const Hints& callee, const Hints& receiver, const HintsVector& arguments) {
environment()->ClearAccumulatorHints(); environment()->ClearAccumulatorHints();
for (auto value : callee) { for (auto hint : callee) {
if (!value->IsJSFunction()) continue; if (!hint->IsJSFunction()) continue;
Handle<JSFunction> callee(Handle<JSFunction>::cast(value)); Handle<JSFunction> function = Handle<JSFunction>::cast(hint);
if (!callee->shared()->HasBytecodeArray() || if (!function->shared()->IsInlineable()) continue;
!callee->shared()->IsInlineable())
continue;
SerializerForBackgroundCompilation child_serializer( JSFunctionRef(broker(), function).Serialize();
broker(), zone(), callee, receiver, arguments);
Handle<SharedFunctionInfo> sfi(function->shared(), broker()->isolate());
Handle<FeedbackVector> feedback(function->feedback_vector(),
broker()->isolate());
SerializerForBackgroundCompilation child_serializer(
broker(), zone(), sfi, feedback, receiver, arguments);
environment()->AddAccumulatorHints(child_serializer.Run()); environment()->AddAccumulatorHints(child_serializer.Run());
} }
} }
......
...@@ -116,20 +116,17 @@ typedef ZoneVector<Hints> HintsVector; ...@@ -116,20 +116,17 @@ typedef ZoneVector<Hints> HintsVector;
// optimizations in the compiler, is copied to the heap broker. // optimizations in the compiler, is copied to the heap broker.
class SerializerForBackgroundCompilation { class SerializerForBackgroundCompilation {
public: public:
class Environment;
SerializerForBackgroundCompilation(JSHeapBroker* broker, Zone* zone, SerializerForBackgroundCompilation(JSHeapBroker* broker, Zone* zone,
Handle<JSFunction> closure); Handle<JSFunction> function);
Hints Run();
private:
SerializerForBackgroundCompilation(JSHeapBroker* broker, Zone* zone, SerializerForBackgroundCompilation(JSHeapBroker* broker, Zone* zone,
Handle<JSFunction> closure, Handle<SharedFunctionInfo> sfi,
Handle<FeedbackVector> feedback,
const Hints& receiver, const Hints& receiver,
const HintsVector& arguments); const HintsVector& arguments);
Hints Run();
Zone* zone() const { return zone_; }
private:
void TraverseBytecode(); void TraverseBytecode();
#define DECLARE_VISIT_BYTECODE(name, ...) \ #define DECLARE_VISIT_BYTECODE(name, ...) \
...@@ -137,6 +134,9 @@ class SerializerForBackgroundCompilation { ...@@ -137,6 +134,9 @@ class SerializerForBackgroundCompilation {
SUPPORTED_BYTECODE_LIST(DECLARE_VISIT_BYTECODE) SUPPORTED_BYTECODE_LIST(DECLARE_VISIT_BYTECODE)
#undef DECLARE_VISIT_BYTECODE #undef DECLARE_VISIT_BYTECODE
class Environment;
Zone* zone() const { return zone_; }
JSHeapBroker* broker() const { return broker_; } JSHeapBroker* broker() const { return broker_; }
Environment* environment() const { return environment_; } Environment* environment() const { return environment_; }
...@@ -147,9 +147,9 @@ class SerializerForBackgroundCompilation { ...@@ -147,9 +147,9 @@ class SerializerForBackgroundCompilation {
JSHeapBroker* broker_; JSHeapBroker* broker_;
Zone* zone_; Zone* zone_;
Handle<SharedFunctionInfo> sfi_;
Handle<FeedbackVector> feedback_;
Environment* environment_; Environment* environment_;
Handle<JSFunction> closure_;
}; };
} // namespace compiler } // namespace compiler
......
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