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 #include <sstream> | 5 #include <sstream> |
6 | 6 |
7 #include "src/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
10 #include "src/layout-descriptor.h" | 10 #include "src/layout-descriptor.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 int new_capacity) { | 99 int new_capacity) { |
100 int old_capacity = layout_descriptor->capacity(); | 100 int old_capacity = layout_descriptor->capacity(); |
101 if (new_capacity <= old_capacity) { | 101 if (new_capacity <= old_capacity) { |
102 return layout_descriptor; | 102 return layout_descriptor; |
103 } | 103 } |
104 Handle<LayoutDescriptor> new_layout_descriptor = | 104 Handle<LayoutDescriptor> new_layout_descriptor = |
105 LayoutDescriptor::New(isolate, new_capacity); | 105 LayoutDescriptor::New(isolate, new_capacity); |
106 DCHECK(new_layout_descriptor->IsSlowLayout()); | 106 DCHECK(new_layout_descriptor->IsSlowLayout()); |
107 | 107 |
108 if (layout_descriptor->IsSlowLayout()) { | 108 if (layout_descriptor->IsSlowLayout()) { |
109 memcpy(new_layout_descriptor->DataPtr(), layout_descriptor->DataPtr(), | 109 DisallowHeapAllocation no_gc; |
110 layout_descriptor->DataSize()); | 110 Handle<FixedTypedArrayBase> elements( |
| 111 FixedTypedArrayBase::cast(layout_descriptor->elements())); |
| 112 Handle<FixedTypedArrayBase> new_elements( |
| 113 FixedTypedArrayBase::cast(new_layout_descriptor->elements())); |
| 114 memcpy(new_elements->DataPtr(), elements->DataPtr(), elements->DataSize()); |
111 return new_layout_descriptor; | 115 return new_layout_descriptor; |
112 } else { | 116 } else { |
113 // Fast layout. | 117 // Fast layout. |
114 uint32_t value = | 118 uint32_t value = |
115 static_cast<uint32_t>(Smi::cast(*layout_descriptor)->value()); | 119 static_cast<uint32_t>(Smi::cast(*layout_descriptor)->value()); |
116 new_layout_descriptor->set(0, value); | 120 new_layout_descriptor->set(0, value); |
117 return new_layout_descriptor; | 121 return new_layout_descriptor; |
118 } | 122 } |
119 } | 123 } |
120 | 124 |
(...skipping 22 matching lines...) Expand all Loading... |
143 | 147 |
144 bool is_tagged = (value & layout_mask) == 0; | 148 bool is_tagged = (value & layout_mask) == 0; |
145 if (!is_tagged) value = ~value; // Count set bits instead of cleared bits. | 149 if (!is_tagged) value = ~value; // Count set bits instead of cleared bits. |
146 value = value & ~(layout_mask - 1); // Clear bits we are not interested in. | 150 value = value & ~(layout_mask - 1); // Clear bits we are not interested in. |
147 int sequence_length = CountTrailingZeros32(value) - layout_bit_index; | 151 int sequence_length = CountTrailingZeros32(value) - layout_bit_index; |
148 | 152 |
149 if (layout_bit_index + sequence_length == kNumberOfBits) { | 153 if (layout_bit_index + sequence_length == kNumberOfBits) { |
150 // This is a contiguous sequence till the end of current word, proceed | 154 // This is a contiguous sequence till the end of current word, proceed |
151 // counting in the subsequent words. | 155 // counting in the subsequent words. |
152 if (IsSlowLayout()) { | 156 if (IsSlowLayout()) { |
153 int len = length(); | 157 int len = Smi::cast(length())->value(); |
154 ++layout_word_index; | 158 ++layout_word_index; |
155 for (; layout_word_index < len; layout_word_index++) { | 159 for (; layout_word_index < len; layout_word_index++) { |
156 value = get_scalar(layout_word_index); | 160 value = get_scalar(layout_word_index); |
157 bool cur_is_tagged = (value & 1) == 0; | 161 bool cur_is_tagged = (value & 1) == 0; |
158 if (cur_is_tagged != is_tagged) break; | 162 if (cur_is_tagged != is_tagged) break; |
159 if (!is_tagged) value = ~value; // Count set bits instead. | 163 if (!is_tagged) value = ~value; // Count set bits instead. |
160 int cur_sequence_length = CountTrailingZeros32(value); | 164 int cur_sequence_length = CountTrailingZeros32(value); |
161 sequence_length += cur_sequence_length; | 165 sequence_length += cur_sequence_length; |
162 if (sequence_length >= max_sequence_length) break; | 166 if (sequence_length >= max_sequence_length) break; |
163 if (cur_sequence_length != kNumberOfBits) break; | 167 if (cur_sequence_length != kNumberOfBits) break; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 if (!IsSlowLayout()) return this; | 238 if (!IsSlowLayout()) return this; |
235 | 239 |
236 int layout_descriptor_length = | 240 int layout_descriptor_length = |
237 CalculateCapacity(map, descriptors, num_descriptors); | 241 CalculateCapacity(map, descriptors, num_descriptors); |
238 // It must not become fast-mode descriptor here, because otherwise it has to | 242 // It must not become fast-mode descriptor here, because otherwise it has to |
239 // be fast pointer layout descriptor already but it's is slow mode now. | 243 // be fast pointer layout descriptor already but it's is slow mode now. |
240 DCHECK_LT(kSmiValueSize, layout_descriptor_length); | 244 DCHECK_LT(kSmiValueSize, layout_descriptor_length); |
241 | 245 |
242 // Trim, clean and reinitialize this slow-mode layout descriptor. | 246 // Trim, clean and reinitialize this slow-mode layout descriptor. |
243 int array_length = GetSlowModeBackingStoreLength(layout_descriptor_length); | 247 int array_length = GetSlowModeBackingStoreLength(layout_descriptor_length); |
244 int current_length = length(); | 248 int current_length = Smi::cast(length())->value(); |
245 if (current_length != array_length) { | 249 if (current_length != array_length) { |
246 DCHECK_LT(array_length, current_length); | 250 DCHECK_LT(array_length, current_length); |
247 int delta = current_length - array_length; | 251 int delta = current_length - array_length; |
248 heap->RightTrimFixedArray<Heap::SEQUENTIAL_TO_SWEEPER>(this, delta); | 252 heap->RightTrimFixedArray<Heap::SEQUENTIAL_TO_SWEEPER>(elements(), delta); |
| 253 set_byte_length(Smi::FromInt(array_length * 4)); |
| 254 set_length(Smi::FromInt(array_length)); |
249 } | 255 } |
250 memset(DataPtr(), 0, DataSize()); | 256 { |
| 257 DisallowHeapAllocation no_gc; |
| 258 Handle<FixedTypedArrayBase> fixed_array( |
| 259 FixedTypedArrayBase::cast(elements())); |
| 260 memset(fixed_array->DataPtr(), 0, fixed_array->DataSize()); |
| 261 } |
251 LayoutDescriptor* layout_descriptor = | 262 LayoutDescriptor* layout_descriptor = |
252 Initialize(this, map, descriptors, num_descriptors); | 263 Initialize(this, map, descriptors, num_descriptors); |
253 DCHECK_EQ(this, layout_descriptor); | 264 DCHECK_EQ(this, layout_descriptor); |
254 return layout_descriptor; | 265 return layout_descriptor; |
255 } | 266 } |
256 | 267 |
257 | 268 |
258 bool LayoutDescriptor::IsConsistentWithMap(Map* map, bool check_tail) { | 269 bool LayoutDescriptor::IsConsistentWithMap(Map* map, bool check_tail) { |
259 if (FLAG_unbox_double_fields) { | 270 if (FLAG_unbox_double_fields) { |
260 DescriptorArray* descriptors = map->instance_descriptors(); | 271 DescriptorArray* descriptors = map->instance_descriptors(); |
(...skipping 18 matching lines...) Expand all Loading... |
279 int n = capacity(); | 290 int n = capacity(); |
280 for (int i = last_field_index; i < n; i++) { | 291 for (int i = last_field_index; i < n; i++) { |
281 DCHECK(IsTagged(i)); | 292 DCHECK(IsTagged(i)); |
282 } | 293 } |
283 } | 294 } |
284 } | 295 } |
285 return true; | 296 return true; |
286 } | 297 } |
287 } | 298 } |
288 } // namespace v8::internal | 299 } // namespace v8::internal |
OLD | NEW |