Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/layout-descriptor-inl.h

Issue 1033273005: Layout descriptor must be trimmed when corresponding descriptors array is trimmed to stay in sync. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 // This is a mixed descriptor which is a fixed typed array. 147 // This is a mixed descriptor which is a fixed typed array.
148 MapWord map_word = reinterpret_cast<HeapObject*>(object)->map_word(); 148 MapWord map_word = reinterpret_cast<HeapObject*>(object)->map_word();
149 if (map_word.IsForwardingAddress()) { 149 if (map_word.IsForwardingAddress()) {
150 // Mark-compact has already moved layout descriptor. 150 // Mark-compact has already moved layout descriptor.
151 object = map_word.ToForwardingAddress(); 151 object = map_word.ToForwardingAddress();
152 } 152 }
153 return LayoutDescriptor::cast(object); 153 return LayoutDescriptor::cast(object);
154 } 154 }
155 155
156 156
157 int LayoutDescriptor::CalculateCapacity(Map* map, DescriptorArray* descriptors,
158 int num_descriptors) {
159 int inobject_properties = map->inobject_properties();
160 if (inobject_properties == 0) return 0;
161
162 DCHECK(num_descriptors <= descriptors->number_of_descriptors());
Toon Verwaest 2015/03/30 11:42:25 _LE
Igor Sheludko 2015/03/30 16:01:29 Done.
163
164 int layout_descriptor_length;
165 const int kMaxWordsPerField = kDoubleSize / kPointerSize;
166
167 if (num_descriptors <= kSmiValueSize / kMaxWordsPerField) {
168 // Even in the "worst" case (all fields are doubles) it would fit into
169 // a Smi, so no need to calculate length.
170 layout_descriptor_length = kSmiValueSize;
171
172 } else {
173 layout_descriptor_length = 0;
174
175 for (int i = 0; i < num_descriptors; i++) {
176 PropertyDetails details = descriptors->GetDetails(i);
177 if (!InobjectUnboxedField(inobject_properties, details)) continue;
178 int field_index = details.field_index();
179 int field_width_in_words = details.field_width_in_words();
180 layout_descriptor_length =
181 Max(layout_descriptor_length, field_index + field_width_in_words);
182 }
183 }
184 layout_descriptor_length = Min(layout_descriptor_length, inobject_properties);
185 return layout_descriptor_length;
186 }
187
188
189 LayoutDescriptor* LayoutDescriptor::Initialize(
190 LayoutDescriptor* layout_descriptor, Map* map, DescriptorArray* descriptors,
191 int num_descriptors) {
192 DisallowHeapAllocation no_allocation;
193 int inobject_properties = map->inobject_properties();
194
195 for (int i = 0; i < num_descriptors; i++) {
196 PropertyDetails details = descriptors->GetDetails(i);
197 if (!InobjectUnboxedField(inobject_properties, details)) {
198 DCHECK(details.location() != kField ||
199 layout_descriptor->IsTagged(details.field_index()));
200 continue;
201 }
202 int field_index = details.field_index();
203 layout_descriptor = layout_descriptor->SetRawData(field_index);
204 if (details.field_width_in_words() > 1) {
205 layout_descriptor = layout_descriptor->SetRawData(field_index + 1);
206 }
207 }
208 return layout_descriptor;
209 }
210
211
157 // InobjectPropertiesHelper is a helper class for querying whether inobject 212 // InobjectPropertiesHelper is a helper class for querying whether inobject
158 // property at offset is Double or not. 213 // property at offset is Double or not.
159 LayoutDescriptorHelper::LayoutDescriptorHelper(Map* map) 214 LayoutDescriptorHelper::LayoutDescriptorHelper(Map* map)
160 : all_fields_tagged_(true), 215 : all_fields_tagged_(true),
161 header_size_(0), 216 header_size_(0),
162 layout_descriptor_(LayoutDescriptor::FastPointerLayout()) { 217 layout_descriptor_(LayoutDescriptor::FastPointerLayout()) {
163 if (!FLAG_unbox_double_fields) return; 218 if (!FLAG_unbox_double_fields) return;
164 219
165 layout_descriptor_ = map->layout_descriptor_gc_safe(); 220 layout_descriptor_ = map->layout_descriptor_gc_safe();
166 if (layout_descriptor_->IsFastPointerLayout()) { 221 if (layout_descriptor_->IsFastPointerLayout()) {
(...skipping 15 matching lines...) Expand all
182 // Object headers do not contain non-tagged fields. 237 // Object headers do not contain non-tagged fields.
183 if (offset_in_bytes < header_size_) return true; 238 if (offset_in_bytes < header_size_) return true;
184 int field_index = (offset_in_bytes - header_size_) / kPointerSize; 239 int field_index = (offset_in_bytes - header_size_) / kPointerSize;
185 240
186 return layout_descriptor_->IsTagged(field_index); 241 return layout_descriptor_->IsTagged(field_index);
187 } 242 }
188 } 243 }
189 } // namespace v8::internal 244 } // namespace v8::internal
190 245
191 #endif // V8_LAYOUT_DESCRIPTOR_INL_H_ 246 #endif // V8_LAYOUT_DESCRIPTOR_INL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698