OLD | NEW |
---|---|
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 3905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3916 return SetInstancePrototype(construct_prototype); | 3916 return SetInstancePrototype(construct_prototype); |
3917 } | 3917 } |
3918 | 3918 |
3919 | 3919 |
3920 Object* JSFunction::SetInstanceClassName(String* name) { | 3920 Object* JSFunction::SetInstanceClassName(String* name) { |
3921 shared()->set_instance_class_name(name); | 3921 shared()->set_instance_class_name(name); |
3922 return this; | 3922 return this; |
3923 } | 3923 } |
3924 | 3924 |
3925 | 3925 |
3926 Context* JSFunction::GlobalContextFromLiterals(FixedArray* literals) { | |
3927 return Context::cast(literals->get(JSFunction::kLiteralGlobalContextIndex)); | |
3928 } | |
3929 | |
3930 | |
3926 void Oddball::OddballIterateBody(ObjectVisitor* v) { | 3931 void Oddball::OddballIterateBody(ObjectVisitor* v) { |
3927 // Assumes all Object* members are contiguously allocated! | 3932 // Assumes all Object* members are contiguously allocated! |
3928 IteratePointers(v, kToStringOffset, kToNumberOffset + kPointerSize); | 3933 IteratePointers(v, kToStringOffset, kToNumberOffset + kPointerSize); |
3929 } | 3934 } |
3930 | 3935 |
3931 | 3936 |
3932 Object* Oddball::Initialize(const char* to_string, Object* to_number) { | 3937 Object* Oddball::Initialize(const char* to_string, Object* to_number) { |
3933 Object* symbol = Heap::LookupAsciiSymbol(to_string); | 3938 Object* symbol = Heap::LookupAsciiSymbol(to_string); |
3934 if (symbol->IsFailure()) return symbol; | 3939 if (symbol->IsFailure()) return symbol; |
3935 set_to_string(String::cast(symbol)); | 3940 set_to_string(String::cast(symbol)); |
(...skipping 1590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5526 template<int prefix_size, int element_size> | 5531 template<int prefix_size, int element_size> |
5527 Object* HashTable<prefix_size, element_size>::EnsureCapacity( | 5532 Object* HashTable<prefix_size, element_size>::EnsureCapacity( |
5528 int n, HashTableKey* key) { | 5533 int n, HashTableKey* key) { |
5529 int capacity = Capacity(); | 5534 int capacity = Capacity(); |
5530 int nof = NumberOfElements() + n; | 5535 int nof = NumberOfElements() + n; |
5531 // Make sure 20% is free | 5536 // Make sure 20% is free |
5532 if (nof + (nof >> 2) <= capacity) return this; | 5537 if (nof + (nof >> 2) <= capacity) return this; |
5533 | 5538 |
5534 Object* obj = Allocate(nof * 2); | 5539 Object* obj = Allocate(nof * 2); |
5535 if (obj->IsFailure()) return obj; | 5540 if (obj->IsFailure()) return obj; |
5536 HashTable* dict = HashTable::cast(obj); | 5541 HashTable* table = HashTable::cast(obj); |
5537 WriteBarrierMode mode = dict->GetWriteBarrierMode(); | 5542 WriteBarrierMode mode = table->GetWriteBarrierMode(); |
5538 | 5543 |
5539 // Copy prefix to new array. | 5544 // Copy prefix to new array. |
5540 for (int i = kPrefixStartIndex; i < kPrefixStartIndex + prefix_size; i++) { | 5545 for (int i = kPrefixStartIndex; i < kPrefixStartIndex + prefix_size; i++) { |
5541 dict->set(i, get(i), mode); | 5546 table->set(i, get(i), mode); |
5542 } | 5547 } |
5543 // Rehash the elements. | 5548 // Rehash the elements. |
5544 uint32_t (*Hash)(Object* key) = key->GetHashFunction(); | 5549 uint32_t (*Hash)(Object* key) = key->GetHashFunction(); |
5545 for (int i = 0; i < capacity; i++) { | 5550 for (int i = 0; i < capacity; i++) { |
5546 uint32_t from_index = EntryToIndex(i); | 5551 uint32_t from_index = EntryToIndex(i); |
5547 Object* key = get(from_index); | 5552 Object* key = get(from_index); |
5548 if (IsKey(key)) { | 5553 if (IsKey(key)) { |
5549 uint32_t insertion_index = | 5554 uint32_t insertion_index = |
5550 EntryToIndex(dict->FindInsertionEntry(key, Hash(key))); | 5555 EntryToIndex(table->FindInsertionEntry(key, Hash(key))); |
5551 for (int j = 0; j < element_size; j++) { | 5556 for (int j = 0; j < element_size; j++) { |
5552 dict->set(insertion_index + j, get(from_index + j), mode); | 5557 table->set(insertion_index + j, get(from_index + j), mode); |
5553 } | 5558 } |
5554 } | 5559 } |
5555 } | 5560 } |
5556 dict->SetNumberOfElements(NumberOfElements()); | 5561 table->SetNumberOfElements(NumberOfElements()); |
5557 return dict; | 5562 return table; |
5558 } | 5563 } |
5559 | 5564 |
5560 | 5565 |
5561 template<int prefix_size, int element_size> | 5566 template<int prefix_size, int element_size> |
5562 uint32_t HashTable<prefix_size, element_size>::FindInsertionEntry( | 5567 uint32_t HashTable<prefix_size, element_size>::FindInsertionEntry( |
5563 Object* key, | 5568 Object* key, |
5564 uint32_t hash) { | 5569 uint32_t hash) { |
5565 uint32_t capacity = Capacity(); | 5570 uint32_t capacity = Capacity(); |
5566 uint32_t entry = GetProbe(hash, 0, capacity); | 5571 uint32_t entry = GetProbe(hash, 0, capacity); |
5567 Object* element = KeyAt(entry); | 5572 Object* element = KeyAt(entry); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5649 CompilationCacheTable* cache = | 5654 CompilationCacheTable* cache = |
5650 reinterpret_cast<CompilationCacheTable*>(obj); | 5655 reinterpret_cast<CompilationCacheTable*>(obj); |
5651 int entry = cache->FindInsertionEntry(src, key.Hash()); | 5656 int entry = cache->FindInsertionEntry(src, key.Hash()); |
5652 cache->set(EntryToIndex(entry), src); | 5657 cache->set(EntryToIndex(entry), src); |
5653 cache->set(EntryToIndex(entry) + 1, value); | 5658 cache->set(EntryToIndex(entry) + 1, value); |
5654 cache->ElementAdded(); | 5659 cache->ElementAdded(); |
5655 return cache; | 5660 return cache; |
5656 } | 5661 } |
5657 | 5662 |
5658 | 5663 |
5664 // SymbolsKey used for HashTable were key is array of symbols. | |
Mads Ager (chromium)
2008/09/25 07:23:19
were -> where
| |
5665 class SymbolsKey : public HashTableKey { | |
5666 public: | |
5667 explicit SymbolsKey(FixedArray* symbols) { | |
5668 symbols_ = symbols; | |
5669 } | |
5670 | |
5671 bool IsMatch(Object* other) { | |
5672 if (!other->IsFixedArray()) return false; | |
5673 FixedArray* o = FixedArray::cast(other); | |
5674 int len = symbols_->length(); | |
5675 if (o->length() != len) return false; | |
5676 for (int i = 0; i < len; i++) { | |
5677 if (o->get(i) != symbols_->get(i)) return false; | |
5678 } | |
5679 return true; | |
5680 } | |
5681 | |
5682 uint32_t Hash() { return SymbolsHash(symbols_); } | |
5683 | |
5684 HashFunction GetHashFunction() { return SymbolsHash; } | |
5685 | |
5686 Object* GetObject() { return symbols_; } | |
5687 | |
5688 static uint32_t SymbolsHash(Object* obj) { | |
5689 FixedArray* symbols_ = FixedArray::cast(obj); | |
5690 int len = symbols_->length(); | |
5691 uint32_t hash = 0; | |
5692 for (int i = 0; i < len; i++) { | |
5693 hash ^= String::cast(symbols_->get(i))->Hash(); | |
5694 } | |
5695 return hash; | |
5696 } | |
5697 | |
5698 bool IsStringKey() { return false; } | |
5699 | |
5700 FixedArray* symbols_; | |
5701 }; | |
5702 | |
5703 Object* MapCache::Lookup(FixedArray* array) { | |
5704 SymbolsKey key(array); | |
5705 int entry = FindEntry(&key); | |
5706 if (entry != -1) { | |
5707 return get(EntryToIndex(entry) + 1); | |
5708 } else { | |
5709 return Heap::undefined_value(); | |
5710 } | |
5711 } | |
5712 | |
5713 | |
5714 Object* MapCache::Put(FixedArray* array, Map* value) { | |
5715 SymbolsKey key(array); | |
5716 Object* obj = EnsureCapacity(1, &key); | |
5717 if (obj->IsFailure()) return obj; | |
5718 | |
5719 MapCache* cache = reinterpret_cast<MapCache*>(obj); | |
5720 int entry = cache->FindInsertionEntry(array, key.Hash()); | |
5721 cache->set(EntryToIndex(entry), array); | |
5722 cache->set(EntryToIndex(entry) + 1, value); | |
5723 cache->ElementAdded(); | |
5724 return cache; | |
5725 } | |
5726 | |
5727 | |
5659 Object* Dictionary::Allocate(int at_least_space_for) { | 5728 Object* Dictionary::Allocate(int at_least_space_for) { |
5660 Object* obj = DictionaryBase::Allocate(at_least_space_for); | 5729 Object* obj = DictionaryBase::Allocate(at_least_space_for); |
5661 // Initialize the next enumeration index. | 5730 // Initialize the next enumeration index. |
5662 if (!obj->IsFailure()) { | 5731 if (!obj->IsFailure()) { |
5663 Dictionary::cast(obj)-> | 5732 Dictionary::cast(obj)-> |
5664 SetNextEnumerationIndex(PropertyDetails::kInitialIndex); | 5733 SetNextEnumerationIndex(PropertyDetails::kInitialIndex); |
5665 } | 5734 } |
5666 return obj; | 5735 return obj; |
5667 } | 5736 } |
5668 | 5737 |
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6315 // No break point. | 6384 // No break point. |
6316 if (break_point_objects()->IsUndefined()) return 0; | 6385 if (break_point_objects()->IsUndefined()) return 0; |
6317 // Single beak point. | 6386 // Single beak point. |
6318 if (!break_point_objects()->IsFixedArray()) return 1; | 6387 if (!break_point_objects()->IsFixedArray()) return 1; |
6319 // Multiple break points. | 6388 // Multiple break points. |
6320 return FixedArray::cast(break_point_objects())->length(); | 6389 return FixedArray::cast(break_point_objects())->length(); |
6321 } | 6390 } |
6322 | 6391 |
6323 | 6392 |
6324 } } // namespace v8::internal | 6393 } } // namespace v8::internal |
OLD | NEW |