Commit 7b9a0c20 authored by Georg Neis's avatar Georg Neis Committed by Commit Bot

[compiler] Replace ScopeInfoData with direct reads

As part of this, introduce a new ObjectData kind for objects that we
want to read directly from the background thread rather than serialize.
ScopeInfoRef is the first user of that.

For details, see:
https://docs.google.com/document/d/1U6x6Q2bpylfxS55nxSe17yyBW0bQG-ycoBhVA82VmS0/edit?usp=sharing

Bug: v8:7790
Change-Id: Ia3cda4f67d3922367afa4a5da2aeaae7160cf1f2
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2346405
Auto-Submit: Georg Neis <neis@chromium.org>
Commit-Queue: Georg Neis <neis@chromium.org>
Reviewed-by: 's avatarNico Hartmann <nicohartmann@chromium.org>
Reviewed-by: 's avatarSantiago Aboy Solanes <solanes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69473}
parent a626bc03
...@@ -705,8 +705,6 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) { ...@@ -705,8 +705,6 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) {
void SetDefaults(); void SetDefaults();
void set_scope_info(Handle<ScopeInfo> scope_info);
friend class DeclarationScope; friend class DeclarationScope;
friend class ClassScope; friend class ClassScope;
friend class ScopeTestHelper; friend class ScopeTestHelper;
......
...@@ -596,7 +596,7 @@ void UpdateSharedFunctionFlagsAfterCompilation(FunctionLiteral* literal, ...@@ -596,7 +596,7 @@ void UpdateSharedFunctionFlagsAfterCompilation(FunctionLiteral* literal,
shared_info.set_has_static_private_methods_or_accessors( shared_info.set_has_static_private_methods_or_accessors(
literal->has_static_private_methods_or_accessors()); literal->has_static_private_methods_or_accessors());
shared_info.set_scope_info(*literal->scope()->scope_info()); shared_info.SetScopeInfo(*literal->scope()->scope_info());
} }
// Finalize a single compilation job. This function can return // Finalize a single compilation job. This function can return
......
...@@ -1785,7 +1785,7 @@ BytecodeGraphBuilder::Environment* BytecodeGraphBuilder::CheckContextExtensions( ...@@ -1785,7 +1785,7 @@ BytecodeGraphBuilder::Environment* BytecodeGraphBuilder::CheckContextExtensions(
// in the same scope as the variable itself has no way of shadowing it. // in the same scope as the variable itself has no way of shadowing it.
Environment* slow_environment = nullptr; Environment* slow_environment = nullptr;
for (uint32_t d = 0; d < depth; d++) { for (uint32_t d = 0; d < depth; d++) {
if (scope_info.HasContextExtension()) { if (scope_info.HasContextExtensionSlot()) {
slow_environment = CheckContextExtensionAtDepth(slow_environment, d); slow_environment = CheckContextExtensionAtDepth(slow_environment, d);
} }
DCHECK_IMPLIES(!scope_info.HasOuterScopeInfo(), d + 1 == depth); DCHECK_IMPLIES(!scope_info.HasOuterScopeInfo(), d + 1 == depth);
......
...@@ -49,57 +49,58 @@ enum class OddballType : uint8_t { ...@@ -49,57 +49,58 @@ enum class OddballType : uint8_t {
// This list is sorted such that subtypes appear before their supertypes. // This list is sorted such that subtypes appear before their supertypes.
// DO NOT VIOLATE THIS PROPERTY! // DO NOT VIOLATE THIS PROPERTY!
#define HEAP_BROKER_OBJECT_LIST(V) \ #define HEAP_BROKER_SERIALIZED_OBJECT_LIST(V) \
/* Subtypes of JSObject */ \ /* Subtypes of JSObject */ \
V(JSArray) \ V(JSArray) \
V(JSBoundFunction) \ V(JSBoundFunction) \
V(JSDataView) \ V(JSDataView) \
V(JSFunction) \ V(JSFunction) \
V(JSGlobalObject) \ V(JSGlobalObject) \
V(JSGlobalProxy) \ V(JSGlobalProxy) \
V(JSRegExp) \ V(JSRegExp) \
V(JSTypedArray) \ V(JSTypedArray) \
/* Subtypes of Context */ \ /* Subtypes of Context */ \
V(NativeContext) \ V(NativeContext) \
/* Subtypes of FixedArray */ \ /* Subtypes of FixedArray */ \
V(Context) \ V(Context) \
V(ObjectBoilerplateDescription) \ V(ObjectBoilerplateDescription) \
V(ScopeInfo) \ V(ScriptContextTable) \
V(ScriptContextTable) \ /* Subtypes of FixedArrayBase */ \
/* Subtypes of FixedArrayBase */ \ V(BytecodeArray) \
V(BytecodeArray) \ V(FixedArray) \
V(FixedArray) \ V(FixedDoubleArray) \
V(FixedDoubleArray) \ /* Subtypes of Name */ \
/* Subtypes of Name */ \ V(InternalizedString) \
V(InternalizedString) \ V(String) \
V(String) \ V(Symbol) \
V(Symbol) \ /* Subtypes of JSReceiver */ \
/* Subtypes of JSReceiver */ \ V(JSObject) \
V(JSObject) \ /* Subtypes of HeapObject */ \
/* Subtypes of HeapObject */ \ V(AccessorInfo) \
V(AccessorInfo) \ V(AllocationSite) \
V(AllocationSite) \ V(ArrayBoilerplateDescription) \
V(ArrayBoilerplateDescription) \ V(BigInt) \
V(BigInt) \ V(CallHandlerInfo) \
V(CallHandlerInfo) \ V(Cell) \
V(Cell) \ V(Code) \
V(Code) \ V(DescriptorArray) \
V(DescriptorArray) \ V(FeedbackCell) \
V(FeedbackCell) \ V(FeedbackVector) \
V(FeedbackVector) \ V(FixedArrayBase) \
V(FixedArrayBase) \ V(FunctionTemplateInfo) \
V(FunctionTemplateInfo) \ V(HeapNumber) \
V(HeapNumber) \ V(JSReceiver) \
V(JSReceiver) \ V(Map) \
V(Map) \ V(Name) \
V(Name) \ V(PropertyCell) \
V(PropertyCell) \ V(SharedFunctionInfo) \
V(SharedFunctionInfo) \ V(SourceTextModule) \
V(SourceTextModule) \ V(TemplateObjectDescription) \
V(TemplateObjectDescription) \ /* Subtypes of Object */ \
/* Subtypes of Object */ \
V(HeapObject) V(HeapObject)
#define HEAP_BROKER_NEVER_SERIALIZED_OBJECT_LIST(V) V(ScopeInfo)
class CompilationDependencies; class CompilationDependencies;
struct FeedbackSource; struct FeedbackSource;
class JSHeapBroker; class JSHeapBroker;
...@@ -107,7 +108,8 @@ class ObjectData; ...@@ -107,7 +108,8 @@ class ObjectData;
class PerIsolateCompilerCache; class PerIsolateCompilerCache;
class PropertyAccessInfo; class PropertyAccessInfo;
#define FORWARD_DECL(Name) class Name##Ref; #define FORWARD_DECL(Name) class Name##Ref;
HEAP_BROKER_OBJECT_LIST(FORWARD_DECL) HEAP_BROKER_SERIALIZED_OBJECT_LIST(FORWARD_DECL)
HEAP_BROKER_NEVER_SERIALIZED_OBJECT_LIST(FORWARD_DECL)
#undef FORWARD_DECL #undef FORWARD_DECL
class V8_EXPORT_PRIVATE ObjectRef { class V8_EXPORT_PRIVATE ObjectRef {
...@@ -127,11 +129,13 @@ class V8_EXPORT_PRIVATE ObjectRef { ...@@ -127,11 +129,13 @@ class V8_EXPORT_PRIVATE ObjectRef {
int AsSmi() const; int AsSmi() const;
#define HEAP_IS_METHOD_DECL(Name) bool Is##Name() const; #define HEAP_IS_METHOD_DECL(Name) bool Is##Name() const;
HEAP_BROKER_OBJECT_LIST(HEAP_IS_METHOD_DECL) HEAP_BROKER_SERIALIZED_OBJECT_LIST(HEAP_IS_METHOD_DECL)
HEAP_BROKER_NEVER_SERIALIZED_OBJECT_LIST(HEAP_IS_METHOD_DECL)
#undef HEAP_IS_METHOD_DECL #undef HEAP_IS_METHOD_DECL
#define HEAP_AS_METHOD_DECL(Name) Name##Ref As##Name() const; #define HEAP_AS_METHOD_DECL(Name) Name##Ref As##Name() const;
HEAP_BROKER_OBJECT_LIST(HEAP_AS_METHOD_DECL) HEAP_BROKER_SERIALIZED_OBJECT_LIST(HEAP_AS_METHOD_DECL)
HEAP_BROKER_NEVER_SERIALIZED_OBJECT_LIST(HEAP_AS_METHOD_DECL)
#undef HEAP_AS_METHOD_DECL #undef HEAP_AS_METHOD_DECL
bool IsNullOrUndefined() const; bool IsNullOrUndefined() const;
...@@ -760,8 +764,7 @@ class ScopeInfoRef : public HeapObjectRef { ...@@ -760,8 +764,7 @@ class ScopeInfoRef : public HeapObjectRef {
int ContextLength() const; int ContextLength() const;
bool HasOuterScopeInfo() const; bool HasOuterScopeInfo() const;
int Flags() const; bool HasContextExtensionSlot() const;
bool HasContextExtension() const;
// Only serialized via SerializeScopeInfoChain. // Only serialized via SerializeScopeInfoChain.
ScopeInfoRef OuterScopeInfo() const; ScopeInfoRef OuterScopeInfo() const;
......
...@@ -45,7 +45,7 @@ namespace compiler { ...@@ -45,7 +45,7 @@ namespace compiler {
#define TRACE_MISSING(broker, x) TRACE_BROKER_MISSING(broker, x) #define TRACE_MISSING(broker, x) TRACE_BROKER_MISSING(broker, x)
#define FORWARD_DECL(Name) class Name##Data; #define FORWARD_DECL(Name) class Name##Data;
HEAP_BROKER_OBJECT_LIST(FORWARD_DECL) HEAP_BROKER_SERIALIZED_OBJECT_LIST(FORWARD_DECL)
#undef FORWARD_DECL #undef FORWARD_DECL
// There are three kinds of ObjectData values. // There are three kinds of ObjectData values.
...@@ -71,6 +71,7 @@ enum ObjectDataKind { ...@@ -71,6 +71,7 @@ enum ObjectDataKind {
kSmi, kSmi,
kSerializedHeapObject, kSerializedHeapObject,
kUnserializedHeapObject, kUnserializedHeapObject,
kNeverSerializedHeapObject,
kUnserializedReadOnlyHeapObject kUnserializedReadOnlyHeapObject
}; };
...@@ -79,7 +80,8 @@ class AllowHandleAllocationIf { ...@@ -79,7 +80,8 @@ class AllowHandleAllocationIf {
explicit AllowHandleAllocationIf(ObjectDataKind kind, explicit AllowHandleAllocationIf(ObjectDataKind kind,
JSHeapBroker::BrokerMode mode) { JSHeapBroker::BrokerMode mode) {
DCHECK_IMPLIES(mode == JSHeapBroker::BrokerMode::kSerialized, DCHECK_IMPLIES(mode == JSHeapBroker::BrokerMode::kSerialized,
kind == kUnserializedReadOnlyHeapObject); kind == kUnserializedReadOnlyHeapObject ||
kind == kNeverSerializedHeapObject);
if (kind == kUnserializedHeapObject) maybe_allow_handle_.emplace(); if (kind == kUnserializedHeapObject) maybe_allow_handle_.emplace();
} }
...@@ -90,16 +92,15 @@ class AllowHandleAllocationIf { ...@@ -90,16 +92,15 @@ class AllowHandleAllocationIf {
class AllowHandleDereferenceIf { class AllowHandleDereferenceIf {
public: public:
explicit AllowHandleDereferenceIf(ObjectDataKind kind, explicit AllowHandleDereferenceIf(ObjectDataKind kind,
JSHeapBroker::BrokerMode mode) { JSHeapBroker::BrokerMode mode)
: AllowHandleDereferenceIf(kind) {
DCHECK_IMPLIES(mode == JSHeapBroker::BrokerMode::kSerialized, DCHECK_IMPLIES(mode == JSHeapBroker::BrokerMode::kSerialized,
kind == kUnserializedReadOnlyHeapObject); kind == kUnserializedReadOnlyHeapObject ||
if (kind == kUnserializedHeapObject || kind == kNeverSerializedHeapObject);
kind == kUnserializedReadOnlyHeapObject)
maybe_allow_handle_.emplace();
} }
explicit AllowHandleDereferenceIf(ObjectDataKind kind) { explicit AllowHandleDereferenceIf(ObjectDataKind kind) {
if (kind == kUnserializedHeapObject || if (kind == kUnserializedHeapObject || kind == kNeverSerializedHeapObject ||
kind == kUnserializedReadOnlyHeapObject) kind == kUnserializedReadOnlyHeapObject)
maybe_allow_handle_.emplace(); maybe_allow_handle_.emplace();
} }
...@@ -154,20 +155,26 @@ class ObjectData : public ZoneObject { ...@@ -154,20 +155,26 @@ class ObjectData : public ZoneObject {
broker->mode() == JSHeapBroker::kSerializing, broker->mode() == JSHeapBroker::kSerializing,
broker->isolate()->handle_scope_data()->canonical_scope != nullptr); broker->isolate()->handle_scope_data()->canonical_scope != nullptr);
CHECK_IMPLIES(broker->mode() == JSHeapBroker::kSerialized, CHECK_IMPLIES(broker->mode() == JSHeapBroker::kSerialized,
IsReadOnlyHeapObject(*object)); (kind == kUnserializedReadOnlyHeapObject &&
IsReadOnlyHeapObject(*object)) ||
kind == kNeverSerializedHeapObject);
} }
#define DECLARE_IS_AND_AS(Name) \ #define DECLARE_IS(Name) bool Is##Name() const;
bool Is##Name() const; \ HEAP_BROKER_SERIALIZED_OBJECT_LIST(DECLARE_IS)
Name##Data* As##Name(); HEAP_BROKER_NEVER_SERIALIZED_OBJECT_LIST(DECLARE_IS)
HEAP_BROKER_OBJECT_LIST(DECLARE_IS_AND_AS) #undef DECLARE_IS
#undef DECLARE_IS_AND_AS
#define DECLARE_AS(Name) Name##Data* As##Name();
HEAP_BROKER_SERIALIZED_OBJECT_LIST(DECLARE_AS)
#undef DECLARE_AS
Handle<Object> object() const { return object_; } Handle<Object> object() const { return object_; }
ObjectDataKind kind() const { return kind_; } ObjectDataKind kind() const { return kind_; }
bool is_smi() const { return kind_ == kSmi; } bool is_smi() const { return kind_ == kSmi; }
bool should_access_heap() const { bool should_access_heap() const {
return kind_ == kUnserializedHeapObject || return kind_ == kUnserializedHeapObject ||
kind_ == kNeverSerializedHeapObject ||
kind_ == kUnserializedReadOnlyHeapObject; kind_ == kUnserializedReadOnlyHeapObject;
} }
...@@ -772,7 +779,7 @@ class NativeContextData : public ContextData { ...@@ -772,7 +779,7 @@ class NativeContextData : public ContextData {
return function_maps_; return function_maps_;
} }
ScopeInfoData* scope_info() const { ObjectData* scope_info() const {
CHECK(serialized_); CHECK(serialized_);
return scope_info_; return scope_info_;
} }
...@@ -787,7 +794,7 @@ class NativeContextData : public ContextData { ...@@ -787,7 +794,7 @@ class NativeContextData : public ContextData {
BROKER_NATIVE_CONTEXT_FIELDS(DECL_MEMBER) BROKER_NATIVE_CONTEXT_FIELDS(DECL_MEMBER)
#undef DECL_MEMBER #undef DECL_MEMBER
ZoneVector<MapData*> function_maps_; ZoneVector<MapData*> function_maps_;
ScopeInfoData* scope_info_ = nullptr; ObjectData* scope_info_ = nullptr;
}; };
class NameData : public HeapObjectData { class NameData : public HeapObjectData {
...@@ -1662,45 +1669,6 @@ ObjectData* JSArrayData::GetOwnElement(JSHeapBroker* broker, uint32_t index, ...@@ -1662,45 +1669,6 @@ ObjectData* JSArrayData::GetOwnElement(JSHeapBroker* broker, uint32_t index,
return result; return result;
} }
class ScopeInfoData : public HeapObjectData {
public:
ScopeInfoData(JSHeapBroker* broker, ObjectData** storage,
Handle<ScopeInfo> object);
int context_length() const { return context_length_; }
bool has_outer_scope_info() const { return has_outer_scope_info_; }
int flags() const { return flags_; }
ScopeInfoData* outer_scope_info() const { return outer_scope_info_; }
void SerializeScopeInfoChain(JSHeapBroker* broker);
private:
int const context_length_;
bool const has_outer_scope_info_;
int const flags_;
// Only serialized via SerializeScopeInfoChain.
ScopeInfoData* outer_scope_info_;
};
ScopeInfoData::ScopeInfoData(JSHeapBroker* broker, ObjectData** storage,
Handle<ScopeInfo> object)
: HeapObjectData(broker, storage, object),
context_length_(object->ContextLength()),
has_outer_scope_info_(object->HasOuterScopeInfo()),
flags_(object->Flags()),
outer_scope_info_(nullptr) {}
void ScopeInfoData::SerializeScopeInfoChain(JSHeapBroker* broker) {
if (outer_scope_info_) return;
if (!has_outer_scope_info_) return;
outer_scope_info_ =
broker
->GetOrCreateData(Handle<ScopeInfo>::cast(object())->OuterScopeInfo())
->AsScopeInfo();
outer_scope_info_->SerializeScopeInfoChain(broker);
}
class SharedFunctionInfoData : public HeapObjectData { class SharedFunctionInfoData : public HeapObjectData {
public: public:
SharedFunctionInfoData(JSHeapBroker* broker, ObjectData** storage, SharedFunctionInfoData(JSHeapBroker* broker, ObjectData** storage,
...@@ -1710,7 +1678,7 @@ class SharedFunctionInfoData : public HeapObjectData { ...@@ -1710,7 +1678,7 @@ class SharedFunctionInfoData : public HeapObjectData {
int context_header_size() const { return context_header_size_; } int context_header_size() const { return context_header_size_; }
BytecodeArrayData* GetBytecodeArray() const { return GetBytecodeArray_; } BytecodeArrayData* GetBytecodeArray() const { return GetBytecodeArray_; }
void SerializeFunctionTemplateInfo(JSHeapBroker* broker); void SerializeFunctionTemplateInfo(JSHeapBroker* broker);
ScopeInfoData* scope_info() const { return scope_info_; } ObjectData* scope_info() const { return scope_info_; }
void SerializeScopeInfoChain(JSHeapBroker* broker); void SerializeScopeInfoChain(JSHeapBroker* broker);
FunctionTemplateInfoData* function_template_info() const { FunctionTemplateInfoData* function_template_info() const {
return function_template_info_; return function_template_info_;
...@@ -1741,7 +1709,7 @@ class SharedFunctionInfoData : public HeapObjectData { ...@@ -1741,7 +1709,7 @@ class SharedFunctionInfoData : public HeapObjectData {
#undef DECL_MEMBER #undef DECL_MEMBER
FunctionTemplateInfoData* function_template_info_; FunctionTemplateInfoData* function_template_info_;
ZoneMap<int, JSArrayData*> template_objects_; ZoneMap<int, JSArrayData*> template_objects_;
ScopeInfoData* scope_info_; ObjectData* scope_info_;
}; };
SharedFunctionInfoData::SharedFunctionInfoData( SharedFunctionInfoData::SharedFunctionInfoData(
...@@ -1781,12 +1749,8 @@ void SharedFunctionInfoData::SerializeFunctionTemplateInfo( ...@@ -1781,12 +1749,8 @@ void SharedFunctionInfoData::SerializeFunctionTemplateInfo(
void SharedFunctionInfoData::SerializeScopeInfoChain(JSHeapBroker* broker) { void SharedFunctionInfoData::SerializeScopeInfoChain(JSHeapBroker* broker) {
if (scope_info_) return; if (scope_info_) return;
scope_info_ = scope_info_ = broker->GetOrCreateData(
broker Handle<SharedFunctionInfo>::cast(object())->synchronized_scope_info());
->GetOrCreateData(
Handle<SharedFunctionInfo>::cast(object())->scope_info())
->AsScopeInfo();
scope_info_->SerializeScopeInfoChain(broker);
} }
class SourceTextModuleData : public HeapObjectData { class SourceTextModuleData : public HeapObjectData {
...@@ -1993,7 +1957,7 @@ class CodeData : public HeapObjectData { ...@@ -1993,7 +1957,7 @@ class CodeData : public HeapObjectData {
unsigned const inlined_bytecode_size_; unsigned const inlined_bytecode_size_;
}; };
#define DEFINE_IS_AND_AS(Name) \ #define DEFINE_IS(Name) \
bool ObjectData::Is##Name() const { \ bool ObjectData::Is##Name() const { \
if (should_access_heap()) { \ if (should_access_heap()) { \
AllowHandleDereferenceIf allow_handle_dereference(kind()); \ AllowHandleDereferenceIf allow_handle_dereference(kind()); \
...@@ -2003,13 +1967,18 @@ class CodeData : public HeapObjectData { ...@@ -2003,13 +1967,18 @@ class CodeData : public HeapObjectData {
InstanceType instance_type = \ InstanceType instance_type = \
static_cast<const HeapObjectData*>(this)->GetMapInstanceType(); \ static_cast<const HeapObjectData*>(this)->GetMapInstanceType(); \
return InstanceTypeChecker::Is##Name(instance_type); \ return InstanceTypeChecker::Is##Name(instance_type); \
} \
Name##Data* ObjectData::As##Name() { \
CHECK(Is##Name()); \
return static_cast<Name##Data*>(this); \
} }
HEAP_BROKER_OBJECT_LIST(DEFINE_IS_AND_AS) HEAP_BROKER_SERIALIZED_OBJECT_LIST(DEFINE_IS)
#undef DEFINE_IS_AND_AS HEAP_BROKER_NEVER_SERIALIZED_OBJECT_LIST(DEFINE_IS)
#undef DEFINE_IS
#define DEFINE_AS(Name) \
Name##Data* ObjectData::As##Name() { \
CHECK(Is##Name()); \
return static_cast<Name##Data*>(this); \
}
HEAP_BROKER_SERIALIZED_OBJECT_LIST(DEFINE_AS)
#undef DEFINE_AS
const JSObjectField& JSObjectData::GetInobjectField(int property_index) const { const JSObjectField& JSObjectData::GetInobjectField(int property_index) const {
CHECK_LT(static_cast<size_t>(property_index), inobject_fields_.size()); CHECK_LT(static_cast<size_t>(property_index), inobject_fields_.size());
...@@ -2683,15 +2652,20 @@ ObjectData* JSHeapBroker::GetOrCreateData(Handle<Object> object) { ...@@ -2683,15 +2652,20 @@ ObjectData* JSHeapBroker::GetOrCreateData(Handle<Object> object) {
} else if (IsReadOnlyHeapObject(*object)) { } else if (IsReadOnlyHeapObject(*object)) {
object_data = zone()->New<ObjectData>(this, data_storage, object, object_data = zone()->New<ObjectData>(this, data_storage, object,
kUnserializedReadOnlyHeapObject); kUnserializedReadOnlyHeapObject);
#define CREATE_DATA_IF_MATCH(name) \ #define CREATE_DATA_FOR_DIRECT_READ(name) \
} else if (object->Is##name()) { \
object_data = zone()->New<ObjectData>( \
this, data_storage, object, kNeverSerializedHeapObject);
HEAP_BROKER_NEVER_SERIALIZED_OBJECT_LIST(CREATE_DATA_FOR_DIRECT_READ)
#undef CREATE_DATA_FOR_DIRECT_READ
#define CREATE_DATA_FOR_SERIALIZATION(name) \
} else if (object->Is##name()) { \ } else if (object->Is##name()) { \
CHECK(SerializingAllowed()); \ CHECK(SerializingAllowed()); \
AllowHandleAllocation handle_allocation; \ AllowHandleAllocation handle_allocation; \
object_data = zone()->New<name##Data>(this, data_storage, \ object_data = zone()->New<name##Data>(this, data_storage, \
Handle<name>::cast(object)); Handle<name>::cast(object));
HEAP_BROKER_SERIALIZED_OBJECT_LIST(CREATE_DATA_FOR_SERIALIZATION)
HEAP_BROKER_OBJECT_LIST(CREATE_DATA_IF_MATCH) #undef CREATE_DATA_FOR_SERIALIZATION
#undef CREATE_DATA_IF_MATCH
} else { } else {
UNREACHABLE(); UNREACHABLE();
} }
...@@ -2704,7 +2678,7 @@ ObjectData* JSHeapBroker::GetOrCreateData(Handle<Object> object) { ...@@ -2704,7 +2678,7 @@ ObjectData* JSHeapBroker::GetOrCreateData(Handle<Object> object) {
// clang-format on // clang-format on
ObjectData* JSHeapBroker::GetOrCreateData(Object object) { ObjectData* JSHeapBroker::GetOrCreateData(Object object) {
return GetOrCreateData(handle(object, isolate())); return GetOrCreateData(CanonicalPersistentHandle(object));
} }
#define DEFINE_IS_AND_AS(Name) \ #define DEFINE_IS_AND_AS(Name) \
...@@ -2713,7 +2687,8 @@ ObjectData* JSHeapBroker::GetOrCreateData(Object object) { ...@@ -2713,7 +2687,8 @@ ObjectData* JSHeapBroker::GetOrCreateData(Object object) {
DCHECK(Is##Name()); \ DCHECK(Is##Name()); \
return Name##Ref(broker(), data()); \ return Name##Ref(broker(), data()); \
} }
HEAP_BROKER_OBJECT_LIST(DEFINE_IS_AND_AS) HEAP_BROKER_SERIALIZED_OBJECT_LIST(DEFINE_IS_AND_AS)
HEAP_BROKER_NEVER_SERIALIZED_OBJECT_LIST(DEFINE_IS_AND_AS)
#undef DEFINE_IS_AND_AS #undef DEFINE_IS_AND_AS
bool ObjectRef::IsSmi() const { return data()->is_smi(); } bool ObjectRef::IsSmi() const { return data()->is_smi(); }
...@@ -3257,8 +3232,6 @@ Handle<Object> JSHeapBroker::GetRootHandle(Object object) { ...@@ -3257,8 +3232,6 @@ Handle<Object> JSHeapBroker::GetRootHandle(Object object) {
#define IF_ACCESS_FROM_HEAP_C(holder, name) \ #define IF_ACCESS_FROM_HEAP_C(holder, name) \
if (data_->should_access_heap()) { \ if (data_->should_access_heap()) { \
CHECK(broker()->mode() == JSHeapBroker::kDisabled || \
ReadOnlyHeap::Contains(HeapObject::cast(*object()))); \
AllowHandleAllocationIf handle_allocation(data_->kind(), \ AllowHandleAllocationIf handle_allocation(data_->kind(), \
broker()->mode()); \ broker()->mode()); \
AllowHandleDereferenceIf allow_handle_dereference(data_->kind(), \ AllowHandleDereferenceIf allow_handle_dereference(data_->kind(), \
...@@ -3266,19 +3239,22 @@ Handle<Object> JSHeapBroker::GetRootHandle(Object object) { ...@@ -3266,19 +3239,22 @@ Handle<Object> JSHeapBroker::GetRootHandle(Object object) {
return object()->name(); \ return object()->name(); \
} }
#define IF_ACCESS_FROM_HEAP(holder, result, name) \ #define IF_ACCESS_FROM_HEAP(holder, result, name) \
if (data_->kind() == ObjectDataKind::kUnserializedHeapObject) { \ if (data_->kind() == ObjectDataKind::kUnserializedHeapObject) { \
AllowHandleAllocationIf handle_allocation(data_->kind(), \ AllowHandleAllocationIf handle_allocation(data_->kind(), \
broker()->mode()); \ broker()->mode()); \
AllowHandleDereferenceIf handle_dereference(data_->kind(), \ AllowHandleDereferenceIf handle_dereference(data_->kind(), \
broker()->mode()); \ broker()->mode()); \
return result##Ref(broker(), \ return result##Ref(broker(), \
handle(object()->name(), broker()->isolate())); \ handle(object()->name(), broker()->isolate())); \
} else if (data_->kind() == \ } else if (data_->kind() == \
ObjectDataKind::kUnserializedReadOnlyHeapObject) { \ ObjectDataKind::kUnserializedReadOnlyHeapObject) { \
AllowHandleDereferenceIf handle_dereference(data_->kind(), \ AllowHandleDereferenceIf handle_dereference(data_->kind(), \
broker()->mode()); \ broker()->mode()); \
return result##Ref(broker(), broker()->GetRootHandle(object()->name())); \ return result##Ref(broker(), broker()->GetRootHandle(object()->name())); \
} else if (data_->kind() == ObjectDataKind::kNeverSerializedHeapObject) { \
return result##Ref(broker(), \
broker()->CanonicalPersistentHandle(object()->name())); \
} }
// Macros for definining a const getter that, depending on the broker mode, // Macros for definining a const getter that, depending on the broker mode,
...@@ -3613,39 +3589,22 @@ int MapRef::GetInObjectProperties() const { ...@@ -3613,39 +3589,22 @@ int MapRef::GetInObjectProperties() const {
int ScopeInfoRef::ContextLength() const { int ScopeInfoRef::ContextLength() const {
IF_ACCESS_FROM_HEAP_C(ScopeInfo, ContextLength); IF_ACCESS_FROM_HEAP_C(ScopeInfo, ContextLength);
return data()->AsScopeInfo()->context_length(); UNREACHABLE();
}
int ScopeInfoRef::Flags() const {
IF_ACCESS_FROM_HEAP_C(ScopeInfo, Flags);
return data()->AsScopeInfo()->flags();
} }
bool ScopeInfoRef::HasContextExtension() const { bool ScopeInfoRef::HasContextExtensionSlot() const {
return ScopeInfo::HasContextExtensionSlotBit::decode(Flags()); IF_ACCESS_FROM_HEAP_C(ScopeInfo, HasContextExtensionSlot);
UNREACHABLE();
} }
bool ScopeInfoRef::HasOuterScopeInfo() const { bool ScopeInfoRef::HasOuterScopeInfo() const {
IF_ACCESS_FROM_HEAP_C(ScopeInfo, HasOuterScopeInfo); IF_ACCESS_FROM_HEAP_C(ScopeInfo, HasOuterScopeInfo);
return data()->AsScopeInfo()->has_outer_scope_info(); UNREACHABLE();
} }
ScopeInfoRef ScopeInfoRef::OuterScopeInfo() const { ScopeInfoRef ScopeInfoRef::OuterScopeInfo() const {
if (data_->should_access_heap()) { IF_ACCESS_FROM_HEAP(ScopeInfo, ScopeInfo, OuterScopeInfo);
DCHECK(data_->kind() != ObjectDataKind::kUnserializedReadOnlyHeapObject); UNREACHABLE();
AllowHandleAllocationIf allow_handle_allocation(data()->kind(),
broker()->mode());
AllowHandleDereferenceIf allow_handle_dereference(data()->kind(),
broker()->mode());
return ScopeInfoRef(
broker(), handle(object()->OuterScopeInfo(), broker()->isolate()));
}
return ScopeInfoRef(broker(), data()->AsScopeInfo()->outer_scope_info());
}
void ScopeInfoRef::SerializeScopeInfoChain() {
CHECK_EQ(broker()->mode(), JSHeapBroker::kSerializing);
data()->AsScopeInfo()->SerializeScopeInfoChain(broker());
} }
bool StringRef::IsExternalString() const { bool StringRef::IsExternalString() const {
...@@ -3686,8 +3645,8 @@ ScopeInfoRef NativeContextRef::scope_info() const { ...@@ -3686,8 +3645,8 @@ ScopeInfoRef NativeContextRef::scope_info() const {
broker()->mode()); broker()->mode());
AllowHandleDereferenceIf allow_handle_dereference(data()->kind(), AllowHandleDereferenceIf allow_handle_dereference(data()->kind(),
broker()->mode()); broker()->mode());
return ScopeInfoRef(broker(), return ScopeInfoRef(
handle(object()->scope_info(), broker()->isolate())); broker(), broker()->CanonicalPersistentHandle(object()->scope_info()));
} }
return ScopeInfoRef(broker(), data()->AsNativeContext()->scope_info()); return ScopeInfoRef(broker(), data()->AsNativeContext()->scope_info());
} }
...@@ -4122,7 +4081,8 @@ Handle<Object> ObjectRef::object() const { ...@@ -4122,7 +4081,8 @@ Handle<Object> ObjectRef::object() const {
} }
#endif // DEBUG #endif // DEBUG
HEAP_BROKER_OBJECT_LIST(DEF_OBJECT_GETTER) HEAP_BROKER_SERIALIZED_OBJECT_LIST(DEF_OBJECT_GETTER)
HEAP_BROKER_NEVER_SERIALIZED_OBJECT_LIST(DEF_OBJECT_GETTER)
#undef DEF_OBJECT_GETTER #undef DEF_OBJECT_GETTER
JSHeapBroker* ObjectRef::broker() const { return broker_; } JSHeapBroker* ObjectRef::broker() const { return broker_; }
...@@ -4188,7 +4148,7 @@ void NativeContextData::Serialize(JSHeapBroker* broker) { ...@@ -4188,7 +4148,7 @@ void NativeContextData::Serialize(JSHeapBroker* broker) {
function_maps_.push_back(broker->GetOrCreateData(context->get(i))->AsMap()); function_maps_.push_back(broker->GetOrCreateData(context->get(i))->AsMap());
} }
scope_info_ = broker->GetOrCreateData(context->scope_info())->AsScopeInfo(); scope_info_ = broker->GetOrCreateData(context->scope_info());
} }
void JSFunctionRef::Serialize() { void JSFunctionRef::Serialize() {
...@@ -4291,8 +4251,8 @@ ScopeInfoRef SharedFunctionInfoRef::scope_info() const { ...@@ -4291,8 +4251,8 @@ ScopeInfoRef SharedFunctionInfoRef::scope_info() const {
broker()->mode()); broker()->mode());
AllowHandleDereferenceIf allow_handle_dereference(data()->kind(), AllowHandleDereferenceIf allow_handle_dereference(data()->kind(),
broker()->mode()); broker()->mode());
return ScopeInfoRef(broker(), return ScopeInfoRef(
handle(object()->scope_info(), broker()->isolate())); broker(), broker()->CanonicalPersistentHandle(object()->scope_info()));
} }
return ScopeInfoRef(broker(), data()->AsSharedFunctionInfo()->scope_info()); return ScopeInfoRef(broker(), data()->AsSharedFunctionInfo()->scope_info());
} }
......
...@@ -1508,6 +1508,9 @@ struct TyperPhase { ...@@ -1508,6 +1508,9 @@ struct TyperPhase {
roots.push_back(data->jsgraph()->TrueConstant()); roots.push_back(data->jsgraph()->TrueConstant());
roots.push_back(data->jsgraph()->FalseConstant()); roots.push_back(data->jsgraph()->FalseConstant());
// The typer inspects heap objects, so we need to unpark the local heap.
UnparkedScopeIfNeeded scope(data->broker());
LoopVariableOptimizer induction_vars(data->jsgraph()->graph(), LoopVariableOptimizer induction_vars(data->jsgraph()->graph(),
data->common(), temp_zone); data->common(), temp_zone);
if (FLAG_turbo_loop_variable) induction_vars.Run(); if (FLAG_turbo_loop_variable) induction_vars.Run();
......
...@@ -1775,12 +1775,6 @@ void SerializerForBackgroundCompilation::VisitForInPrepare( ...@@ -1775,12 +1775,6 @@ void SerializerForBackgroundCompilation::VisitForInPrepare(
void SerializerForBackgroundCompilation::ProcessCreateContext( void SerializerForBackgroundCompilation::ProcessCreateContext(
interpreter::BytecodeArrayIterator* iterator, int scopeinfo_operand_index) { interpreter::BytecodeArrayIterator* iterator, int scopeinfo_operand_index) {
Handle<ScopeInfo> scope_info =
Handle<ScopeInfo>::cast(iterator->GetConstantForIndexOperand(
scopeinfo_operand_index, broker()->isolate()));
ScopeInfoRef scope_info_ref(broker(), scope_info);
scope_info_ref.SerializeScopeInfoChain();
Hints const& current_context_hints = environment()->current_context_hints(); Hints const& current_context_hints = environment()->current_context_hints();
Hints result_hints; Hints result_hints;
......
...@@ -79,6 +79,11 @@ ...@@ -79,6 +79,11 @@
#define DECL_SYNCHRONIZED_INT_ACCESSORS(name) \ #define DECL_SYNCHRONIZED_INT_ACCESSORS(name) \
DECL_SYNCHRONIZED_PRIMITIVE_ACCESSORS(name, int) DECL_SYNCHRONIZED_PRIMITIVE_ACCESSORS(name, int)
#define DECL_SYNCHRONIZED_ACCESSORS(name, type) \
DECL_GETTER(synchronized_##name, type) \
inline void set_synchronized_##name( \
type value, WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
#define DECL_INT32_ACCESSORS(name) DECL_PRIMITIVE_ACCESSORS(name, int32_t) #define DECL_INT32_ACCESSORS(name) DECL_PRIMITIVE_ACCESSORS(name, int32_t)
#define DECL_UINT16_ACCESSORS(name) \ #define DECL_UINT16_ACCESSORS(name) \
......
...@@ -101,6 +101,8 @@ SYNCHRONIZED_ACCESSORS(SharedFunctionInfo, function_data, Object, ...@@ -101,6 +101,8 @@ SYNCHRONIZED_ACCESSORS(SharedFunctionInfo, function_data, Object,
kFunctionDataOffset) kFunctionDataOffset)
ACCESSORS(SharedFunctionInfo, name_or_scope_info, Object, ACCESSORS(SharedFunctionInfo, name_or_scope_info, Object,
kNameOrScopeInfoOffset) kNameOrScopeInfoOffset)
SYNCHRONIZED_ACCESSORS(SharedFunctionInfo, synchronized_name_or_scope_info,
Object, kNameOrScopeInfoOffset)
ACCESSORS(SharedFunctionInfo, script_or_debug_info, HeapObject, ACCESSORS(SharedFunctionInfo, script_or_debug_info, HeapObject,
kScriptOrDebugInfoOffset) kScriptOrDebugInfoOffset)
...@@ -338,8 +340,16 @@ ScopeInfo SharedFunctionInfo::scope_info() const { ...@@ -338,8 +340,16 @@ ScopeInfo SharedFunctionInfo::scope_info() const {
return GetReadOnlyRoots().empty_scope_info(); return GetReadOnlyRoots().empty_scope_info();
} }
void SharedFunctionInfo::set_scope_info(ScopeInfo scope_info, ScopeInfo SharedFunctionInfo::synchronized_scope_info() const {
WriteBarrierMode mode) { Object maybe_scope_info = synchronized_name_or_scope_info();
if (maybe_scope_info.IsScopeInfo()) {
return ScopeInfo::cast(maybe_scope_info);
}
return GetReadOnlyRoots().empty_scope_info();
}
void SharedFunctionInfo::SetScopeInfo(ScopeInfo scope_info,
WriteBarrierMode mode) {
// Move the existing name onto the ScopeInfo. // Move the existing name onto the ScopeInfo.
Object name = name_or_scope_info(); Object name = name_or_scope_info();
if (name.IsScopeInfo()) { if (name.IsScopeInfo()) {
...@@ -351,7 +361,7 @@ void SharedFunctionInfo::set_scope_info(ScopeInfo scope_info, ...@@ -351,7 +361,7 @@ void SharedFunctionInfo::set_scope_info(ScopeInfo scope_info,
if (HasInferredName() && inferred_name().length() != 0) { if (HasInferredName() && inferred_name().length() != 0) {
scope_info.SetInferredFunctionName(inferred_name()); scope_info.SetInferredFunctionName(inferred_name());
} }
set_raw_scope_info(scope_info, mode); set_synchronized_name_or_scope_info(scope_info, mode);
} }
void SharedFunctionInfo::set_raw_scope_info(ScopeInfo scope_info, void SharedFunctionInfo::set_raw_scope_info(ScopeInfo scope_info,
......
...@@ -216,12 +216,16 @@ class SharedFunctionInfo : public HeapObject { ...@@ -216,12 +216,16 @@ class SharedFunctionInfo : public HeapObject {
static const int kNotFound = -1; static const int kNotFound = -1;
// [scope_info]: Scope info. // [scope_info]: Scope info.
DECL_ACCESSORS(scope_info, ScopeInfo) DECL_GETTER(scope_info, ScopeInfo)
DECL_GETTER(synchronized_scope_info, ScopeInfo)
// Set scope_info without moving the existing name onto the ScopeInfo. // Set scope_info without moving the existing name onto the ScopeInfo.
inline void set_raw_scope_info(ScopeInfo scope_info, inline void set_raw_scope_info(ScopeInfo scope_info,
WriteBarrierMode mode = UPDATE_WRITE_BARRIER); WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
inline void SetScopeInfo(ScopeInfo scope_info,
WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
inline bool is_script() const; inline bool is_script() const;
inline bool needs_script_context() const; inline bool needs_script_context() const;
...@@ -662,6 +666,7 @@ class SharedFunctionInfo : public HeapObject { ...@@ -662,6 +666,7 @@ class SharedFunctionInfo : public HeapObject {
// [name_or_scope_info]: Function name string, kNoSharedNameSentinel or // [name_or_scope_info]: Function name string, kNoSharedNameSentinel or
// ScopeInfo. // ScopeInfo.
DECL_ACCESSORS(name_or_scope_info, Object) DECL_ACCESSORS(name_or_scope_info, Object)
DECL_SYNCHRONIZED_ACCESSORS(name_or_scope_info, Object)
// [outer scope info] The outer scope info, needed to lazily parse this // [outer scope info] The outer scope info, needed to lazily parse this
// function. // function.
......
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