But the question is now how do u debug? Generally the loggers we kept are in-sufficient or in production they disabled debug, info levels of log4j; now how? or say we forgot logging a variable.. now how to debug the issue?
wouldnt it be nice if i have an agent sitting outside the main JVM and printing out the variable i wanted? is it possible? the answer is YES!!!
BTrace is the gem in Java-s Crown. So it works like this
- The original JVM runs on some PID
- The Btrace program runs outside and connects to this pid; printing ur variable as u wanted
You need to download the BTrace package; Create a java program; Typically it looks as follows
In the dowloaded package, open the btrace file located in bin folder and in the end change to the below. The line is to the end of the file
Issues to lookout
- If u havent changed btrace file, ran the above process and then modifed the unsafe to true on running the btrace u see VerificationError.
- As said here it happens because the 1st run made the target JVM to mark any unsafe to false
- for this u will have to restart the target m/c