Chromium Code Reviews| Index: runtime/vm/compiler_test.cc |
| diff --git a/runtime/vm/compiler_test.cc b/runtime/vm/compiler_test.cc |
| index aa5b8929c607cf53de5f41f2577444c4eff92bc3..18b6e48fea23dea4d54c5b1e5643c5a17ac349c2 100644 |
| --- a/runtime/vm/compiler_test.cc |
| +++ b/runtime/vm/compiler_test.cc |
| @@ -9,6 +9,7 @@ |
| #include "vm/dart_api_impl.h" |
| #include "vm/object.h" |
| #include "vm/symbols.h" |
| +#include "vm/thread_pool.h" |
| #include "vm/unit_test.h" |
| namespace dart { |
| @@ -28,7 +29,7 @@ TEST_CASE(CompileScript) { |
| } |
| -TEST_CASE(CompileFunction) { |
| +static void CompileFunctionImpl() { |
| const char* kScriptChars = |
| "class A {\n" |
| " static foo() { return 42; }\n" |
| @@ -69,6 +70,70 @@ TEST_CASE(CompileFunction) { |
| } |
| +TEST_CASE(CompileFunction) { |
| + CompileFunctionImpl(); |
| +} |
| + |
| + |
| +// Runs 'CompileFunctionImpl' on a helper thread. |
| +class CompileFunctionTask : public ThreadPool::Task { |
| + public: |
| + CompileFunctionTask(Isolate* isolate, |
| + Monitor* done_monitor, |
| + bool* done) |
|
srdjan
2015/08/17 20:13:48
Better indentation
koda
2015/08/17 20:27:33
Done.
|
| + : isolate_(isolate), |
| + done_monitor_(done_monitor), |
| + done_(done) { |
| + } |
| + |
| + virtual void Run() { |
| + Thread::EnterIsolateAsHelper(isolate_); |
| + { |
| + Thread* thread = Thread::Current(); |
| + StackZone stack_zone(thread); |
| + HANDLESCOPE(thread); |
| + CompileFunctionImpl(); |
| + } |
| + Thread::ExitIsolateAsHelper(); |
| + // Tell main thread that we are done. |
| + { |
| + MonitorLocker ml(done_monitor_); |
| + ASSERT(!*done_); |
| + *done_ = true; |
| + ml.Notify(); |
| + } |
| + } |
| + |
| + private: |
| + Isolate* isolate_; |
| + Monitor* done_monitor_; |
| + bool* done_; |
| +}; |
| + |
| + |
| +TEST_CASE(CompileFunctionOnHelperThread) { |
| + Monitor done_monitor; |
| + bool done = false; |
| + Isolate* isolate = Thread::Current()->isolate(); |
| + // Flush store buffers, etc. |
| + // TODO(koda): Currently, the GC only does this for the current thread, (i.e, |
| + // the helper, in this test), but it should be done for all *threads* |
| + // after/at safepointing. |
| + Thread::PrepareForGC(); |
| + Dart::thread_pool()->Run( |
| + new CompileFunctionTask(isolate, &done_monitor, &done)); |
| + { |
| + // Manually wait. |
| + // TODO(koda): Replace with execution of Dart and/or VM code when GC |
| + // actually safepoints everything. |
| + MonitorLocker ml(&done_monitor); |
| + while (!done) { |
| + ml.Wait(); |
| + } |
| + } |
| +} |
| + |
| + |
| TEST_CASE(RegenerateAllocStubs) { |
| const char* kScriptChars = |
| "class A {\n" |