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) \
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
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;
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));
}
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_));
}
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);
}
(global_handles->Create(*script)));
global_handles->MakeWeak(reinterpret_cast<Object**>(script_.location()),
this,
- NULL,
ScriptCache::HandleWeakScript);
entry->value = script_.location();
}
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.
script_cache->collected_scripts_.Add(id);
// Clear the weak handle.
- obj.Dispose(isolate);
- obj.Clear();
+ obj->Dispose(isolate);
}
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);
(global_handles->Create(debug_info)));
global_handles->MakeWeak(reinterpret_cast<Object**>(debug_info_.location()),
this,
- NULL,
Debug::HandleWeakDebugInfo);
}
// 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.
// Passed to MakeWeak.
static void HandleWeakDebugInfo(v8::Isolate* isolate,
- v8::Persistent<v8::Value> obj,
+ v8::Persistent<v8::Value>* obj,
void* data);
friend class Debugger;
void Deoptimizer::HandleWeakDeoptimizedCode(v8::Isolate* isolate,
- v8::Persistent<v8::Value> obj,
+ v8::Persistent<v8::Value>* obj,
void* parameter) {
DeoptimizingCodeListNode* node =
reinterpret_cast<DeoptimizingCodeListNode*>(parameter);
code_ = Handle<Code>::cast(global_handles->Create(code));
global_handles->MakeWeak(reinterpret_cast<Object**>(code_.location()),
this,
- NULL,
Deoptimizer::HandleWeakDeoptimizedCode);
}
// 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
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
set_partially_dependent(false);
set_state(NORMAL);
parameter_or_next_free_.parameter = NULL;
- near_death_callback_ = NULL;
+ weak_reference_callback_ = NULL;
IncreaseBlockUses();
}
class_id_ = v8::HeapProfiler::kPersistentHandleNoClassId;
set_independent(false);
set_partially_dependent(false);
- near_death_callback_ = NULL;
+ weak_reference_callback_ = NULL;
#endif
DecreaseBlockUses();
}
}
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() {
bool PostGarbageCollectionProcessing(Isolate* isolate) {
if (state() != Node::PENDING) return false;
- if (near_death_callback_ == NULL) {
+ if (weak_reference_callback_ == NULL) {
Release();
return false;
}
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.
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.
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.
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);
}
// 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);
// 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() ==
Handle<Object> handle = isolate->global_handles()->Create(*result);
isolate->global_handles()->MakeWeak(handle.location(),
NULL,
- NULL,
&ClearWrapperCache);
script->wrapper()->set_foreign_address(
reinterpret_cast<Address>(handle.location()));
// 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);
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);
}
private:
static void TokenRemovedCallback(v8::Isolate* isolate,
- v8::Persistent<v8::Value> handle,
+ v8::Persistent<v8::Value>* handle,
void* parameter);
void TokenRemoved(Object** token_location);
global_handles->MakeWeak(h2.location(),
reinterpret_cast<void*>(1234),
- &TestWeakGlobalHandleCallback,
- NULL);
+ &TestWeakGlobalHandleCallback);
// Scavenge treats weak pointers as normal roots.
heap->PerformScavenge();
global_handles->MakeWeak(h2.location(),
reinterpret_cast<void*>(1234),
- &TestWeakGlobalHandleCallback,
- NULL);
+ &TestWeakGlobalHandleCallback);
CHECK(!GlobalHandles::IsNearDeath(h1.location()));
CHECK(!GlobalHandles::IsNearDeath(h2.location()));
global_handles->MakeWeak(h.location(),
reinterpret_cast<void*>(1234),
- &TestWeakGlobalHandleCallback,
- NULL);
+ &TestWeakGlobalHandleCallback);
// Scanvenge does not recognize weak reference.
heap->PerformScavenge();
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());
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.
// 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());
// 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);
HandleScope scope(isolate);
global_handles->MakeWeak(key.location(),
reinterpret_cast<void*>(1234),
- &WeakPointerCallback,
- NULL);
+ &WeakPointerCallback);
}
CHECK(global_handles->IsWeak(key.location()));