Java* Code Analysis
Configuring Java Data Collection
- Embed yourjavacommand in a batch file or executable script.For example, create arun.batfile on Windows* orrun.shfile on Linux* with the following command:Windows:> java.exe -Xcomp -Djava.library.path=native_lib\ia32 -cp C:\Design\Java\mixed_stacks MixedStacksTest 3 2Linux:$ java -Xcomp -Djava.library.path=native_lib/ia32 -cp /home/Design/Java/mixed_stacks MixedStacksTest 3 2
- In theConfigure Analysiswindow >WHEREpane, specify your analysis system, for example,Local Host.
- In theWHATpane, choose theApplication to Launchtarget type.
- In theApplicationfield, specify a path to thisrunfile . For example, on Linux:
$ vtune -collect hotspots -- run.sh
$ vtune -collect hotspots -- java -Xcomp -Djava.library.path=native_lib/ia32 -cp home/Design/Java/mixed_stacks MixedStacksTest 3 2
$ vtune -collect hotspots -target-process java
$ vtune -collect hotspots -target-pid 1234
Identifying Hottest Methods
Analyzing Stacks for Mixed Code
Mixed native/Java call stack
Compiled methods in the Java call stack
Analyzing Hardware Metrics
- System-wide profiling is not supported for managed code.
- The JVM interprets some rarely called methods instead of compiling them for the sake of performance.VTunedoes not recognize interpreted Java methods and marks such calls asProfiler!Interpreterin the restored call stack.If you want such functions to be displayed in stacks with their names, force the JVM to compile them by using the-Xcompoption (show up as[Compiled Java code]methods in the results). However, the timing characteristics may change noticeably if many small or rarely used functions are being called during execution.
- When opening source code for a hotspot, theVTunemay attribute events or time statistics to an incorrect piece of the code. It happens due to JDK Java VM specifics. For a loop, the performance metric may slip upward. Often the information is attributed to the first line of the hot method's source code. In the example below, a real hotspot line consuming most CPU time is line 35.Profiler
- Consider events and time mapping to the source code lines as approximate.
- For the Hotspots analysis type in theuser-mode samplingmode, theVTunemay display only a part of the call stack. To view the complete stack on Windows, use theProfiler-Xcompadditional command line JDK Java VM option that enables the JIT compilation for better quality of stack walking.To view the complete stack on Linux, use additional command line JDK Java VM options that change behavior of the Java VM:
- Use the-Xcompadditional command line JDK Java VM option that enables the JIT compilation for better quality of stack walking.
- On Linux* x86, use client JDK Java VM instead of the server Java VM: either explicitly specify-client, or simply do not specify-serverJDK Java VM command line option.
- On Linux x64, specify-XX:-UseLoopCountercommand line option that switches off on-the-fly substitution of the interpreted method with the compiled version.
- Java application profiling is supported for the Hotspots and Microarchitecture analysis types. Support for the Threading analysis is limited as some embedded Java synchronization primitives (which do not call operating system synchronization objects) cannot be recognized by theVTune. As a result, some of the timing metrics may be distorted.Profiler
- There are no dedicated libraries supplying a user API for collection control in the Java source code. However, you may want to try applying the native API by wrapping the__ittcalls with JNI calls.