OLD | NEW |
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" |
| 11 #include "vm/safepoint.h" |
11 #include "vm/symbols.h" | 12 #include "vm/symbols.h" |
12 #include "vm/thread_pool.h" | 13 #include "vm/thread_pool.h" |
13 #include "vm/thread_registry.h" | |
14 #include "vm/unit_test.h" | 14 #include "vm/unit_test.h" |
15 | 15 |
16 namespace dart { | 16 namespace dart { |
17 | 17 |
18 DECLARE_FLAG(bool, background_compilation); | 18 DECLARE_FLAG(bool, background_compilation); |
19 | 19 |
20 TEST_CASE(CompileScript) { | 20 TEST_CASE(CompileScript) { |
21 const char* kScriptChars = | 21 const char* kScriptChars = |
22 "class A {\n" | 22 "class A {\n" |
23 " static foo() { return 42; }\n" | 23 " static foo() { return 42; }\n" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 EXPECT(!function_moo.IsNull()); | 66 EXPECT(!function_moo.IsNull()); |
67 | 67 |
68 EXPECT(CompilerTest::TestCompileFunction(function_moo)); | 68 EXPECT(CompilerTest::TestCompileFunction(function_moo)); |
69 EXPECT(function_moo.HasCode()); | 69 EXPECT(function_moo.HasCode()); |
70 function_source = function_moo.GetSource(); | 70 function_source = function_moo.GetSource(); |
71 EXPECT_STREQ("static moo() {\n // A.foo();\n }", | 71 EXPECT_STREQ("static moo() {\n // A.foo();\n }", |
72 function_source.ToCString()); | 72 function_source.ToCString()); |
73 } | 73 } |
74 | 74 |
75 | 75 |
76 TEST_CASE(CompileFunctionOnHelperThread) { | 76 VM_TEST_CASE(CompileFunctionOnHelperThread) { |
77 // Create a simple function and compile it without optimization. | 77 // Create a simple function and compile it without optimization. |
78 const char* kScriptChars = | 78 const char* kScriptChars = |
79 "class A {\n" | 79 "class A {\n" |
80 " static foo() { return 42; }\n" | 80 " static foo() { return 42; }\n" |
81 "}\n"; | 81 "}\n"; |
82 String& url = | 82 String& url = |
83 String::Handle(String::New("dart-test:CompileFunctionOnHelperThread")); | 83 String::Handle(String::New("dart-test:CompileFunctionOnHelperThread")); |
84 String& source = String::Handle(String::New(kScriptChars)); | 84 String& source = String::Handle(String::New(kScriptChars)); |
85 Script& script = Script::Handle(Script::New(url, | 85 Script& script = Script::Handle(Script::New(url, |
86 source, | 86 source, |
(...skipping 12 matching lines...) Expand all Loading... |
99 EXPECT(func.HasCode()); | 99 EXPECT(func.HasCode()); |
100 EXPECT(!func.HasOptimizedCode()); | 100 EXPECT(!func.HasOptimizedCode()); |
101 FLAG_background_compilation = true; | 101 FLAG_background_compilation = true; |
102 BackgroundCompiler::EnsureInit(thread); | 102 BackgroundCompiler::EnsureInit(thread); |
103 Isolate* isolate = thread->isolate(); | 103 Isolate* isolate = thread->isolate(); |
104 ASSERT(isolate->background_compiler() != NULL); | 104 ASSERT(isolate->background_compiler() != NULL); |
105 isolate->background_compiler()->CompileOptimized(func); | 105 isolate->background_compiler()->CompileOptimized(func); |
106 Monitor* m = new Monitor(); | 106 Monitor* m = new Monitor(); |
107 MonitorLocker ml(m); | 107 MonitorLocker ml(m); |
108 while (!func.HasOptimizedCode()) { | 108 while (!func.HasOptimizedCode()) { |
109 Isolate::Current()->thread_registry()->CheckSafepoint(); | 109 ml.WaitWithSafepointCheck(thread, 1); |
110 ml.Wait(1); | |
111 } | 110 } |
112 BackgroundCompiler::Stop(isolate->background_compiler()); | 111 BackgroundCompiler::Stop(isolate->background_compiler()); |
113 } | 112 } |
114 | 113 |
115 | 114 |
116 TEST_CASE(RegenerateAllocStubs) { | 115 TEST_CASE(RegenerateAllocStubs) { |
117 const char* kScriptChars = | 116 const char* kScriptChars = |
118 "class A {\n" | 117 "class A {\n" |
119 "}\n" | 118 "}\n" |
120 "unOpt() => new A(); \n" | 119 "unOpt() => new A(); \n" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 val = Instance::Cast(obj).Evaluate(expr_text, | 176 val = Instance::Cast(obj).Evaluate(expr_text, |
178 Array::empty_array(), | 177 Array::empty_array(), |
179 Array::empty_array()); | 178 Array::empty_array()); |
180 EXPECT(!val.IsNull()); | 179 EXPECT(!val.IsNull()); |
181 EXPECT(!val.IsError()); | 180 EXPECT(!val.IsError()); |
182 EXPECT(val.IsString()); | 181 EXPECT(val.IsString()); |
183 EXPECT_STREQ("Herr Nilsson 100.", val.ToCString()); | 182 EXPECT_STREQ("Herr Nilsson 100.", val.ToCString()); |
184 } | 183 } |
185 | 184 |
186 | 185 |
187 TEST_CASE(EvalExpressionWithLazyCompile) { | 186 VM_TEST_CASE(EvalExpressionWithLazyCompile) { |
188 Library& lib = Library::Handle(Library::CoreLibrary()); | 187 Library& lib = Library::Handle(Library::CoreLibrary()); |
189 | 188 |
190 const String& expression = String::Handle(String::New( | 189 const String& expression = String::Handle(String::New( |
191 "(){ return (){ return (){ return 3 + 4; }(); }(); }()")); | 190 "(){ return (){ return (){ return 3 + 4; }(); }(); }()")); |
192 Object& val = Object::Handle(); | 191 Object& val = Object::Handle(); |
193 val = lib.Evaluate(expression, Array::empty_array(), Array::empty_array()); | 192 val = lib.Evaluate(expression, Array::empty_array(), Array::empty_array()); |
194 | 193 |
195 EXPECT(!val.IsNull()); | 194 EXPECT(!val.IsNull()); |
196 EXPECT(!val.IsError()); | 195 EXPECT(!val.IsError()); |
197 EXPECT(val.IsInteger()); | 196 EXPECT(val.IsInteger()); |
(...skipping 23 matching lines...) Expand all Loading... |
221 EXPECT(val.IsInteger()); | 220 EXPECT(val.IsInteger()); |
222 EXPECT_EQ(7, Integer::Cast(val).AsInt64Value()); | 221 EXPECT_EQ(7, Integer::Cast(val).AsInt64Value()); |
223 | 222 |
224 intptr_t final_class_table_size = | 223 intptr_t final_class_table_size = |
225 Isolate::Current()->class_table()->NumCids(); | 224 Isolate::Current()->class_table()->NumCids(); |
226 // Eval should not eat into this non-renewable resource. | 225 // Eval should not eat into this non-renewable resource. |
227 EXPECT_EQ(initial_class_table_size, final_class_table_size); | 226 EXPECT_EQ(initial_class_table_size, final_class_table_size); |
228 } | 227 } |
229 | 228 |
230 } // namespace dart | 229 } // namespace dart |
OLD | NEW |