Commit 36694884 authored by dcarney@chromium.org's avatar dcarney@chromium.org

de-isolate Persistent::Dispose

R=svenpanne@chromium.org
BUG=

Review URL: https://codereview.chromium.org/15648008

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14764 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 2cbc81a5
...@@ -4541,8 +4541,7 @@ class V8EXPORT V8 { ...@@ -4541,8 +4541,7 @@ class V8EXPORT V8 {
static internal::Object** GlobalizeReference(internal::Isolate* isolate, static internal::Object** GlobalizeReference(internal::Isolate* isolate,
internal::Object** handle); internal::Object** handle);
static void DisposeGlobal(internal::Isolate* isolate, static void DisposeGlobal(internal::Object** global_handle);
internal::Object** global_handle);
typedef WeakReferenceCallbacks<Value, void>::Revivable RevivableCallback; typedef WeakReferenceCallbacks<Value, void>::Revivable RevivableCallback;
static void MakeWeak(internal::Isolate* isolate, static void MakeWeak(internal::Isolate* isolate,
internal::Object** global_handle, internal::Object** global_handle,
...@@ -5486,18 +5485,17 @@ bool Persistent<T>::IsWeak(Isolate* isolate) const { ...@@ -5486,18 +5485,17 @@ bool Persistent<T>::IsWeak(Isolate* isolate) const {
template <class T> template <class T>
void Persistent<T>::Dispose() { void Persistent<T>::Dispose() {
Dispose(Isolate::GetCurrent()); if (this->IsEmpty()) return;
V8::DisposeGlobal(reinterpret_cast<internal::Object**>(this->val_));
#ifndef V8_USE_UNSAFE_HANDLES
val_ = 0;
#endif
} }
template <class T> template <class T>
void Persistent<T>::Dispose(Isolate* isolate) { void Persistent<T>::Dispose(Isolate* isolate) {
if (this->IsEmpty()) return; Dispose();
V8::DisposeGlobal(reinterpret_cast<internal::Isolate*>(isolate),
reinterpret_cast<internal::Object**>(this->val_));
#ifndef V8_USE_UNSAFE_HANDLES
val_ = 0;
#endif
} }
......
...@@ -645,11 +645,8 @@ void V8::ClearWeak(i::Isolate* isolate, i::Object** obj) { ...@@ -645,11 +645,8 @@ void V8::ClearWeak(i::Isolate* isolate, i::Object** obj) {
} }
void V8::DisposeGlobal(i::Isolate* isolate, i::Object** obj) { void V8::DisposeGlobal(i::Object** obj) {
ASSERT(isolate == i::Isolate::Current()); i::GlobalHandles::Destroy(obj);
LOG_API(isolate, "DisposeGlobal");
if (!isolate->IsInitialized()) return;
isolate->global_handles()->Destroy(obj);
} }
// --- H a n d l e s --- // --- H a n d l e s ---
......
...@@ -105,7 +105,7 @@ class GlobalHandles::Node { ...@@ -105,7 +105,7 @@ class GlobalHandles::Node {
*first_free = this; *first_free = this;
} }
void Acquire(Object* object, GlobalHandles* global_handles) { void Acquire(Object* object) {
ASSERT(state() == FREE); ASSERT(state() == FREE);
object_ = object; object_ = object;
class_id_ = v8::HeapProfiler::kPersistentHandleNoClassId; class_id_ = v8::HeapProfiler::kPersistentHandleNoClassId;
...@@ -114,10 +114,10 @@ class GlobalHandles::Node { ...@@ -114,10 +114,10 @@ class GlobalHandles::Node {
set_state(NORMAL); set_state(NORMAL);
parameter_or_next_free_.parameter = NULL; parameter_or_next_free_.parameter = NULL;
near_death_callback_ = NULL; near_death_callback_ = NULL;
IncreaseBlockUses(global_handles); IncreaseBlockUses();
} }
void Release(GlobalHandles* global_handles) { void Release() {
ASSERT(state() != FREE); ASSERT(state() != FREE);
set_state(FREE); set_state(FREE);
#ifdef ENABLE_EXTRA_CHECKS #ifdef ENABLE_EXTRA_CHECKS
...@@ -128,9 +128,7 @@ class GlobalHandles::Node { ...@@ -128,9 +128,7 @@ class GlobalHandles::Node {
set_partially_dependent(false); set_partially_dependent(false);
near_death_callback_ = NULL; near_death_callback_ = NULL;
#endif #endif
parameter_or_next_free_.next_free = global_handles->first_free_; DecreaseBlockUses();
global_handles->first_free_ = this;
DecreaseBlockUses(global_handles);
} }
// Object slot accessors. // Object slot accessors.
...@@ -256,11 +254,10 @@ class GlobalHandles::Node { ...@@ -256,11 +254,10 @@ class GlobalHandles::Node {
set_parameter(NULL); set_parameter(NULL);
} }
bool PostGarbageCollectionProcessing(Isolate* isolate, bool PostGarbageCollectionProcessing(Isolate* isolate) {
GlobalHandles* global_handles) {
if (state() != Node::PENDING) return false; if (state() != Node::PENDING) return false;
if (near_death_callback_ == NULL) { if (near_death_callback_ == NULL) {
Release(global_handles); Release();
return false; return false;
} }
void* par = parameter(); void* par = parameter();
...@@ -299,8 +296,8 @@ class GlobalHandles::Node { ...@@ -299,8 +296,8 @@ class GlobalHandles::Node {
private: private:
inline NodeBlock* FindBlock(); inline NodeBlock* FindBlock();
inline void IncreaseBlockUses(GlobalHandles* global_handles); inline void IncreaseBlockUses();
inline void DecreaseBlockUses(GlobalHandles* global_handles); inline void DecreaseBlockUses();
// Storage for object pointer. // Storage for object pointer.
// Placed first to avoid offset computation. // Placed first to avoid offset computation.
...@@ -343,8 +340,12 @@ class GlobalHandles::NodeBlock { ...@@ -343,8 +340,12 @@ class GlobalHandles::NodeBlock {
public: public:
static const int kSize = 256; static const int kSize = 256;
explicit NodeBlock(NodeBlock* next) explicit NodeBlock(GlobalHandles* global_handles, NodeBlock* next)
: next_(next), used_nodes_(0), next_used_(NULL), prev_used_(NULL) {} : next_(next),
used_nodes_(0),
next_used_(NULL),
prev_used_(NULL),
global_handles_(global_handles) {}
void PutNodesOnFreeList(Node** first_free) { void PutNodesOnFreeList(Node** first_free) {
for (int i = kSize - 1; i >= 0; --i) { for (int i = kSize - 1; i >= 0; --i) {
...@@ -357,11 +358,11 @@ class GlobalHandles::NodeBlock { ...@@ -357,11 +358,11 @@ class GlobalHandles::NodeBlock {
return &nodes_[index]; return &nodes_[index];
} }
void IncreaseUses(GlobalHandles* global_handles) { void IncreaseUses() {
ASSERT(used_nodes_ < kSize); ASSERT(used_nodes_ < kSize);
if (used_nodes_++ == 0) { if (used_nodes_++ == 0) {
NodeBlock* old_first = global_handles->first_used_block_; NodeBlock* old_first = global_handles_->first_used_block_;
global_handles->first_used_block_ = this; global_handles_->first_used_block_ = this;
next_used_ = old_first; next_used_ = old_first;
prev_used_ = NULL; prev_used_ = NULL;
if (old_first == NULL) return; if (old_first == NULL) return;
...@@ -369,17 +370,19 @@ class GlobalHandles::NodeBlock { ...@@ -369,17 +370,19 @@ class GlobalHandles::NodeBlock {
} }
} }
void DecreaseUses(GlobalHandles* global_handles) { void DecreaseUses() {
ASSERT(used_nodes_ > 0); ASSERT(used_nodes_ > 0);
if (--used_nodes_ == 0) { if (--used_nodes_ == 0) {
if (next_used_ != NULL) next_used_->prev_used_ = prev_used_; if (next_used_ != NULL) next_used_->prev_used_ = prev_used_;
if (prev_used_ != NULL) prev_used_->next_used_ = next_used_; if (prev_used_ != NULL) prev_used_->next_used_ = next_used_;
if (this == global_handles->first_used_block_) { if (this == global_handles_->first_used_block_) {
global_handles->first_used_block_ = next_used_; global_handles_->first_used_block_ = next_used_;
} }
} }
} }
GlobalHandles* global_handles() { return global_handles_; }
// Next block in the list of all blocks. // Next block in the list of all blocks.
NodeBlock* next() const { return next_; } NodeBlock* next() const { return next_; }
...@@ -393,6 +396,7 @@ class GlobalHandles::NodeBlock { ...@@ -393,6 +396,7 @@ class GlobalHandles::NodeBlock {
int used_nodes_; int used_nodes_;
NodeBlock* next_used_; NodeBlock* next_used_;
NodeBlock* prev_used_; NodeBlock* prev_used_;
GlobalHandles* global_handles_;
}; };
...@@ -405,13 +409,23 @@ GlobalHandles::NodeBlock* GlobalHandles::Node::FindBlock() { ...@@ -405,13 +409,23 @@ GlobalHandles::NodeBlock* GlobalHandles::Node::FindBlock() {
} }
void GlobalHandles::Node::IncreaseBlockUses(GlobalHandles* global_handles) { void GlobalHandles::Node::IncreaseBlockUses() {
FindBlock()->IncreaseUses(global_handles); 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) { void GlobalHandles::Node::DecreaseBlockUses() {
FindBlock()->DecreaseUses(global_handles); 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 +479,15 @@ GlobalHandles::~GlobalHandles() { ...@@ -465,17 +479,15 @@ GlobalHandles::~GlobalHandles() {
Handle<Object> GlobalHandles::Create(Object* value) { Handle<Object> GlobalHandles::Create(Object* value) {
isolate_->counters()->global_handles()->Increment();
number_of_global_handles_++;
if (first_free_ == NULL) { if (first_free_ == NULL) {
first_block_ = new NodeBlock(first_block_); first_block_ = new NodeBlock(this, first_block_);
first_block_->PutNodesOnFreeList(&first_free_); first_block_->PutNodesOnFreeList(&first_free_);
} }
ASSERT(first_free_ != NULL); ASSERT(first_free_ != NULL);
// Take the first node in the free list. // Take the first node in the free list.
Node* result = first_free_; Node* result = first_free_;
first_free_ = result->next_free(); first_free_ = result->next_free();
result->Acquire(value, this); result->Acquire(value);
if (isolate_->heap()->InNewSpace(value) && if (isolate_->heap()->InNewSpace(value) &&
!result->is_in_new_space_list()) { !result->is_in_new_space_list()) {
new_space_nodes_.Add(result); new_space_nodes_.Add(result);
...@@ -486,10 +498,7 @@ Handle<Object> GlobalHandles::Create(Object* value) { ...@@ -486,10 +498,7 @@ Handle<Object> GlobalHandles::Create(Object* value) {
void GlobalHandles::Destroy(Object** location) { void GlobalHandles::Destroy(Object** location) {
isolate_->counters()->global_handles()->Decrement(); if (location != NULL) Node::FromLocation(location)->Release();
number_of_global_handles_--;
if (location == NULL) return;
Node::FromLocation(location)->Release(this);
} }
...@@ -653,7 +662,7 @@ bool GlobalHandles::PostGarbageCollectionProcessing( ...@@ -653,7 +662,7 @@ bool GlobalHandles::PostGarbageCollectionProcessing(
continue; continue;
} }
node->clear_partially_dependent(); node->clear_partially_dependent();
if (node->PostGarbageCollectionProcessing(isolate_, this)) { if (node->PostGarbageCollectionProcessing(isolate_)) {
if (initial_post_gc_processing_count != post_gc_processing_count_) { if (initial_post_gc_processing_count != post_gc_processing_count_) {
// Weak callback triggered another GC and another round of // Weak callback triggered another GC and another round of
// PostGarbageCollection processing. The current node might // PostGarbageCollection processing. The current node might
...@@ -669,7 +678,7 @@ bool GlobalHandles::PostGarbageCollectionProcessing( ...@@ -669,7 +678,7 @@ bool GlobalHandles::PostGarbageCollectionProcessing(
} else { } else {
for (NodeIterator it(this); !it.done(); it.Advance()) { for (NodeIterator it(this); !it.done(); it.Advance()) {
it.node()->clear_partially_dependent(); 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_) { if (initial_post_gc_processing_count != post_gc_processing_count_) {
// See the comment above. // See the comment above.
return next_gc_likely_to_collect_more; return next_gc_likely_to_collect_more;
......
...@@ -128,7 +128,7 @@ class GlobalHandles { ...@@ -128,7 +128,7 @@ class GlobalHandles {
Handle<Object> Create(Object* value); Handle<Object> Create(Object* value);
// Destroy a global handle. // Destroy a global handle.
void Destroy(Object** location); static void Destroy(Object** location);
typedef WeakReferenceCallbacks<v8::Value, void>::Revivable RevivableCallback; typedef WeakReferenceCallbacks<v8::Value, void>::Revivable RevivableCallback;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment