Commit c3bdc076 authored by Jakob Gruber's avatar Jakob Gruber Committed by V8 LUCI CQ

[compiler] Make (Native)Context never-ever serialized

Bug: v8:7790
Change-Id: If558b6db7feed50bd0325a814bcab9e98ebd9493
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2991239
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarSantiago Aboy Solanes <solanes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75463}
parent 55b66b72
This diff is collapsed.
...@@ -464,91 +464,69 @@ class ContextRef : public HeapObjectRef { ...@@ -464,91 +464,69 @@ class ContextRef : public HeapObjectRef {
// {previous} decrements {depth} by 1 for each previous link successfully // {previous} decrements {depth} by 1 for each previous link successfully
// followed. If {depth} != 0 on function return, then it only got partway to // followed. If {depth} != 0 on function return, then it only got partway to
// the desired depth. If {serialize} is true, then {previous} will cache its // the desired depth.
// findings (unless concurrent inlining is enabled). ContextRef previous(size_t* depth) const;
ContextRef previous(size_t* depth,
SerializationPolicy policy =
SerializationPolicy::kAssumeSerialized) const;
// Only returns a value if the index is valid for this ContextRef. // Only returns a value if the index is valid for this ContextRef.
base::Optional<ObjectRef> get( base::Optional<ObjectRef> get(int index) const;
int index, SerializationPolicy policy =
SerializationPolicy::kAssumeSerialized) const;
SourceTextModuleRef GetModule(SerializationPolicy policy) const; SourceTextModuleRef GetModule() const;
}; };
// TODO(jgruber): Don't serialize NativeContext fields once all refs can be // TODO(jgruber): Don't serialize NativeContext fields once all refs can be
// created concurrently. // created concurrently.
#define BROKER_COMPULSORY_NATIVE_CONTEXT_FIELDS(V) \ #define BROKER_NATIVE_CONTEXT_FIELDS(V) \
V(JSFunction, array_function) \ V(JSFunction, array_function) \
V(JSFunction, function_prototype_apply) \ V(JSFunction, bigint_function) \
V(JSFunction, boolean_function) \ V(JSFunction, boolean_function) \
V(JSFunction, bigint_function) \ V(JSFunction, function_prototype_apply) \
V(JSFunction, number_function) \ V(JSFunction, number_function) \
V(JSFunction, object_function) \ V(JSFunction, object_function) \
V(JSFunction, promise_function) \ V(JSFunction, promise_function) \
V(JSFunction, promise_then) \ V(JSFunction, promise_then) \
V(JSFunction, regexp_function) \ V(JSFunction, regexp_exec_function) \
V(JSFunction, string_function) \ V(JSFunction, regexp_function) \
V(JSFunction, symbol_function) \ V(JSFunction, string_function) \
V(JSGlobalObject, global_object) \ V(JSFunction, symbol_function) \
V(JSGlobalProxy, global_proxy_object) \ V(JSGlobalObject, global_object) \
V(JSObject, promise_prototype) \ V(JSGlobalProxy, global_proxy_object) \
V(Map, bound_function_with_constructor_map) \ V(JSObject, promise_prototype) \
V(Map, bound_function_without_constructor_map) \ V(Map, async_function_object_map) \
V(Map, js_array_holey_double_elements_map) \ V(Map, block_context_map) \
V(Map, js_array_holey_elements_map) \ V(Map, bound_function_with_constructor_map) \
V(Map, js_array_holey_smi_elements_map) \ V(Map, bound_function_without_constructor_map) \
V(Map, js_array_packed_double_elements_map) \ V(Map, catch_context_map) \
V(Map, js_array_packed_elements_map) \ V(Map, eval_context_map) \
V(Map, js_array_packed_smi_elements_map) \ V(Map, fast_aliased_arguments_map) \
V(Map, function_context_map) \
V(Map, initial_array_iterator_map) \
V(Map, initial_string_iterator_map) \
V(Map, iterator_result_map) \
V(Map, js_array_holey_double_elements_map) \
V(Map, js_array_holey_elements_map) \
V(Map, js_array_holey_smi_elements_map) \
V(Map, js_array_packed_double_elements_map) \
V(Map, js_array_packed_elements_map) \
V(Map, js_array_packed_smi_elements_map) \
V(Map, map_key_iterator_map) \
V(Map, map_key_value_iterator_map) \
V(Map, map_value_iterator_map) \
V(Map, set_key_value_iterator_map) \
V(Map, set_value_iterator_map) \
V(Map, sloppy_arguments_map) \
V(Map, slow_object_with_null_prototype_map) \
V(Map, strict_arguments_map) \
V(Map, with_context_map) \
V(ScriptContextTable, script_context_table) V(ScriptContextTable, script_context_table)
#define BROKER_OPTIONAL_NATIVE_CONTEXT_FIELDS(V) \
V(JSFunction, regexp_exec_function)
#define BROKER_COMPULSORY_BACKGROUND_NATIVE_CONTEXT_FIELDS(V) \
V(Map, block_context_map) \
V(Map, catch_context_map) \
V(Map, eval_context_map) \
V(Map, fast_aliased_arguments_map) \
V(Map, function_context_map) \
V(Map, initial_array_iterator_map) \
V(Map, initial_string_iterator_map) \
V(Map, iterator_result_map) \
V(Map, sloppy_arguments_map) \
V(Map, slow_object_with_null_prototype_map) \
V(Map, strict_arguments_map) \
V(Map, with_context_map)
// Those are set by Bootstrapper::ExportFromRuntime, which may not yet have
// happened when Turbofan is invoked via --always-opt.
#define BROKER_OPTIONAL_BACKGROUND_NATIVE_CONTEXT_FIELDS(V) \
V(Map, async_function_object_map) \
V(Map, map_key_iterator_map) \
V(Map, map_key_value_iterator_map) \
V(Map, map_value_iterator_map) \
V(Map, set_key_value_iterator_map) \
V(Map, set_value_iterator_map)
#define BROKER_NATIVE_CONTEXT_FIELDS(V) \
BROKER_COMPULSORY_NATIVE_CONTEXT_FIELDS(V) \
BROKER_OPTIONAL_NATIVE_CONTEXT_FIELDS(V) \
BROKER_COMPULSORY_BACKGROUND_NATIVE_CONTEXT_FIELDS(V) \
BROKER_OPTIONAL_BACKGROUND_NATIVE_CONTEXT_FIELDS(V)
class NativeContextRef : public ContextRef { class NativeContextRef : public ContextRef {
public: public:
DEFINE_REF_CONSTRUCTOR(NativeContext, ContextRef) DEFINE_REF_CONSTRUCTOR(NativeContext, ContextRef)
bool is_unserialized_heap_object() const;
Handle<NativeContext> object() const; Handle<NativeContext> object() const;
void Serialize(); void Serialize();
void SerializeOnBackground();
#define DECL_ACCESSOR(type, name) type##Ref name() const; #define DECL_ACCESSOR(type, name) type##Ref name() const;
BROKER_NATIVE_CONTEXT_FIELDS(DECL_ACCESSOR) BROKER_NATIVE_CONTEXT_FIELDS(DECL_ACCESSOR)
......
...@@ -257,9 +257,10 @@ Reduction JSContextSpecialization::ReduceJSGetImportMeta(Node* node) { ...@@ -257,9 +257,10 @@ Reduction JSContextSpecialization::ReduceJSGetImportMeta(Node* node) {
if (!maybe_context.has_value()) return NoChange(); if (!maybe_context.has_value()) return NoChange();
ContextRef context = maybe_context.value(); ContextRef context = maybe_context.value();
SourceTextModuleRef module = base::Optional<ObjectRef> module = context.get(Context::EXTENSION_INDEX);
context.get(Context::EXTENSION_INDEX).value().AsSourceTextModule(); if (!module.has_value()) return NoChange();
base::Optional<ObjectRef> import_meta = module.import_meta(); base::Optional<ObjectRef> import_meta =
module->AsSourceTextModule().import_meta();
if (!import_meta.has_value()) return NoChange(); if (!import_meta.has_value()) return NoChange();
if (!import_meta->IsJSObject()) { if (!import_meta->IsJSObject()) {
DCHECK(import_meta->IsTheHole()); DCHECK(import_meta->IsTheHole());
......
...@@ -102,12 +102,6 @@ void JSHeapBroker::AttachLocalIsolate(OptimizedCompilationInfo* info, ...@@ -102,12 +102,6 @@ void JSHeapBroker::AttachLocalIsolate(OptimizedCompilationInfo* info,
DCHECK_NOT_NULL(local_isolate_); DCHECK_NOT_NULL(local_isolate_);
local_isolate_->heap()->AttachPersistentHandles( local_isolate_->heap()->AttachPersistentHandles(
info->DetachPersistentHandles()); info->DetachPersistentHandles());
if (is_concurrent_inlining()) {
// Ensure any serialization that happens on the background has been
// performed.
target_native_context().SerializeOnBackground();
}
} }
void JSHeapBroker::DetachLocalIsolate(OptimizedCompilationInfo* info) { void JSHeapBroker::DetachLocalIsolate(OptimizedCompilationInfo* info) {
...@@ -140,8 +134,7 @@ void JSHeapBroker::SetTargetNativeContextRef( ...@@ -140,8 +134,7 @@ void JSHeapBroker::SetTargetNativeContextRef(
Handle<NativeContext> native_context) { Handle<NativeContext> native_context) {
DCHECK((mode() == kDisabled && !target_native_context_.has_value()) || DCHECK((mode() == kDisabled && !target_native_context_.has_value()) ||
(mode() == kSerializing && (mode() == kSerializing &&
target_native_context_->object().is_identical_to(native_context) && target_native_context_->object().is_identical_to(native_context)));
target_native_context_->is_unserialized_heap_object()));
target_native_context_ = MakeRef(this, *native_context); target_native_context_ = MakeRef(this, *native_context);
} }
...@@ -700,8 +693,7 @@ ProcessedFeedback const& JSHeapBroker::ReadFeedbackForGlobalAccess( ...@@ -700,8 +693,7 @@ ProcessedFeedback const& JSHeapBroker::ReadFeedbackForGlobalAccess(
} }
ContextRef context_ref = MakeRef(this, context); ContextRef context_ref = MakeRef(this, context);
if (immutable) { if (immutable) {
context_ref.get(context_slot_index, context_ref.get(context_slot_index);
SerializationPolicy::kSerializeIfNeeded);
} }
return *zone()->New<GlobalAccessFeedback>(context_ref, context_slot_index, return *zone()->New<GlobalAccessFeedback>(context_ref, context_slot_index,
immutable, nexus.kind()); immutable, nexus.kind());
......
...@@ -1498,13 +1498,11 @@ void SerializerForBackgroundCompilation::VisitInvokeIntrinsic( ...@@ -1498,13 +1498,11 @@ void SerializerForBackgroundCompilation::VisitInvokeIntrinsic(
case Runtime::kInlineGetImportMetaObject: { case Runtime::kInlineGetImportMetaObject: {
Hints const& context_hints = environment()->current_context_hints(); Hints const& context_hints = environment()->current_context_hints();
for (auto x : context_hints.constants()) { for (auto x : context_hints.constants()) {
MakeRef(broker(), Handle<Context>::cast(x)) MakeRef(broker(), Handle<Context>::cast(x)).GetModule().Serialize();
.GetModule(SerializationPolicy::kSerializeIfNeeded)
.Serialize();
} }
for (auto x : context_hints.virtual_contexts()) { for (auto x : context_hints.virtual_contexts()) {
MakeRef(broker(), Handle<Context>::cast(x.context)) MakeRef(broker(), Handle<Context>::cast(x.context))
.GetModule(SerializationPolicy::kSerializeIfNeeded) .GetModule()
.Serialize(); .Serialize();
} }
break; break;
...@@ -1546,8 +1544,7 @@ void SerializerForBackgroundCompilation::ProcessImmutableLoad( ...@@ -1546,8 +1544,7 @@ void SerializerForBackgroundCompilation::ProcessImmutableLoad(
ContextRef const& context_ref, int slot, ContextProcessingMode mode, ContextRef const& context_ref, int slot, ContextProcessingMode mode,
Hints* result_hints) { Hints* result_hints) {
DCHECK_EQ(mode, kSerializeSlot); DCHECK_EQ(mode, kSerializeSlot);
base::Optional<ObjectRef> slot_value = base::Optional<ObjectRef> slot_value = context_ref.get(slot);
context_ref.get(slot, SerializationPolicy::kSerializeIfNeeded);
// If requested, record the object as a hint for the result value. // If requested, record the object as a hint for the result value.
if (result_hints != nullptr && slot_value.has_value()) { if (result_hints != nullptr && slot_value.has_value()) {
...@@ -1568,8 +1565,7 @@ void SerializerForBackgroundCompilation::ProcessContextAccess( ...@@ -1568,8 +1565,7 @@ void SerializerForBackgroundCompilation::ProcessContextAccess(
// Walk this context to the given depth and serialize the slot found. // Walk this context to the given depth and serialize the slot found.
ContextRef context_ref = MakeRef(broker(), Handle<Context>::cast(x)); ContextRef context_ref = MakeRef(broker(), Handle<Context>::cast(x));
size_t remaining_depth = depth; size_t remaining_depth = depth;
context_ref = context_ref.previous( context_ref = context_ref.previous(&remaining_depth);
&remaining_depth, SerializationPolicy::kSerializeIfNeeded);
if (remaining_depth == 0 && mode != kIgnoreSlot) { if (remaining_depth == 0 && mode != kIgnoreSlot) {
ProcessImmutableLoad(context_ref, slot, mode, result_hints); ProcessImmutableLoad(context_ref, slot, mode, result_hints);
} }
...@@ -1580,8 +1576,7 @@ void SerializerForBackgroundCompilation::ProcessContextAccess( ...@@ -1580,8 +1576,7 @@ void SerializerForBackgroundCompilation::ProcessContextAccess(
ContextRef context_ref = ContextRef context_ref =
MakeRef(broker(), Handle<Context>::cast(x.context)); MakeRef(broker(), Handle<Context>::cast(x.context));
size_t remaining_depth = depth - x.distance; size_t remaining_depth = depth - x.distance;
context_ref = context_ref.previous( context_ref = context_ref.previous(&remaining_depth);
&remaining_depth, SerializationPolicy::kSerializeIfNeeded);
if (remaining_depth == 0 && mode != kIgnoreSlot) { if (remaining_depth == 0 && mode != kIgnoreSlot) {
ProcessImmutableLoad(context_ref, slot, mode, result_hints); ProcessImmutableLoad(context_ref, slot, mode, result_hints);
} }
...@@ -1994,10 +1989,7 @@ void SerializerForBackgroundCompilation::VisitCallJSRuntime( ...@@ -1994,10 +1989,7 @@ void SerializerForBackgroundCompilation::VisitCallJSRuntime(
BytecodeArrayIterator* iterator) { BytecodeArrayIterator* iterator) {
const int runtime_index = iterator->GetNativeContextIndexOperand(0); const int runtime_index = iterator->GetNativeContextIndexOperand(0);
ObjectRef constant = ObjectRef constant =
broker() broker()->target_native_context().get(runtime_index).value();
->target_native_context()
.get(runtime_index, SerializationPolicy::kSerializeIfNeeded)
.value();
Hints const callee = Hints::SingleConstant(constant.object(), zone()); Hints const callee = Hints::SingleConstant(constant.object(), zone());
interpreter::Register first_reg = iterator->GetRegisterOperand(1); interpreter::Register first_reg = iterator->GetRegisterOperand(1);
int reg_count = static_cast<int>(iterator->GetRegisterCountOperand(2)); int reg_count = static_cast<int>(iterator->GetRegisterCountOperand(2));
......
...@@ -694,7 +694,7 @@ class NativeContext : public Context { ...@@ -694,7 +694,7 @@ class NativeContext : public Context {
// initialization. This function should *not* be used from anywhere other // initialization. This function should *not* be used from anywhere other
// than heap-refs.cc. // than heap-refs.cc.
// TODO(jgruber): Remove this function after NativeContextRef is actually // TODO(jgruber): Remove this function after NativeContextRef is actually
// never serialized and BROKER_COMPULSORY_NATIVE_CONTEXT_FIELDS is removed. // never serialized and BROKER_NATIVE_CONTEXT_FIELDS is removed.
JSGlobalObject global_object() { return Context::global_object(); } JSGlobalObject global_object() { return Context::global_object(); }
JSGlobalObject global_object(AcquireLoadTag) { JSGlobalObject global_object(AcquireLoadTag) {
return Context::global_object(); return Context::global_object();
......
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