Chromium Code Reviews| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 #include "isolate-inl.h" | 45 #include "isolate-inl.h" |
| 46 #include "log.h" | 46 #include "log.h" |
| 47 #include "objects-inl.h" | 47 #include "objects-inl.h" |
| 48 #include "objects-visiting-inl.h" | 48 #include "objects-visiting-inl.h" |
| 49 #include "macro-assembler.h" | 49 #include "macro-assembler.h" |
| 50 #include "mark-compact.h" | 50 #include "mark-compact.h" |
| 51 #include "safepoint-table.h" | 51 #include "safepoint-table.h" |
| 52 #include "string-stream.h" | 52 #include "string-stream.h" |
| 53 #include "utils.h" | 53 #include "utils.h" |
| 54 | 54 |
| 55 #include "close-table.h" | |
| 56 | |
| 55 #ifdef ENABLE_DISASSEMBLER | 57 #ifdef ENABLE_DISASSEMBLER |
| 56 #include "disasm.h" | 58 #include "disasm.h" |
| 57 #include "disassembler.h" | 59 #include "disassembler.h" |
| 58 #endif | 60 #endif |
| 59 | 61 |
| 60 namespace v8 { | 62 namespace v8 { |
| 61 namespace internal { | 63 namespace internal { |
| 62 | 64 |
| 63 | 65 |
| 64 MUST_USE_RESULT static MaybeObject* CreateJSValue(JSFunction* constructor, | 66 MUST_USE_RESULT static MaybeObject* CreateJSValue(JSFunction* constructor, |
| (...skipping 15822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 15887 } | 15889 } |
| 15888 | 15890 |
| 15889 | 15891 |
| 15890 void WeakHashTable::AddEntry(int entry, Object* key, Object* value) { | 15892 void WeakHashTable::AddEntry(int entry, Object* key, Object* value) { |
| 15891 set(EntryToIndex(entry), key); | 15893 set(EntryToIndex(entry), key); |
| 15892 set(EntryToValueIndex(entry), value); | 15894 set(EntryToValueIndex(entry), value); |
| 15893 ElementAdded(); | 15895 ElementAdded(); |
| 15894 } | 15896 } |
| 15895 | 15897 |
| 15896 | 15898 |
| 15899 // TODO(adamk): Figure out where to put this, maybe we need some traits | |
| 15900 //const double CloseTable<entrysize>::kLoadFactor = 8.0 / 3.0; | |
| 15901 | |
| 15902 | |
| 15903 template<int entrysize> | |
| 15904 MaybeObject* CloseTable<entrysize>::Allocate(Heap* heap, int capacity) { | |
| 15905 // capacity must be a factor of two | |
| 15906 int num_buckets = capacity / kLoadFactor; | |
| 15907 ASSERT(num_buckets * kLoadFactor == capacity); | |
| 15908 CloseTable* table; | |
| 15909 { MaybeObject* maybe_obj = | |
| 15910 heap->AllocateFixedArray( | |
| 15911 kHashTableStartIndex + num_buckets | |
| 15912 + (capacity * kEntrySize)); | |
| 15913 if (!maybe_obj->To(&table)) return maybe_obj; | |
| 15914 } | |
| 15915 for (int i = 0; i < num_buckets; ++i) { | |
| 15916 table->set(kHashTableStartIndex + i, heap->undefined_value()); | |
| 15917 } | |
| 15918 table->SetNumberOfBuckets(num_buckets); | |
| 15919 table->SetNumberOfElements(0); | |
| 15920 table->SetNumberOfDeletedElements(0); | |
| 15921 return table; | |
| 15922 } | |
| 15923 | |
| 15924 | |
| 15925 template<int entrysize> | |
| 15926 MaybeObject* CloseTable<entrysize>::EnsureCapacity(int num_to_add) { | |
| 15927 int nof = NumberOfElements(); | |
| 15928 int nod = NumberOfDeletedElements(); | |
| 15929 // TODO(adamk): Allow possibility to compact instead of always | |
| 15930 // increasing capacity if num deleted is big. | |
| 15931 if ((nof + nod + num_to_add) <= Capacity()) return this; | |
| 15932 int new_capacity = Capacity() * 2; | |
| 15933 CloseTable* new_table; | |
| 15934 { MaybeObject* maybe_obj = Allocate(GetHeap(), new_capacity); | |
| 15935 if (!maybe_obj->To(&new_table)) return maybe_obj; | |
| 15936 } | |
| 15937 int new_buckets = new_table->NumberOfBuckets(); | |
| 15938 for (int entry = 0; entry < (nof + nod); ++entry) { | |
| 15939 Object* key = KeyAt(entry); | |
| 15940 if (key->IsTheHole()) continue; | |
| 15941 Object* hash = key->GetHash(); | |
| 15942 int bucket = Smi::cast(hash)->value() & (new_buckets - 1); | |
| 15943 Object* old_entry = new_table->get(kHashTableStartIndex + bucket); | |
| 15944 new_table->set(kHashTableStartIndex + bucket, Smi::FromInt(entry)); | |
| 15945 int index = new_table->EntryToIndex(entry); | |
| 15946 new_table->set(index, key); | |
|
arv (Not doing code reviews)
2014/03/27 22:39:02
For map, we probably need to store the value at in
adamk
2014/03/27 22:43:13
Oh, you're looking at an old one. This is now an i
| |
| 15947 new_table->set(index + kChainOffset, old_entry); | |
| 15948 } | |
| 15949 new_table->SetNumberOfElements(nof); | |
| 15950 return new_table; | |
| 15951 } | |
| 15952 | |
| 15953 | |
| 15954 template<int entrysize> | |
| 15955 int CloseTable<entrysize>::Lookup(Object* key) { | |
| 15956 ASSERT(!key->IsTheHole()); | |
| 15957 Object* hash = key->GetHash(); | |
| 15958 if (hash->IsUndefined()) return kNotFound; | |
| 15959 int bucket = Smi::cast(hash)->value() & (NumberOfBuckets() - 1); | |
| 15960 Object* bucket_entry = get(kHashTableStartIndex + bucket); | |
| 15961 if (!bucket_entry->IsSmi()) return kNotFound; | |
|
arv (Not doing code reviews)
2014/03/27 22:39:02
Maybe we should use -1 instead of undefined? Might
adamk
2014/03/27 22:43:13
Hmm, and I guess I can use -1 even in the chain...
| |
| 15962 int entry = Smi::cast(bucket_entry)->value(); | |
| 15963 while (true) { | |
| 15964 Object* candidate = KeyAt(entry); | |
| 15965 if (candidate == key) | |
| 15966 return entry; | |
| 15967 Object* chain = ChainAt(entry); | |
| 15968 if (!chain->IsSmi()) | |
| 15969 break; | |
| 15970 entry = Smi::cast(chain)->value(); | |
| 15971 } | |
| 15972 return kNotFound; | |
| 15973 } | |
| 15974 | |
| 15975 | |
| 15976 bool CloseTableSet::Contains(Object* key) { | |
| 15977 return Lookup(key) != kNotFound; | |
| 15978 } | |
| 15979 | |
| 15980 | |
| 15981 Handle<CloseTableSet> CloseTableSet::EnsureCapacity( | |
| 15982 Handle<CloseTableSet> table, | |
| 15983 int num_to_add) { | |
| 15984 Handle<CloseTable<1> > table_base = table; | |
| 15985 CALL_HEAP_FUNCTION(table_base->GetIsolate(), | |
| 15986 table_base->EnsureCapacity(num_to_add), | |
| 15987 CloseTableSet); | |
| 15988 } | |
| 15989 | |
| 15990 | |
| 15991 Handle<CloseTableSet> CloseTableSet::Add(Handle<CloseTableSet> table, | |
| 15992 Handle<Object> key) { | |
| 15993 if (table->Lookup(*key) != kNotFound) return table; | |
| 15994 | |
| 15995 table = EnsureCapacity(table, 1); | |
| 15996 | |
| 15997 Handle<Object> hash = GetOrCreateHash(key, table->GetIsolate()); | |
| 15998 int bucket = Smi::cast(*hash)->value() & (table->NumberOfBuckets() - 1); | |
| 15999 int nof = table->NumberOfElements(); | |
| 16000 int entry = nof + table->NumberOfDeletedElements(); | |
| 16001 int index = table->EntryToIndex(entry); | |
| 16002 Object* old_entry = table->get(kHashTableStartIndex + bucket); | |
| 16003 table->set(kHashTableStartIndex + bucket, Smi::FromInt(entry)); | |
| 16004 table->set(index, *key); | |
| 16005 table->set(index + kChainOffset, old_entry); | |
| 16006 table->ElementAdded(); | |
| 16007 return table; | |
| 16008 } | |
| 16009 | |
| 16010 | |
| 16011 Handle<CloseTableSet> CloseTableSet::Remove(Handle<CloseTableSet> table, | |
| 16012 Handle<Object> key) { | |
| 16013 int entry = table->Lookup(*key); | |
| 16014 if (entry == kNotFound) return table; | |
| 16015 | |
| 16016 table->set_the_hole(table->EntryToIndex(entry)); | |
| 16017 table->ElementRemoved(); | |
| 16018 | |
| 16019 /* shrink if needed & not iterating */ | |
| 16020 return table; | |
| 16021 } | |
| 16022 | |
| 16023 | |
| 16024 template class CloseTable<1>; | |
| 16025 | |
| 16026 | |
| 15897 DeclaredAccessorDescriptorIterator::DeclaredAccessorDescriptorIterator( | 16027 DeclaredAccessorDescriptorIterator::DeclaredAccessorDescriptorIterator( |
| 15898 DeclaredAccessorDescriptor* descriptor) | 16028 DeclaredAccessorDescriptor* descriptor) |
| 15899 : array_(descriptor->serialized_data()->GetDataStartAddress()), | 16029 : array_(descriptor->serialized_data()->GetDataStartAddress()), |
| 15900 length_(descriptor->serialized_data()->length()), | 16030 length_(descriptor->serialized_data()->length()), |
| 15901 offset_(0) { | 16031 offset_(0) { |
| 15902 } | 16032 } |
| 15903 | 16033 |
| 15904 | 16034 |
| 15905 const DeclaredAccessorDescriptorData* | 16035 const DeclaredAccessorDescriptorData* |
| 15906 DeclaredAccessorDescriptorIterator::Next() { | 16036 DeclaredAccessorDescriptorIterator::Next() { |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 16419 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16549 #define ERROR_MESSAGES_TEXTS(C, T) T, |
| 16420 static const char* error_messages_[] = { | 16550 static const char* error_messages_[] = { |
| 16421 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16551 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
| 16422 }; | 16552 }; |
| 16423 #undef ERROR_MESSAGES_TEXTS | 16553 #undef ERROR_MESSAGES_TEXTS |
| 16424 return error_messages_[reason]; | 16554 return error_messages_[reason]; |
| 16425 } | 16555 } |
| 16426 | 16556 |
| 16427 | 16557 |
| 16428 } } // namespace v8::internal | 16558 } } // namespace v8::internal |
| OLD | NEW |