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_H_ | 5 #ifndef V8_HEAP_H_ |
6 #define V8_HEAP_H_ | 6 #define V8_HEAP_H_ |
7 | 7 |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "src/allocation.h" | 10 #include "src/allocation.h" |
(...skipping 341 matching lines...) Loading... |
352 V(done_string, "done") \ | 352 V(done_string, "done") \ |
353 V(value_string, "value") \ | 353 V(value_string, "value") \ |
354 V(next_string, "next") \ | 354 V(next_string, "next") \ |
355 V(byte_length_string, "byteLength") \ | 355 V(byte_length_string, "byteLength") \ |
356 V(byte_offset_string, "byteOffset") \ | 356 V(byte_offset_string, "byteOffset") \ |
357 V(buffer_string, "buffer") \ | 357 V(buffer_string, "buffer") \ |
358 V(intl_initialized_marker_string, "v8::intl_initialized_marker") \ | 358 V(intl_initialized_marker_string, "v8::intl_initialized_marker") \ |
359 V(intl_impl_object_string, "v8::intl_object") | 359 V(intl_impl_object_string, "v8::intl_object") |
360 | 360 |
361 // Forward declarations. | 361 // Forward declarations. |
362 class GCTracer; | |
363 class HeapStats; | 362 class HeapStats; |
364 class Isolate; | 363 class Isolate; |
365 class WeakObjectRetainer; | 364 class WeakObjectRetainer; |
366 | 365 |
367 | 366 |
368 typedef String* (*ExternalStringTableUpdaterCallback)(Heap* heap, | 367 typedef String* (*ExternalStringTableUpdaterCallback)(Heap* heap, |
369 Object** pointer); | 368 Object** pointer); |
370 | 369 |
371 class StoreBufferRebuilder { | 370 class StoreBufferRebuilder { |
372 public: | 371 public: |
(...skipping 169 matching lines...) Loading... |
542 DISALLOW_COPY_AND_ASSIGN(ExternalStringTable); | 541 DISALLOW_COPY_AND_ASSIGN(ExternalStringTable); |
543 }; | 542 }; |
544 | 543 |
545 | 544 |
546 enum ArrayStorageAllocationMode { | 545 enum ArrayStorageAllocationMode { |
547 DONT_INITIALIZE_ARRAY_ELEMENTS, | 546 DONT_INITIALIZE_ARRAY_ELEMENTS, |
548 INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE | 547 INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE |
549 }; | 548 }; |
550 | 549 |
551 | 550 |
| 551 // GCTracer collects and prints ONE line after each garbage collector |
| 552 // invocation IFF --trace_gc is used. |
| 553 |
| 554 class GCTracer BASE_EMBEDDED { |
| 555 public: |
| 556 class Scope BASE_EMBEDDED { |
| 557 public: |
| 558 enum ScopeId { |
| 559 EXTERNAL, |
| 560 MC_MARK, |
| 561 MC_SWEEP, |
| 562 MC_SWEEP_NEWSPACE, |
| 563 MC_SWEEP_OLDSPACE, |
| 564 MC_SWEEP_CODE, |
| 565 MC_SWEEP_CELL, |
| 566 MC_SWEEP_MAP, |
| 567 MC_EVACUATE_PAGES, |
| 568 MC_UPDATE_NEW_TO_NEW_POINTERS, |
| 569 MC_UPDATE_ROOT_TO_NEW_POINTERS, |
| 570 MC_UPDATE_OLD_TO_NEW_POINTERS, |
| 571 MC_UPDATE_POINTERS_TO_EVACUATED, |
| 572 MC_UPDATE_POINTERS_BETWEEN_EVACUATED, |
| 573 MC_UPDATE_MISC_POINTERS, |
| 574 MC_WEAKCOLLECTION_PROCESS, |
| 575 MC_WEAKCOLLECTION_CLEAR, |
| 576 MC_FLUSH_CODE, |
| 577 NUMBER_OF_SCOPES |
| 578 }; |
| 579 |
| 580 Scope(GCTracer* tracer, ScopeId scope) |
| 581 : tracer_(tracer), |
| 582 scope_(scope) { |
| 583 start_time_ = base::OS::TimeCurrentMillis(); |
| 584 } |
| 585 |
| 586 ~Scope() { |
| 587 ASSERT(scope_ < NUMBER_OF_SCOPES); // scope_ is unsigned. |
| 588 tracer_->scopes_[scope_] += base::OS::TimeCurrentMillis() - start_time_; |
| 589 } |
| 590 |
| 591 private: |
| 592 GCTracer* tracer_; |
| 593 ScopeId scope_; |
| 594 double start_time_; |
| 595 |
| 596 DISALLOW_COPY_AND_ASSIGN(Scope); |
| 597 }; |
| 598 |
| 599 explicit GCTracer(Heap* heap); |
| 600 ~GCTracer(); |
| 601 |
| 602 void start(GarbageCollector collector, |
| 603 const char* gc_reason, |
| 604 const char* collector_reason); |
| 605 |
| 606 void stop(); |
| 607 |
| 608 private: |
| 609 // Returns a string matching the collector. |
| 610 const char* CollectorString() const; |
| 611 |
| 612 // Print one detailed trace line in name=value format. |
| 613 void PrintNVP() const; |
| 614 |
| 615 // Print one trace line. |
| 616 void Print() const; |
| 617 |
| 618 // Timestamp set in the constructor. |
| 619 double start_time_; |
| 620 |
| 621 // Timestamp set in the destructor. |
| 622 double end_time_; |
| 623 |
| 624 // Size of objects in heap set in constructor. |
| 625 intptr_t start_object_size_; |
| 626 |
| 627 // Size of objects in heap set in destructor. |
| 628 intptr_t end_object_size_; |
| 629 |
| 630 // Size of memory allocated from OS set in constructor. |
| 631 intptr_t start_memory_size_; |
| 632 |
| 633 // Size of memory allocated from OS set in destructor. |
| 634 intptr_t end_memory_size_; |
| 635 |
| 636 // Type of collector. |
| 637 GarbageCollector collector_; |
| 638 |
| 639 // Amounts of time spent in different scopes during GC. |
| 640 double scopes_[Scope::NUMBER_OF_SCOPES]; |
| 641 |
| 642 // Total amount of space either wasted or contained in one of free lists |
| 643 // before the current GC. |
| 644 intptr_t in_free_list_or_wasted_before_gc_; |
| 645 |
| 646 // Difference between space used in the heap at the beginning of the current |
| 647 // collection and the end of the previous collection. |
| 648 intptr_t allocated_since_last_gc_; |
| 649 |
| 650 // Amount of time spent in mutator that is time elapsed between end of the |
| 651 // previous collection and the beginning of the current one. |
| 652 double spent_in_mutator_; |
| 653 |
| 654 // Incremental marking steps counters. |
| 655 int steps_count_; |
| 656 double steps_took_; |
| 657 double longest_step_; |
| 658 int steps_count_since_last_gc_; |
| 659 double steps_took_since_last_gc_; |
| 660 |
| 661 Heap* heap_; |
| 662 |
| 663 const char* gc_reason_; |
| 664 const char* collector_reason_; |
| 665 |
| 666 DISALLOW_COPY_AND_ASSIGN(GCTracer); |
| 667 }; |
| 668 |
| 669 |
552 class Heap { | 670 class Heap { |
553 public: | 671 public: |
554 // Configure heap size in MB before setup. Return false if the heap has been | 672 // Configure heap size in MB before setup. Return false if the heap has been |
555 // set up already. | 673 // set up already. |
556 bool ConfigureHeap(int max_semi_space_size, | 674 bool ConfigureHeap(int max_semi_space_size, |
557 int max_old_space_size, | 675 int max_old_space_size, |
558 int max_executable_size, | 676 int max_executable_size, |
559 size_t code_range_size); | 677 size_t code_range_size); |
560 bool ConfigureHeapDefault(); | 678 bool ConfigureHeapDefault(); |
561 | 679 |
(...skipping 661 matching lines...) Loading... |
1223 void VisitExternalResources(v8::ExternalResourceVisitor* visitor); | 1341 void VisitExternalResources(v8::ExternalResourceVisitor* visitor); |
1224 | 1342 |
1225 // An object should be promoted if the object has survived a | 1343 // An object should be promoted if the object has survived a |
1226 // scavenge operation. | 1344 // scavenge operation. |
1227 inline bool ShouldBePromoted(Address old_address, int object_size); | 1345 inline bool ShouldBePromoted(Address old_address, int object_size); |
1228 | 1346 |
1229 void ClearJSFunctionResultCaches(); | 1347 void ClearJSFunctionResultCaches(); |
1230 | 1348 |
1231 void ClearNormalizedMapCaches(); | 1349 void ClearNormalizedMapCaches(); |
1232 | 1350 |
1233 GCTracer* tracer() { return tracer_; } | 1351 GCTracer* tracer() { return &tracer_; } |
1234 | 1352 |
1235 // Returns the size of objects residing in non new spaces. | 1353 // Returns the size of objects residing in non new spaces. |
1236 intptr_t PromotedSpaceSizeOfObjects(); | 1354 intptr_t PromotedSpaceSizeOfObjects(); |
1237 | 1355 |
1238 double total_regexp_code_generated() { return total_regexp_code_generated_; } | 1356 double total_regexp_code_generated() { return total_regexp_code_generated_; } |
1239 void IncreaseTotalRegexpCodeGenerated(int size) { | 1357 void IncreaseTotalRegexpCodeGenerated(int size) { |
1240 total_regexp_code_generated_ += size; | 1358 total_regexp_code_generated_ += size; |
1241 } | 1359 } |
1242 | 1360 |
1243 void IncrementCodeGeneratedBytes(bool is_crankshafted, int size) { | 1361 void IncrementCodeGeneratedBytes(bool is_crankshafted, int size) { |
(...skipping 501 matching lines...) Loading... |
1745 GarbageCollector collector, | 1863 GarbageCollector collector, |
1746 const char* gc_reason, | 1864 const char* gc_reason, |
1747 const char* collector_reason, | 1865 const char* collector_reason, |
1748 const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags); | 1866 const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags); |
1749 | 1867 |
1750 // Performs garbage collection | 1868 // Performs garbage collection |
1751 // Returns whether there is a chance another major GC could | 1869 // Returns whether there is a chance another major GC could |
1752 // collect more garbage. | 1870 // collect more garbage. |
1753 bool PerformGarbageCollection( | 1871 bool PerformGarbageCollection( |
1754 GarbageCollector collector, | 1872 GarbageCollector collector, |
1755 GCTracer* tracer, | |
1756 const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags); | 1873 const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags); |
1757 | 1874 |
1758 inline void UpdateOldSpaceLimits(); | 1875 inline void UpdateOldSpaceLimits(); |
1759 | 1876 |
1760 // Selects the proper allocation space depending on the given object | 1877 // Selects the proper allocation space depending on the given object |
1761 // size, pretenuring decision, and preferred old-space. | 1878 // size, pretenuring decision, and preferred old-space. |
1762 static AllocationSpace SelectSpace(int object_size, | 1879 static AllocationSpace SelectSpace(int object_size, |
1763 AllocationSpace preferred_old_space, | 1880 AllocationSpace preferred_old_space, |
1764 PretenureFlag pretenure) { | 1881 PretenureFlag pretenure) { |
1765 ASSERT(preferred_old_space == OLD_POINTER_SPACE || | 1882 ASSERT(preferred_old_space == OLD_POINTER_SPACE || |
(...skipping 205 matching lines...) Loading... |
1971 static String* UpdateNewSpaceReferenceInExternalStringTableEntry( | 2088 static String* UpdateNewSpaceReferenceInExternalStringTableEntry( |
1972 Heap* heap, | 2089 Heap* heap, |
1973 Object** pointer); | 2090 Object** pointer); |
1974 | 2091 |
1975 Address DoScavenge(ObjectVisitor* scavenge_visitor, Address new_space_front); | 2092 Address DoScavenge(ObjectVisitor* scavenge_visitor, Address new_space_front); |
1976 static void ScavengeStoreBufferCallback(Heap* heap, | 2093 static void ScavengeStoreBufferCallback(Heap* heap, |
1977 MemoryChunk* page, | 2094 MemoryChunk* page, |
1978 StoreBufferEvent event); | 2095 StoreBufferEvent event); |
1979 | 2096 |
1980 // Performs a major collection in the whole heap. | 2097 // Performs a major collection in the whole heap. |
1981 void MarkCompact(GCTracer* tracer); | 2098 void MarkCompact(); |
1982 | 2099 |
1983 // Code to be run before and after mark-compact. | 2100 // Code to be run before and after mark-compact. |
1984 void MarkCompactPrologue(); | 2101 void MarkCompactPrologue(); |
1985 | 2102 |
1986 void ProcessNativeContexts(WeakObjectRetainer* retainer); | 2103 void ProcessNativeContexts(WeakObjectRetainer* retainer); |
1987 void ProcessArrayBuffers(WeakObjectRetainer* retainer); | 2104 void ProcessArrayBuffers(WeakObjectRetainer* retainer); |
1988 void ProcessAllocationSites(WeakObjectRetainer* retainer); | 2105 void ProcessAllocationSites(WeakObjectRetainer* retainer); |
1989 | 2106 |
1990 // Deopts all code that contains allocation instruction which are tenured or | 2107 // Deopts all code that contains allocation instruction which are tenured or |
1991 // not tenured. Moreover it clears the pretenuring allocation site statistics. | 2108 // not tenured. Moreover it clears the pretenuring allocation site statistics. |
(...skipping 10 matching lines...) Loading... |
2002 // Record statistics before and after garbage collection. | 2119 // Record statistics before and after garbage collection. |
2003 void ReportStatisticsBeforeGC(); | 2120 void ReportStatisticsBeforeGC(); |
2004 void ReportStatisticsAfterGC(); | 2121 void ReportStatisticsAfterGC(); |
2005 | 2122 |
2006 // Slow part of scavenge object. | 2123 // Slow part of scavenge object. |
2007 static void ScavengeObjectSlow(HeapObject** p, HeapObject* object); | 2124 static void ScavengeObjectSlow(HeapObject** p, HeapObject* object); |
2008 | 2125 |
2009 // Total RegExp code ever generated | 2126 // Total RegExp code ever generated |
2010 double total_regexp_code_generated_; | 2127 double total_regexp_code_generated_; |
2011 | 2128 |
2012 GCTracer* tracer_; | 2129 GCTracer tracer_; |
2013 | 2130 |
2014 // Creates and installs the full-sized number string cache. | 2131 // Creates and installs the full-sized number string cache. |
2015 int FullSizeNumberStringCacheLength(); | 2132 int FullSizeNumberStringCacheLength(); |
2016 // Flush the number to string cache. | 2133 // Flush the number to string cache. |
2017 void FlushNumberStringCache(); | 2134 void FlushNumberStringCache(); |
2018 | 2135 |
2019 // Sets used allocation sites entries to undefined. | 2136 // Sets used allocation sites entries to undefined. |
2020 void FlushAllocationSitesScratchpad(); | 2137 void FlushAllocationSitesScratchpad(); |
2021 | 2138 |
2022 // Initializes the allocation sites scratchpad with undefined values. | 2139 // Initializes the allocation sites scratchpad with undefined values. |
(...skipping 500 matching lines...) Loading... |
2523 }; | 2640 }; |
2524 | 2641 |
2525 Key keys_[kLength]; | 2642 Key keys_[kLength]; |
2526 int results_[kLength]; | 2643 int results_[kLength]; |
2527 | 2644 |
2528 friend class Isolate; | 2645 friend class Isolate; |
2529 DISALLOW_COPY_AND_ASSIGN(DescriptorLookupCache); | 2646 DISALLOW_COPY_AND_ASSIGN(DescriptorLookupCache); |
2530 }; | 2647 }; |
2531 | 2648 |
2532 | 2649 |
2533 // GCTracer collects and prints ONE line after each garbage collector | |
2534 // invocation IFF --trace_gc is used. | |
2535 | |
2536 class GCTracer BASE_EMBEDDED { | |
2537 public: | |
2538 class Scope BASE_EMBEDDED { | |
2539 public: | |
2540 enum ScopeId { | |
2541 EXTERNAL, | |
2542 MC_MARK, | |
2543 MC_SWEEP, | |
2544 MC_SWEEP_NEWSPACE, | |
2545 MC_SWEEP_OLDSPACE, | |
2546 MC_SWEEP_CODE, | |
2547 MC_SWEEP_CELL, | |
2548 MC_SWEEP_MAP, | |
2549 MC_EVACUATE_PAGES, | |
2550 MC_UPDATE_NEW_TO_NEW_POINTERS, | |
2551 MC_UPDATE_ROOT_TO_NEW_POINTERS, | |
2552 MC_UPDATE_OLD_TO_NEW_POINTERS, | |
2553 MC_UPDATE_POINTERS_TO_EVACUATED, | |
2554 MC_UPDATE_POINTERS_BETWEEN_EVACUATED, | |
2555 MC_UPDATE_MISC_POINTERS, | |
2556 MC_WEAKCOLLECTION_PROCESS, | |
2557 MC_WEAKCOLLECTION_CLEAR, | |
2558 MC_FLUSH_CODE, | |
2559 NUMBER_OF_SCOPES | |
2560 }; | |
2561 | |
2562 Scope(GCTracer* tracer, ScopeId scope) | |
2563 : tracer_(tracer), | |
2564 scope_(scope) { | |
2565 start_time_ = base::OS::TimeCurrentMillis(); | |
2566 } | |
2567 | |
2568 ~Scope() { | |
2569 ASSERT(scope_ < NUMBER_OF_SCOPES); // scope_ is unsigned. | |
2570 tracer_->scopes_[scope_] += base::OS::TimeCurrentMillis() - start_time_; | |
2571 } | |
2572 | |
2573 private: | |
2574 GCTracer* tracer_; | |
2575 ScopeId scope_; | |
2576 double start_time_; | |
2577 | |
2578 DISALLOW_COPY_AND_ASSIGN(Scope); | |
2579 }; | |
2580 | |
2581 explicit GCTracer(Heap* heap, | |
2582 GarbageCollector collector, | |
2583 const char* gc_reason, | |
2584 const char* collector_reason); | |
2585 ~GCTracer(); | |
2586 | |
2587 private: | |
2588 // Returns a string matching the collector. | |
2589 const char* CollectorString() const; | |
2590 | |
2591 // Print one detailed trace line in name=value format. | |
2592 void PrintNVP() const; | |
2593 | |
2594 // Print one trace line. | |
2595 void Print() const; | |
2596 | |
2597 // Timestamp set in the constructor. | |
2598 double start_time_; | |
2599 | |
2600 // Timestamp set in the destructor. | |
2601 double end_time_; | |
2602 | |
2603 // Size of objects in heap set in constructor. | |
2604 intptr_t start_object_size_; | |
2605 | |
2606 // Size of objects in heap set in destructor. | |
2607 intptr_t end_object_size_; | |
2608 | |
2609 // Size of memory allocated from OS set in constructor. | |
2610 intptr_t start_memory_size_; | |
2611 | |
2612 // Size of memory allocated from OS set in destructor. | |
2613 intptr_t end_memory_size_; | |
2614 | |
2615 // Type of collector. | |
2616 GarbageCollector collector_; | |
2617 | |
2618 // Amounts of time spent in different scopes during GC. | |
2619 double scopes_[Scope::NUMBER_OF_SCOPES]; | |
2620 | |
2621 // Total amount of space either wasted or contained in one of free lists | |
2622 // before the current GC. | |
2623 intptr_t in_free_list_or_wasted_before_gc_; | |
2624 | |
2625 // Difference between space used in the heap at the beginning of the current | |
2626 // collection and the end of the previous collection. | |
2627 intptr_t allocated_since_last_gc_; | |
2628 | |
2629 // Amount of time spent in mutator that is time elapsed between end of the | |
2630 // previous collection and the beginning of the current one. | |
2631 double spent_in_mutator_; | |
2632 | |
2633 // Incremental marking steps counters. | |
2634 int steps_count_; | |
2635 double steps_took_; | |
2636 double longest_step_; | |
2637 int steps_count_since_last_gc_; | |
2638 double steps_took_since_last_gc_; | |
2639 | |
2640 Heap* heap_; | |
2641 | |
2642 const char* gc_reason_; | |
2643 const char* collector_reason_; | |
2644 | |
2645 DISALLOW_COPY_AND_ASSIGN(GCTracer); | |
2646 }; | |
2647 | |
2648 | |
2649 class RegExpResultsCache { | 2650 class RegExpResultsCache { |
2650 public: | 2651 public: |
2651 enum ResultsCacheType { REGEXP_MULTIPLE_INDICES, STRING_SPLIT_SUBSTRINGS }; | 2652 enum ResultsCacheType { REGEXP_MULTIPLE_INDICES, STRING_SPLIT_SUBSTRINGS }; |
2652 | 2653 |
2653 // Attempt to retrieve a cached result. On failure, 0 is returned as a Smi. | 2654 // Attempt to retrieve a cached result. On failure, 0 is returned as a Smi. |
2654 // On success, the returned result is guaranteed to be a COW-array. | 2655 // On success, the returned result is guaranteed to be a COW-array. |
2655 static Object* Lookup(Heap* heap, | 2656 static Object* Lookup(Heap* heap, |
2656 String* key_string, | 2657 String* key_string, |
2657 Object* key_pattern, | 2658 Object* key_pattern, |
2658 ResultsCacheType type); | 2659 ResultsCacheType type); |
(...skipping 122 matching lines...) Loading... |
2781 DisallowHeapAllocation no_allocation; // i.e. no gc allowed. | 2782 DisallowHeapAllocation no_allocation; // i.e. no gc allowed. |
2782 | 2783 |
2783 private: | 2784 private: |
2784 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); | 2785 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); |
2785 }; | 2786 }; |
2786 #endif // DEBUG | 2787 #endif // DEBUG |
2787 | 2788 |
2788 } } // namespace v8::internal | 2789 } } // namespace v8::internal |
2789 | 2790 |
2790 #endif // V8_HEAP_H_ | 2791 #endif // V8_HEAP_H_ |
OLD | NEW |