| 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 { |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 // to utilize that "lost" space which could also help to avoid layout | 154 // to utilize that "lost" space which could also help to avoid layout |
| 155 // descriptor reallocations. | 155 // descriptor reallocations. |
| 156 ++length; | 156 ++length; |
| 157 } | 157 } |
| 158 return length; | 158 return length; |
| 159 } | 159 } |
| 160 | 160 |
| 161 | 161 |
| 162 int LayoutDescriptor::CalculateCapacity(Map* map, DescriptorArray* descriptors, | 162 int LayoutDescriptor::CalculateCapacity(Map* map, DescriptorArray* descriptors, |
| 163 int num_descriptors) { | 163 int num_descriptors) { |
| 164 int inobject_properties = map->inobject_properties(); | 164 int inobject_properties = map->GetInObjectProperties(); |
| 165 if (inobject_properties == 0) return 0; | 165 if (inobject_properties == 0) return 0; |
| 166 | 166 |
| 167 DCHECK_LE(num_descriptors, descriptors->number_of_descriptors()); | 167 DCHECK_LE(num_descriptors, descriptors->number_of_descriptors()); |
| 168 | 168 |
| 169 int layout_descriptor_length; | 169 int layout_descriptor_length; |
| 170 const int kMaxWordsPerField = kDoubleSize / kPointerSize; | 170 const int kMaxWordsPerField = kDoubleSize / kPointerSize; |
| 171 | 171 |
| 172 if (num_descriptors <= kSmiValueSize / kMaxWordsPerField) { | 172 if (num_descriptors <= kSmiValueSize / kMaxWordsPerField) { |
| 173 // Even in the "worst" case (all fields are doubles) it would fit into | 173 // Even in the "worst" case (all fields are doubles) it would fit into |
| 174 // a Smi, so no need to calculate length. | 174 // a Smi, so no need to calculate length. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 188 } | 188 } |
| 189 layout_descriptor_length = Min(layout_descriptor_length, inobject_properties); | 189 layout_descriptor_length = Min(layout_descriptor_length, inobject_properties); |
| 190 return layout_descriptor_length; | 190 return layout_descriptor_length; |
| 191 } | 191 } |
| 192 | 192 |
| 193 | 193 |
| 194 LayoutDescriptor* LayoutDescriptor::Initialize( | 194 LayoutDescriptor* LayoutDescriptor::Initialize( |
| 195 LayoutDescriptor* layout_descriptor, Map* map, DescriptorArray* descriptors, | 195 LayoutDescriptor* layout_descriptor, Map* map, DescriptorArray* descriptors, |
| 196 int num_descriptors) { | 196 int num_descriptors) { |
| 197 DisallowHeapAllocation no_allocation; | 197 DisallowHeapAllocation no_allocation; |
| 198 int inobject_properties = map->inobject_properties(); | 198 int inobject_properties = map->GetInObjectProperties(); |
| 199 | 199 |
| 200 for (int i = 0; i < num_descriptors; i++) { | 200 for (int i = 0; i < num_descriptors; i++) { |
| 201 PropertyDetails details = descriptors->GetDetails(i); | 201 PropertyDetails details = descriptors->GetDetails(i); |
| 202 if (!InobjectUnboxedField(inobject_properties, details)) { | 202 if (!InobjectUnboxedField(inobject_properties, details)) { |
| 203 DCHECK(details.location() != kField || | 203 DCHECK(details.location() != kField || |
| 204 layout_descriptor->IsTagged(details.field_index())); | 204 layout_descriptor->IsTagged(details.field_index())); |
| 205 continue; | 205 continue; |
| 206 } | 206 } |
| 207 int field_index = details.field_index(); | 207 int field_index = details.field_index(); |
| 208 layout_descriptor = layout_descriptor->SetRawData(field_index); | 208 layout_descriptor = layout_descriptor->SetRawData(field_index); |
| 209 if (details.field_width_in_words() > 1) { | 209 if (details.field_width_in_words() > 1) { |
| 210 layout_descriptor = layout_descriptor->SetRawData(field_index + 1); | 210 layout_descriptor = layout_descriptor->SetRawData(field_index + 1); |
| 211 } | 211 } |
| 212 } | 212 } |
| 213 return layout_descriptor; | 213 return layout_descriptor; |
| 214 } | 214 } |
| 215 | 215 |
| 216 | 216 |
| 217 // InobjectPropertiesHelper is a helper class for querying whether inobject | 217 // LayoutDescriptorHelper is a helper class for querying whether inobject |
| 218 // property at offset is Double or not. | 218 // property at offset is Double or not. |
| 219 LayoutDescriptorHelper::LayoutDescriptorHelper(Map* map) | 219 LayoutDescriptorHelper::LayoutDescriptorHelper(Map* map) |
| 220 : all_fields_tagged_(true), | 220 : all_fields_tagged_(true), |
| 221 header_size_(0), | 221 header_size_(0), |
| 222 layout_descriptor_(LayoutDescriptor::FastPointerLayout()) { | 222 layout_descriptor_(LayoutDescriptor::FastPointerLayout()) { |
| 223 if (!FLAG_unbox_double_fields) return; | 223 if (!FLAG_unbox_double_fields) return; |
| 224 | 224 |
| 225 layout_descriptor_ = map->layout_descriptor_gc_safe(); | 225 layout_descriptor_ = map->layout_descriptor_gc_safe(); |
| 226 if (layout_descriptor_->IsFastPointerLayout()) { | 226 if (layout_descriptor_->IsFastPointerLayout()) { |
| 227 return; | 227 return; |
| 228 } | 228 } |
| 229 | 229 |
| 230 int inobject_properties = map->inobject_properties(); | 230 int inobject_properties = map->GetInObjectProperties(); |
| 231 DCHECK(inobject_properties > 0); | 231 DCHECK(inobject_properties > 0); |
| 232 header_size_ = map->instance_size() - (inobject_properties * kPointerSize); | 232 header_size_ = map->instance_size() - (inobject_properties * kPointerSize); |
| 233 DCHECK(header_size_ >= 0); | 233 DCHECK(header_size_ >= 0); |
| 234 | 234 |
| 235 all_fields_tagged_ = false; | 235 all_fields_tagged_ = false; |
| 236 } | 236 } |
| 237 | 237 |
| 238 | 238 |
| 239 bool LayoutDescriptorHelper::IsTagged(int offset_in_bytes) { | 239 bool LayoutDescriptorHelper::IsTagged(int offset_in_bytes) { |
| 240 DCHECK(IsAligned(offset_in_bytes, kPointerSize)); | 240 DCHECK(IsAligned(offset_in_bytes, kPointerSize)); |
| 241 if (all_fields_tagged_) return true; | 241 if (all_fields_tagged_) return true; |
| 242 // Object headers do not contain non-tagged fields. | 242 // Object headers do not contain non-tagged fields. |
| 243 if (offset_in_bytes < header_size_) return true; | 243 if (offset_in_bytes < header_size_) return true; |
| 244 int field_index = (offset_in_bytes - header_size_) / kPointerSize; | 244 int field_index = (offset_in_bytes - header_size_) / kPointerSize; |
| 245 | 245 |
| 246 return layout_descriptor_->IsTagged(field_index); | 246 return layout_descriptor_->IsTagged(field_index); |
| 247 } | 247 } |
| 248 } | 248 } |
| 249 } // namespace v8::internal | 249 } // namespace v8::internal |
| 250 | 250 |
| 251 #endif // V8_LAYOUT_DESCRIPTOR_INL_H_ | 251 #endif // V8_LAYOUT_DESCRIPTOR_INL_H_ |
| OLD | NEW |