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

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

Issue 10825077: Change the stackmap builder API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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 | Annotate | Revision Log
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/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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 parsed_function.set_instantiator(NULL); 47 parsed_function.set_instantiator(NULL);
48 parsed_function.set_default_parameter_values(Array::Handle()); 48 parsed_function.set_default_parameter_values(Array::Handle());
49 parsed_function.AllocateVariables(); 49 parsed_function.AllocateVariables();
50 bool retval; 50 bool retval;
51 Isolate* isolate = Isolate::Current(); 51 Isolate* isolate = Isolate::Current();
52 EXPECT(isolate != NULL); 52 EXPECT(isolate != NULL);
53 LongJump* base = isolate->long_jump_base(); 53 LongJump* base = isolate->long_jump_base();
54 LongJump jump; 54 LongJump jump;
55 isolate->set_long_jump_base(&jump); 55 isolate->set_long_jump_base(&jump);
56 if (setjmp(*jump.Set()) == 0) { 56 if (setjmp(*jump.Set()) == 0) {
57 // Build some stack map entries. 57 // Build a stackmap table and some stackmap table entries.
58 StackmapBuilder* builder = new StackmapBuilder(); 58 StackmapTableBuilder* stackmap_table_builder = new StackmapTableBuilder();
59 EXPECT(builder != NULL); 59 EXPECT(stackmap_table_builder != NULL);
60 builder->SetSlotAsObject(0); 60 BitmapBuilder* stackmap = new BitmapBuilder();
61 EXPECT(builder->IsSlotObject(0)); 61 EXPECT(stackmap != NULL);
62 builder->AddEntry(0); // Add a stack map entry at pc offset 0. 62 stackmap->Set(0, true);
63 builder->SetSlotAsValue(1); 63 EXPECT(stackmap->Get(0));
64 EXPECT(!builder->IsSlotObject(1)); 64 // Add a stack map entry at pc offset 0.
65 builder->SetSlotAsObject(2); 65 stackmap_table_builder->AddEntry(0, stackmap);
66 EXPECT(builder->IsSlotObject(2)); 66
67 builder->AddEntry(1); // Add a stack map entry at pc offset 1. 67 stackmap = new BitmapBuilder();
68 builder->SetSlotRangeAsObject(3, 5); 68 EXPECT(stackmap != NULL);
69 stackmap->Set(0, true);
70 stackmap->Set(1, false);
71 stackmap->Set(2, true);
72 EXPECT(stackmap->Get(0));
73 EXPECT(!stackmap->Get(1));
74 EXPECT(stackmap->Get(2));
siva 2012/07/31 19:03:01 Case in point here, this code is not readable at a
75 // Add a stack map entry at pc offset 1.
76 stackmap_table_builder->AddEntry(1, stackmap);
77
78 stackmap = new BitmapBuilder();
79 EXPECT(stackmap != NULL);
80 stackmap->Set(0, true);
81 stackmap->Set(1, false);
82 stackmap->Set(2, true);
83 stackmap->SetRange(3, 5, true);
84 EXPECT(stackmap->Get(0));
85 EXPECT(!stackmap->Get(1));
86 EXPECT(stackmap->Get(2));
69 for (intptr_t i = 3; i <= 5; i++) { 87 for (intptr_t i = 3; i <= 5; i++) {
70 EXPECT(builder->IsSlotObject(i)); 88 EXPECT(stackmap->Get(i));
71 } 89 }
72 builder->AddEntry(2); // Add a stack map entry at pc offset 2. 90 // Add a stack map entry at pc offset 2.
73 builder->SetSlotRangeAsValue(6, 9); 91 stackmap_table_builder->AddEntry(2, stackmap);
92
93 stackmap = new BitmapBuilder();
94 EXPECT(stackmap != NULL);
95 stackmap->Set(0, true);
96 stackmap->Set(1, false);
97 stackmap->Set(2, true);
98 stackmap->SetRange(3, 5, true);
99 stackmap->SetRange(6, 9, false);
100 stackmap->Set(10, true);
101 EXPECT(stackmap->Get(0));
102 EXPECT(!stackmap->Get(1));
103 EXPECT(stackmap->Get(2));
104 for (intptr_t i = 3; i <= 5; i++) {
105 EXPECT(stackmap->Get(i));
106 }
74 for (intptr_t i = 6; i <= 9; i++) { 107 for (intptr_t i = 6; i <= 9; i++) {
75 EXPECT(!builder->IsSlotObject(i)); 108 EXPECT(!stackmap->Get(i));
76 } 109 }
77 builder->SetSlotAsObject(10); 110 EXPECT(stackmap->Get(10));
78 EXPECT(builder->IsSlotObject(10)); 111 // Add a stack map entry at pc offset 3.
79 builder->AddEntry(3); // Add a stack map entry at pc offset 3. 112 stackmap_table_builder->AddEntry(3, stackmap);
80 113
81 const Error& error = 114 const Error& error =
82 Error::Handle(Compiler::CompileParsedFunction(parsed_function)); 115 Error::Handle(Compiler::CompileParsedFunction(parsed_function));
83 EXPECT(error.IsNull()); 116 EXPECT(error.IsNull());
84 const Code& code = Code::Handle(function.CurrentCode()); 117 const Code& code = Code::Handle(function.CurrentCode());
85 118
86 const Array& stack_maps = Array::Handle(builder->FinalizeStackmaps(code)); 119 const Array& stack_maps =
120 Array::Handle(stackmap_table_builder->FinalizeStackmaps(code));
87 code.set_stackmaps(stack_maps); 121 code.set_stackmaps(stack_maps);
88 const Array& stack_map_list = Array::Handle(code.stackmaps()); 122 const Array& stack_map_list = Array::Handle(code.stackmaps());
89 EXPECT(!stack_map_list.IsNull()); 123 EXPECT(!stack_map_list.IsNull());
90 Stackmap& stack_map = Stackmap::Handle(); 124 Stackmap& stack_map = Stackmap::Handle();
91 EXPECT_EQ(4, stack_map_list.Length()); 125 EXPECT_EQ(4, stack_map_list.Length());
92 126
93 // Validate the first stack map entry. 127 // Validate the first stack map entry.
94 stack_map ^= stack_map_list.At(0); 128 stack_map ^= stack_map_list.At(0);
95 EXPECT(stack_map.IsObject(0)); 129 EXPECT(stack_map.IsObject(0));
96 EXPECT_EQ(0, stack_map.MinimumBitIndex()); 130 EXPECT_EQ(0, stack_map.MinimumBitIndex());
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 EXPECT(function_moo.HasCode()); 222 EXPECT(function_moo.HasCode());
189 223
190 String& function_foo_name = String::Handle(String::New("foo")); 224 String& function_foo_name = String::Handle(String::New("foo"));
191 Function& function_foo = 225 Function& function_foo =
192 Function::Handle(cls.LookupStaticFunction(function_foo_name)); 226 Function::Handle(cls.LookupStaticFunction(function_foo_name));
193 EXPECT(CompilerTest::TestCompileFunction(function_foo)); 227 EXPECT(CompilerTest::TestCompileFunction(function_foo));
194 EXPECT(function_foo.HasCode()); 228 EXPECT(function_foo.HasCode());
195 229
196 // Build and setup a stackmap for the call to 'func' in 'A.foo' in order 230 // Build and setup a stackmap for the call to 'func' in 'A.foo' in order
197 // to test the traversal of stack maps when a GC happens. 231 // to test the traversal of stack maps when a GC happens.
198 StackmapBuilder* builder = new StackmapBuilder(); 232 StackmapTableBuilder* stackmap_table_builder = new StackmapTableBuilder();
199 EXPECT(builder != NULL); 233 EXPECT(stackmap_table_builder != NULL);
200 builder->SetSlotAsValue(0); // var i. 234 BitmapBuilder* stackmap = new BitmapBuilder();
201 builder->SetSlotAsObject(1); // var s1. 235 EXPECT(stackmap != NULL);
202 builder->SetSlotAsValue(2); // var k. 236 stackmap->Set(0, false); // var i.
203 builder->SetSlotAsObject(3); // var s2. 237 stackmap->Set(1, true); // var s1.
204 builder->SetSlotAsObject(4); // var s3. 238 stackmap->Set(2, false); // var k.
205 builder->SetSlotAsObject(5); // First argument to func(i, k). 239 stackmap->Set(3, true); // var s2.
206 builder->SetSlotAsObject(6); // Second argument to func(i, k). 240 stackmap->Set(4, true); // var s3.
241 stackmap->Set(5, true); // First argument to func(i, k).
242 stackmap->Set(6, true); // Second argument to func(i, k).
siva 2012/07/31 19:03:01 Ditto comment about readability of this code compa
207 const Code& code = Code::Handle(function_foo.unoptimized_code()); 243 const Code& code = Code::Handle(function_foo.unoptimized_code());
208 // Search for the pc of the call to 'func'. 244 // Search for the pc of the call to 'func'.
209 const PcDescriptors& descriptors = 245 const PcDescriptors& descriptors =
210 PcDescriptors::Handle(code.pc_descriptors()); 246 PcDescriptors::Handle(code.pc_descriptors());
211 int call_count = 0; 247 int call_count = 0;
212 for (int i = 0; i < descriptors.Length(); ++i) { 248 for (int i = 0; i < descriptors.Length(); ++i) {
213 if (descriptors.DescriptorKind(i) == PcDescriptors::kFuncCall) { 249 if (descriptors.DescriptorKind(i) == PcDescriptors::kFuncCall) {
214 builder->AddEntry(descriptors.PC(i) - code.EntryPoint()); 250 stackmap_table_builder->AddEntry(descriptors.PC(i) - code.EntryPoint(),
251 stackmap);
215 ++call_count; 252 ++call_count;
216 } 253 }
217 } 254 }
218 // We can't easily check that we put the stackmap at the correct pc, but 255 // We can't easily check that we put the stackmap at the correct pc, but
219 // we did if there was exactly one call seen. 256 // we did if there was exactly one call seen.
220 EXPECT(call_count == 1); 257 EXPECT(call_count == 1);
221 const Array& stack_maps = Array::Handle(builder->FinalizeStackmaps(code)); 258 const Array& stack_maps =
259 Array::Handle(stackmap_table_builder->FinalizeStackmaps(code));
222 code.set_stackmaps(stack_maps); 260 code.set_stackmaps(stack_maps);
223 261
224 // Now invoke 'A.moo' and it will trigger a GC when the native function 262 // Now invoke 'A.moo' and it will trigger a GC when the native function
225 // is called, this should then cause the stack map of function 'A.foo' 263 // is called, this should then cause the stack map of function 'A.foo'
226 // to be traversed and the appropriate objects visited. 264 // to be traversed and the appropriate objects visited.
227 GrowableArray<const Object*> arguments; 265 GrowableArray<const Object*> arguments;
228 const Array& kNoArgumentNames = Array::Handle(); 266 const Array& kNoArgumentNames = Array::Handle();
229 Object& result = Object::Handle(); 267 Object& result = Object::Handle();
230 result = DartEntry::InvokeStatic(function_foo, arguments, kNoArgumentNames); 268 result = DartEntry::InvokeStatic(function_foo, arguments, kNoArgumentNames);
231 EXPECT(!result.IsError()); 269 EXPECT(!result.IsError());
232 } 270 }
233 271
234 } // namespace dart 272 } // namespace dart
235 273
236 #endif // defined TARGET_ARCH_IA32 || defined(TARGET_ARCH_X64) 274 #endif // defined TARGET_ARCH_IA32 || defined(TARGET_ARCH_X64)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698