Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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/api.h" | 7 #include "src/api.h" |
| 8 #include "src/global-handles.h" | 8 #include "src/global-handles.h" |
| 9 | 9 |
| 10 #include "src/vm-state-inl.h" | 10 #include "src/vm-state-inl.h" |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 493 int index_; | 493 int index_; |
| 494 | 494 |
| 495 DISALLOW_COPY_AND_ASSIGN(NodeIterator); | 495 DISALLOW_COPY_AND_ASSIGN(NodeIterator); |
| 496 }; | 496 }; |
| 497 | 497 |
| 498 class GlobalHandles::PendingPhantomCallbacksSecondPassTask : public v8::Task { | 498 class GlobalHandles::PendingPhantomCallbacksSecondPassTask : public v8::Task { |
| 499 public: | 499 public: |
| 500 // Takes ownership of the contents of pending_phantom_callbacks, leaving it in | 500 // Takes ownership of the contents of pending_phantom_callbacks, leaving it in |
| 501 // the same state it would be after a call to Clear(). | 501 // the same state it would be after a call to Clear(). |
| 502 PendingPhantomCallbacksSecondPassTask( | 502 PendingPhantomCallbacksSecondPassTask( |
| 503 GlobalHandles* global_handles, | |
| 503 List<PendingPhantomCallback>* pending_phantom_callbacks, Isolate* isolate) | 504 List<PendingPhantomCallback>* pending_phantom_callbacks, Isolate* isolate) |
| 504 : isolate_(isolate) { | 505 : global_handles_(global_handles), |
| 506 isolate_(isolate), | |
| 507 heap_is_torn_down_(false) { | |
| 505 pending_phantom_callbacks_.Swap(pending_phantom_callbacks); | 508 pending_phantom_callbacks_.Swap(pending_phantom_callbacks); |
| 506 } | 509 } |
| 507 | 510 |
| 508 ~PendingPhantomCallbacksSecondPassTask() override {} | 511 ~PendingPhantomCallbacksSecondPassTask() override { |
| 512 if (!heap_is_torn_down_) { | |
| 513 global_handles_->ClearPhantomCallbacksTask(this); | |
| 514 } | |
| 515 } | |
| 509 | 516 |
| 510 void Run() override { | 517 void Run() override { |
| 511 InvokeSecondPassPhantomCallbacks(&pending_phantom_callbacks_, isolate_); | 518 if (!heap_is_torn_down_) { |
| 519 InvokeSecondPassPhantomCallbacks(&pending_phantom_callbacks_, isolate_); | |
| 520 } | |
| 512 } | 521 } |
| 513 | 522 |
| 523 void NotifyHeapTearDown() { heap_is_torn_down_ = true; } | |
| 524 | |
| 514 private: | 525 private: |
| 526 GlobalHandles* global_handles_; | |
| 515 List<PendingPhantomCallback> pending_phantom_callbacks_; | 527 List<PendingPhantomCallback> pending_phantom_callbacks_; |
| 516 Isolate* isolate_; | 528 Isolate* isolate_; |
| 529 bool heap_is_torn_down_; | |
| 517 | 530 |
| 518 DISALLOW_COPY_AND_ASSIGN(PendingPhantomCallbacksSecondPassTask); | 531 DISALLOW_COPY_AND_ASSIGN(PendingPhantomCallbacksSecondPassTask); |
| 519 }; | 532 }; |
| 520 | 533 |
| 521 | 534 |
| 522 GlobalHandles::GlobalHandles(Isolate* isolate) | 535 GlobalHandles::GlobalHandles(Isolate* isolate) |
| 523 : isolate_(isolate), | 536 : isolate_(isolate), |
| 524 number_of_global_handles_(0), | 537 number_of_global_handles_(0), |
| 525 first_block_(NULL), | 538 first_block_(NULL), |
| 526 first_used_block_(NULL), | 539 first_used_block_(NULL), |
| 527 first_free_(NULL), | 540 first_free_(NULL), |
| 528 post_gc_processing_count_(0), | 541 post_gc_processing_count_(0), |
| 529 object_group_connections_(kObjectGroupConnectionsCapacity) {} | 542 object_group_connections_(kObjectGroupConnectionsCapacity), |
| 543 phantom_callbacks_task_(nullptr) {} | |
| 530 | 544 |
| 531 | 545 |
| 532 GlobalHandles::~GlobalHandles() { | 546 GlobalHandles::~GlobalHandles() { |
| 533 NodeBlock* block = first_block_; | 547 NodeBlock* block = first_block_; |
| 534 while (block != NULL) { | 548 while (block != NULL) { |
| 535 NodeBlock* tmp = block->next(); | 549 NodeBlock* tmp = block->next(); |
| 536 delete block; | 550 delete block; |
| 537 block = tmp; | 551 block = tmp; |
| 538 } | 552 } |
| 539 first_block_ = NULL; | 553 first_block_ = NULL; |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 820 } else { | 834 } else { |
| 821 node->set_in_new_space_list(false); | 835 node->set_in_new_space_list(false); |
| 822 isolate_->heap()->IncrementNodesDiedInNewSpace(); | 836 isolate_->heap()->IncrementNodesDiedInNewSpace(); |
| 823 } | 837 } |
| 824 } | 838 } |
| 825 new_space_nodes_.Rewind(last); | 839 new_space_nodes_.Rewind(last); |
| 826 new_space_nodes_.Trim(); | 840 new_space_nodes_.Trim(); |
| 827 } | 841 } |
| 828 | 842 |
| 829 | 843 |
| 844 void GlobalHandles::ClearPhantomCallbacksTask( | |
| 845 PendingPhantomCallbacksSecondPassTask* task) { | |
| 846 if (phantom_callbacks_task_ == task) { | |
| 847 phantom_callbacks_task_ = nullptr; | |
| 848 } | |
| 849 } | |
| 850 | |
| 851 | |
| 830 int GlobalHandles::DispatchPendingPhantomCallbacks( | 852 int GlobalHandles::DispatchPendingPhantomCallbacks( |
| 831 bool synchronous_second_pass) { | 853 bool synchronous_second_pass) { |
| 832 int freed_nodes = 0; | 854 int freed_nodes = 0; |
| 833 { | 855 { |
| 834 // The initial pass callbacks must simply clear the nodes. | 856 // The initial pass callbacks must simply clear the nodes. |
| 835 for (auto i = pending_phantom_callbacks_.begin(); | 857 for (auto i = pending_phantom_callbacks_.begin(); |
| 836 i != pending_phantom_callbacks_.end(); ++i) { | 858 i != pending_phantom_callbacks_.end(); ++i) { |
| 837 auto callback = i; | 859 auto callback = i; |
| 838 // Skip callbacks that have already been processed once. | 860 // Skip callbacks that have already been processed once. |
| 839 if (callback->node() == nullptr) continue; | 861 if (callback->node() == nullptr) continue; |
| 840 callback->Invoke(isolate()); | 862 callback->Invoke(isolate()); |
| 841 freed_nodes++; | 863 freed_nodes++; |
| 842 } | 864 } |
| 843 } | 865 } |
| 844 if (pending_phantom_callbacks_.length() > 0) { | 866 if (pending_phantom_callbacks_.length() > 0) { |
| 845 if (synchronous_second_pass) { | 867 if (synchronous_second_pass) { |
| 846 InvokeSecondPassPhantomCallbacks(&pending_phantom_callbacks_, isolate()); | 868 InvokeSecondPassPhantomCallbacks(&pending_phantom_callbacks_, isolate()); |
| 847 } else { | 869 } else { |
| 848 auto* task = new PendingPhantomCallbacksSecondPassTask( | 870 phantom_callbacks_task_ = new PendingPhantomCallbacksSecondPassTask( |
| 849 &pending_phantom_callbacks_, isolate()); | 871 this, &pending_phantom_callbacks_, isolate()); |
| 850 V8::GetCurrentPlatform()->CallOnForegroundThread( | 872 V8::GetCurrentPlatform()->CallOnForegroundThread( |
| 851 reinterpret_cast<v8::Isolate*>(isolate()), task); | 873 reinterpret_cast<v8::Isolate*>(isolate()), phantom_callbacks_task_); |
|
jochen (gone - plz use gerrit)
2015/07/20 09:58:17
there could be more than one task, no?
maybe it's
epertoso
2015/07/20 13:14:21
Done.
| |
| 852 } | 874 } |
| 853 } | 875 } |
| 854 pending_phantom_callbacks_.Clear(); | 876 pending_phantom_callbacks_.Clear(); |
| 855 return freed_nodes; | 877 return freed_nodes; |
| 856 } | 878 } |
| 857 | 879 |
| 858 | 880 |
| 859 void GlobalHandles::PendingPhantomCallback::Invoke(Isolate* isolate) { | 881 void GlobalHandles::PendingPhantomCallback::Invoke(Isolate* isolate) { |
| 860 Data::Callback* callback_addr = nullptr; | 882 Data::Callback* callback_addr = nullptr; |
| 861 if (node_ != nullptr) { | 883 if (node_ != nullptr) { |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1093 void GlobalHandles::RemoveImplicitRefGroups() { | 1115 void GlobalHandles::RemoveImplicitRefGroups() { |
| 1094 for (int i = 0; i < implicit_ref_groups_.length(); i++) { | 1116 for (int i = 0; i < implicit_ref_groups_.length(); i++) { |
| 1095 delete implicit_ref_groups_.at(i); | 1117 delete implicit_ref_groups_.at(i); |
| 1096 } | 1118 } |
| 1097 implicit_ref_groups_.Clear(); | 1119 implicit_ref_groups_.Clear(); |
| 1098 implicit_ref_connections_.Clear(); | 1120 implicit_ref_connections_.Clear(); |
| 1099 } | 1121 } |
| 1100 | 1122 |
| 1101 | 1123 |
| 1102 void GlobalHandles::TearDown() { | 1124 void GlobalHandles::TearDown() { |
| 1125 if (phantom_callbacks_task_) { | |
| 1126 phantom_callbacks_task_->NotifyHeapTearDown(); | |
| 1127 } | |
| 1103 // TODO(1428): invoke weak callbacks. | 1128 // TODO(1428): invoke weak callbacks. |
| 1104 } | 1129 } |
| 1105 | 1130 |
| 1106 | 1131 |
| 1107 void GlobalHandles::ComputeObjectGroupsAndImplicitReferences() { | 1132 void GlobalHandles::ComputeObjectGroupsAndImplicitReferences() { |
| 1108 if (object_group_connections_.length() == 0) { | 1133 if (object_group_connections_.length() == 0) { |
| 1109 for (int i = 0; i < retainer_infos_.length(); ++i) | 1134 for (int i = 0; i < retainer_infos_.length(); ++i) |
| 1110 retainer_infos_[i].info->Dispose(); | 1135 retainer_infos_[i].info->Dispose(); |
| 1111 retainer_infos_.Clear(); | 1136 retainer_infos_.Clear(); |
| 1112 implicit_ref_connections_.Clear(); | 1137 implicit_ref_connections_.Clear(); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1267 blocks_[block][offset] = object; | 1292 blocks_[block][offset] = object; |
| 1268 if (isolate->heap()->InNewSpace(object)) { | 1293 if (isolate->heap()->InNewSpace(object)) { |
| 1269 new_space_indices_.Add(size_); | 1294 new_space_indices_.Add(size_); |
| 1270 } | 1295 } |
| 1271 *index = size_++; | 1296 *index = size_++; |
| 1272 } | 1297 } |
| 1273 | 1298 |
| 1274 | 1299 |
| 1275 } // namespace internal | 1300 } // namespace internal |
| 1276 } // namespace v8 | 1301 } // namespace v8 |
| OLD | NEW |