Implement MarkIndependent(Isolate*) and MarkPartiallyDependent(Isolate*)

BUG=
TEST=cctest/test-api/IndependentWeakHandle

Review URL: https://codereview.chromium.org/11369131
Patch from Kentaro Hara <haraken@chromium.org>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12904 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 36d128d7
...@@ -413,6 +413,7 @@ template <class T> class Persistent : public Handle<T> { ...@@ -413,6 +413,7 @@ template <class T> class Persistent : public Handle<T> {
* or followed by a global GC epilogue callback. * or followed by a global GC epilogue callback.
*/ */
inline void MarkIndependent(); inline void MarkIndependent();
inline void MarkIndependent(Isolate* isolate);
/** /**
* Marks the reference to this object partially dependent. Partially * Marks the reference to this object partially dependent. Partially
...@@ -423,6 +424,7 @@ template <class T> class Persistent : public Handle<T> { ...@@ -423,6 +424,7 @@ template <class T> class Persistent : public Handle<T> {
* after each garbage collection. * after each garbage collection.
*/ */
inline void MarkPartiallyDependent(); inline void MarkPartiallyDependent();
inline void MarkPartiallyDependent(Isolate* isolate);
/** Returns true if this handle was previously marked as independent. */ /** Returns true if this handle was previously marked as independent. */
inline bool IsIndependent() const; inline bool IsIndependent() const;
...@@ -3533,7 +3535,11 @@ class V8EXPORT V8 { ...@@ -3533,7 +3535,11 @@ class V8EXPORT V8 {
WeakReferenceCallback); WeakReferenceCallback);
static void ClearWeak(internal::Object** global_handle); static void ClearWeak(internal::Object** global_handle);
static void MarkIndependent(internal::Object** global_handle); static void MarkIndependent(internal::Object** global_handle);
static void MarkIndependent(internal::Isolate* isolate,
internal::Object** global_handle);
static void MarkPartiallyDependent(internal::Object** global_handle); static void MarkPartiallyDependent(internal::Object** global_handle);
static void MarkPartiallyDependent(internal::Isolate* isolate,
internal::Object** global_handle);
static bool IsGlobalIndependent(internal::Object** global_handle); static bool IsGlobalIndependent(internal::Object** global_handle);
static bool IsGlobalIndependent(internal::Isolate* isolate, static bool IsGlobalIndependent(internal::Isolate* isolate,
internal::Object** global_handle); internal::Object** global_handle);
...@@ -4335,11 +4341,23 @@ void Persistent<T>::MarkIndependent() { ...@@ -4335,11 +4341,23 @@ void Persistent<T>::MarkIndependent() {
V8::MarkIndependent(reinterpret_cast<internal::Object**>(**this)); V8::MarkIndependent(reinterpret_cast<internal::Object**>(**this));
} }
template <class T>
void Persistent<T>::MarkIndependent(Isolate* isolate) {
V8::MarkIndependent(reinterpret_cast<internal::Isolate*>(isolate),
reinterpret_cast<internal::Object**>(**this));
}
template <class T> template <class T>
void Persistent<T>::MarkPartiallyDependent() { void Persistent<T>::MarkPartiallyDependent() {
V8::MarkPartiallyDependent(reinterpret_cast<internal::Object**>(**this)); V8::MarkPartiallyDependent(reinterpret_cast<internal::Object**>(**this));
} }
template <class T>
void Persistent<T>::MarkPartiallyDependent(Isolate* isolate) {
V8::MarkPartiallyDependent(reinterpret_cast<internal::Isolate*>(isolate),
reinterpret_cast<internal::Object**>(**this));
}
template <class T> template <class T>
void Persistent<T>::SetWrapperClassId(uint16_t class_id) { void Persistent<T>::SetWrapperClassId(uint16_t class_id) {
V8::SetWrapperClassId(reinterpret_cast<internal::Object**>(**this), class_id); V8::SetWrapperClassId(reinterpret_cast<internal::Object**>(**this), class_id);
......
...@@ -651,6 +651,13 @@ void V8::MarkIndependent(i::Object** object) { ...@@ -651,6 +651,13 @@ void V8::MarkIndependent(i::Object** object) {
} }
void V8::MarkIndependent(i::Isolate* isolate, i::Object** object) {
ASSERT(isolate == i::Isolate::Current());
LOG_API(isolate, "MarkIndependent");
isolate->global_handles()->MarkIndependent(object);
}
void V8::MarkPartiallyDependent(i::Object** object) { void V8::MarkPartiallyDependent(i::Object** object) {
i::Isolate* isolate = i::Isolate::Current(); i::Isolate* isolate = i::Isolate::Current();
LOG_API(isolate, "MarkPartiallyDependent"); LOG_API(isolate, "MarkPartiallyDependent");
...@@ -658,6 +665,13 @@ void V8::MarkPartiallyDependent(i::Object** object) { ...@@ -658,6 +665,13 @@ void V8::MarkPartiallyDependent(i::Object** object) {
} }
void V8::MarkPartiallyDependent(i::Isolate* isolate, i::Object** object) {
ASSERT(isolate == i::Isolate::Current());
LOG_API(isolate, "MarkPartiallyDependent");
isolate->global_handles()->MarkPartiallyDependent(object);
}
bool V8::IsGlobalIndependent(i::Object** obj) { bool V8::IsGlobalIndependent(i::Object** obj) {
i::Isolate* isolate = i::Isolate::Current(); i::Isolate* isolate = i::Isolate::Current();
LOG_API(isolate, "IsGlobalIndependent"); LOG_API(isolate, "IsGlobalIndependent");
......
...@@ -2610,14 +2610,15 @@ TEST(ApiObjectGroupsCycleForScavenger) { ...@@ -2610,14 +2610,15 @@ TEST(ApiObjectGroupsCycleForScavenger) {
root.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback); root.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
root.MarkPartiallyDependent(); root.MarkPartiallyDependent();
v8::Isolate* isolate = v8::Isolate::GetCurrent();
// Groups are deleted, rebuild groups. // Groups are deleted, rebuild groups.
{ {
g1s1.MarkPartiallyDependent(); g1s1.MarkPartiallyDependent(isolate);
g1s2.MarkPartiallyDependent(); g1s2.MarkPartiallyDependent(isolate);
g2s1.MarkPartiallyDependent(); g2s1.MarkPartiallyDependent(isolate);
g2s2.MarkPartiallyDependent(); g2s2.MarkPartiallyDependent(isolate);
g3s1.MarkPartiallyDependent(); g3s1.MarkPartiallyDependent(isolate);
g3s2.MarkPartiallyDependent(); g3s2.MarkPartiallyDependent(isolate);
Persistent<Value> g1_objects[] = { g1s1, g1s2 }; Persistent<Value> g1_objects[] = { g1s1, g1s2 };
Persistent<Value> g2_objects[] = { g2s1, g2s2 }; Persistent<Value> g2_objects[] = { g2s1, g2s2 };
Persistent<Value> g3_objects[] = { g3s1, g3s2 }; Persistent<Value> g3_objects[] = { g3s1, g3s2 };
...@@ -5505,23 +5506,28 @@ THREADED_TEST(IndependentWeakHandle) { ...@@ -5505,23 +5506,28 @@ THREADED_TEST(IndependentWeakHandle) {
v8::Persistent<Context> context = Context::New(); v8::Persistent<Context> context = Context::New();
Context::Scope context_scope(context); Context::Scope context_scope(context);
v8::Persistent<v8::Object> object_a; v8::Persistent<v8::Object> object_a, object_b;
{ {
v8::HandleScope handle_scope; v8::HandleScope handle_scope;
object_a = v8::Persistent<v8::Object>::New(v8::Object::New()); object_a = v8::Persistent<v8::Object>::New(v8::Object::New());
object_b = v8::Persistent<v8::Object>::New(v8::Object::New());
} }
v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::Isolate* isolate = v8::Isolate::GetCurrent();
bool object_a_disposed = false; bool object_a_disposed = false;
bool object_b_disposed = false;
object_a.MakeWeak(&object_a_disposed, &DisposeAndSetFlag); object_a.MakeWeak(&object_a_disposed, &DisposeAndSetFlag);
object_b.MakeWeak(&object_b_disposed, &DisposeAndSetFlag);
CHECK(!object_a.IsIndependent()); CHECK(!object_a.IsIndependent());
CHECK(!object_a.IsIndependent(isolate)); CHECK(!object_b.IsIndependent(isolate));
object_a.MarkIndependent(); object_a.MarkIndependent();
object_b.MarkIndependent(isolate);
CHECK(object_a.IsIndependent()); CHECK(object_a.IsIndependent());
CHECK(object_a.IsIndependent(isolate)); CHECK(object_b.IsIndependent(isolate));
HEAP->PerformScavenge(); HEAP->PerformScavenge();
CHECK(object_a_disposed); CHECK(object_a_disposed);
CHECK(object_b_disposed);
} }
......
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