Search code examples
javainstrumentationagentjavassistjavaagents

Remote Runtime Instrumentation


I am new at instrumentation world. I am trying to instrumentate a remote JVM at Runtime. Actually, i have to log all classes or part of them and transform them.. I have read many documents and i found this code HERE

I changed the code and i replaced

// Run sayHello in a loop
Person person = new Person();
for(int i = 0; i < 1000; i++) {
    person.sayHello(i);
    person.sayHello("" + (i*-1));
    Thread.currentThread().join(5000);
}

by this one:

for (int i = 1; i < args.length; i++) {
    String className = args[i] ;
    System.out.println("className" + className);
    // Call transformClass on the transformer MBean
    server.invoke(on, "transformClass", new Object[]{className}, new String[]{String.class.getName()});
}

But i found that args.length=0 I don't know what the args[] contain...And if it contains loaded classes (i assume) then why it is empty..

Any help please?


Solution

  • I wrote that code, but I don't understand what you're trying to do in your code. The referenced github gists were in reference to the answer to this SO question, so it may help you to re-read that question.

    There are multiple steps involved, and the classes need to be packaged in a specific way, but the basics are:

    1. Use the AgentInstaller to install the instrumentation agent into a running JVM.
    2. Connect to the JVM via JMX.
    3. Invoke the transformClass(String className, String methodName, String methodSignature) MBean operation to instrument the class using the demo transformer.