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 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
542 DISALLOW_COPY_AND_ASSIGN(ExternalStringTable); | 542 DISALLOW_COPY_AND_ASSIGN(ExternalStringTable); |
543 }; | 543 }; |
544 | 544 |
545 | 545 |
546 enum ArrayStorageAllocationMode { | 546 enum ArrayStorageAllocationMode { |
547 DONT_INITIALIZE_ARRAY_ELEMENTS, | 547 DONT_INITIALIZE_ARRAY_ELEMENTS, |
548 INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE | 548 INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE |
549 }; | 549 }; |
550 | 550 |
551 | 551 |
552 // GCTracer collects and prints ONE line after each garbage collector | |
553 // invocation IFF --trace_gc is used. | |
554 | |
555 class GCTracer BASE_EMBEDDED { | |
556 public: | |
557 class Scope BASE_EMBEDDED { | |
558 public: | |
559 enum ScopeId { | |
560 EXTERNAL, | |
561 MC_MARK, | |
562 MC_SWEEP, | |
563 MC_SWEEP_NEWSPACE, | |
564 MC_SWEEP_OLDSPACE, | |
565 MC_SWEEP_CODE, | |
566 MC_SWEEP_CELL, | |
567 MC_SWEEP_MAP, | |
568 MC_EVACUATE_PAGES, | |
569 MC_UPDATE_NEW_TO_NEW_POINTERS, | |
570 MC_UPDATE_ROOT_TO_NEW_POINTERS, | |
571 MC_UPDATE_OLD_TO_NEW_POINTERS, | |
572 MC_UPDATE_POINTERS_TO_EVACUATED, | |
573 MC_UPDATE_POINTERS_BETWEEN_EVACUATED, | |
574 MC_UPDATE_MISC_POINTERS, | |
575 MC_WEAKCOLLECTION_PROCESS, | |
576 MC_WEAKCOLLECTION_CLEAR, | |
577 MC_FLUSH_CODE, | |
578 kNumberOfScopes | |
jochen (gone - plz use gerrit)
2014/07/14 11:55:32
it's a bit odd to mix MACRO_STYLE and kStyle in th
| |
579 }; | |
580 | |
581 Scope(GCTracer* tracer, ScopeId scope) | |
582 : tracer_(tracer), | |
583 scope_(scope) { | |
584 start_time_ = base::OS::TimeCurrentMillis(); | |
585 } | |
586 | |
587 ~Scope() { | |
588 ASSERT(scope_ < kNumberOfScopes); // scope_ is unsigned. | |
589 tracer_->scopes_[scope_] += base::OS::TimeCurrentMillis() - start_time_; | |
590 } | |
591 | |
592 private: | |
593 GCTracer* tracer_; | |
594 ScopeId scope_; | |
595 double start_time_; | |
596 }; | |
jochen (gone - plz use gerrit)
2014/07/14 11:55:32
DISALLOW_COPY_AND_ASSIGN()
| |
597 | |
598 explicit GCTracer(Heap* heap); | |
599 ~GCTracer(); | |
600 | |
601 void start(const char* gc_reason, const char* collector_reason); | |
602 void stop(); | |
603 | |
604 // Sets the collector. | |
605 void set_collector(GarbageCollector collector) { collector_ = collector; } | |
606 | |
607 // Sets the GC count. | |
608 void set_gc_count(unsigned int count) { gc_count_ = count; } | |
609 | |
610 // Sets the full GC count. | |
611 void set_full_gc_count(int count) { full_gc_count_ = count; } | |
612 | |
613 void increment_nodes_died_in_new_space() { | |
614 nodes_died_in_new_space_++; | |
615 } | |
616 | |
617 void increment_nodes_copied_in_new_space() { | |
618 nodes_copied_in_new_space_++; | |
619 } | |
620 | |
621 void increment_nodes_promoted() { | |
622 nodes_promoted_++; | |
623 } | |
624 | |
625 int steps_count() { return steps_count_; } | |
626 | |
627 void add_step(double duration) { | |
628 steps_count_++; | |
629 steps_count_since_last_gc_++; | |
630 steps_took_ += duration; | |
631 steps_took_since_last_gc_ += duration; | |
632 longest_step_ = Max(longest_step_, duration); | |
633 } | |
634 | |
635 void reset_step_counters(bool reset_all_counters) { | |
636 if (reset_all_counters) { | |
637 steps_count_ = 0; | |
638 steps_took_ = 0.0; | |
639 } | |
640 steps_count_since_last_gc_ = 0; | |
641 steps_took_since_last_gc_ = 0.0; | |
642 longest_step_ = 0.0; | |
643 } | |
644 | |
645 private: | |
646 // Returns a string matching the collector. | |
647 const char* CollectorString(); | |
648 | |
649 // Returns size of object in heap (in MB). | |
650 inline double SizeOfHeapObjects(); | |
651 | |
652 // Timestamp set in the constructor. | |
653 double start_time_; | |
654 | |
655 // Size of objects in heap set in constructor. | |
656 intptr_t start_object_size_; | |
657 | |
658 // Size of memory allocated from OS set in constructor. | |
659 intptr_t start_memory_size_; | |
660 | |
661 // Type of collector. | |
662 GarbageCollector collector_; | |
663 | |
664 // A count (including this one, e.g. the first collection is 1) of the | |
665 // number of garbage collections. | |
666 unsigned int gc_count_; | |
667 | |
668 // A count (including this one) of the number of full garbage collections. | |
669 int full_gc_count_; | |
670 | |
671 // Amounts of time spent in different scopes during GC. | |
672 double scopes_[Scope::kNumberOfScopes]; | |
673 | |
674 // Total amount of space either wasted or contained in one of free lists | |
675 // before the current GC. | |
676 intptr_t in_free_list_or_wasted_before_gc_; | |
677 | |
678 // Difference between space used in the heap at the beginning of the current | |
679 // collection and the end of the previous collection. | |
680 intptr_t allocated_since_last_gc_; | |
681 | |
682 // Amount of time spent in mutator that is time elapsed between end of the | |
683 // previous collection and the beginning of the current one. | |
684 double spent_in_mutator_; | |
685 | |
686 // Number of died nodes in the new space. | |
687 int nodes_died_in_new_space_; | |
688 | |
689 // Number of copied nodes to the new space. | |
690 int nodes_copied_in_new_space_; | |
691 | |
692 // Number of promoted nodes to the old space. | |
693 int nodes_promoted_; | |
694 | |
695 // Incremental marking steps counters. | |
696 int steps_count_; | |
697 double steps_took_; | |
698 double longest_step_; | |
699 int steps_count_since_last_gc_; | |
700 double steps_took_since_last_gc_; | |
701 | |
702 Heap* heap_; | |
703 | |
704 const char* gc_reason_; | |
705 const char* collector_reason_; | |
706 }; | |
jochen (gone - plz use gerrit)
2014/07/14 11:55:33
disallopw copy/assign
| |
707 | |
708 | |
552 class Heap { | 709 class Heap { |
553 public: | 710 public: |
554 // Configure heap size in MB before setup. Return false if the heap has been | 711 // Configure heap size in MB before setup. Return false if the heap has been |
555 // set up already. | 712 // set up already. |
556 bool ConfigureHeap(int max_semi_space_size, | 713 bool ConfigureHeap(int max_semi_space_size, |
557 int max_old_space_size, | 714 int max_old_space_size, |
558 int max_executable_size, | 715 int max_executable_size, |
559 size_t code_range_size); | 716 size_t code_range_size); |
560 bool ConfigureHeapDefault(); | 717 bool ConfigureHeapDefault(); |
561 | 718 |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1211 void VisitExternalResources(v8::ExternalResourceVisitor* visitor); | 1368 void VisitExternalResources(v8::ExternalResourceVisitor* visitor); |
1212 | 1369 |
1213 // An object should be promoted if the object has survived a | 1370 // An object should be promoted if the object has survived a |
1214 // scavenge operation. | 1371 // scavenge operation. |
1215 inline bool ShouldBePromoted(Address old_address, int object_size); | 1372 inline bool ShouldBePromoted(Address old_address, int object_size); |
1216 | 1373 |
1217 void ClearJSFunctionResultCaches(); | 1374 void ClearJSFunctionResultCaches(); |
1218 | 1375 |
1219 void ClearNormalizedMapCaches(); | 1376 void ClearNormalizedMapCaches(); |
1220 | 1377 |
1221 GCTracer* tracer() { return tracer_; } | 1378 GCTracer* tracer() { return &tracer_; } |
1222 | 1379 |
1223 // Returns the size of objects residing in non new spaces. | 1380 // Returns the size of objects residing in non new spaces. |
1224 intptr_t PromotedSpaceSizeOfObjects(); | 1381 intptr_t PromotedSpaceSizeOfObjects(); |
1225 | 1382 |
1226 double total_regexp_code_generated() { return total_regexp_code_generated_; } | 1383 double total_regexp_code_generated() { return total_regexp_code_generated_; } |
1227 void IncreaseTotalRegexpCodeGenerated(int size) { | 1384 void IncreaseTotalRegexpCodeGenerated(int size) { |
1228 total_regexp_code_generated_ += size; | 1385 total_regexp_code_generated_ += size; |
1229 } | 1386 } |
1230 | 1387 |
1231 void IncrementCodeGeneratedBytes(bool is_crankshafted, int size) { | 1388 void IncrementCodeGeneratedBytes(bool is_crankshafted, int size) { |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1727 GarbageCollector collector, | 1884 GarbageCollector collector, |
1728 const char* gc_reason, | 1885 const char* gc_reason, |
1729 const char* collector_reason, | 1886 const char* collector_reason, |
1730 const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags); | 1887 const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags); |
1731 | 1888 |
1732 // Performs garbage collection | 1889 // Performs garbage collection |
1733 // Returns whether there is a chance another major GC could | 1890 // Returns whether there is a chance another major GC could |
1734 // collect more garbage. | 1891 // collect more garbage. |
1735 bool PerformGarbageCollection( | 1892 bool PerformGarbageCollection( |
1736 GarbageCollector collector, | 1893 GarbageCollector collector, |
1737 GCTracer* tracer, | |
1738 const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags); | 1894 const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags); |
1739 | 1895 |
1740 inline void UpdateOldSpaceLimits(); | 1896 inline void UpdateOldSpaceLimits(); |
1741 | 1897 |
1742 // Selects the proper allocation space depending on the given object | 1898 // Selects the proper allocation space depending on the given object |
1743 // size, pretenuring decision, and preferred old-space. | 1899 // size, pretenuring decision, and preferred old-space. |
1744 static AllocationSpace SelectSpace(int object_size, | 1900 static AllocationSpace SelectSpace(int object_size, |
1745 AllocationSpace preferred_old_space, | 1901 AllocationSpace preferred_old_space, |
1746 PretenureFlag pretenure) { | 1902 PretenureFlag pretenure) { |
1747 ASSERT(preferred_old_space == OLD_POINTER_SPACE || | 1903 ASSERT(preferred_old_space == OLD_POINTER_SPACE || |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1953 static String* UpdateNewSpaceReferenceInExternalStringTableEntry( | 2109 static String* UpdateNewSpaceReferenceInExternalStringTableEntry( |
1954 Heap* heap, | 2110 Heap* heap, |
1955 Object** pointer); | 2111 Object** pointer); |
1956 | 2112 |
1957 Address DoScavenge(ObjectVisitor* scavenge_visitor, Address new_space_front); | 2113 Address DoScavenge(ObjectVisitor* scavenge_visitor, Address new_space_front); |
1958 static void ScavengeStoreBufferCallback(Heap* heap, | 2114 static void ScavengeStoreBufferCallback(Heap* heap, |
1959 MemoryChunk* page, | 2115 MemoryChunk* page, |
1960 StoreBufferEvent event); | 2116 StoreBufferEvent event); |
1961 | 2117 |
1962 // Performs a major collection in the whole heap. | 2118 // Performs a major collection in the whole heap. |
1963 void MarkCompact(GCTracer* tracer); | 2119 void MarkCompact(); |
1964 | 2120 |
1965 // Code to be run before and after mark-compact. | 2121 // Code to be run before and after mark-compact. |
1966 void MarkCompactPrologue(); | 2122 void MarkCompactPrologue(); |
1967 | 2123 |
1968 void ProcessNativeContexts(WeakObjectRetainer* retainer); | 2124 void ProcessNativeContexts(WeakObjectRetainer* retainer); |
1969 void ProcessArrayBuffers(WeakObjectRetainer* retainer); | 2125 void ProcessArrayBuffers(WeakObjectRetainer* retainer); |
1970 void ProcessAllocationSites(WeakObjectRetainer* retainer); | 2126 void ProcessAllocationSites(WeakObjectRetainer* retainer); |
1971 | 2127 |
1972 // Deopts all code that contains allocation instruction which are tenured or | 2128 // Deopts all code that contains allocation instruction which are tenured or |
1973 // not tenured. Moreover it clears the pretenuring allocation site statistics. | 2129 // not tenured. Moreover it clears the pretenuring allocation site statistics. |
(...skipping 10 matching lines...) Expand all Loading... | |
1984 // Record statistics before and after garbage collection. | 2140 // Record statistics before and after garbage collection. |
1985 void ReportStatisticsBeforeGC(); | 2141 void ReportStatisticsBeforeGC(); |
1986 void ReportStatisticsAfterGC(); | 2142 void ReportStatisticsAfterGC(); |
1987 | 2143 |
1988 // Slow part of scavenge object. | 2144 // Slow part of scavenge object. |
1989 static void ScavengeObjectSlow(HeapObject** p, HeapObject* object); | 2145 static void ScavengeObjectSlow(HeapObject** p, HeapObject* object); |
1990 | 2146 |
1991 // Total RegExp code ever generated | 2147 // Total RegExp code ever generated |
1992 double total_regexp_code_generated_; | 2148 double total_regexp_code_generated_; |
1993 | 2149 |
1994 GCTracer* tracer_; | 2150 GCTracer tracer_; |
1995 | 2151 |
1996 // Creates and installs the full-sized number string cache. | 2152 // Creates and installs the full-sized number string cache. |
1997 int FullSizeNumberStringCacheLength(); | 2153 int FullSizeNumberStringCacheLength(); |
1998 // Flush the number to string cache. | 2154 // Flush the number to string cache. |
1999 void FlushNumberStringCache(); | 2155 void FlushNumberStringCache(); |
2000 | 2156 |
2001 // Sets used allocation sites entries to undefined. | 2157 // Sets used allocation sites entries to undefined. |
2002 void FlushAllocationSitesScratchpad(); | 2158 void FlushAllocationSitesScratchpad(); |
2003 | 2159 |
2004 // Initializes the allocation sites scratchpad with undefined values. | 2160 // Initializes the allocation sites scratchpad with undefined values. |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2502 }; | 2658 }; |
2503 | 2659 |
2504 Key keys_[kLength]; | 2660 Key keys_[kLength]; |
2505 int results_[kLength]; | 2661 int results_[kLength]; |
2506 | 2662 |
2507 friend class Isolate; | 2663 friend class Isolate; |
2508 DISALLOW_COPY_AND_ASSIGN(DescriptorLookupCache); | 2664 DISALLOW_COPY_AND_ASSIGN(DescriptorLookupCache); |
2509 }; | 2665 }; |
2510 | 2666 |
2511 | 2667 |
2512 // GCTracer collects and prints ONE line after each garbage collector | |
2513 // invocation IFF --trace_gc is used. | |
2514 | |
2515 class GCTracer BASE_EMBEDDED { | |
2516 public: | |
2517 class Scope BASE_EMBEDDED { | |
2518 public: | |
2519 enum ScopeId { | |
2520 EXTERNAL, | |
2521 MC_MARK, | |
2522 MC_SWEEP, | |
2523 MC_SWEEP_NEWSPACE, | |
2524 MC_SWEEP_OLDSPACE, | |
2525 MC_SWEEP_CODE, | |
2526 MC_SWEEP_CELL, | |
2527 MC_SWEEP_MAP, | |
2528 MC_EVACUATE_PAGES, | |
2529 MC_UPDATE_NEW_TO_NEW_POINTERS, | |
2530 MC_UPDATE_ROOT_TO_NEW_POINTERS, | |
2531 MC_UPDATE_OLD_TO_NEW_POINTERS, | |
2532 MC_UPDATE_POINTERS_TO_EVACUATED, | |
2533 MC_UPDATE_POINTERS_BETWEEN_EVACUATED, | |
2534 MC_UPDATE_MISC_POINTERS, | |
2535 MC_WEAKCOLLECTION_PROCESS, | |
2536 MC_WEAKCOLLECTION_CLEAR, | |
2537 MC_FLUSH_CODE, | |
2538 kNumberOfScopes | |
2539 }; | |
2540 | |
2541 Scope(GCTracer* tracer, ScopeId scope) | |
2542 : tracer_(tracer), | |
2543 scope_(scope) { | |
2544 start_time_ = base::OS::TimeCurrentMillis(); | |
2545 } | |
2546 | |
2547 ~Scope() { | |
2548 ASSERT(scope_ < kNumberOfScopes); // scope_ is unsigned. | |
2549 tracer_->scopes_[scope_] += base::OS::TimeCurrentMillis() - start_time_; | |
2550 } | |
2551 | |
2552 private: | |
2553 GCTracer* tracer_; | |
2554 ScopeId scope_; | |
2555 double start_time_; | |
2556 }; | |
2557 | |
2558 explicit GCTracer(Heap* heap, | |
2559 const char* gc_reason, | |
2560 const char* collector_reason); | |
2561 ~GCTracer(); | |
2562 | |
2563 // Sets the collector. | |
2564 void set_collector(GarbageCollector collector) { collector_ = collector; } | |
2565 | |
2566 // Sets the GC count. | |
2567 void set_gc_count(unsigned int count) { gc_count_ = count; } | |
2568 | |
2569 // Sets the full GC count. | |
2570 void set_full_gc_count(int count) { full_gc_count_ = count; } | |
2571 | |
2572 void increment_nodes_died_in_new_space() { | |
2573 nodes_died_in_new_space_++; | |
2574 } | |
2575 | |
2576 void increment_nodes_copied_in_new_space() { | |
2577 nodes_copied_in_new_space_++; | |
2578 } | |
2579 | |
2580 void increment_nodes_promoted() { | |
2581 nodes_promoted_++; | |
2582 } | |
2583 | |
2584 private: | |
2585 // Returns a string matching the collector. | |
2586 const char* CollectorString(); | |
2587 | |
2588 // Returns size of object in heap (in MB). | |
2589 inline double SizeOfHeapObjects(); | |
2590 | |
2591 // Timestamp set in the constructor. | |
2592 double start_time_; | |
2593 | |
2594 // Size of objects in heap set in constructor. | |
2595 intptr_t start_object_size_; | |
2596 | |
2597 // Size of memory allocated from OS set in constructor. | |
2598 intptr_t start_memory_size_; | |
2599 | |
2600 // Type of collector. | |
2601 GarbageCollector collector_; | |
2602 | |
2603 // A count (including this one, e.g. the first collection is 1) of the | |
2604 // number of garbage collections. | |
2605 unsigned int gc_count_; | |
2606 | |
2607 // A count (including this one) of the number of full garbage collections. | |
2608 int full_gc_count_; | |
2609 | |
2610 // Amounts of time spent in different scopes during GC. | |
2611 double scopes_[Scope::kNumberOfScopes]; | |
2612 | |
2613 // Total amount of space either wasted or contained in one of free lists | |
2614 // before the current GC. | |
2615 intptr_t in_free_list_or_wasted_before_gc_; | |
2616 | |
2617 // Difference between space used in the heap at the beginning of the current | |
2618 // collection and the end of the previous collection. | |
2619 intptr_t allocated_since_last_gc_; | |
2620 | |
2621 // Amount of time spent in mutator that is time elapsed between end of the | |
2622 // previous collection and the beginning of the current one. | |
2623 double spent_in_mutator_; | |
2624 | |
2625 // Number of died nodes in the new space. | |
2626 int nodes_died_in_new_space_; | |
2627 | |
2628 // Number of copied nodes to the new space. | |
2629 int nodes_copied_in_new_space_; | |
2630 | |
2631 // Number of promoted nodes to the old space. | |
2632 int nodes_promoted_; | |
2633 | |
2634 // Incremental marking steps counters. | |
2635 int steps_count_; | |
2636 double steps_took_; | |
2637 double longest_step_; | |
2638 int steps_count_since_last_gc_; | |
2639 double steps_took_since_last_gc_; | |
2640 | |
2641 Heap* heap_; | |
2642 | |
2643 const char* gc_reason_; | |
2644 const char* collector_reason_; | |
2645 }; | |
2646 | |
2647 | |
2648 class RegExpResultsCache { | 2668 class RegExpResultsCache { |
2649 public: | 2669 public: |
2650 enum ResultsCacheType { REGEXP_MULTIPLE_INDICES, STRING_SPLIT_SUBSTRINGS }; | 2670 enum ResultsCacheType { REGEXP_MULTIPLE_INDICES, STRING_SPLIT_SUBSTRINGS }; |
2651 | 2671 |
2652 // Attempt to retrieve a cached result. On failure, 0 is returned as a Smi. | 2672 // Attempt to retrieve a cached result. On failure, 0 is returned as a Smi. |
2653 // On success, the returned result is guaranteed to be a COW-array. | 2673 // On success, the returned result is guaranteed to be a COW-array. |
2654 static Object* Lookup(Heap* heap, | 2674 static Object* Lookup(Heap* heap, |
2655 String* key_string, | 2675 String* key_string, |
2656 Object* key_pattern, | 2676 Object* key_pattern, |
2657 ResultsCacheType type); | 2677 ResultsCacheType type); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2780 DisallowHeapAllocation no_allocation; // i.e. no gc allowed. | 2800 DisallowHeapAllocation no_allocation; // i.e. no gc allowed. |
2781 | 2801 |
2782 private: | 2802 private: |
2783 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); | 2803 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); |
2784 }; | 2804 }; |
2785 #endif // DEBUG | 2805 #endif // DEBUG |
2786 | 2806 |
2787 } } // namespace v8::internal | 2807 } } // namespace v8::internal |
2788 | 2808 |
2789 #endif // V8_HEAP_H_ | 2809 #endif // V8_HEAP_H_ |
OLD | NEW |