| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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_LAYOUT_DESCRIPTOR_INL_H_ | 5 #ifndef V8_LAYOUT_DESCRIPTOR_INL_H_ |
| 6 #define V8_LAYOUT_DESCRIPTOR_INL_H_ | 6 #define V8_LAYOUT_DESCRIPTOR_INL_H_ |
| 7 | 7 |
| 8 #include "src/layout-descriptor.h" | 8 #include "src/layout-descriptor.h" |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| 11 namespace internal { | 11 namespace internal { |
| 12 | 12 |
| 13 LayoutDescriptor* LayoutDescriptor::FromSmi(Smi* smi) { | 13 LayoutDescriptor* LayoutDescriptor::FromSmi(Smi* smi) { |
| 14 return LayoutDescriptor::cast(smi); | 14 return LayoutDescriptor::cast(smi); |
| 15 } | 15 } |
| 16 | 16 |
| 17 | 17 |
| 18 Handle<LayoutDescriptor> LayoutDescriptor::New(Isolate* isolate, int length) { | 18 Handle<LayoutDescriptor> LayoutDescriptor::New(Isolate* isolate, int length) { |
| 19 if (length <= kSmiValueSize) { | 19 if (length <= kSmiValueSize) { |
| 20 // The whole bit vector fits into a smi. | 20 // The whole bit vector fits into a smi. |
| 21 return handle(LayoutDescriptor::FromSmi(Smi::FromInt(0)), isolate); | 21 return handle(LayoutDescriptor::FromSmi(Smi::FromInt(0)), isolate); |
| 22 } | 22 } |
| 23 length = GetSlowModeBackingStoreLength(length); | 23 length = GetSlowModeBackingStoreLength(length); |
| 24 return Handle<LayoutDescriptor>::cast( | 24 return Handle<LayoutDescriptor>::cast( |
| 25 isolate->factory()->NewJSTypedArray(UINT32_ELEMENTS, length)); | 25 isolate->factory()->NewFixedTypedArray(length, kExternalUint32Array)); |
| 26 } | 26 } |
| 27 | 27 |
| 28 | 28 |
| 29 bool LayoutDescriptor::InobjectUnboxedField(int inobject_properties, | 29 bool LayoutDescriptor::InobjectUnboxedField(int inobject_properties, |
| 30 PropertyDetails details) { | 30 PropertyDetails details) { |
| 31 if (details.type() != DATA || !details.representation().IsDouble()) { | 31 if (details.type() != DATA || !details.representation().IsDouble()) { |
| 32 return false; | 32 return false; |
| 33 } | 33 } |
| 34 // We care only about in-object properties. | 34 // We care only about in-object properties. |
| 35 return details.field_index() < inobject_properties; | 35 return details.field_index() < inobject_properties; |
| 36 } | 36 } |
| 37 | 37 |
| 38 | 38 |
| 39 LayoutDescriptor* LayoutDescriptor::FastPointerLayout() { | 39 LayoutDescriptor* LayoutDescriptor::FastPointerLayout() { |
| 40 return LayoutDescriptor::FromSmi(Smi::FromInt(0)); | 40 return LayoutDescriptor::FromSmi(Smi::FromInt(0)); |
| 41 } | 41 } |
| 42 | 42 |
| 43 | 43 |
| 44 bool LayoutDescriptor::GetIndexes(int field_index, int* layout_word_index, | 44 bool LayoutDescriptor::GetIndexes(int field_index, int* layout_word_index, |
| 45 int* layout_bit_index) { | 45 int* layout_bit_index) { |
| 46 if (static_cast<unsigned>(field_index) >= static_cast<unsigned>(capacity())) { | 46 if (static_cast<unsigned>(field_index) >= static_cast<unsigned>(capacity())) { |
| 47 return false; | 47 return false; |
| 48 } | 48 } |
| 49 | 49 |
| 50 *layout_word_index = field_index / kNumberOfBits; | 50 *layout_word_index = field_index / kNumberOfBits; |
| 51 CHECK((!IsSmi() && (*layout_word_index < Smi::cast(length())->value())) || | 51 CHECK((!IsSmi() && (*layout_word_index < length())) || |
| 52 (IsSmi() && (*layout_word_index < 1))); | 52 (IsSmi() && (*layout_word_index < 1))); |
| 53 | 53 |
| 54 *layout_bit_index = field_index % kNumberOfBits; | 54 *layout_bit_index = field_index % kNumberOfBits; |
| 55 return true; | 55 return true; |
| 56 } | 56 } |
| 57 | 57 |
| 58 | 58 |
| 59 LayoutDescriptor* LayoutDescriptor::SetTagged(int field_index, bool tagged) { | 59 LayoutDescriptor* LayoutDescriptor::SetTagged(int field_index, bool tagged) { |
| 60 int layout_word_index; | 60 int layout_word_index; |
| 61 int layout_bit_index; | 61 int layout_bit_index; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 116 |
| 117 bool LayoutDescriptor::IsFastPointerLayout(Object* layout_descriptor) { | 117 bool LayoutDescriptor::IsFastPointerLayout(Object* layout_descriptor) { |
| 118 return layout_descriptor == FastPointerLayout(); | 118 return layout_descriptor == FastPointerLayout(); |
| 119 } | 119 } |
| 120 | 120 |
| 121 | 121 |
| 122 bool LayoutDescriptor::IsSlowLayout() { return !IsSmi(); } | 122 bool LayoutDescriptor::IsSlowLayout() { return !IsSmi(); } |
| 123 | 123 |
| 124 | 124 |
| 125 int LayoutDescriptor::capacity() { | 125 int LayoutDescriptor::capacity() { |
| 126 return IsSlowLayout() ? (Smi::cast(length())->value() * kNumberOfBits) | 126 return IsSlowLayout() ? (length() * kNumberOfBits) : kSmiValueSize; |
| 127 : kSmiValueSize; | |
| 128 } | 127 } |
| 129 | 128 |
| 130 | 129 |
| 131 uint32_t LayoutDescriptor::get_scalar(int index) { | |
| 132 DCHECK(IsSlowLayout()); | |
| 133 return GcSafeElements()->get_scalar(index); | |
| 134 } | |
| 135 | |
| 136 | |
| 137 void LayoutDescriptor::set(int index, uint32_t value) { | |
| 138 DCHECK(IsSlowLayout()); | |
| 139 GcSafeElements()->set(index, value); | |
| 140 } | |
| 141 | |
| 142 | |
| 143 LayoutDescriptor* LayoutDescriptor::cast_gc_safe(Object* object) { | 130 LayoutDescriptor* LayoutDescriptor::cast_gc_safe(Object* object) { |
| 144 if (object->IsSmi()) { | 131 if (object->IsSmi()) { |
| 145 // Fast mode layout descriptor. | 132 // Fast mode layout descriptor. |
| 146 return reinterpret_cast<LayoutDescriptor*>(object); | 133 return reinterpret_cast<LayoutDescriptor*>(object); |
| 147 } | 134 } |
| 148 | 135 |
| 149 // This is a mixed descriptor which is a fixed typed array. | 136 // This is a mixed descriptor which is a fixed typed array. |
| 150 MapWord map_word = reinterpret_cast<HeapObject*>(object)->map_word(); | 137 MapWord map_word = reinterpret_cast<HeapObject*>(object)->map_word(); |
| 151 if (map_word.IsForwardingAddress()) { | 138 if (map_word.IsForwardingAddress()) { |
| 152 // Mark-compact has already moved layout descriptor. | 139 // Mark-compact has already moved layout descriptor. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 int field_index = details.field_index(); | 207 int field_index = details.field_index(); |
| 221 layout_descriptor = layout_descriptor->SetRawData(field_index); | 208 layout_descriptor = layout_descriptor->SetRawData(field_index); |
| 222 if (details.field_width_in_words() > 1) { | 209 if (details.field_width_in_words() > 1) { |
| 223 layout_descriptor = layout_descriptor->SetRawData(field_index + 1); | 210 layout_descriptor = layout_descriptor->SetRawData(field_index + 1); |
| 224 } | 211 } |
| 225 } | 212 } |
| 226 return layout_descriptor; | 213 return layout_descriptor; |
| 227 } | 214 } |
| 228 | 215 |
| 229 | 216 |
| 230 FixedTypedArray<Uint32ArrayTraits>* LayoutDescriptor::GcSafeElements() { | |
| 231 MapWord map_word = HeapObject::cast(elements())->map_word(); | |
| 232 if (map_word.IsForwardingAddress()) { | |
| 233 return FixedTypedArray<Uint32ArrayTraits>::cast( | |
| 234 map_word.ToForwardingAddress()); | |
| 235 } | |
| 236 return FixedTypedArray<Uint32ArrayTraits>::cast(elements()); | |
| 237 } | |
| 238 | |
| 239 | |
| 240 // InobjectPropertiesHelper is a helper class for querying whether inobject | 217 // InobjectPropertiesHelper is a helper class for querying whether inobject |
| 241 // property at offset is Double or not. | 218 // property at offset is Double or not. |
| 242 LayoutDescriptorHelper::LayoutDescriptorHelper(Map* map) | 219 LayoutDescriptorHelper::LayoutDescriptorHelper(Map* map) |
| 243 : all_fields_tagged_(true), | 220 : all_fields_tagged_(true), |
| 244 header_size_(0), | 221 header_size_(0), |
| 245 layout_descriptor_(LayoutDescriptor::FastPointerLayout()) { | 222 layout_descriptor_(LayoutDescriptor::FastPointerLayout()) { |
| 246 if (!FLAG_unbox_double_fields) return; | 223 if (!FLAG_unbox_double_fields) return; |
| 247 | 224 |
| 248 layout_descriptor_ = map->layout_descriptor_gc_safe(); | 225 layout_descriptor_ = map->layout_descriptor_gc_safe(); |
| 249 if (layout_descriptor_->IsFastPointerLayout()) { | 226 if (layout_descriptor_->IsFastPointerLayout()) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 265 // Object headers do not contain non-tagged fields. | 242 // Object headers do not contain non-tagged fields. |
| 266 if (offset_in_bytes < header_size_) return true; | 243 if (offset_in_bytes < header_size_) return true; |
| 267 int field_index = (offset_in_bytes - header_size_) / kPointerSize; | 244 int field_index = (offset_in_bytes - header_size_) / kPointerSize; |
| 268 | 245 |
| 269 return layout_descriptor_->IsTagged(field_index); | 246 return layout_descriptor_->IsTagged(field_index); |
| 270 } | 247 } |
| 271 } | 248 } |
| 272 } // namespace v8::internal | 249 } // namespace v8::internal |
| 273 | 250 |
| 274 #endif // V8_LAYOUT_DESCRIPTOR_INL_H_ | 251 #endif // V8_LAYOUT_DESCRIPTOR_INL_H_ |
| OLD | NEW |