OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 5162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5173 Handle<ObjectHashTable> JSObject::GetOrCreateHiddenPropertiesHashtable( | 5173 Handle<ObjectHashTable> JSObject::GetOrCreateHiddenPropertiesHashtable( |
5174 Handle<JSObject> object) { | 5174 Handle<JSObject> object) { |
5175 Isolate* isolate = object->GetIsolate(); | 5175 Isolate* isolate = object->GetIsolate(); |
5176 | 5176 |
5177 static const int kInitialCapacity = 4; | 5177 static const int kInitialCapacity = 4; |
5178 Handle<Object> inline_value(object->GetHiddenPropertiesHashTable(), isolate); | 5178 Handle<Object> inline_value(object->GetHiddenPropertiesHashTable(), isolate); |
5179 if (inline_value->IsHashTable()) { | 5179 if (inline_value->IsHashTable()) { |
5180 return Handle<ObjectHashTable>::cast(inline_value); | 5180 return Handle<ObjectHashTable>::cast(inline_value); |
5181 } | 5181 } |
5182 | 5182 |
5183 Handle<ObjectHashTable> hashtable = isolate->factory()->NewObjectHashTable( | 5183 Handle<ObjectHashTable> hashtable = ObjectHashTable::New( |
5184 kInitialCapacity, | 5184 isolate, kInitialCapacity, USE_CUSTOM_MINIMUM_CAPACITY); |
5185 USE_CUSTOM_MINIMUM_CAPACITY); | |
5186 | 5185 |
5187 if (inline_value->IsSmi()) { | 5186 if (inline_value->IsSmi()) { |
5188 // We were storing the identity hash inline and now allocated an actual | 5187 // We were storing the identity hash inline and now allocated an actual |
5189 // dictionary. Put the identity hash into the new dictionary. | 5188 // dictionary. Put the identity hash into the new dictionary. |
5190 hashtable = ObjectHashTable::Put(hashtable, | 5189 hashtable = ObjectHashTable::Put(hashtable, |
5191 isolate->factory()->identity_hash_string(), | 5190 isolate->factory()->identity_hash_string(), |
5192 inline_value); | 5191 inline_value); |
5193 } | 5192 } |
5194 | 5193 |
5195 JSObject::SetLocalPropertyIgnoreAttributes( | 5194 JSObject::SetLocalPropertyIgnoreAttributes( |
(...skipping 9386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14582 | 14581 |
14583 template<typename Derived, typename Shape, typename Key> | 14582 template<typename Derived, typename Shape, typename Key> |
14584 void HashTable<Derived, Shape, Key>::IterateElements(ObjectVisitor* v) { | 14583 void HashTable<Derived, Shape, Key>::IterateElements(ObjectVisitor* v) { |
14585 IteratePointers(v, | 14584 IteratePointers(v, |
14586 kElementsStartOffset, | 14585 kElementsStartOffset, |
14587 kHeaderSize + length() * kPointerSize); | 14586 kHeaderSize + length() * kPointerSize); |
14588 } | 14587 } |
14589 | 14588 |
14590 | 14589 |
14591 template<typename Derived, typename Shape, typename Key> | 14590 template<typename Derived, typename Shape, typename Key> |
14592 MaybeObject* HashTable<Derived, Shape, Key>::Allocate( | 14591 Handle<Derived> HashTable<Derived, Shape, Key>::New( |
14593 Heap* heap, | 14592 Isolate* isolate, |
14594 int at_least_space_for, | 14593 int at_least_space_for, |
14595 MinimumCapacity capacity_option, | 14594 MinimumCapacity capacity_option, |
14596 PretenureFlag pretenure) { | 14595 PretenureFlag pretenure) { |
| 14596 ASSERT(0 <= at_least_space_for); |
14597 ASSERT(!capacity_option || IsPowerOf2(at_least_space_for)); | 14597 ASSERT(!capacity_option || IsPowerOf2(at_least_space_for)); |
14598 int capacity = (capacity_option == USE_CUSTOM_MINIMUM_CAPACITY) | 14598 int capacity = (capacity_option == USE_CUSTOM_MINIMUM_CAPACITY) |
14599 ? at_least_space_for | 14599 ? at_least_space_for |
14600 : ComputeCapacity(at_least_space_for); | 14600 : ComputeCapacity(at_least_space_for); |
14601 if (capacity > HashTable::kMaxCapacity) { | 14601 if (capacity > HashTable::kMaxCapacity) { |
14602 v8::internal::Heap::FatalProcessOutOfMemory("invalid table size", true); | 14602 v8::internal::Heap::FatalProcessOutOfMemory("invalid table size", true); |
14603 } | 14603 } |
14604 | 14604 |
14605 Object* obj; | 14605 Factory* factory = isolate->factory(); |
14606 { MaybeObject* maybe_obj = | 14606 int length = EntryToIndex(capacity); |
14607 heap-> AllocateHashTable(EntryToIndex(capacity), pretenure); | 14607 Handle<FixedArray> array = factory->NewFixedArray(length, pretenure); |
14608 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 14608 array->set_map_no_write_barrier(*factory->hash_table_map()); |
14609 } | 14609 Handle<Derived> table = Handle<Derived>::cast(array); |
14610 HashTable::cast(obj)->SetNumberOfElements(0); | 14610 |
14611 HashTable::cast(obj)->SetNumberOfDeletedElements(0); | 14611 table->SetNumberOfElements(0); |
14612 HashTable::cast(obj)->SetCapacity(capacity); | 14612 table->SetNumberOfDeletedElements(0); |
14613 return obj; | 14613 table->SetCapacity(capacity); |
| 14614 return table; |
14614 } | 14615 } |
14615 | 14616 |
14616 | 14617 |
14617 template<typename Derived, typename Shape, typename Key> | |
14618 Handle<Derived> HashTable<Derived, Shape, Key>::New( | |
14619 Isolate* isolate, | |
14620 int at_least_space_for, | |
14621 MinimumCapacity capacity_option, | |
14622 PretenureFlag pretenure) { | |
14623 CALL_HEAP_FUNCTION( | |
14624 isolate, | |
14625 Allocate(isolate->heap(), at_least_space_for, capacity_option, pretenure), | |
14626 Derived); | |
14627 } | |
14628 | |
14629 | |
14630 // TODO(ishell): Remove this when all the callers are handlified. | 14618 // TODO(ishell): Remove this when all the callers are handlified. |
14631 int NameDictionary::FindEntry(Name* key) { | 14619 int NameDictionary::FindEntry(Name* key) { |
14632 DisallowHeapAllocation no_allocation; | 14620 DisallowHeapAllocation no_allocation; |
14633 Isolate* isolate = key->GetIsolate(); | 14621 Isolate* isolate = key->GetIsolate(); |
14634 HandleScope scope(isolate); | 14622 HandleScope scope(isolate); |
14635 return FindEntry(handle(key, isolate)); | 14623 return FindEntry(handle(key, isolate)); |
14636 } | 14624 } |
14637 | 14625 |
14638 | 14626 |
14639 // Find entry for key otherwise return kNotFound. | 14627 // Find entry for key otherwise return kNotFound. |
(...skipping 2702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17342 #define ERROR_MESSAGES_TEXTS(C, T) T, | 17330 #define ERROR_MESSAGES_TEXTS(C, T) T, |
17343 static const char* error_messages_[] = { | 17331 static const char* error_messages_[] = { |
17344 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 17332 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
17345 }; | 17333 }; |
17346 #undef ERROR_MESSAGES_TEXTS | 17334 #undef ERROR_MESSAGES_TEXTS |
17347 return error_messages_[reason]; | 17335 return error_messages_[reason]; |
17348 } | 17336 } |
17349 | 17337 |
17350 | 17338 |
17351 } } // namespace v8::internal | 17339 } } // namespace v8::internal |
OLD | NEW |