remove old MakeWeak

R=svenpanne@chromium.org
BUG=

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14911 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
dcarney@chromium.org 2013-06-03 08:17:04 +00:00
parent f6499289f6
commit 595d0ea8b0
14 changed files with 45 additions and 112 deletions

View File

@ -214,11 +214,6 @@ class WeakReferenceCallbacks {
P* parameter); P* parameter);
}; };
// TODO(svenpanne) Temporary definition until Chrome is in sync.
typedef void (*NearDeathCallback)(Isolate* isolate,
Persistent<Value> object,
void* parameter);
// --- Handles --- // --- Handles ---
#define TYPE_CHECK(T, S) \ #define TYPE_CHECK(T, S) \
@ -676,11 +671,6 @@ template <class T> class Persistent // NOLINT
MakeWeak<P>(parameters, callback); MakeWeak<P>(parameters, callback);
} }
// TODO(dcarney): remove before cutover
V8_INLINE(void MakeWeak(Isolate* isolate,
void* parameters,
NearDeathCallback callback));
V8_INLINE(void ClearWeak()); V8_INLINE(void ClearWeak());
// TODO(dcarney): deprecate // TODO(dcarney): deprecate
@ -4606,8 +4596,7 @@ class V8EXPORT V8 {
typedef WeakReferenceCallbacks<Value, void>::Revivable RevivableCallback; typedef WeakReferenceCallbacks<Value, void>::Revivable RevivableCallback;
static void MakeWeak(internal::Object** global_handle, static void MakeWeak(internal::Object** global_handle,
void* data, void* data,
RevivableCallback weak_reference_callback, RevivableCallback weak_reference_callback);
NearDeathCallback near_death_callback);
static void ClearWeak(internal::Object** global_handle); static void ClearWeak(internal::Object** global_handle);
template <class T> friend class Handle; template <class T> friend class Handle;
@ -5541,8 +5530,7 @@ void Persistent<T>::MakeWeak(
typedef typename WeakReferenceCallbacks<Value, void>::Revivable Revivable; typedef typename WeakReferenceCallbacks<Value, void>::Revivable Revivable;
V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_),
parameters, parameters,
reinterpret_cast<Revivable>(callback), reinterpret_cast<Revivable>(callback));
NULL);
} }
@ -5555,17 +5543,6 @@ void Persistent<T>::MakeWeak(
} }
template <class T>
void Persistent<T>::MakeWeak(Isolate* isolate,
void* parameters,
NearDeathCallback callback) {
V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_),
parameters,
NULL,
callback);
}
template <class T> template <class T>
void Persistent<T>::ClearWeak() { void Persistent<T>::ClearWeak() {
V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)); V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_));

View File

@ -627,12 +627,10 @@ i::Object** V8::GlobalizeReference(i::Isolate* isolate, i::Object** obj) {
void V8::MakeWeak(i::Object** object, void V8::MakeWeak(i::Object** object,
void* parameters, void* parameters,
RevivableCallback weak_reference_callback, RevivableCallback weak_reference_callback) {
NearDeathCallback near_death_callback) {
i::GlobalHandles::MakeWeak(object, i::GlobalHandles::MakeWeak(object,
parameters, parameters,
weak_reference_callback, weak_reference_callback);
near_death_callback);
} }

View File

@ -619,7 +619,6 @@ void ScriptCache::Add(Handle<Script> script) {
(global_handles->Create(*script))); (global_handles->Create(*script)));
global_handles->MakeWeak(reinterpret_cast<Object**>(script_.location()), global_handles->MakeWeak(reinterpret_cast<Object**>(script_.location()),
this, this,
NULL,
ScriptCache::HandleWeakScript); ScriptCache::HandleWeakScript);
entry->value = script_.location(); entry->value = script_.location();
} }
@ -664,12 +663,12 @@ void ScriptCache::Clear() {
void ScriptCache::HandleWeakScript(v8::Isolate* isolate, void ScriptCache::HandleWeakScript(v8::Isolate* isolate,
v8::Persistent<v8::Value> obj, v8::Persistent<v8::Value>* obj,
void* data) { void* data) {
ScriptCache* script_cache = reinterpret_cast<ScriptCache*>(data); ScriptCache* script_cache = reinterpret_cast<ScriptCache*>(data);
// Find the location of the global handle. // Find the location of the global handle.
Script** location = Script** location =
reinterpret_cast<Script**>(Utils::OpenHandle(*obj).location()); reinterpret_cast<Script**>(Utils::OpenHandle(**obj).location());
ASSERT((*location)->IsScript()); ASSERT((*location)->IsScript());
// Remove the entry from the cache. // Remove the entry from the cache.
@ -678,8 +677,7 @@ void ScriptCache::HandleWeakScript(v8::Isolate* isolate,
script_cache->collected_scripts_.Add(id); script_cache->collected_scripts_.Add(id);
// Clear the weak handle. // Clear the weak handle.
obj.Dispose(isolate); obj->Dispose(isolate);
obj.Clear();
} }
@ -699,7 +697,7 @@ void Debug::SetUp(bool create_heap_objects) {
void Debug::HandleWeakDebugInfo(v8::Isolate* isolate, void Debug::HandleWeakDebugInfo(v8::Isolate* isolate,
v8::Persistent<v8::Value> obj, v8::Persistent<v8::Value>* obj,
void* data) { void* data) {
Debug* debug = reinterpret_cast<Isolate*>(isolate)->debug(); Debug* debug = reinterpret_cast<Isolate*>(isolate)->debug();
DebugInfoListNode* node = reinterpret_cast<DebugInfoListNode*>(data); DebugInfoListNode* node = reinterpret_cast<DebugInfoListNode*>(data);
@ -727,7 +725,6 @@ DebugInfoListNode::DebugInfoListNode(DebugInfo* debug_info): next_(NULL) {
(global_handles->Create(debug_info))); (global_handles->Create(debug_info)));
global_handles->MakeWeak(reinterpret_cast<Object**>(debug_info_.location()), global_handles->MakeWeak(reinterpret_cast<Object**>(debug_info_.location()),
this, this,
NULL,
Debug::HandleWeakDebugInfo); Debug::HandleWeakDebugInfo);
} }

View File

@ -190,7 +190,7 @@ class ScriptCache : private HashMap {
// Weak handle callback for scripts in the cache. // Weak handle callback for scripts in the cache.
static void HandleWeakScript(v8::Isolate* isolate, static void HandleWeakScript(v8::Isolate* isolate,
v8::Persistent<v8::Value> obj, v8::Persistent<v8::Value>* obj,
void* data); void* data);
// List used during GC to temporarily store id's of collected scripts. // List used during GC to temporarily store id's of collected scripts.
@ -387,7 +387,7 @@ class Debug {
// Passed to MakeWeak. // Passed to MakeWeak.
static void HandleWeakDebugInfo(v8::Isolate* isolate, static void HandleWeakDebugInfo(v8::Isolate* isolate,
v8::Persistent<v8::Value> obj, v8::Persistent<v8::Value>* obj,
void* data); void* data);
friend class Debugger; friend class Debugger;

View File

@ -463,7 +463,7 @@ void Deoptimizer::DeoptimizeAllFunctionsWith(Isolate* isolate,
void Deoptimizer::HandleWeakDeoptimizedCode(v8::Isolate* isolate, void Deoptimizer::HandleWeakDeoptimizedCode(v8::Isolate* isolate,
v8::Persistent<v8::Value> obj, v8::Persistent<v8::Value>* obj,
void* parameter) { void* parameter) {
DeoptimizingCodeListNode* node = DeoptimizingCodeListNode* node =
reinterpret_cast<DeoptimizingCodeListNode*>(parameter); reinterpret_cast<DeoptimizingCodeListNode*>(parameter);
@ -2750,7 +2750,6 @@ DeoptimizingCodeListNode::DeoptimizingCodeListNode(Code* code): next_(NULL) {
code_ = Handle<Code>::cast(global_handles->Create(code)); code_ = Handle<Code>::cast(global_handles->Create(code));
global_handles->MakeWeak(reinterpret_cast<Object**>(code_.location()), global_handles->MakeWeak(reinterpret_cast<Object**>(code_.location()),
this, this,
NULL,
Deoptimizer::HandleWeakDeoptimizedCode); Deoptimizer::HandleWeakDeoptimizedCode);
} }

View File

@ -403,7 +403,7 @@ class Deoptimizer : public Malloced {
// Weak handle callback for deoptimizing code objects. // Weak handle callback for deoptimizing code objects.
static void HandleWeakDeoptimizedCode(v8::Isolate* isolate, static void HandleWeakDeoptimizedCode(v8::Isolate* isolate,
v8::Persistent<v8::Value> obj, v8::Persistent<v8::Value>* obj,
void* data); void* data);
// Deoptimize function assuming that function->next_function_link() points // Deoptimize function assuming that function->next_function_link() points

View File

@ -92,7 +92,7 @@ class GlobalHandles::Node {
set_partially_dependent(false); set_partially_dependent(false);
set_in_new_space_list(false); set_in_new_space_list(false);
parameter_or_next_free_.next_free = NULL; parameter_or_next_free_.next_free = NULL;
near_death_callback_ = NULL; weak_reference_callback_ = NULL;
} }
#endif #endif
@ -113,7 +113,7 @@ class GlobalHandles::Node {
set_partially_dependent(false); set_partially_dependent(false);
set_state(NORMAL); set_state(NORMAL);
parameter_or_next_free_.parameter = NULL; parameter_or_next_free_.parameter = NULL;
near_death_callback_ = NULL; weak_reference_callback_ = NULL;
IncreaseBlockUses(); IncreaseBlockUses();
} }
@ -126,7 +126,7 @@ class GlobalHandles::Node {
class_id_ = v8::HeapProfiler::kPersistentHandleNoClassId; class_id_ = v8::HeapProfiler::kPersistentHandleNoClassId;
set_independent(false); set_independent(false);
set_partially_dependent(false); set_partially_dependent(false);
near_death_callback_ = NULL; weak_reference_callback_ = NULL;
#endif #endif
DecreaseBlockUses(); DecreaseBlockUses();
} }
@ -232,19 +232,11 @@ class GlobalHandles::Node {
} }
void MakeWeak(void* parameter, void MakeWeak(void* parameter,
RevivableCallback weak_reference_callback, RevivableCallback weak_reference_callback) {
NearDeathCallback near_death_callback) {
ASSERT(state() != FREE); ASSERT(state() != FREE);
set_state(WEAK); set_state(WEAK);
set_parameter(parameter); set_parameter(parameter);
if (weak_reference_callback != NULL) { weak_reference_callback_ = weak_reference_callback;
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;
}
} }
void ClearWeakness() { void ClearWeakness() {
@ -255,7 +247,7 @@ class GlobalHandles::Node {
bool PostGarbageCollectionProcessing(Isolate* isolate) { bool PostGarbageCollectionProcessing(Isolate* isolate) {
if (state() != Node::PENDING) return false; if (state() != Node::PENDING) return false;
if (near_death_callback_ == NULL) { if (weak_reference_callback_ == NULL) {
Release(); Release();
return false; return false;
} }
@ -263,7 +255,7 @@ class GlobalHandles::Node {
set_state(NEAR_DEATH); set_state(NEAR_DEATH);
set_parameter(NULL); 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 // Check that we are not passing a finalized external string to
// the callback. // the callback.
@ -273,19 +265,9 @@ class GlobalHandles::Node {
ExternalTwoByteString::cast(object_)->resource() != NULL); ExternalTwoByteString::cast(object_)->resource() != NULL);
// Leaving V8. // Leaving V8.
VMState<EXTERNAL> state(isolate); VMState<EXTERNAL> state(isolate);
if (near_death_callback_ != NULL) { weak_reference_callback_(reinterpret_cast<v8::Isolate*>(isolate),
if (IsWeakCallback::decode(flags_)) { reinterpret_cast<Persistent<Value>*>(&object),
RevivableCallback callback =
reinterpret_cast<RevivableCallback>(near_death_callback_);
callback(reinterpret_cast<v8::Isolate*>(isolate),
&object,
par); par);
} else {
near_death_callback_(reinterpret_cast<v8::Isolate*>(isolate),
object,
par);
}
}
} }
// Absence of explicit cleanup or revival of weak handle // Absence of explicit cleanup or revival of weak handle
// in most of the cases would lead to memory leak. // in most of the cases would lead to memory leak.
@ -318,12 +300,11 @@ class GlobalHandles::Node {
class IsIndependent: public BitField<bool, 4, 1> {}; class IsIndependent: public BitField<bool, 4, 1> {};
class IsPartiallyDependent: public BitField<bool, 5, 1> {}; class IsPartiallyDependent: public BitField<bool, 5, 1> {};
class IsInNewSpaceList: public BitField<bool, 6, 1> {}; class IsInNewSpaceList: public BitField<bool, 6, 1> {};
class IsWeakCallback: public BitField<bool, 7, 1> {};
uint8_t flags_; uint8_t flags_;
// Handle specific callback - might be a weak reference in disguise. // 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 // Provided data for callback. In FREE state, this is used for
// the free list link. // the free list link.
@ -509,12 +490,9 @@ void GlobalHandles::Destroy(Object** location) {
void GlobalHandles::MakeWeak(Object** location, void GlobalHandles::MakeWeak(Object** location,
void* parameter, void* parameter,
RevivableCallback weak_reference_callback, RevivableCallback weak_reference_callback) {
NearDeathCallback near_death_callback) { ASSERT(weak_reference_callback != NULL);
ASSERT((weak_reference_callback == NULL) != (near_death_callback == NULL)); Node::FromLocation(location)->MakeWeak(parameter, weak_reference_callback);
Node::FromLocation(location)->MakeWeak(parameter,
weak_reference_callback,
near_death_callback);
} }

View File

@ -140,8 +140,7 @@ class GlobalHandles {
// reason is that Smi::FromInt(0) does not change during garage collection. // reason is that Smi::FromInt(0) does not change during garage collection.
static void MakeWeak(Object** location, static void MakeWeak(Object** location,
void* parameter, void* parameter,
RevivableCallback weak_reference_callback, RevivableCallback weak_reference_callback);
NearDeathCallback near_death_callback);
void RecordStats(HeapStats* stats); void RecordStats(HeapStats* stats);

View File

@ -345,9 +345,9 @@ Handle<Object> SetAccessor(Handle<JSObject> obj, Handle<AccessorInfo> info) {
// associated with the wrapper and get rid of both the wrapper and the // associated with the wrapper and get rid of both the wrapper and the
// handle. // handle.
static void ClearWrapperCache(v8::Isolate* v8_isolate, static void ClearWrapperCache(v8::Isolate* v8_isolate,
Persistent<v8::Value> handle, Persistent<v8::Value>* handle,
void*) { void*) {
Handle<Object> cache = Utils::OpenHandle(*handle); Handle<Object> cache = Utils::OpenHandle(**handle);
JSValue* wrapper = JSValue::cast(*cache); JSValue* wrapper = JSValue::cast(*cache);
Foreign* foreign = Script::cast(wrapper->value())->wrapper(); Foreign* foreign = Script::cast(wrapper->value())->wrapper();
ASSERT(foreign->foreign_address() == ASSERT(foreign->foreign_address() ==
@ -387,7 +387,6 @@ Handle<JSValue> GetScriptWrapper(Handle<Script> script) {
// garbage collector when it is not used anymore. // garbage collector when it is not used anymore.
Handle<Object> handle = isolate->global_handles()->Create(*result); Handle<Object> handle = isolate->global_handles()->Create(*result);
isolate->global_handles()->MakeWeak(handle.location(), isolate->global_handles()->MakeWeak(handle.location(),
NULL,
NULL, NULL,
&ClearWrapperCache); &ClearWrapperCache);
script->wrapper()->set_foreign_address( script->wrapper()->set_foreign_address(

View File

@ -68,7 +68,6 @@ int TokenEnumerator::GetTokenId(Object* token) {
// to a token object in the V8's heap. // to a token object in the V8's heap.
isolate->global_handles()->MakeWeak(handle.location(), isolate->global_handles()->MakeWeak(handle.location(),
this, this,
NULL,
TokenRemovedCallback); TokenRemovedCallback);
token_locations_.Add(handle.location()); token_locations_.Add(handle.location());
token_removed_.Add(false); token_removed_.Add(false);
@ -77,11 +76,11 @@ int TokenEnumerator::GetTokenId(Object* token) {
void TokenEnumerator::TokenRemovedCallback(v8::Isolate* isolate, void TokenEnumerator::TokenRemovedCallback(v8::Isolate* isolate,
v8::Persistent<v8::Value> handle, v8::Persistent<v8::Value>* handle,
void* parameter) { void* parameter) {
reinterpret_cast<TokenEnumerator*>(parameter)->TokenRemoved( reinterpret_cast<TokenEnumerator*>(parameter)->TokenRemoved(
Utils::OpenHandle(*handle).location()); Utils::OpenHandle(**handle).location());
handle.Dispose(isolate); handle->Dispose(isolate);
} }

View File

@ -48,7 +48,7 @@ class TokenEnumerator {
private: private:
static void TokenRemovedCallback(v8::Isolate* isolate, static void TokenRemovedCallback(v8::Isolate* isolate,
v8::Persistent<v8::Value> handle, v8::Persistent<v8::Value>* handle,
void* parameter); void* parameter);
void TokenRemoved(Object** token_location); void TokenRemoved(Object** token_location);

View File

@ -423,8 +423,7 @@ TEST(WeakGlobalHandlesScavenge) {
global_handles->MakeWeak(h2.location(), global_handles->MakeWeak(h2.location(),
reinterpret_cast<void*>(1234), reinterpret_cast<void*>(1234),
&TestWeakGlobalHandleCallback, &TestWeakGlobalHandleCallback);
NULL);
// Scavenge treats weak pointers as normal roots. // Scavenge treats weak pointers as normal roots.
heap->PerformScavenge(); heap->PerformScavenge();
@ -470,8 +469,7 @@ TEST(WeakGlobalHandlesMark) {
global_handles->MakeWeak(h2.location(), global_handles->MakeWeak(h2.location(),
reinterpret_cast<void*>(1234), reinterpret_cast<void*>(1234),
&TestWeakGlobalHandleCallback, &TestWeakGlobalHandleCallback);
NULL);
CHECK(!GlobalHandles::IsNearDeath(h1.location())); CHECK(!GlobalHandles::IsNearDeath(h1.location()));
CHECK(!GlobalHandles::IsNearDeath(h2.location())); CHECK(!GlobalHandles::IsNearDeath(h2.location()));
@ -507,8 +505,7 @@ TEST(DeleteWeakGlobalHandle) {
global_handles->MakeWeak(h.location(), global_handles->MakeWeak(h.location(),
reinterpret_cast<void*>(1234), reinterpret_cast<void*>(1234),
&TestWeakGlobalHandleCallback, &TestWeakGlobalHandleCallback);
NULL);
// Scanvenge does not recognize weak reference. // Scanvenge does not recognize weak reference.
heap->PerformScavenge(); heap->PerformScavenge();

View File

@ -323,16 +323,13 @@ TEST(ObjectGroups) {
global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
global_handles->MakeWeak(g1s1.location(), global_handles->MakeWeak(g1s1.location(),
reinterpret_cast<void*>(1234), reinterpret_cast<void*>(1234),
&WeakPointerCallback, &WeakPointerCallback);
NULL);
global_handles->MakeWeak(g1s2.location(), global_handles->MakeWeak(g1s2.location(),
reinterpret_cast<void*>(1234), reinterpret_cast<void*>(1234),
&WeakPointerCallback, &WeakPointerCallback);
NULL);
global_handles->MakeWeak(g1c1.location(), global_handles->MakeWeak(g1c1.location(),
reinterpret_cast<void*>(1234), reinterpret_cast<void*>(1234),
&WeakPointerCallback, &WeakPointerCallback);
NULL);
Handle<Object> g2s1 = Handle<Object> g2s1 =
global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
@ -342,16 +339,13 @@ TEST(ObjectGroups) {
global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
global_handles->MakeWeak(g2s1.location(), global_handles->MakeWeak(g2s1.location(),
reinterpret_cast<void*>(1234), reinterpret_cast<void*>(1234),
&WeakPointerCallback, &WeakPointerCallback);
NULL);
global_handles->MakeWeak(g2s2.location(), global_handles->MakeWeak(g2s2.location(),
reinterpret_cast<void*>(1234), reinterpret_cast<void*>(1234),
&WeakPointerCallback, &WeakPointerCallback);
NULL);
global_handles->MakeWeak(g2c1.location(), global_handles->MakeWeak(g2c1.location(),
reinterpret_cast<void*>(1234), reinterpret_cast<void*>(1234),
&WeakPointerCallback, &WeakPointerCallback);
NULL);
Handle<Object> root = global_handles->Create(*g1s1); // make a root. Handle<Object> root = global_handles->Create(*g1s1); // make a root.
@ -380,8 +374,7 @@ TEST(ObjectGroups) {
// Weaken the root. // Weaken the root.
global_handles->MakeWeak(root.location(), global_handles->MakeWeak(root.location(),
reinterpret_cast<void*>(1234), reinterpret_cast<void*>(1234),
&WeakPointerCallback, &WeakPointerCallback);
NULL);
// But make children strong roots---all the objects (except for children) // But make children strong roots---all the objects (except for children)
// should be collectable now. // should be collectable now.
global_handles->ClearWeakness(g1c1.location()); global_handles->ClearWeakness(g1c1.location());
@ -409,12 +402,10 @@ TEST(ObjectGroups) {
// And now make children weak again and collect them. // And now make children weak again and collect them.
global_handles->MakeWeak(g1c1.location(), global_handles->MakeWeak(g1c1.location(),
reinterpret_cast<void*>(1234), reinterpret_cast<void*>(1234),
&WeakPointerCallback, &WeakPointerCallback);
NULL);
global_handles->MakeWeak(g2c1.location(), global_handles->MakeWeak(g2c1.location(),
reinterpret_cast<void*>(1234), reinterpret_cast<void*>(1234),
&WeakPointerCallback, &WeakPointerCallback);
NULL);
HEAP->CollectGarbage(OLD_POINTER_SPACE); HEAP->CollectGarbage(OLD_POINTER_SPACE);
CHECK_EQ(7, NumberOfWeakCalls); CHECK_EQ(7, NumberOfWeakCalls);

View File

@ -114,8 +114,7 @@ TEST(Weakness) {
HandleScope scope(isolate); HandleScope scope(isolate);
global_handles->MakeWeak(key.location(), global_handles->MakeWeak(key.location(),
reinterpret_cast<void*>(1234), reinterpret_cast<void*>(1234),
&WeakPointerCallback, &WeakPointerCallback);
NULL);
} }
CHECK(global_handles->IsWeak(key.location())); CHECK(global_handles->IsWeak(key.location()));