Hi Yang, Sorry to disturb you again. I worked around the hash problem by only instrumenting the NewClosure runtime function. If I understand correctly, all JS unctions defined in a *.js file is considered as a closure so they should be created by NewClosure runtime (after I disable the FastNewClosureStub). Also, there are some functions not created by NewClosure runtime, they seem to be some sort of internal functions.
In general, I only care about the functions defined in *.js file instead of others. So I am wondering if my instrumentation is complete? Thanks, Wenzhi Cui On Monday, December 21, 2015 at 5:57:24 PM UTC+8, Yang Guo wrote: > > Hi Wenzhi, > > I'll try to answer your questions inline. > > On Sun, Dec 20, 2015 at 2:28 PM WENZHI CUI <[email protected] > <javascript:>> wrote: > >> Hi all, >> Sorry if this post disturbs you, I have some specific questions about >> v8 function events but I cannot find anything on google. >> >> For some reason I want to instrument the JSFunction events (especially >> for closures), e.g., I want to instrument the creation/invocation events of >> JSFunction activities. I want to make v8 call some my own function if a >> JSFunction get allocated and accessed. >> >> The high level idea is when a JSFunction is created on heap, I will >> create a persistent handle for it and put it in a hash table (currently I >> am using unordered_set). I will also make it weak so I can instrument the >> deallocation of this JSFunction object. >> > You would have to come up with a custom weakness implementation similar to > the external string table. The standard way for weakness through WeakCell > does not offer a finalizer callback. > > >> I also modified runtime function traceEnter & traceExit so I can add my >> hooks for function invocation. >> >> However, I do have two questions about this: >> 1. The way I instrument function creation is add a hook in >> Factory::NewFunction(...). Unfortunately some closures are created through >> FastNewClosureStub which will not call the factory methods. My work around >> is to force all closure are allocated through runtime function NewClosure >> but it seems a bad idea. I guess somewhere in the FastNewClosureStub will >> also call some heap allocation procedure which created a JSFunction object >> but I cannot find it. Does anyone know where is it? >> > I think, for the sake of tracing, not using the FastNewClosureStub is not > an issue. It's just a performance optimization after all. > > >> >> 2. I want to put the persistent handles in a hash table, but I have >> trouble find a useful hash function. I tried Local->GetIdentityHash() but >> it seems it will break my code somehow, especially when I call it in >> kTraceEnter, Here is my code: >> >> RUNTIME_FUNCTION(Runtime_TraceEnter) { >> ... >> JavaScriptFrameIterator it(isolate); >> if (!it.done()) { >> if (it.frame()->is_java_script()) { >> JavaScriptFrame* frame = it.frame(); >> JSFunction* function = frame->function(); >> Handle<JSFunction> handle(function); >> Local<Function> local = Utils::ToLocal(handle); >> local->GetIdentityHash(); // my program always crash is I call >> GetIdentityHash here >> } >> } >> } >> >> You don't have to go through the API to get to the identity hash. You can > use JSReceiver::GetOrCreateIdentityHash. You should hook up the crash to > gdb to see what's going on there. > > >> Please let me know if you have any question or other concern. Thank you >> for reading my post. >> >> Thanks, >> Wenzhi Cui >> >> -- >> -- >> v8-dev mailing list >> [email protected] <javascript:> >> http://groups.google.com/group/v8-dev >> --- >> You received this message because you are subscribed to the Google Groups >> "v8-dev" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > -- -- v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev --- You received this message because you are subscribed to the Google Groups "v8-dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
