How to compare thecaller thread object and callee's holder?
Tony Guan
guanxiaohua at gmail.com
Thu Apr 22 15:50:11 PDT 2010
Hi David,
Thanks you for the reply. By "holder" of a method, I mean the object
whose class owns the method interested.
for a callee method, we may refer it as receiver.
and for a caller, let's just name it as a caller object, sorry for the
vague term I borrowed from the source code of hotspot. The following
code shows more accurately what I want:
class B{
methodB(){
...
}
}
class A{
void methodA()
{
B objectB=new B();
objectB.methodB(); //*****here is what I am at
}
static public main(args)
{
A objectA=new A();
A.methodA();
}
}
Now, as we are calling objectB.methodB() from A.methodA(), all I need
is to find out objectA and objectB from within the JVM.
Given that from the dtrace functionality, I already know the current
thread, and the methodOoopDesc* of the called method, I need to
identify the caller object and the callee object from the two
parameters passed to the dtrace_method_entry:
JRT_LEAF(int, SharedRuntime::dtrace_method_entry( JavaThread* thread,
methodOopDesc* method)) in shareRuntime.cpp
Thanks!
Tony (Xiaohua Guan)
On Wed, Apr 21, 2010 at 8:11 PM, David Holmes <David.Holmes at oracle.com> wrote:
> Tony,
>
> Tony Guan said the following on 04/22/10 00:06:
>>
>> a quick question: given a caller thread object( JavaThread* thread)
>> and the method to be called by the thread (methodOopDesc* method), how
>> do I know that the holder of the "method" is from the same caller
>> object or not?
>
> I don't understand what you mean here by "holder"?
>
>> The reason why I am asking is:
>> in
>> JRT_LEAF(int, SharedRuntime::dtrace_method_entry( JavaThread*
>> thread, methodOopDesc* method)) in shareRuntime.cpp
>>
>> I want to check if the method called will start another thread or not,
>> so I need to compare the holders of the caller and callee.
>
> Again I don't know what the "holder" is here. If a method starts a thread
> then that new thread doesn't necessarily have any connection back to the
> method from which it was started.
>
>> So one more question: is there any other way to achieve this?
>
> I think you would have to add code in the thread start routine (of the JVM)
> and have the before/after method hooks to do this eg:
>
> before-method: set flag showing current thread is interested in thread
> start
> start-thread: check if current thread interested in thread start and if so
> bump a counter
> after-method: check counter and clear flag
>
> David Holmes
>
More information about the hotspot-runtime-dev
mailing list