OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_OBJECTS_H_ | 5 #ifndef V8_OBJECTS_H_ |
6 #define V8_OBJECTS_H_ | 6 #define V8_OBJECTS_H_ |
7 | 7 |
8 #include "allocation.h" | 8 #include "allocation.h" |
9 #include "assert-scope.h" | 9 #include "assert-scope.h" |
10 #include "builtins.h" | 10 #include "builtins.h" |
(...skipping 3073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3084 // Dispatched behavior. | 3084 // Dispatched behavior. |
3085 DECLARE_PRINTER(FixedDoubleArray) | 3085 DECLARE_PRINTER(FixedDoubleArray) |
3086 DECLARE_VERIFIER(FixedDoubleArray) | 3086 DECLARE_VERIFIER(FixedDoubleArray) |
3087 | 3087 |
3088 private: | 3088 private: |
3089 DISALLOW_IMPLICIT_CONSTRUCTORS(FixedDoubleArray); | 3089 DISALLOW_IMPLICIT_CONSTRUCTORS(FixedDoubleArray); |
3090 }; | 3090 }; |
3091 | 3091 |
3092 | 3092 |
3093 // ConstantPoolArray describes a fixed-sized array containing constant pool | 3093 // ConstantPoolArray describes a fixed-sized array containing constant pool |
3094 // entires. | 3094 // entries. |
3095 // The format of the pool is: | 3095 // |
3096 // [0]: Field holding the first index which is a raw code target pointer entry | 3096 // A ConstantPoolArray can be structured in two different ways depending upon |
3097 // [1]: Field holding the first index which is a heap pointer entry | 3097 // whether it is extended or small. The is_extended_layout() method can be used |
3098 // [2]: Field holding the first index which is a int32 entry | 3098 // to discover which layout the constant pool has. |
3099 // [3] ... [first_code_ptr_index() - 1] : 64 bit entries | 3099 // |
3100 // [first_code_ptr_index()] ... [first_heap_ptr_index() - 1] : code pointers | 3100 // The format of a small constant pool is: |
3101 // [first_heap_ptr_index()] ... [first_int32_index() - 1] : heap pointers | 3101 // [kSmallLayout1Offset] : Small section layout bitmap 1 |
3102 // [first_int32_index()] ... [length - 1] : 32 bit entries | 3102 // [kSmallLayout2Offset] : Small section layout bitmap 2 |
3103 class ConstantPoolArray: public FixedArrayBase { | 3103 // [first_index(INT64, SMALL_SECTION)] : 64 bit entries |
3104 // ... : ... | |
3105 // [first_index(CODE_PTR, SMALL_SECTION)] : code pointer entries | |
3106 // ... : ... | |
3107 // [first_index(HEAP_PTR, SMALL_SECTION)] : heap pointer entries | |
3108 // ... : ... | |
3109 // [first_index(INT32, SMALL_SECTION)] : 32 bit entries | |
3110 // ... : ... | |
3111 // | |
3112 // If the constant pool has an extended layout, the extended section constant | |
3113 // pool also contains an extended section, which has the following format at | |
3114 // location get_extended_section_header_offset(): | |
3115 // [kExtendedInt64CountOffset] : count of extended 64 bit entries | |
3116 // [kExtendedCodePtrCountOffset] : count of extended code pointers | |
3117 // [kExtendedHeapPtrCountOffset] : count of extended heap pointers | |
3118 // [kExtendedInt32CountOffset] : count of extended 32 bit entries | |
3119 // [first_index(INT64, EXTENDED_SECTION)] : 64 bit entries | |
3120 // ... : ... | |
3121 // [first_index(CODE_PTR, EXTENDED_SECTION)]: code pointer entries | |
3122 // ... : ... | |
3123 // [first_index(HEAP_PTR, EXTENDED_SECTION)]: heap pointer entries | |
3124 // ... : ... | |
3125 // [first_index(INT32, EXTENDED_SECTION)] : 32 bit entries | |
3126 // ... : ... | |
3127 // | |
3128 class ConstantPoolArray: public HeapObject { | |
3104 public: | 3129 public: |
3105 enum WeakObjectState { | 3130 enum WeakObjectState { |
3106 NO_WEAK_OBJECTS, | 3131 NO_WEAK_OBJECTS, |
3107 WEAK_OBJECTS_IN_OPTIMIZED_CODE, | 3132 WEAK_OBJECTS_IN_OPTIMIZED_CODE, |
3108 WEAK_OBJECTS_IN_IC | 3133 WEAK_OBJECTS_IN_IC |
3109 }; | 3134 }; |
3110 | 3135 |
3111 // Getters for the field storing the first index for different type entries. | 3136 enum Type { |
3112 inline int first_code_ptr_index(); | 3137 INT32, |
3113 inline int first_heap_ptr_index(); | 3138 INT64, |
3114 inline int first_int64_index(); | 3139 CODE_PTR, |
3115 inline int first_int32_index(); | 3140 HEAP_PTR |
3141 }; | |
3116 | 3142 |
3117 // Getters for counts of different type entries. | 3143 enum LayoutSection { |
3118 inline int count_of_code_ptr_entries(); | 3144 SMALL_SECTION, |
3119 inline int count_of_heap_ptr_entries(); | 3145 EXTENDED_SECTION |
3120 inline int count_of_int64_entries(); | 3146 }; |
3121 inline int count_of_int32_entries(); | 3147 |
3148 class Iterator BASE_EMBEDDED { | |
3149 public: | |
3150 inline Iterator(ConstantPoolArray* array, Type type) | |
3151 : array_(array), type_(type), final_section_(array->final_section()) { | |
3152 current_section_ = SMALL_SECTION; | |
3153 next_index_ = array->first_index(type, SMALL_SECTION); | |
3154 update_section(); | |
3155 } | |
3156 | |
3157 inline int next_index(); | |
3158 inline bool is_finished(); | |
3159 private: | |
3160 inline void update_section(); | |
3161 ConstantPoolArray* array_; | |
3162 const Type type_; | |
3163 const LayoutSection final_section_; | |
3164 | |
3165 LayoutSection current_section_; | |
3166 int next_index_; | |
3167 }; | |
3168 | |
3169 // Getters for the first index, the last index and the count of entries of | |
3170 // a given type for a given layout section. | |
3171 inline int first_index(Type type, LayoutSection layout_section); | |
3172 inline int last_index(Type type, LayoutSection layout_section); | |
3173 inline int number_of_entries(Type type, LayoutSection layout_section); | |
3174 | |
3175 // Returns the type of the entry at the given index. | |
3176 inline Type get_type(int index); | |
3122 | 3177 |
3123 // Setter and getter for pool elements. | 3178 // Setter and getter for pool elements. |
3124 inline Address get_code_ptr_entry(int index); | 3179 inline Address get_code_ptr_entry(int index); |
3125 inline Object* get_heap_ptr_entry(int index); | 3180 inline Object* get_heap_ptr_entry(int index); |
3126 inline int64_t get_int64_entry(int index); | 3181 inline int64_t get_int64_entry(int index); |
3127 inline int32_t get_int32_entry(int index); | 3182 inline int32_t get_int32_entry(int index); |
3128 inline double get_int64_entry_as_double(int index); | 3183 inline double get_int64_entry_as_double(int index); |
3129 | 3184 |
3130 // Setter and getter for weak objects state | |
3131 inline void set_weak_object_state(WeakObjectState state); | |
3132 inline WeakObjectState get_weak_object_state(); | |
3133 | |
3134 inline void set(int index, Address value); | 3185 inline void set(int index, Address value); |
3135 inline void set(int index, Object* value); | 3186 inline void set(int index, Object* value); |
3136 inline void set(int index, int64_t value); | 3187 inline void set(int index, int64_t value); |
3137 inline void set(int index, double value); | 3188 inline void set(int index, double value); |
3138 inline void set(int index, int32_t value); | 3189 inline void set(int index, int32_t value); |
3139 | 3190 |
3140 // Set up initial state. | 3191 // Setter and getter for weak objects state |
3141 inline void Init(int number_of_int64_entries, | 3192 inline void set_weak_object_state(WeakObjectState state); |
3142 int number_of_code_ptr_entries, | 3193 inline WeakObjectState get_weak_object_state(); |
3143 int number_of_heap_ptr_entries, | 3194 |
3144 int number_of_int32_entries); | 3195 // Returns true if the constant pool has an extended layout, false if it has |
3196 // only the small layout. | |
3197 inline bool is_extended_layout(); | |
3198 | |
3199 // Returns the last LayoutSection in this constant pool array. | |
3200 inline LayoutSection final_section(); | |
3201 | |
3202 // Set up initial state for a small layout constant pool array. | |
3203 inline void Init(int int64_count, int code_ptr_count, int heap_ptr_count, | |
3204 int int32_count); | |
3205 | |
3206 // Set up initial state for an extended layout constant pool array. | |
3207 inline void InitExtended(int small_section_int64_count, | |
3208 int small_section_code_ptr_count, | |
3209 int small_section_heap_ptr_count, | |
3210 int small_section_int32_count, | |
3211 int extended_section_int64_count, | |
3212 int extended_section_code_ptr_count, | |
3213 int extended_section_heap_ptr_count, | |
3214 int extended_section_int32_count); | |
3215 | |
3216 // Clears the pointer entries with GC safe values. | |
3217 void ClearPtrEntries(Isolate* isolate); | |
3218 | |
3219 // returns the total number of entries in the constant pool array. | |
3220 inline int length(); | |
3145 | 3221 |
3146 // Garbage collection support. | 3222 // Garbage collection support. |
3147 inline static int SizeFor(int number_of_int64_entries, | 3223 inline int size(); |
3148 int number_of_code_ptr_entries, | 3224 |
3149 int number_of_heap_ptr_entries, | 3225 inline static int SizeFor(int int64_count, int code_ptr_count, |
3150 int number_of_int32_entries) { | 3226 int heap_ptr_count, int int32_count) { |
3151 return RoundUp(OffsetAt(number_of_int64_entries, | 3227 int size = kFirstEntryOffset + (int64_count * kInt64Size) + |
3152 number_of_code_ptr_entries, | 3228 (code_ptr_count * kPointerSize) + (heap_ptr_count * kPointerSize) + |
3153 number_of_heap_ptr_entries, | 3229 (int32_count * kInt32Size); |
3154 number_of_int32_entries), | 3230 return RoundUp(size, kPointerSize); |
3155 kPointerSize); | 3231 } |
3232 | |
3233 inline static int SizeForExtended(int small_section_int64_count, | |
3234 int small_section_code_ptr_count, | |
3235 int small_section_heap_ptr_count, | |
3236 int small_section_int32_count, | |
3237 int extended_section_int64_count, | |
3238 int extended_section_code_ptr_count, | |
3239 int extended_section_heap_ptr_count, | |
3240 int extended_section_int32_count) { | |
3241 int size = SizeFor(small_section_int64_count, | |
3242 small_section_code_ptr_count, | |
3243 small_section_heap_ptr_count, | |
3244 small_section_int32_count); | |
3245 size = RoundUp(size, kInt64Size); // Align extended header to 64 bits. | |
3246 size += kExtendedFirstOffset + | |
3247 (extended_section_int64_count * kInt64Size) + | |
3248 (extended_section_code_ptr_count * kPointerSize) + | |
3249 (extended_section_heap_ptr_count * kPointerSize) + | |
3250 (extended_section_int32_count * kInt32Size); | |
3251 return RoundUp(size, kPointerSize); | |
3156 } | 3252 } |
3157 | 3253 |
3158 // Code Generation support. | 3254 // Code Generation support. |
3159 inline int OffsetOfElementAt(int index) { | 3255 inline int OffsetOfElementAt(int index) { |
3160 ASSERT(index < length()); | 3256 int offset; |
3161 if (index >= first_int32_index()) { | 3257 LayoutSection section; |
3162 return OffsetAt(count_of_int64_entries(), count_of_code_ptr_entries(), | 3258 if (is_extended_layout() && index >= first_extended_section_index()) { |
3163 count_of_heap_ptr_entries(), index - first_int32_index()); | 3259 section = EXTENDED_SECTION; |
3164 } else if (index >= first_heap_ptr_index()) { | 3260 offset = get_extended_section_header_offset() + kExtendedFirstOffset; |
3165 return OffsetAt(count_of_int64_entries(), count_of_code_ptr_entries(), | |
3166 index - first_heap_ptr_index(), 0); | |
3167 } else if (index >= first_code_ptr_index()) { | |
3168 return OffsetAt(count_of_int64_entries(), index - first_code_ptr_index(), | |
3169 0, 0); | |
3170 } else { | 3261 } else { |
3171 return OffsetAt(index, 0, 0, 0); | 3262 section = SMALL_SECTION; |
3263 offset = kFirstEntryOffset; | |
3172 } | 3264 } |
3265 offset += kInt64Size * Min(Max(0, index - first_index(INT64, section)), | |
ulan
2014/06/02 12:32:58
int t = 0;
while (last_index(t, section) < index)
rmcilroy
2014/06/03 12:32:28
Done (somewhat differently both to avoid lots of s
| |
3266 number_of_entries(INT64, section)); | |
3267 offset += kPointerSize * Min(Max(0, index - first_index(CODE_PTR, section)), | |
3268 number_of_entries(CODE_PTR, section)); | |
3269 offset += kPointerSize * Min(Max(0, index - first_index(HEAP_PTR, section)), | |
3270 number_of_entries(HEAP_PTR, section)); | |
3271 offset += kInt32Size * Min(Max(0, index - first_index(INT32, section)), | |
3272 number_of_entries(INT32, section)); | |
3273 ASSERT(index <= last_index(INT32, section)); | |
3274 return offset; | |
3173 } | 3275 } |
3174 | 3276 |
3175 // Casting. | 3277 // Casting. |
3176 static inline ConstantPoolArray* cast(Object* obj); | 3278 static inline ConstantPoolArray* cast(Object* obj); |
3177 | 3279 |
3178 // Garbage collection support. | 3280 // Garbage collection support. |
3179 Object** RawFieldOfElementAt(int index) { | 3281 Object** RawFieldOfElementAt(int index) { |
3180 return HeapObject::RawField(this, OffsetOfElementAt(index)); | 3282 return HeapObject::RawField(this, OffsetOfElementAt(index)); |
3181 } | 3283 } |
3182 | 3284 |
3183 // Layout description. | 3285 // Small Layout description. |
3184 static const int kArrayLayoutOffset = FixedArray::kHeaderSize; | 3286 static const int kSmallLayout1Offset = HeapObject::kHeaderSize; |
3185 static const int kFirstOffset = kArrayLayoutOffset + kPointerSize; | 3287 static const int kSmallLayout2Offset = kSmallLayout1Offset + kInt32Size; |
3288 static const int kHeaderSize = kSmallLayout2Offset + kInt32Size; | |
3289 static const int kFirstEntryOffset = ROUND_UP(kHeaderSize, kInt64Size); | |
3186 | 3290 |
3187 static const int kFieldBitSize = 10; | 3291 static const int kSmallLayoutCountBits = 10; |
3188 static const int kMaxEntriesPerType = (1 << kFieldBitSize) - 1; | 3292 static const int kMaxSmallEntriesPerType = (1 << kSmallLayoutCountBits) - 1; |
3189 | 3293 |
3190 class NumberOfInt64EntriesField: public BitField<int, 0, kFieldBitSize> {}; | 3294 // Fields in kSmallLayout1Offset. |
3191 class NumberOfCodePtrEntriesField: public BitField<int, 10, kFieldBitSize> {}; | 3295 class Int64CountField: public BitField<int, 1, kSmallLayoutCountBits> {}; |
3192 class NumberOfHeapPtrEntriesField: public BitField<int, 20, kFieldBitSize> {}; | 3296 class CodePtrCountField: public BitField<int, 11, kSmallLayoutCountBits> {}; |
3193 class WeakObjectStateField: public BitField<WeakObjectState, 30, 2> {}; | 3297 class HeapPtrCountField: public BitField<int, 21, kSmallLayoutCountBits> {}; |
3298 class IsExtendedField: public BitField<bool, 31, 1> {}; | |
3299 | |
3300 // Fields in kSmallLayout2Offset. | |
3301 class Int32CountField: public BitField<int, 1, kSmallLayoutCountBits> {}; | |
3302 class TotalCountField: public BitField<int, 11, 12> {}; | |
3303 class WeakObjectStateField: public BitField<WeakObjectState, 23, 2> {}; | |
3304 | |
3305 // Extended layout description, which starts at | |
3306 // get_extended_section_header_offset(). | |
3307 static const int kExtendedInt64CountOffset = 0; | |
3308 static const int kExtendedCodePtrCountOffset = | |
3309 kExtendedInt64CountOffset + kPointerSize; | |
3310 static const int kExtendedHeapPtrCountOffset = | |
3311 kExtendedCodePtrCountOffset + kPointerSize; | |
3312 static const int kExtendedInt32CountOffset = | |
3313 kExtendedHeapPtrCountOffset + kPointerSize; | |
3314 static const int kExtendedFirstOffset = | |
3315 kExtendedInt32CountOffset + kPointerSize; | |
3194 | 3316 |
3195 // Dispatched behavior. | 3317 // Dispatched behavior. |
3196 void ConstantPoolIterateBody(ObjectVisitor* v); | 3318 void ConstantPoolIterateBody(ObjectVisitor* v); |
3197 | 3319 |
3198 DECLARE_PRINTER(ConstantPoolArray) | 3320 DECLARE_PRINTER(ConstantPoolArray) |
3199 DECLARE_VERIFIER(ConstantPoolArray) | 3321 DECLARE_VERIFIER(ConstantPoolArray) |
3200 | 3322 |
3201 private: | 3323 private: |
3202 inline static int OffsetAt(int number_of_int64_entries, | 3324 inline int first_extended_section_index(); |
3203 int number_of_code_ptr_entries, | 3325 inline int get_extended_section_header_offset(); |
3204 int number_of_heap_ptr_entries, | |
3205 int number_of_int32_entries) { | |
3206 return kFirstOffset | |
3207 + (number_of_int64_entries * kInt64Size) | |
3208 + (number_of_code_ptr_entries * kPointerSize) | |
3209 + (number_of_heap_ptr_entries * kPointerSize) | |
3210 + (number_of_int32_entries * kInt32Size); | |
3211 } | |
3212 | 3326 |
3213 DISALLOW_IMPLICIT_CONSTRUCTORS(ConstantPoolArray); | 3327 DISALLOW_IMPLICIT_CONSTRUCTORS(ConstantPoolArray); |
3214 }; | 3328 }; |
3215 | 3329 |
3216 | 3330 |
3217 // DescriptorArrays are fixed arrays used to hold instance descriptors. | 3331 // DescriptorArrays are fixed arrays used to hold instance descriptors. |
3218 // The format of the these objects is: | 3332 // The format of the these objects is: |
3219 // [0]: Number of descriptors | 3333 // [0]: Number of descriptors |
3220 // [1]: Either Smi(0) if uninitialized, or a pointer to small fixed array: | 3334 // [1]: Either Smi(0) if uninitialized, or a pointer to small fixed array: |
3221 // [0]: pointer to fixed array with enum cache | 3335 // [0]: pointer to fixed array with enum cache |
(...skipping 7841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
11063 } else { | 11177 } else { |
11064 value &= ~(1 << bit_position); | 11178 value &= ~(1 << bit_position); |
11065 } | 11179 } |
11066 return value; | 11180 return value; |
11067 } | 11181 } |
11068 }; | 11182 }; |
11069 | 11183 |
11070 } } // namespace v8::internal | 11184 } } // namespace v8::internal |
11071 | 11185 |
11072 #endif // V8_OBJECTS_H_ | 11186 #endif // V8_OBJECTS_H_ |
OLD | NEW |