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

Side by Side Diff: src/objects.h

Issue 257853003: ObjectHashTable's key and WeakHashTable's key types are now Handle<Object> instead of Object*. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/mark-compact.cc ('k') | src/objects.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 3663 matching lines...) Expand 10 before | Expand all | Expand 10 after
3674 return HashForObject(key, object); 3674 return HashForObject(key, object);
3675 } 3675 }
3676 }; 3676 };
3677 3677
3678 template<typename Derived, typename Shape, typename Key> 3678 template<typename Derived, typename Shape, typename Key>
3679 class HashTable: public FixedArray { 3679 class HashTable: public FixedArray {
3680 public: 3680 public:
3681 // Wrapper methods 3681 // Wrapper methods
3682 inline uint32_t Hash(Key key) { 3682 inline uint32_t Hash(Key key) {
3683 if (Shape::UsesSeed) { 3683 if (Shape::UsesSeed) {
3684 return Shape::SeededHash(key, 3684 return Shape::SeededHash(key, GetHeap()->HashSeed());
3685 GetHeap()->HashSeed());
3686 } else { 3685 } else {
3687 return Shape::Hash(key); 3686 return Shape::Hash(key);
3688 } 3687 }
3689 } 3688 }
3690 3689
3691 inline uint32_t HashForObject(Key key, Object* object) { 3690 inline uint32_t HashForObject(Key key, Object* object) {
3692 if (Shape::UsesSeed) { 3691 if (Shape::UsesSeed) {
3693 return Shape::SeededHashForObject(key, 3692 return Shape::SeededHashForObject(key, GetHeap()->HashSeed(), object);
3694 GetHeap()->HashSeed(), object);
3695 } else { 3693 } else {
3696 return Shape::HashForObject(key, object); 3694 return Shape::HashForObject(key, object);
3697 } 3695 }
3698 } 3696 }
3699 3697
3700 // Returns the number of elements in the hash table. 3698 // Returns the number of elements in the hash table.
3701 int NumberOfElements() { 3699 int NumberOfElements() {
3702 return Smi::cast(get(kNumberOfElementsIndex))->value(); 3700 return Smi::cast(get(kNumberOfElementsIndex))->value();
3703 } 3701 }
3704 3702
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
4253 4251
4254 // Set an existing entry or add a new one if needed. 4252 // Set an existing entry or add a new one if needed.
4255 // Return the updated dictionary. 4253 // Return the updated dictionary.
4256 MUST_USE_RESULT static Handle<UnseededNumberDictionary> Set( 4254 MUST_USE_RESULT static Handle<UnseededNumberDictionary> Set(
4257 Handle<UnseededNumberDictionary> dictionary, 4255 Handle<UnseededNumberDictionary> dictionary,
4258 uint32_t key, 4256 uint32_t key,
4259 Handle<Object> value); 4257 Handle<Object> value);
4260 }; 4258 };
4261 4259
4262 4260
4263 class ObjectHashTableShape : public BaseShape<Object*> { 4261 class ObjectHashTableShape : public BaseShape<Handle<Object> > {
4264 public: 4262 public:
4265 static inline bool IsMatch(Object* key, Object* other); 4263 static inline bool IsMatch(Handle<Object> key, Object* other);
4266 static inline uint32_t Hash(Object* key); 4264 static inline uint32_t Hash(Handle<Object> key);
4267 static inline uint32_t HashForObject(Object* key, Object* object); 4265 static inline uint32_t HashForObject(Handle<Object> key, Object* object);
4268 MUST_USE_RESULT static inline MaybeObject* AsObject(Heap* heap, 4266 MUST_USE_RESULT static inline MaybeObject* AsObject(Heap* heap,
4269 Object* key); 4267 Handle<Object> key);
4268 static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Object> key);
4270 static const int kPrefixSize = 0; 4269 static const int kPrefixSize = 0;
4271 static const int kEntrySize = 2; 4270 static const int kEntrySize = 2;
4272 }; 4271 };
4273 4272
4274 4273
4275 // ObjectHashTable maps keys that are arbitrary objects to object values by 4274 // ObjectHashTable maps keys that are arbitrary objects to object values by
4276 // using the identity hash of the key for hashing purposes. 4275 // using the identity hash of the key for hashing purposes.
4277 class ObjectHashTable: public HashTable<ObjectHashTable, 4276 class ObjectHashTable: public HashTable<ObjectHashTable,
4278 ObjectHashTableShape, 4277 ObjectHashTableShape,
4279 Object*> { 4278 Handle<Object> > {
4280 typedef HashTable< 4279 typedef HashTable<
4281 ObjectHashTable, ObjectHashTableShape, Object*> DerivedHashTable; 4280 ObjectHashTable, ObjectHashTableShape, Handle<Object> > DerivedHashTable;
4282 public: 4281 public:
4283 static inline ObjectHashTable* cast(Object* obj) { 4282 static inline ObjectHashTable* cast(Object* obj) {
4284 ASSERT(obj->IsHashTable()); 4283 ASSERT(obj->IsHashTable());
4285 return reinterpret_cast<ObjectHashTable*>(obj); 4284 return reinterpret_cast<ObjectHashTable*>(obj);
4286 } 4285 }
4287 4286
4288 // Attempt to shrink hash table after removal of key. 4287 // Attempt to shrink hash table after removal of key.
4289 MUST_USE_RESULT static inline Handle<ObjectHashTable> Shrink( 4288 MUST_USE_RESULT static inline Handle<ObjectHashTable> Shrink(
4290 Handle<ObjectHashTable> table, 4289 Handle<ObjectHashTable> table,
4291 Handle<Object> key); 4290 Handle<Object> key);
4292 4291
4293 // Looks up the value associated with the given key. The hole value is 4292 // Looks up the value associated with the given key. The hole value is
4294 // returned in case the key is not present. 4293 // returned in case the key is not present.
4295 Object* Lookup(Object* key); 4294 Object* Lookup(Object* key);
4296 4295
4296 int FindEntry(Handle<Object> key);
4297 // TODO(ishell): Remove this when all the callers are handlified.
4298 int FindEntry(Object* key);
4299
4297 // Adds (or overwrites) the value associated with the given key. Mapping a 4300 // Adds (or overwrites) the value associated with the given key. Mapping a
4298 // key to the hole value causes removal of the whole entry. 4301 // key to the hole value causes removal of the whole entry.
4299 static Handle<ObjectHashTable> Put(Handle<ObjectHashTable> table, 4302 static Handle<ObjectHashTable> Put(Handle<ObjectHashTable> table,
4300 Handle<Object> key, 4303 Handle<Object> key,
4301 Handle<Object> value); 4304 Handle<Object> value);
4302 4305
4303 private: 4306 private:
4304 friend class MarkCompactCollector; 4307 friend class MarkCompactCollector;
4305 4308
4306 void AddEntry(int entry, Object* key, Object* value); 4309 void AddEntry(int entry, Object* key, Object* value);
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
4485 private: 4488 private:
4486 Object* ValueAt(int entry) { 4489 Object* ValueAt(int entry) {
4487 return get(EntryToIndex(entry) + kValueOffset); 4490 return get(EntryToIndex(entry) + kValueOffset);
4488 } 4491 }
4489 4492
4490 static const int kValueOffset = 1; 4493 static const int kValueOffset = 1;
4491 }; 4494 };
4492 4495
4493 4496
4494 template <int entrysize> 4497 template <int entrysize>
4495 class WeakHashTableShape : public BaseShape<Object*> { 4498 class WeakHashTableShape : public BaseShape<Handle<Object> > {
4496 public: 4499 public:
4497 static inline bool IsMatch(Object* key, Object* other); 4500 static inline bool IsMatch(Handle<Object> key, Object* other);
4498 static inline uint32_t Hash(Object* key); 4501 static inline uint32_t Hash(Handle<Object> key);
4499 static inline uint32_t HashForObject(Object* key, Object* object); 4502 static inline uint32_t HashForObject(Handle<Object> key, Object* object);
4500 MUST_USE_RESULT static inline MaybeObject* AsObject(Heap* heap, 4503 static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Object> key);
4501 Object* key);
4502 static const int kPrefixSize = 0; 4504 static const int kPrefixSize = 0;
4503 static const int kEntrySize = entrysize; 4505 static const int kEntrySize = entrysize;
4504 }; 4506 };
4505 4507
4506 4508
4507 // WeakHashTable maps keys that are arbitrary objects to object values. 4509 // WeakHashTable maps keys that are arbitrary objects to object values.
4508 // It is used for the global weak hash table that maps objects 4510 // It is used for the global weak hash table that maps objects
4509 // embedded in optimized code to dependent code lists. 4511 // embedded in optimized code to dependent code lists.
4510 class WeakHashTable: public HashTable<WeakHashTable, 4512 class WeakHashTable: public HashTable<WeakHashTable,
4511 WeakHashTableShape<2>, 4513 WeakHashTableShape<2>,
4512 Object*> { 4514 Handle<Object> > {
4515 typedef HashTable<
4516 WeakHashTable, WeakHashTableShape<2>, Handle<Object> > DerivedHashTable;
4513 public: 4517 public:
4514 static inline WeakHashTable* cast(Object* obj) { 4518 static inline WeakHashTable* cast(Object* obj) {
4515 ASSERT(obj->IsHashTable()); 4519 ASSERT(obj->IsHashTable());
4516 return reinterpret_cast<WeakHashTable*>(obj); 4520 return reinterpret_cast<WeakHashTable*>(obj);
4517 } 4521 }
4518 4522
4519 // Looks up the value associated with the given key. The hole value is 4523 // Looks up the value associated with the given key. The hole value is
4520 // returned in case the key is not present. 4524 // returned in case the key is not present.
4521 Object* Lookup(Object* key); 4525 Object* Lookup(Object* key);
4522 4526
4527 int FindEntry(Handle<Object> key);
4528 // TODO(ishell): Remove this when all the callers are handlified.
4529 int FindEntry(Object* key);
4530
4523 // Adds (or overwrites) the value associated with the given key. Mapping a 4531 // Adds (or overwrites) the value associated with the given key. Mapping a
4524 // key to the hole value causes removal of the whole entry. 4532 // key to the hole value causes removal of the whole entry.
4525 MUST_USE_RESULT static Handle<WeakHashTable> Put(Handle<WeakHashTable> table, 4533 MUST_USE_RESULT static Handle<WeakHashTable> Put(Handle<WeakHashTable> table,
4526 Handle<Object> key, 4534 Handle<Object> key,
4527 Handle<Object> value); 4535 Handle<Object> value);
4528 4536
4529 // This function is called when heap verification is turned on. 4537 // This function is called when heap verification is turned on.
4530 void Zap(Object* value) { 4538 void Zap(Object* value) {
4531 int capacity = Capacity(); 4539 int capacity = Capacity();
4532 for (int i = 0; i < capacity; i++) { 4540 for (int i = 0; i < capacity; i++) {
(...skipping 6748 matching lines...) Expand 10 before | Expand all | Expand 10 after
11281 } else { 11289 } else {
11282 value &= ~(1 << bit_position); 11290 value &= ~(1 << bit_position);
11283 } 11291 }
11284 return value; 11292 return value;
11285 } 11293 }
11286 }; 11294 };
11287 11295
11288 } } // namespace v8::internal 11296 } } // namespace v8::internal
11289 11297
11290 #endif // V8_OBJECTS_H_ 11298 #endif // V8_OBJECTS_H_
OLDNEW
« no previous file with comments | « src/mark-compact.cc ('k') | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698