Commit acb60162 authored by Maya Lekova's avatar Maya Lekova Committed by Commit Bot

[test] Add testing facility for SerializerForBackgroundCompilation

R=neis@chromium.org

Bug: v8:7790
Change-Id: Id759112d0c780ff857eb094102245b38fcbb1709
Reviewed-on: https://chromium-review.googlesource.com/c/1434375Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Commit-Queue: Maya Lekova <mslekova@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59153}
parent eb18edb4
......@@ -535,7 +535,7 @@ class PipelineImpl final {
std::unique_ptr<AssemblerBuffer> buffer = {});
// Step D. Run the code finalization pass.
MaybeHandle<Code> FinalizeCode();
MaybeHandle<Code> FinalizeCode(bool retire_broker = true);
// Step E. Install any code dependencies.
bool CommitDependencies(Handle<Code> code);
......@@ -2292,12 +2292,17 @@ MaybeHandle<Code> Pipeline::GenerateCodeForWasmHeapStub(
// static
MaybeHandle<Code> Pipeline::GenerateCodeForTesting(
OptimizedCompilationInfo* info, Isolate* isolate) {
OptimizedCompilationInfo* info, Isolate* isolate,
JSHeapBroker** out_broker) {
ZoneStats zone_stats(isolate->allocator());
std::unique_ptr<PipelineStatistics> pipeline_statistics(
CreatePipelineStatistics(Handle<Script>::null(), info, isolate,
&zone_stats));
PipelineData data(&zone_stats, isolate, info, pipeline_statistics.get());
if (out_broker != nullptr) {
*out_broker = data.broker();
}
PipelineImpl pipeline(&data);
Linkage linkage(Linkage::ComputeIncoming(data.instruction_zone(), info));
......@@ -2307,7 +2312,7 @@ MaybeHandle<Code> Pipeline::GenerateCodeForTesting(
if (!pipeline.OptimizeGraph(&linkage)) return MaybeHandle<Code>();
pipeline.AssembleCode(&linkage);
Handle<Code> code;
if (pipeline.FinalizeCode().ToHandle(&code) &&
if (pipeline.FinalizeCode(out_broker == nullptr).ToHandle(&code) &&
pipeline.CommitDependencies(code)) {
return code;
}
......@@ -2706,9 +2711,9 @@ std::ostream& operator<<(std::ostream& out, const BlockStartsAsJSON& s) {
return out;
}
MaybeHandle<Code> PipelineImpl::FinalizeCode() {
MaybeHandle<Code> PipelineImpl::FinalizeCode(bool retire_broker) {
PipelineData* data = this->data_;
if (data->broker()) {
if (data->broker() && retire_broker) {
data->broker()->Retire();
}
Run<FinalizeCodePhase>();
......
......@@ -32,6 +32,7 @@ namespace compiler {
class CallDescriptor;
class Graph;
class InstructionSequence;
class JSHeapBroker;
class MachineGraph;
class NodeOriginTable;
class Schedule;
......@@ -80,8 +81,11 @@ class Pipeline : public AllStatic {
// ---------------------------------------------------------------------------
// Run the pipeline on JavaScript bytecode and generate code.
// If requested, hands out the heap broker, which is allocated
// in {info}'s zone.
static MaybeHandle<Code> GenerateCodeForTesting(
OptimizedCompilationInfo* info, Isolate* isolate);
OptimizedCompilationInfo* info, Isolate* isolate,
JSHeapBroker** out_broker = nullptr);
// Run the pipeline on a machine graph and generate code. If {schedule} is
// {nullptr}, then compute a new schedule for code generation.
......
......@@ -64,6 +64,8 @@ v8_source_set("cctest_sources") {
"compiler/function-tester.cc",
"compiler/function-tester.h",
"compiler/graph-builder-tester.h",
"compiler/serializer-tester.cc",
"compiler/serializer-tester.h",
"compiler/test-basic-block-profiler.cc",
"compiler/test-branch-combine.cc",
"compiler/test-code-assembler.cc",
......
......@@ -29,8 +29,11 @@
#include "test/cctest/cctest.h"
#include "include/libplatform/libplatform.h"
#include "src/compiler.h"
#include "src/compiler/pipeline.h"
#include "src/debug/debug.h"
#include "src/objects-inl.h"
#include "src/optimized-compilation-info.h"
#include "src/trap-handler/trap-handler.h"
#include "test/cctest/print-extension.h"
#include "test/cctest/profiler-extension.h"
......@@ -222,6 +225,36 @@ HandleAndZoneScope::HandleAndZoneScope()
HandleAndZoneScope::~HandleAndZoneScope() = default;
i::Handle<i::JSFunction> Optimize(i::Handle<i::JSFunction> function,
i::Zone* zone, i::Isolate* isolate,
uint32_t flags,
i::compiler::JSHeapBroker** out_broker) {
i::Handle<i::SharedFunctionInfo> shared(function->shared(), isolate);
i::IsCompiledScope is_compiled_scope(shared->is_compiled_scope());
CHECK(is_compiled_scope.is_compiled() ||
i::Compiler::Compile(function, i::Compiler::CLEAR_EXCEPTION,
&is_compiled_scope));
CHECK_NOT_NULL(zone);
i::OptimizedCompilationInfo info(zone, isolate, shared, function);
if (flags & i::OptimizedCompilationInfo::kInliningEnabled) {
info.MarkAsInliningEnabled();
}
CHECK(info.shared_info()->HasBytecodeArray());
i::JSFunction::EnsureFeedbackVector(function);
i::Handle<i::Code> code =
i::compiler::Pipeline::GenerateCodeForTesting(&info, isolate, out_broker)
.ToHandleChecked();
info.native_context()->AddOptimizedCode(*code);
function->set_code(*code);
return function;
}
static void PrintTestList(CcTest* current) {
if (current == nullptr) return;
PrintTestList(current->prev());
......
......@@ -56,6 +56,12 @@ const auto GetRegConfig = RegisterConfiguration::Default;
class HandleScope;
class Zone;
namespace compiler {
class JSHeapBroker;
} // namespace compiler
} // namespace internal
} // namespace v8
......@@ -487,7 +493,13 @@ static inline v8::Local<v8::Value> CompileRunWithOrigin(
return CompileRunWithOrigin(v8_str(source), origin_url);
}
// Takes a JSFunction and runs it through the test version of the optimizing
// pipeline, allocating the temporary compilation artifacts in a given Zone.
// For possible {flags} values, look at OptimizedCompilationInfo::Flag.
// If passed a non-null pointer for {broker}, outputs the JSHeapBroker to it.
i::Handle<i::JSFunction> Optimize(
i::Handle<i::JSFunction> function, i::Zone* zone, i::Isolate* isolate,
uint32_t flags, i::compiler::JSHeapBroker** out_broker = nullptr);
static inline void ExpectString(const char* code, const char* expected) {
v8::Local<v8::Value> result = CompileRun(code);
......
......@@ -6,7 +6,6 @@
#include "src/api-inl.h"
#include "src/assembler.h"
#include "src/compiler.h"
#include "src/compiler/linkage.h"
#include "src/compiler/pipeline.h"
#include "src/execution.h"
......@@ -142,27 +141,8 @@ Handle<JSFunction> FunctionTester::ForMachineGraph(Graph* graph,
}
Handle<JSFunction> FunctionTester::Compile(Handle<JSFunction> function) {
Handle<SharedFunctionInfo> shared(function->shared(), isolate);
IsCompiledScope is_compiled_scope(shared->is_compiled_scope());
CHECK(is_compiled_scope.is_compiled() ||
Compiler::Compile(function, Compiler::CLEAR_EXCEPTION,
&is_compiled_scope));
Zone zone(isolate->allocator(), ZONE_NAME);
OptimizedCompilationInfo info(&zone, isolate, shared, function);
if (flags_ & OptimizedCompilationInfo::kInliningEnabled) {
info.MarkAsInliningEnabled();
}
CHECK(info.shared_info()->HasBytecodeArray());
JSFunction::EnsureFeedbackVector(function);
Handle<Code> code =
Pipeline::GenerateCodeForTesting(&info, isolate).ToHandleChecked();
info.native_context()->AddOptimizedCode(*code);
function->set_code(*code);
return function;
return Optimize(function, &zone, isolate, flags_);
}
// Compile the given machine graph instead of the source of the function
......
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "test/cctest/compiler/serializer-tester.h"
#include "src/api-inl.h"
#include "src/compiler/serializer-for-background-compilation.h"
#include "src/compiler/zone-stats.h"
#include "src/zone/zone.h"
namespace v8 {
namespace internal {
namespace compiler {
SerializerTester::SerializerTester(const char* source)
: canonical_(main_isolate()) {
FLAG_concurrent_inlining = true;
Handle<JSFunction> function = Handle<JSFunction>::cast(v8::Utils::OpenHandle(
*v8::Local<v8::Function>::Cast(CompileRun(source))));
Optimize(function, main_zone(), main_isolate(), 0, &broker_);
function_ = JSFunctionRef(broker_, function);
}
TEST(SerializeEmptyFunction) {
SerializerTester tester("(function() { function f() {}; return f; })();");
CHECK(tester.function().shared().IsSerializedForCompilation(
tester.function().feedback_vector()));
}
} // namespace compiler
} // namespace internal
} // namespace v8
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_CCTEST_COMPILER_SERIALIZER_TESTER_H_
#define V8_CCTEST_COMPILER_SERIALIZER_TESTER_H_
#include "src/compiler/js-heap-broker.h"
#include "test/cctest/cctest.h"
namespace v8 {
namespace internal {
namespace compiler {
class ZoneStats;
class SerializerTester : public HandleAndZoneScope {
public:
explicit SerializerTester(const char* source);
JSFunctionRef function() const { return function_.value(); }
private:
CanonicalHandleScope canonical_;
base::Optional<JSFunctionRef> function_;
JSHeapBroker* broker_ = nullptr;
};
} // namespace compiler
} // namespace internal
} // namespace v8
#endif // V8_CCTEST_COMPILER_SERIALIZER_TESTER_H_
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