Commit 2600bba4 authored by Maya Lekova's avatar Maya Lekova Committed by Commit Bot

[turbofan] Enhance the serializer for background compilation phase

This CL adds handling for almost all calls, and for some load and store
bytecodes in the serializer and marks the relevant call targets as
"serialized for compilation".

Design doc:
https://docs.google.com/document/d/1vCQYhtFPqXafSMweSnGD8l0TKEIB6cPV5UGMHJtpy8k/edit?ts=5bf7d341

Bug: v8:7790
Change-Id: I2bd24c1b0541e83c108422b66902a5b979f1e1a8
Reviewed-on: https://chromium-review.googlesource.com/c/1351014Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Commit-Queue: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58873}
parent fab59bbb
......@@ -319,6 +319,14 @@ class JSFunctionData : public JSObjectData {
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_; }
NativeContextData* native_context() const { return native_context_; }
MapData* initial_map() const { return initial_map_; }
......@@ -335,6 +343,7 @@ class JSFunctionData : public JSObjectData {
bool PrototypeRequiresRuntimeLookup_;
bool serialized_ = false;
bool serialized_for_compilation_ = false;
ContextData* context_ = nullptr;
NativeContextData* native_context_ = nullptr;
......@@ -2629,6 +2638,16 @@ void JSFunctionRef::Serialize() {
data()->AsJSFunction()->Serialize(broker());
}
void JSFunctionRef::SetSerializedForCompilation() {
CHECK_EQ(broker()->mode(), JSHeapBroker::kSerializing);
data()->AsJSFunction()->SetSerializedForCompilation(broker());
}
bool JSFunctionRef::serialized_for_compilation() const {
CHECK_EQ(broker()->mode(), JSHeapBroker::kSerializing);
return data()->AsJSFunction()->serialized_for_compilation();
}
void JSObjectRef::SerializeObjectCreateMap() {
if (broker()->mode() == JSHeapBroker::kDisabled) return;
CHECK_EQ(broker()->mode(), JSHeapBroker::kSerializing);
......
......@@ -234,6 +234,9 @@ class JSFunctionRef : public JSObjectRef {
bool PrototypeRequiresRuntimeLookup() const;
void Serialize();
void SetSerializedForCompilation();
bool serialized_for_compilation() const;
// The following are available only after calling Serialize().
ObjectRef prototype() const;
......
......@@ -289,6 +289,15 @@ bool JSInliner::DetermineCallTarget(
if (match.HasValue() && match.Value()->IsJSFunction()) {
Handle<JSFunction> function = Handle<JSFunction>::cast(match.Value());
JSFunctionRef ref(broker(), function);
if (FLAG_concurrent_inlining && !ref.serialized_for_compilation()) {
broker()->Trace("Possibly missed opportunity to inline a function ");
if (FLAG_trace_heap_broker) {
match.Value()->ShortPrint();
PrintF(")\n");
}
}
// Disallow cross native-context inlining for now. This means that all parts
// of the resulting code will operate on the same global object. This also
// prevents cross context leaks, where we could inline functions from a
......
......@@ -6,60 +6,148 @@
#define V8_COMPILER_SERIALIZER_FOR_BACKGROUND_COMPILATION_H_
#include "src/handles.h"
#include "src/zone/zone-containers.h"
namespace v8 {
namespace internal {
namespace interpreter {
class BytecodeArrayIterator;
}
class Register;
} // namespace interpreter
class BytecodeArray;
class FeedbackVector;
class LookupIterator;
class NativeContext;
class ScriptContextTable;
class SharedFunctionInfo;
class BytecodeArray;
class SourcePositionTableIterator;
class Zone;
namespace compiler {
#define SUPPORTED_BYTECODE_LIST(V) V(Illegal)
#define CLEAR_ENVIRONMENT_LIST(V) \
V(Abort) \
V(CallRuntime) \
V(CallRuntimeForPair) \
V(CreateBlockContext) \
V(CreateFunctionContext) \
V(CreateEvalContext) \
V(Jump) \
V(JumpConstant) \
V(JumpIfFalse) \
V(JumpIfFalseConstant) \
V(JumpIfJSReceiver) \
V(JumpIfJSReceiverConstant) \
V(JumpIfNotNull) \
V(JumpIfNotNullConstant) \
V(JumpIfNotUndefined) \
V(JumpIfNotUndefinedConstant) \
V(JumpIfNull) \
V(JumpIfNullConstant) \
V(JumpIfToBooleanTrueConstant) \
V(JumpIfToBooleanFalseConstant) \
V(JumpIfToBooleanTrue) \
V(JumpIfToBooleanFalse) \
V(JumpIfTrue) \
V(JumpIfTrueConstant) \
V(JumpIfUndefined) \
V(JumpIfUndefinedConstant) \
V(JumpLoop) \
V(PushContext) \
V(PopContext) \
V(ReThrow) \
V(StaContextSlot) \
V(StaCurrentContextSlot) \
V(Throw)
#define CLEAR_ACCUMULATOR_LIST(V) \
V(Construct) \
V(CreateClosure) \
V(CreateEmptyObjectLiteral) \
V(CreateMappedArguments) \
V(CreateRestParameter) \
V(CreateUnmappedArguments) \
V(LdaContextSlot) \
V(LdaCurrentContextSlot) \
V(LdaGlobal) \
V(LdaGlobalInsideTypeof) \
V(LdaImmutableContextSlot) \
V(LdaImmutableCurrentContextSlot) \
V(LdaKeyedProperty) \
V(LdaNamedProperty) \
V(LdaNamedPropertyNoFeedback)
#define SUPPORTED_BYTECODE_LIST(V) \
V(CallAnyReceiver) \
V(CallNoFeedback) \
V(CallProperty) \
V(CallProperty0) \
V(CallProperty1) \
V(CallProperty2) \
V(CallUndefinedReceiver) \
V(CallUndefinedReceiver0) \
V(CallUndefinedReceiver1) \
V(CallUndefinedReceiver2) \
V(ExtraWide) \
V(Illegal) \
V(LdaConstant) \
V(LdaNull) \
V(Ldar) \
V(LdaSmi) \
V(LdaUndefined) \
V(LdaZero) \
V(Mov) \
V(Return) \
V(Star) \
V(Wide) \
CLEAR_ENVIRONMENT_LIST(V) \
CLEAR_ACCUMULATOR_LIST(V)
class JSHeapBroker;
typedef ZoneVector<Handle<Object>> Hints;
typedef ZoneVector<Hints> HintsVector;
// The SerializerForBackgroundCompilation makes sure that the relevant function
// data such as bytecode, SharedFunctionInfo and FeedbackVector, used by later
// optimizations in the compiler, is copied to the heap broker.
class SerializerForBackgroundCompilation {
public:
explicit SerializerForBackgroundCompilation(JSHeapBroker* broker, Zone* zone,
Handle<JSFunction> closure);
class Environment;
void Run();
SerializerForBackgroundCompilation(JSHeapBroker* broker, Zone* zone,
Handle<JSFunction> closure);
SerializerForBackgroundCompilation(JSHeapBroker* broker, Zone* zone,
Handle<JSFunction> closure,
const Hints& receiver,
const HintsVector& arguments);
Zone* zone() const { return zone_; }
Hints Run();
const Handle<BytecodeArray>& bytecode_array() const {
return bytecode_array_;
}
Zone* zone() const { return zone_; }
private:
class Environment;
void TraverseBytecode();
#define DECLARE_VISIT_BYTECODE(name, ...) void Visit##name();
#define DECLARE_VISIT_BYTECODE(name, ...) \
void Visit##name(interpreter::BytecodeArrayIterator* iterator);
SUPPORTED_BYTECODE_LIST(DECLARE_VISIT_BYTECODE)
#undef DECLARE_VISIT_BYTECODE
JSHeapBroker* broker() { return broker_; }
Environment* environment() { return environment_; }
JSHeapBroker* broker() const { return broker_; }
Environment* environment() const { return environment_; }
void ProcessCall(const Hints& callee, const Hints& receiver,
const HintsVector& arguments);
void ProcessCallVarArgs(interpreter::BytecodeArrayIterator* iterator,
ConvertReceiverMode receiver_mode);
JSHeapBroker* broker_;
Zone* zone_;
Environment* environment_;
Handle<JSFunction> closure_;
Handle<BytecodeArray> bytecode_array_;
};
} // 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