OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 "vm/globals.h" | 5 #include "vm/globals.h" |
6 #if defined(TARGET_ARCH_X64) | 6 #if defined(TARGET_ARCH_X64) |
7 | 7 |
8 #include "vm/assembler_macros.h" | 8 #include "vm/assembler_macros.h" |
9 | 9 |
10 #include "vm/assembler.h" | 10 #include "vm/assembler.h" |
11 | 11 |
12 namespace dart { | 12 namespace dart { |
13 | 13 |
14 DECLARE_FLAG(bool, inline_alloc); | 14 DECLARE_FLAG(bool, inline_alloc); |
15 | 15 |
16 #define __ assembler-> | 16 #define __ assembler-> |
17 | 17 |
18 // Static. | 18 // Static. |
19 void AssemblerMacros::TryAllocate(Assembler* assembler, | 19 void AssemblerMacros::TryAllocate(Assembler* assembler, |
20 const Class& cls, | 20 const Class& cls, |
21 Register class_reg, | |
22 Label* failure, | 21 Label* failure, |
23 Register instance_reg) { | 22 Register instance_reg) { |
24 #if defined(DEBUG) | 23 #if defined(DEBUG) |
25 __ Untested("AssemblerMacros::TryAllocate"); | 24 __ Untested("AssemblerMacros::TryAllocate"); |
26 Label ok; | |
27 __ LoadObject(instance_reg, cls); | |
28 __ cmpq(instance_reg, class_reg); | |
29 __ j(EQUAL, &ok, Assembler::kNearJump); | |
30 __ Stop("AssemblerMacros::TryAllocate, wrong arguments"); | |
31 __ Bind(&ok); | |
32 #endif | 25 #endif |
33 ASSERT(failure != NULL); | 26 ASSERT(failure != NULL); |
34 ASSERT(class_reg != instance_reg); | |
35 if (FLAG_inline_alloc) { | 27 if (FLAG_inline_alloc) { |
36 Heap* heap = Isolate::Current()->heap(); | 28 Heap* heap = Isolate::Current()->heap(); |
37 const intptr_t instance_size = cls.instance_size(); | 29 const intptr_t instance_size = cls.instance_size(); |
38 __ movq(TMP, Immediate(heap->TopAddress())); | 30 __ movq(TMP, Immediate(heap->TopAddress())); |
39 __ movq(instance_reg, Address(TMP, 0)); | 31 __ movq(instance_reg, Address(TMP, 0)); |
40 __ addq(instance_reg, Immediate(instance_size)); | 32 __ addq(instance_reg, Immediate(instance_size)); |
41 // instance_reg: potential next object start. | 33 // instance_reg: potential next object start. |
42 __ movq(TMP, Immediate(heap->EndAddress())); | 34 __ movq(TMP, Immediate(heap->EndAddress())); |
43 __ cmpq(instance_reg, Address(TMP, 0)); | 35 __ cmpq(instance_reg, Address(TMP, 0)); |
44 __ j(ABOVE_EQUAL, failure, Assembler::kNearJump); | 36 __ j(ABOVE_EQUAL, failure, Assembler::kNearJump); |
45 // Successfully allocated the object, now update top to point to | 37 // Successfully allocated the object, now update top to point to |
46 // next object start and store the class in the class field of object. | 38 // next object start and store the class in the class field of object. |
47 __ movq(TMP, Immediate(heap->TopAddress())); | 39 __ movq(TMP, Immediate(heap->TopAddress())); |
48 __ movq(Address(TMP, 0), instance_reg); | 40 __ movq(Address(TMP, 0), instance_reg); |
49 ASSERT(instance_size >= kHeapObjectTag); | 41 ASSERT(instance_size >= kHeapObjectTag); |
50 __ subq(instance_reg, Immediate(instance_size - kHeapObjectTag)); | 42 __ subq(instance_reg, Immediate(instance_size - kHeapObjectTag)); |
51 __ StoreIntoObject(instance_reg, | |
52 FieldAddress(instance_reg, Instance::class_offset()), | |
53 class_reg); | |
54 uword tags = 0; | 43 uword tags = 0; |
55 tags = RawObject::SizeTag::update(instance_size, tags); | 44 tags = RawObject::SizeTag::update(instance_size, tags); |
56 ASSERT(cls.id() != kIllegalObjectKind); | 45 ASSERT(cls.id() != kIllegalObjectKind); |
57 tags = RawObject::ClassIdTag::update(cls.id(), tags); | 46 tags = RawObject::ClassIdTag::update(cls.id(), tags); |
58 __ movq(FieldAddress(instance_reg, Object::tags_offset()), Immediate(tags)); | 47 __ movq(FieldAddress(instance_reg, Object::tags_offset()), Immediate(tags)); |
59 } else { | 48 } else { |
60 __ jmp(failure); | 49 __ jmp(failure); |
61 } | 50 } |
62 } | 51 } |
63 | 52 |
(...skipping 19 matching lines...) Expand all Loading... |
83 void AssemblerMacros::EnterStubFrame(Assembler* assembler) { | 72 void AssemblerMacros::EnterStubFrame(Assembler* assembler) { |
84 __ EnterFrame(0); | 73 __ EnterFrame(0); |
85 __ pushq(Immediate(0)); // Push 0 in the saved PC area for stub frames. | 74 __ pushq(Immediate(0)); // Push 0 in the saved PC area for stub frames. |
86 } | 75 } |
87 | 76 |
88 #undef __ | 77 #undef __ |
89 | 78 |
90 } // namespace dart | 79 } // namespace dart |
91 | 80 |
92 #endif // defined TARGET_ARCH_X64 | 81 #endif // defined TARGET_ARCH_X64 |
OLD | NEW |