diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2013-06-11 23:45:46 +0200 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2013-06-11 23:46:00 +0200 |
commit | 6dd78074a3c0a7579ca5e919021587c22ff763ae (patch) | |
tree | e225460f8e76126f4e4b2e1809dbd4c9c2ba511b /deps/v8/src/global-handles.cc | |
parent | 9ae1d182ba98629ac7c7b9100022ac93133494b7 (diff) | |
download | android-node-v8-6dd78074a3c0a7579ca5e919021587c22ff763ae.tar.gz android-node-v8-6dd78074a3c0a7579ca5e919021587c22ff763ae.tar.bz2 android-node-v8-6dd78074a3c0a7579ca5e919021587c22ff763ae.zip |
v8: upgrade to v3.19.13
Diffstat (limited to 'deps/v8/src/global-handles.cc')
-rw-r--r-- | deps/v8/src/global-handles.cc | 146 |
1 files changed, 67 insertions, 79 deletions
diff --git a/deps/v8/src/global-handles.cc b/deps/v8/src/global-handles.cc index 29432bb5b7..b601e99900 100644 --- a/deps/v8/src/global-handles.cc +++ b/deps/v8/src/global-handles.cc @@ -25,9 +25,6 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// TODO(dcarney): remove -#define V8_ALLOW_ACCESS_TO_PERSISTENT_IMPLICIT - #include "v8.h" #include "api.h" @@ -92,7 +89,7 @@ class GlobalHandles::Node { set_partially_dependent(false); set_in_new_space_list(false); parameter_or_next_free_.next_free = NULL; - near_death_callback_ = NULL; + weak_reference_callback_ = NULL; } #endif @@ -105,7 +102,7 @@ class GlobalHandles::Node { *first_free = this; } - void Acquire(Object* object, GlobalHandles* global_handles) { + void Acquire(Object* object) { ASSERT(state() == FREE); object_ = object; class_id_ = v8::HeapProfiler::kPersistentHandleNoClassId; @@ -113,11 +110,11 @@ class GlobalHandles::Node { set_partially_dependent(false); set_state(NORMAL); parameter_or_next_free_.parameter = NULL; - near_death_callback_ = NULL; - IncreaseBlockUses(global_handles); + weak_reference_callback_ = NULL; + IncreaseBlockUses(); } - void Release(GlobalHandles* global_handles) { + void Release() { ASSERT(state() != FREE); set_state(FREE); #ifdef ENABLE_EXTRA_CHECKS @@ -126,11 +123,9 @@ class GlobalHandles::Node { class_id_ = v8::HeapProfiler::kPersistentHandleNoClassId; set_independent(false); set_partially_dependent(false); - near_death_callback_ = NULL; + weak_reference_callback_ = NULL; #endif - parameter_or_next_free_.next_free = global_handles->first_free_; - global_handles->first_free_ = this; - DecreaseBlockUses(global_handles); + DecreaseBlockUses(); } // Object slot accessors. @@ -201,9 +196,9 @@ class GlobalHandles::Node { set_independent(true); } - void MarkPartiallyDependent(GlobalHandles* global_handles) { + void MarkPartiallyDependent() { ASSERT(state() != FREE); - if (global_handles->isolate()->heap()->InNewSpace(object_)) { + if (GetGlobalHandles()->isolate()->heap()->InNewSpace(object_)) { set_partially_dependent(true); } } @@ -233,41 +228,31 @@ class GlobalHandles::Node { parameter_or_next_free_.next_free = value; } - void MakeWeak(GlobalHandles* global_handles, - void* parameter, - RevivableCallback weak_reference_callback, - NearDeathCallback near_death_callback) { + void MakeWeak(void* parameter, + RevivableCallback weak_reference_callback) { ASSERT(state() != FREE); set_state(WEAK); set_parameter(parameter); - if (weak_reference_callback != NULL) { - flags_ = IsWeakCallback::update(flags_, true); - near_death_callback_ = - reinterpret_cast<NearDeathCallback>(weak_reference_callback); - } else { - flags_ = IsWeakCallback::update(flags_, false); - near_death_callback_ = near_death_callback; - } + weak_reference_callback_ = weak_reference_callback; } - void ClearWeakness(GlobalHandles* global_handles) { + void ClearWeakness() { ASSERT(state() != FREE); set_state(NORMAL); set_parameter(NULL); } - bool PostGarbageCollectionProcessing(Isolate* isolate, - GlobalHandles* global_handles) { + bool PostGarbageCollectionProcessing(Isolate* isolate) { if (state() != Node::PENDING) return false; - if (near_death_callback_ == NULL) { - Release(global_handles); + if (weak_reference_callback_ == NULL) { + Release(); return false; } void* par = parameter(); set_state(NEAR_DEATH); set_parameter(NULL); - v8::Persistent<v8::Value> object = ToApi<v8::Value>(handle()); + Object** object = location(); { // Check that we are not passing a finalized external string to // the callback. @@ -277,19 +262,9 @@ class GlobalHandles::Node { ExternalTwoByteString::cast(object_)->resource() != NULL); // Leaving V8. VMState<EXTERNAL> state(isolate); - if (near_death_callback_ != NULL) { - if (IsWeakCallback::decode(flags_)) { - RevivableCallback callback = - reinterpret_cast<RevivableCallback>(near_death_callback_); - callback(reinterpret_cast<v8::Isolate*>(isolate), - &object, - par); - } else { - near_death_callback_(reinterpret_cast<v8::Isolate*>(isolate), - object, + weak_reference_callback_(reinterpret_cast<v8::Isolate*>(isolate), + reinterpret_cast<Persistent<Value>*>(&object), par); - } - } } // Absence of explicit cleanup or revival of weak handle // in most of the cases would lead to memory leak. @@ -299,8 +274,9 @@ class GlobalHandles::Node { private: inline NodeBlock* FindBlock(); - inline void IncreaseBlockUses(GlobalHandles* global_handles); - inline void DecreaseBlockUses(GlobalHandles* global_handles); + inline GlobalHandles* GetGlobalHandles(); + inline void IncreaseBlockUses(); + inline void DecreaseBlockUses(); // Storage for object pointer. // Placed first to avoid offset computation. @@ -321,12 +297,11 @@ class GlobalHandles::Node { class IsIndependent: public BitField<bool, 4, 1> {}; class IsPartiallyDependent: public BitField<bool, 5, 1> {}; class IsInNewSpaceList: public BitField<bool, 6, 1> {}; - class IsWeakCallback: public BitField<bool, 7, 1> {}; uint8_t flags_; // Handle specific callback - might be a weak reference in disguise. - NearDeathCallback near_death_callback_; + RevivableCallback weak_reference_callback_; // Provided data for callback. In FREE state, this is used for // the free list link. @@ -343,8 +318,12 @@ class GlobalHandles::NodeBlock { public: static const int kSize = 256; - explicit NodeBlock(NodeBlock* next) - : next_(next), used_nodes_(0), next_used_(NULL), prev_used_(NULL) {} + explicit NodeBlock(GlobalHandles* global_handles, NodeBlock* next) + : next_(next), + used_nodes_(0), + next_used_(NULL), + prev_used_(NULL), + global_handles_(global_handles) {} void PutNodesOnFreeList(Node** first_free) { for (int i = kSize - 1; i >= 0; --i) { @@ -357,11 +336,11 @@ class GlobalHandles::NodeBlock { return &nodes_[index]; } - void IncreaseUses(GlobalHandles* global_handles) { + void IncreaseUses() { ASSERT(used_nodes_ < kSize); if (used_nodes_++ == 0) { - NodeBlock* old_first = global_handles->first_used_block_; - global_handles->first_used_block_ = this; + NodeBlock* old_first = global_handles_->first_used_block_; + global_handles_->first_used_block_ = this; next_used_ = old_first; prev_used_ = NULL; if (old_first == NULL) return; @@ -369,17 +348,19 @@ class GlobalHandles::NodeBlock { } } - void DecreaseUses(GlobalHandles* global_handles) { + void DecreaseUses() { ASSERT(used_nodes_ > 0); if (--used_nodes_ == 0) { if (next_used_ != NULL) next_used_->prev_used_ = prev_used_; if (prev_used_ != NULL) prev_used_->next_used_ = next_used_; - if (this == global_handles->first_used_block_) { - global_handles->first_used_block_ = next_used_; + if (this == global_handles_->first_used_block_) { + global_handles_->first_used_block_ = next_used_; } } } + GlobalHandles* global_handles() { return global_handles_; } + // Next block in the list of all blocks. NodeBlock* next() const { return next_; } @@ -393,9 +374,15 @@ class GlobalHandles::NodeBlock { int used_nodes_; NodeBlock* next_used_; NodeBlock* prev_used_; + GlobalHandles* global_handles_; }; +GlobalHandles* GlobalHandles::Node::GetGlobalHandles() { + return FindBlock()->global_handles(); +} + + GlobalHandles::NodeBlock* GlobalHandles::Node::FindBlock() { intptr_t ptr = reinterpret_cast<intptr_t>(this); ptr = ptr - index_ * sizeof(Node); @@ -405,13 +392,23 @@ GlobalHandles::NodeBlock* GlobalHandles::Node::FindBlock() { } -void GlobalHandles::Node::IncreaseBlockUses(GlobalHandles* global_handles) { - FindBlock()->IncreaseUses(global_handles); +void GlobalHandles::Node::IncreaseBlockUses() { + NodeBlock* node_block = FindBlock(); + node_block->IncreaseUses(); + GlobalHandles* global_handles = node_block->global_handles(); + global_handles->isolate()->counters()->global_handles()->Increment(); + global_handles->number_of_global_handles_++; } -void GlobalHandles::Node::DecreaseBlockUses(GlobalHandles* global_handles) { - FindBlock()->DecreaseUses(global_handles); +void GlobalHandles::Node::DecreaseBlockUses() { + NodeBlock* node_block = FindBlock(); + GlobalHandles* global_handles = node_block->global_handles(); + parameter_or_next_free_.next_free = global_handles->first_free_; + global_handles->first_free_ = this; + node_block->DecreaseUses(); + global_handles->isolate()->counters()->global_handles()->Decrement(); + global_handles->number_of_global_handles_--; } @@ -465,17 +462,15 @@ GlobalHandles::~GlobalHandles() { Handle<Object> GlobalHandles::Create(Object* value) { - isolate_->counters()->global_handles()->Increment(); - number_of_global_handles_++; if (first_free_ == NULL) { - first_block_ = new NodeBlock(first_block_); + first_block_ = new NodeBlock(this, first_block_); first_block_->PutNodesOnFreeList(&first_free_); } ASSERT(first_free_ != NULL); // Take the first node in the free list. Node* result = first_free_; first_free_ = result->next_free(); - result->Acquire(value, this); + result->Acquire(value); if (isolate_->heap()->InNewSpace(value) && !result->is_in_new_space_list()) { new_space_nodes_.Add(result); @@ -486,27 +481,20 @@ Handle<Object> GlobalHandles::Create(Object* value) { void GlobalHandles::Destroy(Object** location) { - isolate_->counters()->global_handles()->Decrement(); - number_of_global_handles_--; - if (location == NULL) return; - Node::FromLocation(location)->Release(this); + if (location != NULL) Node::FromLocation(location)->Release(); } void GlobalHandles::MakeWeak(Object** location, void* parameter, - RevivableCallback weak_reference_callback, - NearDeathCallback near_death_callback) { - ASSERT((weak_reference_callback == NULL) != (near_death_callback == NULL)); - Node::FromLocation(location)->MakeWeak(this, - parameter, - weak_reference_callback, - near_death_callback); + RevivableCallback weak_reference_callback) { + ASSERT(weak_reference_callback != NULL); + Node::FromLocation(location)->MakeWeak(parameter, weak_reference_callback); } void GlobalHandles::ClearWeakness(Object** location) { - Node::FromLocation(location)->ClearWeakness(this); + Node::FromLocation(location)->ClearWeakness(); } @@ -516,7 +504,7 @@ void GlobalHandles::MarkIndependent(Object** location) { void GlobalHandles::MarkPartiallyDependent(Object** location) { - Node::FromLocation(location)->MarkPartiallyDependent(this); + Node::FromLocation(location)->MarkPartiallyDependent(); } @@ -653,7 +641,7 @@ bool GlobalHandles::PostGarbageCollectionProcessing( continue; } node->clear_partially_dependent(); - if (node->PostGarbageCollectionProcessing(isolate_, this)) { + if (node->PostGarbageCollectionProcessing(isolate_)) { if (initial_post_gc_processing_count != post_gc_processing_count_) { // Weak callback triggered another GC and another round of // PostGarbageCollection processing. The current node might @@ -669,7 +657,7 @@ bool GlobalHandles::PostGarbageCollectionProcessing( } else { for (NodeIterator it(this); !it.done(); it.Advance()) { it.node()->clear_partially_dependent(); - if (it.node()->PostGarbageCollectionProcessing(isolate_, this)) { + if (it.node()->PostGarbageCollectionProcessing(isolate_)) { if (initial_post_gc_processing_count != post_gc_processing_count_) { // See the comment above. return next_gc_likely_to_collect_more; |