| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 stack_bitmap->Set(0, true); | 65 stack_bitmap->Set(0, true); |
| 66 EXPECT_EQ(1, stack_bitmap->Length()); | 66 EXPECT_EQ(1, stack_bitmap->Length()); |
| 67 stack_bitmap->SetLength(kStackSlotCount); | 67 stack_bitmap->SetLength(kStackSlotCount); |
| 68 EXPECT_EQ(kStackSlotCount, stack_bitmap->Length()); | 68 EXPECT_EQ(kStackSlotCount, stack_bitmap->Length()); |
| 69 | 69 |
| 70 bool expectation0[kStackSlotCount] = { true }; | 70 bool expectation0[kStackSlotCount] = { true }; |
| 71 for (intptr_t i = 0; i < kStackSlotCount; ++i) { | 71 for (intptr_t i = 0; i < kStackSlotCount; ++i) { |
| 72 EXPECT_EQ(expectation0[i], stack_bitmap->Get(i)); | 72 EXPECT_EQ(expectation0[i], stack_bitmap->Get(i)); |
| 73 } | 73 } |
| 74 // Add a stack map entry at pc offset 0. | 74 // Add a stack map entry at pc offset 0. |
| 75 stackmap_table_builder->AddEntry(0, stack_bitmap); | 75 stackmap_table_builder->AddEntry(0, stack_bitmap, 0); |
| 76 | 76 |
| 77 stack_bitmap = new BitmapBuilder(); | 77 stack_bitmap = new BitmapBuilder(); |
| 78 EXPECT(stack_bitmap != NULL); | 78 EXPECT(stack_bitmap != NULL); |
| 79 EXPECT_EQ(0, stack_bitmap->Length()); | 79 EXPECT_EQ(0, stack_bitmap->Length()); |
| 80 stack_bitmap->Set(0, true); | 80 stack_bitmap->Set(0, true); |
| 81 stack_bitmap->Set(1, false); | 81 stack_bitmap->Set(1, false); |
| 82 stack_bitmap->Set(2, true); | 82 stack_bitmap->Set(2, true); |
| 83 EXPECT_EQ(3, stack_bitmap->Length()); | 83 EXPECT_EQ(3, stack_bitmap->Length()); |
| 84 stack_bitmap->SetLength(kStackSlotCount); | 84 stack_bitmap->SetLength(kStackSlotCount); |
| 85 EXPECT_EQ(kStackSlotCount, stack_bitmap->Length()); | 85 EXPECT_EQ(kStackSlotCount, stack_bitmap->Length()); |
| 86 | 86 |
| 87 bool expectation1[kStackSlotCount] = { true, false, true }; | 87 bool expectation1[kStackSlotCount] = { true, false, true }; |
| 88 for (intptr_t i = 0; i < kStackSlotCount; ++i) { | 88 for (intptr_t i = 0; i < kStackSlotCount; ++i) { |
| 89 EXPECT_EQ(expectation1[i], stack_bitmap->Get(i)); | 89 EXPECT_EQ(expectation1[i], stack_bitmap->Get(i)); |
| 90 } | 90 } |
| 91 // Add a stack map entry at pc offset 1. | 91 // Add a stack map entry at pc offset 1. |
| 92 stackmap_table_builder->AddEntry(1, stack_bitmap); | 92 stackmap_table_builder->AddEntry(1, stack_bitmap, 0); |
| 93 | 93 |
| 94 stack_bitmap = new BitmapBuilder(); | 94 stack_bitmap = new BitmapBuilder(); |
| 95 EXPECT(stack_bitmap != NULL); | 95 EXPECT(stack_bitmap != NULL); |
| 96 EXPECT_EQ(0, stack_bitmap->Length()); | 96 EXPECT_EQ(0, stack_bitmap->Length()); |
| 97 stack_bitmap->Set(0, true); | 97 stack_bitmap->Set(0, true); |
| 98 stack_bitmap->Set(1, false); | 98 stack_bitmap->Set(1, false); |
| 99 stack_bitmap->Set(2, true); | 99 stack_bitmap->Set(2, true); |
| 100 stack_bitmap->SetRange(3, 5, true); | 100 stack_bitmap->SetRange(3, 5, true); |
| 101 EXPECT_EQ(6, stack_bitmap->Length()); | 101 EXPECT_EQ(6, stack_bitmap->Length()); |
| 102 stack_bitmap->SetLength(kStackSlotCount); | 102 stack_bitmap->SetLength(kStackSlotCount); |
| 103 EXPECT_EQ(kStackSlotCount, stack_bitmap->Length()); | 103 EXPECT_EQ(kStackSlotCount, stack_bitmap->Length()); |
| 104 | 104 |
| 105 bool expectation2[kStackSlotCount] = | 105 bool expectation2[kStackSlotCount] = |
| 106 { true, false, true, true, true, true }; | 106 { true, false, true, true, true, true }; |
| 107 for (intptr_t i = 0; i < kStackSlotCount; ++i) { | 107 for (intptr_t i = 0; i < kStackSlotCount; ++i) { |
| 108 EXPECT_EQ(expectation2[i], stack_bitmap->Get(i)); | 108 EXPECT_EQ(expectation2[i], stack_bitmap->Get(i)); |
| 109 } | 109 } |
| 110 // Add a stack map entry at pc offset 2. | 110 // Add a stack map entry at pc offset 2. |
| 111 stackmap_table_builder->AddEntry(2, stack_bitmap); | 111 stackmap_table_builder->AddEntry(2, stack_bitmap, 0); |
| 112 | 112 |
| 113 stack_bitmap = new BitmapBuilder(); | 113 stack_bitmap = new BitmapBuilder(); |
| 114 EXPECT(stack_bitmap != NULL); | 114 EXPECT(stack_bitmap != NULL); |
| 115 EXPECT_EQ(0, stack_bitmap->Length()); | 115 EXPECT_EQ(0, stack_bitmap->Length()); |
| 116 stack_bitmap->Set(0, true); | 116 stack_bitmap->Set(0, true); |
| 117 stack_bitmap->Set(1, false); | 117 stack_bitmap->Set(1, false); |
| 118 stack_bitmap->Set(2, true); | 118 stack_bitmap->Set(2, true); |
| 119 stack_bitmap->SetRange(3, 5, true); | 119 stack_bitmap->SetRange(3, 5, true); |
| 120 stack_bitmap->SetRange(6, 9, false); | 120 stack_bitmap->SetRange(6, 9, false); |
| 121 stack_bitmap->Set(10, true); | 121 stack_bitmap->Set(10, true); |
| 122 EXPECT_EQ(11, stack_bitmap->Length()); | 122 EXPECT_EQ(11, stack_bitmap->Length()); |
| 123 stack_bitmap->SetLength(kStackSlotCount); | 123 stack_bitmap->SetLength(kStackSlotCount); |
| 124 EXPECT_EQ(kStackSlotCount, stack_bitmap->Length()); | 124 EXPECT_EQ(kStackSlotCount, stack_bitmap->Length()); |
| 125 | 125 |
| 126 bool expectation3[kStackSlotCount] = | 126 bool expectation3[kStackSlotCount] = |
| 127 { true, false, true, true, true, true, false, false, | 127 { true, false, true, true, true, true, false, false, |
| 128 false, false, true }; | 128 false, false, true }; |
| 129 for (intptr_t i = 0; i < kStackSlotCount; ++i) { | 129 for (intptr_t i = 0; i < kStackSlotCount; ++i) { |
| 130 EXPECT_EQ(expectation3[i], stack_bitmap->Get(i)); | 130 EXPECT_EQ(expectation3[i], stack_bitmap->Get(i)); |
| 131 } | 131 } |
| 132 // Add a stack map entry at pc offset 3. | 132 // Add a stack map entry at pc offset 3. |
| 133 stackmap_table_builder->AddEntry(3, stack_bitmap); | 133 stackmap_table_builder->AddEntry(3, stack_bitmap, 0); |
| 134 | 134 |
| 135 const Error& error = | 135 const Error& error = |
| 136 Error::Handle(Compiler::CompileParsedFunction(parsed_function)); | 136 Error::Handle(Compiler::CompileParsedFunction(parsed_function)); |
| 137 EXPECT(error.IsNull()); | 137 EXPECT(error.IsNull()); |
| 138 const Code& code = Code::Handle(function.CurrentCode()); | 138 const Code& code = Code::Handle(function.CurrentCode()); |
| 139 | 139 |
| 140 const Array& stack_maps = | 140 const Array& stack_maps = |
| 141 Array::Handle(stackmap_table_builder->FinalizeStackmaps(code)); | 141 Array::Handle(stackmap_table_builder->FinalizeStackmaps(code)); |
| 142 code.set_stackmaps(stack_maps); | 142 code.set_stackmaps(stack_maps); |
| 143 const Array& stack_map_list = Array::Handle(code.stackmaps()); | 143 const Array& stack_map_list = Array::Handle(code.stackmaps()); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 stack_bitmap->Set(3, true); // var s2. | 250 stack_bitmap->Set(3, true); // var s2. |
| 251 stack_bitmap->Set(4, true); // var s3. | 251 stack_bitmap->Set(4, true); // var s3. |
| 252 const Code& code = Code::Handle(function_foo.unoptimized_code()); | 252 const Code& code = Code::Handle(function_foo.unoptimized_code()); |
| 253 // Search for the pc of the call to 'func'. | 253 // Search for the pc of the call to 'func'. |
| 254 const PcDescriptors& descriptors = | 254 const PcDescriptors& descriptors = |
| 255 PcDescriptors::Handle(code.pc_descriptors()); | 255 PcDescriptors::Handle(code.pc_descriptors()); |
| 256 int call_count = 0; | 256 int call_count = 0; |
| 257 for (int i = 0; i < descriptors.Length(); ++i) { | 257 for (int i = 0; i < descriptors.Length(); ++i) { |
| 258 if (descriptors.DescriptorKind(i) == PcDescriptors::kFuncCall) { | 258 if (descriptors.DescriptorKind(i) == PcDescriptors::kFuncCall) { |
| 259 stackmap_table_builder->AddEntry(descriptors.PC(i) - code.EntryPoint(), | 259 stackmap_table_builder->AddEntry(descriptors.PC(i) - code.EntryPoint(), |
| 260 stack_bitmap); | 260 stack_bitmap, |
| 261 0); |
| 261 ++call_count; | 262 ++call_count; |
| 262 } | 263 } |
| 263 } | 264 } |
| 264 // We can't easily check that we put the stackmap at the correct pc, but | 265 // We can't easily check that we put the stackmap at the correct pc, but |
| 265 // we did if there was exactly one call seen. | 266 // we did if there was exactly one call seen. |
| 266 EXPECT(call_count == 1); | 267 EXPECT(call_count == 1); |
| 267 const Array& stack_maps = | 268 const Array& stack_maps = |
| 268 Array::Handle(stackmap_table_builder->FinalizeStackmaps(code)); | 269 Array::Handle(stackmap_table_builder->FinalizeStackmaps(code)); |
| 269 code.set_stackmaps(stack_maps); | 270 code.set_stackmaps(stack_maps); |
| 270 | 271 |
| 271 // Now invoke 'A.moo' and it will trigger a GC when the native function | 272 // Now invoke 'A.moo' and it will trigger a GC when the native function |
| 272 // is called, this should then cause the stack map of function 'A.foo' | 273 // is called, this should then cause the stack map of function 'A.foo' |
| 273 // to be traversed and the appropriate objects visited. | 274 // to be traversed and the appropriate objects visited. |
| 274 GrowableArray<const Object*> arguments; | 275 GrowableArray<const Object*> arguments; |
| 275 const Array& kNoArgumentNames = Array::Handle(); | 276 const Array& kNoArgumentNames = Array::Handle(); |
| 276 Object& result = Object::Handle(); | 277 Object& result = Object::Handle(); |
| 277 result = DartEntry::InvokeStatic(function_foo, arguments, kNoArgumentNames); | 278 result = DartEntry::InvokeStatic(function_foo, arguments, kNoArgumentNames); |
| 278 EXPECT(!result.IsError()); | 279 EXPECT(!result.IsError()); |
| 279 } | 280 } |
| 280 | 281 |
| 281 } // namespace dart | 282 } // namespace dart |
| 282 | 283 |
| 283 #endif // defined TARGET_ARCH_IA32 || defined(TARGET_ARCH_X64) | 284 #endif // defined TARGET_ARCH_IA32 || defined(TARGET_ARCH_X64) |
| OLD | NEW |