Chromium Code Reviews| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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(11); | 58 const intptr_t kStackSlotCount = 11; |
| 59 StackmapTableBuilder* stackmap_table_builder = | |
| 60 new StackmapTableBuilder(kStackSlotCount); | |
| 59 EXPECT(stackmap_table_builder != NULL); | 61 EXPECT(stackmap_table_builder != NULL); |
| 62 | |
| 60 BitmapBuilder* stack_bitmap = new BitmapBuilder(); | 63 BitmapBuilder* stack_bitmap = new BitmapBuilder(); |
| 61 EXPECT(stack_bitmap != NULL); | 64 EXPECT(stack_bitmap != NULL); |
| 62 stack_bitmap->Set(0, true); | 65 stack_bitmap->Set(0, true); |
| 63 EXPECT(stack_bitmap->Get(0)); | 66 bool expectation0[kStackSlotCount] = { true }; |
| 67 for (intptr_t i = 0; i < kStackSlotCount; ++i) { | |
| 68 EXPECT_EQ(expectation0[i], stack_bitmap->Get(i)); | |
| 69 } | |
| 64 // Add a stack map entry at pc offset 0. | 70 // Add a stack map entry at pc offset 0. |
| 65 stackmap_table_builder->AddEntry(0, stack_bitmap); | 71 stackmap_table_builder->AddEntry(0, stack_bitmap); |
| 66 | 72 |
| 67 stack_bitmap = new BitmapBuilder(); | 73 stack_bitmap = new BitmapBuilder(); |
| 68 EXPECT(stack_bitmap != NULL); | 74 EXPECT(stack_bitmap != NULL); |
| 69 stack_bitmap->Set(0, true); | 75 stack_bitmap->Set(0, true); |
| 70 stack_bitmap->Set(1, false); | 76 stack_bitmap->Set(1, false); |
| 71 stack_bitmap->Set(2, true); | 77 stack_bitmap->Set(2, true); |
| 72 EXPECT(stack_bitmap->Get(0)); | 78 bool expectation1[kStackSlotCount] = { true, false, true }; |
| 73 EXPECT(!stack_bitmap->Get(1)); | 79 for (intptr_t i = 0; i < kStackSlotCount; ++i) { |
| 74 EXPECT(stack_bitmap->Get(2)); | 80 EXPECT_EQ(expectation1[i], stack_bitmap->Get(i)); |
| 81 } | |
| 75 // Add a stack map entry at pc offset 1. | 82 // Add a stack map entry at pc offset 1. |
| 76 stackmap_table_builder->AddEntry(1, stack_bitmap); | 83 stackmap_table_builder->AddEntry(1, stack_bitmap); |
| 77 | 84 |
| 78 stack_bitmap = new BitmapBuilder(); | 85 stack_bitmap = new BitmapBuilder(); |
| 79 EXPECT(stack_bitmap != NULL); | 86 EXPECT(stack_bitmap != NULL); |
| 80 stack_bitmap->Set(0, true); | 87 stack_bitmap->Set(0, true); |
| 81 stack_bitmap->Set(1, false); | 88 stack_bitmap->Set(1, false); |
| 82 stack_bitmap->Set(2, true); | 89 stack_bitmap->Set(2, true); |
| 83 stack_bitmap->SetRange(3, 5, true); | 90 stack_bitmap->SetRange(3, 5, true); |
| 84 EXPECT(stack_bitmap->Get(0)); | 91 bool expectation2[kStackSlotCount] = |
| 85 EXPECT(!stack_bitmap->Get(1)); | 92 { true, false, true, true, true, true }; |
| 86 EXPECT(stack_bitmap->Get(2)); | 93 for (intptr_t i = 0; i < kStackSlotCount; ++i) { |
| 87 for (intptr_t i = 3; i <= 5; i++) { | 94 EXPECT_EQ(expectation2[i], stack_bitmap->Get(i)); |
| 88 EXPECT(stack_bitmap->Get(i)); | |
| 89 } | 95 } |
| 90 // Add a stack map entry at pc offset 2. | 96 // Add a stack map entry at pc offset 2. |
| 91 stackmap_table_builder->AddEntry(2, stack_bitmap); | 97 stackmap_table_builder->AddEntry(2, stack_bitmap); |
| 92 | 98 |
| 93 stack_bitmap = new BitmapBuilder(); | 99 stack_bitmap = new BitmapBuilder(); |
| 94 EXPECT(stack_bitmap != NULL); | 100 EXPECT(stack_bitmap != NULL); |
| 95 stack_bitmap->Set(0, true); | 101 stack_bitmap->Set(0, true); |
| 96 stack_bitmap->Set(1, false); | 102 stack_bitmap->Set(1, false); |
| 97 stack_bitmap->Set(2, true); | 103 stack_bitmap->Set(2, true); |
| 98 stack_bitmap->SetRange(3, 5, true); | 104 stack_bitmap->SetRange(3, 5, true); |
| 99 stack_bitmap->SetRange(6, 9, false); | 105 stack_bitmap->SetRange(6, 9, false); |
| 100 stack_bitmap->Set(10, true); | 106 stack_bitmap->Set(10, true); |
| 101 EXPECT(stack_bitmap->Get(0)); | 107 bool expectation3[kStackSlotCount] = |
| 102 EXPECT(!stack_bitmap->Get(1)); | 108 { true, false, true, true, true, true, false, false, |
| 103 EXPECT(stack_bitmap->Get(2)); | 109 false, false, true }; |
| 104 for (intptr_t i = 3; i <= 5; i++) { | 110 for (intptr_t i = 0; i < kStackSlotCount; ++i) { |
| 105 EXPECT(stack_bitmap->Get(i)); | 111 EXPECT_EQ(expectation3[i], stack_bitmap->Get(i)); |
| 106 } | 112 } |
| 107 for (intptr_t i = 6; i <= 9; i++) { | |
| 108 EXPECT(!stack_bitmap->Get(i)); | |
| 109 } | |
| 110 EXPECT(stack_bitmap->Get(10)); | |
| 111 // Add a stack map entry at pc offset 3. | 113 // Add a stack map entry at pc offset 3. |
| 112 stackmap_table_builder->AddEntry(3, stack_bitmap); | 114 stackmap_table_builder->AddEntry(3, stack_bitmap); |
| 113 | 115 |
| 114 const Error& error = | 116 const Error& error = |
| 115 Error::Handle(Compiler::CompileParsedFunction(parsed_function)); | 117 Error::Handle(Compiler::CompileParsedFunction(parsed_function)); |
| 116 EXPECT(error.IsNull()); | 118 EXPECT(error.IsNull()); |
| 117 const Code& code = Code::Handle(function.CurrentCode()); | 119 const Code& code = Code::Handle(function.CurrentCode()); |
| 118 | 120 |
| 119 const Array& stack_maps = | 121 const Array& stack_maps = |
| 120 Array::Handle(stackmap_table_builder->FinalizeStackmaps(code)); | 122 Array::Handle(stackmap_table_builder->FinalizeStackmaps(code)); |
| 121 code.set_stackmaps(stack_maps); | 123 code.set_stackmaps(stack_maps); |
| 122 const Array& stack_map_list = Array::Handle(code.stackmaps()); | 124 const Array& stack_map_list = Array::Handle(code.stackmaps()); |
| 123 EXPECT(!stack_map_list.IsNull()); | 125 EXPECT(!stack_map_list.IsNull()); |
| 124 Stackmap& stack_map = Stackmap::Handle(); | 126 Stackmap& stack_map = Stackmap::Handle(); |
| 125 EXPECT_EQ(4, stack_map_list.Length()); | 127 EXPECT_EQ(4, stack_map_list.Length()); |
| 126 | 128 |
| 127 // Validate the first stack map entry. | 129 // Validate the first stack map entry. |
| 128 stack_map ^= stack_map_list.At(0); | 130 stack_map ^= stack_map_list.At(0); |
| 129 EXPECT(stack_map.IsObject(0)); | 131 EXPECT_EQ(kStackSlotCount, stack_map.Length()); |
| 130 EXPECT_EQ(0, stack_map.MinimumBitIndex()); | 132 for (intptr_t i = 0; i < kStackSlotCount; ++i) { |
| 131 EXPECT_EQ(0, stack_map.MaximumBitIndex()); | 133 EXPECT_EQ(expectation0[i], stack_map.IsObject(i)); |
| 134 } | |
| 132 | 135 |
| 133 // Validate the second stack map entry. | 136 // Validate the second stack map entry. |
| 134 stack_map ^= stack_map_list.At(1); | 137 stack_map ^= stack_map_list.At(1); |
| 135 EXPECT(stack_map.IsObject(0)); | 138 EXPECT_EQ(kStackSlotCount, stack_map.Length()); |
| 136 EXPECT(!stack_map.IsObject(1)); | 139 for (intptr_t i = 0; i < kStackSlotCount; ++i) { |
| 137 EXPECT(stack_map.IsObject(2)); | 140 EXPECT_EQ(expectation1[i], stack_map.IsObject(i)); |
| 138 EXPECT_EQ(0, stack_map.MinimumBitIndex()); | 141 } |
| 139 EXPECT_EQ(2, stack_map.MaximumBitIndex()); | |
| 140 | 142 |
| 141 // Validate the third stack map entry. | 143 // Validate the third stack map entry. |
| 142 stack_map ^= stack_map_list.At(2); | 144 stack_map ^= stack_map_list.At(2); |
| 143 EXPECT(stack_map.IsObject(0)); | 145 EXPECT_EQ(kStackSlotCount, stack_map.Length()); |
| 144 EXPECT(!stack_map.IsObject(1)); | 146 for (intptr_t i = 0; i < kStackSlotCount; ++i) { |
| 145 for (intptr_t i = 2; i <= 5; i++) { | 147 EXPECT_EQ(expectation2[i], stack_map.IsObject(i)); |
| 146 EXPECT(stack_map.IsObject(i)); | |
| 147 } | 148 } |
| 148 EXPECT_EQ(0, stack_map.MinimumBitIndex()); | |
| 149 EXPECT_EQ(5, stack_map.MaximumBitIndex()); | |
| 150 | 149 |
| 151 // Validate the fourth stack map entry. | 150 // Validate the fourth stack map entry. |
| 152 stack_map ^= stack_map_list.At(3); | 151 stack_map ^= stack_map_list.At(3); |
| 153 EXPECT(stack_map.IsObject(0)); | 152 EXPECT_EQ(kStackSlotCount, stack_map.Length()); |
| 154 EXPECT(!stack_map.IsObject(1)); | 153 for (intptr_t i = 0; i < kStackSlotCount; ++i) { |
| 155 for (intptr_t i = 2; i <= 5; i++) { | 154 EXPECT_EQ(expectation3[i], stack_map.IsObject(i)); |
| 156 EXPECT(stack_map.IsObject(i)); | |
| 157 } | 155 } |
| 158 for (intptr_t i = 6; i <= 9; i++) { | |
| 159 EXPECT(!stack_map.IsObject(i)); | |
| 160 } | |
| 161 EXPECT(stack_map.IsObject(10)); | |
| 162 EXPECT_EQ(0, stack_map.MinimumBitIndex()); | |
| 163 EXPECT_EQ(10, stack_map.MaximumBitIndex()); | |
| 164 retval = true; | 156 retval = true; |
| 165 } else { | 157 } else { |
| 166 retval = false; | 158 retval = false; |
| 167 } | 159 } |
| 168 EXPECT(retval); | 160 EXPECT(retval); |
| 169 isolate->set_long_jump_base(base); | 161 isolate->set_long_jump_base(base); |
| 170 } | 162 } |
| 171 CODEGEN_TEST_RUN(StackmapCodegen, Smi::New(1)) | 163 CODEGEN_TEST_RUN(StackmapCodegen, Smi::New(1)) |
| 172 | 164 |
| 173 | 165 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 EXPECT(function_moo.HasCode()); | 214 EXPECT(function_moo.HasCode()); |
| 223 | 215 |
| 224 String& function_foo_name = String::Handle(String::New("foo")); | 216 String& function_foo_name = String::Handle(String::New("foo")); |
| 225 Function& function_foo = | 217 Function& function_foo = |
| 226 Function::Handle(cls.LookupStaticFunction(function_foo_name)); | 218 Function::Handle(cls.LookupStaticFunction(function_foo_name)); |
| 227 EXPECT(CompilerTest::TestCompileFunction(function_foo)); | 219 EXPECT(CompilerTest::TestCompileFunction(function_foo)); |
| 228 EXPECT(function_foo.HasCode()); | 220 EXPECT(function_foo.HasCode()); |
| 229 | 221 |
| 230 // Build and setup a stackmap for the call to 'func' in 'A.foo' in order | 222 // 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. | 223 // to test the traversal of stack maps when a GC happens. |
| 232 StackmapTableBuilder* stackmap_table_builder = new StackmapTableBuilder(7); | 224 StackmapTableBuilder* stackmap_table_builder = new StackmapTableBuilder(5); |
| 233 EXPECT(stackmap_table_builder != NULL); | 225 EXPECT(stackmap_table_builder != NULL); |
| 234 BitmapBuilder* stack_bitmap = new BitmapBuilder(); | 226 BitmapBuilder* stack_bitmap = new BitmapBuilder(); |
| 235 EXPECT(stack_bitmap != NULL); | 227 EXPECT(stack_bitmap != NULL); |
| 236 stack_bitmap->Set(0, false); // var i. | 228 stack_bitmap->Set(0, false); // var i. |
| 237 stack_bitmap->Set(1, true); // var s1. | 229 stack_bitmap->Set(1, true); // var s1. |
| 238 stack_bitmap->Set(2, false); // var k. | 230 stack_bitmap->Set(2, false); // var k. |
| 239 stack_bitmap->Set(3, true); // var s2. | 231 stack_bitmap->Set(3, true); // var s2. |
| 240 stack_bitmap->Set(4, true); // var s3. | 232 stack_bitmap->Set(4, true); // var s3. |
| 241 stack_bitmap->Set(5, true); // First argument to func(i, k). | |
|
Kevin Millikin (Google)
2012/08/17 09:07:43
This test is really brittle and will soon be repla
| |
| 242 stack_bitmap->Set(6, true); // Second argument to func(i, k). | |
| 243 const Code& code = Code::Handle(function_foo.unoptimized_code()); | 233 const Code& code = Code::Handle(function_foo.unoptimized_code()); |
| 244 // Search for the pc of the call to 'func'. | 234 // Search for the pc of the call to 'func'. |
| 245 const PcDescriptors& descriptors = | 235 const PcDescriptors& descriptors = |
| 246 PcDescriptors::Handle(code.pc_descriptors()); | 236 PcDescriptors::Handle(code.pc_descriptors()); |
| 247 int call_count = 0; | 237 int call_count = 0; |
| 248 for (int i = 0; i < descriptors.Length(); ++i) { | 238 for (int i = 0; i < descriptors.Length(); ++i) { |
| 249 if (descriptors.DescriptorKind(i) == PcDescriptors::kFuncCall) { | 239 if (descriptors.DescriptorKind(i) == PcDescriptors::kFuncCall) { |
| 250 stackmap_table_builder->AddEntry(descriptors.PC(i) - code.EntryPoint(), | 240 stackmap_table_builder->AddEntry(descriptors.PC(i) - code.EntryPoint(), |
| 251 stack_bitmap); | 241 stack_bitmap); |
| 252 ++call_count; | 242 ++call_count; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 265 GrowableArray<const Object*> arguments; | 255 GrowableArray<const Object*> arguments; |
| 266 const Array& kNoArgumentNames = Array::Handle(); | 256 const Array& kNoArgumentNames = Array::Handle(); |
| 267 Object& result = Object::Handle(); | 257 Object& result = Object::Handle(); |
| 268 result = DartEntry::InvokeStatic(function_foo, arguments, kNoArgumentNames); | 258 result = DartEntry::InvokeStatic(function_foo, arguments, kNoArgumentNames); |
| 269 EXPECT(!result.IsError()); | 259 EXPECT(!result.IsError()); |
| 270 } | 260 } |
| 271 | 261 |
| 272 } // namespace dart | 262 } // namespace dart |
| 273 | 263 |
| 274 #endif // defined TARGET_ARCH_IA32 || defined(TARGET_ARCH_X64) | 264 #endif // defined TARGET_ARCH_IA32 || defined(TARGET_ARCH_X64) |
| OLD | NEW |