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 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
488 block_ = block_->next_used(); | 488 block_ = block_->next_used(); |
489 } | 489 } |
490 | 490 |
491 private: | 491 private: |
492 NodeBlock* block_; | 492 NodeBlock* block_; |
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 { | |
499 public: | |
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(). | |
502 PendingPhantomCallbacksSecondPassTask( | |
503 List<PendingPhantomCallback>* pending_phantom_callbacks, Isolate* isolate) | |
504 : isolate_(isolate) { | |
505 pending_phantom_callbacks_.Swap(pending_phantom_callbacks); | |
506 } | |
507 | |
508 ~PendingPhantomCallbacksSecondPassTask() override {} | |
509 | |
510 void Run() override { | |
511 while (pending_phantom_callbacks_.length() != 0) { | |
512 auto callback = pending_phantom_callbacks_.RemoveLast(); | |
513 DCHECK(callback.node() == nullptr); | |
514 // No second pass callback required. | |
515 if (callback.callback() == nullptr) continue; | |
516 // Fire second pass callback | |
517 callback.Invoke(isolate_); | |
518 } | |
519 pending_phantom_callbacks_.Clear(); | |
520 } | |
521 | |
522 private: | |
523 List<PendingPhantomCallback> pending_phantom_callbacks_; | |
524 Isolate* isolate_; | |
525 }; | |
jochen (gone - plz use gerrit)
2015/07/03 12:42:27
nit. DISALLOW_COPY_AND_ASSIGN(PendingPhantomCallba
epertoso
2015/07/03 14:38:00
Done.
| |
526 | |
498 | 527 |
499 GlobalHandles::GlobalHandles(Isolate* isolate) | 528 GlobalHandles::GlobalHandles(Isolate* isolate) |
500 : isolate_(isolate), | 529 : isolate_(isolate), |
501 number_of_global_handles_(0), | 530 number_of_global_handles_(0), |
502 first_block_(NULL), | 531 first_block_(NULL), |
503 first_used_block_(NULL), | 532 first_used_block_(NULL), |
504 first_free_(NULL), | 533 first_free_(NULL), |
505 post_gc_processing_count_(0), | 534 post_gc_processing_count_(0), |
506 object_group_connections_(kObjectGroupConnectionsCapacity) {} | 535 object_group_connections_(kObjectGroupConnectionsCapacity) {} |
507 | 536 |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
797 // The initial pass callbacks must simply clear the nodes. | 826 // The initial pass callbacks must simply clear the nodes. |
798 for (auto i = pending_phantom_callbacks_.begin(); | 827 for (auto i = pending_phantom_callbacks_.begin(); |
799 i != pending_phantom_callbacks_.end(); ++i) { | 828 i != pending_phantom_callbacks_.end(); ++i) { |
800 auto callback = i; | 829 auto callback = i; |
801 // Skip callbacks that have already been processed once. | 830 // Skip callbacks that have already been processed once. |
802 if (callback->node() == nullptr) continue; | 831 if (callback->node() == nullptr) continue; |
803 callback->Invoke(isolate()); | 832 callback->Invoke(isolate()); |
804 freed_nodes++; | 833 freed_nodes++; |
805 } | 834 } |
806 } | 835 } |
807 // The second pass empties the list. | 836 if (pending_phantom_callbacks_.length() > 0) { |
808 while (pending_phantom_callbacks_.length() != 0) { | 837 auto* task = new PendingPhantomCallbacksSecondPassTask( |
809 auto callback = pending_phantom_callbacks_.RemoveLast(); | 838 &pending_phantom_callbacks_, isolate()); |
810 DCHECK(callback.node() == nullptr); | 839 V8::GetCurrentPlatform()->CallOnForegroundThread( |
811 // No second pass callback required. | 840 reinterpret_cast<v8::Isolate*>(isolate()), task); |
812 if (callback.callback() == nullptr) continue; | |
813 // Fire second pass callback. | |
814 callback.Invoke(isolate()); | |
815 } | 841 } |
816 pending_phantom_callbacks_.Clear(); | 842 pending_phantom_callbacks_.Clear(); |
817 return freed_nodes; | 843 return freed_nodes; |
818 } | 844 } |
819 | 845 |
820 | 846 |
821 void GlobalHandles::PendingPhantomCallback::Invoke(Isolate* isolate) { | 847 void GlobalHandles::PendingPhantomCallback::Invoke(Isolate* isolate) { |
822 Data::Callback* callback_addr = nullptr; | 848 Data::Callback* callback_addr = nullptr; |
823 if (node_ != nullptr) { | 849 if (node_ != nullptr) { |
824 // Initialize for first pass callback. | 850 // Initialize for first pass callback. |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1226 blocks_[block][offset] = object; | 1252 blocks_[block][offset] = object; |
1227 if (isolate->heap()->InNewSpace(object)) { | 1253 if (isolate->heap()->InNewSpace(object)) { |
1228 new_space_indices_.Add(size_); | 1254 new_space_indices_.Add(size_); |
1229 } | 1255 } |
1230 *index = size_++; | 1256 *index = size_++; |
1231 } | 1257 } |
1232 | 1258 |
1233 | 1259 |
1234 } // namespace internal | 1260 } // namespace internal |
1235 } // namespace v8 | 1261 } // namespace v8 |
OLD | NEW |