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

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

Issue 10832292: Reduce space used for stackmaps. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Restore inadvertently deleted code. 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 a stackmap table and some stackmap table entries. 57 // Build a stackmap table and some stackmap table entries.
58 StackmapTableBuilder* stackmap_table_builder = new StackmapTableBuilder(); 58 StackmapTableBuilder* stackmap_table_builder = new StackmapTableBuilder(11);
59 EXPECT(stackmap_table_builder != NULL); 59 EXPECT(stackmap_table_builder != NULL);
60 BitmapBuilder* stackmap = new BitmapBuilder(); 60 BitmapBuilder* stack_bitmap = new BitmapBuilder();
61 EXPECT(stackmap != NULL); 61 EXPECT(stack_bitmap != NULL);
62 stackmap->Set(0, true); 62 stack_bitmap->Set(0, true);
63 EXPECT(stackmap->Get(0)); 63 EXPECT(stack_bitmap->Get(0));
64 // Add a stack map entry at pc offset 0. 64 // Add a stack map entry at pc offset 0.
65 stackmap_table_builder->AddEntry(0, stackmap); 65 stackmap_table_builder->AddEntry(0, stack_bitmap);
66 66
67 stackmap = new BitmapBuilder(); 67 stack_bitmap = new BitmapBuilder();
68 EXPECT(stackmap != NULL); 68 EXPECT(stack_bitmap != NULL);
69 stackmap->Set(0, true); 69 stack_bitmap->Set(0, true);
70 stackmap->Set(1, false); 70 stack_bitmap->Set(1, false);
71 stackmap->Set(2, true); 71 stack_bitmap->Set(2, true);
72 EXPECT(stackmap->Get(0)); 72 EXPECT(stack_bitmap->Get(0));
73 EXPECT(!stackmap->Get(1)); 73 EXPECT(!stack_bitmap->Get(1));
74 EXPECT(stackmap->Get(2)); 74 EXPECT(stack_bitmap->Get(2));
75 // Add a stack map entry at pc offset 1. 75 // Add a stack map entry at pc offset 1.
76 stackmap_table_builder->AddEntry(1, stackmap); 76 stackmap_table_builder->AddEntry(1, stack_bitmap);
77 77
78 stackmap = new BitmapBuilder(); 78 stack_bitmap = new BitmapBuilder();
79 EXPECT(stackmap != NULL); 79 EXPECT(stack_bitmap != NULL);
80 stackmap->Set(0, true); 80 stack_bitmap->Set(0, true);
81 stackmap->Set(1, false); 81 stack_bitmap->Set(1, false);
82 stackmap->Set(2, true); 82 stack_bitmap->Set(2, true);
83 stackmap->SetRange(3, 5, true); 83 stack_bitmap->SetRange(3, 5, true);
84 EXPECT(stackmap->Get(0)); 84 EXPECT(stack_bitmap->Get(0));
85 EXPECT(!stackmap->Get(1)); 85 EXPECT(!stack_bitmap->Get(1));
86 EXPECT(stackmap->Get(2)); 86 EXPECT(stack_bitmap->Get(2));
87 for (intptr_t i = 3; i <= 5; i++) { 87 for (intptr_t i = 3; i <= 5; i++) {
88 EXPECT(stackmap->Get(i)); 88 EXPECT(stack_bitmap->Get(i));
89 } 89 }
90 // Add a stack map entry at pc offset 2. 90 // Add a stack map entry at pc offset 2.
91 stackmap_table_builder->AddEntry(2, stackmap); 91 stackmap_table_builder->AddEntry(2, stack_bitmap);
92 92
93 stackmap = new BitmapBuilder(); 93 stack_bitmap = new BitmapBuilder();
94 EXPECT(stackmap != NULL); 94 EXPECT(stack_bitmap != NULL);
95 stackmap->Set(0, true); 95 stack_bitmap->Set(0, true);
96 stackmap->Set(1, false); 96 stack_bitmap->Set(1, false);
97 stackmap->Set(2, true); 97 stack_bitmap->Set(2, true);
98 stackmap->SetRange(3, 5, true); 98 stack_bitmap->SetRange(3, 5, true);
99 stackmap->SetRange(6, 9, false); 99 stack_bitmap->SetRange(6, 9, false);
100 stackmap->Set(10, true); 100 stack_bitmap->Set(10, true);
101 EXPECT(stackmap->Get(0)); 101 EXPECT(stack_bitmap->Get(0));
102 EXPECT(!stackmap->Get(1)); 102 EXPECT(!stack_bitmap->Get(1));
103 EXPECT(stackmap->Get(2)); 103 EXPECT(stack_bitmap->Get(2));
104 for (intptr_t i = 3; i <= 5; i++) { 104 for (intptr_t i = 3; i <= 5; i++) {
105 EXPECT(stackmap->Get(i)); 105 EXPECT(stack_bitmap->Get(i));
106 } 106 }
107 for (intptr_t i = 6; i <= 9; i++) { 107 for (intptr_t i = 6; i <= 9; i++) {
108 EXPECT(!stackmap->Get(i)); 108 EXPECT(!stack_bitmap->Get(i));
109 } 109 }
110 EXPECT(stackmap->Get(10)); 110 EXPECT(stack_bitmap->Get(10));
111 // Add a stack map entry at pc offset 3. 111 // Add a stack map entry at pc offset 3.
112 stackmap_table_builder->AddEntry(3, stackmap); 112 stackmap_table_builder->AddEntry(3, stack_bitmap);
113 113
114 const Error& error = 114 const Error& error =
115 Error::Handle(Compiler::CompileParsedFunction(parsed_function)); 115 Error::Handle(Compiler::CompileParsedFunction(parsed_function));
116 EXPECT(error.IsNull()); 116 EXPECT(error.IsNull());
117 const Code& code = Code::Handle(function.CurrentCode()); 117 const Code& code = Code::Handle(function.CurrentCode());
118 118
119 const Array& stack_maps = 119 const Array& stack_maps =
120 Array::Handle(stackmap_table_builder->FinalizeStackmaps(code)); 120 Array::Handle(stackmap_table_builder->FinalizeStackmaps(code));
121 code.set_stackmaps(stack_maps); 121 code.set_stackmaps(stack_maps);
122 const Array& stack_map_list = Array::Handle(code.stackmaps()); 122 const Array& stack_map_list = Array::Handle(code.stackmaps());
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 EXPECT(function_moo.HasCode()); 222 EXPECT(function_moo.HasCode());
223 223
224 String& function_foo_name = String::Handle(String::New("foo")); 224 String& function_foo_name = String::Handle(String::New("foo"));
225 Function& function_foo = 225 Function& function_foo =
226 Function::Handle(cls.LookupStaticFunction(function_foo_name)); 226 Function::Handle(cls.LookupStaticFunction(function_foo_name));
227 EXPECT(CompilerTest::TestCompileFunction(function_foo)); 227 EXPECT(CompilerTest::TestCompileFunction(function_foo));
228 EXPECT(function_foo.HasCode()); 228 EXPECT(function_foo.HasCode());
229 229
230 // 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
231 // to test the traversal of stack maps when a GC happens. 231 // to test the traversal of stack maps when a GC happens.
232 StackmapTableBuilder* stackmap_table_builder = new StackmapTableBuilder(); 232 StackmapTableBuilder* stackmap_table_builder = new StackmapTableBuilder(7);
233 EXPECT(stackmap_table_builder != NULL); 233 EXPECT(stackmap_table_builder != NULL);
234 BitmapBuilder* stackmap = new BitmapBuilder(); 234 BitmapBuilder* stack_bitmap = new BitmapBuilder();
235 EXPECT(stackmap != NULL); 235 EXPECT(stack_bitmap != NULL);
236 stackmap->Set(0, false); // var i. 236 stack_bitmap->Set(0, false); // var i.
237 stackmap->Set(1, true); // var s1. 237 stack_bitmap->Set(1, true); // var s1.
238 stackmap->Set(2, false); // var k. 238 stack_bitmap->Set(2, false); // var k.
239 stackmap->Set(3, true); // var s2. 239 stack_bitmap->Set(3, true); // var s2.
240 stackmap->Set(4, true); // var s3. 240 stack_bitmap->Set(4, true); // var s3.
241 stackmap->Set(5, true); // First argument to func(i, k). 241 stack_bitmap->Set(5, true); // First argument to func(i, k).
242 stackmap->Set(6, true); // Second argument to func(i, k). 242 stack_bitmap->Set(6, true); // Second argument to func(i, k).
243 const Code& code = Code::Handle(function_foo.unoptimized_code()); 243 const Code& code = Code::Handle(function_foo.unoptimized_code());
244 // Search for the pc of the call to 'func'. 244 // Search for the pc of the call to 'func'.
245 const PcDescriptors& descriptors = 245 const PcDescriptors& descriptors =
246 PcDescriptors::Handle(code.pc_descriptors()); 246 PcDescriptors::Handle(code.pc_descriptors());
247 int call_count = 0; 247 int call_count = 0;
248 for (int i = 0; i < descriptors.Length(); ++i) { 248 for (int i = 0; i < descriptors.Length(); ++i) {
249 if (descriptors.DescriptorKind(i) == PcDescriptors::kFuncCall) { 249 if (descriptors.DescriptorKind(i) == PcDescriptors::kFuncCall) {
250 stackmap_table_builder->AddEntry(descriptors.PC(i) - code.EntryPoint(), 250 stackmap_table_builder->AddEntry(descriptors.PC(i) - code.EntryPoint(),
251 stackmap); 251 stack_bitmap);
252 ++call_count; 252 ++call_count;
253 } 253 }
254 } 254 }
255 // 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
256 // we did if there was exactly one call seen. 256 // we did if there was exactly one call seen.
257 EXPECT(call_count == 1); 257 EXPECT(call_count == 1);
258 const Array& stack_maps = 258 const Array& stack_maps =
259 Array::Handle(stackmap_table_builder->FinalizeStackmaps(code)); 259 Array::Handle(stackmap_table_builder->FinalizeStackmaps(code));
260 code.set_stackmaps(stack_maps); 260 code.set_stackmaps(stack_maps);
261 261
262 // 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
263 // 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'
264 // to be traversed and the appropriate objects visited. 264 // to be traversed and the appropriate objects visited.
265 GrowableArray<const Object*> arguments; 265 GrowableArray<const Object*> arguments;
266 const Array& kNoArgumentNames = Array::Handle(); 266 const Array& kNoArgumentNames = Array::Handle();
267 Object& result = Object::Handle(); 267 Object& result = Object::Handle();
268 result = DartEntry::InvokeStatic(function_foo, arguments, kNoArgumentNames); 268 result = DartEntry::InvokeStatic(function_foo, arguments, kNoArgumentNames);
269 EXPECT(!result.IsError()); 269 EXPECT(!result.IsError());
270 } 270 }
271 271
272 } // namespace dart 272 } // namespace dart
273 273
274 #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