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 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/heap/incremental-marking.h" | 7 #include "src/heap/incremental-marking.h" |
8 | 8 |
9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/compilation-cache.h" | 10 #include "src/compilation-cache.h" |
11 #include "src/conversions.h" | 11 #include "src/conversions.h" |
12 #include "src/heap/objects-visiting.h" | 12 #include "src/heap/objects-visiting.h" |
13 #include "src/heap/objects-visiting-inl.h" | 13 #include "src/heap/objects-visiting-inl.h" |
14 | 14 |
15 namespace v8 { | 15 namespace v8 { |
16 namespace internal { | 16 namespace internal { |
17 | 17 |
18 | 18 |
19 IncrementalMarking::IncrementalMarking(Heap* heap) | 19 IncrementalMarking::IncrementalMarking(Heap* heap) |
20 : heap_(heap), | 20 : heap_(heap), |
21 state_(STOPPED), | 21 state_(STOPPED), |
22 marking_deque_memory_(NULL), | 22 marking_deque_memory_(NULL), |
23 marking_deque_memory_committed_(false), | 23 marking_deque_memory_committed_(false), |
24 steps_count_(0), | 24 steps_count_(0), |
25 old_generation_space_available_at_start_of_incremental_(0), | 25 old_generation_space_available_at_start_of_incremental_(0), |
26 old_generation_space_used_at_start_of_incremental_(0), | 26 old_generation_space_used_at_start_of_incremental_(0), |
27 should_hurry_(false), | 27 should_hurry_(false), |
28 marking_speed_(0), | 28 marking_speed_(0), |
29 allocated_(0), | 29 allocated_(0), |
| 30 idle_marking_delay_counter_(0), |
30 no_marking_scope_depth_(0), | 31 no_marking_scope_depth_(0), |
31 unscanned_bytes_of_large_object_(0) {} | 32 unscanned_bytes_of_large_object_(0) {} |
32 | 33 |
33 | 34 |
34 void IncrementalMarking::TearDown() { delete marking_deque_memory_; } | 35 void IncrementalMarking::TearDown() { delete marking_deque_memory_; } |
35 | 36 |
36 | 37 |
37 void IncrementalMarking::RecordWriteSlow(HeapObject* obj, Object** slot, | 38 void IncrementalMarking::RecordWriteSlow(HeapObject* obj, Object** slot, |
38 Object* value) { | 39 Object* value) { |
39 if (BaseRecordWrite(obj, slot, value) && slot != NULL) { | 40 if (BaseRecordWrite(obj, slot, value) && slot != NULL) { |
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 marking_speed_ = static_cast<int>( | 886 marking_speed_ = static_cast<int>( |
886 Min(kMaxMarkingSpeed, static_cast<intptr_t>(marking_speed_ * 1.3))); | 887 Min(kMaxMarkingSpeed, static_cast<intptr_t>(marking_speed_ * 1.3))); |
887 if (FLAG_trace_gc) { | 888 if (FLAG_trace_gc) { |
888 PrintPID("Marking speed increased to %d\n", marking_speed_); | 889 PrintPID("Marking speed increased to %d\n", marking_speed_); |
889 } | 890 } |
890 } | 891 } |
891 } | 892 } |
892 } | 893 } |
893 | 894 |
894 | 895 |
895 void IncrementalMarking::Step(intptr_t allocated_bytes, CompletionAction action, | 896 intptr_t IncrementalMarking::Step(intptr_t allocated_bytes, |
896 bool force_marking) { | 897 CompletionAction action, |
| 898 ForceMarkingAction marking, |
| 899 ForceCompletionAction completion) { |
897 if (heap_->gc_state() != Heap::NOT_IN_GC || !FLAG_incremental_marking || | 900 if (heap_->gc_state() != Heap::NOT_IN_GC || !FLAG_incremental_marking || |
898 !FLAG_incremental_marking_steps || | 901 !FLAG_incremental_marking_steps || |
899 (state_ != SWEEPING && state_ != MARKING)) { | 902 (state_ != SWEEPING && state_ != MARKING)) { |
900 return; | 903 return 0; |
901 } | 904 } |
902 | 905 |
903 allocated_ += allocated_bytes; | 906 allocated_ += allocated_bytes; |
904 | 907 |
905 if (!force_marking && allocated_ < kAllocatedThreshold && | 908 if (marking == DO_NOT_FORCE_MARKING && allocated_ < kAllocatedThreshold && |
906 write_barriers_invoked_since_last_step_ < | 909 write_barriers_invoked_since_last_step_ < |
907 kWriteBarriersInvokedThreshold) { | 910 kWriteBarriersInvokedThreshold) { |
908 return; | 911 return 0; |
909 } | 912 } |
910 | 913 |
911 if (state_ == MARKING && no_marking_scope_depth_ > 0) return; | 914 if (state_ == MARKING && no_marking_scope_depth_ > 0) return 0; |
912 | 915 |
| 916 intptr_t bytes_processed = 0; |
913 { | 917 { |
914 HistogramTimerScope incremental_marking_scope( | 918 HistogramTimerScope incremental_marking_scope( |
915 heap_->isolate()->counters()->gc_incremental_marking()); | 919 heap_->isolate()->counters()->gc_incremental_marking()); |
916 double start = base::OS::TimeCurrentMillis(); | 920 double start = base::OS::TimeCurrentMillis(); |
917 | 921 |
918 // The marking speed is driven either by the allocation rate or by the rate | 922 // The marking speed is driven either by the allocation rate or by the rate |
919 // at which we are having to check the color of objects in the write | 923 // at which we are having to check the color of objects in the write |
920 // barrier. | 924 // barrier. |
921 // It is possible for a tight non-allocating loop to run a lot of write | 925 // It is possible for a tight non-allocating loop to run a lot of write |
922 // barriers before we get here and check them (marking can only take place | 926 // barriers before we get here and check them (marking can only take place |
923 // on | 927 // on |
924 // allocation), so to reduce the lumpiness we don't use the write barriers | 928 // allocation), so to reduce the lumpiness we don't use the write barriers |
925 // invoked since last step directly to determine the amount of work to do. | 929 // invoked since last step directly to determine the amount of work to do. |
926 intptr_t bytes_to_process = | 930 intptr_t bytes_to_process = |
927 marking_speed_ * | 931 marking_speed_ * |
928 Max(allocated_, write_barriers_invoked_since_last_step_); | 932 Max(allocated_, write_barriers_invoked_since_last_step_); |
929 allocated_ = 0; | 933 allocated_ = 0; |
930 write_barriers_invoked_since_last_step_ = 0; | 934 write_barriers_invoked_since_last_step_ = 0; |
931 | 935 |
932 bytes_scanned_ += bytes_to_process; | 936 bytes_scanned_ += bytes_to_process; |
933 intptr_t bytes_processed = 0; | |
934 | 937 |
935 if (state_ == SWEEPING) { | 938 if (state_ == SWEEPING) { |
936 if (heap_->mark_compact_collector()->sweeping_in_progress() && | 939 if (heap_->mark_compact_collector()->sweeping_in_progress() && |
937 heap_->mark_compact_collector()->IsSweepingCompleted()) { | 940 heap_->mark_compact_collector()->IsSweepingCompleted()) { |
938 heap_->mark_compact_collector()->EnsureSweepingCompleted(); | 941 heap_->mark_compact_collector()->EnsureSweepingCompleted(); |
939 } | 942 } |
940 if (!heap_->mark_compact_collector()->sweeping_in_progress()) { | 943 if (!heap_->mark_compact_collector()->sweeping_in_progress()) { |
941 bytes_scanned_ = 0; | 944 bytes_scanned_ = 0; |
942 StartMarking(PREVENT_COMPACTION); | 945 StartMarking(PREVENT_COMPACTION); |
943 } | 946 } |
944 } else if (state_ == MARKING) { | 947 } else if (state_ == MARKING) { |
945 bytes_processed = ProcessMarkingDeque(bytes_to_process); | 948 bytes_processed = ProcessMarkingDeque(bytes_to_process); |
946 if (marking_deque_.IsEmpty()) MarkingComplete(action); | 949 if (marking_deque_.IsEmpty()) { |
| 950 if (completion == FORCE_COMPLETION || |
| 951 IsIdleMarkingDelayCounterLimitReached()) { |
| 952 MarkingComplete(action); |
| 953 } else { |
| 954 IncrementIdleMarkingDelayCounter(); |
| 955 } |
| 956 } |
947 } | 957 } |
948 | 958 |
949 steps_count_++; | 959 steps_count_++; |
950 | 960 |
951 // Speed up marking if we are marking too slow or if we are almost done | 961 // Speed up marking if we are marking too slow or if we are almost done |
952 // with marking. | 962 // with marking. |
953 SpeedUp(); | 963 SpeedUp(); |
954 | 964 |
955 double end = base::OS::TimeCurrentMillis(); | 965 double end = base::OS::TimeCurrentMillis(); |
956 double duration = (end - start); | 966 double duration = (end - start); |
957 // Note that we report zero bytes here when sweeping was in progress or | 967 // Note that we report zero bytes here when sweeping was in progress or |
958 // when we just started incremental marking. In these cases we did not | 968 // when we just started incremental marking. In these cases we did not |
959 // process the marking deque. | 969 // process the marking deque. |
960 heap_->tracer()->AddIncrementalMarkingStep(duration, bytes_processed); | 970 heap_->tracer()->AddIncrementalMarkingStep(duration, bytes_processed); |
961 } | 971 } |
| 972 return bytes_processed; |
962 } | 973 } |
963 | 974 |
964 | 975 |
965 void IncrementalMarking::ResetStepCounters() { | 976 void IncrementalMarking::ResetStepCounters() { |
966 steps_count_ = 0; | 977 steps_count_ = 0; |
967 old_generation_space_available_at_start_of_incremental_ = | 978 old_generation_space_available_at_start_of_incremental_ = |
968 SpaceLeftInOldSpace(); | 979 SpaceLeftInOldSpace(); |
969 old_generation_space_used_at_start_of_incremental_ = | 980 old_generation_space_used_at_start_of_incremental_ = |
970 heap_->PromotedTotalSize(); | 981 heap_->PromotedTotalSize(); |
971 bytes_rescanned_ = 0; | 982 bytes_rescanned_ = 0; |
972 marking_speed_ = kInitialMarkingSpeed; | 983 marking_speed_ = kInitialMarkingSpeed; |
973 bytes_scanned_ = 0; | 984 bytes_scanned_ = 0; |
974 write_barriers_invoked_since_last_step_ = 0; | 985 write_barriers_invoked_since_last_step_ = 0; |
975 } | 986 } |
976 | 987 |
977 | 988 |
978 int64_t IncrementalMarking::SpaceLeftInOldSpace() { | 989 int64_t IncrementalMarking::SpaceLeftInOldSpace() { |
979 return heap_->MaxOldGenerationSize() - heap_->PromotedSpaceSizeOfObjects(); | 990 return heap_->MaxOldGenerationSize() - heap_->PromotedSpaceSizeOfObjects(); |
980 } | 991 } |
| 992 |
| 993 |
| 994 bool IncrementalMarking::IsIdleMarkingDelayCounterLimitReached() { |
| 995 return idle_marking_delay_counter_ > kMaxIdleMarkingDelayCounter; |
| 996 } |
| 997 |
| 998 |
| 999 void IncrementalMarking::IncrementIdleMarkingDelayCounter() { |
| 1000 idle_marking_delay_counter_++; |
| 1001 } |
| 1002 |
| 1003 |
| 1004 void IncrementalMarking::ClearIdleMarkingDelayCounter() { |
| 1005 idle_marking_delay_counter_ = 0; |
| 1006 } |
981 } | 1007 } |
982 } // namespace v8::internal | 1008 } // namespace v8::internal |
OLD | NEW |