2016-08-26 08:41:20 +00:00
|
|
|
// 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"
|
2016-08-31 08:49:14 +00:00
|
|
|
#include "src/compilation-info.h"
|
2016-08-26 08:41:20 +00:00
|
|
|
#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"
|
2016-11-30 13:21:11 +00:00
|
|
|
#include "src/parsing/parsing.h"
|
2016-08-26 08:41:20 +00:00
|
|
|
#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);
|
2016-10-10 05:53:31 +00:00
|
|
|
const uint32_t supported_flags = CompilationInfo::kInliningEnabled;
|
2016-08-26 08:41:20 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-11-16 11:48:07 +00:00
|
|
|
FunctionTester::FunctionTester(Handle<Code> code) : FunctionTester(code, 0) {}
|
2016-08-26 08:41:20 +00:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2016-09-01 12:01:33 +00:00
|
|
|
void FunctionTester::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();
|
|
|
|
CHECK(expected->SameValue(*result));
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<JSFunction> FunctionTester::NewFunction(const char* source) {
|
|
|
|
return Handle<JSFunction>::cast(v8::Utils::OpenHandle(
|
|
|
|
*v8::Local<v8::Function>::Cast(CompileRun(source))));
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<JSObject> FunctionTester::NewObject(const char* source) {
|
|
|
|
return Handle<JSObject>::cast(
|
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Object>::Cast(CompileRun(source))));
|
|
|
|
}
|
|
|
|
|
2016-08-26 08:41:20 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2016-09-01 12:01:33 +00:00
|
|
|
Handle<JSFunction> FunctionTester::ForMachineGraph(Graph* graph,
|
|
|
|
int param_count) {
|
|
|
|
JSFunction* p = NULL;
|
|
|
|
{ // because of the implicit handle scope of FunctionTester.
|
|
|
|
FunctionTester f(graph, param_count);
|
|
|
|
p = *f.function;
|
|
|
|
}
|
|
|
|
return Handle<JSFunction>(p); // allocated in outer handle scope.
|
|
|
|
}
|
|
|
|
|
2016-08-26 08:41:20 +00:00
|
|
|
Handle<JSFunction> FunctionTester::Compile(Handle<JSFunction> function) {
|
Reland of land: [Parse] ParseInfo owns the parsing Zone. (patchset #1 id:1 of https://codereview.chromium.org/2683733002/ )
Reason for revert:
False alarm, bot hiccup
Original issue's description:
> Revert of Reland: [Parse] ParseInfo owns the parsing Zone. (patchset #7 id:140001 of https://codereview.chromium.org/2632123006/ )
>
> Reason for revert:
> Speculative revert because of revert needed for https://codereview.chromium.org/2632123006
>
> Original issue's description:
> > Reland: [Parse] ParseInfo owns the parsing Zone.
> >
> > Moves ownership of the parsing Zone to ParseInfo with a shared_ptr. This is
> > in preperation for enabling background compilation jobs for inner functions
> > share the AST in the outer-function's parse zone memory (read-only), with the
> > and zone being released when all compilation jobs have completed.
> >
> > BUG=v8:5203,v8:5215
> >
> > Review-Url: https://codereview.chromium.org/2632123006
> > Cr-Original-Commit-Position: refs/heads/master@{#42993}
> > Committed: https://chromium.googlesource.com/v8/v8/+/14fb337200d5da09c77438ddd40bea935b1dc823
> > Review-Url: https://codereview.chromium.org/2632123006
> > Cr-Commit-Position: refs/heads/master@{#42996}
> > Committed: https://chromium.googlesource.com/v8/v8/+/9e7d5a6065470ca03411d4c8dbc61d1be5c3f84a
>
> TBR=marja@chromium.org,mstarzinger@chromium.org,ahaas@chromium.org,verwaest@chromium.org,rmcilroy@chromium.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=v8:5203,v8:5215
>
> Review-Url: https://codereview.chromium.org/2683733002
> Cr-Commit-Position: refs/heads/master@{#43008}
> Committed: https://chromium.googlesource.com/v8/v8/+/9fe08ec067051c5b46e694568bd01c6dba44cc4d
TBR=marja@chromium.org,mstarzinger@chromium.org,ahaas@chromium.org,verwaest@chromium.org,rmcilroy@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=v8:5203,v8:5215
Review-Url: https://codereview.chromium.org/2679303003
Cr-Commit-Position: refs/heads/master@{#43015}
2017-02-07 20:46:47 +00:00
|
|
|
ParseInfo parse_info(handle(function->shared()));
|
2017-02-10 09:55:22 +00:00
|
|
|
CompilationInfo info(parse_info.zone(), &parse_info, function);
|
2016-08-26 08:41:20 +00:00
|
|
|
|
|
|
|
info.SetOptimizing();
|
2016-10-06 15:11:23 +00:00
|
|
|
info.MarkAsDeoptimizationEnabled();
|
2016-08-26 08:41:20 +00:00
|
|
|
if (flags_ & CompilationInfo::kInliningEnabled) {
|
|
|
|
info.MarkAsInliningEnabled();
|
|
|
|
}
|
2016-11-23 09:30:11 +00:00
|
|
|
|
|
|
|
CHECK(Compiler::Compile(function, Compiler::CLEAR_EXCEPTION));
|
|
|
|
if (info.shared_info()->HasBytecodeArray()) {
|
2016-08-26 08:41:20 +00:00
|
|
|
info.MarkAsOptimizeFromBytecode();
|
|
|
|
} else {
|
2016-10-06 15:11:23 +00:00
|
|
|
CHECK(Compiler::ParseAndAnalyze(info.parse_info()));
|
2016-08-26 08:41:20 +00:00
|
|
|
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) {
|
Reland of land: [Parse] ParseInfo owns the parsing Zone. (patchset #1 id:1 of https://codereview.chromium.org/2683733002/ )
Reason for revert:
False alarm, bot hiccup
Original issue's description:
> Revert of Reland: [Parse] ParseInfo owns the parsing Zone. (patchset #7 id:140001 of https://codereview.chromium.org/2632123006/ )
>
> Reason for revert:
> Speculative revert because of revert needed for https://codereview.chromium.org/2632123006
>
> Original issue's description:
> > Reland: [Parse] ParseInfo owns the parsing Zone.
> >
> > Moves ownership of the parsing Zone to ParseInfo with a shared_ptr. This is
> > in preperation for enabling background compilation jobs for inner functions
> > share the AST in the outer-function's parse zone memory (read-only), with the
> > and zone being released when all compilation jobs have completed.
> >
> > BUG=v8:5203,v8:5215
> >
> > Review-Url: https://codereview.chromium.org/2632123006
> > Cr-Original-Commit-Position: refs/heads/master@{#42993}
> > Committed: https://chromium.googlesource.com/v8/v8/+/14fb337200d5da09c77438ddd40bea935b1dc823
> > Review-Url: https://codereview.chromium.org/2632123006
> > Cr-Commit-Position: refs/heads/master@{#42996}
> > Committed: https://chromium.googlesource.com/v8/v8/+/9e7d5a6065470ca03411d4c8dbc61d1be5c3f84a
>
> TBR=marja@chromium.org,mstarzinger@chromium.org,ahaas@chromium.org,verwaest@chromium.org,rmcilroy@chromium.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=v8:5203,v8:5215
>
> Review-Url: https://codereview.chromium.org/2683733002
> Cr-Commit-Position: refs/heads/master@{#43008}
> Committed: https://chromium.googlesource.com/v8/v8/+/9fe08ec067051c5b46e694568bd01c6dba44cc4d
TBR=marja@chromium.org,mstarzinger@chromium.org,ahaas@chromium.org,verwaest@chromium.org,rmcilroy@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=v8:5203,v8:5215
Review-Url: https://codereview.chromium.org/2679303003
Cr-Commit-Position: refs/heads/master@{#43015}
2017-02-07 20:46:47 +00:00
|
|
|
ParseInfo parse_info(handle(function->shared()));
|
2017-02-10 09:55:22 +00:00
|
|
|
CompilationInfo info(parse_info.zone(), &parse_info, function);
|
2016-08-26 08:41:20 +00:00
|
|
|
|
2016-11-30 13:21:11 +00:00
|
|
|
CHECK(parsing::ParseFunction(info.parse_info()));
|
2016-08-26 08:41:20 +00:00
|
|
|
info.SetOptimizing();
|
|
|
|
|
|
|
|
Handle<Code> code = Pipeline::GenerateCodeForTesting(&info, graph);
|
|
|
|
CHECK(!code.is_null());
|
|
|
|
function->ReplaceCode(*code);
|
|
|
|
return function;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|