Hi Yang,
  Thank you very much for your reply.
  
  I looked into the problem of identity hash problem and noticed something 
weird: In function create event, I will call GetOrCreateIdentityHash on 
every object then I save the hash code in a wrapper class. Later, when 
function is called, I will call GetIdentityHash again and then I notice 
sometimes, the hash code returned is <undefined> while I am sure the hash 
code is created before in function create event. It seems some JSFunction 
object will lost its hash code somehow, is that designed such way?
  
  Plus, the hash code seems will make call/apply methods in Javascript not 
working properly and the Javascript will throw a error say call/apply is 
not a function object. Do you have any clue what may be wrong?

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.

Reply via email to