Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Unified Diff: src/objects.h

Issue 227423004: Reland "HashTable::Shrink() handlified and derived template parameter added to HashTable hierarchy." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: The fix Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/objects.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index 1c3a82078adc0dfb89cb610f172d1f577dbdebe9..c74d252086185047e7cff43c081c916082a27545 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -3656,7 +3656,7 @@ class BaseShape {
}
};
-template<typename Shape, typename Key>
+template<typename Derived, typename Shape, typename Key>
class HashTable: public FixedArray {
public:
// Wrapper methods
@@ -3709,12 +3709,20 @@ class HashTable: public FixedArray {
}
// Returns a new HashTable object. Might return Failure.
+ // TODO(ishell): this will be eventually replaced by New().
MUST_USE_RESULT static MaybeObject* Allocate(
Heap* heap,
int at_least_space_for,
MinimumCapacity capacity_option = USE_DEFAULT_MINIMUM_CAPACITY,
PretenureFlag pretenure = NOT_TENURED);
+ // Returns a new HashTable object.
+ static Handle<Derived> New(
+ Isolate* isolate,
+ int at_least_space_for,
+ MinimumCapacity capacity_option = USE_DEFAULT_MINIMUM_CAPACITY,
+ PretenureFlag pretenure = NOT_TENURED);
+
// Computes the required capacity for a table holding the given
// number of elements. May be more than HashTable::kMaxCapacity.
static int ComputeCapacity(int at_least_space_for);
@@ -3824,10 +3832,10 @@ class HashTable: public FixedArray {
void Swap(uint32_t entry1, uint32_t entry2, WriteBarrierMode mode);
// Rehashes this hash-table into the new table.
- MUST_USE_RESULT MaybeObject* Rehash(HashTable* new_table, Key key);
+ void Rehash(Derived* new_table, Key key);
// Attempt to shrink hash table after removal of key.
- MUST_USE_RESULT MaybeObject* Shrink(Key key);
+ static Handle<Derived> Shrink(Handle<Derived> table, Key key);
// Ensure enough space for n additional elements.
MUST_USE_RESULT MaybeObject* EnsureCapacity(
@@ -3880,7 +3888,11 @@ class SeqOneByteString;
//
// No special elements in the prefix and the element size is 1
// because only the string itself (the key) needs to be stored.
-class StringTable: public HashTable<StringTableShape, HashTableKey*> {
+// TODO(ishell): Make StringTable a singleton class and move
+// Heap::InternalizeStringXX() methods here.
+class StringTable: public HashTable<StringTable,
+ StringTableShape,
+ HashTableKey*> {
public:
// Find string in the string table. If it is not there yet, it is
// added. The return value is the string table which might have
@@ -3932,7 +3944,7 @@ class MapCacheShape : public BaseShape<HashTableKey*> {
//
// Maps keys that are a fixed array of unique names to a map.
// Used for canonicalize maps for object literals.
-class MapCache: public HashTable<MapCacheShape, HashTableKey*> {
+class MapCache: public HashTable<MapCache, MapCacheShape, HashTableKey*> {
public:
// Find cached value for a name key, otherwise return null.
Object* Lookup(FixedArray* key);
@@ -3944,33 +3956,36 @@ class MapCache: public HashTable<MapCacheShape, HashTableKey*> {
};
-template <typename Shape, typename Key>
-class Dictionary: public HashTable<Shape, Key> {
+template <typename Derived, typename Shape, typename Key>
+class Dictionary: public HashTable<Derived, Shape, Key> {
+ protected:
+ typedef HashTable<Derived, Shape, Key> DerivedHashTable;
+
public:
- static inline Dictionary<Shape, Key>* cast(Object* obj) {
- return reinterpret_cast<Dictionary<Shape, Key>*>(obj);
+ static inline Dictionary* cast(Object* obj) {
+ return reinterpret_cast<Dictionary*>(obj);
}
// Returns the value at entry.
Object* ValueAt(int entry) {
- return this->get(HashTable<Shape, Key>::EntryToIndex(entry) + 1);
+ return this->get(DerivedHashTable::EntryToIndex(entry) + 1);
}
// Set the value for entry.
void ValueAtPut(int entry, Object* value) {
- this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 1, value);
+ this->set(DerivedHashTable::EntryToIndex(entry) + 1, value);
}
// Returns the property details for the property at entry.
PropertyDetails DetailsAt(int entry) {
ASSERT(entry >= 0); // Not found is -1, which is not caught by get().
return PropertyDetails(
- Smi::cast(this->get(HashTable<Shape, Key>::EntryToIndex(entry) + 2)));
+ Smi::cast(this->get(DerivedHashTable::EntryToIndex(entry) + 2)));
}
// Set the details for entry.
void DetailsAtPut(int entry, PropertyDetails value) {
- this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 2, value.AsSmi());
+ this->set(DerivedHashTable::EntryToIndex(entry) + 2, value.AsSmi());
}
// Sorting support
@@ -3980,16 +3995,14 @@ class Dictionary: public HashTable<Shape, Key> {
Object* DeleteProperty(int entry, JSObject::DeleteMode mode);
// TODO(ishell): Temporary wrapper until handlified.
static Handle<Object> DeleteProperty(
- Handle<Dictionary<Shape, Key> > dictionary,
+ Handle<Dictionary> dictionary,
int entry,
JSObject::DeleteMode mode);
// Attempt to shrink the dictionary after deletion of key.
- MUST_USE_RESULT MaybeObject* Shrink(Key key);
- // TODO(ishell): Temporary wrapper until handlified.
- MUST_USE_RESULT static Handle<FixedArray> Shrink(
- Handle<Dictionary<Shape, Key> > dictionary,
- Key key);
+ static inline Handle<Derived> Shrink(Handle<Derived> dictionary, Key key) {
+ return DerivedHashTable::Shrink(dictionary, key);
+ }
// Returns the number of elements in the dictionary filtering out properties
// with the specified attributes.
@@ -4059,8 +4072,7 @@ class Dictionary: public HashTable<Shape, Key> {
// Generate new enumeration indices to avoid enumeration index overflow.
MUST_USE_RESULT MaybeObject* GenerateNewEnumerationIndices();
- static const int kMaxNumberKeyIndex =
- HashTable<Shape, Key>::kPrefixStartIndex;
+ static const int kMaxNumberKeyIndex = DerivedHashTable::kPrefixStartIndex;
static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1;
};
@@ -4078,7 +4090,9 @@ class NameDictionaryShape : public BaseShape<Name*> {
};
-class NameDictionary: public Dictionary<NameDictionaryShape, Name*> {
+class NameDictionary: public Dictionary<NameDictionary,
+ NameDictionaryShape,
+ Name*> {
public:
static inline NameDictionary* cast(Object* obj) {
ASSERT(obj->IsDictionary());
@@ -4128,7 +4142,9 @@ class UnseededNumberDictionaryShape : public NumberDictionaryShape {
class SeededNumberDictionary
- : public Dictionary<SeededNumberDictionaryShape, uint32_t> {
+ : public Dictionary<SeededNumberDictionary,
+ SeededNumberDictionaryShape,
+ uint32_t> {
public:
static SeededNumberDictionary* cast(Object* obj) {
ASSERT(obj->IsDictionary());
@@ -4181,7 +4197,9 @@ class SeededNumberDictionary
class UnseededNumberDictionary
- : public Dictionary<UnseededNumberDictionaryShape, uint32_t> {
+ : public Dictionary<UnseededNumberDictionary,
+ UnseededNumberDictionaryShape,
+ uint32_t> {
public:
static UnseededNumberDictionary* cast(Object* obj) {
ASSERT(obj->IsDictionary());
@@ -4217,7 +4235,10 @@ class ObjectHashTableShape : public BaseShape<Object*> {
// ObjectHashTable maps keys that are arbitrary objects to object values by
// using the identity hash of the key for hashing purposes.
-class ObjectHashTable: public HashTable<ObjectHashTableShape, Object*> {
+class ObjectHashTable: public HashTable<ObjectHashTable,
+ ObjectHashTableShape,
+ Object*> {
+ typedef HashTable<ObjectHashTable, ObjectHashTableShape, Object*> HashTable_;
public:
static inline ObjectHashTable* cast(Object* obj) {
ASSERT(obj->IsHashTable());
@@ -4231,8 +4252,8 @@ class ObjectHashTable: public HashTable<ObjectHashTableShape, Object*> {
PretenureFlag pretenure = NOT_TENURED);
// Attempt to shrink hash table after removal of key.
- static Handle<ObjectHashTable> Shrink(Handle<ObjectHashTable> table,
- Handle<Object> key);
+ static inline Handle<ObjectHashTable> Shrink(Handle<ObjectHashTable> table,
+ Handle<Object> key);
// Looks up the value associated with the given key. The hole value is
// returned in case the key is not present.
@@ -4430,7 +4451,9 @@ class WeakHashTableShape : public BaseShape<Object*> {
// WeakHashTable maps keys that are arbitrary objects to object values.
// It is used for the global weak hash table that maps objects
// embedded in optimized code to dependent code lists.
-class WeakHashTable: public HashTable<WeakHashTableShape<2>, Object*> {
+class WeakHashTable: public HashTable<WeakHashTable,
+ WeakHashTableShape<2>,
+ Object*> {
public:
static inline WeakHashTable* cast(Object* obj) {
ASSERT(obj->IsHashTable());
@@ -8200,7 +8223,8 @@ class CompilationCacheShape : public BaseShape<HashTableKey*> {
};
-class CompilationCacheTable: public HashTable<CompilationCacheShape,
+class CompilationCacheTable: public HashTable<CompilationCacheTable,
+ CompilationCacheShape,
HashTableKey*> {
public:
// Find cached value for a string key, otherwise return null.
@@ -8301,7 +8325,8 @@ class CodeCacheHashTableShape : public BaseShape<HashTableKey*> {
};
-class CodeCacheHashTable: public HashTable<CodeCacheHashTableShape,
+class CodeCacheHashTable: public HashTable<CodeCacheHashTable,
+ CodeCacheHashTableShape,
HashTableKey*> {
public:
Object* Lookup(Name* name, Code::Flags flags);
@@ -8351,7 +8376,9 @@ class PolymorphicCodeCache: public Struct {
class PolymorphicCodeCacheHashTable
- : public HashTable<CodeCacheHashTableShape, HashTableKey*> {
+ : public HashTable<PolymorphicCodeCacheHashTable,
+ CodeCacheHashTableShape,
+ HashTableKey*> {
public:
Object* Lookup(MapHandleList* maps, int code_kind);
« no previous file with comments | « no previous file | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698