add weakcallback without persistent copying
R=svenpanne@chromium.org BUG= Review URL: https://codereview.chromium.org/14908004 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14566 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
46d39cabd6
commit
42a8ff87ba
47
include/v8.h
47
include/v8.h
@ -191,8 +191,13 @@ class UniqueId {
|
||||
* \param object the weak global object to be reclaimed by the garbage collector
|
||||
* \param parameter the value passed in when making the weak global object
|
||||
*/
|
||||
typedef void (*WeakReferenceCallback)(Persistent<Value> object,
|
||||
void* parameter);
|
||||
template<typename T, typename P>
|
||||
class WeakReferenceCallbacks {
|
||||
public:
|
||||
typedef void (*Revivable)(Isolate* isolate,
|
||||
Persistent<T>* object,
|
||||
P* parameter);
|
||||
};
|
||||
|
||||
// TODO(svenpanne) Temporary definition until Chrome is in sync.
|
||||
typedef void (*NearDeathCallback)(Isolate* isolate,
|
||||
@ -598,8 +603,17 @@ template <class T> class Persistent // NOLINT
|
||||
// TODO(dcarney): remove before cutover
|
||||
V8_INLINE(void Dispose(Isolate* isolate));
|
||||
|
||||
V8_INLINE(void MakeWeak(void* parameters,
|
||||
WeakReferenceCallback callback));
|
||||
template<typename S, typename P>
|
||||
V8_INLINE(void MakeWeak(
|
||||
Isolate* isolate,
|
||||
P* parameters,
|
||||
typename WeakReferenceCallbacks<S, P>::Revivable callback));
|
||||
|
||||
template<typename P>
|
||||
V8_INLINE(void MakeWeak(
|
||||
Isolate* isolate,
|
||||
P* parameters,
|
||||
typename WeakReferenceCallbacks<T, P>::Revivable callback));
|
||||
|
||||
/**
|
||||
* Make the reference to this object weak. When only weak handles
|
||||
@ -4363,10 +4377,11 @@ class V8EXPORT V8 {
|
||||
internal::Object** handle);
|
||||
static void DisposeGlobal(internal::Isolate* isolate,
|
||||
internal::Object** global_handle);
|
||||
typedef WeakReferenceCallbacks<Value, void>::Revivable RevivableCallback;
|
||||
static void MakeWeak(internal::Isolate* isolate,
|
||||
internal::Object** global_handle,
|
||||
void* data,
|
||||
WeakReferenceCallback weak_reference_callback,
|
||||
RevivableCallback weak_reference_callback,
|
||||
NearDeathCallback near_death_callback);
|
||||
static void ClearWeak(internal::Isolate* isolate,
|
||||
internal::Object** global_handle);
|
||||
@ -5282,15 +5297,31 @@ void Persistent<T>::Dispose(Isolate* isolate) {
|
||||
|
||||
|
||||
template <class T>
|
||||
void Persistent<T>::MakeWeak(void* parameters, WeakReferenceCallback callback) {
|
||||
Isolate* isolate = Isolate::GetCurrent();
|
||||
template <typename S, typename P>
|
||||
void Persistent<T>::MakeWeak(
|
||||
Isolate* isolate,
|
||||
P* parameters,
|
||||
typename WeakReferenceCallbacks<S, P>::Revivable callback) {
|
||||
TYPE_CHECK(S, T);
|
||||
typedef typename WeakReferenceCallbacks<Value, void>::Revivable Revivable;
|
||||
V8::MakeWeak(reinterpret_cast<internal::Isolate*>(isolate),
|
||||
reinterpret_cast<internal::Object**>(this->val_),
|
||||
parameters,
|
||||
callback,
|
||||
reinterpret_cast<Revivable>(callback),
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
template <typename P>
|
||||
void Persistent<T>::MakeWeak(
|
||||
Isolate* isolate,
|
||||
P* parameters,
|
||||
typename WeakReferenceCallbacks<T, P>::Revivable callback) {
|
||||
MakeWeak<T, P>(isolate, parameters, callback);
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
void Persistent<T>::MakeWeak(Isolate* isolate,
|
||||
void* parameters,
|
||||
|
@ -628,7 +628,7 @@ i::Object** V8::GlobalizeReference(i::Isolate* isolate, i::Object** obj) {
|
||||
void V8::MakeWeak(i::Isolate* isolate,
|
||||
i::Object** object,
|
||||
void* parameters,
|
||||
WeakReferenceCallback weak_reference_callback,
|
||||
RevivableCallback weak_reference_callback,
|
||||
NearDeathCallback near_death_callback) {
|
||||
ASSERT(isolate == i::Isolate::Current());
|
||||
LOG_API(isolate, "MakeWeak");
|
||||
|
10
src/d8.cc
10
src/d8.cc
@ -1062,14 +1062,14 @@ Handle<Value> Shell::ArraySet(const Arguments& args) {
|
||||
|
||||
|
||||
void Shell::ExternalArrayWeakCallback(v8::Isolate* isolate,
|
||||
Persistent<Value> object,
|
||||
void* data) {
|
||||
Persistent<Object>* object,
|
||||
uint8_t* data) {
|
||||
HandleScope scope(isolate);
|
||||
int32_t length = object->ToObject()->Get(
|
||||
int32_t length = (*object)->Get(
|
||||
PerIsolateData::byteLength_string(isolate))->Uint32Value();
|
||||
isolate->AdjustAmountOfExternalAllocatedMemory(-length);
|
||||
delete[] static_cast<uint8_t*>(data);
|
||||
object.Dispose(isolate);
|
||||
delete[] data;
|
||||
object->Dispose(isolate);
|
||||
}
|
||||
|
||||
|
||||
|
4
src/d8.h
4
src/d8.h
@ -416,8 +416,8 @@ class Shell : public i::AllStatic {
|
||||
ExternalArrayType type,
|
||||
int32_t element_size);
|
||||
static void ExternalArrayWeakCallback(Isolate* isolate,
|
||||
Persistent<Value> object,
|
||||
void* data);
|
||||
Persistent<Object>* object,
|
||||
uint8_t* data);
|
||||
};
|
||||
|
||||
|
||||
|
@ -235,7 +235,7 @@ class GlobalHandles::Node {
|
||||
|
||||
void MakeWeak(GlobalHandles* global_handles,
|
||||
void* parameter,
|
||||
WeakReferenceCallback weak_reference_callback,
|
||||
RevivableCallback weak_reference_callback,
|
||||
NearDeathCallback near_death_callback) {
|
||||
ASSERT(state() != FREE);
|
||||
set_state(WEAK);
|
||||
@ -267,7 +267,7 @@ class GlobalHandles::Node {
|
||||
set_state(NEAR_DEATH);
|
||||
set_parameter(NULL);
|
||||
|
||||
v8::Persistent<v8::Object> object = ToApi<v8::Object>(handle());
|
||||
v8::Persistent<v8::Value> object = ToApi<v8::Value>(handle());
|
||||
{
|
||||
// Check that we are not passing a finalized external string to
|
||||
// the callback.
|
||||
@ -279,9 +279,11 @@ class GlobalHandles::Node {
|
||||
VMState<EXTERNAL> state(isolate);
|
||||
if (near_death_callback_ != NULL) {
|
||||
if (IsWeakCallback::decode(flags_)) {
|
||||
WeakReferenceCallback callback =
|
||||
reinterpret_cast<WeakReferenceCallback>(near_death_callback_);
|
||||
callback(object, par);
|
||||
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,
|
||||
@ -493,9 +495,9 @@ void GlobalHandles::Destroy(Object** location) {
|
||||
|
||||
void GlobalHandles::MakeWeak(Object** location,
|
||||
void* parameter,
|
||||
WeakReferenceCallback weak_reference_callback,
|
||||
RevivableCallback weak_reference_callback,
|
||||
NearDeathCallback near_death_callback) {
|
||||
ASSERT(near_death_callback != NULL);
|
||||
ASSERT((weak_reference_callback == NULL) != (near_death_callback == NULL));
|
||||
Node::FromLocation(location)->MakeWeak(this,
|
||||
parameter,
|
||||
weak_reference_callback,
|
||||
|
@ -130,6 +130,8 @@ class GlobalHandles {
|
||||
// Destroy a global handle.
|
||||
void Destroy(Object** location);
|
||||
|
||||
typedef WeakReferenceCallbacks<v8::Value, void>::Revivable RevivableCallback;
|
||||
|
||||
// Make the global handle weak and set the callback parameter for the
|
||||
// handle. When the garbage collector recognizes that only weak global
|
||||
// handles point to an object the handles are cleared and the callback
|
||||
@ -138,7 +140,7 @@ class GlobalHandles {
|
||||
// reason is that Smi::FromInt(0) does not change during garage collection.
|
||||
void MakeWeak(Object** location,
|
||||
void* parameter,
|
||||
WeakReferenceCallback weak_reference_callback,
|
||||
RevivableCallback weak_reference_callback,
|
||||
NearDeathCallback near_death_callback);
|
||||
|
||||
void RecordStats(HeapStats* stats);
|
||||
|
@ -653,11 +653,11 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_Fix) {
|
||||
|
||||
|
||||
static void ArrayBufferWeakCallback(v8::Isolate* external_isolate,
|
||||
Persistent<Value> object,
|
||||
Persistent<Value>* object,
|
||||
void* data) {
|
||||
Isolate* isolate = reinterpret_cast<Isolate*>(external_isolate);
|
||||
HandleScope scope(isolate);
|
||||
Handle<Object> internal_object = Utils::OpenHandle(*object);
|
||||
Handle<Object> internal_object = Utils::OpenHandle(**object);
|
||||
|
||||
size_t allocated_length = NumberToSize(
|
||||
isolate, JSArrayBuffer::cast(*internal_object)->byte_length());
|
||||
@ -665,7 +665,7 @@ static void ArrayBufferWeakCallback(v8::Isolate* external_isolate,
|
||||
-static_cast<intptr_t>(allocated_length));
|
||||
if (data != NULL)
|
||||
free(data);
|
||||
object.Dispose(external_isolate);
|
||||
object->Dispose(external_isolate);
|
||||
}
|
||||
|
||||
|
||||
|
@ -2510,12 +2510,11 @@ class WeakCallCounter {
|
||||
|
||||
|
||||
static void WeakPointerCallback(v8::Isolate* isolate,
|
||||
Persistent<Value> handle,
|
||||
void* id) {
|
||||
WeakCallCounter* counter = reinterpret_cast<WeakCallCounter*>(id);
|
||||
Persistent<Object>* handle,
|
||||
WeakCallCounter* counter) {
|
||||
CHECK_EQ(1234, counter->id());
|
||||
counter->increment();
|
||||
handle.Dispose(isolate);
|
||||
handle->Dispose(isolate);
|
||||
}
|
||||
|
||||
|
||||
@ -2538,16 +2537,16 @@ THREADED_TEST(OldApiObjectGroups) {
|
||||
g1s1 = Persistent<Object>::New(iso, Object::New());
|
||||
g1s2 = Persistent<Object>::New(iso, Object::New());
|
||||
g1c1 = Persistent<Object>::New(iso, Object::New());
|
||||
g1s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g1s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g1c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g1s1.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
g1s2.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
g1c1.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
|
||||
g2s1 = Persistent<Object>::New(iso, Object::New());
|
||||
g2s2 = Persistent<Object>::New(iso, Object::New());
|
||||
g2c1 = Persistent<Object>::New(iso, Object::New());
|
||||
g2s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g2s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g2c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g2s1.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
g2s2.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
g2c1.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
}
|
||||
|
||||
Persistent<Object> root = Persistent<Object>::New(iso, g1s1); // make a root.
|
||||
@ -2573,7 +2572,7 @@ THREADED_TEST(OldApiObjectGroups) {
|
||||
CHECK_EQ(0, counter.NumberOfWeakCalls());
|
||||
|
||||
// Weaken the root.
|
||||
root.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
root.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
// But make children strong roots---all the objects (except for children)
|
||||
// should be collectable now.
|
||||
g1c1.ClearWeak(iso);
|
||||
@ -2597,8 +2596,8 @@ THREADED_TEST(OldApiObjectGroups) {
|
||||
CHECK_EQ(5, counter.NumberOfWeakCalls());
|
||||
|
||||
// And now make children weak again and collect them.
|
||||
g1c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g2c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g1c1.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
g2c1.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
|
||||
HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
|
||||
CHECK_EQ(7, counter.NumberOfWeakCalls());
|
||||
@ -2624,16 +2623,16 @@ THREADED_TEST(ApiObjectGroups) {
|
||||
g1s1 = Persistent<Object>::New(iso, Object::New());
|
||||
g1s2 = Persistent<Object>::New(iso, Object::New());
|
||||
g1c1 = Persistent<Object>::New(iso, Object::New());
|
||||
g1s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g1s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g1c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g1s1.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
g1s2.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
g1c1.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
|
||||
g2s1 = Persistent<Object>::New(iso, Object::New());
|
||||
g2s2 = Persistent<Object>::New(iso, Object::New());
|
||||
g2c1 = Persistent<Object>::New(iso, Object::New());
|
||||
g2s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g2s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g2c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g2s1.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
g2s2.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
g2c1.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
}
|
||||
|
||||
Persistent<Object> root = Persistent<Object>::New(iso, g1s1); // make a root.
|
||||
@ -2661,7 +2660,7 @@ THREADED_TEST(ApiObjectGroups) {
|
||||
CHECK_EQ(0, counter.NumberOfWeakCalls());
|
||||
|
||||
// Weaken the root.
|
||||
root.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
root.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
// But make children strong roots---all the objects (except for children)
|
||||
// should be collectable now.
|
||||
g1c1.ClearWeak(iso);
|
||||
@ -2685,8 +2684,8 @@ THREADED_TEST(ApiObjectGroups) {
|
||||
CHECK_EQ(5, counter.NumberOfWeakCalls());
|
||||
|
||||
// And now make children weak again and collect them.
|
||||
g1c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g2c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g1c1.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
g2c1.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
|
||||
heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
|
||||
CHECK_EQ(7, counter.NumberOfWeakCalls());
|
||||
@ -2713,29 +2712,29 @@ THREADED_TEST(OldApiObjectGroupsCycle) {
|
||||
HandleScope scope(iso);
|
||||
g1s1 = Persistent<Object>::New(iso, Object::New());
|
||||
g1s2 = Persistent<Object>::New(iso, Object::New());
|
||||
g1s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g1s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g1s1.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
g1s2.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
CHECK(g1s1.IsWeak(iso));
|
||||
CHECK(g1s2.IsWeak(iso));
|
||||
|
||||
g2s1 = Persistent<Object>::New(iso, Object::New());
|
||||
g2s2 = Persistent<Object>::New(iso, Object::New());
|
||||
g2s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g2s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g2s1.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
g2s2.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
CHECK(g2s1.IsWeak(iso));
|
||||
CHECK(g2s2.IsWeak(iso));
|
||||
|
||||
g3s1 = Persistent<Object>::New(iso, Object::New());
|
||||
g3s2 = Persistent<Object>::New(iso, Object::New());
|
||||
g3s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g3s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g3s1.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
g3s2.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
CHECK(g3s1.IsWeak(iso));
|
||||
CHECK(g3s2.IsWeak(iso));
|
||||
|
||||
g4s1 = Persistent<Object>::New(iso, Object::New());
|
||||
g4s2 = Persistent<Object>::New(iso, Object::New());
|
||||
g4s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g4s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g4s1.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
g4s2.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
CHECK(g4s1.IsWeak(iso));
|
||||
CHECK(g4s2.IsWeak(iso));
|
||||
}
|
||||
@ -2770,7 +2769,7 @@ THREADED_TEST(OldApiObjectGroupsCycle) {
|
||||
CHECK_EQ(0, counter.NumberOfWeakCalls());
|
||||
|
||||
// Weaken the root.
|
||||
root.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
root.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
|
||||
// Groups are deleted, rebuild groups.
|
||||
{
|
||||
@ -2819,29 +2818,29 @@ THREADED_TEST(ApiObjectGroupsCycle) {
|
||||
HandleScope scope(iso);
|
||||
g1s1 = Persistent<Object>::New(iso, Object::New());
|
||||
g1s2 = Persistent<Object>::New(iso, Object::New());
|
||||
g1s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g1s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g1s1.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
g1s2.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
CHECK(g1s1.IsWeak(iso));
|
||||
CHECK(g1s2.IsWeak(iso));
|
||||
|
||||
g2s1 = Persistent<Object>::New(iso, Object::New());
|
||||
g2s2 = Persistent<Object>::New(iso, Object::New());
|
||||
g2s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g2s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g2s1.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
g2s2.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
CHECK(g2s1.IsWeak(iso));
|
||||
CHECK(g2s2.IsWeak(iso));
|
||||
|
||||
g3s1 = Persistent<Object>::New(iso, Object::New());
|
||||
g3s2 = Persistent<Object>::New(iso, Object::New());
|
||||
g3s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g3s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g3s1.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
g3s2.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
CHECK(g3s1.IsWeak(iso));
|
||||
CHECK(g3s2.IsWeak(iso));
|
||||
|
||||
g4s1 = Persistent<Object>::New(iso, Object::New());
|
||||
g4s2 = Persistent<Object>::New(iso, Object::New());
|
||||
g4s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g4s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g4s1.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
g4s2.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
CHECK(g4s1.IsWeak(iso));
|
||||
CHECK(g4s2.IsWeak(iso));
|
||||
}
|
||||
@ -2878,7 +2877,7 @@ THREADED_TEST(ApiObjectGroupsCycle) {
|
||||
CHECK_EQ(0, counter.NumberOfWeakCalls());
|
||||
|
||||
// Weaken the root.
|
||||
root.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
root.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
|
||||
// Groups are deleted, rebuild groups.
|
||||
{
|
||||
@ -2929,18 +2928,18 @@ TEST(OldApiObjectGroupsCycleForScavenger) {
|
||||
HandleScope scope(iso);
|
||||
g1s1 = Persistent<Object>::New(iso, Object::New());
|
||||
g1s2 = Persistent<Object>::New(iso, Object::New());
|
||||
g1s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g1s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g1s1.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
g1s2.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
|
||||
g2s1 = Persistent<Object>::New(iso, Object::New());
|
||||
g2s2 = Persistent<Object>::New(iso, Object::New());
|
||||
g2s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g2s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g2s1.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
g2s2.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
|
||||
g3s1 = Persistent<Object>::New(iso, Object::New());
|
||||
g3s2 = Persistent<Object>::New(iso, Object::New());
|
||||
g3s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g3s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g3s1.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
g3s2.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
}
|
||||
|
||||
// Make a root.
|
||||
@ -2974,7 +2973,7 @@ TEST(OldApiObjectGroupsCycleForScavenger) {
|
||||
CHECK_EQ(0, counter.NumberOfWeakCalls());
|
||||
|
||||
// Weaken the root.
|
||||
root.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
root.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
root.MarkPartiallyDependent(iso);
|
||||
|
||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||
@ -3026,18 +3025,18 @@ TEST(ApiObjectGroupsCycleForScavenger) {
|
||||
HandleScope scope(iso);
|
||||
g1s1 = Persistent<Object>::New(iso, Object::New());
|
||||
g1s2 = Persistent<Object>::New(iso, Object::New());
|
||||
g1s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g1s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g1s1.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
g1s2.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
|
||||
g2s1 = Persistent<Object>::New(iso, Object::New());
|
||||
g2s2 = Persistent<Object>::New(iso, Object::New());
|
||||
g2s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g2s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g2s1.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
g2s2.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
|
||||
g3s1 = Persistent<Object>::New(iso, Object::New());
|
||||
g3s2 = Persistent<Object>::New(iso, Object::New());
|
||||
g3s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g3s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
g3s1.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
g3s2.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
}
|
||||
|
||||
// Make a root.
|
||||
@ -3073,7 +3072,7 @@ TEST(ApiObjectGroupsCycleForScavenger) {
|
||||
CHECK_EQ(0, counter.NumberOfWeakCalls());
|
||||
|
||||
// Weaken the root.
|
||||
root.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
|
||||
root.MakeWeak(iso, &counter, &WeakPointerCallback);
|
||||
root.MarkPartiallyDependent(iso);
|
||||
|
||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||
@ -5959,11 +5958,10 @@ class Whammy {
|
||||
};
|
||||
|
||||
static void HandleWeakReference(v8::Isolate* isolate,
|
||||
v8::Persistent<v8::Value> obj,
|
||||
void* data) {
|
||||
Snorkel* snorkel = reinterpret_cast<Snorkel*>(data);
|
||||
v8::Persistent<v8::Value>* obj,
|
||||
Snorkel* snorkel) {
|
||||
delete snorkel;
|
||||
obj.ClearWeak(isolate);
|
||||
obj->ClearWeak(isolate);
|
||||
}
|
||||
|
||||
v8::Handle<Value> WhammyPropertyGetter(Local<String> name,
|
||||
@ -5978,7 +5976,9 @@ v8::Handle<Value> WhammyPropertyGetter(Local<String> name,
|
||||
v8::Persistent<v8::Object>::New(info.GetIsolate(), obj);
|
||||
if (!prev.IsEmpty()) {
|
||||
prev->Set(v8_str("next"), obj);
|
||||
prev.MakeWeak(info.GetIsolate(), new Snorkel(), &HandleWeakReference);
|
||||
prev.MakeWeak<Value, Snorkel>(info.GetIsolate(),
|
||||
new Snorkel(),
|
||||
&HandleWeakReference);
|
||||
whammy->objects_[whammy->cursor_].Clear();
|
||||
}
|
||||
whammy->objects_[whammy->cursor_] = global;
|
||||
@ -6017,11 +6017,10 @@ THREADED_TEST(WeakReference) {
|
||||
|
||||
|
||||
static void DisposeAndSetFlag(v8::Isolate* isolate,
|
||||
v8::Persistent<v8::Value> obj,
|
||||
void* data) {
|
||||
obj.Dispose(isolate);
|
||||
obj.Clear();
|
||||
*(reinterpret_cast<bool*>(data)) = true;
|
||||
v8::Persistent<v8::Object>* obj,
|
||||
bool* data) {
|
||||
obj->Dispose(isolate);
|
||||
*(data) = true;
|
||||
}
|
||||
|
||||
|
||||
@ -6064,21 +6063,19 @@ static void InvokeMarkSweep() {
|
||||
|
||||
|
||||
static void ForceScavenge(v8::Isolate* isolate,
|
||||
v8::Persistent<v8::Value> obj,
|
||||
void* data) {
|
||||
obj.Dispose(isolate);
|
||||
obj.Clear();
|
||||
*(reinterpret_cast<bool*>(data)) = true;
|
||||
v8::Persistent<v8::Object>* obj,
|
||||
bool* data) {
|
||||
obj->Dispose(isolate);
|
||||
*(data) = true;
|
||||
InvokeScavenge();
|
||||
}
|
||||
|
||||
|
||||
static void ForceMarkSweep(v8::Isolate* isolate,
|
||||
v8::Persistent<v8::Value> obj,
|
||||
void* data) {
|
||||
obj.Dispose(isolate);
|
||||
obj.Clear();
|
||||
*(reinterpret_cast<bool*>(data)) = true;
|
||||
v8::Persistent<v8::Object>* obj,
|
||||
bool* data) {
|
||||
obj->Dispose(isolate);
|
||||
*(data) = true;
|
||||
InvokeMarkSweep();
|
||||
}
|
||||
|
||||
@ -6090,7 +6087,8 @@ THREADED_TEST(GCFromWeakCallbacks) {
|
||||
Context::Scope context_scope(context);
|
||||
|
||||
static const int kNumberOfGCTypes = 2;
|
||||
v8::NearDeathCallback gc_forcing_callback[kNumberOfGCTypes] =
|
||||
typedef v8::WeakReferenceCallbacks<v8::Object, bool>::Revivable Callback;
|
||||
Callback gc_forcing_callback[kNumberOfGCTypes] =
|
||||
{&ForceScavenge, &ForceMarkSweep};
|
||||
|
||||
typedef void (*GCInvoker)();
|
||||
@ -6114,10 +6112,10 @@ THREADED_TEST(GCFromWeakCallbacks) {
|
||||
|
||||
|
||||
static void RevivingCallback(v8::Isolate* isolate,
|
||||
v8::Persistent<v8::Value> obj,
|
||||
void* data) {
|
||||
obj.ClearWeak(isolate);
|
||||
*(reinterpret_cast<bool*>(data)) = true;
|
||||
v8::Persistent<v8::Object>* obj,
|
||||
bool* data) {
|
||||
obj->ClearWeak(isolate);
|
||||
*(data) = true;
|
||||
}
|
||||
|
||||
|
||||
@ -11812,11 +11810,11 @@ v8::Persistent<v8::Object> some_object;
|
||||
v8::Persistent<v8::Object> bad_handle;
|
||||
|
||||
void NewPersistentHandleCallback(v8::Isolate* isolate,
|
||||
v8::Persistent<v8::Value> handle,
|
||||
v8::Persistent<v8::Value>* handle,
|
||||
void*) {
|
||||
v8::HandleScope scope(isolate);
|
||||
bad_handle = v8::Persistent<v8::Object>::New(isolate, some_object);
|
||||
handle.Dispose(isolate);
|
||||
handle->Dispose(isolate);
|
||||
}
|
||||
|
||||
|
||||
@ -11835,7 +11833,9 @@ THREADED_TEST(NewPersistentHandleFromWeakCallback) {
|
||||
// global handle nodes are processed by PostGarbageCollectionProcessing
|
||||
// in reverse allocation order, so if second allocated handle is deleted,
|
||||
// weak callback of the first handle would be able to 'reallocate' it.
|
||||
handle1.MakeWeak(isolate, NULL, NewPersistentHandleCallback);
|
||||
handle1.MakeWeak<v8::Value, void>(isolate,
|
||||
NULL,
|
||||
NewPersistentHandleCallback);
|
||||
handle2.Dispose(isolate);
|
||||
HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
|
||||
}
|
||||
@ -11844,11 +11844,11 @@ THREADED_TEST(NewPersistentHandleFromWeakCallback) {
|
||||
v8::Persistent<v8::Object> to_be_disposed;
|
||||
|
||||
void DisposeAndForceGcCallback(v8::Isolate* isolate,
|
||||
v8::Persistent<v8::Value> handle,
|
||||
v8::Persistent<v8::Value>* handle,
|
||||
void*) {
|
||||
to_be_disposed.Dispose(isolate);
|
||||
HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
|
||||
handle.Dispose(isolate);
|
||||
handle->Dispose(isolate);
|
||||
}
|
||||
|
||||
|
||||
@ -11862,23 +11862,23 @@ THREADED_TEST(DoNotUseDeletedNodesInSecondLevelGc) {
|
||||
handle1 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
|
||||
handle2 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
|
||||
}
|
||||
handle1.MakeWeak(isolate, NULL, DisposeAndForceGcCallback);
|
||||
handle1.MakeWeak<v8::Value, void>(isolate, NULL, DisposeAndForceGcCallback);
|
||||
to_be_disposed = handle2;
|
||||
HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
|
||||
}
|
||||
|
||||
void DisposingCallback(v8::Isolate* isolate,
|
||||
v8::Persistent<v8::Value> handle,
|
||||
v8::Persistent<v8::Value>* handle,
|
||||
void*) {
|
||||
handle.Dispose(isolate);
|
||||
handle->Dispose(isolate);
|
||||
}
|
||||
|
||||
void HandleCreatingCallback(v8::Isolate* isolate,
|
||||
v8::Persistent<v8::Value> handle,
|
||||
v8::Persistent<v8::Value>* handle,
|
||||
void*) {
|
||||
v8::HandleScope scope(isolate);
|
||||
v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
|
||||
handle.Dispose(isolate);
|
||||
handle->Dispose(isolate);
|
||||
}
|
||||
|
||||
|
||||
@ -11893,8 +11893,8 @@ THREADED_TEST(NoGlobalHandlesOrphaningDueToWeakCallback) {
|
||||
handle2 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
|
||||
handle1 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
|
||||
}
|
||||
handle2.MakeWeak(isolate, NULL, DisposingCallback);
|
||||
handle3.MakeWeak(isolate, NULL, HandleCreatingCallback);
|
||||
handle2.MakeWeak<v8::Value, void>(isolate, NULL, DisposingCallback);
|
||||
handle3.MakeWeak<v8::Value, void>(isolate, NULL, HandleCreatingCallback);
|
||||
HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
|
||||
}
|
||||
|
||||
|
@ -1586,9 +1586,9 @@ bool HasWeakGlobalHandle() {
|
||||
|
||||
|
||||
static void PersistentHandleCallback(v8::Isolate* isolate,
|
||||
v8::Persistent<v8::Value> handle,
|
||||
v8::Persistent<v8::Value>* handle,
|
||||
void*) {
|
||||
handle.Dispose(isolate);
|
||||
handle->Dispose(isolate);
|
||||
}
|
||||
|
||||
|
||||
@ -1600,7 +1600,9 @@ TEST(WeakGlobalHandle) {
|
||||
|
||||
v8::Persistent<v8::Object> handle =
|
||||
v8::Persistent<v8::Object>::New(env->GetIsolate(), v8::Object::New());
|
||||
handle.MakeWeak(env->GetIsolate(), NULL, PersistentHandleCallback);
|
||||
handle.MakeWeak<v8::Value, void>(env->GetIsolate(),
|
||||
NULL,
|
||||
PersistentHandleCallback);
|
||||
|
||||
CHECK(HasWeakGlobalHandle());
|
||||
}
|
||||
|
@ -396,10 +396,10 @@ TEST(GlobalHandles) {
|
||||
static bool WeakPointerCleared = false;
|
||||
|
||||
static void TestWeakGlobalHandleCallback(v8::Isolate* isolate,
|
||||
v8::Persistent<v8::Value> handle,
|
||||
v8::Persistent<v8::Value>* handle,
|
||||
void* id) {
|
||||
if (1234 == reinterpret_cast<intptr_t>(id)) WeakPointerCleared = true;
|
||||
handle.Dispose(isolate);
|
||||
handle->Dispose(isolate);
|
||||
}
|
||||
|
||||
|
||||
@ -427,8 +427,8 @@ TEST(WeakGlobalHandlesScavenge) {
|
||||
|
||||
global_handles->MakeWeak(h2.location(),
|
||||
reinterpret_cast<void*>(1234),
|
||||
NULL,
|
||||
&TestWeakGlobalHandleCallback);
|
||||
&TestWeakGlobalHandleCallback,
|
||||
NULL);
|
||||
|
||||
// Scavenge treats weak pointers as normal roots.
|
||||
heap->PerformScavenge();
|
||||
@ -474,8 +474,8 @@ TEST(WeakGlobalHandlesMark) {
|
||||
|
||||
global_handles->MakeWeak(h2.location(),
|
||||
reinterpret_cast<void*>(1234),
|
||||
NULL,
|
||||
&TestWeakGlobalHandleCallback);
|
||||
&TestWeakGlobalHandleCallback,
|
||||
NULL);
|
||||
CHECK(!GlobalHandles::IsNearDeath(h1.location()));
|
||||
CHECK(!GlobalHandles::IsNearDeath(h2.location()));
|
||||
|
||||
@ -511,8 +511,8 @@ TEST(DeleteWeakGlobalHandle) {
|
||||
|
||||
global_handles->MakeWeak(h.location(),
|
||||
reinterpret_cast<void*>(1234),
|
||||
NULL,
|
||||
&TestWeakGlobalHandleCallback);
|
||||
&TestWeakGlobalHandleCallback,
|
||||
NULL);
|
||||
|
||||
// Scanvenge does not recognize weak reference.
|
||||
heap->PerformScavenge();
|
||||
|
@ -304,11 +304,11 @@ TEST(GCCallback) {
|
||||
|
||||
static int NumberOfWeakCalls = 0;
|
||||
static void WeakPointerCallback(v8::Isolate* isolate,
|
||||
v8::Persistent<v8::Value> handle,
|
||||
v8::Persistent<v8::Value>* handle,
|
||||
void* id) {
|
||||
ASSERT(id == reinterpret_cast<void*>(1234));
|
||||
NumberOfWeakCalls++;
|
||||
handle.Dispose(isolate);
|
||||
handle->Dispose(isolate);
|
||||
}
|
||||
|
||||
TEST(ObjectGroups) {
|
||||
@ -327,16 +327,16 @@ TEST(ObjectGroups) {
|
||||
global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
|
||||
global_handles->MakeWeak(g1s1.location(),
|
||||
reinterpret_cast<void*>(1234),
|
||||
NULL,
|
||||
&WeakPointerCallback);
|
||||
&WeakPointerCallback,
|
||||
NULL);
|
||||
global_handles->MakeWeak(g1s2.location(),
|
||||
reinterpret_cast<void*>(1234),
|
||||
NULL,
|
||||
&WeakPointerCallback);
|
||||
&WeakPointerCallback,
|
||||
NULL);
|
||||
global_handles->MakeWeak(g1c1.location(),
|
||||
reinterpret_cast<void*>(1234),
|
||||
NULL,
|
||||
&WeakPointerCallback);
|
||||
&WeakPointerCallback,
|
||||
NULL);
|
||||
|
||||
Handle<Object> g2s1 =
|
||||
global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
|
||||
@ -346,16 +346,16 @@ TEST(ObjectGroups) {
|
||||
global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
|
||||
global_handles->MakeWeak(g2s1.location(),
|
||||
reinterpret_cast<void*>(1234),
|
||||
NULL,
|
||||
&WeakPointerCallback);
|
||||
&WeakPointerCallback,
|
||||
NULL);
|
||||
global_handles->MakeWeak(g2s2.location(),
|
||||
reinterpret_cast<void*>(1234),
|
||||
NULL,
|
||||
&WeakPointerCallback);
|
||||
&WeakPointerCallback,
|
||||
NULL);
|
||||
global_handles->MakeWeak(g2c1.location(),
|
||||
reinterpret_cast<void*>(1234),
|
||||
NULL,
|
||||
&WeakPointerCallback);
|
||||
&WeakPointerCallback,
|
||||
NULL);
|
||||
|
||||
Handle<Object> root = global_handles->Create(*g1s1); // make a root.
|
||||
|
||||
@ -384,8 +384,8 @@ TEST(ObjectGroups) {
|
||||
// Weaken the root.
|
||||
global_handles->MakeWeak(root.location(),
|
||||
reinterpret_cast<void*>(1234),
|
||||
NULL,
|
||||
&WeakPointerCallback);
|
||||
&WeakPointerCallback,
|
||||
NULL);
|
||||
// But make children strong roots---all the objects (except for children)
|
||||
// should be collectable now.
|
||||
global_handles->ClearWeakness(g1c1.location());
|
||||
@ -413,12 +413,12 @@ TEST(ObjectGroups) {
|
||||
// And now make children weak again and collect them.
|
||||
global_handles->MakeWeak(g1c1.location(),
|
||||
reinterpret_cast<void*>(1234),
|
||||
NULL,
|
||||
&WeakPointerCallback);
|
||||
&WeakPointerCallback,
|
||||
NULL);
|
||||
global_handles->MakeWeak(g2c1.location(),
|
||||
reinterpret_cast<void*>(1234),
|
||||
NULL,
|
||||
&WeakPointerCallback);
|
||||
&WeakPointerCallback,
|
||||
NULL);
|
||||
|
||||
HEAP->CollectGarbage(OLD_POINTER_SPACE);
|
||||
CHECK_EQ(7, NumberOfWeakCalls);
|
||||
|
@ -65,11 +65,11 @@ static void PutIntoWeakMap(Handle<JSWeakMap> weakmap,
|
||||
|
||||
static int NumberOfWeakCalls = 0;
|
||||
static void WeakPointerCallback(v8::Isolate* isolate,
|
||||
v8::Persistent<v8::Value> handle,
|
||||
v8::Persistent<v8::Value>* handle,
|
||||
void* id) {
|
||||
ASSERT(id == reinterpret_cast<void*>(1234));
|
||||
NumberOfWeakCalls++;
|
||||
handle.Dispose(isolate);
|
||||
handle->Dispose(isolate);
|
||||
}
|
||||
|
||||
|
||||
@ -114,8 +114,8 @@ TEST(Weakness) {
|
||||
HandleScope scope(isolate);
|
||||
global_handles->MakeWeak(key.location(),
|
||||
reinterpret_cast<void*>(1234),
|
||||
NULL,
|
||||
&WeakPointerCallback);
|
||||
&WeakPointerCallback,
|
||||
NULL);
|
||||
}
|
||||
CHECK(global_handles->IsWeak(key.location()));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user