Commit 7235ebc5 authored by Mike Stanton's avatar Mike Stanton Committed by V8 LUCI CQ

[compiler] Remove kPossiblyBackgroundSerialized

This allows us to eliminate some boilerplate.

Bug: v8:7790
Change-Id: Id3a14f27621435ea4e7cbf8daf68b71da62e3f1f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2875209
Commit-Queue: Michael Stanton <mvstanton@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74572}
parent 0e1cf1fa
...@@ -1594,8 +1594,7 @@ void BytecodeGraphBuilder::VisitLdaSmi() { ...@@ -1594,8 +1594,7 @@ void BytecodeGraphBuilder::VisitLdaSmi() {
} }
void BytecodeGraphBuilder::VisitLdaConstant() { void BytecodeGraphBuilder::VisitLdaConstant() {
ObjectRef object(broker(), GetConstantForIndexOperand(0), ObjectRef object(broker(), GetConstantForIndexOperand(0));
ObjectRef::BackgroundSerialization::kAllowed);
Node* node = jsgraph()->Constant(object); Node* node = jsgraph()->Constant(object);
environment()->BindAccumulator(node); environment()->BindAccumulator(node);
} }
......
...@@ -2657,11 +2657,9 @@ namespace { ...@@ -2657,11 +2657,9 @@ namespace {
template <RefSerializationKind Kind, class DataT, class ObjectT> template <RefSerializationKind Kind, class DataT, class ObjectT>
struct CreateDataFunctor { struct CreateDataFunctor {
bool operator()(JSHeapBroker* broker, RefsMap* refs, bool operator()(JSHeapBroker* broker, RefsMap* refs,
ObjectRef::BackgroundSerialization background_serialization,
Handle<Object> object, RefsMap::Entry** entry_out, Handle<Object> object, RefsMap::Entry** entry_out,
ObjectData** object_data_out) { ObjectData** object_data_out) {
USE(broker, refs, background_serialization, object, entry_out, USE(broker, refs, object, entry_out, object_data_out);
object_data_out);
UNREACHABLE(); UNREACHABLE();
} }
}; };
...@@ -2669,7 +2667,6 @@ struct CreateDataFunctor { ...@@ -2669,7 +2667,6 @@ struct CreateDataFunctor {
template <class DataT, class ObjectT> template <class DataT, class ObjectT>
struct CreateDataFunctor<RefSerializationKind::kSerialized, DataT, ObjectT> { struct CreateDataFunctor<RefSerializationKind::kSerialized, DataT, ObjectT> {
bool operator()(JSHeapBroker* broker, RefsMap* refs, bool operator()(JSHeapBroker* broker, RefsMap* refs,
ObjectRef::BackgroundSerialization background_serialization,
Handle<Object> object, RefsMap::Entry** entry_out, Handle<Object> object, RefsMap::Entry** entry_out,
ObjectData** object_data_out) { ObjectData** object_data_out) {
if (broker->mode() == JSHeapBroker::kSerializing) { if (broker->mode() == JSHeapBroker::kSerializing) {
...@@ -2687,7 +2684,6 @@ template <class DataT, class ObjectT> ...@@ -2687,7 +2684,6 @@ template <class DataT, class ObjectT>
struct CreateDataFunctor<RefSerializationKind::kBackgroundSerialized, DataT, struct CreateDataFunctor<RefSerializationKind::kBackgroundSerialized, DataT,
ObjectT> { ObjectT> {
bool operator()(JSHeapBroker* broker, RefsMap* refs, bool operator()(JSHeapBroker* broker, RefsMap* refs,
ObjectRef::BackgroundSerialization background_serialization,
Handle<Object> object, RefsMap::Entry** entry_out, Handle<Object> object, RefsMap::Entry** entry_out,
ObjectData** object_data_out) { ObjectData** object_data_out) {
if (broker->is_concurrent_inlining()) { if (broker->is_concurrent_inlining()) {
...@@ -2709,35 +2705,10 @@ struct CreateDataFunctor<RefSerializationKind::kBackgroundSerialized, DataT, ...@@ -2709,35 +2705,10 @@ struct CreateDataFunctor<RefSerializationKind::kBackgroundSerialized, DataT,
} }
}; };
template <class DataT, class ObjectT>
struct CreateDataFunctor<RefSerializationKind::kPossiblyBackgroundSerialized,
DataT, ObjectT> {
bool operator()(JSHeapBroker* broker, RefsMap* refs,
ObjectRef::BackgroundSerialization background_serialization,
Handle<Object> object, RefsMap::Entry** entry_out,
ObjectData** object_data_out) {
if (broker->mode() == JSHeapBroker::kSerialized &&
background_serialization !=
ObjectRef::BackgroundSerialization::kAllowed) {
return false;
}
RefsMap::Entry* entry = refs->LookupOrInsert(object.address());
ObjectDataKind kind = (background_serialization ==
ObjectRef::BackgroundSerialization::kAllowed)
? kBackgroundSerializedHeapObject
: kSerializedHeapObject;
*object_data_out = broker->zone()->New<DataT>(
broker, &entry->value, Handle<ObjectT>::cast(object), kind);
*entry_out = entry;
return true;
}
};
template <class DataT, class ObjectT> template <class DataT, class ObjectT>
struct CreateDataFunctor<RefSerializationKind::kNeverSerialized, DataT, struct CreateDataFunctor<RefSerializationKind::kNeverSerialized, DataT,
ObjectT> { ObjectT> {
bool operator()(JSHeapBroker* broker, RefsMap* refs, bool operator()(JSHeapBroker* broker, RefsMap* refs, Handle<Object> object,
ObjectRef::BackgroundSerialization, Handle<Object> object,
RefsMap::Entry** entry_out, ObjectData** object_data_out) { RefsMap::Entry** entry_out, ObjectData** object_data_out) {
// TODO(solanes, v8:10866): Remove the `(mode() == kSerializing)` case // TODO(solanes, v8:10866): Remove the `(mode() == kSerializing)` case
// below when all classes skip serialization. Same for similar spots if we // below when all classes skip serialization. Same for similar spots if we
...@@ -2781,9 +2752,8 @@ void JSHeapBroker::ClearReconstructibleData() { ...@@ -2781,9 +2752,8 @@ void JSHeapBroker::ClearReconstructibleData() {
} }
} }
ObjectData* JSHeapBroker::TryGetOrCreateData( ObjectData* JSHeapBroker::TryGetOrCreateData(Handle<Object> object,
Handle<Object> object, bool crash_on_error, bool crash_on_error) {
ObjectRef::BackgroundSerialization background_serialization) {
RefsMap::Entry* entry = refs_->Lookup(object.address()); RefsMap::Entry* entry = refs_->Lookup(object.address());
if (entry != nullptr) return entry->value; if (entry != nullptr) return entry->value;
...@@ -2814,8 +2784,7 @@ ObjectData* JSHeapBroker::TryGetOrCreateData( ...@@ -2814,8 +2784,7 @@ ObjectData* JSHeapBroker::TryGetOrCreateData(
/* NOLINTNEXTLINE(readability/braces) */ \ /* NOLINTNEXTLINE(readability/braces) */ \
else if (object->Is##Name()) { \ else if (object->Is##Name()) { \
CreateDataFunctor<Kind, Name##Data, Name> f; \ CreateDataFunctor<Kind, Name##Data, Name> f; \
if (!f(this, refs_, background_serialization, object, &entry, \ if (!f(this, refs_, object, &entry, &object_data)) { \
&object_data)) { \
CHECK(!crash_on_error); \ CHECK(!crash_on_error); \
return nullptr; \ return nullptr; \
} }
...@@ -3977,12 +3946,11 @@ base::Optional<ObjectRef> SourceTextModuleRef::import_meta() const { ...@@ -3977,12 +3946,11 @@ base::Optional<ObjectRef> SourceTextModuleRef::import_meta() const {
} }
ObjectRef::ObjectRef(JSHeapBroker* broker, Handle<Object> object, ObjectRef::ObjectRef(JSHeapBroker* broker, Handle<Object> object,
BackgroundSerialization background_serialization,
bool check_type) bool check_type)
: broker_(broker) { : broker_(broker) {
CHECK_NE(broker->mode(), JSHeapBroker::kRetired); CHECK_NE(broker->mode(), JSHeapBroker::kRetired);
data_ = broker->GetOrCreateData(object, background_serialization); data_ = broker->GetOrCreateData(object);
if (!data_) { // TODO(mslekova): Remove once we're on the background thread. if (!data_) { // TODO(mslekova): Remove once we're on the background thread.
object->Print(); object->Print();
} }
...@@ -4254,10 +4222,9 @@ void NativeContextData::SerializeOnBackground(JSHeapBroker* broker) { ...@@ -4254,10 +4222,9 @@ void NativeContextData::SerializeOnBackground(JSHeapBroker* broker) {
TraceScope tracer(broker, this, "NativeContextData::SerializeOnBackground"); TraceScope tracer(broker, this, "NativeContextData::SerializeOnBackground");
Handle<NativeContext> context = Handle<NativeContext>::cast(object()); Handle<NativeContext> context = Handle<NativeContext>::cast(object());
constexpr auto kAllowed = ObjectRef::BackgroundSerialization::kAllowed;
#define SERIALIZE_MEMBER(type, name) \ #define SERIALIZE_MEMBER(type, name) \
DCHECK_NULL(name##_); \ DCHECK_NULL(name##_); \
name##_ = broker->GetOrCreateData(context->name(kAcquireLoad), kAllowed); \ name##_ = broker->GetOrCreateData(context->name(kAcquireLoad)); \
if (!name##_->should_access_heap()) { \ if (!name##_->should_access_heap()) { \
DCHECK(!name##_->IsJSFunction()); \ DCHECK(!name##_->IsJSFunction()); \
} }
...@@ -4273,7 +4240,7 @@ void NativeContextData::SerializeOnBackground(JSHeapBroker* broker) { ...@@ -4273,7 +4240,7 @@ void NativeContextData::SerializeOnBackground(JSHeapBroker* broker) {
function_maps_.reserve(last + 1 - first); function_maps_.reserve(last + 1 - first);
for (int i = first; i <= last; ++i) { for (int i = first; i <= last; ++i) {
function_maps_.push_back( function_maps_.push_back(
broker->GetOrCreateData(context->get(i, kAcquireLoad), kAllowed)); broker->GetOrCreateData(context->get(i, kAcquireLoad)));
} }
} }
......
...@@ -73,12 +73,6 @@ enum class RefSerializationKind { ...@@ -73,12 +73,6 @@ enum class RefSerializationKind {
kNeverSerialized, kNeverSerialized,
// Can be serialized on demand from the background thread. // Can be serialized on demand from the background thread.
kBackgroundSerialized, kBackgroundSerialized,
// Behave like serialized classes, but allow lazy serialization from
// background threads where this is safe (e.g. for objects that are immutable
// and fully initialized once visible). Pass
// ObjectRef::BackgroundSerialization::kAllowed to the ObjectRef constructor
// for objects where serialization from the background thread is safe.
kPossiblyBackgroundSerialized,
kSerialized, kSerialized,
}; };
...@@ -166,14 +160,7 @@ struct ref_traits<Object> { ...@@ -166,14 +160,7 @@ struct ref_traits<Object> {
class V8_EXPORT_PRIVATE ObjectRef { class V8_EXPORT_PRIVATE ObjectRef {
public: public:
enum class BackgroundSerialization {
kDisallowed,
kAllowed,
};
ObjectRef(JSHeapBroker* broker, Handle<Object> object, ObjectRef(JSHeapBroker* broker, Handle<Object> object,
BackgroundSerialization background_serialization =
BackgroundSerialization::kDisallowed,
bool check_type = true); bool check_type = true);
ObjectRef(JSHeapBroker* broker, ObjectData* data, bool check_type = true) ObjectRef(JSHeapBroker* broker, ObjectData* data, bool check_type = true)
: data_(data), broker_(broker) { : data_(data), broker_(broker) {
......
...@@ -227,27 +227,19 @@ bool JSHeapBroker::IsArrayOrObjectPrototype(Handle<JSObject> object) const { ...@@ -227,27 +227,19 @@ bool JSHeapBroker::IsArrayOrObjectPrototype(Handle<JSObject> object) const {
array_and_object_prototypes_.end(); array_and_object_prototypes_.end();
} }
ObjectData* JSHeapBroker::TryGetOrCreateData( ObjectData* JSHeapBroker::TryGetOrCreateData(Object object,
Object object, bool crash_on_error, bool crash_on_error) {
ObjectRef::BackgroundSerialization background_serialization) { return TryGetOrCreateData(CanonicalPersistentHandle(object), crash_on_error);
return TryGetOrCreateData(CanonicalPersistentHandle(object), crash_on_error, }
background_serialization);
} ObjectData* JSHeapBroker::GetOrCreateData(Handle<Object> object) {
ObjectData* return_value = TryGetOrCreateData(object, true);
ObjectData* JSHeapBroker::GetOrCreateData(
Handle<Object> object,
ObjectRef::BackgroundSerialization background_serialization) {
ObjectData* return_value =
TryGetOrCreateData(object, true, background_serialization);
DCHECK_NOT_NULL(return_value); DCHECK_NOT_NULL(return_value);
return return_value; return return_value;
} }
ObjectData* JSHeapBroker::GetOrCreateData( ObjectData* JSHeapBroker::GetOrCreateData(Object object) {
Object object, return GetOrCreateData(CanonicalPersistentHandle(object));
ObjectRef::BackgroundSerialization background_serialization) {
return GetOrCreateData(CanonicalPersistentHandle(object),
background_serialization);
} }
bool JSHeapBroker::StackHasOverflowed() const { bool JSHeapBroker::StackHasOverflowed() const {
......
...@@ -151,25 +151,14 @@ class V8_EXPORT_PRIVATE JSHeapBroker { ...@@ -151,25 +151,14 @@ class V8_EXPORT_PRIVATE JSHeapBroker {
Handle<Object> GetRootHandle(Object object); Handle<Object> GetRootHandle(Object object);
// Never returns nullptr. // Never returns nullptr.
ObjectData* GetOrCreateData( ObjectData* GetOrCreateData(Handle<Object>);
Handle<Object>,
ObjectRef::BackgroundSerialization background_serialization =
ObjectRef::BackgroundSerialization::kDisallowed);
// Like the previous but wraps argument in handle first (for convenience). // Like the previous but wraps argument in handle first (for convenience).
ObjectData* GetOrCreateData( ObjectData* GetOrCreateData(Object);
Object, ObjectRef::BackgroundSerialization background_serialization =
ObjectRef::BackgroundSerialization::kDisallowed);
// Gets data only if we have it. However, thin wrappers will be created for // Gets data only if we have it. However, thin wrappers will be created for
// smis, read-only objects and never-serialized objects. // smis, read-only objects and never-serialized objects.
ObjectData* TryGetOrCreateData( ObjectData* TryGetOrCreateData(Handle<Object>, bool crash_on_error = false);
Handle<Object>, bool crash_on_error = false, ObjectData* TryGetOrCreateData(Object object, bool crash_on_error = false);
ObjectRef::BackgroundSerialization background_serialization =
ObjectRef::BackgroundSerialization::kDisallowed);
ObjectData* TryGetOrCreateData(
Object object, bool crash_on_error = false,
ObjectRef::BackgroundSerialization background_serialization =
ObjectRef::BackgroundSerialization::kDisallowed);
// Check if {object} is any native context's %ArrayPrototype% or // Check if {object} is any native context's %ArrayPrototype% or
// %ObjectPrototype%. // %ObjectPrototype%.
......
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