Dynamic Byteman Rule Injection
gaurav6281 Nov 16, 2016 6:45 AMHi,
I am using JDK 6. Tried both Byteman versions 2.1.2 and 3.0.6. Both Java program and agent / rule installation and submission of rule is happening on my local Windows machine only.
I want to inject my agent and rule dynamically inside already running java process. But I am not getting expected result and also no errors.
My Java process which is running with ProcessId :- 15356
public class TestByteMan {
public static void main(String[] args) throws Exception{
System.out.println("Inside Main");
int x=1;
Thread.sleep(120000);
System.out.println("x is "+x);
int y =add();
System.out.println("Y is "+y);
int z=x+y;
System.out.println("Final Addition result is "+z);
}
private static int add(){
return 3;
}
}
My btm file (rule file is)
RULE Testing Going On
CLASS TestByteMan
METHOD main
AFTER WRITE $y
IF $y==3
DO traceln("hello World")
ENDRULE
(a) I am installing agent dynamically as below:-
C:\Users\gaurav>java -classpath "C:\Users\gaurav\BYTEMAN_TESTING\install\*" org.jboss.byteman.agent.install.Install -h localhost -p 12345 -Dorg.jboss.byteman.verbose 15356 ---(where C:\Users\gaurav\BYTEMAN_TESTING\install contains both byteman.jar , jdk 6 tools.jar and byteman-install.jar)
When above command is fired in another command prompt , I can see below getting printing in the first command prompt where Java process is running.
C:\Users\gaurav>java TestByteMan
Inside Main
Setting org.jboss.byteman.verbose=
TransformListener() : accepting requests on localhost:12345
(b) I am submitting the rules dynamically as below:-
C:\Users\N662245>java -classpath "C:\Users\gaurav\BYTEMAN_TESTING\submit\*" org.jboss.byteman.agent.submit.Submit -h localhost -p 12345 -l test.btm ---(where C:\Users\gaurav\BYTEMAN_TESTING\submit contains tools.jar, byteman.jar and byyteman-submit.jar)
install rule Testing Going On
When above command is fired in another command prompt , I can see below getting printing in the first command prompt where Java process is running.
TransformListener() : handling connection on port 12345
retransforming TestByteMan
org.jboss.byteman.agent.Transformer : possible trigger for rule Testing Going On in class TestByteMan
org.jboss.byteman.agent.Transformer : inserted trigger for Testing Going On in class TestByteMan
My Expectations:- After int y=add() statement in my above java class, my logger statement of "hello World" should get printed and then Y is 3 should be printed. I am submitting and injecting rule well within 2 mins of sleep which I have given in my main java class.
But actual result is :-(without my rule getting worked)
C:\Users\N662245>java TestByteMan
Inside Main
Setting org.jboss.byteman.verbose=
TransformListener() : accepting requests on localhost:12345
TransformListener() : handling connection on port 12345
retransforming TestByteMan
org.jboss.byteman.agent.Transformer : possible trigger for rule Testing Going On in class TestByteMan
org.jboss.byteman.agent.Transformer : inserted trigger for Testing Going On in class TestByteMan
x is 1
Y is 3
Final Addition result is 4
Can someone please guide me why it is not working ?