Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Unified Diff: test/unittests/compiler-dispatcher/compiler-dispatcher-job-unittest.cc

Issue 2251713002: [Compiler] Add compile to CompilerDispatcherJob. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@offheap_compilerdispatcher
Patch Set: Fix comment Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/interpreter/interpreter.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/unittests/compiler-dispatcher/compiler-dispatcher-job-unittest.cc
diff --git a/test/unittests/compiler-dispatcher/compiler-dispatcher-job-unittest.cc b/test/unittests/compiler-dispatcher/compiler-dispatcher-job-unittest.cc
index 922ed2f44ea1ee5fdda5beb02eb4aa4ee3e7ad42..d90c5bda1c623bf6e0547cbf3ad8c8421713f3df 100644
--- a/test/unittests/compiler-dispatcher/compiler-dispatcher-job-unittest.cc
+++ b/test/unittests/compiler-dispatcher/compiler-dispatcher-job-unittest.cc
@@ -52,8 +52,8 @@ Handle<JSFunction> CreateFunction(
}
Handle<Script> script = isolate->factory()->NewScript(source);
Handle<SharedFunctionInfo> shared = isolate->factory()->NewSharedFunctionInfo(
- isolate->factory()->NewStringFromAsciiChecked("f"), MaybeHandle<Code>(),
- false);
+ isolate->factory()->NewStringFromAsciiChecked("f"),
+ isolate->builtins()->CompileLazy(), false);
SharedFunctionInfo::SetScript(shared, script);
shared->set_end_position(source->length());
Handle<JSFunction> function =
@@ -62,6 +62,17 @@ Handle<JSFunction> CreateFunction(
return scope.CloseAndEscape(function);
}
+Handle<Object> RunJS(v8::Isolate* isolate, const char* script) {
+ return Utils::OpenHandle(
+ *v8::Script::Compile(
+ isolate->GetCurrentContext(),
+ v8::String::NewFromUtf8(isolate, script, v8::NewStringType::kNormal)
+ .ToLocalChecked())
+ .ToLocalChecked()
+ ->Run(isolate->GetCurrentContext())
+ .ToLocalChecked());
+}
+
} // namespace
TEST_F(CompilerDispatcherJobTest, Construct) {
@@ -93,7 +104,13 @@ TEST_F(CompilerDispatcherJobTest, StateTransitions) {
job->Parse();
ASSERT_TRUE(job->status() == CompileJobStatus::kParsed);
ASSERT_TRUE(job->FinalizeParsingOnMainThread());
+ ASSERT_TRUE(job->status() == CompileJobStatus::kReadyToAnalyse);
+ ASSERT_TRUE(job->PrepareToCompileOnMainThread());
ASSERT_TRUE(job->status() == CompileJobStatus::kReadyToCompile);
+ job->Compile();
+ ASSERT_TRUE(job->status() == CompileJobStatus::kCompiled);
+ ASSERT_TRUE(job->FinalizeCompilingOnMainThread());
+ ASSERT_TRUE(job->status() == CompileJobStatus::kDone);
job->ResetOnMainThread();
ASSERT_TRUE(job->status() == CompileJobStatus::kInitial);
}
@@ -119,14 +136,7 @@ TEST_F(CompilerDispatcherJobTest, ScopeChain) {
const char script[] =
"function g() { var g = 1; function f(x) { return x * g }; return f; } "
"g();";
- Handle<JSFunction> f = Handle<JSFunction>::cast(Utils::OpenHandle(
- *v8::Script::Compile(isolate()->GetCurrentContext(),
- v8::String::NewFromUtf8(isolate(), script,
- v8::NewStringType::kNormal)
- .ToLocalChecked())
- .ToLocalChecked()
- ->Run(isolate()->GetCurrentContext())
- .ToLocalChecked()));
+ Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script));
std::unique_ptr<CompilerDispatcherJob> job(
new CompilerDispatcherJob(i_isolate(), f, FLAG_stack_size));
@@ -134,7 +144,7 @@ TEST_F(CompilerDispatcherJobTest, ScopeChain) {
job->PrepareToParseOnMainThread();
job->Parse();
ASSERT_TRUE(job->FinalizeParsingOnMainThread());
- ASSERT_TRUE(job->status() == CompileJobStatus::kReadyToCompile);
+ ASSERT_TRUE(job->status() == CompileJobStatus::kReadyToAnalyse);
const AstRawString* var_x =
job->parse_info_->ast_value_factory()->GetOneByteString("x");
@@ -152,5 +162,80 @@ TEST_F(CompilerDispatcherJobTest, ScopeChain) {
ASSERT_TRUE(job->status() == CompileJobStatus::kInitial);
}
+TEST_F(CompilerDispatcherJobTest, CompileAndRun) {
+ const char script[] =
+ "function g() {\n"
+ " f = function(a) {\n"
+ " for (var i = 0; i < 3; i++) { a += 20; }\n"
+ " return a;\n"
+ " }\n"
+ " return f;\n"
+ "}\n"
+ "g();";
+ Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script));
+ std::unique_ptr<CompilerDispatcherJob> job(
+ new CompilerDispatcherJob(i_isolate(), f, FLAG_stack_size));
+
+ job->PrepareToParseOnMainThread();
+ job->Parse();
+ job->FinalizeParsingOnMainThread();
+ job->PrepareToCompileOnMainThread();
+ job->Compile();
+ ASSERT_TRUE(job->FinalizeCompilingOnMainThread());
+ ASSERT_TRUE(job->status() == CompileJobStatus::kDone);
+
+ Smi* value = Smi::cast(*RunJS(isolate(), "f(100);"));
+ ASSERT_TRUE(value == Smi::FromInt(160));
+
+ job->ResetOnMainThread();
+ ASSERT_TRUE(job->status() == CompileJobStatus::kInitial);
+}
+
+TEST_F(CompilerDispatcherJobTest, CompileFailureToPrepare) {
+ std::string raw_script("() { var a = ");
+ for (int i = 0; i < 100000; i++) {
+ raw_script += "'x' + ";
+ }
+ raw_script += " 'x'; }";
+ ScriptResource script(raw_script.c_str(), strlen(raw_script.c_str()));
+ std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob(
+ i_isolate(), CreateFunction(i_isolate(), &script), 100));
+
+ job->PrepareToParseOnMainThread();
+ job->Parse();
+ job->FinalizeParsingOnMainThread();
+ ASSERT_FALSE(job->PrepareToCompileOnMainThread());
+ ASSERT_TRUE(job->status() == CompileJobStatus::kFailed);
+ ASSERT_TRUE(i_isolate()->has_pending_exception());
+
+ i_isolate()->clear_pending_exception();
+ job->ResetOnMainThread();
+ ASSERT_TRUE(job->status() == CompileJobStatus::kInitial);
+}
+
+TEST_F(CompilerDispatcherJobTest, CompileFailureToFinalize) {
+ std::string raw_script("() { var a = ");
+ for (int i = 0; i < 1000; i++) {
+ raw_script += "'x' + ";
+ }
+ raw_script += " 'x'; }";
+ ScriptResource script(raw_script.c_str(), strlen(raw_script.c_str()));
+ std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob(
+ i_isolate(), CreateFunction(i_isolate(), &script), 100));
+
+ job->PrepareToParseOnMainThread();
+ job->Parse();
+ job->FinalizeParsingOnMainThread();
+ job->PrepareToCompileOnMainThread();
+ job->Compile();
+ ASSERT_FALSE(job->FinalizeCompilingOnMainThread());
+ ASSERT_TRUE(job->status() == CompileJobStatus::kFailed);
+ ASSERT_TRUE(i_isolate()->has_pending_exception());
+
+ i_isolate()->clear_pending_exception();
+ job->ResetOnMainThread();
+ ASSERT_TRUE(job->status() == CompileJobStatus::kInitial);
+}
+
} // namespace internal
} // namespace v8
« no previous file with comments | « src/interpreter/interpreter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698