Chromium Code Reviews| 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_HEAP_HEAP_H_ | 5 #ifndef V8_HEAP_HEAP_H_ |
| 6 #define V8_HEAP_HEAP_H_ | 6 #define V8_HEAP_HEAP_H_ |
| 7 | 7 |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 415 V(BooleanMap) \ | 415 V(BooleanMap) \ |
| 416 V(UninitializedMap) \ | 416 V(UninitializedMap) \ |
| 417 V(ArgumentsMarkerMap) \ | 417 V(ArgumentsMarkerMap) \ |
| 418 V(JSMessageObjectMap) \ | 418 V(JSMessageObjectMap) \ |
| 419 V(ForeignMap) \ | 419 V(ForeignMap) \ |
| 420 V(NeanderMap) \ | 420 V(NeanderMap) \ |
| 421 V(empty_string) \ | 421 V(empty_string) \ |
| 422 PRIVATE_SYMBOL_LIST(V) | 422 PRIVATE_SYMBOL_LIST(V) |
| 423 | 423 |
| 424 // Forward declarations. | 424 // Forward declarations. |
| 425 class HeapObjectsFilter; | |
| 425 class HeapStats; | 426 class HeapStats; |
| 426 class Isolate; | 427 class Isolate; |
| 427 class MemoryReducer; | 428 class MemoryReducer; |
| 428 class WeakObjectRetainer; | 429 class WeakObjectRetainer; |
| 429 | 430 |
| 430 | 431 |
| 431 typedef String* (*ExternalStringTableUpdaterCallback)(Heap* heap, | |
| 432 Object** pointer); | |
| 433 | |
| 434 | |
| 435 // A queue of objects promoted during scavenge. Each object is accompanied | 432 // A queue of objects promoted during scavenge. Each object is accompanied |
| 436 // by it's size to avoid dereferencing a map pointer for scanning. | 433 // by it's size to avoid dereferencing a map pointer for scanning. |
| 437 // The last page in to-space is used for the promotion queue. On conflict | 434 // The last page in to-space is used for the promotion queue. On conflict |
| 438 // during scavenge, the promotion queue is allocated externally and all | 435 // during scavenge, the promotion queue is allocated externally and all |
| 439 // entries are copied to the external queue. | 436 // entries are copied to the external queue. |
| 440 class PromotionQueue { | 437 class PromotionQueue { |
| 441 public: | 438 public: |
| 442 explicit PromotionQueue(Heap* heap) | 439 explicit PromotionQueue(Heap* heap) |
| 443 : front_(NULL), | 440 : front_(NULL), |
| 444 rear_(NULL), | 441 rear_(NULL), |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 534 void RelocateQueueHead(); | 531 void RelocateQueueHead(); |
| 535 | 532 |
| 536 DISALLOW_COPY_AND_ASSIGN(PromotionQueue); | 533 DISALLOW_COPY_AND_ASSIGN(PromotionQueue); |
| 537 }; | 534 }; |
| 538 | 535 |
| 539 | 536 |
| 540 typedef void (*ScavengingCallback)(Map* map, HeapObject** slot, | 537 typedef void (*ScavengingCallback)(Map* map, HeapObject** slot, |
| 541 HeapObject* object); | 538 HeapObject* object); |
| 542 | 539 |
| 543 | 540 |
| 544 // External strings table is a place where all external strings are | |
| 545 // registered. We need to keep track of such strings to properly | |
| 546 // finalize them. | |
| 547 class ExternalStringTable { | |
| 548 public: | |
| 549 // Registers an external string. | |
| 550 inline void AddString(String* string); | |
| 551 | |
| 552 inline void Iterate(ObjectVisitor* v); | |
| 553 | |
| 554 // Restores internal invariant and gets rid of collected strings. | |
| 555 // Must be called after each Iterate() that modified the strings. | |
| 556 void CleanUp(); | |
| 557 | |
| 558 // Destroys all allocated memory. | |
| 559 void TearDown(); | |
| 560 | |
| 561 private: | |
| 562 explicit ExternalStringTable(Heap* heap) : heap_(heap) {} | |
| 563 | |
| 564 friend class Heap; | |
| 565 | |
| 566 inline void Verify(); | |
| 567 | |
| 568 inline void AddOldString(String* string); | |
| 569 | |
| 570 // Notifies the table that only a prefix of the new list is valid. | |
| 571 inline void ShrinkNewStrings(int position); | |
| 572 | |
| 573 // To speed up scavenge collections new space string are kept | |
| 574 // separate from old space strings. | |
| 575 List<Object*> new_space_strings_; | |
| 576 List<Object*> old_space_strings_; | |
| 577 | |
| 578 Heap* heap_; | |
| 579 | |
| 580 DISALLOW_COPY_AND_ASSIGN(ExternalStringTable); | |
| 581 }; | |
| 582 | |
| 583 | |
| 584 enum ArrayStorageAllocationMode { | 541 enum ArrayStorageAllocationMode { |
| 585 DONT_INITIALIZE_ARRAY_ELEMENTS, | 542 DONT_INITIALIZE_ARRAY_ELEMENTS, |
| 586 INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE | 543 INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE |
| 587 }; | 544 }; |
| 588 | 545 |
| 589 | 546 |
| 590 class Heap { | 547 class Heap { |
| 591 public: | 548 public: |
| 592 // Declare all the root indices. This defines the root list order. | 549 // Declare all the root indices. This defines the root list order. |
| 593 enum RootListIndex { | 550 enum RootListIndex { |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 863 // Iterates the whole code space to clear all ICs of the given kind. | 820 // Iterates the whole code space to clear all ICs of the given kind. |
| 864 void ClearAllICsByKind(Code::Kind kind); | 821 void ClearAllICsByKind(Code::Kind kind); |
| 865 | 822 |
| 866 // FreeSpace objects have a null map after deserialization. Update the map. | 823 // FreeSpace objects have a null map after deserialization. Update the map. |
| 867 void RepairFreeListsAfterDeserialization(); | 824 void RepairFreeListsAfterDeserialization(); |
| 868 | 825 |
| 869 // Move len elements within a given array from src_index index to dst_index | 826 // Move len elements within a given array from src_index index to dst_index |
| 870 // index. | 827 // index. |
| 871 void MoveElements(FixedArray* array, int dst_index, int src_index, int len); | 828 void MoveElements(FixedArray* array, int dst_index, int src_index, int len); |
| 872 | 829 |
| 873 // Finalizes an external string by deleting the associated external | |
| 874 // data and clearing the resource pointer. | |
| 875 inline void FinalizeExternalString(String* string); | |
| 876 | |
| 877 // Initialize a filler object to keep the ability to iterate over the heap | 830 // Initialize a filler object to keep the ability to iterate over the heap |
| 878 // when introducing gaps within pages. | 831 // when introducing gaps within pages. |
| 879 void CreateFillerObjectAt(Address addr, int size); | 832 void CreateFillerObjectAt(Address addr, int size); |
| 880 | 833 |
| 881 bool CanMoveObjectStart(HeapObject* object); | 834 bool CanMoveObjectStart(HeapObject* object); |
| 882 | 835 |
| 883 // Maintain consistency of live bytes during incremental marking. | 836 // Maintain consistency of live bytes during incremental marking. |
| 884 void AdjustLiveBytes(HeapObject* object, int by, InvocationMode mode); | 837 void AdjustLiveBytes(HeapObject* object, int by, InvocationMode mode); |
| 885 | 838 |
| 886 // Trim the given array from the left. Note that this relocates the object | 839 // Trim the given array from the left. Note that this relocates the object |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1213 GCTracer* tracer() { return tracer_; } | 1166 GCTracer* tracer() { return tracer_; } |
| 1214 | 1167 |
| 1215 PromotionQueue* promotion_queue() { return &promotion_queue_; } | 1168 PromotionQueue* promotion_queue() { return &promotion_queue_; } |
| 1216 | 1169 |
| 1217 inline Isolate* isolate(); | 1170 inline Isolate* isolate(); |
| 1218 | 1171 |
| 1219 MarkCompactCollector* mark_compact_collector() { | 1172 MarkCompactCollector* mark_compact_collector() { |
| 1220 return &mark_compact_collector_; | 1173 return &mark_compact_collector_; |
| 1221 } | 1174 } |
| 1222 | 1175 |
| 1223 ExternalStringTable* external_string_table() { | |
| 1224 return &external_string_table_; | |
| 1225 } | |
| 1226 | |
| 1227 // =========================================================================== | 1176 // =========================================================================== |
| 1228 // Root set access. ========================================================== | 1177 // Root set access. ========================================================== |
| 1229 // =========================================================================== | 1178 // =========================================================================== |
| 1230 | 1179 |
| 1231 // Heap root getters. We have versions with and without type::cast() here. | 1180 // Heap root getters. We have versions with and without type::cast() here. |
| 1232 // You can't use type::cast during GC because the assert fails. | 1181 // You can't use type::cast during GC because the assert fails. |
| 1233 // TODO(1490): Try removing the unchecked accessors, now that GC marking does | 1182 // TODO(1490): Try removing the unchecked accessors, now that GC marking does |
| 1234 // not corrupt the map. | 1183 // not corrupt the map. |
| 1235 #define ROOT_ACCESSOR(type, name, camel_name) \ | 1184 #define ROOT_ACCESSOR(type, name, camel_name) \ |
| 1236 inline type* name(); \ | 1185 inline type* name(); \ |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1386 // an estimate increment. Returns the remaining time that cannot be used | 1335 // an estimate increment. Returns the remaining time that cannot be used |
| 1387 // for incremental marking anymore because a single step would exceed the | 1336 // for incremental marking anymore because a single step would exceed the |
| 1388 // deadline. | 1337 // deadline. |
| 1389 double AdvanceIncrementalMarking( | 1338 double AdvanceIncrementalMarking( |
| 1390 intptr_t step_size_in_bytes, double deadline_in_ms, | 1339 intptr_t step_size_in_bytes, double deadline_in_ms, |
| 1391 IncrementalMarking::StepActions step_actions); | 1340 IncrementalMarking::StepActions step_actions); |
| 1392 | 1341 |
| 1393 IncrementalMarking* incremental_marking() { return &incremental_marking_; } | 1342 IncrementalMarking* incremental_marking() { return &incremental_marking_; } |
| 1394 | 1343 |
| 1395 // =========================================================================== | 1344 // =========================================================================== |
| 1345 // External string table API. ================================================ | |
| 1346 // =========================================================================== | |
| 1347 | |
| 1348 // Registers an external string. | |
| 1349 inline void AddExternalString(String* string); | |
|
Michael Starzinger
2015/08/25 14:18:30
Wasn't sure whether "AddExternalString" or "Regist
Michael Lippautz
2015/08/25 17:23:37
We already have a couple of Register*() methods. L
Michael Starzinger
2015/08/26 08:39:57
Done.
| |
| 1350 | |
| 1351 // Finalizes an external string by deleting the associated external | |
| 1352 // data and clearing the resource pointer. | |
| 1353 inline void FinalizeExternalString(String* string); | |
| 1354 | |
| 1355 // =========================================================================== | |
| 1396 // Methods checking/returning the space of a given object/address. =========== | 1356 // Methods checking/returning the space of a given object/address. =========== |
| 1397 // =========================================================================== | 1357 // =========================================================================== |
| 1398 | 1358 |
| 1399 // Returns whether the object resides in new space. | 1359 // Returns whether the object resides in new space. |
| 1400 inline bool InNewSpace(Object* object); | 1360 inline bool InNewSpace(Object* object); |
| 1401 inline bool InNewSpace(Address address); | 1361 inline bool InNewSpace(Address address); |
| 1402 inline bool InNewSpacePage(Address address); | 1362 inline bool InNewSpacePage(Address address); |
| 1403 inline bool InFromSpace(Object* object); | 1363 inline bool InFromSpace(Object* object); |
| 1404 inline bool InToSpace(Object* object); | 1364 inline bool InToSpace(Object* object); |
| 1405 | 1365 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1606 void PrintHandles(); | 1566 void PrintHandles(); |
| 1607 | 1567 |
| 1608 // Report heap statistics. | 1568 // Report heap statistics. |
| 1609 void ReportHeapStatistics(const char* title); | 1569 void ReportHeapStatistics(const char* title); |
| 1610 void ReportCodeStatistics(const char* title); | 1570 void ReportCodeStatistics(const char* title); |
| 1611 #endif | 1571 #endif |
| 1612 | 1572 |
| 1613 private: | 1573 private: |
| 1614 class UnmapFreeMemoryTask; | 1574 class UnmapFreeMemoryTask; |
| 1615 | 1575 |
| 1576 // External strings table is a place where all external strings are | |
| 1577 // registered. We need to keep track of such strings to properly | |
| 1578 // finalize them. | |
| 1579 class ExternalStringTable { | |
| 1580 public: | |
| 1581 // Registers an external string. | |
| 1582 inline void AddString(String* string); | |
| 1583 | |
| 1584 inline void Iterate(ObjectVisitor* v); | |
| 1585 | |
| 1586 // Restores internal invariant and gets rid of collected strings. | |
| 1587 // Must be called after each Iterate() that modified the strings. | |
| 1588 void CleanUp(); | |
| 1589 | |
| 1590 // Destroys all allocated memory. | |
| 1591 void TearDown(); | |
| 1592 | |
| 1593 private: | |
| 1594 explicit ExternalStringTable(Heap* heap) : heap_(heap) {} | |
| 1595 | |
| 1596 friend class Heap; | |
|
Michael Lippautz
2015/08/25 17:23:37
Move to bottom.
Michael Starzinger
2015/08/26 08:39:57
Done.
| |
| 1597 | |
| 1598 inline void Verify(); | |
| 1599 | |
| 1600 inline void AddOldString(String* string); | |
| 1601 | |
| 1602 // Notifies the table that only a prefix of the new list is valid. | |
| 1603 inline void ShrinkNewStrings(int position); | |
| 1604 | |
| 1605 // To speed up scavenge collections new space string are kept | |
| 1606 // separate from old space strings. | |
| 1607 List<Object*> new_space_strings_; | |
| 1608 List<Object*> old_space_strings_; | |
| 1609 | |
| 1610 Heap* heap_; | |
| 1611 | |
| 1612 DISALLOW_COPY_AND_ASSIGN(ExternalStringTable); | |
| 1613 }; | |
| 1614 | |
| 1616 struct StrongRootsList; | 1615 struct StrongRootsList; |
| 1617 | 1616 |
| 1618 struct StringTypeTable { | 1617 struct StringTypeTable { |
| 1619 InstanceType type; | 1618 InstanceType type; |
| 1620 int size; | 1619 int size; |
| 1621 RootListIndex index; | 1620 RootListIndex index; |
| 1622 }; | 1621 }; |
| 1623 | 1622 |
| 1624 struct ConstantStringTable { | 1623 struct ConstantStringTable { |
| 1625 const char* contents; | 1624 const char* contents; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1639 | 1638 |
| 1640 bool operator==(const GCCallbackPair& other) const { | 1639 bool operator==(const GCCallbackPair& other) const { |
| 1641 return other.callback == callback; | 1640 return other.callback == callback; |
| 1642 } | 1641 } |
| 1643 | 1642 |
| 1644 v8::Isolate::GCCallback callback; | 1643 v8::Isolate::GCCallback callback; |
| 1645 GCType gc_type; | 1644 GCType gc_type; |
| 1646 bool pass_isolate; | 1645 bool pass_isolate; |
| 1647 }; | 1646 }; |
| 1648 | 1647 |
| 1648 typedef String* (*ExternalStringTableUpdaterCallback)(Heap* heap, | |
| 1649 Object** pointer); | |
| 1650 | |
| 1649 static const int kInitialStringTableSize = 2048; | 1651 static const int kInitialStringTableSize = 2048; |
| 1650 static const int kInitialEvalCacheSize = 64; | 1652 static const int kInitialEvalCacheSize = 64; |
| 1651 static const int kInitialNumberStringCacheSize = 256; | 1653 static const int kInitialNumberStringCacheSize = 256; |
| 1652 | 1654 |
| 1653 static const int kRememberedUnmappedPages = 128; | 1655 static const int kRememberedUnmappedPages = 128; |
| 1654 | 1656 |
| 1655 static const StringTypeTable string_type_table[]; | 1657 static const StringTypeTable string_type_table[]; |
| 1656 static const ConstantStringTable constant_string_table[]; | 1658 static const ConstantStringTable constant_string_table[]; |
| 1657 static const StructTable struct_table[]; | 1659 static const StructTable struct_table[]; |
| 1658 | 1660 |
| (...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2562 // these can only iterate over one space only. | 2564 // these can only iterate over one space only. |
| 2563 // | 2565 // |
| 2564 // HeapIterator ensures there is no allocation during its lifetime | 2566 // HeapIterator ensures there is no allocation during its lifetime |
| 2565 // (using an embedded DisallowHeapAllocation instance). | 2567 // (using an embedded DisallowHeapAllocation instance). |
| 2566 // | 2568 // |
| 2567 // HeapIterator can skip free list nodes (that is, de-allocated heap | 2569 // HeapIterator can skip free list nodes (that is, de-allocated heap |
| 2568 // objects that still remain in the heap). As implementation of free | 2570 // objects that still remain in the heap). As implementation of free |
| 2569 // nodes filtering uses GC marks, it can't be used during MS/MC GC | 2571 // nodes filtering uses GC marks, it can't be used during MS/MC GC |
| 2570 // phases. Also, it is forbidden to interrupt iteration in this mode, | 2572 // phases. Also, it is forbidden to interrupt iteration in this mode, |
| 2571 // as this will leave heap objects marked (and thus, unusable). | 2573 // as this will leave heap objects marked (and thus, unusable). |
| 2572 class HeapObjectsFilter; | |
| 2573 | |
| 2574 class HeapIterator BASE_EMBEDDED { | 2574 class HeapIterator BASE_EMBEDDED { |
| 2575 public: | 2575 public: |
| 2576 enum HeapObjectsFiltering { kNoFiltering, kFilterUnreachable }; | 2576 enum HeapObjectsFiltering { kNoFiltering, kFilterUnreachable }; |
| 2577 | 2577 |
| 2578 explicit HeapIterator(Heap* heap); | 2578 explicit HeapIterator(Heap* heap); |
| 2579 HeapIterator(Heap* heap, HeapObjectsFiltering filtering); | 2579 HeapIterator(Heap* heap, HeapObjectsFiltering filtering); |
| 2580 ~HeapIterator(); | 2580 ~HeapIterator(); |
| 2581 | 2581 |
| 2582 HeapObject* next(); | 2582 HeapObject* next(); |
| 2583 void reset(); | 2583 void reset(); |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2783 DisallowHeapAllocation no_allocation; // i.e. no gc allowed. | 2783 DisallowHeapAllocation no_allocation; // i.e. no gc allowed. |
| 2784 | 2784 |
| 2785 private: | 2785 private: |
| 2786 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); | 2786 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); |
| 2787 }; | 2787 }; |
| 2788 #endif // DEBUG | 2788 #endif // DEBUG |
| 2789 } | 2789 } |
| 2790 } // namespace v8::internal | 2790 } // namespace v8::internal |
| 2791 | 2791 |
| 2792 #endif // V8_HEAP_HEAP_H_ | 2792 #endif // V8_HEAP_HEAP_H_ |
| OLD | NEW |