-4

I can't get or modify the source code of the program. So I'm trying to read the jvm(hotspot) source code to see if I can do something when it fetch the "call method" instruction, but it seems very complex.

I want to know where is the relevant code I should start with or if there is other way to do this.

  • 1
    It is really not clear what you are asking for. You can use a **profiler**, such as YourKit or JProfiler to *profile* the execution of a Java program. But that just records what is going on. The idea to *patch* a JVM in order to do something special ... honestly: that sounds crazy. I am a 20 year Java programmer, and I wouldn't dare to do that. That is no a viable, robust option to change the behavior of an existing appliction, imho. – GhostCat Jun 21 '19 at 11:10
  • Beyond that: asking for pointers to libraries, tools, source code ... that is off topic here. – GhostCat Jun 21 '19 at 11:10

1 Answers1

1

There is no need to modify JVM code to intercept method invocation. There is a standard documented way to do this using JVMTI.

You'll need to create an agent that will set callbacks for MethodEntry / MethodExit JVMTI events, compile it to a shared library, then run Java with -agentpath:/path/to/libYourAgent.so option.

See an example of using MethodEntry / MethodExit events in this question.

apangin
  • 92,924
  • 10
  • 193
  • 247