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/heap/heap.h" | 5 #include "src/heap/heap.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/api.h" | 8 #include "src/api.h" |
9 #include "src/ast/scopeinfo.h" | 9 #include "src/ast/scopeinfo.h" |
10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
(...skipping 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1092 | 1092 |
1093 void Heap::MoveElements(FixedArray* array, int dst_index, int src_index, | 1093 void Heap::MoveElements(FixedArray* array, int dst_index, int src_index, |
1094 int len) { | 1094 int len) { |
1095 if (len == 0) return; | 1095 if (len == 0) return; |
1096 | 1096 |
1097 DCHECK(array->map() != fixed_cow_array_map()); | 1097 DCHECK(array->map() != fixed_cow_array_map()); |
1098 Object** dst_objects = array->data_start() + dst_index; | 1098 Object** dst_objects = array->data_start() + dst_index; |
1099 MemMove(dst_objects, array->data_start() + src_index, len * kPointerSize); | 1099 MemMove(dst_objects, array->data_start() + src_index, len * kPointerSize); |
1100 if (!InNewSpace(array)) { | 1100 if (!InNewSpace(array)) { |
1101 for (int i = 0; i < len; i++) { | 1101 for (int i = 0; i < len; i++) { |
1102 // TODO(hpayer): check store buffer for entries | 1102 RecordWrite(array, array->OffsetOfElementAt(dst_index + i), |
1103 if (InNewSpace(dst_objects[i])) { | 1103 dst_objects[i]); |
1104 RecordWrite(array->address(), array->OffsetOfElementAt(dst_index + i)); | |
1105 } | |
1106 } | 1104 } |
1107 } | 1105 } |
1108 incremental_marking()->RecordWrites(array); | 1106 incremental_marking()->RecordWrites(array); |
1109 } | 1107 } |
1110 | 1108 |
1111 | 1109 |
1112 #ifdef VERIFY_HEAP | 1110 #ifdef VERIFY_HEAP |
1113 // Helper class for verifying the string table. | 1111 // Helper class for verifying the string table. |
1114 class StringTableVerifier : public ObjectVisitor { | 1112 class StringTableVerifier : public ObjectVisitor { |
1115 public: | 1113 public: |
(...skipping 1951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3067 | 3065 |
3068 if (lo_space()->Contains(object)) return false; | 3066 if (lo_space()->Contains(object)) return false; |
3069 | 3067 |
3070 Page* page = Page::FromAddress(address); | 3068 Page* page = Page::FromAddress(address); |
3071 // We can move the object start if: | 3069 // We can move the object start if: |
3072 // (1) the object is not in old space, | 3070 // (1) the object is not in old space, |
3073 // (2) the page of the object was already swept, | 3071 // (2) the page of the object was already swept, |
3074 // (3) the page was already concurrently swept. This case is an optimization | 3072 // (3) the page was already concurrently swept. This case is an optimization |
3075 // for concurrent sweeping. The WasSwept predicate for concurrently swept | 3073 // for concurrent sweeping. The WasSwept predicate for concurrently swept |
3076 // pages is set after sweeping all pages. | 3074 // pages is set after sweeping all pages. |
3077 return !InOldSpace(address) || page->SweepingDone(); | 3075 return !InOldSpace(object) || page->SweepingDone(); |
3078 } | 3076 } |
3079 | 3077 |
3080 | 3078 |
3081 void Heap::AdjustLiveBytes(HeapObject* object, int by, InvocationMode mode) { | 3079 void Heap::AdjustLiveBytes(HeapObject* object, int by, InvocationMode mode) { |
3082 // As long as the inspected object is black and we are currently not iterating | 3080 // As long as the inspected object is black and we are currently not iterating |
3083 // the heap using HeapIterator, we can update the live byte count. We cannot | 3081 // the heap using HeapIterator, we can update the live byte count. We cannot |
3084 // update while using HeapIterator because the iterator is temporarily | 3082 // update while using HeapIterator because the iterator is temporarily |
3085 // marking the whole object graph, without updating live bytes. | 3083 // marking the whole object graph, without updating live bytes. |
3086 if (!in_heap_iterator() && | 3084 if (!in_heap_iterator() && |
3087 !mark_compact_collector()->sweeping_in_progress() && | 3085 !mark_compact_collector()->sweeping_in_progress() && |
(...skipping 1236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4324 code_space_->ReportStatistics(); | 4322 code_space_->ReportStatistics(); |
4325 PrintF("Map space : "); | 4323 PrintF("Map space : "); |
4326 map_space_->ReportStatistics(); | 4324 map_space_->ReportStatistics(); |
4327 PrintF("Large object space : "); | 4325 PrintF("Large object space : "); |
4328 lo_space_->ReportStatistics(); | 4326 lo_space_->ReportStatistics(); |
4329 PrintF(">>>>>> ========================================= >>>>>>\n"); | 4327 PrintF(">>>>>> ========================================= >>>>>>\n"); |
4330 } | 4328 } |
4331 | 4329 |
4332 #endif // DEBUG | 4330 #endif // DEBUG |
4333 | 4331 |
4334 bool Heap::Contains(HeapObject* value) { return Contains(value->address()); } | 4332 bool Heap::Contains(HeapObject* value) { |
4335 | 4333 if (isolate_->memory_allocator()->IsOutsideAllocatedSpace(value->address())) { |
4336 | 4334 return false; |
4337 bool Heap::Contains(Address addr) { | 4335 } |
4338 if (isolate_->memory_allocator()->IsOutsideAllocatedSpace(addr)) return false; | |
4339 return HasBeenSetUp() && | 4336 return HasBeenSetUp() && |
4340 (new_space_.ToSpaceContains(addr) || old_space_->Contains(addr) || | 4337 (new_space_.ToSpaceContains(value) || old_space_->Contains(value) || |
4341 code_space_->Contains(addr) || map_space_->Contains(addr) || | 4338 code_space_->Contains(value) || map_space_->Contains(value) || |
4342 lo_space_->SlowContains(addr)); | 4339 lo_space_->Contains(value)); |
4343 } | 4340 } |
4344 | 4341 |
| 4342 bool Heap::ContainsSlow(Address addr) { |
| 4343 if (isolate_->memory_allocator()->IsOutsideAllocatedSpace(addr)) { |
| 4344 return false; |
| 4345 } |
| 4346 return HasBeenSetUp() && |
| 4347 (new_space_.ToSpaceContainsSlow(addr) || |
| 4348 old_space_->ContainsSlow(addr) || code_space_->ContainsSlow(addr) || |
| 4349 map_space_->ContainsSlow(addr) || lo_space_->ContainsSlow(addr)); |
| 4350 } |
4345 | 4351 |
4346 bool Heap::InSpace(HeapObject* value, AllocationSpace space) { | 4352 bool Heap::InSpace(HeapObject* value, AllocationSpace space) { |
4347 return InSpace(value->address(), space); | 4353 if (isolate_->memory_allocator()->IsOutsideAllocatedSpace(value->address())) { |
4348 } | 4354 return false; |
4349 | 4355 } |
4350 | |
4351 bool Heap::InSpace(Address addr, AllocationSpace space) { | |
4352 if (isolate_->memory_allocator()->IsOutsideAllocatedSpace(addr)) return false; | |
4353 if (!HasBeenSetUp()) return false; | 4356 if (!HasBeenSetUp()) return false; |
4354 | 4357 |
4355 switch (space) { | 4358 switch (space) { |
4356 case NEW_SPACE: | 4359 case NEW_SPACE: |
4357 return new_space_.ToSpaceContains(addr); | 4360 return new_space_.ToSpaceContains(value); |
4358 case OLD_SPACE: | 4361 case OLD_SPACE: |
4359 return old_space_->Contains(addr); | 4362 return old_space_->Contains(value); |
4360 case CODE_SPACE: | 4363 case CODE_SPACE: |
4361 return code_space_->Contains(addr); | 4364 return code_space_->Contains(value); |
4362 case MAP_SPACE: | 4365 case MAP_SPACE: |
4363 return map_space_->Contains(addr); | 4366 return map_space_->Contains(value); |
4364 case LO_SPACE: | 4367 case LO_SPACE: |
4365 return lo_space_->SlowContains(addr); | 4368 return lo_space_->Contains(value); |
4366 } | 4369 } |
4367 UNREACHABLE(); | 4370 UNREACHABLE(); |
4368 return false; | 4371 return false; |
| 4372 } |
| 4373 |
| 4374 bool Heap::InSpaceSlow(Address addr, AllocationSpace space) { |
| 4375 if (isolate_->memory_allocator()->IsOutsideAllocatedSpace(addr)) { |
| 4376 return false; |
| 4377 } |
| 4378 if (!HasBeenSetUp()) return false; |
| 4379 |
| 4380 switch (space) { |
| 4381 case NEW_SPACE: |
| 4382 return new_space_.ToSpaceContainsSlow(addr); |
| 4383 case OLD_SPACE: |
| 4384 return old_space_->ContainsSlow(addr); |
| 4385 case CODE_SPACE: |
| 4386 return code_space_->ContainsSlow(addr); |
| 4387 case MAP_SPACE: |
| 4388 return map_space_->ContainsSlow(addr); |
| 4389 case LO_SPACE: |
| 4390 return lo_space_->ContainsSlow(addr); |
| 4391 } |
| 4392 UNREACHABLE(); |
| 4393 return false; |
4369 } | 4394 } |
4370 | 4395 |
4371 | 4396 |
4372 bool Heap::IsValidAllocationSpace(AllocationSpace space) { | 4397 bool Heap::IsValidAllocationSpace(AllocationSpace space) { |
4373 switch (space) { | 4398 switch (space) { |
4374 case NEW_SPACE: | 4399 case NEW_SPACE: |
4375 case OLD_SPACE: | 4400 case OLD_SPACE: |
4376 case CODE_SPACE: | 4401 case CODE_SPACE: |
4377 case MAP_SPACE: | 4402 case MAP_SPACE: |
4378 case LO_SPACE: | 4403 case LO_SPACE: |
(...skipping 1808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6187 } | 6212 } |
6188 | 6213 |
6189 | 6214 |
6190 // static | 6215 // static |
6191 int Heap::GetStaticVisitorIdForMap(Map* map) { | 6216 int Heap::GetStaticVisitorIdForMap(Map* map) { |
6192 return StaticVisitorBase::GetVisitorId(map); | 6217 return StaticVisitorBase::GetVisitorId(map); |
6193 } | 6218 } |
6194 | 6219 |
6195 } // namespace internal | 6220 } // namespace internal |
6196 } // namespace v8 | 6221 } // namespace v8 |
OLD | NEW |