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() {
}
void BytecodeGraphBuilder::VisitLdaConstant() {
ObjectRef object(broker(), GetConstantForIndexOperand(0),
ObjectRef::BackgroundSerialization::kAllowed);
ObjectRef object(broker(), GetConstantForIndexOperand(0));
Node* node = jsgraph()->Constant(object);
environment()->BindAccumulator(node);
}
......
......@@ -2657,11 +2657,9 @@ namespace {
template <RefSerializationKind Kind, class DataT, class ObjectT>
struct CreateDataFunctor {
bool operator()(JSHeapBroker* broker, RefsMap* refs,
ObjectRef::BackgroundSerialization background_serialization,
Handle<Object> object, RefsMap::Entry** entry_out,
ObjectData** object_data_out) {
USE(broker, refs, background_serialization, object, entry_out,
object_data_out);
USE(broker, refs, object, entry_out, object_data_out);
UNREACHABLE();
}
};
......@@ -2669,7 +2667,6 @@ struct CreateDataFunctor {
template <class DataT, class ObjectT>
struct CreateDataFunctor<RefSerializationKind::kSerialized, 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::kSerializing) {
......@@ -2687,7 +2684,6 @@ template <class DataT, class ObjectT>
struct CreateDataFunctor<RefSerializationKind::kBackgroundSerialized, 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->is_concurrent_inlining()) {
......@@ -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>
struct CreateDataFunctor<RefSerializationKind::kNeverSerialized, DataT,
ObjectT> {
bool operator()(JSHeapBroker* broker, RefsMap* refs,
ObjectRef::BackgroundSerialization, Handle<Object> object,
bool operator()(JSHeapBroker* broker, RefsMap* refs, Handle<Object> object,
RefsMap::Entry** entry_out, ObjectData** object_data_out) {
// TODO(solanes, v8:10866): Remove the `(mode() == kSerializing)` case
// below when all classes skip serialization. Same for similar spots if we
......@@ -2781,9 +2752,8 @@ void JSHeapBroker::ClearReconstructibleData() {
}
}
ObjectData* JSHeapBroker::TryGetOrCreateData(
Handle<Object> object, bool crash_on_error,
ObjectRef::BackgroundSerialization background_serialization) {
ObjectData* JSHeapBroker::TryGetOrCreateData(Handle<Object> object,
bool crash_on_error) {
RefsMap::Entry* entry = refs_->Lookup(object.address());
if (entry != nullptr) return entry->value;
......@@ -2809,15 +2779,14 @@ ObjectData* JSHeapBroker::TryGetOrCreateData(
entry = refs_->LookupOrInsert(object.address());
object_data = zone()->New<ObjectData>(this, &(entry->value), object,
kUnserializedReadOnlyHeapObject);
#define CREATE_DATA(Name, Kind) \
} \
/* NOLINTNEXTLINE(readability/braces) */ \
else if (object->Is##Name()) { \
CreateDataFunctor<Kind, Name##Data, Name> f; \
if (!f(this, refs_, background_serialization, object, &entry, \
&object_data)) { \
CHECK(!crash_on_error); \
return nullptr; \
#define CREATE_DATA(Name, Kind) \
} \
/* NOLINTNEXTLINE(readability/braces) */ \
else if (object->Is##Name()) { \
CreateDataFunctor<Kind, Name##Data, Name> f; \
if (!f(this, refs_, object, &entry, &object_data)) { \
CHECK(!crash_on_error); \
return nullptr; \
}
HEAP_BROKER_OBJECT_LIST(CREATE_DATA)
#undef CREATE_DATA
......@@ -3977,12 +3946,11 @@ base::Optional<ObjectRef> SourceTextModuleRef::import_meta() const {
}
ObjectRef::ObjectRef(JSHeapBroker* broker, Handle<Object> object,
BackgroundSerialization background_serialization,
bool check_type)
: broker_(broker) {
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.
object->Print();
}
......@@ -4254,12 +4222,11 @@ void NativeContextData::SerializeOnBackground(JSHeapBroker* broker) {
TraceScope tracer(broker, this, "NativeContextData::SerializeOnBackground");
Handle<NativeContext> context = Handle<NativeContext>::cast(object());
constexpr auto kAllowed = ObjectRef::BackgroundSerialization::kAllowed;
#define SERIALIZE_MEMBER(type, name) \
DCHECK_NULL(name##_); \
name##_ = broker->GetOrCreateData(context->name(kAcquireLoad), kAllowed); \
if (!name##_->should_access_heap()) { \
DCHECK(!name##_->IsJSFunction()); \
#define SERIALIZE_MEMBER(type, name) \
DCHECK_NULL(name##_); \
name##_ = broker->GetOrCreateData(context->name(kAcquireLoad)); \
if (!name##_->should_access_heap()) { \
DCHECK(!name##_->IsJSFunction()); \
}
BROKER_COMPULSORY_BACKGROUND_NATIVE_CONTEXT_FIELDS(SERIALIZE_MEMBER)
if (!broker->is_isolate_bootstrapping()) {
......@@ -4273,7 +4240,7 @@ void NativeContextData::SerializeOnBackground(JSHeapBroker* broker) {
function_maps_.reserve(last + 1 - first);
for (int i = first; i <= last; ++i) {
function_maps_.push_back(
broker->GetOrCreateData(context->get(i, kAcquireLoad), kAllowed));
broker->GetOrCreateData(context->get(i, kAcquireLoad)));
}
}
......
......@@ -73,12 +73,6 @@ enum class RefSerializationKind {
kNeverSerialized,
// Can be serialized on demand from the background thread.
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,
};
......@@ -166,14 +160,7 @@ struct ref_traits<Object> {
class V8_EXPORT_PRIVATE ObjectRef {
public:
enum class BackgroundSerialization {
kDisallowed,
kAllowed,
};
ObjectRef(JSHeapBroker* broker, Handle<Object> object,
BackgroundSerialization background_serialization =
BackgroundSerialization::kDisallowed,
bool check_type = true);
ObjectRef(JSHeapBroker* broker, ObjectData* data, bool check_type = true)
: data_(data), broker_(broker) {
......
......@@ -227,27 +227,19 @@ bool JSHeapBroker::IsArrayOrObjectPrototype(Handle<JSObject> object) const {
array_and_object_prototypes_.end();
}
ObjectData* JSHeapBroker::TryGetOrCreateData(
Object object, bool crash_on_error,
ObjectRef::BackgroundSerialization background_serialization) {
return TryGetOrCreateData(CanonicalPersistentHandle(object), crash_on_error,
background_serialization);
}
ObjectData* JSHeapBroker::GetOrCreateData(
Handle<Object> object,
ObjectRef::BackgroundSerialization background_serialization) {
ObjectData* return_value =
TryGetOrCreateData(object, true, background_serialization);
ObjectData* JSHeapBroker::TryGetOrCreateData(Object object,
bool crash_on_error) {
return TryGetOrCreateData(CanonicalPersistentHandle(object), crash_on_error);
}
ObjectData* JSHeapBroker::GetOrCreateData(Handle<Object> object) {
ObjectData* return_value = TryGetOrCreateData(object, true);
DCHECK_NOT_NULL(return_value);
return return_value;
}
ObjectData* JSHeapBroker::GetOrCreateData(
Object object,
ObjectRef::BackgroundSerialization background_serialization) {
return GetOrCreateData(CanonicalPersistentHandle(object),
background_serialization);
ObjectData* JSHeapBroker::GetOrCreateData(Object object) {
return GetOrCreateData(CanonicalPersistentHandle(object));
}
bool JSHeapBroker::StackHasOverflowed() const {
......
......@@ -151,25 +151,14 @@ class V8_EXPORT_PRIVATE JSHeapBroker {
Handle<Object> GetRootHandle(Object object);
// Never returns nullptr.
ObjectData* GetOrCreateData(
Handle<Object>,
ObjectRef::BackgroundSerialization background_serialization =
ObjectRef::BackgroundSerialization::kDisallowed);
ObjectData* GetOrCreateData(Handle<Object>);
// Like the previous but wraps argument in handle first (for convenience).
ObjectData* GetOrCreateData(
Object, ObjectRef::BackgroundSerialization background_serialization =
ObjectRef::BackgroundSerialization::kDisallowed);
ObjectData* GetOrCreateData(Object);
// Gets data only if we have it. However, thin wrappers will be created for
// smis, read-only objects and never-serialized objects.
ObjectData* TryGetOrCreateData(
Handle<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);
ObjectData* TryGetOrCreateData(Handle<Object>, bool crash_on_error = false);
ObjectData* TryGetOrCreateData(Object object, bool crash_on_error = false);
// Check if {object} is any native context's %ArrayPrototype% or
// %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