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 #ifndef VM_OBJECT_H_ | 5 #ifndef VM_OBJECT_H_ |
6 #define VM_OBJECT_H_ | 6 #define VM_OBJECT_H_ |
7 | 7 |
8 #include <limits> | 8 #include <limits> |
9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
(...skipping 2934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2945 RawString* GetName(intptr_t var_index) const; | 2945 RawString* GetName(intptr_t var_index) const; |
2946 | 2946 |
2947 void SetVar(intptr_t var_index, | 2947 void SetVar(intptr_t var_index, |
2948 const String& name, | 2948 const String& name, |
2949 RawLocalVarDescriptors::VarInfo* info) const; | 2949 RawLocalVarDescriptors::VarInfo* info) const; |
2950 | 2950 |
2951 void GetInfo(intptr_t var_index, RawLocalVarDescriptors::VarInfo* info) const; | 2951 void GetInfo(intptr_t var_index, RawLocalVarDescriptors::VarInfo* info) const; |
2952 | 2952 |
2953 static const intptr_t kBytesPerElement = | 2953 static const intptr_t kBytesPerElement = |
2954 sizeof(RawLocalVarDescriptors::VarInfo); | 2954 sizeof(RawLocalVarDescriptors::VarInfo); |
2955 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; | 2955 static const intptr_t kMaxElements = RawLocalVarDescriptors::kMaxIndex; |
2956 | 2956 |
2957 static intptr_t InstanceSize() { | 2957 static intptr_t InstanceSize() { |
2958 ASSERT(sizeof(RawLocalVarDescriptors) == | 2958 ASSERT(sizeof(RawLocalVarDescriptors) == |
2959 OFFSET_OF_RETURNED_VALUE(RawLocalVarDescriptors, data)); | 2959 OFFSET_OF_RETURNED_VALUE(RawLocalVarDescriptors, data)); |
2960 return 0; | 2960 return 0; |
2961 } | 2961 } |
2962 static intptr_t InstanceSize(intptr_t len) { | 2962 static intptr_t InstanceSize(intptr_t len) { |
2963 ASSERT(0 <= len && len <= kMaxElements); | 2963 ASSERT(0 <= len && len <= kMaxElements); |
2964 return RoundedAllocationSize( | 2964 return RoundedAllocationSize( |
2965 sizeof(RawLocalVarDescriptors) + (len * kBytesPerElement)); | 2965 sizeof(RawLocalVarDescriptors) + (len * kBytesPerElement)); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3071 static const intptr_t kNoMaximum = -1; | 3071 static const intptr_t kNoMaximum = -1; |
3072 static const intptr_t kNoMinimum = -1; | 3072 static const intptr_t kNoMinimum = -1; |
3073 | 3073 |
3074 bool IsObject(intptr_t index) const { | 3074 bool IsObject(intptr_t index) const { |
3075 ASSERT(InRange(index)); | 3075 ASSERT(InRange(index)); |
3076 return GetBit(index); | 3076 return GetBit(index); |
3077 } | 3077 } |
3078 | 3078 |
3079 intptr_t Length() const { return raw_ptr()->length_; } | 3079 intptr_t Length() const { return raw_ptr()->length_; } |
3080 | 3080 |
3081 uword PC() const { return raw_ptr()->pc_; } | 3081 uword PC() const { return static_cast<uword>(raw_ptr()->pc_offset_); } |
Ivan Posva
2014/07/23 12:23:27
Unclear whether we are now storing the PC or the P
zra
2014/08/20 22:13:56
Changed to PcOffset, and SetPcOffset.
| |
3082 void SetPC(uword value) const { raw_ptr()->pc_ = value; } | 3082 void SetPC(uword value) const { |
3083 ASSERT(value <= kMaxUint32); | |
3084 raw_ptr()->pc_offset_ = static_cast<uint32_t>(value); | |
3085 } | |
3083 | 3086 |
3084 intptr_t RegisterBitCount() const { return raw_ptr()->register_bit_count_; } | 3087 intptr_t RegisterBitCount() const { return raw_ptr()->register_bit_count_; } |
3085 void SetRegisterBitCount(intptr_t register_bit_count) const { | 3088 void SetRegisterBitCount(intptr_t register_bit_count) const { |
3086 raw_ptr()->register_bit_count_ = register_bit_count; | 3089 raw_ptr()->register_bit_count_ = register_bit_count; |
3087 } | 3090 } |
3088 | 3091 |
3089 static const intptr_t kMaxLengthInBytes = kSmiMax; | 3092 static const intptr_t kMaxLengthInBytes = kSmiMax; |
3090 | 3093 |
3091 static intptr_t InstanceSize() { | 3094 static intptr_t InstanceSize() { |
3092 ASSERT(sizeof(RawStackmap) == OFFSET_OF_RETURNED_VALUE(RawStackmap, data)); | 3095 ASSERT(sizeof(RawStackmap) == OFFSET_OF_RETURNED_VALUE(RawStackmap, data)); |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3473 }; | 3476 }; |
3474 | 3477 |
3475 | 3478 |
3476 class Code : public Object { | 3479 class Code : public Object { |
3477 public: | 3480 public: |
3478 RawInstructions* instructions() const { return raw_ptr()->instructions_; } | 3481 RawInstructions* instructions() const { return raw_ptr()->instructions_; } |
3479 static intptr_t instructions_offset() { | 3482 static intptr_t instructions_offset() { |
3480 return OFFSET_OF(RawCode, instructions_); | 3483 return OFFSET_OF(RawCode, instructions_); |
3481 } | 3484 } |
3482 intptr_t pointer_offsets_length() const { | 3485 intptr_t pointer_offsets_length() const { |
3483 return raw_ptr()->pointer_offsets_length_; | 3486 return PtrOffBits::decode(raw_ptr()->state_bits_); |
3484 } | 3487 } |
3485 | 3488 |
3486 bool is_optimized() const { | 3489 bool is_optimized() const { |
3487 return OptimizedBit::decode(raw_ptr()->state_bits_); | 3490 return OptimizedBit::decode(raw_ptr()->state_bits_); |
3488 } | 3491 } |
3489 void set_is_optimized(bool value) const; | 3492 void set_is_optimized(bool value) const; |
3490 bool is_alive() const { | 3493 bool is_alive() const { |
3491 return AliveBit::decode(raw_ptr()->state_bits_); | 3494 return AliveBit::decode(raw_ptr()->state_bits_); |
3492 } | 3495 } |
3493 void set_is_alive(bool value) const; | 3496 void set_is_alive(bool value) const; |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3707 intptr_t lazy_deopt_pc_offset() const { | 3710 intptr_t lazy_deopt_pc_offset() const { |
3708 return raw_ptr()->lazy_deopt_pc_offset_; | 3711 return raw_ptr()->lazy_deopt_pc_offset_; |
3709 } | 3712 } |
3710 void set_lazy_deopt_pc_offset(intptr_t pc) const { | 3713 void set_lazy_deopt_pc_offset(intptr_t pc) const { |
3711 raw_ptr()->lazy_deopt_pc_offset_ = pc; | 3714 raw_ptr()->lazy_deopt_pc_offset_ = pc; |
3712 } | 3715 } |
3713 | 3716 |
3714 private: | 3717 private: |
3715 void set_state_bits(intptr_t bits) const; | 3718 void set_state_bits(intptr_t bits) const; |
3716 | 3719 |
3720 friend class RawObject; // For RawObject::SizeFromClass(). | |
3717 friend class RawCode; | 3721 friend class RawCode; |
3718 enum { | 3722 enum { |
3719 kOptimizedBit = 0, | 3723 kOptimizedBit = 0, |
3720 kAliveBit = 1, | 3724 kAliveBit = 1, |
3725 kPtrOffBit = 2, | |
3726 kPtrOffSize = 30, | |
3721 }; | 3727 }; |
3722 | 3728 |
3723 class OptimizedBit : public BitField<bool, kOptimizedBit, 1> {}; | 3729 class OptimizedBit : public BitField<bool, kOptimizedBit, 1> {}; |
3724 class AliveBit : public BitField<bool, kAliveBit, 1> {}; | 3730 class AliveBit : public BitField<bool, kAliveBit, 1> {}; |
3731 class PtrOffBits : public BitField<intptr_t, kPtrOffBit, kPtrOffSize> {}; | |
3725 | 3732 |
3726 // An object finder visitor interface. | 3733 // An object finder visitor interface. |
3727 class FindRawCodeVisitor : public FindObjectVisitor { | 3734 class FindRawCodeVisitor : public FindObjectVisitor { |
3728 public: | 3735 public: |
3729 explicit FindRawCodeVisitor(uword pc) | 3736 explicit FindRawCodeVisitor(uword pc) |
3730 : FindObjectVisitor(Isolate::Current()), pc_(pc) { } | 3737 : FindObjectVisitor(Isolate::Current()), pc_(pc) { } |
3731 virtual ~FindRawCodeVisitor() { } | 3738 virtual ~FindRawCodeVisitor() { } |
3732 | 3739 |
3733 virtual uword filter_addr() const { return pc_; } | 3740 virtual uword filter_addr() const { return pc_; } |
3734 | 3741 |
(...skipping 10 matching lines...) Expand all Loading... | |
3745 | 3752 |
3746 void set_compile_timestamp(int64_t timestamp) const { | 3753 void set_compile_timestamp(int64_t timestamp) const { |
3747 raw_ptr()->compile_timestamp_ = timestamp; | 3754 raw_ptr()->compile_timestamp_ = timestamp; |
3748 } | 3755 } |
3749 | 3756 |
3750 void set_instructions(RawInstructions* instructions) { | 3757 void set_instructions(RawInstructions* instructions) { |
3751 // RawInstructions are never allocated in New space and hence a | 3758 // RawInstructions are never allocated in New space and hence a |
3752 // store buffer update is not needed here. | 3759 // store buffer update is not needed here. |
3753 raw_ptr()->instructions_ = instructions; | 3760 raw_ptr()->instructions_ = instructions; |
3754 } | 3761 } |
3762 | |
3755 void set_pointer_offsets_length(intptr_t value) { | 3763 void set_pointer_offsets_length(intptr_t value) { |
3756 ASSERT(value >= 0); | 3764 // The number of fixups is limited to 1-billion. |
3757 raw_ptr()->pointer_offsets_length_ = value; | 3765 ASSERT(Utils::IsUint(30, value)); |
3766 set_state_bits(PtrOffBits::update(value, raw_ptr()->state_bits_)); | |
3758 } | 3767 } |
3759 int32_t* PointerOffsetAddrAt(int index) const { | 3768 int32_t* PointerOffsetAddrAt(int index) const { |
3760 ASSERT(index >= 0); | 3769 ASSERT(index >= 0); |
3761 ASSERT(index < pointer_offsets_length()); | 3770 ASSERT(index < pointer_offsets_length()); |
3762 // TODO(iposva): Unit test is missing for this functionality. | 3771 // TODO(iposva): Unit test is missing for this functionality. |
3763 return &raw_ptr()->data()[index]; | 3772 return &raw_ptr()->data()[index]; |
3764 } | 3773 } |
3765 void SetPointerOffsetAt(int index, int32_t offset_in_instructions) { | 3774 void SetPointerOffsetAt(int index, int32_t offset_in_instructions) { |
3766 *PointerOffsetAddrAt(index) = offset_in_instructions; | 3775 *PointerOffsetAddrAt(index) = offset_in_instructions; |
3767 } | 3776 } |
(...skipping 3053 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6821 | 6830 |
6822 // Internal JavaScript regular expression object. | 6831 // Internal JavaScript regular expression object. |
6823 class JSRegExp : public Instance { | 6832 class JSRegExp : public Instance { |
6824 public: | 6833 public: |
6825 // Meaning of RegExType: | 6834 // Meaning of RegExType: |
6826 // kUninitialized: the type of th regexp has not been initialized yet. | 6835 // kUninitialized: the type of th regexp has not been initialized yet. |
6827 // kSimple: A simple pattern to match against, using string indexOf operation. | 6836 // kSimple: A simple pattern to match against, using string indexOf operation. |
6828 // kComplex: A complex pattern to match. | 6837 // kComplex: A complex pattern to match. |
6829 enum RegExType { | 6838 enum RegExType { |
6830 kUnitialized = 0, | 6839 kUnitialized = 0, |
6831 kSimple, | 6840 kSimple = 1, |
6832 kComplex, | 6841 kComplex = 2, |
6833 }; | 6842 }; |
6834 | 6843 |
6835 // Flags are passed to a regex object as follows: | 6844 // Flags are passed to a regex object as follows: |
6836 // 'i': ignore case, 'g': do global matches, 'm': pattern is multi line. | 6845 // 'i': ignore case, 'g': do global matches, 'm': pattern is multi line. |
6837 enum Flags { | 6846 enum Flags { |
6838 kNone = 0, | 6847 kNone = 0, |
6839 kGlobal = 1, | 6848 kGlobal = 1, |
6840 kIgnoreCase = 2, | 6849 kIgnoreCase = 2, |
6841 kMultiLine = 4, | 6850 kMultiLine = 4, |
6842 }; | 6851 }; |
6843 | 6852 |
6844 bool is_initialized() const { return (raw_ptr()->type_ != kUnitialized); } | 6853 enum { |
6845 bool is_simple() const { return (raw_ptr()->type_ == kSimple); } | 6854 kTypePos = 0, |
6846 bool is_complex() const { return (raw_ptr()->type_ == kComplex); } | 6855 kTypeSize = 2, |
6856 kFlagsPos = 2, | |
6857 kFlagsSize = 4, | |
6858 }; | |
6847 | 6859 |
6848 bool is_global() const { return (raw_ptr()->flags_ & kGlobal); } | 6860 class TypeBits : public BitField<RegExType, kTypePos, kTypeSize> {}; |
6849 bool is_ignore_case() const { return (raw_ptr()->flags_ & kIgnoreCase); } | 6861 class FlagsBits : public BitField<intptr_t, kFlagsPos, kFlagsSize> {}; |
6850 bool is_multi_line() const { return (raw_ptr()->flags_ & kMultiLine); } | 6862 |
6863 bool is_initialized() const { return (type() != kUnitialized); } | |
6864 bool is_simple() const { return (type() == kSimple); } | |
6865 bool is_complex() const { return (type() == kComplex); } | |
6866 | |
6867 bool is_global() const { return (flags() & kGlobal); } | |
6868 bool is_ignore_case() const { return (flags() & kIgnoreCase); } | |
6869 bool is_multi_line() const { return (flags() & kMultiLine); } | |
6851 | 6870 |
6852 RawString* pattern() const { return raw_ptr()->pattern_; } | 6871 RawString* pattern() const { return raw_ptr()->pattern_; } |
6853 RawSmi* num_bracket_expressions() const { | 6872 RawSmi* num_bracket_expressions() const { |
6854 return raw_ptr()->num_bracket_expressions_; | 6873 return raw_ptr()->num_bracket_expressions_; |
6855 } | 6874 } |
6856 | 6875 |
6857 void set_pattern(const String& pattern) const; | 6876 void set_pattern(const String& pattern) const; |
6858 void set_num_bracket_expressions(intptr_t value) const; | 6877 void set_num_bracket_expressions(intptr_t value) const; |
6859 void set_is_global() const { raw_ptr()->flags_ |= kGlobal; } | 6878 void set_is_global() const { set_flags(flags() | kGlobal); } |
6860 void set_is_ignore_case() const { raw_ptr()->flags_ |= kIgnoreCase; } | 6879 void set_is_ignore_case() const { set_flags(flags() | kIgnoreCase); } |
6861 void set_is_multi_line() const { raw_ptr()->flags_ |= kMultiLine; } | 6880 void set_is_multi_line() const { set_flags(flags() | kMultiLine); } |
6862 void set_is_simple() const { raw_ptr()->type_ = kSimple; } | 6881 void set_is_simple() const { set_type(kSimple); } |
6863 void set_is_complex() const { raw_ptr()->type_ = kComplex; } | 6882 void set_is_complex() const { set_type(kComplex); } |
6864 | 6883 |
6865 void* GetDataStartAddress() const; | 6884 void* GetDataStartAddress() const; |
6866 static RawJSRegExp* FromDataStartAddress(void* data); | 6885 static RawJSRegExp* FromDataStartAddress(void* data); |
6867 const char* Flags() const; | 6886 const char* Flags() const; |
6868 | 6887 |
6869 virtual bool CanonicalizeEquals(const Instance& other) const; | 6888 virtual bool CanonicalizeEquals(const Instance& other) const; |
6870 | 6889 |
6871 static const intptr_t kBytesPerElement = 1; | 6890 static const intptr_t kBytesPerElement = 1; |
6872 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; | 6891 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
6873 | 6892 |
6874 static intptr_t InstanceSize() { | 6893 static intptr_t InstanceSize() { |
6875 ASSERT(sizeof(RawJSRegExp) == OFFSET_OF_RETURNED_VALUE(RawJSRegExp, data)); | 6894 ASSERT(sizeof(RawJSRegExp) == OFFSET_OF_RETURNED_VALUE(RawJSRegExp, data)); |
6876 return 0; | 6895 return 0; |
6877 } | 6896 } |
6878 | 6897 |
6879 static intptr_t InstanceSize(intptr_t len) { | 6898 static intptr_t InstanceSize(intptr_t len) { |
6880 ASSERT(0 <= len && len <= kMaxElements); | 6899 ASSERT(0 <= len && len <= kMaxElements); |
6881 return RoundedAllocationSize( | 6900 return RoundedAllocationSize( |
6882 sizeof(RawJSRegExp) + (len * kBytesPerElement)); | 6901 sizeof(RawJSRegExp) + (len * kBytesPerElement)); |
6883 } | 6902 } |
6884 | 6903 |
6885 static RawJSRegExp* New(intptr_t length, Heap::Space space = Heap::kNew); | 6904 static RawJSRegExp* New(intptr_t length, Heap::Space space = Heap::kNew); |
6886 | 6905 |
6887 private: | 6906 private: |
6888 void set_type(RegExType type) const { raw_ptr()->type_ = type; } | 6907 void set_type(RegExType type) const { |
6889 void set_flags(intptr_t value) const { raw_ptr()->flags_ = value; } | 6908 raw_ptr()->type_flags_ = TypeBits::update(type, raw_ptr()->type_flags_); |
6909 } | |
6910 void set_flags(intptr_t value) const { | |
6911 raw_ptr()->type_flags_ = FlagsBits::update(value, raw_ptr()->type_flags_); | |
6912 } | |
6913 | |
6914 RegExType type() const { | |
6915 return TypeBits::decode(raw_ptr()->type_flags_); | |
6916 } | |
6917 intptr_t flags() const { | |
6918 return FlagsBits::decode(raw_ptr()->type_flags_); | |
6919 } | |
6890 | 6920 |
6891 void SetLength(intptr_t value) const { | 6921 void SetLength(intptr_t value) const { |
6892 // This is only safe because we create a new Smi, which does not cause | 6922 // This is only safe because we create a new Smi, which does not cause |
6893 // heap allocation. | 6923 // heap allocation. |
6894 raw_ptr()->data_length_ = Smi::New(value); | 6924 raw_ptr()->data_length_ = Smi::New(value); |
6895 } | 6925 } |
6896 | 6926 |
6897 FINAL_HEAP_OBJECT_IMPLEMENTATION(JSRegExp, Instance); | 6927 FINAL_HEAP_OBJECT_IMPLEMENTATION(JSRegExp, Instance); |
6898 friend class Class; | 6928 friend class Class; |
6899 }; | 6929 }; |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7142 | 7172 |
7143 | 7173 |
7144 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, | 7174 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, |
7145 intptr_t index) { | 7175 intptr_t index) { |
7146 return array.At((index * kEntryLength) + kTargetFunctionIndex); | 7176 return array.At((index * kEntryLength) + kTargetFunctionIndex); |
7147 } | 7177 } |
7148 | 7178 |
7149 } // namespace dart | 7179 } // namespace dart |
7150 | 7180 |
7151 #endif // VM_OBJECT_H_ | 7181 #endif // VM_OBJECT_H_ |
OLD | NEW |