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 "src/allocation.h" | 8 #include "src/allocation.h" |
9 #include "src/assert-scope.h" | 9 #include "src/assert-scope.h" |
10 #include "src/builtins.h" | 10 #include "src/builtins.h" |
(...skipping 3076 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3087 // Dispatched behavior. | 3087 // Dispatched behavior. |
3088 DECLARE_PRINTER(FixedDoubleArray) | 3088 DECLARE_PRINTER(FixedDoubleArray) |
3089 DECLARE_VERIFIER(FixedDoubleArray) | 3089 DECLARE_VERIFIER(FixedDoubleArray) |
3090 | 3090 |
3091 private: | 3091 private: |
3092 DISALLOW_IMPLICIT_CONSTRUCTORS(FixedDoubleArray); | 3092 DISALLOW_IMPLICIT_CONSTRUCTORS(FixedDoubleArray); |
3093 }; | 3093 }; |
3094 | 3094 |
3095 | 3095 |
3096 // ConstantPoolArray describes a fixed-sized array containing constant pool | 3096 // ConstantPoolArray describes a fixed-sized array containing constant pool |
3097 // entires. | 3097 // entries. |
3098 // The format of the pool is: | 3098 // |
3099 // [0]: Field holding the first index which is a raw code target pointer entry | 3099 // A ConstantPoolArray can be structured in two different ways depending upon |
3100 // [1]: Field holding the first index which is a heap pointer entry | 3100 // whether it is extended or small. The is_extended_layout() method can be used |
3101 // [2]: Field holding the first index which is a int32 entry | 3101 // to discover which layout the constant pool has. |
3102 // [3] ... [first_code_ptr_index() - 1] : 64 bit entries | 3102 // |
3103 // [first_code_ptr_index()] ... [first_heap_ptr_index() - 1] : code pointers | 3103 // The format of a small constant pool is: |
3104 // [first_heap_ptr_index()] ... [first_int32_index() - 1] : heap pointers | 3104 // [kSmallLayout1Offset] : Small section layout bitmap 1 |
3105 // [first_int32_index()] ... [length - 1] : 32 bit entries | 3105 // [kSmallLayout2Offset] : Small section layout bitmap 2 |
3106 class ConstantPoolArray: public FixedArrayBase { | 3106 // [first_index(INT64, SMALL_SECTION)] : 64 bit entries |
| 3107 // ... : ... |
| 3108 // [first_index(CODE_PTR, SMALL_SECTION)] : code pointer entries |
| 3109 // ... : ... |
| 3110 // [first_index(HEAP_PTR, SMALL_SECTION)] : heap pointer entries |
| 3111 // ... : ... |
| 3112 // [first_index(INT32, SMALL_SECTION)] : 32 bit entries |
| 3113 // ... : ... |
| 3114 // |
| 3115 // If the constant pool has an extended layout, the extended section constant |
| 3116 // pool also contains an extended section, which has the following format at |
| 3117 // location get_extended_section_header_offset(): |
| 3118 // [kExtendedInt64CountOffset] : count of extended 64 bit entries |
| 3119 // [kExtendedCodePtrCountOffset] : count of extended code pointers |
| 3120 // [kExtendedHeapPtrCountOffset] : count of extended heap pointers |
| 3121 // [kExtendedInt32CountOffset] : count of extended 32 bit entries |
| 3122 // [first_index(INT64, EXTENDED_SECTION)] : 64 bit entries |
| 3123 // ... : ... |
| 3124 // [first_index(CODE_PTR, EXTENDED_SECTION)]: code pointer entries |
| 3125 // ... : ... |
| 3126 // [first_index(HEAP_PTR, EXTENDED_SECTION)]: heap pointer entries |
| 3127 // ... : ... |
| 3128 // [first_index(INT32, EXTENDED_SECTION)] : 32 bit entries |
| 3129 // ... : ... |
| 3130 // |
| 3131 class ConstantPoolArray: public HeapObject { |
3107 public: | 3132 public: |
3108 enum WeakObjectState { | 3133 enum WeakObjectState { |
3109 NO_WEAK_OBJECTS, | 3134 NO_WEAK_OBJECTS, |
3110 WEAK_OBJECTS_IN_OPTIMIZED_CODE, | 3135 WEAK_OBJECTS_IN_OPTIMIZED_CODE, |
3111 WEAK_OBJECTS_IN_IC | 3136 WEAK_OBJECTS_IN_IC |
3112 }; | 3137 }; |
3113 | 3138 |
3114 // Getters for the field storing the first index for different type entries. | 3139 enum Type { |
3115 inline int first_code_ptr_index(); | 3140 INT64 = 0, |
3116 inline int first_heap_ptr_index(); | 3141 CODE_PTR, |
3117 inline int first_int64_index(); | 3142 HEAP_PTR, |
3118 inline int first_int32_index(); | 3143 INT32, |
| 3144 // Number of types stored by the ConstantPoolArrays. |
| 3145 NUMBER_OF_TYPES, |
| 3146 FIRST_TYPE = INT64, |
| 3147 LAST_TYPE = INT32 |
| 3148 }; |
3119 | 3149 |
3120 // Getters for counts of different type entries. | 3150 enum LayoutSection { |
3121 inline int count_of_code_ptr_entries(); | 3151 SMALL_SECTION = 0, |
3122 inline int count_of_heap_ptr_entries(); | 3152 EXTENDED_SECTION |
3123 inline int count_of_int64_entries(); | 3153 }; |
3124 inline int count_of_int32_entries(); | 3154 |
| 3155 class NumberOfEntries BASE_EMBEDDED { |
| 3156 public: |
| 3157 inline NumberOfEntries(int int64_count, int code_ptr_count, |
| 3158 int heap_ptr_count, int int32_count) { |
| 3159 element_counts_[INT64] = int64_count; |
| 3160 element_counts_[CODE_PTR] = code_ptr_count; |
| 3161 element_counts_[HEAP_PTR] = heap_ptr_count; |
| 3162 element_counts_[INT32] = int32_count; |
| 3163 } |
| 3164 |
| 3165 inline NumberOfEntries(ConstantPoolArray* array, LayoutSection section) { |
| 3166 element_counts_[INT64] = array->number_of_entries(INT64, section); |
| 3167 element_counts_[CODE_PTR] = array->number_of_entries(CODE_PTR, section); |
| 3168 element_counts_[HEAP_PTR] = array->number_of_entries(HEAP_PTR, section); |
| 3169 element_counts_[INT32] = array->number_of_entries(INT32, section); |
| 3170 } |
| 3171 |
| 3172 inline int count_of(Type type) const { |
| 3173 ASSERT(type < NUMBER_OF_TYPES); |
| 3174 return element_counts_[type]; |
| 3175 } |
| 3176 |
| 3177 inline int total_count() const { |
| 3178 int count = 0; |
| 3179 for (int i = 0; i < NUMBER_OF_TYPES; i++) { |
| 3180 count += element_counts_[i]; |
| 3181 } |
| 3182 return count; |
| 3183 } |
| 3184 |
| 3185 inline int are_in_range(int min, int max) const { |
| 3186 for (int i = FIRST_TYPE; i < NUMBER_OF_TYPES; i++) { |
| 3187 if (element_counts_[i] < min || element_counts_[i] > max) { |
| 3188 return false; |
| 3189 } |
| 3190 } |
| 3191 return true; |
| 3192 } |
| 3193 |
| 3194 private: |
| 3195 int element_counts_[NUMBER_OF_TYPES]; |
| 3196 }; |
| 3197 |
| 3198 class Iterator BASE_EMBEDDED { |
| 3199 public: |
| 3200 inline Iterator(ConstantPoolArray* array, Type type) |
| 3201 : array_(array), type_(type), final_section_(array->final_section()) { |
| 3202 current_section_ = SMALL_SECTION; |
| 3203 next_index_ = array->first_index(type, SMALL_SECTION); |
| 3204 update_section(); |
| 3205 } |
| 3206 |
| 3207 inline int next_index(); |
| 3208 inline bool is_finished(); |
| 3209 private: |
| 3210 inline void update_section(); |
| 3211 ConstantPoolArray* array_; |
| 3212 const Type type_; |
| 3213 const LayoutSection final_section_; |
| 3214 |
| 3215 LayoutSection current_section_; |
| 3216 int next_index_; |
| 3217 }; |
| 3218 |
| 3219 // Getters for the first index, the last index and the count of entries of |
| 3220 // a given type for a given layout section. |
| 3221 inline int first_index(Type type, LayoutSection layout_section); |
| 3222 inline int last_index(Type type, LayoutSection layout_section); |
| 3223 inline int number_of_entries(Type type, LayoutSection layout_section); |
| 3224 |
| 3225 // Returns the type of the entry at the given index. |
| 3226 inline Type get_type(int index); |
3125 | 3227 |
3126 // Setter and getter for pool elements. | 3228 // Setter and getter for pool elements. |
3127 inline Address get_code_ptr_entry(int index); | 3229 inline Address get_code_ptr_entry(int index); |
3128 inline Object* get_heap_ptr_entry(int index); | 3230 inline Object* get_heap_ptr_entry(int index); |
3129 inline int64_t get_int64_entry(int index); | 3231 inline int64_t get_int64_entry(int index); |
3130 inline int32_t get_int32_entry(int index); | 3232 inline int32_t get_int32_entry(int index); |
3131 inline double get_int64_entry_as_double(int index); | 3233 inline double get_int64_entry_as_double(int index); |
3132 | 3234 |
3133 // Setter and getter for weak objects state | |
3134 inline void set_weak_object_state(WeakObjectState state); | |
3135 inline WeakObjectState get_weak_object_state(); | |
3136 | |
3137 inline void set(int index, Address value); | 3235 inline void set(int index, Address value); |
3138 inline void set(int index, Object* value); | 3236 inline void set(int index, Object* value); |
3139 inline void set(int index, int64_t value); | 3237 inline void set(int index, int64_t value); |
3140 inline void set(int index, double value); | 3238 inline void set(int index, double value); |
3141 inline void set(int index, int32_t value); | 3239 inline void set(int index, int32_t value); |
3142 | 3240 |
3143 // Set up initial state. | 3241 // Setter and getter for weak objects state |
3144 inline void Init(int number_of_int64_entries, | 3242 inline void set_weak_object_state(WeakObjectState state); |
3145 int number_of_code_ptr_entries, | 3243 inline WeakObjectState get_weak_object_state(); |
3146 int number_of_heap_ptr_entries, | 3244 |
3147 int number_of_int32_entries); | 3245 // Returns true if the constant pool has an extended layout, false if it has |
| 3246 // only the small layout. |
| 3247 inline bool is_extended_layout(); |
| 3248 |
| 3249 // Returns the last LayoutSection in this constant pool array. |
| 3250 inline LayoutSection final_section(); |
| 3251 |
| 3252 // Set up initial state for a small layout constant pool array. |
| 3253 inline void Init(const NumberOfEntries& small); |
| 3254 |
| 3255 // Set up initial state for an extended layout constant pool array. |
| 3256 inline void InitExtended(const NumberOfEntries& small, |
| 3257 const NumberOfEntries& extended); |
| 3258 |
| 3259 // Clears the pointer entries with GC safe values. |
| 3260 void ClearPtrEntries(Isolate* isolate); |
| 3261 |
| 3262 // returns the total number of entries in the constant pool array. |
| 3263 inline int length(); |
3148 | 3264 |
3149 // Garbage collection support. | 3265 // Garbage collection support. |
3150 inline static int SizeFor(int number_of_int64_entries, | 3266 inline int size(); |
3151 int number_of_code_ptr_entries, | 3267 |
3152 int number_of_heap_ptr_entries, | 3268 inline static int SizeFor(const NumberOfEntries& small) { |
3153 int number_of_int32_entries) { | 3269 int size = kFirstEntryOffset + |
3154 return RoundUp(OffsetAt(number_of_int64_entries, | 3270 (small.count_of(INT64) * kInt64Size) + |
3155 number_of_code_ptr_entries, | 3271 (small.count_of(CODE_PTR) * kPointerSize) + |
3156 number_of_heap_ptr_entries, | 3272 (small.count_of(HEAP_PTR) * kPointerSize) + |
3157 number_of_int32_entries), | 3273 (small.count_of(INT32) * kInt32Size); |
3158 kPointerSize); | 3274 return RoundUp(size, kPointerSize); |
| 3275 } |
| 3276 |
| 3277 inline static int SizeForExtended(const NumberOfEntries& small, |
| 3278 const NumberOfEntries& extended) { |
| 3279 int size = SizeFor(small); |
| 3280 size = RoundUp(size, kInt64Size); // Align extended header to 64 bits. |
| 3281 size += kExtendedFirstOffset + |
| 3282 (extended.count_of(INT64) * kInt64Size) + |
| 3283 (extended.count_of(CODE_PTR) * kPointerSize) + |
| 3284 (extended.count_of(HEAP_PTR) * kPointerSize) + |
| 3285 (extended.count_of(INT32) * kInt32Size); |
| 3286 return RoundUp(size, kPointerSize); |
| 3287 } |
| 3288 |
| 3289 inline static int entry_size(Type type) { |
| 3290 switch (type) { |
| 3291 case INT32: |
| 3292 return kInt32Size; |
| 3293 case INT64: |
| 3294 return kInt64Size; |
| 3295 case CODE_PTR: |
| 3296 case HEAP_PTR: |
| 3297 return kPointerSize; |
| 3298 default: |
| 3299 UNREACHABLE(); |
| 3300 return 0; |
| 3301 } |
3159 } | 3302 } |
3160 | 3303 |
3161 // Code Generation support. | 3304 // Code Generation support. |
3162 inline int OffsetOfElementAt(int index) { | 3305 inline int OffsetOfElementAt(int index) { |
3163 ASSERT(index < length()); | 3306 int offset; |
3164 if (index >= first_int32_index()) { | 3307 LayoutSection section; |
3165 return OffsetAt(count_of_int64_entries(), count_of_code_ptr_entries(), | 3308 if (is_extended_layout() && index >= first_extended_section_index()) { |
3166 count_of_heap_ptr_entries(), index - first_int32_index()); | 3309 section = EXTENDED_SECTION; |
3167 } else if (index >= first_heap_ptr_index()) { | 3310 offset = get_extended_section_header_offset() + kExtendedFirstOffset; |
3168 return OffsetAt(count_of_int64_entries(), count_of_code_ptr_entries(), | |
3169 index - first_heap_ptr_index(), 0); | |
3170 } else if (index >= first_code_ptr_index()) { | |
3171 return OffsetAt(count_of_int64_entries(), index - first_code_ptr_index(), | |
3172 0, 0); | |
3173 } else { | 3311 } else { |
3174 return OffsetAt(index, 0, 0, 0); | 3312 section = SMALL_SECTION; |
| 3313 offset = kFirstEntryOffset; |
3175 } | 3314 } |
| 3315 |
| 3316 // Add offsets for the preceding type sections. |
| 3317 ASSERT(index <= last_index(LAST_TYPE, section)); |
| 3318 for (Type type = FIRST_TYPE; index > last_index(type, section); |
| 3319 type = next_type(type)) { |
| 3320 offset += entry_size(type) * number_of_entries(type, section); |
| 3321 } |
| 3322 |
| 3323 // Add offset for the index in it's type. |
| 3324 Type type = get_type(index); |
| 3325 offset += entry_size(type) * (index - first_index(type, section)); |
| 3326 return offset; |
3176 } | 3327 } |
3177 | 3328 |
3178 // Casting. | 3329 // Casting. |
3179 static inline ConstantPoolArray* cast(Object* obj); | 3330 static inline ConstantPoolArray* cast(Object* obj); |
3180 | 3331 |
3181 // Garbage collection support. | 3332 // Garbage collection support. |
3182 Object** RawFieldOfElementAt(int index) { | 3333 Object** RawFieldOfElementAt(int index) { |
3183 return HeapObject::RawField(this, OffsetOfElementAt(index)); | 3334 return HeapObject::RawField(this, OffsetOfElementAt(index)); |
3184 } | 3335 } |
3185 | 3336 |
3186 // Layout description. | 3337 // Small Layout description. |
3187 static const int kArrayLayoutOffset = FixedArray::kHeaderSize; | 3338 static const int kSmallLayout1Offset = HeapObject::kHeaderSize; |
3188 static const int kFirstOffset = kArrayLayoutOffset + kPointerSize; | 3339 static const int kSmallLayout2Offset = kSmallLayout1Offset + kInt32Size; |
| 3340 static const int kHeaderSize = kSmallLayout2Offset + kInt32Size; |
| 3341 static const int kFirstEntryOffset = ROUND_UP(kHeaderSize, kInt64Size); |
3189 | 3342 |
3190 static const int kFieldBitSize = 10; | 3343 static const int kSmallLayoutCountBits = 10; |
3191 static const int kMaxEntriesPerType = (1 << kFieldBitSize) - 1; | 3344 static const int kMaxSmallEntriesPerType = (1 << kSmallLayoutCountBits) - 1; |
3192 | 3345 |
3193 class NumberOfInt64EntriesField: public BitField<int, 0, kFieldBitSize> {}; | 3346 // Fields in kSmallLayout1Offset. |
3194 class NumberOfCodePtrEntriesField: public BitField<int, 10, kFieldBitSize> {}; | 3347 class Int64CountField: public BitField<int, 1, kSmallLayoutCountBits> {}; |
3195 class NumberOfHeapPtrEntriesField: public BitField<int, 20, kFieldBitSize> {}; | 3348 class CodePtrCountField: public BitField<int, 11, kSmallLayoutCountBits> {}; |
3196 class WeakObjectStateField: public BitField<WeakObjectState, 30, 2> {}; | 3349 class HeapPtrCountField: public BitField<int, 21, kSmallLayoutCountBits> {}; |
| 3350 class IsExtendedField: public BitField<bool, 31, 1> {}; |
| 3351 |
| 3352 // Fields in kSmallLayout2Offset. |
| 3353 class Int32CountField: public BitField<int, 1, kSmallLayoutCountBits> {}; |
| 3354 class TotalCountField: public BitField<int, 11, 12> {}; |
| 3355 class WeakObjectStateField: public BitField<WeakObjectState, 23, 2> {}; |
| 3356 |
| 3357 // Extended layout description, which starts at |
| 3358 // get_extended_section_header_offset(). |
| 3359 static const int kExtendedInt64CountOffset = 0; |
| 3360 static const int kExtendedCodePtrCountOffset = |
| 3361 kExtendedInt64CountOffset + kPointerSize; |
| 3362 static const int kExtendedHeapPtrCountOffset = |
| 3363 kExtendedCodePtrCountOffset + kPointerSize; |
| 3364 static const int kExtendedInt32CountOffset = |
| 3365 kExtendedHeapPtrCountOffset + kPointerSize; |
| 3366 static const int kExtendedFirstOffset = |
| 3367 kExtendedInt32CountOffset + kPointerSize; |
3197 | 3368 |
3198 // Dispatched behavior. | 3369 // Dispatched behavior. |
3199 void ConstantPoolIterateBody(ObjectVisitor* v); | 3370 void ConstantPoolIterateBody(ObjectVisitor* v); |
3200 | 3371 |
3201 DECLARE_PRINTER(ConstantPoolArray) | 3372 DECLARE_PRINTER(ConstantPoolArray) |
3202 DECLARE_VERIFIER(ConstantPoolArray) | 3373 DECLARE_VERIFIER(ConstantPoolArray) |
3203 | 3374 |
3204 private: | 3375 private: |
3205 inline static int OffsetAt(int number_of_int64_entries, | 3376 inline int first_extended_section_index(); |
3206 int number_of_code_ptr_entries, | 3377 inline int get_extended_section_header_offset(); |
3207 int number_of_heap_ptr_entries, | 3378 |
3208 int number_of_int32_entries) { | 3379 inline static Type next_type(Type type) { |
3209 return kFirstOffset | 3380 ASSERT(type >= FIRST_TYPE && type < NUMBER_OF_TYPES); |
3210 + (number_of_int64_entries * kInt64Size) | 3381 int type_int = static_cast<int>(type); |
3211 + (number_of_code_ptr_entries * kPointerSize) | 3382 return static_cast<Type>(++type_int); |
3212 + (number_of_heap_ptr_entries * kPointerSize) | |
3213 + (number_of_int32_entries * kInt32Size); | |
3214 } | 3383 } |
3215 | 3384 |
3216 DISALLOW_IMPLICIT_CONSTRUCTORS(ConstantPoolArray); | 3385 DISALLOW_IMPLICIT_CONSTRUCTORS(ConstantPoolArray); |
3217 }; | 3386 }; |
3218 | 3387 |
3219 | 3388 |
3220 // DescriptorArrays are fixed arrays used to hold instance descriptors. | 3389 // DescriptorArrays are fixed arrays used to hold instance descriptors. |
3221 // The format of the these objects is: | 3390 // The format of the these objects is: |
3222 // [0]: Number of descriptors | 3391 // [0]: Number of descriptors |
3223 // [1]: Either Smi(0) if uninitialized, or a pointer to small fixed array: | 3392 // [1]: Either Smi(0) if uninitialized, or a pointer to small fixed array: |
(...skipping 7851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11075 } else { | 11244 } else { |
11076 value &= ~(1 << bit_position); | 11245 value &= ~(1 << bit_position); |
11077 } | 11246 } |
11078 return value; | 11247 return value; |
11079 } | 11248 } |
11080 }; | 11249 }; |
11081 | 11250 |
11082 } } // namespace v8::internal | 11251 } } // namespace v8::internal |
11083 | 11252 |
11084 #endif // V8_OBJECTS_H_ | 11253 #endif // V8_OBJECTS_H_ |
OLD | NEW |