Commit fc6425c5 authored by marja's avatar marja Committed by Commit bot

Include only stuff you need, part 5: make function-tester.h slimmer.

Rebuilding (after touching certain files) is crazy slow because
includes are out of control. Many of these files we need to rebuild are
cctests which pull in more includes than they need.

BUG=v8:5294

Review-Url: https://codereview.chromium.org/2278103002
Cr-Commit-Position: refs/heads/master@{#38933}
parent 76f740b2
......@@ -37,6 +37,7 @@
'compiler/codegen-tester.cc',
'compiler/codegen-tester.h',
'compiler/code-assembler-tester.h',
'compiler/function-tester.cc',
'compiler/function-tester.h',
'compiler/graph-builder-tester.h',
'compiler/test-basic-block-profiler.cc',
......
// Copyright 2014 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/function-tester.h"
#include "src/ast/ast-numbering.h"
#include "src/compiler.h"
#include "src/compiler/linkage.h"
#include "src/compiler/pipeline.h"
#include "src/execution.h"
#include "src/full-codegen/full-codegen.h"
#include "src/handles.h"
#include "src/objects-inl.h"
#include "src/parsing/parse-info.h"
#include "src/parsing/parser.h"
#include "test/cctest/cctest.h"
namespace v8 {
namespace internal {
namespace compiler {
FunctionTester::FunctionTester(const char* source, uint32_t flags)
: isolate(main_isolate()),
function((FLAG_allow_natives_syntax = true, NewFunction(source))),
flags_(flags) {
Compile(function);
const uint32_t supported_flags = CompilationInfo::kNativeContextSpecializing |
CompilationInfo::kInliningEnabled;
CHECK_EQ(0u, flags_ & ~supported_flags);
}
FunctionTester::FunctionTester(Graph* graph, int param_count)
: isolate(main_isolate()),
function(NewFunction(BuildFunction(param_count).c_str())),
flags_(0) {
CompileGraph(graph);
}
FunctionTester::FunctionTester(Handle<Code> code, int param_count)
: isolate(main_isolate()),
function((FLAG_allow_natives_syntax = true,
NewFunction(BuildFunction(param_count).c_str()))),
flags_(0) {
Compile(function);
function->ReplaceCode(*code);
}
FunctionTester::FunctionTester(const CallInterfaceDescriptor& descriptor,
Handle<Code> code)
: FunctionTester(code, descriptor.GetParameterCount()) {}
MaybeHandle<Object> FunctionTester::Call() {
return Execution::Call(isolate, function, undefined(), 0, nullptr);
}
MaybeHandle<Object> FunctionTester::Call(Handle<Object> a) {
Handle<Object> args[] = {a};
return Execution::Call(isolate, function, undefined(), 1, args);
}
MaybeHandle<Object> FunctionTester::Call(Handle<Object> a, Handle<Object> b) {
Handle<Object> args[] = {a, b};
return Execution::Call(isolate, function, undefined(), 2, args);
}
MaybeHandle<Object> FunctionTester::Call(Handle<Object> a, Handle<Object> b,
Handle<Object> c) {
Handle<Object> args[] = {a, b, c};
return Execution::Call(isolate, function, undefined(), 3, args);
}
MaybeHandle<Object> FunctionTester::Call(Handle<Object> a, Handle<Object> b,
Handle<Object> c, Handle<Object> d) {
Handle<Object> args[] = {a, b, c, d};
return Execution::Call(isolate, function, undefined(), 4, args);
}
void FunctionTester::CheckThrows(Handle<Object> a, Handle<Object> b) {
TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate));
MaybeHandle<Object> no_result = Call(a, b);
CHECK(isolate->has_pending_exception());
CHECK(try_catch.HasCaught());
CHECK(no_result.is_null());
isolate->OptionalRescheduleException(true);
}
v8::Local<v8::Message> FunctionTester::CheckThrowsReturnMessage(
Handle<Object> a, Handle<Object> b) {
TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate));
MaybeHandle<Object> no_result = Call(a, b);
CHECK(isolate->has_pending_exception());
CHECK(try_catch.HasCaught());
CHECK(no_result.is_null());
isolate->OptionalRescheduleException(true);
CHECK(!try_catch.Message().IsEmpty());
return try_catch.Message();
}
Handle<String> FunctionTester::Val(const char* string) {
return isolate->factory()->InternalizeUtf8String(string);
}
Handle<Object> FunctionTester::Val(double value) {
return isolate->factory()->NewNumber(value);
}
Handle<Object> FunctionTester::infinity() {
return isolate->factory()->infinity_value();
}
Handle<Object> FunctionTester::minus_infinity() { return Val(-V8_INFINITY); }
Handle<Object> FunctionTester::nan() { return isolate->factory()->nan_value(); }
Handle<Object> FunctionTester::undefined() {
return isolate->factory()->undefined_value();
}
Handle<Object> FunctionTester::null() {
return isolate->factory()->null_value();
}
Handle<Object> FunctionTester::true_value() {
return isolate->factory()->true_value();
}
Handle<Object> FunctionTester::false_value() {
return isolate->factory()->false_value();
}
Handle<JSFunction> FunctionTester::Compile(Handle<JSFunction> function) {
Zone zone(function->GetIsolate()->allocator());
ParseInfo parse_info(&zone, function);
CompilationInfo info(&parse_info, function);
info.MarkAsDeoptimizationEnabled();
if (!FLAG_turbo_from_bytecode) {
CHECK(Parser::ParseStatic(info.parse_info()));
}
info.SetOptimizing();
if (flags_ & CompilationInfo::kNativeContextSpecializing) {
info.MarkAsNativeContextSpecializing();
}
if (flags_ & CompilationInfo::kInliningEnabled) {
info.MarkAsInliningEnabled();
}
if (FLAG_turbo_from_bytecode) {
CHECK(Compiler::EnsureBytecode(&info));
info.MarkAsOptimizeFromBytecode();
} else {
CHECK(Compiler::Analyze(info.parse_info()));
CHECK(Compiler::EnsureDeoptimizationSupport(&info));
}
JSFunction::EnsureLiterals(function);
Handle<Code> code = Pipeline::GenerateCodeForTesting(&info);
CHECK(!code.is_null());
info.dependencies()->Commit(code);
info.context()->native_context()->AddOptimizedCode(*code);
function->ReplaceCode(*code);
return function;
}
// Compile the given machine graph instead of the source of the function
// and replace the JSFunction's code with the result.
Handle<JSFunction> FunctionTester::CompileGraph(Graph* graph) {
Zone zone(function->GetIsolate()->allocator());
ParseInfo parse_info(&zone, function);
CompilationInfo info(&parse_info, function);
CHECK(Parser::ParseStatic(info.parse_info()));
info.SetOptimizing();
Handle<Code> code = Pipeline::GenerateCodeForTesting(&info, graph);
CHECK(!code.is_null());
function->ReplaceCode(*code);
return function;
}
} // namespace compiler
} // namespace internal
} // namespace v8
......@@ -5,105 +5,43 @@
#ifndef V8_CCTEST_COMPILER_FUNCTION_TESTER_H_
#define V8_CCTEST_COMPILER_FUNCTION_TESTER_H_
#include "src/ast/ast-numbering.h"
#include "src/compiler.h"
#include "src/compiler/linkage.h"
#include "src/compiler/pipeline.h"
#include "src/execution.h"
#include "src/full-codegen/full-codegen.h"
#include "src/handles.h"
#include "src/objects-inl.h"
#include "src/parsing/parse-info.h"
#include "src/parsing/parser.h"
#include "src/parsing/rewriter.h"
#include "test/cctest/cctest.h"
namespace v8 {
namespace internal {
class CallInterfaceDescriptor;
class Isolate;
namespace compiler {
class Graph;
class FunctionTester : public InitializedHandleScope {
public:
explicit FunctionTester(const char* source, uint32_t flags = 0)
: isolate(main_isolate()),
function((FLAG_allow_natives_syntax = true, NewFunction(source))),
flags_(flags) {
Compile(function);
const uint32_t supported_flags =
CompilationInfo::kNativeContextSpecializing |
CompilationInfo::kInliningEnabled;
CHECK_EQ(0u, flags_ & ~supported_flags);
}
explicit FunctionTester(const char* source, uint32_t flags = 0);
FunctionTester(Graph* graph, int param_count)
: isolate(main_isolate()),
function(NewFunction(BuildFunction(param_count).c_str())),
flags_(0) {
CompileGraph(graph);
}
FunctionTester(Graph* graph, int param_count);
FunctionTester(Handle<Code> code, int param_count)
: isolate(main_isolate()),
function((FLAG_allow_natives_syntax = true,
NewFunction(BuildFunction(param_count).c_str()))),
flags_(0) {
Compile(function);
function->ReplaceCode(*code);
}
FunctionTester(Handle<Code> code, int param_count);
FunctionTester(const CallInterfaceDescriptor& descriptor, Handle<Code> code)
: FunctionTester(code, descriptor.GetParameterCount()) {}
FunctionTester(const CallInterfaceDescriptor& descriptor, Handle<Code> code);
Isolate* isolate;
Handle<JSFunction> function;
MaybeHandle<Object> Call() {
return Execution::Call(isolate, function, undefined(), 0, nullptr);
}
MaybeHandle<Object> Call(Handle<Object> a) {
Handle<Object> args[] = {a};
return Execution::Call(isolate, function, undefined(), 1, args);
}
MaybeHandle<Object> Call(Handle<Object> a, Handle<Object> b) {
Handle<Object> args[] = {a, b};
return Execution::Call(isolate, function, undefined(), 2, args);
}
MaybeHandle<Object> Call();
MaybeHandle<Object> Call(Handle<Object> a);
MaybeHandle<Object> Call(Handle<Object> a, Handle<Object> b);
MaybeHandle<Object> Call(Handle<Object> a, Handle<Object> b,
Handle<Object> c) {
Handle<Object> args[] = {a, b, c};
return Execution::Call(isolate, function, undefined(), 3, args);
}
Handle<Object> c);
MaybeHandle<Object> Call(Handle<Object> a, Handle<Object> b, Handle<Object> c,
Handle<Object> d) {
Handle<Object> args[] = {a, b, c, d};
return Execution::Call(isolate, function, undefined(), 4, args);
}
void CheckThrows(Handle<Object> a, Handle<Object> b) {
TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate));
MaybeHandle<Object> no_result = Call(a, b);
CHECK(isolate->has_pending_exception());
CHECK(try_catch.HasCaught());
CHECK(no_result.is_null());
isolate->OptionalRescheduleException(true);
}
Handle<Object> d);
void CheckThrows(Handle<Object> a, Handle<Object> b);
v8::Local<v8::Message> CheckThrowsReturnMessage(Handle<Object> a,
Handle<Object> b) {
TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate));
MaybeHandle<Object> no_result = Call(a, b);
CHECK(isolate->has_pending_exception());
CHECK(try_catch.HasCaught());
CHECK(no_result.is_null());
isolate->OptionalRescheduleException(true);
CHECK(!try_catch.Message().IsEmpty());
return try_catch.Message();
}
Handle<Object> b);
void CheckCall(Handle<Object> expected, Handle<Object> a, Handle<Object> b,
Handle<Object> c, Handle<Object> d) {
Handle<Object> result = Call(a, b, c, d).ToHandleChecked();
......@@ -168,27 +106,15 @@ class FunctionTester : public InitializedHandleScope {
*v8::Local<v8::Object>::Cast(CompileRun(source))));
}
Handle<String> Val(const char* string) {
return isolate->factory()->InternalizeUtf8String(string);
}
Handle<Object> Val(double value) {
return isolate->factory()->NewNumber(value);
}
Handle<Object> infinity() { return isolate->factory()->infinity_value(); }
Handle<Object> minus_infinity() { return Val(-V8_INFINITY); }
Handle<Object> nan() { return isolate->factory()->nan_value(); }
Handle<Object> undefined() { return isolate->factory()->undefined_value(); }
Handle<Object> null() { return isolate->factory()->null_value(); }
Handle<Object> true_value() { return isolate->factory()->true_value(); }
Handle<Object> false_value() { return isolate->factory()->false_value(); }
Handle<String> Val(const char* string);
Handle<Object> Val(double value);
Handle<Object> infinity();
Handle<Object> minus_infinity();
Handle<Object> nan();
Handle<Object> undefined();
Handle<Object> null();
Handle<Object> true_value();
Handle<Object> false_value();
static Handle<JSFunction> ForMachineGraph(Graph* graph, int param_count) {
JSFunction* p = NULL;
......@@ -202,39 +128,7 @@ class FunctionTester : public InitializedHandleScope {
private:
uint32_t flags_;
Handle<JSFunction> Compile(Handle<JSFunction> function) {
Zone zone(function->GetIsolate()->allocator());
ParseInfo parse_info(&zone, function);
CompilationInfo info(&parse_info, function);
info.MarkAsDeoptimizationEnabled();
if (!FLAG_turbo_from_bytecode) {
CHECK(Parser::ParseStatic(info.parse_info()));
}
info.SetOptimizing();
if (flags_ & CompilationInfo::kNativeContextSpecializing) {
info.MarkAsNativeContextSpecializing();
}
if (flags_ & CompilationInfo::kInliningEnabled) {
info.MarkAsInliningEnabled();
}
if (FLAG_turbo_from_bytecode) {
CHECK(Compiler::EnsureBytecode(&info));
info.MarkAsOptimizeFromBytecode();
} else {
CHECK(Compiler::Analyze(info.parse_info()));
CHECK(Compiler::EnsureDeoptimizationSupport(&info));
}
JSFunction::EnsureLiterals(function);
Handle<Code> code = Pipeline::GenerateCodeForTesting(&info);
CHECK(!code.is_null());
info.dependencies()->Commit(code);
info.context()->native_context()->AddOptimizedCode(*code);
function->ReplaceCode(*code);
return function;
}
Handle<JSFunction> Compile(Handle<JSFunction> function);
std::string BuildFunction(int param_count) {
std::string function_string = "(function(";
if (param_count > 0) {
......@@ -250,19 +144,7 @@ class FunctionTester : public InitializedHandleScope {
// Compile the given machine graph instead of the source of the function
// and replace the JSFunction's code with the result.
Handle<JSFunction> CompileGraph(Graph* graph) {
Zone zone(function->GetIsolate()->allocator());
ParseInfo parse_info(&zone, function);
CompilationInfo info(&parse_info, function);
CHECK(Parser::ParseStatic(info.parse_info()));
info.SetOptimizing();
Handle<Code> code = Pipeline::GenerateCodeForTesting(&info, graph);
CHECK(!code.is_null());
function->ReplaceCode(*code);
return function;
}
Handle<JSFunction> CompileGraph(Graph* graph);
};
} // namespace compiler
} // namespace internal
......
......@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/code-factory.h"
#include "src/compiler/code-assembler.h"
#include "src/isolate.h"
#include "test/cctest/compiler/code-assembler-tester.h"
......
......@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/compiler.h"
#include "src/frames-inl.h"
#include "test/cctest/compiler/function-tester.h"
......
......@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/compiler.h"
#include "test/cctest/compiler/function-tester.h"
namespace v8 {
......
......@@ -4,6 +4,7 @@
#include "src/bootstrapper.h"
#include "src/code-stubs.h"
#include "src/compiler.h"
#include "src/compiler/common-operator.h"
#include "src/compiler/graph.h"
#include "src/compiler/js-graph.h"
......
......@@ -3,6 +3,9 @@
// found in the LICENSE file.
#include "src/base/utils/random-number-generator.h"
#include "src/code-factory.h"
#include "src/code-stub-assembler.h"
#include "src/compiler/node.h"
#include "src/ic/stub-cache.h"
#include "src/isolate.h"
#include "test/cctest/compiler/code-assembler-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