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/globals.h" | 6 #include "vm/globals.h" |
7 | 7 |
| 8 #include "vm/assembler.h" |
8 #include "vm/ast.h" | 9 #include "vm/ast.h" |
9 #include "vm/assembler.h" | |
10 #include "vm/code_descriptors.h" | 10 #include "vm/code_descriptors.h" |
11 #include "vm/compiler.h" | 11 #include "vm/compiler.h" |
12 #include "vm/dart_entry.h" | 12 #include "vm/dart_entry.h" |
13 #include "vm/native_entry.h" | 13 #include "vm/native_entry.h" |
14 #include "vm/parser.h" | 14 #include "vm/parser.h" |
15 #include "vm/symbols.h" | 15 #include "vm/symbols.h" |
16 #include "vm/thread.h" | 16 #include "vm/thread.h" |
17 #include "vm/unit_test.h" | 17 #include "vm/unit_test.h" |
18 | 18 |
19 namespace dart { | 19 namespace dart { |
20 | 20 |
21 static const TokenPosition kPos = TokenPosition::kNoSource; | 21 static const TokenPosition kPos = TokenPosition::kNoSource; |
22 | 22 |
23 | |
24 CODEGEN_TEST_GENERATE(StackMapCodegen, test) { | 23 CODEGEN_TEST_GENERATE(StackMapCodegen, test) { |
25 ParsedFunction* parsed_function = | 24 ParsedFunction* parsed_function = |
26 new ParsedFunction(Thread::Current(), test->function()); | 25 new ParsedFunction(Thread::Current(), test->function()); |
27 LiteralNode* l = new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(1))); | 26 LiteralNode* l = new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(1))); |
28 test->node_sequence()->Add(new ReturnNode(kPos, l)); | 27 test->node_sequence()->Add(new ReturnNode(kPos, l)); |
29 l = new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(2))); | 28 l = new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(2))); |
30 test->node_sequence()->Add(new ReturnNode(kPos, l)); | 29 test->node_sequence()->Add(new ReturnNode(kPos, l)); |
31 l = new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(3))); | 30 l = new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(3))); |
32 test->node_sequence()->Add(new ReturnNode(kPos, l)); | 31 test->node_sequence()->Add(new ReturnNode(kPos, l)); |
33 parsed_function->SetNodeSequence(test->node_sequence()); | 32 parsed_function->SetNodeSequence(test->node_sequence()); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 EXPECT_EQ(expectation3[i], stack_map.IsObject(i)); | 158 EXPECT_EQ(expectation3[i], stack_map.IsObject(i)); |
160 } | 159 } |
161 retval = true; | 160 retval = true; |
162 } else { | 161 } else { |
163 retval = false; | 162 retval = false; |
164 } | 163 } |
165 EXPECT(retval); | 164 EXPECT(retval); |
166 } | 165 } |
167 CODEGEN_TEST_RUN(StackMapCodegen, Smi::New(1)) | 166 CODEGEN_TEST_RUN(StackMapCodegen, Smi::New(1)) |
168 | 167 |
169 | |
170 static void NativeFunc(Dart_NativeArguments args) { | 168 static void NativeFunc(Dart_NativeArguments args) { |
171 Dart_Handle i = Dart_GetNativeArgument(args, 0); | 169 Dart_Handle i = Dart_GetNativeArgument(args, 0); |
172 Dart_Handle k = Dart_GetNativeArgument(args, 1); | 170 Dart_Handle k = Dart_GetNativeArgument(args, 1); |
173 int64_t value = -1; | 171 int64_t value = -1; |
174 EXPECT_VALID(Dart_IntegerToInt64(i, &value)); | 172 EXPECT_VALID(Dart_IntegerToInt64(i, &value)); |
175 EXPECT_EQ(10, value); | 173 EXPECT_EQ(10, value); |
176 EXPECT_VALID(Dart_IntegerToInt64(k, &value)); | 174 EXPECT_VALID(Dart_IntegerToInt64(k, &value)); |
177 EXPECT_EQ(20, value); | 175 EXPECT_EQ(20, value); |
178 { | 176 { |
179 TransitionNativeToVM transition(Thread::Current()); | 177 TransitionNativeToVM transition(Thread::Current()); |
180 Isolate::Current()->heap()->CollectAllGarbage(); | 178 Isolate::Current()->heap()->CollectAllGarbage(); |
181 } | 179 } |
182 } | 180 } |
183 | 181 |
184 | |
185 static Dart_NativeFunction native_resolver(Dart_Handle name, | 182 static Dart_NativeFunction native_resolver(Dart_Handle name, |
186 int argument_count, | 183 int argument_count, |
187 bool* auto_setup_scope) { | 184 bool* auto_setup_scope) { |
188 ASSERT(auto_setup_scope); | 185 ASSERT(auto_setup_scope); |
189 *auto_setup_scope = false; | 186 *auto_setup_scope = false; |
190 return reinterpret_cast<Dart_NativeFunction>(&NativeFunc); | 187 return reinterpret_cast<Dart_NativeFunction>(&NativeFunc); |
191 } | 188 } |
192 | 189 |
193 | |
194 TEST_CASE(StackMapGC) { | 190 TEST_CASE(StackMapGC) { |
195 const char* kScriptChars = | 191 const char* kScriptChars = |
196 "class A {" | 192 "class A {" |
197 " static void func(var i, var k) native 'NativeFunc';" | 193 " static void func(var i, var k) native 'NativeFunc';" |
198 " static foo() {" | 194 " static foo() {" |
199 " var i;" | 195 " var i;" |
200 " var s1;" | 196 " var s1;" |
201 " var k;" | 197 " var k;" |
202 " var s2;" | 198 " var s2;" |
203 " var s3;" | 199 " var s3;" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 code.set_stackmaps(stack_maps); | 259 code.set_stackmaps(stack_maps); |
264 | 260 |
265 // Now invoke 'A.moo' and it will trigger a GC when the native function | 261 // Now invoke 'A.moo' and it will trigger a GC when the native function |
266 // is called, this should then cause the stack map of function 'A.foo' | 262 // is called, this should then cause the stack map of function 'A.foo' |
267 // to be traversed and the appropriate objects visited. | 263 // to be traversed and the appropriate objects visited. |
268 const Object& result = Object::Handle( | 264 const Object& result = Object::Handle( |
269 DartEntry::InvokeFunction(function_foo, Object::empty_array())); | 265 DartEntry::InvokeFunction(function_foo, Object::empty_array())); |
270 EXPECT(!result.IsError()); | 266 EXPECT(!result.IsError()); |
271 } | 267 } |
272 | 268 |
273 | |
274 TEST_CASE(DescriptorList_TokenPositions) { | 269 TEST_CASE(DescriptorList_TokenPositions) { |
275 DescriptorList* descriptors = new DescriptorList(64); | 270 DescriptorList* descriptors = new DescriptorList(64); |
276 ASSERT(descriptors != NULL); | 271 ASSERT(descriptors != NULL); |
277 const intptr_t token_positions[] = { | 272 const intptr_t token_positions[] = { |
278 kMinInt32, | 273 kMinInt32, |
279 5, | 274 5, |
280 13, | 275 13, |
281 13, | 276 13, |
282 13, | 277 13, |
283 13, | 278 13, |
(...skipping 28 matching lines...) Expand all Loading... |
312 if (token_positions[i] != it.TokenPos().value()) { | 307 if (token_positions[i] != it.TokenPos().value()) { |
313 OS::Print("[%" Pd "]: Expected: %" Pd " != %" Pd "\n", i, | 308 OS::Print("[%" Pd "]: Expected: %" Pd " != %" Pd "\n", i, |
314 token_positions[i], it.TokenPos().value()); | 309 token_positions[i], it.TokenPos().value()); |
315 } | 310 } |
316 EXPECT(token_positions[i] == it.TokenPos().value()); | 311 EXPECT(token_positions[i] == it.TokenPos().value()); |
317 i++; | 312 i++; |
318 } | 313 } |
319 } | 314 } |
320 | 315 |
321 } // namespace dart | 316 } // namespace dart |
OLD | NEW |