Commit a550528d authored by rmcilroy's avatar rmcilroy Committed by Commit bot

[Ignition] Add test of bytecode compilation on background thread.

BUG=v8:5203

Review-Url: https://codereview.chromium.org/2278153003
Cr-Commit-Position: refs/heads/master@{#39207}
parent 059b5643
......@@ -8,10 +8,12 @@
#include "src/api.h"
#include "src/ast/ast.h"
#include "src/ast/scopes.h"
#include "src/base/platform/semaphore.h"
#include "src/compiler-dispatcher/compiler-dispatcher-job.h"
#include "src/flags.h"
#include "src/isolate-inl.h"
#include "src/parsing/parse-info.h"
#include "src/v8.h"
#include "test/unittests/test-utils.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -20,6 +22,29 @@ namespace internal {
typedef TestWithContext CompilerDispatcherJobTest;
class IgnitionCompilerDispatcherJobTest : public TestWithContext {
public:
IgnitionCompilerDispatcherJobTest() {}
~IgnitionCompilerDispatcherJobTest() override {}
static void SetUpTestCase() {
old_flag_ = i::FLAG_ignition;
i::FLAG_ignition = true;
TestWithContext::SetUpTestCase();
}
static void TearDownTestCase() {
TestWithContext::TearDownTestCase();
i::FLAG_ignition = old_flag_;
}
private:
static bool old_flag_;
DISALLOW_COPY_AND_ASSIGN(IgnitionCompilerDispatcherJobTest);
};
bool IgnitionCompilerDispatcherJobTest::old_flag_;
namespace {
const char test_script[] = "(x) { x*x; }";
......@@ -238,5 +263,52 @@ TEST_F(CompilerDispatcherJobTest, CompileFailureToFinalize) {
ASSERT_TRUE(job->status() == CompileJobStatus::kInitial);
}
class CompileTask : public Task {
public:
CompileTask(CompilerDispatcherJob* job, base::Semaphore* semaphore)
: job_(job), semaphore_(semaphore) {}
~CompileTask() override {}
void Run() override {
job_->Compile();
semaphore_->Signal();
}
private:
CompilerDispatcherJob* job_;
base::Semaphore* semaphore_;
DISALLOW_COPY_AND_ASSIGN(CompileTask);
};
TEST_F(IgnitionCompilerDispatcherJobTest, CompileOnBackgroundThread) {
const char* raw_script =
"(a, b) {\n"
" var c = a + b;\n"
" function bar() { return b }\n"
" var d = { foo: 100, bar : bar() }\n"
" return bar;"
"}";
ScriptResource script(raw_script, strlen(raw_script));
std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob(
i_isolate(), CreateFunction(i_isolate(), &script), 100));
job->PrepareToParseOnMainThread();
job->Parse();
job->FinalizeParsingOnMainThread();
job->PrepareToCompileOnMainThread();
ASSERT_TRUE(job->can_compile_on_background_thread());
base::Semaphore semaphore(0);
CompileTask* background_task = new CompileTask(job.get(), &semaphore);
V8::GetCurrentPlatform()->CallOnBackgroundThread(background_task,
Platform::kShortRunningTask);
semaphore.Wait();
ASSERT_TRUE(job->FinalizeCompilingOnMainThread());
ASSERT_TRUE(job->status() == CompileJobStatus::kDone);
job->ResetOnMainThread();
ASSERT_TRUE(job->status() == CompileJobStatus::kInitial);
}
} // namespace internal
} // namespace v8
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