Commit 8ff0ca1b authored by Ross McIlroy's avatar Ross McIlroy Committed by Commit Bot

[Compiler] Simplify UnoptimizedCompileJob

Simplifies the unoptimized compile job to have only three steps, the
on-main-thread prepare step, the off-thread compile step and the
on-main-thread finalization step.

As part of this change, the compiler dispatcher no longer supports
functions with outer scopeinfo's, since these need to be analysed on the
main thread.

BUG=v8:5203

Change-Id: Ifb378ef81bd47b6f6d4037a3b8acf88660896c4e
Reviewed-on: https://chromium-review.googlesource.com/774558
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49413}
parent 473fb7d6
...@@ -30,26 +30,14 @@ CompilerDispatcherTracer::Scope::Scope(CompilerDispatcherTracer* tracer, ...@@ -30,26 +30,14 @@ CompilerDispatcherTracer::Scope::Scope(CompilerDispatcherTracer* tracer,
CompilerDispatcherTracer::Scope::~Scope() { CompilerDispatcherTracer::Scope::~Scope() {
double elapsed = MonotonicallyIncreasingTimeInMs() - start_time_; double elapsed = MonotonicallyIncreasingTimeInMs() - start_time_;
switch (scope_id_) { switch (scope_id_) {
case ScopeID::kPrepareToParse: case ScopeID::kPrepare:
tracer_->RecordPrepareToParse(elapsed); tracer_->RecordPrepare(elapsed);
break;
case ScopeID::kParse:
tracer_->RecordParse(elapsed, num_);
break;
case ScopeID::kFinalizeParsing:
tracer_->RecordFinalizeParsing(elapsed);
break;
case ScopeID::kAnalyze:
tracer_->RecordAnalyze(elapsed);
break;
case ScopeID::kPrepareToCompile:
tracer_->RecordPrepareToCompile(elapsed);
break; break;
case ScopeID::kCompile: case ScopeID::kCompile:
tracer_->RecordCompile(elapsed); tracer_->RecordCompile(elapsed, num_);
break; break;
case ScopeID::kFinalizeCompiling: case ScopeID::kFinalize:
tracer_->RecordFinalizeCompiling(elapsed); tracer_->RecordFinalize(elapsed);
break; break;
} }
} }
...@@ -57,20 +45,12 @@ CompilerDispatcherTracer::Scope::~Scope() { ...@@ -57,20 +45,12 @@ CompilerDispatcherTracer::Scope::~Scope() {
// static // static
const char* CompilerDispatcherTracer::Scope::Name(ScopeID scope_id) { const char* CompilerDispatcherTracer::Scope::Name(ScopeID scope_id) {
switch (scope_id) { switch (scope_id) {
case ScopeID::kPrepareToParse: case ScopeID::kPrepare:
return "V8.BackgroundCompile_PrepareToParse"; return "V8.BackgroundCompile_Prepare";
case ScopeID::kParse:
return "V8.BackgroundCompile_Parse";
case ScopeID::kFinalizeParsing:
return "V8.BackgroundCompile_FinalizeParsing";
case ScopeID::kAnalyze:
return "V8.BackgroundCompile_Analyze";
case ScopeID::kPrepareToCompile:
return "V8.BackgroundCompile_PrepareToCompile";
case ScopeID::kCompile: case ScopeID::kCompile:
return "V8.BackgroundCompile_Compile"; return "V8.BackgroundCompile_Compile";
case ScopeID::kFinalizeCompiling: case ScopeID::kFinalize:
return "V8.BackgroundCompile_FinalizeCompiling"; return "V8.BackgroundCompile_Finalize";
} }
UNREACHABLE(); UNREACHABLE();
} }
...@@ -85,87 +65,44 @@ CompilerDispatcherTracer::CompilerDispatcherTracer(Isolate* isolate) ...@@ -85,87 +65,44 @@ CompilerDispatcherTracer::CompilerDispatcherTracer(Isolate* isolate)
CompilerDispatcherTracer::~CompilerDispatcherTracer() {} CompilerDispatcherTracer::~CompilerDispatcherTracer() {}
void CompilerDispatcherTracer::RecordPrepareToParse(double duration_ms) { void CompilerDispatcherTracer::RecordPrepare(double duration_ms) {
base::LockGuard<base::Mutex> lock(&mutex_);
prepare_parse_events_.Push(duration_ms);
}
void CompilerDispatcherTracer::RecordParse(double duration_ms,
size_t source_length) {
base::LockGuard<base::Mutex> lock(&mutex_);
parse_events_.Push(std::make_pair(source_length, duration_ms));
}
void CompilerDispatcherTracer::RecordFinalizeParsing(double duration_ms) {
base::LockGuard<base::Mutex> lock(&mutex_);
finalize_parsing_events_.Push(duration_ms);
}
void CompilerDispatcherTracer::RecordAnalyze(double duration_ms) {
base::LockGuard<base::Mutex> lock(&mutex_);
analyze_events_.Push(duration_ms);
}
void CompilerDispatcherTracer::RecordPrepareToCompile(double duration_ms) {
base::LockGuard<base::Mutex> lock(&mutex_);
prepare_compile_events_.Push(duration_ms);
}
void CompilerDispatcherTracer::RecordCompile(double duration_ms) {
base::LockGuard<base::Mutex> lock(&mutex_);
compile_events_.Push(duration_ms);
}
void CompilerDispatcherTracer::RecordFinalizeCompiling(double duration_ms) {
base::LockGuard<base::Mutex> lock(&mutex_);
finalize_compiling_events_.Push(duration_ms);
}
double CompilerDispatcherTracer::EstimatePrepareToParseInMs() const {
base::LockGuard<base::Mutex> lock(&mutex_);
return Average(prepare_parse_events_);
}
double CompilerDispatcherTracer::EstimateParseInMs(size_t source_length) const {
base::LockGuard<base::Mutex> lock(&mutex_); base::LockGuard<base::Mutex> lock(&mutex_);
return Estimate(parse_events_, source_length); prepare_events_.Push(duration_ms);
} }
double CompilerDispatcherTracer::EstimateFinalizeParsingInMs() const { void CompilerDispatcherTracer::RecordCompile(double duration_ms,
size_t source_length) {
base::LockGuard<base::Mutex> lock(&mutex_); base::LockGuard<base::Mutex> lock(&mutex_);
return Average(finalize_parsing_events_); compile_events_.Push(std::make_pair(source_length, duration_ms));
} }
double CompilerDispatcherTracer::EstimateAnalyzeInMs() const { void CompilerDispatcherTracer::RecordFinalize(double duration_ms) {
base::LockGuard<base::Mutex> lock(&mutex_); base::LockGuard<base::Mutex> lock(&mutex_);
return Average(analyze_events_); finalize_events_.Push(duration_ms);
} }
double CompilerDispatcherTracer::EstimatePrepareToCompileInMs() const { double CompilerDispatcherTracer::EstimatePrepareInMs() const {
base::LockGuard<base::Mutex> lock(&mutex_); base::LockGuard<base::Mutex> lock(&mutex_);
return Average(prepare_compile_events_); return Average(prepare_events_);
} }
double CompilerDispatcherTracer::EstimateCompileInMs() const { double CompilerDispatcherTracer::EstimateCompileInMs(
size_t source_length) const {
base::LockGuard<base::Mutex> lock(&mutex_); base::LockGuard<base::Mutex> lock(&mutex_);
return Average(compile_events_); return Estimate(compile_events_, source_length);
} }
double CompilerDispatcherTracer::EstimateFinalizeCompilingInMs() const { double CompilerDispatcherTracer::EstimateFinalizeInMs() const {
base::LockGuard<base::Mutex> lock(&mutex_); base::LockGuard<base::Mutex> lock(&mutex_);
return Average(finalize_compiling_events_); return Average(finalize_events_);
} }
void CompilerDispatcherTracer::DumpStatistics() const { void CompilerDispatcherTracer::DumpStatistics() const {
PrintF( PrintF(
"CompilerDispatcherTracer: " "CompilerDispatcherTracer: "
"prepare_parsing=%.2lfms parsing=%.2lfms/kb finalize_parsing=%.2lfms " "prepare=%.2lfms compiling=%.2lfms/kb finalize=%.2lfms\n",
"analyze=%.2lfms prepare_compiling=%.2lfms compiling=%.2lfms/kb " EstimatePrepareInMs(), EstimateCompileInMs(1 * KB),
"finalize_compiling=%.2lfms\n", EstimateFinalizeInMs());
EstimatePrepareToParseInMs(), EstimateParseInMs(1 * KB),
EstimateFinalizeParsingInMs(), EstimateAnalyzeInMs(),
EstimatePrepareToCompileInMs(), EstimateCompileInMs(),
EstimateFinalizeCompilingInMs());
} }
double CompilerDispatcherTracer::Average( double CompilerDispatcherTracer::Average(
......
...@@ -31,15 +31,7 @@ class RuntimeCallStats; ...@@ -31,15 +31,7 @@ class RuntimeCallStats;
class V8_EXPORT_PRIVATE CompilerDispatcherTracer { class V8_EXPORT_PRIVATE CompilerDispatcherTracer {
public: public:
enum class ScopeID { enum class ScopeID { kPrepare, kCompile, kFinalize };
kPrepareToParse,
kParse,
kFinalizeParsing,
kAnalyze,
kPrepareToCompile,
kCompile,
kFinalizeCompiling
};
class Scope { class Scope {
public: public:
...@@ -60,21 +52,13 @@ class V8_EXPORT_PRIVATE CompilerDispatcherTracer { ...@@ -60,21 +52,13 @@ class V8_EXPORT_PRIVATE CompilerDispatcherTracer {
explicit CompilerDispatcherTracer(Isolate* isolate); explicit CompilerDispatcherTracer(Isolate* isolate);
~CompilerDispatcherTracer(); ~CompilerDispatcherTracer();
void RecordPrepareToParse(double duration_ms); void RecordPrepare(double duration_ms);
void RecordParse(double duration_ms, size_t source_length); void RecordCompile(double duration_ms, size_t source_length);
void RecordFinalizeParsing(double duration_ms); void RecordFinalize(double duration_ms);
void RecordAnalyze(double duration_ms);
void RecordPrepareToCompile(double duration_ms); double EstimatePrepareInMs() const;
void RecordCompile(double duration_ms); double EstimateCompileInMs(size_t source_length) const;
void RecordFinalizeCompiling(double duration_ms); double EstimateFinalizeInMs() const;
double EstimatePrepareToParseInMs() const;
double EstimateParseInMs(size_t source_length) const;
double EstimateFinalizeParsingInMs() const;
double EstimateAnalyzeInMs() const;
double EstimatePrepareToCompileInMs() const;
double EstimateCompileInMs() const;
double EstimateFinalizeCompilingInMs() const;
void DumpStatistics() const; void DumpStatistics() const;
...@@ -84,13 +68,9 @@ class V8_EXPORT_PRIVATE CompilerDispatcherTracer { ...@@ -84,13 +68,9 @@ class V8_EXPORT_PRIVATE CompilerDispatcherTracer {
const base::RingBuffer<std::pair<size_t, double>>& buffer, size_t num); const base::RingBuffer<std::pair<size_t, double>>& buffer, size_t num);
mutable base::Mutex mutex_; mutable base::Mutex mutex_;
base::RingBuffer<double> prepare_parse_events_; base::RingBuffer<double> prepare_events_;
base::RingBuffer<std::pair<size_t, double>> parse_events_; base::RingBuffer<std::pair<size_t, double>> compile_events_;
base::RingBuffer<double> finalize_parsing_events_; base::RingBuffer<double> finalize_events_;
base::RingBuffer<double> analyze_events_;
base::RingBuffer<double> prepare_compile_events_;
base::RingBuffer<double> compile_events_;
base::RingBuffer<double> finalize_compiling_events_;
RuntimeCallStats* runtime_call_stats_; RuntimeCallStats* runtime_call_stats_;
......
...@@ -34,12 +34,9 @@ class V8_EXPORT_PRIVATE UnoptimizedCompileJob : public CompilerDispatcherJob { ...@@ -34,12 +34,9 @@ class V8_EXPORT_PRIVATE UnoptimizedCompileJob : public CompilerDispatcherJob {
public: public:
enum class Status { enum class Status {
kInitial, kInitial,
kReadyToParse,
kParsed,
kReadyToAnalyze,
kAnalyzed,
kReadyToCompile, kReadyToCompile,
kCompiled, kCompiled,
kReportErrors,
kDone, kDone,
kFailed, kFailed,
}; };
...@@ -68,8 +65,7 @@ class V8_EXPORT_PRIVATE UnoptimizedCompileJob : public CompilerDispatcherJob { ...@@ -68,8 +65,7 @@ class V8_EXPORT_PRIVATE UnoptimizedCompileJob : public CompilerDispatcherJob {
// StepNextOnMainThread and StepNextOnBackgroundThread could be used for the // StepNextOnMainThread and StepNextOnBackgroundThread could be used for the
// next step. // next step.
bool CanStepNextOnAnyThread() override { bool CanStepNextOnAnyThread() override {
return status() == Status::kReadyToParse || return status() == Status::kReadyToCompile;
status() == Status::kReadyToCompile;
} }
// Step the job forward by one state on the main thread. // Step the job forward by one state on the main thread.
...@@ -98,6 +94,7 @@ class V8_EXPORT_PRIVATE UnoptimizedCompileJob : public CompilerDispatcherJob { ...@@ -98,6 +94,7 @@ class V8_EXPORT_PRIVATE UnoptimizedCompileJob : public CompilerDispatcherJob {
Status status_; Status status_;
int main_thread_id_; int main_thread_id_;
CompilerDispatcherTracer* tracer_; CompilerDispatcherTracer* tracer_;
AccountingAllocator* allocator_;
Handle<Context> context_; // Global handle. Handle<Context> context_; // Global handle.
Handle<SharedFunctionInfo> shared_; // Global handle. Handle<SharedFunctionInfo> shared_; // Global handle.
Handle<String> source_; // Global handle. Handle<String> source_; // Global handle.
...@@ -115,26 +112,20 @@ class V8_EXPORT_PRIVATE UnoptimizedCompileJob : public CompilerDispatcherJob { ...@@ -115,26 +112,20 @@ class V8_EXPORT_PRIVATE UnoptimizedCompileJob : public CompilerDispatcherJob {
bool trace_compiler_dispatcher_jobs_; bool trace_compiler_dispatcher_jobs_;
// Transition from kInitial to kReadyToParse. // Transition from kInitial to kReadyToCompile
void PrepareToParseOnMainThread(Isolate* isolate); void PrepareOnMainThread(Isolate* isolate);
// Transition from kReadyToParse to kParsed. // Transition from kReadyToCompile to kCompiled (or kReportErrors).
void Parse(); void Compile(bool on_background_thread);
// Transition from kParsed to kReadyToAnalyze (or kFailed). // Transition from kCompiled to kDone (or kFailed).
void FinalizeParsingOnMainThread(Isolate* isolate); void FinalizeOnMainThread(Isolate* isolate);
// Transition from kReadyToAnalyze to kAnalyzed (or kFailed).
void AnalyzeOnMainThread(Isolate* isolate);
// Transition from kAnalyzed to kReadyToCompile (or kFailed).
void PrepareToCompileOnMainThread(Isolate* isolate);
// Transition from kReadyToCompile to kCompiled. // Transition from kReportErrors to kFailed.
void Compile(); void ReportErrorsOnMainThread(Isolate* isolate);
// Transition from kCompiled to kDone (or kFailed). // Free all resources.
void FinalizeCompilingOnMainThread(Isolate* isolate); void ResetDataOnMainThread(Isolate* isolate);
DISALLOW_COPY_AND_ASSIGN(UnoptimizedCompileJob); DISALLOW_COPY_AND_ASSIGN(UnoptimizedCompileJob);
}; };
......
...@@ -11,40 +11,36 @@ namespace internal { ...@@ -11,40 +11,36 @@ namespace internal {
TEST(CompilerDispatcherTracerTest, EstimateWithoutSamples) { TEST(CompilerDispatcherTracerTest, EstimateWithoutSamples) {
CompilerDispatcherTracer tracer(nullptr); CompilerDispatcherTracer tracer(nullptr);
EXPECT_EQ(0.0, tracer.EstimatePrepareToParseInMs()); EXPECT_EQ(0.0, tracer.EstimatePrepareInMs());
EXPECT_EQ(1.0, tracer.EstimateParseInMs(0)); EXPECT_EQ(1.0, tracer.EstimateCompileInMs(1));
EXPECT_EQ(1.0, tracer.EstimateParseInMs(42)); EXPECT_EQ(1.0, tracer.EstimateCompileInMs(42));
EXPECT_EQ(0.0, tracer.EstimateFinalizeParsingInMs()); EXPECT_EQ(0.0, tracer.EstimateFinalizeInMs());
EXPECT_EQ(0.0, tracer.EstimatePrepareToCompileInMs());
EXPECT_EQ(0.0, tracer.EstimateCompileInMs());
EXPECT_EQ(0.0, tracer.EstimateCompileInMs());
EXPECT_EQ(0.0, tracer.EstimateFinalizeCompilingInMs());
} }
TEST(CompilerDispatcherTracerTest, Average) { TEST(CompilerDispatcherTracerTest, Average) {
CompilerDispatcherTracer tracer(nullptr); CompilerDispatcherTracer tracer(nullptr);
EXPECT_EQ(0.0, tracer.EstimatePrepareToParseInMs()); EXPECT_EQ(0.0, tracer.EstimatePrepareInMs());
tracer.RecordPrepareToParse(1.0); tracer.RecordPrepare(1.0);
tracer.RecordPrepareToParse(2.0); tracer.RecordPrepare(2.0);
tracer.RecordPrepareToParse(3.0); tracer.RecordPrepare(3.0);
EXPECT_EQ((1.0 + 2.0 + 3.0) / 3, tracer.EstimatePrepareToParseInMs()); EXPECT_EQ((1.0 + 2.0 + 3.0) / 3, tracer.EstimatePrepareInMs());
} }
TEST(CompilerDispatcherTracerTest, SizeBasedAverage) { TEST(CompilerDispatcherTracerTest, SizeBasedAverage) {
CompilerDispatcherTracer tracer(nullptr); CompilerDispatcherTracer tracer(nullptr);
EXPECT_EQ(1.0, tracer.EstimateParseInMs(100)); EXPECT_EQ(1.0, tracer.EstimateCompileInMs(100));
// All three samples parse 100 units/ms. // All three samples parse 100 units/ms.
tracer.RecordParse(1.0, 100); tracer.RecordCompile(1.0, 100);
tracer.RecordParse(2.0, 200); tracer.RecordCompile(2.0, 200);
tracer.RecordParse(3.0, 300); tracer.RecordCompile(3.0, 300);
EXPECT_EQ(1.0, tracer.EstimateParseInMs(100)); EXPECT_EQ(1.0, tracer.EstimateCompileInMs(100));
EXPECT_EQ(5.0, tracer.EstimateParseInMs(500)); EXPECT_EQ(5.0, tracer.EstimateCompileInMs(500));
} }
} // namespace internal } // namespace internal
......
...@@ -31,9 +31,8 @@ ...@@ -31,9 +31,8 @@
#define STR(x) _STR(x) #define STR(x) _STR(x)
#define _SCRIPT(fn, a, b, c) a fn b fn c #define _SCRIPT(fn, a, b, c) a fn b fn c
#define SCRIPT(a, b, c) _SCRIPT("f" STR(__LINE__), a, b, c) #define SCRIPT(a, b, c) _SCRIPT("f" STR(__LINE__), a, b, c)
#define TEST_SCRIPT() \ #define TEST_SCRIPT() \
SCRIPT("function g() { var y = 1; function ", \ "function f" STR(__LINE__) "(x, y) { return x * y }; f" STR(__LINE__) ";"
"(x) { return x * y }; return ", "; } g();")
namespace v8 { namespace v8 {
namespace internal { namespace internal {
...@@ -335,9 +334,8 @@ TEST_F(CompilerDispatcherTest, FinishAllNow) { ...@@ -335,9 +334,8 @@ TEST_F(CompilerDispatcherTest, FinishAllNow) {
std::stringstream ss; std::stringstream ss;
ss << 'f' << STR(__LINE__) << '_' << i; ss << 'f' << STR(__LINE__) << '_' << i;
std::string func_name = ss.str(); std::string func_name = ss.str();
std::string script("function g() { function " + func_name + std::string script("function f" + func_name + "(x, y) { return x * y }; f" +
"(x) { var a = 'x'; }; return " + func_name + func_name + ";");
"; } g();");
f[i] = RunJS<JSFunction>(script.c_str()); f[i] = RunJS<JSFunction>(script.c_str());
shared[i] = Handle<SharedFunctionInfo>(f[i]->shared(), i_isolate()); shared[i] = Handle<SharedFunctionInfo>(f[i]->shared(), i_isolate());
ASSERT_FALSE(shared[i]->is_compiled()); ASSERT_FALSE(shared[i]->is_compiled());
...@@ -400,7 +398,7 @@ TEST_F(CompilerDispatcherTest, IdleTaskSmallIdleTime) { ...@@ -400,7 +398,7 @@ TEST_F(CompilerDispatcherTest, IdleTaskSmallIdleTime) {
// The job should be still scheduled for the main thread, but ready for // The job should be still scheduled for the main thread, but ready for
// parsing. // parsing.
ASSERT_EQ(dispatcher.jobs_.size(), 1u); ASSERT_EQ(dispatcher.jobs_.size(), 1u);
ASSERT_EQ(UnoptimizedCompileJob::Status::kReadyToParse, ASSERT_EQ(UnoptimizedCompileJob::Status::kReadyToCompile,
GetUnoptimizedJobStatus(dispatcher.jobs_.begin()->second)); GetUnoptimizedJobStatus(dispatcher.jobs_.begin()->second));
// Now grant a lot of idle time and freeze time. // Now grant a lot of idle time and freeze time.
...@@ -416,12 +414,12 @@ TEST_F(CompilerDispatcherTest, IdleTaskException) { ...@@ -416,12 +414,12 @@ TEST_F(CompilerDispatcherTest, IdleTaskException) {
CompilerDispatcher dispatcher(i_isolate(), &platform, 50); CompilerDispatcher dispatcher(i_isolate(), &platform, 50);
std::string func_name("f" STR(__LINE__)); std::string func_name("f" STR(__LINE__));
std::string script("function g() { function " + func_name + "(x) { var a = "); std::string script("function " + func_name + "(x) { var a = ");
for (int i = 0; i < 500; i++) { for (int i = 0; i < 500; i++) {
// Alternate + and - to avoid n-ary operation nodes. // Alternate + and - to avoid n-ary operation nodes.
script += "'x' + 'x' - "; script += "'x' + 'x' - ";
} }
script += " 'x'; }; return " + func_name + "; } g();"; script += " 'x'; }; " + func_name + ";";
Handle<JSFunction> f = RunJS<JSFunction>(script.c_str()); Handle<JSFunction> f = RunJS<JSFunction>(script.c_str());
Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
...@@ -456,7 +454,7 @@ TEST_F(CompilerDispatcherTest, CompileOnBackgroundThread) { ...@@ -456,7 +454,7 @@ TEST_F(CompilerDispatcherTest, CompileOnBackgroundThread) {
// Make compiling super expensive, and advance job as much as possible on the // Make compiling super expensive, and advance job as much as possible on the
// foreground thread. // foreground thread.
dispatcher.tracer_->RecordCompile(50000.0); dispatcher.tracer_->RecordCompile(50000.0, 1);
platform.RunIdleTask(10.0, 0.0); platform.RunIdleTask(10.0, 0.0);
ASSERT_EQ(UnoptimizedCompileJob::Status::kReadyToCompile, ASSERT_EQ(UnoptimizedCompileJob::Status::kReadyToCompile,
GetUnoptimizedJobStatus(dispatcher.jobs_.begin()->second)); GetUnoptimizedJobStatus(dispatcher.jobs_.begin()->second));
...@@ -499,7 +497,7 @@ TEST_F(CompilerDispatcherTest, FinishNowWithBackgroundTask) { ...@@ -499,7 +497,7 @@ TEST_F(CompilerDispatcherTest, FinishNowWithBackgroundTask) {
// Make compiling super expensive, and advance job as much as possible on the // Make compiling super expensive, and advance job as much as possible on the
// foreground thread. // foreground thread.
dispatcher.tracer_->RecordCompile(50000.0); dispatcher.tracer_->RecordCompile(50000.0, 1);
platform.RunIdleTask(10.0, 0.0); platform.RunIdleTask(10.0, 0.0);
ASSERT_EQ(UnoptimizedCompileJob::Status::kReadyToCompile, ASSERT_EQ(UnoptimizedCompileJob::Status::kReadyToCompile,
GetUnoptimizedJobStatus(dispatcher.jobs_.begin()->second)); GetUnoptimizedJobStatus(dispatcher.jobs_.begin()->second));
...@@ -552,12 +550,12 @@ TEST_F(CompilerDispatcherTest, FinishNowException) { ...@@ -552,12 +550,12 @@ TEST_F(CompilerDispatcherTest, FinishNowException) {
CompilerDispatcher dispatcher(i_isolate(), &platform, 50); CompilerDispatcher dispatcher(i_isolate(), &platform, 50);
std::string func_name("f" STR(__LINE__)); std::string func_name("f" STR(__LINE__));
std::string script("function g() { function " + func_name + "(x) { var a = "); std::string script("function " + func_name + "(x) { var a = ");
for (int i = 0; i < 500; i++) { for (int i = 0; i < 500; i++) {
// Alternate + and - to avoid n-ary operation nodes. // Alternate + and - to avoid n-ary operation nodes.
script += "'x' + 'x' - "; script += "'x' + 'x' - ";
} }
script += " 'x'; }; return " + func_name + "; } g();"; script += " 'x'; }; " + func_name + ";";
Handle<JSFunction> f = RunJS<JSFunction>(script.c_str()); Handle<JSFunction> f = RunJS<JSFunction>(script.c_str());
Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
...@@ -593,7 +591,7 @@ TEST_F(CompilerDispatcherTest, AsyncAbortAllPendingBackgroundTask) { ...@@ -593,7 +591,7 @@ TEST_F(CompilerDispatcherTest, AsyncAbortAllPendingBackgroundTask) {
// Make compiling super expensive, and advance job as much as possible on the // Make compiling super expensive, and advance job as much as possible on the
// foreground thread. // foreground thread.
dispatcher.tracer_->RecordCompile(50000.0); dispatcher.tracer_->RecordCompile(50000.0, 1);
platform.RunIdleTask(10.0, 0.0); platform.RunIdleTask(10.0, 0.0);
ASSERT_EQ(UnoptimizedCompileJob::Status::kReadyToCompile, ASSERT_EQ(UnoptimizedCompileJob::Status::kReadyToCompile,
GetUnoptimizedJobStatus(dispatcher.jobs_.begin()->second)); GetUnoptimizedJobStatus(dispatcher.jobs_.begin()->second));
...@@ -639,7 +637,7 @@ TEST_F(CompilerDispatcherTest, AsyncAbortAllRunningBackgroundTask) { ...@@ -639,7 +637,7 @@ TEST_F(CompilerDispatcherTest, AsyncAbortAllRunningBackgroundTask) {
// Make compiling super expensive, and advance job as much as possible on the // Make compiling super expensive, and advance job as much as possible on the
// foreground thread. // foreground thread.
dispatcher.tracer_->RecordCompile(50000.0); dispatcher.tracer_->RecordCompile(50000.0, 1);
platform.RunIdleTask(10.0, 0.0); platform.RunIdleTask(10.0, 0.0);
ASSERT_EQ(UnoptimizedCompileJob::Status::kReadyToCompile, ASSERT_EQ(UnoptimizedCompileJob::Status::kReadyToCompile,
GetUnoptimizedJobStatus(dispatcher.jobs_.begin()->second)); GetUnoptimizedJobStatus(dispatcher.jobs_.begin()->second));
...@@ -715,7 +713,7 @@ TEST_F(CompilerDispatcherTest, FinishNowDuringAbortAll) { ...@@ -715,7 +713,7 @@ TEST_F(CompilerDispatcherTest, FinishNowDuringAbortAll) {
// Make compiling super expensive, and advance job as much as possible on the // Make compiling super expensive, and advance job as much as possible on the
// foreground thread. // foreground thread.
dispatcher.tracer_->RecordCompile(50000.0); dispatcher.tracer_->RecordCompile(50000.0, 1);
platform.RunIdleTask(10.0, 0.0); platform.RunIdleTask(10.0, 0.0);
ASSERT_EQ(UnoptimizedCompileJob::Status::kReadyToCompile, ASSERT_EQ(UnoptimizedCompileJob::Status::kReadyToCompile,
GetUnoptimizedJobStatus(dispatcher.jobs_.begin()->second)); GetUnoptimizedJobStatus(dispatcher.jobs_.begin()->second));
...@@ -884,7 +882,7 @@ TEST_F(CompilerDispatcherTest, EnqueueAndStep) { ...@@ -884,7 +882,7 @@ TEST_F(CompilerDispatcherTest, EnqueueAndStep) {
ASSERT_TRUE(dispatcher.EnqueueAndStep(shared)); ASSERT_TRUE(dispatcher.EnqueueAndStep(shared));
ASSERT_TRUE(dispatcher.IsEnqueued(shared)); ASSERT_TRUE(dispatcher.IsEnqueued(shared));
ASSERT_EQ(UnoptimizedCompileJob::Status::kReadyToParse, ASSERT_EQ(UnoptimizedCompileJob::Status::kReadyToCompile,
GetUnoptimizedJobStatus(dispatcher.jobs_.begin()->second)); GetUnoptimizedJobStatus(dispatcher.jobs_.begin()->second));
ASSERT_TRUE(platform.IdleTaskPending()); ASSERT_TRUE(platform.IdleTaskPending());
...@@ -898,7 +896,7 @@ TEST_F(CompilerDispatcherTest, CompileLazyFinishesDispatcherJob) { ...@@ -898,7 +896,7 @@ TEST_F(CompilerDispatcherTest, CompileLazyFinishesDispatcherJob) {
// enqueued functions. // enqueued functions.
CompilerDispatcher* dispatcher = i_isolate()->compiler_dispatcher(); CompilerDispatcher* dispatcher = i_isolate()->compiler_dispatcher();
const char script[] = TEST_SCRIPT(); const char script[] = "function lazy() { return 42; }; lazy;";
Handle<JSFunction> f = RunJS<JSFunction>(script); Handle<JSFunction> f = RunJS<JSFunction>(script);
Handle<SharedFunctionInfo> shared(f->shared(), i_isolate()); Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
...@@ -909,7 +907,7 @@ TEST_F(CompilerDispatcherTest, CompileLazyFinishesDispatcherJob) { ...@@ -909,7 +907,7 @@ TEST_F(CompilerDispatcherTest, CompileLazyFinishesDispatcherJob) {
// Now force the function to run and ensure CompileLazy finished and dequeues // Now force the function to run and ensure CompileLazy finished and dequeues
// it from the dispatcher. // it from the dispatcher.
RunJS("g()();"); RunJS("lazy();");
ASSERT_TRUE(shared->is_compiled()); ASSERT_TRUE(shared->is_compiled());
ASSERT_FALSE(dispatcher->IsEnqueued(shared)); ASSERT_FALSE(dispatcher->IsEnqueued(shared));
} }
...@@ -950,12 +948,12 @@ TEST_F(CompilerDispatcherTest, EnqueueAndStepTwice) { ...@@ -950,12 +948,12 @@ TEST_F(CompilerDispatcherTest, EnqueueAndStepTwice) {
ASSERT_FALSE(dispatcher.IsEnqueued(shared)); ASSERT_FALSE(dispatcher.IsEnqueued(shared));
ASSERT_TRUE(dispatcher.EnqueueAndStep(shared)); ASSERT_TRUE(dispatcher.EnqueueAndStep(shared));
ASSERT_TRUE(dispatcher.IsEnqueued(shared)); ASSERT_TRUE(dispatcher.IsEnqueued(shared));
ASSERT_EQ(UnoptimizedCompileJob::Status::kReadyToParse, ASSERT_EQ(UnoptimizedCompileJob::Status::kReadyToCompile,
GetUnoptimizedJobStatus(dispatcher.jobs_.begin()->second)); GetUnoptimizedJobStatus(dispatcher.jobs_.begin()->second));
// EnqueueAndStep of the same function again (shouldn't step the job. // EnqueueAndStep of the same function again (shouldn't step the job.
ASSERT_TRUE(dispatcher.EnqueueAndStep(shared)); ASSERT_TRUE(dispatcher.EnqueueAndStep(shared));
ASSERT_EQ(UnoptimizedCompileJob::Status::kReadyToParse, ASSERT_EQ(UnoptimizedCompileJob::Status::kReadyToCompile,
GetUnoptimizedJobStatus(dispatcher.jobs_.begin()->second)); GetUnoptimizedJobStatus(dispatcher.jobs_.begin()->second));
ASSERT_TRUE(platform.IdleTaskPending()); ASSERT_TRUE(platform.IdleTaskPending());
...@@ -988,7 +986,7 @@ TEST_F(CompilerDispatcherTest, CompileMultipleOnBackgroundThread) { ...@@ -988,7 +986,7 @@ TEST_F(CompilerDispatcherTest, CompileMultipleOnBackgroundThread) {
// Make compiling super expensive, and advance job as much as possible on the // Make compiling super expensive, and advance job as much as possible on the
// foreground thread. // foreground thread.
dispatcher.tracer_->RecordCompile(50000.0); dispatcher.tracer_->RecordCompile(50000.0, 1);
platform.RunIdleTask(10.0, 0.0); platform.RunIdleTask(10.0, 0.0);
ASSERT_EQ(dispatcher.jobs_.size(), 2u); ASSERT_EQ(dispatcher.jobs_.size(), 2u);
ASSERT_EQ(UnoptimizedCompileJob::Status::kReadyToCompile, ASSERT_EQ(UnoptimizedCompileJob::Status::kReadyToCompile,
...@@ -1023,5 +1021,11 @@ TEST_F(CompilerDispatcherTest, CompileMultipleOnBackgroundThread) { ...@@ -1023,5 +1021,11 @@ TEST_F(CompilerDispatcherTest, CompileMultipleOnBackgroundThread) {
ASSERT_FALSE(platform.IdleTaskPending()); ASSERT_FALSE(platform.IdleTaskPending());
} }
#undef _STR
#undef STR
#undef _SCRIPT
#undef SCRIPT
#undef TEST_SCRIPT
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
...@@ -84,18 +84,6 @@ TEST_F(UnoptimizedCompileJobTest, StateTransitions) { ...@@ -84,18 +84,6 @@ TEST_F(UnoptimizedCompileJobTest, StateTransitions) {
ASSERT_JOB_STATUS(UnoptimizedCompileJob::Status::kInitial, job); ASSERT_JOB_STATUS(UnoptimizedCompileJob::Status::kInitial, job);
job->StepNextOnMainThread(isolate()); job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed()); ASSERT_FALSE(job->IsFailed());
ASSERT_JOB_STATUS(UnoptimizedCompileJob::Status::kReadyToParse, job);
job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed());
ASSERT_JOB_STATUS(UnoptimizedCompileJob::Status::kParsed, job);
job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed());
ASSERT_JOB_STATUS(UnoptimizedCompileJob::Status::kReadyToAnalyze, job);
job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed());
ASSERT_JOB_STATUS(UnoptimizedCompileJob::Status::kAnalyzed, job);
job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed());
ASSERT_JOB_STATUS(UnoptimizedCompileJob::Status::kReadyToCompile, job); ASSERT_JOB_STATUS(UnoptimizedCompileJob::Status::kReadyToCompile, job);
job->StepNextOnMainThread(isolate()); job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed()); ASSERT_FALSE(job->IsFailed());
...@@ -128,39 +116,6 @@ TEST_F(UnoptimizedCompileJobTest, SyntaxError) { ...@@ -128,39 +116,6 @@ TEST_F(UnoptimizedCompileJobTest, SyntaxError) {
ASSERT_JOB_STATUS(UnoptimizedCompileJob::Status::kInitial, job); ASSERT_JOB_STATUS(UnoptimizedCompileJob::Status::kInitial, job);
} }
TEST_F(UnoptimizedCompileJobTest, ScopeChain) {
const char script[] =
"function g() { var y = 1; function f(x) { return x * y }; return f; } "
"g();";
Handle<JSFunction> f = RunJS<JSFunction>(script);
std::unique_ptr<UnoptimizedCompileJob> job(new UnoptimizedCompileJob(
isolate(), tracer(), handle(f->shared()), FLAG_stack_size));
job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed());
job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed());
job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed());
job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed());
job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed());
ASSERT_JOB_STATUS(UnoptimizedCompileJob::Status::kReadyToCompile, job);
Variable* var = LookupVariableByName(job.get(), "x");
ASSERT_TRUE(var);
ASSERT_TRUE(var->IsParameter());
var = LookupVariableByName(job.get(), "y");
ASSERT_TRUE(var);
ASSERT_TRUE(var->IsContextSlot());
job->ResetOnMainThread(isolate());
ASSERT_JOB_STATUS(UnoptimizedCompileJob::Status::kInitial, job);
}
TEST_F(UnoptimizedCompileJobTest, CompileAndRun) { TEST_F(UnoptimizedCompileJobTest, CompileAndRun) {
const char script[] = const char script[] =
"function g() {\n" "function g() {\n"
...@@ -175,14 +130,6 @@ TEST_F(UnoptimizedCompileJobTest, CompileAndRun) { ...@@ -175,14 +130,6 @@ TEST_F(UnoptimizedCompileJobTest, CompileAndRun) {
std::unique_ptr<UnoptimizedCompileJob> job(new UnoptimizedCompileJob( std::unique_ptr<UnoptimizedCompileJob> job(new UnoptimizedCompileJob(
isolate(), tracer(), handle(f->shared()), FLAG_stack_size)); isolate(), tracer(), handle(f->shared()), FLAG_stack_size));
job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed());
job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed());
job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed());
job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed());
job->StepNextOnMainThread(isolate()); job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed()); ASSERT_FALSE(job->IsFailed());
job->StepNextOnMainThread(isolate()); job->StepNextOnMainThread(isolate());
...@@ -213,8 +160,6 @@ TEST_F(UnoptimizedCompileJobTest, CompileFailureToAnalyse) { ...@@ -213,8 +160,6 @@ TEST_F(UnoptimizedCompileJobTest, CompileFailureToAnalyse) {
isolate(), tracer(), test::CreateSharedFunctionInfo(isolate(), &script), isolate(), tracer(), test::CreateSharedFunctionInfo(isolate(), &script),
100)); 100));
job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed());
job->StepNextOnMainThread(isolate()); job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed()); ASSERT_FALSE(job->IsFailed());
job->StepNextOnMainThread(isolate()); job->StepNextOnMainThread(isolate());
...@@ -241,14 +186,6 @@ TEST_F(UnoptimizedCompileJobTest, CompileFailureToFinalize) { ...@@ -241,14 +186,6 @@ TEST_F(UnoptimizedCompileJobTest, CompileFailureToFinalize) {
isolate(), tracer(), test::CreateSharedFunctionInfo(isolate(), &script), isolate(), tracer(), test::CreateSharedFunctionInfo(isolate(), &script),
50)); 50));
job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed());
job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed());
job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed());
job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed());
job->StepNextOnMainThread(isolate()); job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed()); ASSERT_FALSE(job->IsFailed());
job->StepNextOnMainThread(isolate()); job->StepNextOnMainThread(isolate());
...@@ -296,14 +233,6 @@ TEST_F(UnoptimizedCompileJobTest, CompileOnBackgroundThread) { ...@@ -296,14 +233,6 @@ TEST_F(UnoptimizedCompileJobTest, CompileOnBackgroundThread) {
job->StepNextOnMainThread(isolate()); job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed()); ASSERT_FALSE(job->IsFailed());
job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed());
job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed());
job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed());
job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed());
base::Semaphore semaphore(0); base::Semaphore semaphore(0);
CompileTask* background_task = new CompileTask(job.get(), &semaphore); CompileTask* background_task = new CompileTask(job.get(), &semaphore);
...@@ -321,27 +250,16 @@ TEST_F(UnoptimizedCompileJobTest, CompileOnBackgroundThread) { ...@@ -321,27 +250,16 @@ TEST_F(UnoptimizedCompileJobTest, CompileOnBackgroundThread) {
TEST_F(UnoptimizedCompileJobTest, LazyInnerFunctions) { TEST_F(UnoptimizedCompileJobTest, LazyInnerFunctions) {
const char script[] = const char script[] =
"function g() {\n" "f = function() {\n"
" f = function() {\n" " e = (function() { return 42; });\n"
" e = (function() { return 42; });\n" " return e;\n"
" return e;\n" "};\n"
" };\n" "f;";
" return f;\n"
"}\n"
"g();";
Handle<JSFunction> f = RunJS<JSFunction>(script); Handle<JSFunction> f = RunJS<JSFunction>(script);
std::unique_ptr<UnoptimizedCompileJob> job(new UnoptimizedCompileJob( std::unique_ptr<UnoptimizedCompileJob> job(new UnoptimizedCompileJob(
isolate(), tracer(), handle(f->shared()), FLAG_stack_size)); isolate(), tracer(), handle(f->shared()), FLAG_stack_size));
job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed());
job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed());
job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed());
job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed());
job->StepNextOnMainThread(isolate()); job->StepNextOnMainThread(isolate());
ASSERT_FALSE(job->IsFailed()); ASSERT_FALSE(job->IsFailed());
job->StepNextOnMainThread(isolate()); job->StepNextOnMainThread(isolate());
......
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