Enumerate closure variable

88 views
Skip to first unread message

Mihail Slavchev

unread,
Aug 6, 2015, 12:02:43 PM8/6/15
to v8-users
Hi guys,

I work on NativeScript project and my team uses V8 to access Android APIs from JavaScript. In order to orchestrate V8/Dalvik garbage collectors dance I need to know whether a function creates a closure over an object. For example:

var x = {
    f
: function () { }
}


var y = {
    g
: function () {
        x
.f()
   
}
}


In the example about I have weak callbacks (WeakCallbackData<T, P>::Callback) for both x and y object and during GC I need to know whether object x is reachable from object y. My current approach is built around v8::internal::ScopeInfo and v8::internal::Context::Lookup which played well until recently when we start observing app crashes mostly when we try to access the objects which we concluded belong to a closure.

So far my approach is flawed and I am wondering is there a recommended way that I can use during GC so I can detect whether object x is reachable from object y. Any ideas are appreciated.

TIA,
Mihail


Yang Guo

unread,
Aug 11, 2015, 5:21:19 AM8/11/15
to v8-users
V8 includes the methods Heap::TracePathToObjectFrom, Heap::TracePathToObject and Heap::TracePathToGlobal in debug builds to help with debugging with object reachability. Found paths are printed to stdout. Maybe these methods can help?

Yang

Mihail Slavchev

unread,
Aug 11, 2015, 6:41:34 AM8/11/15
to v8-users
Thanks, I will have a look at it.
Reply all
Reply to author
Forward
0 new messages