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 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) | 7 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) |
8 | 8 |
9 #include "vm/ast.h" | 9 #include "vm/ast.h" |
10 #include "vm/assembler.h" | 10 #include "vm/assembler.h" |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 Function::Handle(cls.LookupStaticFunction(function_moo_name)); | 185 Function::Handle(cls.LookupStaticFunction(function_moo_name)); |
186 EXPECT(CompilerTest::TestCompileFunction(function_moo)); | 186 EXPECT(CompilerTest::TestCompileFunction(function_moo)); |
187 EXPECT(function_moo.HasCode()); | 187 EXPECT(function_moo.HasCode()); |
188 | 188 |
189 String& function_foo_name = String::Handle(String::New("foo")); | 189 String& function_foo_name = String::Handle(String::New("foo")); |
190 Function& function_foo = | 190 Function& function_foo = |
191 Function::Handle(cls.LookupStaticFunction(function_foo_name)); | 191 Function::Handle(cls.LookupStaticFunction(function_foo_name)); |
192 EXPECT(CompilerTest::TestCompileFunction(function_foo)); | 192 EXPECT(CompilerTest::TestCompileFunction(function_foo)); |
193 EXPECT(function_foo.HasCode()); | 193 EXPECT(function_foo.HasCode()); |
194 | 194 |
195 // Build and setup a stackmap for function 'A.foo' in order to test the | 195 // Build and setup a stackmap for the call to 'func' in 'A.foo' in order |
196 // traversal of stack maps when a GC happens. | 196 // to test the traversal of stack maps when a GC happens. |
197 StackmapBuilder* builder = new StackmapBuilder(); | 197 StackmapBuilder* builder = new StackmapBuilder(); |
198 EXPECT(builder != NULL); | 198 EXPECT(builder != NULL); |
199 builder->SetSlotAsValue(0); // var i. | 199 builder->SetSlotAsValue(0); // var i. |
200 builder->SetSlotAsObject(1); // var s1. | 200 builder->SetSlotAsObject(1); // var s1. |
201 builder->SetSlotAsValue(2); // var k. | 201 builder->SetSlotAsValue(2); // var k. |
202 builder->SetSlotAsObject(3); // var s2. | 202 builder->SetSlotAsObject(3); // var s2. |
203 builder->SetSlotAsObject(4); // var s3. | 203 builder->SetSlotAsObject(4); // var s3. |
| 204 builder->SetSlotAsObject(5); // First argument to func(i, k). |
| 205 builder->SetSlotAsObject(6); // Second argument to func(i, k). |
204 const Code& code = Code::Handle(function_foo.unoptimized_code()); | 206 const Code& code = Code::Handle(function_foo.unoptimized_code()); |
205 // Search for the pc of the call to 'func'. | 207 // Search for the pc of the call to 'func'. |
206 const PcDescriptors& descriptors = | 208 const PcDescriptors& descriptors = |
207 PcDescriptors::Handle(code.pc_descriptors()); | 209 PcDescriptors::Handle(code.pc_descriptors()); |
| 210 int call_count = 0; |
208 for (int i = 0; i < descriptors.Length(); ++i) { | 211 for (int i = 0; i < descriptors.Length(); ++i) { |
209 if (descriptors.DescriptorKind(i) == PcDescriptors::kFuncCall) { | 212 if (descriptors.DescriptorKind(i) == PcDescriptors::kFuncCall) { |
210 builder->AddEntry(descriptors.PC(i) - code.EntryPoint()); | 213 builder->AddEntry(descriptors.PC(i) - code.EntryPoint()); |
| 214 ++call_count; |
211 } | 215 } |
212 } | 216 } |
| 217 // We can't easily check that we put the stackmap at the correct pc, but |
| 218 // we did if there was exactly one call seen. |
| 219 EXPECT(call_count == 1); |
213 const Array& stack_maps = Array::Handle(builder->FinalizeStackmaps(code)); | 220 const Array& stack_maps = Array::Handle(builder->FinalizeStackmaps(code)); |
214 code.set_stackmaps(stack_maps); | 221 code.set_stackmaps(stack_maps); |
215 | 222 |
216 // Now invoke 'A.moo' and it will trigger a GC when the native function | 223 // Now invoke 'A.moo' and it will trigger a GC when the native function |
217 // is called, this should then cause the stack map of function 'A.foo' | 224 // is called, this should then cause the stack map of function 'A.foo' |
218 // to be traversed and the appropriate objects visited. | 225 // to be traversed and the appropriate objects visited. |
219 GrowableArray<const Object*> arguments; | 226 GrowableArray<const Object*> arguments; |
220 const Array& kNoArgumentNames = Array::Handle(); | 227 const Array& kNoArgumentNames = Array::Handle(); |
221 Object& result = Object::Handle(); | 228 Object& result = Object::Handle(); |
222 result = DartEntry::InvokeStatic(function_foo, arguments, kNoArgumentNames); | 229 result = DartEntry::InvokeStatic(function_foo, arguments, kNoArgumentNames); |
223 EXPECT(!result.IsError()); | 230 EXPECT(!result.IsError()); |
224 } | 231 } |
225 | 232 |
226 } // namespace dart | 233 } // namespace dart |
227 | 234 |
228 #endif // defined TARGET_ARCH_IA32 || defined(TARGET_ARCH_X64) | 235 #endif // defined TARGET_ARCH_IA32 || defined(TARGET_ARCH_X64) |
OLD | NEW |