Remote debugging runtime library in a JVM from a different vendor - java

Is there a good approach to remotely debug and step through JVM classes (think rt.jar) of the target JVM? For example if my main development environment is on Windows Oracle HotSpot JVM and I want to remotely debug the application running on the AIX IBM JVM? The bytecode/internal classes are different so the line numbers don't exactly match up to what my IDE is showing me.

IBM offers their SDK for Windows here - https://www.ibm.com/developerworks/java/jdk/java8/.

Related

How to enable Memory monitors in Eclipse (Java project)?

I am trying to inspect the memory contents (bytes) of an object in a Java project.
The program is paused in the Eclipse IDE.
How ever: the Memory view is disabled - as in: the Add Memory monitor + button is greyed out.
Why?
This question seems to be unanswered for quite a while and the one above sure doesn't help. This is the only post about it I could find.
In the Eclipse Help platform information about Memory view can be found in the C/C++ Development User Guide > Reference > Debug Views > Memory View but that isn't useful when were on Java. In the Java Development Guide it isn't as easy to find. Adding just Java Development Guide to the scope and searching for memory returns information about the Memory View in Running and Debugging but doesn't help very much. It is a view but isn't found in the same > Reference > Debug Views > as the C/C++ Guide.
When running a program in Debug mode in Eclipse C\C++ the + in the Memory view lights up and you can add addresses. However, running your program in Debug view doesn't seem to do the same in Eclipse Java. I'm assuming it can't be used in Java Eclipse or has a special case use that isn't mentioned.
Using JConsole
The JConsole graphical user interface is a monitoring tool that complies to the Java Management Extensions (JMX) specification. JConsole uses the extensive instrumentation of the Java Virtual Machine (Java VM) to provide information about the performance and resource consumption of applications running on the Java platform.
In the Java Platform, Standard Edition (Java SE platform) 6, JConsole has been updated to present the look and feel of the Windows and GNOME desktops (other platforms will present the standard Java graphical look and feel). The screen captures presented in this document were taken from an instance of the interface running on Windows XP.
Starting JConsole
The jconsole executable can be found in JDK_HOME/bin, where JDK_HOME is the directory in which the Java Development Kit (JDK) is installed. If this directory is in your system path, you can start JConsole by simply typing jconsole in a command (shell) prompt. Otherwise, you have to type the full path to the executable file.
Command Syntax
You can use JConsole to monitor both local applications, namely those running on the same system as JConsole, as well as remote applications, namely those running on other systems.
source : http://docs.oracle.com/javase/6/docs/technotes/guides/management/jconsole.html

Vagrant for a Java project: should you compile in the VM or on the host?

Here’s the question: When using Vagrant for a Java project (or any compiled language project for that matter), should you compile in the VM or on the host? Also, would you want your IDE and all your development tools to be run from inside the VM as well, or on the host?
It seems to be not very well defined exactly how a Java IDE and the compile/deploy process work with a Vagrant VM. Generally my impression is that code is edited on the host, and run on the VM, which works great for non-compiled languages. Other answers on Stackoverflow have implied that Vagrant is less useful for compiled languages because of the extra compile step, but I still want to see what can be done.
Some things I’ve thought through already:
Why compile on the VM
if compiling on host, java is one more piece of software to install
if compiling on host, the java version on host must be manually kept up to date with that on the VM
the corresponding java version on the host might be unavailable (say, on a Mac)
Why have IDE on the VM
tighter integration between environment and IDE, can use shortcuts to run the application
can connect debugger for java applications without remote debugging (one step run/debug)
Why compile on the host
faster compile times
want to keep the VM as close to what production looks like as possible
Why have IDE on the host
it’s the vagrant convention to edit code on the host and run it on the VM
better UI performance (X forwarding and VNC are slow)
What are your thoughts: should I run my IDE from inside the VM or the host? Should I compile from inside the VM or the host?
After much thought and experimentation, I've decided on where to use Vagrant and how it integrates with the Java development workflow.
For JavaEE / deployed applications, configuring a web server and a database server are definitely things that have "enough" complexity to warrant the use of Vagrant. With two servers and the myriad ways to configure them, it's easy for configuration to get out of sync from one developer to another, bringing about the "works on my machine" syndrome. For this kind of software, it would work best to edit and compile the code on the host, and deploy to a Vagrant VM that mimics your production environment. The deployment folder for the web server could even be symlinked to a compile target on the host, removing the need to manually redeploy. So Vagrant could be an important part of your development lifecycle, but the cycle time for code/compile/deploy from the host and run on the VM with Java would be longer than the cycle time for code on the host and run on the VM that we see with PHP/Ruby/Node/etc.
For standalone Java applications (like libraries or desktop applications) the story changes a bit. In this case it makes the most sense to edit, compile, and run on the host machine, eschewing the use of Vagrant altogether. If you're using one of the big Java IDE's (Eclipse, Netbeans, IntelliJ...), you already have Java installed on the machine. At that point there is very little advantage compared to the overhead of using Vagrant, and only serves to put an extra layer of complexity in your development process. This is because by the time you are able to edit Java with an IDE you are able to run everything on the host anyway. One issue is that the version of Java required for the project may not match the version running the IDE on the host. In general (hopefully) this is not too much of a problem; as of this writing JDK6 is end-of-lifed and JDK8 is not yet released (guess where that leaves us). But if you did need to run multiple versions, you should be able to set JAVA_HOME on the host as needed. Though this does introduce extra complexity, it is less complexity than maintaining a Vagrant runtime just to work with projects using different versions of Java.
The interesting question is what to do with containerless web applications. Should the web server (in this case internal to the application) be run inside the VM as we did for the external web server? Or run on the host as we did for the standalone application? For containerless web applications, there is no external web server to worry about, but there is still likely a database. In this situation we can take a hybrid approach. Running a containerless web app is essentially the same as running a standalone application, so it would be effective to compile and run your code on the host machine. But with a database involved there is still enough complexity and configuration there that it makes sense to have the database server be on its own Vagrant VM.
Hopefully this gives Java developers who are interested in Vagrant some context about how to use it.
I was interested to this topic during the last year :)
My solution is to have a vagrant machine configurable with flags.
For example one of this flag enable the desktop gui because some developer prefer to code on the host machine while others prefer to have a much more integrated environment with the desktop and the IDE in it.
To face the desktop slowness you should install a very useful vagrant plugin (yeah... vagrant has plugins that greatly improve the development environment) in this way: vagrant plugin install vagrant-vbguest
This plugin will install virtual box guest addition on every guest to make it usable while using the virtualbox interface.
Then to enable the gui edit the Vagrantfile in this way:
config.vm.provider "virtualbox" do |vb|
vb.gui = true
end
Instead to speed-up the shared folder performances I suggest to use rsync:
config.vm.synced_folder "./git", "/home/vagrant/git", type: "rsync", rsync__exclude: ".git/"
In this way the source code is edited on the host and then rsync-ed to the guest.

End to end profiling of web/J2EE and client applications

Is there a good tool to do end to end profiling of a system that uses J2EE and has clients?
I realize that you can easily profile the server and the client seperately. However, I do not know of any tools that'll give you information about the effect of the network connection between the two and how it affect's their performance. [An end-to-end profiler, would take in consideration of when the application is stuck on communicating and when it is processing]
I am not aware of any profiling agent that provides an out-of-the-box feature to profile applications end-to-end. At least, not at the time of writing this.
However, you could consider using DTrace to collect profiling information (not necessarily all the info provided by a typical profiler) from both the client and the server at the same time. An example on how to use this in a Java web-application (with Firefox as the client, and Tomcat as the server) is available in this article. The trick lies in having DTrace instrumentation built into the JVM (running the server) and the client, and in writing a DTrace script that writes the collected information from the traces into a parseable output. Since, the question isn't clear about whether the client is in Java I'll assume that the client is also in Java; if not, the application/executable must support DTrace instrumentation.
A few caveats are to be mentioned though:
DTrace is not available in all operating systems.
It is currently available in Solaris 10 and Mac OS Leopard.
I'm not aware of Dtrace support in Linux distributions, where SystemTap is the recommended alternative. FreeBSD has an experimental implementation of DTrace. It should be noted that SystemTap is not an implementation of DTrace for Linux, but a wholly different entity in itself.
On MSFT Windows, you're left to fend for yourself, atleast for the moment.
Assumptions about the JVM and the client (since I know that the server runs on a JVM)
If your client is a JVM then you must use a JVM that has DTrace instrumentation or equivalent (I'm referring to SystemTap here) built into it, or your DTrace/SystemTap scripts will not work. This means that unless the authors of the JRE/JDK for your distribution, have added code to support DTrace/SystemTap, you are constrained to use a JVM that has such a support built in. If it is of importance in your context, OpenJDK 1.6.0 appears have instrumentation support for SystemTap, and the Oracle/Sun Java 6 distributions for Solaris have support for DTrace. On Java 1.4 and 5 on Solaris, you'll need to install a JVMTI agent.
If your client is a web-browser or a thick-client written in a different language, then you must ensure that the process it is running under can support DTrace. For instance, DTrace instrumented Firefox is available on Solaris 10, and presumably on Solaris Express 11 (I have verified DTrace support only on OpenSolaris 2009.06). SystemTap probes haven't been added in Firefox for a lot of Linux distributions, so you'll often need to build Firefox from source, with the appropriate flags in the Firefox build script to add the probes; my previous experience with this process leads me to believe that this is doable, but isn't easy. If you are running a different application (neither Firefox, nor a JVM) as the client, then you'll need to verify DTrace/SystemTap support for it.
Writing good DTrace/SystemTap scripts to collect profiling information is not easy. You'll need to learn another language, and you'll need to ensure that the scripts do not add their own overhead (and validating the Heisenberg Uncertainty Principle in the context of profiling).
You can certainly write DTrace/SystemTap scripts that operate over remote clients and servers, but it is not advisable to write the collected instrumentation data to a socket (to avoid the afore-mentioned overhead).
Since version 8.0, JProfiler has the capability to follow RMI, web services and remote EJB calls between two profiled JVMs.
In the JVM that makes the call, call sites have hyperlinks that take you to the execution site in the remote JVM:
On the remote side, execution sites are recorded separately for each call sites, so you can inspect the call in isolation.
Disclaimer: My company develops JProfiler.

Profiling a jar file remotely?

Is there any profiler available in the java environment which can be used on a remote machine?
I have a .jar file (plain java code,nothing fancy) running on a remote machine and I want to profile that file. However,I can't install the profiler on the remote machine since I do not have the necessary permissions. Is there any way I can profile the application from my local machine?
Aall Java profilers I know have that ability, since the Java debugging interface (JVMTI) is inherently network-capable.
VisualVM has basic (but often sufficient) profiling features and comes with the JDK.

Eclipse TPTP or other java profiling solutions on OSX. Suggestions welcome

I'm attempting to profile junit tests in eclipse on OSX using TPTP. I installed the TPTP package from eclipse with no problem, I went to profile some code and it tells me:
Agent Controller is unavailable under port 10002.
Make sure that the service is started and the port number is correct
under preferences.
I searched around on the internets and discovered many complains about Agent Controller not being available for os X. Almost all of the java developers I know run eclipse under os x. Why would eclipse not support os x? Why even make the TPTP packages available for os x if os x can't run agent controller? Purely for remote debugging purposes?
Os X is built on BSD, Linux has an Agent Controller port. Has this been ported to os x?
Any ideas or success stories getting TPTP to work on os x (remote debugging on linux, agent controller replacements)?
What other options are there (Netbeans, VisualVM, JProfiler) and how good are they?
What does stackoverflow suggest I do?
Note: I am interested in profiling on class and method, of the number of times each method is called, and the amount of time the program spends in each method. Due to the complexity of the code using System.nanotime() statements are not an option.
According to the Eclipse TPTP FAQ
What platforms and environments does TPTP support?
The user interface components of the
TPTP Infrastructure can run on any
Eclipse-supported platform. The
various test execution, monitoring and
tracing components typically run on a
broad range of infrastructure and
interface with a broad range of
systems. One notable deficiency at
present is that the various trace
facilities are currently
Java-specific, although the project
has a goal to extend additional
language support in due course. For
the other agents there is a reasonable
coverage implemented or planned for
popular operating systems, application
servers, web servers etc, with a
particular focus on providing support
for other open source products.
Related Questions:
How can I see what parts of my code are running the most
Using java to get os level system information
if you have a java application that is consuming cpu when it isnt doing anything
Related Links:
Open Source Profilers for Java
As far as other Java profilers go, I think this is the best Stack Overflow question:
Please Recommend a Java Profiler
I personally would recommend YourKit Java Profiler, I've found it much more user-friendly than TPTP, and (while I haven't tested it) it should work on OS X.
Have you seen if the Netbeans profiler works under OS X? It is the original of which jvisualvm is a subset. It might just work...

Categories

Resources