OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_OBJECTS_H_ | 5 #ifndef V8_OBJECTS_H_ |
6 #define V8_OBJECTS_H_ | 6 #define V8_OBJECTS_H_ |
7 | 7 |
8 #include <iosfwd> | 8 #include <iosfwd> |
9 | 9 |
10 #include "src/allocation.h" | 10 #include "src/allocation.h" |
(...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 | 843 |
844 | 844 |
845 class AccessorPair; | 845 class AccessorPair; |
846 class AllocationSite; | 846 class AllocationSite; |
847 class AllocationSiteCreationContext; | 847 class AllocationSiteCreationContext; |
848 class AllocationSiteUsageContext; | 848 class AllocationSiteUsageContext; |
849 class ConsString; | 849 class ConsString; |
850 class DictionaryElementsAccessor; | 850 class DictionaryElementsAccessor; |
851 class ElementsAccessor; | 851 class ElementsAccessor; |
852 class FixedArrayBase; | 852 class FixedArrayBase; |
| 853 class FunctionLiteral; |
853 class GlobalObject; | 854 class GlobalObject; |
854 class LayoutDescriptor; | 855 class LayoutDescriptor; |
855 class LookupIterator; | 856 class LookupIterator; |
856 class ObjectVisitor; | 857 class ObjectVisitor; |
857 class StringStream; | 858 class StringStream; |
858 class TypeFeedbackVector; | 859 class TypeFeedbackVector; |
859 class WeakCell; | 860 class WeakCell; |
860 class FunctionLiteral; | |
861 | 861 |
862 // We cannot just say "class HeapType;" if it is created from a template... =8-? | 862 // We cannot just say "class HeapType;" if it is created from a template... =8-? |
863 template<class> class TypeImpl; | 863 template<class> class TypeImpl; |
864 struct HeapTypeConfig; | 864 struct HeapTypeConfig; |
865 typedef TypeImpl<HeapTypeConfig> HeapType; | 865 typedef TypeImpl<HeapTypeConfig> HeapType; |
866 | 866 |
867 | 867 |
868 // A template-ized version of the IsXXX functions. | 868 // A template-ized version of the IsXXX functions. |
869 template <class C> inline bool Is(Object* obj); | 869 template <class C> inline bool Is(Object* obj); |
870 | 870 |
(...skipping 3171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4042 public: | 4042 public: |
4043 static inline bool IsMatch(Handle<Object> key, Object* other); | 4043 static inline bool IsMatch(Handle<Object> key, Object* other); |
4044 static inline uint32_t Hash(Handle<Object> key); | 4044 static inline uint32_t Hash(Handle<Object> key); |
4045 static inline uint32_t HashForObject(Handle<Object> key, Object* object); | 4045 static inline uint32_t HashForObject(Handle<Object> key, Object* object); |
4046 static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Object> key); | 4046 static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Object> key); |
4047 static const int kPrefixSize = 0; | 4047 static const int kPrefixSize = 0; |
4048 static const int kEntrySize = entrysize; | 4048 static const int kEntrySize = entrysize; |
4049 }; | 4049 }; |
4050 | 4050 |
4051 | 4051 |
4052 // WeakHashTable maps keys that are arbitrary objects to object values. | 4052 // WeakHashTable maps keys that are arbitrary heap objects to heap object |
4053 // It is used for the global weak hash table that maps objects | 4053 // values. The table wraps the keys in weak cells and store values directly. |
4054 // embedded in optimized code to dependent code lists. | 4054 // Thus it references keys weakly and values strongly. |
4055 class WeakHashTable: public HashTable<WeakHashTable, | 4055 class WeakHashTable: public HashTable<WeakHashTable, |
4056 WeakHashTableShape<2>, | 4056 WeakHashTableShape<2>, |
4057 Handle<Object> > { | 4057 Handle<Object> > { |
4058 typedef HashTable< | 4058 typedef HashTable< |
4059 WeakHashTable, WeakHashTableShape<2>, Handle<Object> > DerivedHashTable; | 4059 WeakHashTable, WeakHashTableShape<2>, Handle<Object> > DerivedHashTable; |
4060 public: | 4060 public: |
4061 DECLARE_CAST(WeakHashTable) | 4061 DECLARE_CAST(WeakHashTable) |
4062 | 4062 |
4063 // Looks up the value associated with the given key. The hole value is | 4063 // Looks up the value associated with the given key. The hole value is |
4064 // returned in case the key is not present. | 4064 // returned in case the key is not present. |
4065 Object* Lookup(Handle<Object> key); | 4065 Object* Lookup(Handle<HeapObject> key); |
4066 | 4066 |
4067 // Adds (or overwrites) the value associated with the given key. Mapping a | 4067 // Adds (or overwrites) the value associated with the given key. Mapping a |
4068 // key to the hole value causes removal of the whole entry. | 4068 // key to the hole value causes removal of the whole entry. |
4069 MUST_USE_RESULT static Handle<WeakHashTable> Put(Handle<WeakHashTable> table, | 4069 MUST_USE_RESULT static Handle<WeakHashTable> Put(Handle<WeakHashTable> table, |
4070 Handle<Object> key, | 4070 Handle<HeapObject> key, |
4071 Handle<Object> value); | 4071 Handle<HeapObject> value); |
4072 | |
4073 // This function is called when heap verification is turned on. | |
4074 void Zap(Object* value) { | |
4075 int capacity = Capacity(); | |
4076 for (int i = 0; i < capacity; i++) { | |
4077 set(EntryToIndex(i), value); | |
4078 set(EntryToValueIndex(i), value); | |
4079 } | |
4080 } | |
4081 | 4072 |
4082 private: | 4073 private: |
4083 friend class MarkCompactCollector; | 4074 friend class MarkCompactCollector; |
4084 | 4075 |
4085 void AddEntry(int entry, Handle<Object> key, Handle<Object> value); | 4076 void AddEntry(int entry, Handle<WeakCell> key, Handle<HeapObject> value); |
4086 | 4077 |
4087 // Returns the index to the value of an entry. | 4078 // Returns the index to the value of an entry. |
4088 static inline int EntryToValueIndex(int entry) { | 4079 static inline int EntryToValueIndex(int entry) { |
4089 return EntryToIndex(entry) + 1; | 4080 return EntryToIndex(entry) + 1; |
4090 } | 4081 } |
4091 }; | 4082 }; |
4092 | 4083 |
4093 | 4084 |
4094 // JSFunctionResultCache caches results of some JSFunction invocation. | 4085 // JSFunctionResultCache caches results of some JSFunction invocation. |
4095 // It is a fixed array with fixed structure: | 4086 // It is a fixed array with fixed structure: |
(...skipping 1440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5536 // array is partitioned into several groups of dependent codes. Each group | 5527 // array is partitioned into several groups of dependent codes. Each group |
5537 // contains codes with the same dependency on the map. The array has the | 5528 // contains codes with the same dependency on the map. The array has the |
5538 // following layout for n dependency groups: | 5529 // following layout for n dependency groups: |
5539 // | 5530 // |
5540 // +----+----+-----+----+---------+----------+-----+---------+-----------+ | 5531 // +----+----+-----+----+---------+----------+-----+---------+-----------+ |
5541 // | C1 | C2 | ... | Cn | group 1 | group 2 | ... | group n | undefined | | 5532 // | C1 | C2 | ... | Cn | group 1 | group 2 | ... | group n | undefined | |
5542 // +----+----+-----+----+---------+----------+-----+---------+-----------+ | 5533 // +----+----+-----+----+---------+----------+-----+---------+-----------+ |
5543 // | 5534 // |
5544 // The first n elements are Smis, each of them specifies the number of codes | 5535 // The first n elements are Smis, each of them specifies the number of codes |
5545 // in the corresponding group. The subsequent elements contain grouped code | 5536 // in the corresponding group. The subsequent elements contain grouped code |
5546 // objects. The suffix of the array can be filled with the undefined value if | 5537 // objects in weak cells. The suffix of the array can be filled with the |
5547 // the number of codes is less than the length of the array. The order of the | 5538 // undefined value if the number of codes is less than the length of the |
5548 // code objects within a group is not preserved. | 5539 // array. The order of the code objects within a group is not preserved. |
5549 // | 5540 // |
5550 // All code indexes used in the class are counted starting from the first | 5541 // All code indexes used in the class are counted starting from the first |
5551 // code object of the first group. In other words, code index 0 corresponds | 5542 // code object of the first group. In other words, code index 0 corresponds |
5552 // to array index n = kCodesStartIndex. | 5543 // to array index n = kCodesStartIndex. |
5553 | 5544 |
5554 class DependentCode: public FixedArray { | 5545 class DependentCode: public FixedArray { |
5555 public: | 5546 public: |
5556 enum DependencyGroup { | 5547 enum DependencyGroup { |
5557 // Group of code that weakly embed this map and depend on being | 5548 // Group of code that weakly embed this map and depend on being |
5558 // deoptimized when the map is garbage collected. | 5549 // deoptimized when the map is garbage collected. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5592 class GroupStartIndexes { | 5583 class GroupStartIndexes { |
5593 public: | 5584 public: |
5594 explicit GroupStartIndexes(DependentCode* entries); | 5585 explicit GroupStartIndexes(DependentCode* entries); |
5595 void Recompute(DependentCode* entries); | 5586 void Recompute(DependentCode* entries); |
5596 int at(int i) { return start_indexes_[i]; } | 5587 int at(int i) { return start_indexes_[i]; } |
5597 int number_of_entries() { return start_indexes_[kGroupCount]; } | 5588 int number_of_entries() { return start_indexes_[kGroupCount]; } |
5598 private: | 5589 private: |
5599 int start_indexes_[kGroupCount + 1]; | 5590 int start_indexes_[kGroupCount + 1]; |
5600 }; | 5591 }; |
5601 | 5592 |
5602 bool Contains(DependencyGroup group, Code* code); | 5593 bool Contains(DependencyGroup group, WeakCell* code_cell); |
5603 static Handle<DependentCode> Insert(Handle<DependentCode> entries, | 5594 |
5604 DependencyGroup group, | 5595 static Handle<DependentCode> InsertCompilationInfo( |
5605 Handle<Object> object); | 5596 Handle<DependentCode> entries, DependencyGroup group, |
5606 void UpdateToFinishedCode(DependencyGroup group, | 5597 Handle<Foreign> info); |
5607 CompilationInfo* info, | 5598 |
5608 Code* code); | 5599 static Handle<DependentCode> InsertWeakCode(Handle<DependentCode> entries, |
| 5600 DependencyGroup group, |
| 5601 Handle<WeakCell> code_cell); |
| 5602 |
| 5603 void UpdateToFinishedCode(DependencyGroup group, Foreign* info, |
| 5604 WeakCell* code_cell); |
| 5605 |
5609 void RemoveCompilationInfo(DependentCode::DependencyGroup group, | 5606 void RemoveCompilationInfo(DependentCode::DependencyGroup group, |
5610 CompilationInfo* info); | 5607 Foreign* info); |
5611 | 5608 |
5612 void DeoptimizeDependentCodeGroup(Isolate* isolate, | 5609 void DeoptimizeDependentCodeGroup(Isolate* isolate, |
5613 DependentCode::DependencyGroup group); | 5610 DependentCode::DependencyGroup group); |
5614 | 5611 |
5615 bool MarkCodeForDeoptimization(Isolate* isolate, | 5612 bool MarkCodeForDeoptimization(Isolate* isolate, |
5616 DependentCode::DependencyGroup group); | 5613 DependentCode::DependencyGroup group); |
5617 | 5614 |
5618 // The following low-level accessors should only be used by this class | 5615 // The following low-level accessors should only be used by this class |
5619 // and the mark compact collector. | 5616 // and the mark compact collector. |
5620 inline int number_of_entries(DependencyGroup group); | 5617 inline int number_of_entries(DependencyGroup group); |
5621 inline void set_number_of_entries(DependencyGroup group, int value); | 5618 inline void set_number_of_entries(DependencyGroup group, int value); |
5622 inline bool is_code_at(int i); | 5619 inline Object* object_at(int i); |
5623 inline Code* code_at(int i); | |
5624 inline CompilationInfo* compilation_info_at(int i); | |
5625 inline void set_object_at(int i, Object* object); | 5620 inline void set_object_at(int i, Object* object); |
5626 inline Object** slot_at(int i); | |
5627 inline Object* object_at(int i); | |
5628 inline void clear_at(int i); | 5621 inline void clear_at(int i); |
5629 inline void copy(int from, int to); | 5622 inline void copy(int from, int to); |
5630 DECLARE_CAST(DependentCode) | 5623 DECLARE_CAST(DependentCode) |
5631 | 5624 |
5632 static DependentCode* ForObject(Handle<HeapObject> object, | 5625 static DependentCode* ForObject(Handle<HeapObject> object, |
5633 DependencyGroup group); | 5626 DependencyGroup group); |
5634 | 5627 |
5635 static const char* DependencyGroupName(DependencyGroup group); | 5628 static const char* DependencyGroupName(DependencyGroup group); |
5636 static void SetMarkedForDeoptimization(Code* code, DependencyGroup group); | 5629 static void SetMarkedForDeoptimization(Code* code, DependencyGroup group); |
5637 | 5630 |
5638 private: | 5631 private: |
| 5632 static Handle<DependentCode> Insert(Handle<DependentCode> entries, |
| 5633 DependencyGroup group, |
| 5634 Handle<Object> object); |
| 5635 static Handle<DependentCode> EnsureSpace(Handle<DependentCode> entries); |
5639 // Make a room at the end of the given group by moving out the first | 5636 // Make a room at the end of the given group by moving out the first |
5640 // code objects of the subsequent groups. | 5637 // code objects of the subsequent groups. |
5641 inline void ExtendGroup(DependencyGroup group); | 5638 inline void ExtendGroup(DependencyGroup group); |
| 5639 // Compact by removing cleared weak cells and return true if there was |
| 5640 // any cleared weak cell. |
| 5641 bool Compact(); |
| 5642 static int Grow(int number_of_entries) { |
| 5643 if (number_of_entries < 5) return number_of_entries + 1; |
| 5644 return number_of_entries * 5 / 4; |
| 5645 } |
5642 static const int kCodesStartIndex = kGroupCount; | 5646 static const int kCodesStartIndex = kGroupCount; |
5643 }; | 5647 }; |
5644 | 5648 |
5645 | 5649 |
5646 // All heap objects have a Map that describes their structure. | 5650 // All heap objects have a Map that describes their structure. |
5647 // A Map contains information about: | 5651 // A Map contains information about: |
5648 // - Size information about the object | 5652 // - Size information about the object |
5649 // - How to iterate over an object (for garbage collection) | 5653 // - How to iterate over an object (for garbage collection) |
5650 class Map: public HeapObject { | 5654 class Map: public HeapObject { |
5651 public: | 5655 public: |
(...skipping 2814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8466 static const int kPretenureCreateCountOffset = | 8470 static const int kPretenureCreateCountOffset = |
8467 kPretenureDataOffset + kPointerSize; | 8471 kPretenureDataOffset + kPointerSize; |
8468 static const int kDependentCodeOffset = | 8472 static const int kDependentCodeOffset = |
8469 kPretenureCreateCountOffset + kPointerSize; | 8473 kPretenureCreateCountOffset + kPointerSize; |
8470 static const int kWeakNextOffset = kDependentCodeOffset + kPointerSize; | 8474 static const int kWeakNextOffset = kDependentCodeOffset + kPointerSize; |
8471 static const int kSize = kWeakNextOffset + kPointerSize; | 8475 static const int kSize = kWeakNextOffset + kPointerSize; |
8472 | 8476 |
8473 // During mark compact we need to take special care for the dependent code | 8477 // During mark compact we need to take special care for the dependent code |
8474 // field. | 8478 // field. |
8475 static const int kPointerFieldsBeginOffset = kTransitionInfoOffset; | 8479 static const int kPointerFieldsBeginOffset = kTransitionInfoOffset; |
8476 static const int kPointerFieldsEndOffset = kDependentCodeOffset; | 8480 static const int kPointerFieldsEndOffset = kWeakNextOffset; |
8477 | 8481 |
8478 // For other visitors, use the fixed body descriptor below. | 8482 // For other visitors, use the fixed body descriptor below. |
8479 typedef FixedBodyDescriptor<HeapObject::kHeaderSize, | 8483 typedef FixedBodyDescriptor<HeapObject::kHeaderSize, |
8480 kDependentCodeOffset + kPointerSize, | 8484 kDependentCodeOffset + kPointerSize, |
8481 kSize> BodyDescriptor; | 8485 kSize> BodyDescriptor; |
8482 | 8486 |
8483 private: | 8487 private: |
8484 static void AddDependentCompilationInfo(Handle<AllocationSite> site, | 8488 static void AddDependentCompilationInfo(Handle<AllocationSite> site, |
8485 DependentCode::DependencyGroup group, | 8489 DependentCode::DependencyGroup group, |
8486 CompilationInfo* info); | 8490 CompilationInfo* info); |
(...skipping 1247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9734 // Dispatched behavior. | 9738 // Dispatched behavior. |
9735 DECLARE_PRINTER(PropertyCell) | 9739 DECLARE_PRINTER(PropertyCell) |
9736 DECLARE_VERIFIER(PropertyCell) | 9740 DECLARE_VERIFIER(PropertyCell) |
9737 | 9741 |
9738 // Layout description. | 9742 // Layout description. |
9739 static const int kTypeOffset = kValueOffset + kPointerSize; | 9743 static const int kTypeOffset = kValueOffset + kPointerSize; |
9740 static const int kDependentCodeOffset = kTypeOffset + kPointerSize; | 9744 static const int kDependentCodeOffset = kTypeOffset + kPointerSize; |
9741 static const int kSize = kDependentCodeOffset + kPointerSize; | 9745 static const int kSize = kDependentCodeOffset + kPointerSize; |
9742 | 9746 |
9743 static const int kPointerFieldsBeginOffset = kValueOffset; | 9747 static const int kPointerFieldsBeginOffset = kValueOffset; |
9744 static const int kPointerFieldsEndOffset = kDependentCodeOffset; | 9748 static const int kPointerFieldsEndOffset = kSize; |
9745 | 9749 |
9746 typedef FixedBodyDescriptor<kValueOffset, | 9750 typedef FixedBodyDescriptor<kValueOffset, |
9747 kSize, | 9751 kSize, |
9748 kSize> BodyDescriptor; | 9752 kSize> BodyDescriptor; |
9749 | 9753 |
9750 private: | 9754 private: |
9751 DECL_ACCESSORS(type_raw, Object) | 9755 DECL_ACCESSORS(type_raw, Object) |
9752 DISALLOW_IMPLICIT_CONSTRUCTORS(PropertyCell); | 9756 DISALLOW_IMPLICIT_CONSTRUCTORS(PropertyCell); |
9753 }; | 9757 }; |
9754 | 9758 |
(...skipping 1213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10968 } else { | 10972 } else { |
10969 value &= ~(1 << bit_position); | 10973 value &= ~(1 << bit_position); |
10970 } | 10974 } |
10971 return value; | 10975 return value; |
10972 } | 10976 } |
10973 }; | 10977 }; |
10974 | 10978 |
10975 } } // namespace v8::internal | 10979 } } // namespace v8::internal |
10976 | 10980 |
10977 #endif // V8_OBJECTS_H_ | 10981 #endif // V8_OBJECTS_H_ |
OLD | NEW |