Debugging a Java Code running in Oracle JVM - java

I have a code which is running inside Oracle JVM. Is there any way to debug the java code which is running inside the oracle jvm??
Thanks in advance..

Debugging method would be different depending on how you are running the program.
1.If you are running the code from a Java IDE (e.g. Eclipse), you can add Oracle JVM as Runtime (Preferences > Java > Installed JRE) and then launch the Java program from the IDE in debug mode (Debug As > Java Application). This will allow the execution to be suspended at the marked breakpoints and you can browse the code in IDE in suspended mode.
2.If you are running the code in a container or in a standalone JVM (class with main() method), then you may have to enable remote debuging while launching the program. For enabling remote debugging in a container, refer to your container docs. If you are running a standalone program, then use below command for launching the program:
java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=4000,suspend=n NameOfYourMainClass
Once your application is launched with remote debugging enabled, you can use an IDE (e.g. Eclipse) to debug. Refer to this article for detailed steps:
http://java.dzone.com/articles/how-debug-remote-java-applicat
I hope, it helps!

Related

Tomcat applications won't enter debug through intellij on OSX

I am following this book Wrox Java for Web Applications
I have Tomcat 8 set up on my macbook pro which is running OSX Mavericks. When I ever I set a break point in Intellij it just gets ignored. I tried the same in Eclipse and it worked.
I really like Intelij so if I could get it working that be great. Does anyone have any suggestions as to what could be in the issue? I am using Intellij 13.
Thank You
If you're launching Tomcat from IntelliJ then make sure that you launch it debug mode, otherwise breakpoints won't work.
If your Tomcat is external then you can add this to the JVM parameters to enable debuggers to talk to it: -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=5005,suspend=y

Running Visual VM from eclipse

I am trying to debug a java app using Visual VM in Eclipse kepler. I am executing the class having main method selecting Visual VM as launcher. I have configured Visual VM as per the instructions given in http://blog.idrsolutions.com/2013/05/setting-up-visualvm-in-under-5-minutes. I am getting the following error:
An internal error occurred during: “Launching TestNew”.
java.lang.NullPointerException
“TestNew” is the name of the class with main method I am trying to execute.
please help.
I had the same issue... Let me expand a bit on Anushree's comment:
Go to Window ⇒ Preferences ⇒ Run/Debug ⇒ Launching ⇒ VisualVM Configuration
Browse... for the VisualVM Executable in your JDK's bin-directory
Make sure to also set the JDK's root directory under JDK Home. If you leave that pointing to your JRE directory, you'll run into the next error...
Happy profiling...
BTW: If you then have issues getting your application to show up inside jVisualVM, take a look here:
Getting Java program running in Eclipse to show up in VisualVM
For Linux users :
Once visual vm launcher is intalled in eclipse , install visual vm in linux using command "sudo apt-get install -y visualvm".
On successfull installation , in terminal search for
whereis visualvm
The search will give following responses :
visualvm: /usr/bin/visualvm /etc/visualvm /usr/share/visualvm
/usr/share/man/man1/visualvm.1.gz
In eclipse go to
Window --> Preferences --> Run/Debug --> Launching --> VisualVM Configuration
copy the value "/usr/bin/visualvm" in the space and click on apply & close.

Java Linux Arm Remote Debugging With Eclipse: "Profiling and debugging agents are not supported in this VM"

I am part of a team working on a library for the First Robotics Competition. We have a series of tools that allow teams to write and debug their robots using eclipse along with our own custom eclipse plugins. Before now, we were confined to using a custom version of JDK 1.3 to run programs on the CRIO which had a built in debug mode. However we are now using jdk-linux-arm (a version of Java 8 for embedded ARM chips). In order to debug our programs they have to be run remotely on the chip because of JNI dependencies.
The command that I am using to run the program in debug mode is:
killall java
killall FRCUserProgram
sleep 1
nohup /usr/local/frc/JRE/bin/java -Xdebug -Xrunjdwp:transport=dt_socket,address=8998,server=y -jar FRCUserProgram.jar
However when I try this I get the following Output:
[sshexec] killall: java: no process killed
[sshexec] Profiling and debugging agents are not supported in this VM
[sshexec] Error: Could not create the Java Virtual Machine.
[sshexec] Error: A fatal exception has occurred. Program will exit.
Are there any other methods to enable remote debugging for JDK Linux Arm through eclipse? This has to be able to run through eclipse with breakpoints enabled an all of the other features that eclipse debugging offers.
Rebuild the jvm to support debugging using jrecreate
jrecreate --dest tmp/JRE_DEBUG/ --profile compact2 --vm client --kee
p-debug-info --debug
see this link http://docs.oracle.com/javase/8/embedded/develop-platforms/jrecreate.htm#CACGABAD
use the following command line to run the program:
java -XX:+UsePerfData -agentlib:jdwp=transport=dt_socket,address=8348,server=y,suspend=y -jar FRCUserProgram.jar

Remote Java Debugging with Eclipse's Remote System Explorer

Does anyone have experience debugging java code (code lives on remote Linux server) using Eclipse's Remote System Explorer? I'm able to explorer files and use the built in shell but I can't get it to stop on any breakpoints within the eclipse ide.
I'm taking a punt that your remote java server needs to be started using something like:
java -Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y suspend=y -jar stockTradingGUI.jar
Then you will be able to connect using the eclipse remote debugger
For a full run down see: http://javarevisited.blogspot.com/2011/02/how-to-setup-remote-debugging-in.html

VisualVM "not supported for this JVM" on all local applications?

I have already spent a long time to load and test my application, now I need to profile it. But unluckily, the VisualVM always says "not supported for this JVM" on my local applications?
The applications were started on the same JVM with VisualVM.
I found out that (at least under Windows) one can easily write small batch files to run VisualVM in combination with specific JVMs, which is important for me, since I have installed the 32bit JDK alongside with the 64bit JDK (I need both, so this is sensible for me).
I have created two batch files in the folder "S:\applications\visualvm\bin\":
run_32.bat:
#echo off
START "VisualVM 32" visualvm.exe --jdkhome "C:\Program Files (x86)\Java\jdk1.7.0_07"
run_64.bat:
#echo off
START "VisualVM 64" visualvm.exe --jdkhome "C:\Program Files\Java\jdk1.7.0_07"
Obviously, all paths may differ on your system, but the general idea should still work correctly (on all 64bit versions of Windows). The benefit is that I can use the 32bit batch file when I want to use VisualVM in combination with Java applications that run on the 32bit JVM, and so on for 64bit.
The "start" command has the only benefit that the batch file launches the application without waiting for it to finish, so the command prompt window closes immediately. This is not a feature of VisualVM, but of the Windows batch file interpreter.
In my case, even with the JVMs matching (both 64-Bit), the only way to get things working was sending the argument -Dcom.sun.management.jmxremote to the JVM to be monitored. That also works if you are having problems to connect via Java Mission Control (JMC).
According to JMX's documentation, this what the argument does:
Setting this property registered the Java VM platform's MBeans and published the Remote Method Invocation (RMI) connector via a private interface to allow JMX client applications to monitor a local Java platform, that is, a Java VM running on the same machine as the JMX client.
This was supposed to be enabled automatically, but for some reason it wasn't on my Linux.
VisualVM needs to be run with the same JVM - at least Java 6 with the same 32-bit/64-bit size - as the program to be profiled. (You also need to be the same user, but then this message does not apply).
I would be triple-check that it was the exact same JVM in your situation.
On Linux:
Make sure that your /etc/hosts correctly references the effective ip address of your "hostname"
It appears that a discrepancy here totally confuses the poor jvisualvm and its programmers.
I too got the same problem for local tomcat, I search for solutions for stackoverflow. after some serious debugging, I figured out that VisualGC don't have permissions to get GC informations from tool.jar file.
by links
http://docs.oracle.com/javase/7/docs/technotes/tools/share/jstatd.html#SECURITY
https://stackoverflow.com/a/42107355/3876619
I following steps to solve the issue
1) Create a permission file
vim /tmp/tools.policy
Add
grant codebase "file:${java.home}/../lib/tools.jar" {
permission java.security.AllPermission;
};
save it
2) Now add /tmp/tools.policy to JVM startup parameters
-Djava.security.policy=/tmp/tools.policy
3) Run jvisualVm with sudo
An issue that I just found, thanks to the hint from #user3356656, is that if you start the program while your machine is on one IP, and then try to connect while it is on a different IP, it will fail.
I also met this issue. My case is that on linux, I started tomcat with tomcat_user but I run jvisualvm with root user. It works after I start tomcat with root user.
I was having the problem having of visualvm detect my local tomcat installation on Windows 7. I could connect manually, but then things like memory snapshots and visualgc plugin were not enabled. I confirmed that I was using same JVM version, temp file permissions, etc. Didn't work. Then I found that starting visualvm first, and then tomcat, solved the problem.
As you can see, you are running VisualVM on 32bit JVM
You don't need to unistall 32bit JVM. Just tell VisualVM to use tour 64bit JVM.
If you want to change it permanently, you can edit
in visualvm_13\etc\visualvm.conf and specify the path of jvm here
My problem was JVM optimizations - -XX:+PerfDisableSharedMem flag will break VisualGC. This is apparent if jps will not show your app in the listing.
I can reproduce next behaviour.
I have a java application with right-click menu item to open jvisualvm.
I'm running this java application as standalone setup from a bat file.
It means I modify %path% and other needed environment variables like JDK
accordingly to form my environment.
The BAT that starts application is marked running as non-admin. Environment points to a 64-bit JDK.
Then I start other java application as admin. VM lives from the to same 64-bit JDK-source.
Then I start jvisualvm from first app with the right click ie.as non-admin.
I can see the app in jvisualvm ‘Applications list’ but clickin ‘System properties’ gives error. Message is “Not supported for this JVM”.
JVM arguments are exposed.
Solution is like in some other previous comments:
Starting my right-click jvisualvm-starter as admin I can see also "system properties" .
Certainly if JDKs would be 32-bit and other 64-bit it would not work. been there.
I thought this notion needs to be added here.
In my case, the application was running with admin permissions. So, visualVM also need to be running as admin.
I have changed name to my Windows User and set it all lowercase, restarted my PC and it all works now.
For me, the reason is that I have run the "jstatd" with a different user with the JVM process. I have a special user in the linux to start the JVM thread(it is a tomcat), but I start the jstatd process with root. If you use root to run jps, you cannot see any information of the JVM threads belonging to other users. That is the trouble.
I killed the "jstatd" process started by root, su to the owner of the JVM process, and restart the "jstatd" process and everything wokrs fine now.

Categories