Capturing the first invocation of a method
Volker Simonis
volker.simonis at gmail.com
Tue Jan 8 01:48:19 PST 2008
Hi Harry,
you can use the option "-XX:+TraceBytecodes" which is however
available in a debug build only. This will you give on output as
follows:
[5158714] static void java.lang.Object.<clinit>()
[5158714] 1 0 invokestatic 9 <registerNatives> <()V>
[5158714] 2 3 return
[5158714] static void java.lang.String.<clinit>()
[5158714] 3 0 iconst_0
[5158714] 4 1 anewarray java/io/ObjectStreamField
[5158714] 5 4 putstatic 84
[5158714] 6 7 new 105
[5158714] 7 10 dup
[5158714] 8 11 aconst_null
[5158714] 9 12 invokespecial 85 <<init>> <(Ljava/lang/String$1;)V>
[5158714] virtual void
java.lang.String$CaseInsensitiveComparator.<init>(jobject)
[5158714] 10 0 aload_0
[5158714] 11 1 invokespecial 0 <<init>> <()V>
Now you can grep the output for the first invocation of the method
you're interested in. Once you know the bytecodeindex, you can use
'-XX:TraceBytecodesAt=<BytecodeIndex>' to start the Bytecodetrace at
the given index or '-XX:StopInterpreterAt=<BytecodeIndex>' to stop at
the given ByteCode (this only works inside a debugger!).
If you want to stop at the first invocation of a compiled method, you
can use the '.hotspot_compiler' file or the
'-XX:CompileCommand=break,class/name.methodName' command line option
(e.g. '-XX:CompileCommand=break,java/lang/StringBuffer.append' - see
hotspot/src/share/vm/compiler/CompilerOracle.cpp for more details.)
Hope this helps,
Volker
On 1/8/08, Harry Yale <harryyale at gmail.com> wrote:
> Hi,
>
> How can I capture the moment of the very first invocation of every Java
> method?
>
> I have tried the following approach:
>
>
> In InterpreterGenerator::generate_counter_incr(), I look
> for the counter value 1 (actually 8 (1 << 3) because the lowest 3 bits are
> used for other purposes)
> and if so jump to a function in InterpreterRuntime (like
> InterpreterRuntime::frequency_counter_overflow()) which
> prints the name of the method.
>
> but I haven't been able to see the first invocation of non-native Java
> methods. Non-native Java methods seem to have a much larger counter value by
> the time I capture them in the above function.
>
> Am I missing another invocation path or is there a better approach?
>
> Thanks.
>
>
More information about the hotspot-dev
mailing list