| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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" // NOLINT | 5 #include "vm/globals.h" // NOLINT |
| 6 #if defined(TARGET_ARCH_IA32) | 6 #if defined(TARGET_ARCH_IA32) |
| 7 | 7 |
| 8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
| 9 #include "vm/code_generator.h" | 9 #include "vm/code_generator.h" |
| 10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
| (...skipping 2686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2697 ASSERT(Utils::IsInt(8, offset)); | 2697 ASSERT(Utils::IsInt(8, offset)); |
| 2698 buffer_.Store<int8_t>(position, offset); | 2698 buffer_.Store<int8_t>(position, offset); |
| 2699 } | 2699 } |
| 2700 label->BindTo(bound); | 2700 label->BindTo(bound); |
| 2701 } | 2701 } |
| 2702 | 2702 |
| 2703 | 2703 |
| 2704 void Assembler::MaybeTraceAllocation(intptr_t cid, | 2704 void Assembler::MaybeTraceAllocation(intptr_t cid, |
| 2705 Register temp_reg, | 2705 Register temp_reg, |
| 2706 Label* trace, | 2706 Label* trace, |
| 2707 bool near_jump, | 2707 bool near_jump) { |
| 2708 bool inline_isolate) { | |
| 2709 ASSERT(cid > 0); | 2708 ASSERT(cid > 0); |
| 2710 Address state_address(kNoRegister, 0); | 2709 Address state_address(kNoRegister, 0); |
| 2711 intptr_t state_offset = ClassTable::StateOffsetFor(cid); | 2710 intptr_t state_offset = ClassTable::StateOffsetFor(cid); |
| 2712 if (inline_isolate) { | 2711 ASSERT(temp_reg != kNoRegister); |
| 2713 ClassTable* class_table = Isolate::Current()->class_table(); | 2712 LoadIsolate(temp_reg); |
| 2714 ClassHeapStats** table_ptr = class_table->TableAddressFor(cid); | 2713 intptr_t table_offset = |
| 2715 if (cid < kNumPredefinedCids) { | 2714 Isolate::class_table_offset() + ClassTable::TableOffsetFor(cid); |
| 2716 state_address = Address::Absolute( | 2715 movl(temp_reg, Address(temp_reg, table_offset)); |
| 2717 reinterpret_cast<uword>(*table_ptr) + state_offset); | 2716 state_address = Address(temp_reg, state_offset); |
| 2718 } else { | |
| 2719 ASSERT(temp_reg != kNoRegister); | |
| 2720 // temp_reg gets address of class table pointer. | |
| 2721 movl(temp_reg, | |
| 2722 Address::Absolute(reinterpret_cast<uword>(table_ptr))); | |
| 2723 state_address = Address(temp_reg, state_offset); | |
| 2724 } | |
| 2725 } else { | |
| 2726 ASSERT(temp_reg != kNoRegister); | |
| 2727 LoadIsolate(temp_reg); | |
| 2728 intptr_t table_offset = | |
| 2729 Isolate::class_table_offset() + ClassTable::TableOffsetFor(cid); | |
| 2730 movl(temp_reg, Address(temp_reg, table_offset)); | |
| 2731 state_address = Address(temp_reg, state_offset); | |
| 2732 } | |
| 2733 testb(state_address, Immediate(ClassHeapStats::TraceAllocationMask())); | 2717 testb(state_address, Immediate(ClassHeapStats::TraceAllocationMask())); |
| 2734 // We are tracing for this class, jump to the trace label which will use | 2718 // We are tracing for this class, jump to the trace label which will use |
| 2735 // the allocation stub. | 2719 // the allocation stub. |
| 2736 j(NOT_ZERO, trace, near_jump); | 2720 j(NOT_ZERO, trace, near_jump); |
| 2737 } | 2721 } |
| 2738 | 2722 |
| 2739 | 2723 |
| 2740 void Assembler::UpdateAllocationStats(intptr_t cid, | 2724 void Assembler::UpdateAllocationStats(intptr_t cid, |
| 2741 Register temp_reg, | 2725 Register temp_reg, |
| 2742 Heap::Space space, | 2726 Heap::Space space) { |
| 2743 bool inline_isolate) { | |
| 2744 ASSERT(cid > 0); | 2727 ASSERT(cid > 0); |
| 2745 intptr_t counter_offset = | 2728 intptr_t counter_offset = |
| 2746 ClassTable::CounterOffsetFor(cid, space == Heap::kNew); | 2729 ClassTable::CounterOffsetFor(cid, space == Heap::kNew); |
| 2747 if (inline_isolate) { | 2730 ASSERT(temp_reg != kNoRegister); |
| 2748 ClassTable* class_table = Isolate::Current()->class_table(); | 2731 LoadIsolate(temp_reg); |
| 2749 ClassHeapStats** table_ptr = class_table->TableAddressFor(cid); | 2732 intptr_t table_offset = |
| 2750 if (cid < kNumPredefinedCids) { | 2733 Isolate::class_table_offset() + ClassTable::TableOffsetFor(cid); |
| 2751 incl(Address::Absolute( | 2734 movl(temp_reg, Address(temp_reg, table_offset)); |
| 2752 reinterpret_cast<uword>(*table_ptr) + counter_offset)); | 2735 incl(Address(temp_reg, counter_offset)); |
| 2753 } else { | |
| 2754 ASSERT(temp_reg != kNoRegister); | |
| 2755 movl(temp_reg, | |
| 2756 Address::Absolute(reinterpret_cast<uword>(table_ptr))); | |
| 2757 incl(Address(temp_reg, counter_offset)); | |
| 2758 } | |
| 2759 } else { | |
| 2760 ASSERT(temp_reg != kNoRegister); | |
| 2761 LoadIsolate(temp_reg); | |
| 2762 intptr_t table_offset = | |
| 2763 Isolate::class_table_offset() + ClassTable::TableOffsetFor(cid); | |
| 2764 movl(temp_reg, Address(temp_reg, table_offset)); | |
| 2765 incl(Address(temp_reg, counter_offset)); | |
| 2766 } | |
| 2767 } | 2736 } |
| 2768 | 2737 |
| 2769 | 2738 |
| 2770 void Assembler::UpdateAllocationStatsWithSize(intptr_t cid, | 2739 void Assembler::UpdateAllocationStatsWithSize(intptr_t cid, |
| 2771 Register size_reg, | 2740 Register size_reg, |
| 2772 Register temp_reg, | 2741 Register temp_reg, |
| 2773 Heap::Space space, | 2742 Heap::Space space) { |
| 2774 bool inline_isolate) { | |
| 2775 ASSERT(cid > 0); | 2743 ASSERT(cid > 0); |
| 2776 ASSERT(cid < kNumPredefinedCids); | 2744 ASSERT(cid < kNumPredefinedCids); |
| 2777 UpdateAllocationStats(cid, temp_reg, space, inline_isolate); | 2745 UpdateAllocationStats(cid, temp_reg, space); |
| 2778 intptr_t size_offset = ClassTable::SizeOffsetFor(cid, space == Heap::kNew); | 2746 intptr_t size_offset = ClassTable::SizeOffsetFor(cid, space == Heap::kNew); |
| 2779 if (inline_isolate) { | 2747 addl(Address(temp_reg, size_offset), size_reg); |
| 2780 ClassTable* class_table = Isolate::Current()->class_table(); | |
| 2781 ClassHeapStats** table_ptr = class_table->TableAddressFor(cid); | |
| 2782 addl(Address::Absolute( | |
| 2783 reinterpret_cast<uword>(*table_ptr) + size_offset), size_reg); | |
| 2784 } else { | |
| 2785 addl(Address(temp_reg, size_offset), size_reg); | |
| 2786 } | |
| 2787 } | 2748 } |
| 2788 | 2749 |
| 2789 | 2750 |
| 2790 void Assembler::UpdateAllocationStatsWithSize(intptr_t cid, | 2751 void Assembler::UpdateAllocationStatsWithSize(intptr_t cid, |
| 2791 intptr_t size_in_bytes, | 2752 intptr_t size_in_bytes, |
| 2792 Register temp_reg, | 2753 Register temp_reg, |
| 2793 Heap::Space space, | 2754 Heap::Space space) { |
| 2794 bool inline_isolate) { | |
| 2795 ASSERT(cid > 0); | 2755 ASSERT(cid > 0); |
| 2796 ASSERT(cid < kNumPredefinedCids); | 2756 ASSERT(cid < kNumPredefinedCids); |
| 2797 UpdateAllocationStats(cid, temp_reg, space, inline_isolate); | 2757 UpdateAllocationStats(cid, temp_reg, space); |
| 2798 intptr_t size_offset = ClassTable::SizeOffsetFor(cid, space == Heap::kNew); | 2758 intptr_t size_offset = ClassTable::SizeOffsetFor(cid, space == Heap::kNew); |
| 2799 if (inline_isolate) { | 2759 addl(Address(temp_reg, size_offset), Immediate(size_in_bytes)); |
| 2800 ClassTable* class_table = Isolate::Current()->class_table(); | |
| 2801 ClassHeapStats** table_ptr = class_table->TableAddressFor(cid); | |
| 2802 addl(Address::Absolute(reinterpret_cast<uword>(*table_ptr) + size_offset), | |
| 2803 Immediate(size_in_bytes)); | |
| 2804 } else { | |
| 2805 addl(Address(temp_reg, size_offset), Immediate(size_in_bytes)); | |
| 2806 } | |
| 2807 } | 2760 } |
| 2808 | 2761 |
| 2809 | 2762 |
| 2810 void Assembler::TryAllocate(const Class& cls, | 2763 void Assembler::TryAllocate(const Class& cls, |
| 2811 Label* failure, | 2764 Label* failure, |
| 2812 bool near_jump, | 2765 bool near_jump, |
| 2813 Register instance_reg, | 2766 Register instance_reg, |
| 2814 Register temp_reg) { | 2767 Register temp_reg) { |
| 2815 ASSERT(failure != NULL); | 2768 ASSERT(failure != NULL); |
| 2816 ASSERT(temp_reg != kNoRegister); | 2769 ASSERT(temp_reg != kNoRegister); |
| 2817 if (FLAG_inline_alloc) { | 2770 if (FLAG_inline_alloc) { |
| 2818 // If this allocation is traced, program will jump to failure path | 2771 // If this allocation is traced, program will jump to failure path |
| 2819 // (i.e. the allocation stub) which will allocate the object and trace the | 2772 // (i.e. the allocation stub) which will allocate the object and trace the |
| 2820 // allocation call site. | 2773 // allocation call site. |
| 2821 MaybeTraceAllocation(cls.id(), temp_reg, failure, near_jump, | 2774 MaybeTraceAllocation(cls.id(), temp_reg, failure, near_jump); |
| 2822 /* inline_isolate = */ false); | |
| 2823 const intptr_t instance_size = cls.instance_size(); | 2775 const intptr_t instance_size = cls.instance_size(); |
| 2824 Heap::Space space = Heap::SpaceForAllocation(cls.id()); | 2776 Heap::Space space = Heap::SpaceForAllocation(cls.id()); |
| 2825 movl(temp_reg, Address(THR, Thread::heap_offset())); | 2777 movl(temp_reg, Address(THR, Thread::heap_offset())); |
| 2826 movl(instance_reg, Address(temp_reg, Heap::TopOffset(space))); | 2778 movl(instance_reg, Address(temp_reg, Heap::TopOffset(space))); |
| 2827 addl(instance_reg, Immediate(instance_size)); | 2779 addl(instance_reg, Immediate(instance_size)); |
| 2828 // instance_reg: potential next object start. | 2780 // instance_reg: potential next object start. |
| 2829 cmpl(instance_reg, Address(temp_reg, Heap::EndOffset(space))); | 2781 cmpl(instance_reg, Address(temp_reg, Heap::EndOffset(space))); |
| 2830 j(ABOVE_EQUAL, failure, near_jump); | 2782 j(ABOVE_EQUAL, failure, near_jump); |
| 2831 // Successfully allocated the object, now update top to point to | 2783 // Successfully allocated the object, now update top to point to |
| 2832 // next object start and store the class in the class field of object. | 2784 // next object start and store the class in the class field of object. |
| 2833 movl(Address(temp_reg, Heap::TopOffset(space)), instance_reg); | 2785 movl(Address(temp_reg, Heap::TopOffset(space)), instance_reg); |
| 2834 UpdateAllocationStats(cls.id(), temp_reg, space, | 2786 UpdateAllocationStats(cls.id(), temp_reg, space); |
| 2835 /* inline_isolate = */ false); | |
| 2836 ASSERT(instance_size >= kHeapObjectTag); | 2787 ASSERT(instance_size >= kHeapObjectTag); |
| 2837 subl(instance_reg, Immediate(instance_size - kHeapObjectTag)); | 2788 subl(instance_reg, Immediate(instance_size - kHeapObjectTag)); |
| 2838 uword tags = 0; | 2789 uword tags = 0; |
| 2839 tags = RawObject::SizeTag::update(instance_size, tags); | 2790 tags = RawObject::SizeTag::update(instance_size, tags); |
| 2840 ASSERT(cls.id() != kIllegalCid); | 2791 ASSERT(cls.id() != kIllegalCid); |
| 2841 tags = RawObject::ClassIdTag::update(cls.id(), tags); | 2792 tags = RawObject::ClassIdTag::update(cls.id(), tags); |
| 2842 movl(FieldAddress(instance_reg, Object::tags_offset()), Immediate(tags)); | 2793 movl(FieldAddress(instance_reg, Object::tags_offset()), Immediate(tags)); |
| 2843 } else { | 2794 } else { |
| 2844 jmp(failure); | 2795 jmp(failure); |
| 2845 } | 2796 } |
| 2846 } | 2797 } |
| 2847 | 2798 |
| 2848 | 2799 |
| 2849 void Assembler::TryAllocateArray(intptr_t cid, | 2800 void Assembler::TryAllocateArray(intptr_t cid, |
| 2850 intptr_t instance_size, | 2801 intptr_t instance_size, |
| 2851 Label* failure, | 2802 Label* failure, |
| 2852 bool near_jump, | 2803 bool near_jump, |
| 2853 Register instance, | 2804 Register instance, |
| 2854 Register end_address, | 2805 Register end_address, |
| 2855 Register temp_reg) { | 2806 Register temp_reg) { |
| 2856 ASSERT(failure != NULL); | 2807 ASSERT(failure != NULL); |
| 2857 ASSERT(temp_reg != kNoRegister); | 2808 ASSERT(temp_reg != kNoRegister); |
| 2858 if (FLAG_inline_alloc) { | 2809 if (FLAG_inline_alloc) { |
| 2859 // If this allocation is traced, program will jump to failure path | 2810 // If this allocation is traced, program will jump to failure path |
| 2860 // (i.e. the allocation stub) which will allocate the object and trace the | 2811 // (i.e. the allocation stub) which will allocate the object and trace the |
| 2861 // allocation call site. | 2812 // allocation call site. |
| 2862 MaybeTraceAllocation(cid, temp_reg, failure, near_jump, | 2813 MaybeTraceAllocation(cid, temp_reg, failure, near_jump); |
| 2863 /* inline_isolate = */ false); | |
| 2864 Heap::Space space = Heap::SpaceForAllocation(cid); | 2814 Heap::Space space = Heap::SpaceForAllocation(cid); |
| 2865 movl(temp_reg, Address(THR, Thread::heap_offset())); | 2815 movl(temp_reg, Address(THR, Thread::heap_offset())); |
| 2866 movl(instance, Address(temp_reg, Heap::TopOffset(space))); | 2816 movl(instance, Address(temp_reg, Heap::TopOffset(space))); |
| 2867 movl(end_address, instance); | 2817 movl(end_address, instance); |
| 2868 | 2818 |
| 2869 addl(end_address, Immediate(instance_size)); | 2819 addl(end_address, Immediate(instance_size)); |
| 2870 j(CARRY, failure); | 2820 j(CARRY, failure); |
| 2871 | 2821 |
| 2872 // Check if the allocation fits into the remaining space. | 2822 // Check if the allocation fits into the remaining space. |
| 2873 // EAX: potential new object start. | 2823 // EAX: potential new object start. |
| 2874 // EBX: potential next object start. | 2824 // EBX: potential next object start. |
| 2875 cmpl(end_address, Address(temp_reg, Heap::EndOffset(space))); | 2825 cmpl(end_address, Address(temp_reg, Heap::EndOffset(space))); |
| 2876 j(ABOVE_EQUAL, failure); | 2826 j(ABOVE_EQUAL, failure); |
| 2877 | 2827 |
| 2878 // Successfully allocated the object(s), now update top to point to | 2828 // Successfully allocated the object(s), now update top to point to |
| 2879 // next object start and initialize the object. | 2829 // next object start and initialize the object. |
| 2880 movl(Address(temp_reg, Heap::TopOffset(space)), end_address); | 2830 movl(Address(temp_reg, Heap::TopOffset(space)), end_address); |
| 2881 addl(instance, Immediate(kHeapObjectTag)); | 2831 addl(instance, Immediate(kHeapObjectTag)); |
| 2882 UpdateAllocationStatsWithSize(cid, instance_size, temp_reg, space, | 2832 UpdateAllocationStatsWithSize(cid, instance_size, temp_reg, space); |
| 2883 /* inline_isolate = */ false); | |
| 2884 | 2833 |
| 2885 // Initialize the tags. | 2834 // Initialize the tags. |
| 2886 uword tags = 0; | 2835 uword tags = 0; |
| 2887 tags = RawObject::ClassIdTag::update(cid, tags); | 2836 tags = RawObject::ClassIdTag::update(cid, tags); |
| 2888 tags = RawObject::SizeTag::update(instance_size, tags); | 2837 tags = RawObject::SizeTag::update(instance_size, tags); |
| 2889 movl(FieldAddress(instance, Object::tags_offset()), Immediate(tags)); | 2838 movl(FieldAddress(instance, Object::tags_offset()), Immediate(tags)); |
| 2890 } else { | 2839 } else { |
| 2891 jmp(failure); | 2840 jmp(failure); |
| 2892 } | 2841 } |
| 2893 } | 2842 } |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3229 | 3178 |
| 3230 const char* Assembler::FpuRegisterName(FpuRegister reg) { | 3179 const char* Assembler::FpuRegisterName(FpuRegister reg) { |
| 3231 ASSERT((0 <= reg) && (reg < kNumberOfXmmRegisters)); | 3180 ASSERT((0 <= reg) && (reg < kNumberOfXmmRegisters)); |
| 3232 return xmm_reg_names[reg]; | 3181 return xmm_reg_names[reg]; |
| 3233 } | 3182 } |
| 3234 | 3183 |
| 3235 | 3184 |
| 3236 } // namespace dart | 3185 } // namespace dart |
| 3237 | 3186 |
| 3238 #endif // defined TARGET_ARCH_IA32 | 3187 #endif // defined TARGET_ARCH_IA32 |
| OLD | NEW |