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 14518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14529 } | 14529 } |
14530 | 14530 |
14531 | 14531 |
14532 template class SubStringKey<uint8_t>; | 14532 template class SubStringKey<uint8_t>; |
14533 template class SubStringKey<uint16_t>; | 14533 template class SubStringKey<uint16_t>; |
14534 | 14534 |
14535 | 14535 |
14536 // InternalizedStringKey carries a string/internalized-string object as key. | 14536 // InternalizedStringKey carries a string/internalized-string object as key. |
14537 class InternalizedStringKey : public HashTableKey { | 14537 class InternalizedStringKey : public HashTableKey { |
14538 public: | 14538 public: |
14539 explicit InternalizedStringKey(String* string) | 14539 explicit InternalizedStringKey(Handle<String> string) |
14540 : string_(string) { } | 14540 : string_(string) { } |
14541 | 14541 |
14542 bool IsMatch(Object* string) { | 14542 virtual bool IsMatch(Object* string) V8_OVERRIDE { |
14543 return String::cast(string)->Equals(string_); | 14543 return String::cast(string)->Equals(*string_); |
14544 } | 14544 } |
14545 | 14545 |
14546 uint32_t Hash() { return string_->Hash(); } | 14546 virtual uint32_t Hash() V8_OVERRIDE { return string_->Hash(); } |
14547 | 14547 |
14548 uint32_t HashForObject(Object* other) { | 14548 virtual uint32_t HashForObject(Object* other) V8_OVERRIDE { |
14549 return String::cast(other)->Hash(); | 14549 return String::cast(other)->Hash(); |
14550 } | 14550 } |
14551 | 14551 |
14552 MaybeObject* AsObject(Heap* heap) { | 14552 virtual MaybeObject* AsObject(Heap* heap) V8_OVERRIDE { |
14553 // Internalize the string if possible. | 14553 // Internalize the string if possible. |
14554 Map* map = heap->InternalizedStringMapForString(string_); | 14554 Map* map = heap->InternalizedStringMapForString(*string_); |
14555 if (map != NULL) { | 14555 if (map != NULL) { |
14556 string_->set_map_no_write_barrier(map); | 14556 string_->set_map_no_write_barrier(map); |
14557 ASSERT(string_->IsInternalizedString()); | 14557 ASSERT(string_->IsInternalizedString()); |
14558 return string_; | 14558 return *string_; |
14559 } | 14559 } |
14560 // Otherwise allocate a new internalized string. | 14560 // Otherwise allocate a new internalized string. |
14561 return heap->AllocateInternalizedStringImpl( | 14561 return heap->AllocateInternalizedStringImpl( |
14562 string_, string_->length(), string_->hash_field()); | 14562 *string_, string_->length(), string_->hash_field()); |
14563 } | 14563 } |
14564 | 14564 |
14565 static uint32_t StringHash(Object* obj) { | 14565 static uint32_t StringHash(Object* obj) { |
14566 return String::cast(obj)->Hash(); | 14566 return String::cast(obj)->Hash(); |
14567 } | 14567 } |
14568 | 14568 |
14569 String* string_; | 14569 Handle<String> string_; |
14570 }; | 14570 }; |
14571 | 14571 |
14572 | 14572 |
14573 template<typename Derived, typename Shape, typename Key> | 14573 template<typename Derived, typename Shape, typename Key> |
14574 void HashTable<Derived, Shape, Key>::IteratePrefix(ObjectVisitor* v) { | 14574 void HashTable<Derived, Shape, Key>::IteratePrefix(ObjectVisitor* v) { |
14575 IteratePointers(v, 0, kElementsStartOffset); | 14575 IteratePointers(v, 0, kElementsStartOffset); |
14576 } | 14576 } |
14577 | 14577 |
14578 | 14578 |
14579 template<typename Derived, typename Shape, typename Key> | 14579 template<typename Derived, typename Shape, typename Key> |
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15485 global->set_properties(*dictionary); | 15485 global->set_properties(*dictionary); |
15486 return cell; | 15486 return cell; |
15487 } else { | 15487 } else { |
15488 Object* value = global->property_dictionary()->ValueAt(entry); | 15488 Object* value = global->property_dictionary()->ValueAt(entry); |
15489 ASSERT(value->IsPropertyCell()); | 15489 ASSERT(value->IsPropertyCell()); |
15490 return handle(PropertyCell::cast(value)); | 15490 return handle(PropertyCell::cast(value)); |
15491 } | 15491 } |
15492 } | 15492 } |
15493 | 15493 |
15494 | 15494 |
15495 MaybeObject* StringTable::LookupString(String* string, Object** s) { | |
15496 InternalizedStringKey key(string); | |
15497 return LookupKey(&key, s); | |
15498 } | |
15499 | |
15500 | |
15501 // This class is used for looking up two character strings in the string table. | 15495 // This class is used for looking up two character strings in the string table. |
15502 // If we don't have a hit we don't want to waste much time so we unroll the | 15496 // If we don't have a hit we don't want to waste much time so we unroll the |
15503 // string hash calculation loop here for speed. Doesn't work if the two | 15497 // string hash calculation loop here for speed. Doesn't work if the two |
15504 // characters form a decimal integer, since such strings have a different hash | 15498 // characters form a decimal integer, since such strings have a different hash |
15505 // algorithm. | 15499 // algorithm. |
15506 class TwoCharHashTableKey : public HashTableKey { | 15500 class TwoCharHashTableKey : public HashTableKey { |
15507 public: | 15501 public: |
15508 TwoCharHashTableKey(uint16_t c1, uint16_t c2, uint32_t seed) | 15502 TwoCharHashTableKey(uint16_t c1, uint16_t c2, uint32_t seed) |
15509 : c1_(c1), c2_(c2) { | 15503 : c1_(c1), c2_(c2) { |
15510 // Char 1. | 15504 // Char 1. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15557 | 15551 |
15558 private: | 15552 private: |
15559 uint16_t c1_; | 15553 uint16_t c1_; |
15560 uint16_t c2_; | 15554 uint16_t c2_; |
15561 uint32_t hash_; | 15555 uint32_t hash_; |
15562 }; | 15556 }; |
15563 | 15557 |
15564 | 15558 |
15565 bool StringTable::LookupStringIfExists(String* string, String** result) { | 15559 bool StringTable::LookupStringIfExists(String* string, String** result) { |
15566 SLOW_ASSERT(this == HeapObject::cast(this)->GetHeap()->string_table()); | 15560 SLOW_ASSERT(this == HeapObject::cast(this)->GetHeap()->string_table()); |
15567 InternalizedStringKey key(string); | 15561 DisallowHeapAllocation no_alloc; |
| 15562 // TODO(ishell): Handlify all the callers and remove this scope. |
| 15563 HandleScope scope(GetIsolate()); |
| 15564 InternalizedStringKey key(handle(string)); |
15568 int entry = FindEntry(&key); | 15565 int entry = FindEntry(&key); |
15569 if (entry == kNotFound) { | 15566 if (entry == kNotFound) { |
15570 return false; | 15567 return false; |
15571 } else { | 15568 } else { |
15572 *result = String::cast(KeyAt(entry)); | 15569 *result = String::cast(KeyAt(entry)); |
15573 ASSERT(StringShape(*result).IsInternalized()); | 15570 ASSERT(StringShape(*result).IsInternalized()); |
15574 return true; | 15571 return true; |
15575 } | 15572 } |
15576 } | 15573 } |
15577 | 15574 |
15578 | 15575 |
15579 bool StringTable::LookupTwoCharsStringIfExists(uint16_t c1, | 15576 bool StringTable::LookupTwoCharsStringIfExists(uint16_t c1, |
15580 uint16_t c2, | 15577 uint16_t c2, |
15581 String** result) { | 15578 String** result) { |
15582 SLOW_ASSERT(this == HeapObject::cast(this)->GetHeap()->string_table()); | 15579 SLOW_ASSERT(this == HeapObject::cast(this)->GetHeap()->string_table()); |
15583 TwoCharHashTableKey key(c1, c2, GetHeap()->HashSeed()); | 15580 TwoCharHashTableKey key(c1, c2, GetHeap()->HashSeed()); |
15584 int entry = FindEntry(&key); | 15581 int entry = FindEntry(&key); |
15585 if (entry == kNotFound) { | 15582 if (entry == kNotFound) { |
15586 return false; | 15583 return false; |
15587 } else { | 15584 } else { |
15588 *result = String::cast(KeyAt(entry)); | 15585 *result = String::cast(KeyAt(entry)); |
15589 ASSERT(StringShape(*result).IsInternalized()); | 15586 ASSERT(StringShape(*result).IsInternalized()); |
15590 return true; | 15587 return true; |
15591 } | 15588 } |
15592 } | 15589 } |
15593 | 15590 |
15594 | 15591 |
15595 MaybeObject* StringTable::LookupKey(HashTableKey* key, Object** s) { | 15592 Handle<String> StringTable::LookupString(Isolate* isolate, |
15596 SLOW_ASSERT(this == HeapObject::cast(this)->GetHeap()->string_table()); | 15593 Handle<String> string) { |
15597 int entry = FindEntry(key); | 15594 InternalizedStringKey key(string); |
| 15595 return LookupKey(isolate, &key); |
| 15596 } |
| 15597 |
| 15598 |
| 15599 // TODO(ishell): Maybehandlify callers. |
| 15600 Handle<String> StringTable::LookupKey(Isolate* isolate, HashTableKey* key) { |
| 15601 Handle<StringTable> table = isolate->factory()->string_table(); |
| 15602 int entry = table->FindEntry(key); |
15598 | 15603 |
15599 // String already in table. | 15604 // String already in table. |
15600 if (entry != kNotFound) { | 15605 if (entry != kNotFound) { |
15601 *s = KeyAt(entry); | 15606 return handle(String::cast(table->KeyAt(entry)), isolate); |
15602 return this; | |
15603 } | 15607 } |
15604 | 15608 |
15605 // Adding new string. Grow table if needed. | 15609 // Adding new string. Grow table if needed. |
15606 Object* obj; | 15610 table = StringTable::EnsureCapacity(table, 1, key); |
15607 { MaybeObject* maybe_obj = EnsureCapacity(1, key); | |
15608 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | |
15609 } | |
15610 | 15611 |
15611 // Create string object. | 15612 // Create string object. |
15612 Object* string; | 15613 Handle<Object> string = key->AsHandle(isolate); |
15613 { MaybeObject* maybe_string = key->AsObject(GetHeap()); | 15614 // TODO(ishell): Maybehandlify this. |
15614 if (!maybe_string->ToObject(&string)) return maybe_string; | 15615 if (string.is_null()) return Handle<String>(); |
15615 } | |
15616 | |
15617 // If the string table grew as part of EnsureCapacity, obj is not | |
15618 // the current string table and therefore we cannot use | |
15619 // StringTable::cast here. | |
15620 StringTable* table = reinterpret_cast<StringTable*>(obj); | |
15621 | 15616 |
15622 // Add the new string and return it along with the string table. | 15617 // Add the new string and return it along with the string table. |
15623 entry = table->FindInsertionEntry(key->Hash()); | 15618 entry = table->FindInsertionEntry(key->Hash()); |
15624 table->set(EntryToIndex(entry), string); | 15619 table->set(EntryToIndex(entry), *string); |
15625 table->ElementAdded(); | 15620 table->ElementAdded(); |
15626 *s = string; | 15621 |
15627 return table; | 15622 isolate->factory()->set_string_table(table); |
| 15623 return Handle<String>::cast(string); |
15628 } | 15624 } |
15629 | 15625 |
15630 | 15626 |
15631 Handle<Object> CompilationCacheTable::Lookup(Handle<String> src, | 15627 Handle<Object> CompilationCacheTable::Lookup(Handle<String> src, |
15632 Handle<Context> context) { | 15628 Handle<Context> context) { |
15633 Isolate* isolate = GetIsolate(); | 15629 Isolate* isolate = GetIsolate(); |
15634 Handle<SharedFunctionInfo> shared(context->closure()->shared()); | 15630 Handle<SharedFunctionInfo> shared(context->closure()->shared()); |
15635 StringSharedKey key(src, shared, FLAG_use_strict ? STRICT : SLOPPY, | 15631 StringSharedKey key(src, shared, FLAG_use_strict ? STRICT : SLOPPY, |
15636 RelocInfo::kNoPosition); | 15632 RelocInfo::kNoPosition); |
15637 int entry = FindEntry(&key); | 15633 int entry = FindEntry(&key); |
(...skipping 1794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17432 #define ERROR_MESSAGES_TEXTS(C, T) T, | 17428 #define ERROR_MESSAGES_TEXTS(C, T) T, |
17433 static const char* error_messages_[] = { | 17429 static const char* error_messages_[] = { |
17434 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 17430 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
17435 }; | 17431 }; |
17436 #undef ERROR_MESSAGES_TEXTS | 17432 #undef ERROR_MESSAGES_TEXTS |
17437 return error_messages_[reason]; | 17433 return error_messages_[reason]; |
17438 } | 17434 } |
17439 | 17435 |
17440 | 17436 |
17441 } } // namespace v8::internal | 17437 } } // namespace v8::internal |
OLD | NEW |