From 27df753f458ff98310d146212ce1d6cde4d9341d Mon Sep 17 00:00:00 2001 From: Maya Lekova Date: Thu, 12 Sep 2019 13:49:26 +0200 Subject: [PATCH] [turbofan] Brokerize JSContextSpecialization Bug: v8:7790 Change-Id: Ief620bc24b59c2a4e0c823a7f7cebf5df114b9a6 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1787430 Commit-Queue: Maya Lekova Reviewed-by: Georg Neis Reviewed-by: Michael Stanton Cr-Commit-Position: refs/heads/master@{#63714} --- src/compiler/js-context-specialization.cc | 2 +- src/compiler/pipeline.cc | 68 +++++++++++-------- .../serializer-for-background-compilation.cc | 1 + 3 files changed, 41 insertions(+), 30 deletions(-) diff --git a/src/compiler/js-context-specialization.cc b/src/compiler/js-context-specialization.cc index 035e8b7ceb..409fc6c9a1 100644 --- a/src/compiler/js-context-specialization.cc +++ b/src/compiler/js-context-specialization.cc @@ -38,7 +38,7 @@ Reduction JSContextSpecialization::ReduceParameter(Node* node) { // Constant-fold the function parameter {node}. Handle function; if (closure().ToHandle(&function)) { - Node* value = jsgraph()->HeapConstant(function); + Node* value = jsgraph()->Constant(JSFunctionRef(broker_, function)); return Replace(value); } } diff --git a/src/compiler/pipeline.cc b/src/compiler/pipeline.cc index c5fa7f314e..2321dc98f5 100644 --- a/src/compiler/pipeline.cc +++ b/src/compiler/pipeline.cc @@ -107,6 +107,23 @@ static constexpr char kRegisterAllocationZoneName[] = "register-allocation-zone"; static constexpr char kRegisterAllocatorVerifierZoneName[] = "register-allocator-verifier-zone"; +namespace { + +Maybe GetModuleContext(Handle closure) { + Context current = closure->context(); + size_t distance = 0; + while (!current.IsNativeContext()) { + if (current.IsModuleContext()) { + return Just( + OuterContext(handle(current, current.GetIsolate()), distance)); + } + current = current.previous(); + distance++; + } + return Nothing(); +} + +} // anonymous namespace class PipelineData { public: @@ -338,6 +355,20 @@ class PipelineData { return assembler_options_; } + void ChooseSpecializationContext() { + if (info()->is_function_context_specializing()) { + DCHECK(info()->has_context()); + specialization_context_ = + Just(OuterContext(handle(info()->context(), isolate()), 0)); + } else { + specialization_context_ = GetModuleContext(info()->closure()); + } + } + + Maybe specialization_context() const { + return specialization_context_; + } + size_t* address_of_max_unoptimized_frame_height() { return &max_unoptimized_frame_height_; } @@ -546,6 +577,7 @@ class PipelineData { JumpOptimizationInfo* jump_optimization_info_ = nullptr; AssemblerOptions assembler_options_; + Maybe specialization_context_ = Nothing(); // The maximal combined height of all inlined frames in their unoptimized // state. Calculated during instruction selection, applied during code @@ -999,6 +1031,7 @@ PipelineCompilationJob::Status PipelineCompilationJob::PrepareJobImpl( if (compilation_info()->closure()->raw_feedback_cell().map() == ReadOnlyRoots(isolate).one_closure_cell_map()) { compilation_info()->MarkAsFunctionContextSpecializing(); + data_.ChooseSpecializationContext(); } if (compilation_info()->is_source_positions_enabled()) { @@ -1032,6 +1065,7 @@ PipelineCompilationJob::Status PipelineCompilationJob::ExecuteJobImpl() { TRACE_DISABLED_BY_DEFAULT("v8.compile"), "v8.optimizingCompile.execute", this, TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, "function", compilation_info()->shared_info()->TraceIDRef()); + bool success; if (FLAG_turboprop) { success = pipeline_.OptimizeGraphForMidTier(linkage_); @@ -1239,38 +1273,10 @@ struct GraphBuilderPhase { } }; -namespace { - -Maybe GetModuleContext(Handle closure) { - Context current = closure->context(); - size_t distance = 0; - while (!current.IsNativeContext()) { - if (current.IsModuleContext()) { - return Just( - OuterContext(handle(current, current.GetIsolate()), distance)); - } - current = current.previous(); - distance++; - } - return Nothing(); -} - -Maybe ChooseSpecializationContext( - Isolate* isolate, OptimizedCompilationInfo* info) { - if (info->is_function_context_specializing()) { - DCHECK(info->has_context()); - return Just(OuterContext(handle(info->context(), isolate), 0)); - } - return GetModuleContext(info->closure()); -} - -} // anonymous namespace - struct InliningPhase { static const char* phase_name() { return "V8.TFInlining"; } void Run(PipelineData* data, Zone* temp_zone) { - Isolate* isolate = data->isolate(); OptimizedCompilationInfo* info = data->info(); GraphReducer graph_reducer(temp_zone, data->graph(), &info->tick_counter(), data->jsgraph()->Dead()); @@ -1287,7 +1293,7 @@ struct InliningPhase { data->dependencies()); JSContextSpecialization context_specialization( &graph_reducer, data->jsgraph(), data->broker(), - ChooseSpecializationContext(isolate, data->info()), + data->specialization_context(), data->info()->is_function_context_specializing() ? data->info()->closure() : MaybeHandle()); @@ -1419,6 +1425,10 @@ struct SerializationPhase { RunSerializerForBackgroundCompilation(data->broker(), data->dependencies(), temp_zone, data->info()->closure(), flags, data->info()->osr_offset()); + if (data->specialization_context().IsJust()) { + ContextRef(data->broker(), + data->specialization_context().FromJust().context); + } } }; diff --git a/src/compiler/serializer-for-background-compilation.cc b/src/compiler/serializer-for-background-compilation.cc index a5b4481cd2..8a7625f82b 100644 --- a/src/compiler/serializer-for-background-compilation.cc +++ b/src/compiler/serializer-for-background-compilation.cc @@ -1969,6 +1969,7 @@ void SerializerForBackgroundCompilation::ProcessBuiltinCall( case Builtins::kPromiseResolveTrampoline: // For JSCallReducer::ReducePromiseInternalResolve and // JSNativeContextSpecialization::ReduceJSResolvePromise. + // TODO(mslekova): Check if this condition is redundant. if (arguments.size() >= 1) { Hints const& resolution_hints = arguments.size() >= 2