OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 | 51 |
52 namespace v8 { | 52 namespace v8 { |
53 namespace internal { | 53 namespace internal { |
54 | 54 |
55 PropertyDetails::PropertyDetails(Smi* smi) { | 55 PropertyDetails::PropertyDetails(Smi* smi) { |
56 value_ = smi->value(); | 56 value_ = smi->value(); |
57 } | 57 } |
58 | 58 |
59 | 59 |
60 Smi* PropertyDetails::AsSmi() { | 60 Smi* PropertyDetails::AsSmi() { |
61 // Ensure the upper 2 bits have the same value by sign extending it. This is | 61 return Smi::FromInt(value_); |
62 // necessary to be able to use the 31st bit of the property details. | |
63 int value = value_ << 1; | |
64 return Smi::FromInt(value >> 1); | |
65 } | 62 } |
66 | 63 |
67 | 64 |
68 PropertyDetails PropertyDetails::AsDeleted() { | 65 PropertyDetails PropertyDetails::AsDeleted() { |
69 Smi* smi = Smi::FromInt(value_ | DeletedField::encode(1)); | 66 Smi* smi = Smi::FromInt(value_ | DeletedField::encode(1)); |
70 return PropertyDetails(smi); | 67 return PropertyDetails(smi); |
71 } | 68 } |
72 | 69 |
73 | 70 |
74 #define TYPE_CHECKER(type, instancetype) \ | 71 #define TYPE_CHECKER(type, instancetype) \ |
(...skipping 2265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2340 GetValue(descriptor_number), | 2337 GetValue(descriptor_number), |
2341 GetDetails(descriptor_number)); | 2338 GetDetails(descriptor_number)); |
2342 } | 2339 } |
2343 | 2340 |
2344 | 2341 |
2345 void DescriptorArray::Set(int descriptor_number, | 2342 void DescriptorArray::Set(int descriptor_number, |
2346 Descriptor* desc, | 2343 Descriptor* desc, |
2347 const WhitenessWitness&) { | 2344 const WhitenessWitness&) { |
2348 // Range check. | 2345 // Range check. |
2349 ASSERT(descriptor_number < number_of_descriptors()); | 2346 ASSERT(descriptor_number < number_of_descriptors()); |
2350 ASSERT(desc->GetDetails().descriptor_index() <= | |
2351 number_of_descriptors()); | |
2352 ASSERT(desc->GetDetails().descriptor_index() > 0); | |
2353 | 2347 |
2354 ASSERT(!desc->GetDetails().representation().IsNone()); | 2348 ASSERT(!desc->GetDetails().representation().IsNone()); |
2355 NoIncrementalWriteBarrierSet(this, | 2349 NoIncrementalWriteBarrierSet(this, |
2356 ToKeyIndex(descriptor_number), | 2350 ToKeyIndex(descriptor_number), |
2357 desc->GetKey()); | 2351 desc->GetKey()); |
2358 NoIncrementalWriteBarrierSet(this, | 2352 NoIncrementalWriteBarrierSet(this, |
2359 ToValueIndex(descriptor_number), | 2353 ToValueIndex(descriptor_number), |
2360 desc->GetValue()); | 2354 desc->GetValue()); |
2361 NoIncrementalWriteBarrierSet(this, | 2355 NoIncrementalWriteBarrierSet(this, |
2362 ToDetailsIndex(descriptor_number), | 2356 ToDetailsIndex(descriptor_number), |
2363 desc->GetDetails().AsSmi()); | 2357 desc->GetDetails().AsSmi()); |
2364 } | 2358 } |
2365 | 2359 |
2366 | 2360 |
2367 void DescriptorArray::Set(int descriptor_number, Descriptor* desc) { | 2361 void DescriptorArray::Set(int descriptor_number, Descriptor* desc) { |
2368 // Range check. | 2362 // Range check. |
2369 ASSERT(descriptor_number < number_of_descriptors()); | 2363 ASSERT(descriptor_number < number_of_descriptors()); |
2370 ASSERT(desc->GetDetails().descriptor_index() <= | |
2371 number_of_descriptors()); | |
2372 ASSERT(desc->GetDetails().descriptor_index() > 0); | |
2373 ASSERT(!desc->GetDetails().representation().IsNone()); | 2364 ASSERT(!desc->GetDetails().representation().IsNone()); |
2374 | 2365 |
2375 set(ToKeyIndex(descriptor_number), desc->GetKey()); | 2366 set(ToKeyIndex(descriptor_number), desc->GetKey()); |
2376 set(ToValueIndex(descriptor_number), desc->GetValue()); | 2367 set(ToValueIndex(descriptor_number), desc->GetValue()); |
2377 set(ToDetailsIndex(descriptor_number), desc->GetDetails().AsSmi()); | 2368 set(ToDetailsIndex(descriptor_number), desc->GetDetails().AsSmi()); |
2378 } | 2369 } |
2379 | 2370 |
2380 | 2371 |
2381 void DescriptorArray::Append(Descriptor* desc, | 2372 void DescriptorArray::Append(Descriptor* desc, |
2382 const WhitenessWitness& witness) { | 2373 const WhitenessWitness& witness) { |
2383 int descriptor_number = number_of_descriptors(); | 2374 int descriptor_number = number_of_descriptors(); |
2384 int enumeration_index = descriptor_number + 1; | |
2385 SetNumberOfDescriptors(descriptor_number + 1); | 2375 SetNumberOfDescriptors(descriptor_number + 1); |
2386 desc->SetEnumerationIndex(enumeration_index); | |
2387 Set(descriptor_number, desc, witness); | 2376 Set(descriptor_number, desc, witness); |
2388 | 2377 |
2389 uint32_t hash = desc->GetKey()->Hash(); | 2378 uint32_t hash = desc->GetKey()->Hash(); |
2390 | 2379 |
2391 int insertion; | 2380 int insertion; |
2392 | 2381 |
2393 for (insertion = descriptor_number; insertion > 0; --insertion) { | 2382 for (insertion = descriptor_number; insertion > 0; --insertion) { |
2394 Name* key = GetSortedKey(insertion - 1); | 2383 Name* key = GetSortedKey(insertion - 1); |
2395 if (key->Hash() <= hash) break; | 2384 if (key->Hash() <= hash) break; |
2396 SetSortedKey(insertion, GetSortedKeyIndex(insertion - 1)); | 2385 SetSortedKey(insertion, GetSortedKeyIndex(insertion - 1)); |
2397 } | 2386 } |
2398 | 2387 |
2399 SetSortedKey(insertion, descriptor_number); | 2388 SetSortedKey(insertion, descriptor_number); |
2400 } | 2389 } |
2401 | 2390 |
2402 | 2391 |
2403 void DescriptorArray::Append(Descriptor* desc) { | 2392 void DescriptorArray::Append(Descriptor* desc) { |
2404 int descriptor_number = number_of_descriptors(); | 2393 int descriptor_number = number_of_descriptors(); |
2405 int enumeration_index = descriptor_number + 1; | |
2406 SetNumberOfDescriptors(descriptor_number + 1); | 2394 SetNumberOfDescriptors(descriptor_number + 1); |
2407 desc->SetEnumerationIndex(enumeration_index); | |
2408 Set(descriptor_number, desc); | 2395 Set(descriptor_number, desc); |
2409 | 2396 |
2410 uint32_t hash = desc->GetKey()->Hash(); | 2397 uint32_t hash = desc->GetKey()->Hash(); |
2411 | 2398 |
2412 int insertion; | 2399 int insertion; |
2413 | 2400 |
2414 for (insertion = descriptor_number; insertion > 0; --insertion) { | 2401 for (insertion = descriptor_number; insertion > 0; --insertion) { |
2415 Name* key = GetSortedKey(insertion - 1); | 2402 Name* key = GetSortedKey(insertion - 1); |
2416 if (key->Hash() <= hash) break; | 2403 if (key->Hash() <= hash) break; |
2417 SetSortedKey(insertion, GetSortedKeyIndex(insertion - 1)); | 2404 SetSortedKey(insertion, GetSortedKeyIndex(insertion - 1)); |
(...skipping 1727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4145 } else { | 4132 } else { |
4146 return map; | 4133 return map; |
4147 } | 4134 } |
4148 map->set_transitions(transitions); | 4135 map->set_transitions(transitions); |
4149 return transitions; | 4136 return transitions; |
4150 } | 4137 } |
4151 | 4138 |
4152 | 4139 |
4153 void Map::InitializeDescriptors(DescriptorArray* descriptors) { | 4140 void Map::InitializeDescriptors(DescriptorArray* descriptors) { |
4154 int len = descriptors->number_of_descriptors(); | 4141 int len = descriptors->number_of_descriptors(); |
4155 #ifdef DEBUG | |
4156 ASSERT(len <= DescriptorArray::kMaxNumberOfDescriptors); | |
4157 | |
4158 bool used_indices[DescriptorArray::kMaxNumberOfDescriptors]; | |
4159 for (int i = 0; i < len; ++i) used_indices[i] = false; | |
4160 | |
4161 // Ensure that all enumeration indexes between 1 and length occur uniquely in | |
4162 // the descriptor array. | |
4163 for (int i = 0; i < len; ++i) { | |
4164 int enum_index = descriptors->GetDetails(i).descriptor_index() - | |
4165 PropertyDetails::kInitialIndex; | |
4166 ASSERT(0 <= enum_index && enum_index < len); | |
4167 ASSERT(!used_indices[enum_index]); | |
4168 used_indices[enum_index] = true; | |
4169 } | |
4170 #endif | |
4171 | |
4172 set_instance_descriptors(descriptors); | 4142 set_instance_descriptors(descriptors); |
4173 SetNumberOfOwnDescriptors(len); | 4143 SetNumberOfOwnDescriptors(len); |
4174 } | 4144 } |
4175 | 4145 |
4176 | 4146 |
4177 ACCESSORS(Map, instance_descriptors, DescriptorArray, kDescriptorsOffset) | 4147 ACCESSORS(Map, instance_descriptors, DescriptorArray, kDescriptorsOffset) |
4178 SMI_ACCESSORS(Map, bit_field3, kBitField3Offset) | 4148 SMI_ACCESSORS(Map, bit_field3, kBitField3Offset) |
4179 | 4149 |
4180 | 4150 |
4181 void Map::ClearTransitions(Heap* heap, WriteBarrierMode mode) { | 4151 void Map::ClearTransitions(Heap* heap, WriteBarrierMode mode) { |
(...skipping 2045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6227 #undef WRITE_UINT32_FIELD | 6197 #undef WRITE_UINT32_FIELD |
6228 #undef READ_SHORT_FIELD | 6198 #undef READ_SHORT_FIELD |
6229 #undef WRITE_SHORT_FIELD | 6199 #undef WRITE_SHORT_FIELD |
6230 #undef READ_BYTE_FIELD | 6200 #undef READ_BYTE_FIELD |
6231 #undef WRITE_BYTE_FIELD | 6201 #undef WRITE_BYTE_FIELD |
6232 | 6202 |
6233 | 6203 |
6234 } } // namespace v8::internal | 6204 } } // namespace v8::internal |
6235 | 6205 |
6236 #endif // V8_OBJECTS_INL_H_ | 6206 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |