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

Side by Side Diff: src/heap.h

Issue 403543002: Make GCTracer persistent. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Remove destr and initialize last gc timestamp. Created 6 years, 5 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 | « no previous file | src/heap.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 // 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...) Expand 10 before | Expand all | Expand 10 after
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...) Expand 10 before | Expand all | Expand 10 after
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
601 // Start collecting data.
602 void start(GarbageCollector collector,
603 const char* gc_reason,
604 const char* collector_reason);
605
606 // Stop collecting data and print results.
607 void stop();
608
609 private:
610 // Returns a string matching the collector.
611 const char* CollectorString() const;
612
613 // Print one detailed trace line in name=value format.
614 void PrintNVP() const;
615
616 // Print one trace line.
617 void Print() const;
618
619 // Timestamp set in the constructor.
620 double start_time_;
621
622 // Timestamp set in the destructor.
623 double end_time_;
624
625 // Size of objects in heap set in constructor.
626 intptr_t start_object_size_;
627
628 // Size of objects in heap set in destructor.
629 intptr_t end_object_size_;
630
631 // Size of memory allocated from OS set in constructor.
632 intptr_t start_memory_size_;
633
634 // Size of memory allocated from OS set in destructor.
635 intptr_t end_memory_size_;
636
637 // Type of collector.
638 GarbageCollector collector_;
639
640 // Amounts of time spent in different scopes during GC.
641 double scopes_[Scope::NUMBER_OF_SCOPES];
642
643 // Total amount of space either wasted or contained in one of free lists
644 // before the current GC.
645 intptr_t in_free_list_or_wasted_before_gc_;
646
647 // Difference between space used in the heap at the beginning of the current
648 // collection and the end of the previous collection.
649 intptr_t allocated_since_last_gc_;
650
651 // Amount of time spent in mutator that is time elapsed between end of the
652 // previous collection and the beginning of the current one.
653 double spent_in_mutator_;
654
655 // Incremental marking steps counters.
656 int steps_count_;
657 double steps_took_;
658 double longest_step_;
659 int steps_count_since_last_gc_;
660 double steps_took_since_last_gc_;
661
662 Heap* heap_;
663
664 const char* gc_reason_;
665 const char* collector_reason_;
666
667 DISALLOW_COPY_AND_ASSIGN(GCTracer);
668 };
669
670
552 class Heap { 671 class Heap {
553 public: 672 public:
554 // Configure heap size in MB before setup. Return false if the heap has been 673 // Configure heap size in MB before setup. Return false if the heap has been
555 // set up already. 674 // set up already.
556 bool ConfigureHeap(int max_semi_space_size, 675 bool ConfigureHeap(int max_semi_space_size,
557 int max_old_space_size, 676 int max_old_space_size,
558 int max_executable_size, 677 int max_executable_size,
559 size_t code_range_size); 678 size_t code_range_size);
560 bool ConfigureHeapDefault(); 679 bool ConfigureHeapDefault();
561 680
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 void VisitExternalResources(v8::ExternalResourceVisitor* visitor); 1342 void VisitExternalResources(v8::ExternalResourceVisitor* visitor);
1224 1343
1225 // An object should be promoted if the object has survived a 1344 // An object should be promoted if the object has survived a
1226 // scavenge operation. 1345 // scavenge operation.
1227 inline bool ShouldBePromoted(Address old_address, int object_size); 1346 inline bool ShouldBePromoted(Address old_address, int object_size);
1228 1347
1229 void ClearJSFunctionResultCaches(); 1348 void ClearJSFunctionResultCaches();
1230 1349
1231 void ClearNormalizedMapCaches(); 1350 void ClearNormalizedMapCaches();
1232 1351
1233 GCTracer* tracer() { return tracer_; } 1352 GCTracer* tracer() { return &tracer_; }
1234 1353
1235 // Returns the size of objects residing in non new spaces. 1354 // Returns the size of objects residing in non new spaces.
1236 intptr_t PromotedSpaceSizeOfObjects(); 1355 intptr_t PromotedSpaceSizeOfObjects();
1237 1356
1238 double total_regexp_code_generated() { return total_regexp_code_generated_; } 1357 double total_regexp_code_generated() { return total_regexp_code_generated_; }
1239 void IncreaseTotalRegexpCodeGenerated(int size) { 1358 void IncreaseTotalRegexpCodeGenerated(int size) {
1240 total_regexp_code_generated_ += size; 1359 total_regexp_code_generated_ += size;
1241 } 1360 }
1242 1361
1243 void IncrementCodeGeneratedBytes(bool is_crankshafted, int size) { 1362 void IncrementCodeGeneratedBytes(bool is_crankshafted, int size) {
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
1745 GarbageCollector collector, 1864 GarbageCollector collector,
1746 const char* gc_reason, 1865 const char* gc_reason,
1747 const char* collector_reason, 1866 const char* collector_reason,
1748 const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags); 1867 const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags);
1749 1868
1750 // Performs garbage collection 1869 // Performs garbage collection
1751 // Returns whether there is a chance another major GC could 1870 // Returns whether there is a chance another major GC could
1752 // collect more garbage. 1871 // collect more garbage.
1753 bool PerformGarbageCollection( 1872 bool PerformGarbageCollection(
1754 GarbageCollector collector, 1873 GarbageCollector collector,
1755 GCTracer* tracer,
1756 const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags); 1874 const GCCallbackFlags gc_callback_flags = kNoGCCallbackFlags);
1757 1875
1758 inline void UpdateOldSpaceLimits(); 1876 inline void UpdateOldSpaceLimits();
1759 1877
1760 // Selects the proper allocation space depending on the given object 1878 // Selects the proper allocation space depending on the given object
1761 // size, pretenuring decision, and preferred old-space. 1879 // size, pretenuring decision, and preferred old-space.
1762 static AllocationSpace SelectSpace(int object_size, 1880 static AllocationSpace SelectSpace(int object_size,
1763 AllocationSpace preferred_old_space, 1881 AllocationSpace preferred_old_space,
1764 PretenureFlag pretenure) { 1882 PretenureFlag pretenure) {
1765 ASSERT(preferred_old_space == OLD_POINTER_SPACE || 1883 ASSERT(preferred_old_space == OLD_POINTER_SPACE ||
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1971 static String* UpdateNewSpaceReferenceInExternalStringTableEntry( 2089 static String* UpdateNewSpaceReferenceInExternalStringTableEntry(
1972 Heap* heap, 2090 Heap* heap,
1973 Object** pointer); 2091 Object** pointer);
1974 2092
1975 Address DoScavenge(ObjectVisitor* scavenge_visitor, Address new_space_front); 2093 Address DoScavenge(ObjectVisitor* scavenge_visitor, Address new_space_front);
1976 static void ScavengeStoreBufferCallback(Heap* heap, 2094 static void ScavengeStoreBufferCallback(Heap* heap,
1977 MemoryChunk* page, 2095 MemoryChunk* page,
1978 StoreBufferEvent event); 2096 StoreBufferEvent event);
1979 2097
1980 // Performs a major collection in the whole heap. 2098 // Performs a major collection in the whole heap.
1981 void MarkCompact(GCTracer* tracer); 2099 void MarkCompact();
1982 2100
1983 // Code to be run before and after mark-compact. 2101 // Code to be run before and after mark-compact.
1984 void MarkCompactPrologue(); 2102 void MarkCompactPrologue();
1985 2103
1986 void ProcessNativeContexts(WeakObjectRetainer* retainer); 2104 void ProcessNativeContexts(WeakObjectRetainer* retainer);
1987 void ProcessArrayBuffers(WeakObjectRetainer* retainer); 2105 void ProcessArrayBuffers(WeakObjectRetainer* retainer);
1988 void ProcessAllocationSites(WeakObjectRetainer* retainer); 2106 void ProcessAllocationSites(WeakObjectRetainer* retainer);
1989 2107
1990 // Deopts all code that contains allocation instruction which are tenured or 2108 // Deopts all code that contains allocation instruction which are tenured or
1991 // not tenured. Moreover it clears the pretenuring allocation site statistics. 2109 // not tenured. Moreover it clears the pretenuring allocation site statistics.
(...skipping 10 matching lines...) Expand all
2002 // Record statistics before and after garbage collection. 2120 // Record statistics before and after garbage collection.
2003 void ReportStatisticsBeforeGC(); 2121 void ReportStatisticsBeforeGC();
2004 void ReportStatisticsAfterGC(); 2122 void ReportStatisticsAfterGC();
2005 2123
2006 // Slow part of scavenge object. 2124 // Slow part of scavenge object.
2007 static void ScavengeObjectSlow(HeapObject** p, HeapObject* object); 2125 static void ScavengeObjectSlow(HeapObject** p, HeapObject* object);
2008 2126
2009 // Total RegExp code ever generated 2127 // Total RegExp code ever generated
2010 double total_regexp_code_generated_; 2128 double total_regexp_code_generated_;
2011 2129
2012 GCTracer* tracer_; 2130 GCTracer tracer_;
2013 2131
2014 // Creates and installs the full-sized number string cache. 2132 // Creates and installs the full-sized number string cache.
2015 int FullSizeNumberStringCacheLength(); 2133 int FullSizeNumberStringCacheLength();
2016 // Flush the number to string cache. 2134 // Flush the number to string cache.
2017 void FlushNumberStringCache(); 2135 void FlushNumberStringCache();
2018 2136
2019 // Sets used allocation sites entries to undefined. 2137 // Sets used allocation sites entries to undefined.
2020 void FlushAllocationSitesScratchpad(); 2138 void FlushAllocationSitesScratchpad();
2021 2139
2022 // Initializes the allocation sites scratchpad with undefined values. 2140 // Initializes the allocation sites scratchpad with undefined values.
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
2523 }; 2641 };
2524 2642
2525 Key keys_[kLength]; 2643 Key keys_[kLength];
2526 int results_[kLength]; 2644 int results_[kLength];
2527 2645
2528 friend class Isolate; 2646 friend class Isolate;
2529 DISALLOW_COPY_AND_ASSIGN(DescriptorLookupCache); 2647 DISALLOW_COPY_AND_ASSIGN(DescriptorLookupCache);
2530 }; 2648 };
2531 2649
2532 2650
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 { 2651 class RegExpResultsCache {
2650 public: 2652 public:
2651 enum ResultsCacheType { REGEXP_MULTIPLE_INDICES, STRING_SPLIT_SUBSTRINGS }; 2653 enum ResultsCacheType { REGEXP_MULTIPLE_INDICES, STRING_SPLIT_SUBSTRINGS };
2652 2654
2653 // Attempt to retrieve a cached result. On failure, 0 is returned as a Smi. 2655 // 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. 2656 // On success, the returned result is guaranteed to be a COW-array.
2655 static Object* Lookup(Heap* heap, 2657 static Object* Lookup(Heap* heap,
2656 String* key_string, 2658 String* key_string,
2657 Object* key_pattern, 2659 Object* key_pattern,
2658 ResultsCacheType type); 2660 ResultsCacheType type);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
2781 DisallowHeapAllocation no_allocation; // i.e. no gc allowed. 2783 DisallowHeapAllocation no_allocation; // i.e. no gc allowed.
2782 2784
2783 private: 2785 private:
2784 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); 2786 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer);
2785 }; 2787 };
2786 #endif // DEBUG 2788 #endif // DEBUG
2787 2789
2788 } } // namespace v8::internal 2790 } } // namespace v8::internal
2789 2791
2790 #endif // V8_HEAP_H_ 2792 #endif // V8_HEAP_H_
OLDNEW
« no previous file with comments | « no previous file | src/heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698