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