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:
parent
f6499289f6
commit
595d0ea8b0
27
include/v8.h
27
include/v8.h
@ -214,11 +214,6 @@ class WeakReferenceCallbacks {
|
||||
P* parameter);
|
||||
};
|
||||
|
||||
// TODO(svenpanne) Temporary definition until Chrome is in sync.
|
||||
typedef void (*NearDeathCallback)(Isolate* isolate,
|
||||
Persistent<Value> object,
|
||||
void* parameter);
|
||||
|
||||
// --- Handles ---
|
||||
|
||||
#define TYPE_CHECK(T, S) \
|
||||
@ -676,11 +671,6 @@ template <class T> class Persistent // NOLINT
|
||||
MakeWeak<P>(parameters, callback);
|
||||
}
|
||||
|
||||
// TODO(dcarney): remove before cutover
|
||||
V8_INLINE(void MakeWeak(Isolate* isolate,
|
||||
void* parameters,
|
||||
NearDeathCallback callback));
|
||||
|
||||
V8_INLINE(void ClearWeak());
|
||||
|
||||
// TODO(dcarney): deprecate
|
||||
@ -4606,8 +4596,7 @@ class V8EXPORT V8 {
|
||||
typedef WeakReferenceCallbacks<Value, void>::Revivable RevivableCallback;
|
||||
static void MakeWeak(internal::Object** global_handle,
|
||||
void* data,
|
||||
RevivableCallback weak_reference_callback,
|
||||
NearDeathCallback near_death_callback);
|
||||
RevivableCallback weak_reference_callback);
|
||||
static void ClearWeak(internal::Object** global_handle);
|
||||
|
||||
template <class T> friend class Handle;
|
||||
@ -5541,8 +5530,7 @@ void Persistent<T>::MakeWeak(
|
||||
typedef typename WeakReferenceCallbacks<Value, void>::Revivable Revivable;
|
||||
V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_),
|
||||
parameters,
|
||||
reinterpret_cast<Revivable>(callback),
|
||||
NULL);
|
||||
reinterpret_cast<Revivable>(callback));
|
||||
}
|
||||
|
||||
|
||||
@ -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>
|
||||
void Persistent<T>::ClearWeak() {
|
||||
V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_));
|
||||
|
@ -627,12 +627,10 @@ i::Object** V8::GlobalizeReference(i::Isolate* isolate, i::Object** obj) {
|
||||
|
||||
void V8::MakeWeak(i::Object** object,
|
||||
void* parameters,
|
||||
RevivableCallback weak_reference_callback,
|
||||
NearDeathCallback near_death_callback) {
|
||||
RevivableCallback weak_reference_callback) {
|
||||
i::GlobalHandles::MakeWeak(object,
|
||||
parameters,
|
||||
weak_reference_callback,
|
||||
near_death_callback);
|
||||
weak_reference_callback);
|
||||
}
|
||||
|
||||
|
||||
|
11
src/debug.cc
11
src/debug.cc
@ -619,7 +619,6 @@ void ScriptCache::Add(Handle<Script> script) {
|
||||
(global_handles->Create(*script)));
|
||||
global_handles->MakeWeak(reinterpret_cast<Object**>(script_.location()),
|
||||
this,
|
||||
NULL,
|
||||
ScriptCache::HandleWeakScript);
|
||||
entry->value = script_.location();
|
||||
}
|
||||
@ -664,12 +663,12 @@ void ScriptCache::Clear() {
|
||||
|
||||
|
||||
void ScriptCache::HandleWeakScript(v8::Isolate* isolate,
|
||||
v8::Persistent<v8::Value> obj,
|
||||
v8::Persistent<v8::Value>* obj,
|
||||
void* data) {
|
||||
ScriptCache* script_cache = reinterpret_cast<ScriptCache*>(data);
|
||||
// Find the location of the global handle.
|
||||
Script** location =
|
||||
reinterpret_cast<Script**>(Utils::OpenHandle(*obj).location());
|
||||
reinterpret_cast<Script**>(Utils::OpenHandle(**obj).location());
|
||||
ASSERT((*location)->IsScript());
|
||||
|
||||
// Remove the entry from the cache.
|
||||
@ -678,8 +677,7 @@ void ScriptCache::HandleWeakScript(v8::Isolate* isolate,
|
||||
script_cache->collected_scripts_.Add(id);
|
||||
|
||||
// Clear the weak handle.
|
||||
obj.Dispose(isolate);
|
||||
obj.Clear();
|
||||
obj->Dispose(isolate);
|
||||
}
|
||||
|
||||
|
||||
@ -699,7 +697,7 @@ void Debug::SetUp(bool create_heap_objects) {
|
||||
|
||||
|
||||
void Debug::HandleWeakDebugInfo(v8::Isolate* isolate,
|
||||
v8::Persistent<v8::Value> obj,
|
||||
v8::Persistent<v8::Value>* obj,
|
||||
void* data) {
|
||||
Debug* debug = reinterpret_cast<Isolate*>(isolate)->debug();
|
||||
DebugInfoListNode* node = reinterpret_cast<DebugInfoListNode*>(data);
|
||||
@ -727,7 +725,6 @@ DebugInfoListNode::DebugInfoListNode(DebugInfo* debug_info): next_(NULL) {
|
||||
(global_handles->Create(debug_info)));
|
||||
global_handles->MakeWeak(reinterpret_cast<Object**>(debug_info_.location()),
|
||||
this,
|
||||
NULL,
|
||||
Debug::HandleWeakDebugInfo);
|
||||
}
|
||||
|
||||
|
@ -190,7 +190,7 @@ class ScriptCache : private HashMap {
|
||||
|
||||
// Weak handle callback for scripts in the cache.
|
||||
static void HandleWeakScript(v8::Isolate* isolate,
|
||||
v8::Persistent<v8::Value> obj,
|
||||
v8::Persistent<v8::Value>* obj,
|
||||
void* data);
|
||||
|
||||
// List used during GC to temporarily store id's of collected scripts.
|
||||
@ -387,7 +387,7 @@ class Debug {
|
||||
|
||||
// Passed to MakeWeak.
|
||||
static void HandleWeakDebugInfo(v8::Isolate* isolate,
|
||||
v8::Persistent<v8::Value> obj,
|
||||
v8::Persistent<v8::Value>* obj,
|
||||
void* data);
|
||||
|
||||
friend class Debugger;
|
||||
|
@ -463,7 +463,7 @@ void Deoptimizer::DeoptimizeAllFunctionsWith(Isolate* isolate,
|
||||
|
||||
|
||||
void Deoptimizer::HandleWeakDeoptimizedCode(v8::Isolate* isolate,
|
||||
v8::Persistent<v8::Value> obj,
|
||||
v8::Persistent<v8::Value>* obj,
|
||||
void* parameter) {
|
||||
DeoptimizingCodeListNode* node =
|
||||
reinterpret_cast<DeoptimizingCodeListNode*>(parameter);
|
||||
@ -2750,7 +2750,6 @@ DeoptimizingCodeListNode::DeoptimizingCodeListNode(Code* code): next_(NULL) {
|
||||
code_ = Handle<Code>::cast(global_handles->Create(code));
|
||||
global_handles->MakeWeak(reinterpret_cast<Object**>(code_.location()),
|
||||
this,
|
||||
NULL,
|
||||
Deoptimizer::HandleWeakDeoptimizedCode);
|
||||
}
|
||||
|
||||
|
@ -403,7 +403,7 @@ class Deoptimizer : public Malloced {
|
||||
|
||||
// Weak handle callback for deoptimizing code objects.
|
||||
static void HandleWeakDeoptimizedCode(v8::Isolate* isolate,
|
||||
v8::Persistent<v8::Value> obj,
|
||||
v8::Persistent<v8::Value>* obj,
|
||||
void* data);
|
||||
|
||||
// Deoptimize function assuming that function->next_function_link() points
|
||||
|
@ -92,7 +92,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
|
||||
|
||||
@ -113,7 +113,7 @@ class GlobalHandles::Node {
|
||||
set_partially_dependent(false);
|
||||
set_state(NORMAL);
|
||||
parameter_or_next_free_.parameter = NULL;
|
||||
near_death_callback_ = NULL;
|
||||
weak_reference_callback_ = NULL;
|
||||
IncreaseBlockUses();
|
||||
}
|
||||
|
||||
@ -126,7 +126,7 @@ class GlobalHandles::Node {
|
||||
class_id_ = v8::HeapProfiler::kPersistentHandleNoClassId;
|
||||
set_independent(false);
|
||||
set_partially_dependent(false);
|
||||
near_death_callback_ = NULL;
|
||||
weak_reference_callback_ = NULL;
|
||||
#endif
|
||||
DecreaseBlockUses();
|
||||
}
|
||||
@ -232,19 +232,11 @@ class GlobalHandles::Node {
|
||||
}
|
||||
|
||||
void MakeWeak(void* parameter,
|
||||
RevivableCallback weak_reference_callback,
|
||||
NearDeathCallback near_death_callback) {
|
||||
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() {
|
||||
@ -255,7 +247,7 @@ class GlobalHandles::Node {
|
||||
|
||||
bool PostGarbageCollectionProcessing(Isolate* isolate) {
|
||||
if (state() != Node::PENDING) return false;
|
||||
if (near_death_callback_ == NULL) {
|
||||
if (weak_reference_callback_ == NULL) {
|
||||
Release();
|
||||
return false;
|
||||
}
|
||||
@ -263,7 +255,7 @@ class GlobalHandles::Node {
|
||||
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.
|
||||
@ -273,19 +265,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,
|
||||
weak_reference_callback_(reinterpret_cast<v8::Isolate*>(isolate),
|
||||
reinterpret_cast<Persistent<Value>*>(&object),
|
||||
par);
|
||||
} else {
|
||||
near_death_callback_(reinterpret_cast<v8::Isolate*>(isolate),
|
||||
object,
|
||||
par);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Absence of explicit cleanup or revival of weak handle
|
||||
// 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 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.
|
||||
@ -509,12 +490,9 @@ void GlobalHandles::Destroy(Object** location) {
|
||||
|
||||
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(parameter,
|
||||
weak_reference_callback,
|
||||
near_death_callback);
|
||||
RevivableCallback weak_reference_callback) {
|
||||
ASSERT(weak_reference_callback != NULL);
|
||||
Node::FromLocation(location)->MakeWeak(parameter, weak_reference_callback);
|
||||
}
|
||||
|
||||
|
||||
|
@ -140,8 +140,7 @@ class GlobalHandles {
|
||||
// reason is that Smi::FromInt(0) does not change during garage collection.
|
||||
static void MakeWeak(Object** location,
|
||||
void* parameter,
|
||||
RevivableCallback weak_reference_callback,
|
||||
NearDeathCallback near_death_callback);
|
||||
RevivableCallback weak_reference_callback);
|
||||
|
||||
void RecordStats(HeapStats* stats);
|
||||
|
||||
|
@ -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
|
||||
// handle.
|
||||
static void ClearWrapperCache(v8::Isolate* v8_isolate,
|
||||
Persistent<v8::Value> handle,
|
||||
Persistent<v8::Value>* handle,
|
||||
void*) {
|
||||
Handle<Object> cache = Utils::OpenHandle(*handle);
|
||||
Handle<Object> cache = Utils::OpenHandle(**handle);
|
||||
JSValue* wrapper = JSValue::cast(*cache);
|
||||
Foreign* foreign = Script::cast(wrapper->value())->wrapper();
|
||||
ASSERT(foreign->foreign_address() ==
|
||||
@ -387,7 +387,6 @@ Handle<JSValue> GetScriptWrapper(Handle<Script> script) {
|
||||
// garbage collector when it is not used anymore.
|
||||
Handle<Object> handle = isolate->global_handles()->Create(*result);
|
||||
isolate->global_handles()->MakeWeak(handle.location(),
|
||||
NULL,
|
||||
NULL,
|
||||
&ClearWrapperCache);
|
||||
script->wrapper()->set_foreign_address(
|
||||
|
@ -68,7 +68,6 @@ int TokenEnumerator::GetTokenId(Object* token) {
|
||||
// to a token object in the V8's heap.
|
||||
isolate->global_handles()->MakeWeak(handle.location(),
|
||||
this,
|
||||
NULL,
|
||||
TokenRemovedCallback);
|
||||
token_locations_.Add(handle.location());
|
||||
token_removed_.Add(false);
|
||||
@ -77,11 +76,11 @@ int TokenEnumerator::GetTokenId(Object* token) {
|
||||
|
||||
|
||||
void TokenEnumerator::TokenRemovedCallback(v8::Isolate* isolate,
|
||||
v8::Persistent<v8::Value> handle,
|
||||
v8::Persistent<v8::Value>* handle,
|
||||
void* parameter) {
|
||||
reinterpret_cast<TokenEnumerator*>(parameter)->TokenRemoved(
|
||||
Utils::OpenHandle(*handle).location());
|
||||
handle.Dispose(isolate);
|
||||
Utils::OpenHandle(**handle).location());
|
||||
handle->Dispose(isolate);
|
||||
}
|
||||
|
||||
|
||||
|
@ -48,7 +48,7 @@ class TokenEnumerator {
|
||||
|
||||
private:
|
||||
static void TokenRemovedCallback(v8::Isolate* isolate,
|
||||
v8::Persistent<v8::Value> handle,
|
||||
v8::Persistent<v8::Value>* handle,
|
||||
void* parameter);
|
||||
void TokenRemoved(Object** token_location);
|
||||
|
||||
|
@ -423,8 +423,7 @@ TEST(WeakGlobalHandlesScavenge) {
|
||||
|
||||
global_handles->MakeWeak(h2.location(),
|
||||
reinterpret_cast<void*>(1234),
|
||||
&TestWeakGlobalHandleCallback,
|
||||
NULL);
|
||||
&TestWeakGlobalHandleCallback);
|
||||
|
||||
// Scavenge treats weak pointers as normal roots.
|
||||
heap->PerformScavenge();
|
||||
@ -470,8 +469,7 @@ TEST(WeakGlobalHandlesMark) {
|
||||
|
||||
global_handles->MakeWeak(h2.location(),
|
||||
reinterpret_cast<void*>(1234),
|
||||
&TestWeakGlobalHandleCallback,
|
||||
NULL);
|
||||
&TestWeakGlobalHandleCallback);
|
||||
CHECK(!GlobalHandles::IsNearDeath(h1.location()));
|
||||
CHECK(!GlobalHandles::IsNearDeath(h2.location()));
|
||||
|
||||
@ -507,8 +505,7 @@ TEST(DeleteWeakGlobalHandle) {
|
||||
|
||||
global_handles->MakeWeak(h.location(),
|
||||
reinterpret_cast<void*>(1234),
|
||||
&TestWeakGlobalHandleCallback,
|
||||
NULL);
|
||||
&TestWeakGlobalHandleCallback);
|
||||
|
||||
// Scanvenge does not recognize weak reference.
|
||||
heap->PerformScavenge();
|
||||
|
@ -323,16 +323,13 @@ TEST(ObjectGroups) {
|
||||
global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
|
||||
global_handles->MakeWeak(g1s1.location(),
|
||||
reinterpret_cast<void*>(1234),
|
||||
&WeakPointerCallback,
|
||||
NULL);
|
||||
&WeakPointerCallback);
|
||||
global_handles->MakeWeak(g1s2.location(),
|
||||
reinterpret_cast<void*>(1234),
|
||||
&WeakPointerCallback,
|
||||
NULL);
|
||||
&WeakPointerCallback);
|
||||
global_handles->MakeWeak(g1c1.location(),
|
||||
reinterpret_cast<void*>(1234),
|
||||
&WeakPointerCallback,
|
||||
NULL);
|
||||
&WeakPointerCallback);
|
||||
|
||||
Handle<Object> g2s1 =
|
||||
global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
|
||||
@ -342,16 +339,13 @@ TEST(ObjectGroups) {
|
||||
global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
|
||||
global_handles->MakeWeak(g2s1.location(),
|
||||
reinterpret_cast<void*>(1234),
|
||||
&WeakPointerCallback,
|
||||
NULL);
|
||||
&WeakPointerCallback);
|
||||
global_handles->MakeWeak(g2s2.location(),
|
||||
reinterpret_cast<void*>(1234),
|
||||
&WeakPointerCallback,
|
||||
NULL);
|
||||
&WeakPointerCallback);
|
||||
global_handles->MakeWeak(g2c1.location(),
|
||||
reinterpret_cast<void*>(1234),
|
||||
&WeakPointerCallback,
|
||||
NULL);
|
||||
&WeakPointerCallback);
|
||||
|
||||
Handle<Object> root = global_handles->Create(*g1s1); // make a root.
|
||||
|
||||
@ -380,8 +374,7 @@ TEST(ObjectGroups) {
|
||||
// Weaken the root.
|
||||
global_handles->MakeWeak(root.location(),
|
||||
reinterpret_cast<void*>(1234),
|
||||
&WeakPointerCallback,
|
||||
NULL);
|
||||
&WeakPointerCallback);
|
||||
// But make children strong roots---all the objects (except for children)
|
||||
// should be collectable now.
|
||||
global_handles->ClearWeakness(g1c1.location());
|
||||
@ -409,12 +402,10 @@ TEST(ObjectGroups) {
|
||||
// And now make children weak again and collect them.
|
||||
global_handles->MakeWeak(g1c1.location(),
|
||||
reinterpret_cast<void*>(1234),
|
||||
&WeakPointerCallback,
|
||||
NULL);
|
||||
&WeakPointerCallback);
|
||||
global_handles->MakeWeak(g2c1.location(),
|
||||
reinterpret_cast<void*>(1234),
|
||||
&WeakPointerCallback,
|
||||
NULL);
|
||||
&WeakPointerCallback);
|
||||
|
||||
HEAP->CollectGarbage(OLD_POINTER_SPACE);
|
||||
CHECK_EQ(7, NumberOfWeakCalls);
|
||||
|
@ -114,8 +114,7 @@ TEST(Weakness) {
|
||||
HandleScope scope(isolate);
|
||||
global_handles->MakeWeak(key.location(),
|
||||
reinterpret_cast<void*>(1234),
|
||||
&WeakPointerCallback,
|
||||
NULL);
|
||||
&WeakPointerCallback);
|
||||
}
|
||||
CHECK(global_handles->IsWeak(key.location()));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user