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/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/api.h" | 8 #include "src/api.h" |
9 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 #endif | 47 #endif |
48 #if V8_TARGET_ARCH_MIPS64 && !V8_INTERPRETED_REGEXP | 48 #if V8_TARGET_ARCH_MIPS64 && !V8_INTERPRETED_REGEXP |
49 #include "src/regexp-macro-assembler.h" | 49 #include "src/regexp-macro-assembler.h" |
50 #include "src/mips64/regexp-macro-assembler-mips64.h" | 50 #include "src/mips64/regexp-macro-assembler-mips64.h" |
51 #endif | 51 #endif |
52 | 52 |
53 namespace v8 { | 53 namespace v8 { |
54 namespace internal { | 54 namespace internal { |
55 | 55 |
56 | 56 |
| 57 struct Heap::StrongRootsList { |
| 58 Object** start; |
| 59 Object** end; |
| 60 StrongRootsList* next; |
| 61 }; |
| 62 |
| 63 |
57 Heap::Heap() | 64 Heap::Heap() |
58 : amount_of_external_allocated_memory_(0), | 65 : amount_of_external_allocated_memory_(0), |
59 amount_of_external_allocated_memory_at_last_global_gc_(0), | 66 amount_of_external_allocated_memory_at_last_global_gc_(0), |
60 isolate_(NULL), | 67 isolate_(NULL), |
61 code_range_size_(0), | 68 code_range_size_(0), |
62 // semispace_size_ should be a power of 2 and old_generation_size_ should | 69 // semispace_size_ should be a power of 2 and old_generation_size_ should |
63 // be a multiple of Page::kPageSize. | 70 // be a multiple of Page::kPageSize. |
64 reserved_semispace_size_(8 * (kPointerSize / 4) * MB), | 71 reserved_semispace_size_(8 * (kPointerSize / 4) * MB), |
65 max_semi_space_size_(8 * (kPointerSize / 4) * MB), | 72 max_semi_space_size_(8 * (kPointerSize / 4) * MB), |
66 initial_semispace_size_(Page::kPageSize), | 73 initial_semispace_size_(Page::kPageSize), |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 full_codegen_bytes_generated_(0), | 141 full_codegen_bytes_generated_(0), |
135 crankshaft_codegen_bytes_generated_(0), | 142 crankshaft_codegen_bytes_generated_(0), |
136 gcs_since_last_deopt_(0), | 143 gcs_since_last_deopt_(0), |
137 allocation_sites_scratchpad_length_(0), | 144 allocation_sites_scratchpad_length_(0), |
138 promotion_queue_(this), | 145 promotion_queue_(this), |
139 configured_(false), | 146 configured_(false), |
140 external_string_table_(this), | 147 external_string_table_(this), |
141 chunks_queued_for_free_(NULL), | 148 chunks_queued_for_free_(NULL), |
142 gc_callbacks_depth_(0), | 149 gc_callbacks_depth_(0), |
143 deserialization_complete_(false), | 150 deserialization_complete_(false), |
144 concurrent_sweeping_enabled_(false) { | 151 concurrent_sweeping_enabled_(false), |
| 152 strong_roots_list_(NULL) { |
145 // Allow build-time customization of the max semispace size. Building | 153 // Allow build-time customization of the max semispace size. Building |
146 // V8 with snapshots and a non-default max semispace size is much | 154 // V8 with snapshots and a non-default max semispace size is much |
147 // easier if you can define it as part of the build environment. | 155 // easier if you can define it as part of the build environment. |
148 #if defined(V8_MAX_SEMISPACE_SIZE) | 156 #if defined(V8_MAX_SEMISPACE_SIZE) |
149 max_semi_space_size_ = reserved_semispace_size_ = V8_MAX_SEMISPACE_SIZE; | 157 max_semi_space_size_ = reserved_semispace_size_ = V8_MAX_SEMISPACE_SIZE; |
150 #endif | 158 #endif |
151 | 159 |
152 // Ensure old_generation_size_ is a multiple of kPageSize. | 160 // Ensure old_generation_size_ is a multiple of kPageSize. |
153 DCHECK(MB >= Page::kPageSize); | 161 DCHECK(MB >= Page::kPageSize); |
154 | 162 |
(...skipping 4865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5020 isolate_->eternal_handles()->IterateNewSpaceRoots(v); | 5028 isolate_->eternal_handles()->IterateNewSpaceRoots(v); |
5021 } else { | 5029 } else { |
5022 isolate_->eternal_handles()->IterateAllRoots(v); | 5030 isolate_->eternal_handles()->IterateAllRoots(v); |
5023 } | 5031 } |
5024 v->Synchronize(VisitorSynchronization::kEternalHandles); | 5032 v->Synchronize(VisitorSynchronization::kEternalHandles); |
5025 | 5033 |
5026 // Iterate over pointers being held by inactive threads. | 5034 // Iterate over pointers being held by inactive threads. |
5027 isolate_->thread_manager()->Iterate(v); | 5035 isolate_->thread_manager()->Iterate(v); |
5028 v->Synchronize(VisitorSynchronization::kThreadManager); | 5036 v->Synchronize(VisitorSynchronization::kThreadManager); |
5029 | 5037 |
| 5038 // Iterate over other strong roots (currently only identity maps). |
| 5039 for (StrongRootsList* list = strong_roots_list_; list; list = list->next) { |
| 5040 v->VisitPointers(list->start, list->end); |
| 5041 } |
| 5042 v->Synchronize(VisitorSynchronization::kStrongRoots); |
| 5043 |
5030 // Iterate over the pointers the Serialization/Deserialization code is | 5044 // Iterate over the pointers the Serialization/Deserialization code is |
5031 // holding. | 5045 // holding. |
5032 // During garbage collection this keeps the partial snapshot cache alive. | 5046 // During garbage collection this keeps the partial snapshot cache alive. |
5033 // During deserialization of the startup snapshot this creates the partial | 5047 // During deserialization of the startup snapshot this creates the partial |
5034 // snapshot cache and deserializes the objects it refers to. During | 5048 // snapshot cache and deserializes the objects it refers to. During |
5035 // serialization this does nothing, since the partial snapshot cache is | 5049 // serialization this does nothing, since the partial snapshot cache is |
5036 // empty. However the next thing we do is create the partial snapshot, | 5050 // empty. However the next thing we do is create the partial snapshot, |
5037 // filling up the partial snapshot cache with objects it needs as we go. | 5051 // filling up the partial snapshot cache with objects it needs as we go. |
5038 SerializerDeserializer::Iterate(isolate_, v); | 5052 SerializerDeserializer::Iterate(isolate_, v); |
5039 // We don't do a v->Synchronize call here, because in debug mode that will | 5053 // We don't do a v->Synchronize call here, because in debug mode that will |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5534 | 5548 |
5535 if (lo_space_ != NULL) { | 5549 if (lo_space_ != NULL) { |
5536 lo_space_->TearDown(); | 5550 lo_space_->TearDown(); |
5537 delete lo_space_; | 5551 delete lo_space_; |
5538 lo_space_ = NULL; | 5552 lo_space_ = NULL; |
5539 } | 5553 } |
5540 | 5554 |
5541 store_buffer()->TearDown(); | 5555 store_buffer()->TearDown(); |
5542 | 5556 |
5543 isolate_->memory_allocator()->TearDown(); | 5557 isolate_->memory_allocator()->TearDown(); |
| 5558 |
| 5559 StrongRootsList* next = NULL; |
| 5560 for (StrongRootsList* list = strong_roots_list_; list; list = next) { |
| 5561 next = list->next; |
| 5562 delete list; |
| 5563 } |
| 5564 strong_roots_list_ = NULL; |
5544 } | 5565 } |
5545 | 5566 |
5546 | 5567 |
5547 void Heap::AddGCPrologueCallback(v8::Isolate::GCPrologueCallback callback, | 5568 void Heap::AddGCPrologueCallback(v8::Isolate::GCPrologueCallback callback, |
5548 GCType gc_type, bool pass_isolate) { | 5569 GCType gc_type, bool pass_isolate) { |
5549 DCHECK(callback != NULL); | 5570 DCHECK(callback != NULL); |
5550 GCPrologueCallbackPair pair(callback, gc_type, pass_isolate); | 5571 GCPrologueCallbackPair pair(callback, gc_type, pass_isolate); |
5551 DCHECK(!gc_prologue_callbacks_.Contains(pair)); | 5572 DCHECK(!gc_prologue_callbacks_.Contains(pair)); |
5552 return gc_prologue_callbacks_.Add(pair); | 5573 return gc_prologue_callbacks_.Add(pair); |
5553 } | 5574 } |
(...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6432 static_cast<int>(object_sizes_[index])); \ | 6453 static_cast<int>(object_sizes_[index])); \ |
6433 counters->size_of_CODE_AGE_##name()->Decrement( \ | 6454 counters->size_of_CODE_AGE_##name()->Decrement( \ |
6434 static_cast<int>(object_sizes_last_time_[index])); | 6455 static_cast<int>(object_sizes_last_time_[index])); |
6435 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) | 6456 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) |
6436 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 6457 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
6437 | 6458 |
6438 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 6459 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
6439 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 6460 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
6440 ClearObjectStats(); | 6461 ClearObjectStats(); |
6441 } | 6462 } |
| 6463 |
| 6464 |
| 6465 void Heap::RegisterStrongRoots(Object** start, Object** end) { |
| 6466 StrongRootsList* list = new StrongRootsList(); |
| 6467 list->next = strong_roots_list_; |
| 6468 list->start = start; |
| 6469 list->end = end; |
| 6470 strong_roots_list_ = list; |
| 6471 } |
| 6472 |
| 6473 |
| 6474 void Heap::UnregisterStrongRoots(Object** start) { |
| 6475 StrongRootsList* prev = NULL; |
| 6476 StrongRootsList* list = strong_roots_list_; |
| 6477 while (list != nullptr) { |
| 6478 StrongRootsList* next = list->next; |
| 6479 if (list->start == start) { |
| 6480 if (prev) { |
| 6481 prev->next = next; |
| 6482 } else { |
| 6483 strong_roots_list_ = next; |
| 6484 } |
| 6485 delete list; |
| 6486 } else { |
| 6487 prev = list; |
| 6488 } |
| 6489 list = next; |
| 6490 } |
| 6491 } |
6442 } | 6492 } |
6443 } // namespace v8::internal | 6493 } // namespace v8::internal |
OLD | NEW |