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

Side by Side Diff: runtime/vm/compiler_test.cc

Issue 1302623002: Only test optimizing compilation in helper thread compilation test. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Update URL. Created 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | runtime/vm/object.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/assert.h" 5 #include "platform/assert.h"
6 #include "vm/class_finalizer.h" 6 #include "vm/class_finalizer.h"
7 #include "vm/code_patcher.h" 7 #include "vm/code_patcher.h"
8 #include "vm/compiler.h" 8 #include "vm/compiler.h"
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/object.h" 10 #include "vm/object.h"
(...skipping 11 matching lines...) Expand all
22 String& url = String::Handle(String::New("dart-test:CompileScript")); 22 String& url = String::Handle(String::New("dart-test:CompileScript"));
23 String& source = String::Handle(String::New(kScriptChars)); 23 String& source = String::Handle(String::New(kScriptChars));
24 Script& script = Script::Handle(Script::New(url, 24 Script& script = Script::Handle(Script::New(url,
25 source, 25 source,
26 RawScript::kScriptTag)); 26 RawScript::kScriptTag));
27 Library& lib = Library::Handle(Library::CoreLibrary()); 27 Library& lib = Library::Handle(Library::CoreLibrary());
28 EXPECT(CompilerTest::TestCompileScript(lib, script)); 28 EXPECT(CompilerTest::TestCompileScript(lib, script));
29 } 29 }
30 30
31 31
32 static void CompileFunctionImpl() { 32 TEST_CASE(CompileFunction) {
33 const char* kScriptChars = 33 const char* kScriptChars =
34 "class A {\n" 34 "class A {\n"
35 " static foo() { return 42; }\n" 35 " static foo() { return 42; }\n"
36 " static moo() {\n" 36 " static moo() {\n"
37 " // A.foo();\n" 37 " // A.foo();\n"
38 " }\n" 38 " }\n"
39 "}\n"; 39 "}\n";
40 String& url = String::Handle(String::New("dart-test:CompileFunction")); 40 String& url = String::Handle(String::New("dart-test:CompileFunction"));
41 String& source = String::Handle(String::New(kScriptChars)); 41 String& source = String::Handle(String::New(kScriptChars));
42 Script& script = Script::Handle(Script::New(url, 42 Script& script = Script::Handle(Script::New(url,
(...skipping 20 matching lines...) Expand all
63 EXPECT(!function_moo.IsNull()); 63 EXPECT(!function_moo.IsNull());
64 64
65 EXPECT(CompilerTest::TestCompileFunction(function_moo)); 65 EXPECT(CompilerTest::TestCompileFunction(function_moo));
66 EXPECT(function_moo.HasCode()); 66 EXPECT(function_moo.HasCode());
67 function_source = function_moo.GetSource(); 67 function_source = function_moo.GetSource();
68 EXPECT_STREQ("static moo() {\n // A.foo();\n }", 68 EXPECT_STREQ("static moo() {\n // A.foo();\n }",
69 function_source.ToCString()); 69 function_source.ToCString());
70 } 70 }
71 71
72 72
73 TEST_CASE(CompileFunction) {
74 CompileFunctionImpl();
75 }
76
77
78 // Runs 'CompileFunctionImpl' on a helper thread.
79 class CompileFunctionTask : public ThreadPool::Task { 73 class CompileFunctionTask : public ThreadPool::Task {
80 public: 74 public:
81 CompileFunctionTask(Isolate* isolate, 75 CompileFunctionTask(Isolate* isolate,
82 Monitor* done_monitor, 76 const Function& func,
83 bool* done) 77 Monitor* done_monitor,
78 bool* done)
84 : isolate_(isolate), 79 : isolate_(isolate),
80 func_(func),
85 done_monitor_(done_monitor), 81 done_monitor_(done_monitor),
86 done_(done) { 82 done_(done) {
87 } 83 }
88 84
89 virtual void Run() { 85 virtual void Run() {
90 Thread::EnterIsolateAsHelper(isolate_); 86 Thread::EnterIsolateAsHelper(isolate_);
91 { 87 {
92 Thread* thread = Thread::Current(); 88 Thread* thread = Thread::Current();
93 StackZone stack_zone(thread); 89 StackZone stack_zone(thread);
94 HANDLESCOPE(thread); 90 HANDLESCOPE(thread);
95 CompileFunctionImpl(); 91 EXPECT(!func_.HasOptimizedCode());
srdjan 2015/08/18 23:07:18 Assert that function has (unoptimized) code. We ex
koda 2015/08/19 00:16:32 Yes, although I'm already doing that in the code b
92 const Error& err =
93 Error::Handle(Compiler::CompileOptimizedFunction(thread, func_));
94 EXPECT(err.IsNull());
95 EXPECT(func_.HasOptimizedCode());
96 } 96 }
97 Thread::ExitIsolateAsHelper(); 97 Thread::ExitIsolateAsHelper();
98 // Tell main thread that we are done. 98 // Tell main thread that we are done.
99 { 99 {
100 MonitorLocker ml(done_monitor_); 100 MonitorLocker ml(done_monitor_);
101 ASSERT(!*done_); 101 ASSERT(!*done_);
102 *done_ = true; 102 *done_ = true;
103 ml.Notify(); 103 ml.Notify();
104 } 104 }
105 } 105 }
106 106
107 private: 107 private:
108 Isolate* isolate_; 108 Isolate* isolate_;
109 const Function& func_;
109 Monitor* done_monitor_; 110 Monitor* done_monitor_;
110 bool* done_; 111 bool* done_;
111 }; 112 };
112 113
113 114
114 TEST_CASE(CompileFunctionOnHelperThread) { 115 TEST_CASE(CompileFunctionOnHelperThread) {
115 Monitor done_monitor; 116 Monitor done_monitor;
116 bool done = false; 117 bool done = false;
117 Isolate* isolate = Thread::Current()->isolate(); 118 Isolate* isolate = Thread::Current()->isolate();
118 // Flush store buffers, etc. 119 // Flush store buffers, etc.
119 // TODO(koda): Currently, the GC only does this for the current thread, (i.e, 120 // TODO(koda): Currently, the GC only does this for the current thread, (i.e,
120 // the helper, in this test), but it should be done for all *threads* 121 // the helper, in this test), but it should be done for all *threads*
121 // after/at safepointing. 122 // after/at safepointing.
122 Thread::PrepareForGC(); 123 Thread::PrepareForGC();
124
125 // Create a simple function and compile it without optimization.
126 const char* kScriptChars =
127 "class A {\n"
128 " static foo() { return 42; }\n"
129 "}\n";
130 String& url =
131 String::Handle(String::New("dart-test:CompileFunctionOnHelperThread"));
132 String& source = String::Handle(String::New(kScriptChars));
133 Script& script = Script::Handle(Script::New(url,
134 source,
135 RawScript::kScriptTag));
136 Library& lib = Library::Handle(Library::CoreLibrary());
137 EXPECT(CompilerTest::TestCompileScript(lib, script));
138 EXPECT(ClassFinalizer::ProcessPendingClasses());
139 Class& cls = Class::Handle(
140 lib.LookupClass(String::Handle(Symbols::New("A"))));
141 EXPECT(!cls.IsNull());
142 String& function_foo_name = String::Handle(String::New("foo"));
143 Function& func =
144 Function::Handle(cls.LookupStaticFunction(function_foo_name));
145 EXPECT(!func.HasCode());
146 CompilerTest::TestCompileFunction(func);
147 EXPECT(func.HasCode());
148 EXPECT(!func.HasOptimizedCode());
149
150 // Now optimize it on a helper thread.
123 Dart::thread_pool()->Run( 151 Dart::thread_pool()->Run(
124 new CompileFunctionTask(isolate, &done_monitor, &done)); 152 new CompileFunctionTask(isolate, func, &done_monitor, &done));
125 { 153 {
126 // Manually wait. 154 // Manually wait.
127 // TODO(koda): Replace with execution of Dart and/or VM code when GC 155 // TODO(koda): Replace with execution of Dart and/or VM code when GC
128 // actually safepoints everything. 156 // actually safepoints everything.
129 MonitorLocker ml(&done_monitor); 157 MonitorLocker ml(&done_monitor);
130 while (!done) { 158 while (!done) {
131 ml.Wait(); 159 ml.Wait();
132 } 160 }
133 } 161 }
134 } 162 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 EXPECT(val.IsInteger()); 270 EXPECT(val.IsInteger());
243 EXPECT_EQ(7, Integer::Cast(val).AsInt64Value()); 271 EXPECT_EQ(7, Integer::Cast(val).AsInt64Value());
244 272
245 intptr_t final_class_table_size = 273 intptr_t final_class_table_size =
246 Isolate::Current()->class_table()->NumCids(); 274 Isolate::Current()->class_table()->NumCids();
247 // Eval should not eat into this non-renewable resource. 275 // Eval should not eat into this non-renewable resource.
248 EXPECT_EQ(initial_class_table_size, final_class_table_size); 276 EXPECT_EQ(initial_class_table_size, final_class_table_size);
249 } 277 }
250 278
251 } // namespace dart 279 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698