advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Java Profile Programs
Partners & Affiliates
advertisement
advertisement
advertisement
Average Rating: 4.3/5 | Rate this item | 3 users have rated this item.
Use a Profiler to Make Your Java Apps JVM-Friendly (cont'd)

Java Profile Examples

Using two Java programs, MyApp.java and MyAppComplex.java, I started 10 different threads and created dummy objects (click here to download the programs). MyApp.java creates objects within the method and explicitly nulls them after use, while MyAppComplex.java creates a number of class-level objects and does not null them. These programs demonstrate the activity within young and old generation JVM spaces and their effect on performance. Both programs have similar functionality, but MyApp takes less time as it is more JVM-friendly. I used the standard Java profilers jconsole and jstat to monitor the running application.
advertisement

When I ran MyApp.java, it actively used the young generation space (see Figure 2).

Click to enlarge 
Figure 2. Jstat Snapshot of MyApp.java

In the jconsole display in Figure 3, you can see that the old generation space is constant.

Click to enlarge 
Figure 3. Jconsole Snapshot of Old Generation Space for MyApp.java

However, the Eden space is quite active (see Figure 4).

Click to enlarge 
Figure 4. Jconsole Snapshot of Eden Space for MyApp.java

When I run MyAppComplex with a large number of objects hanging around, you can see that the old generation space keeps growing (see Figure 5).

Click to enlarge 
Figure 5. Jconsole Old Generation Space Snapshot of MyComplexApp.java

At the same time, the young generation space is extremely busy swapping objects from young generation space to old generation space. The young generation space gets filled up pretty quickly, so the JVM performs frequent minor collections (see Figure 6).

Click to enlarge 
Figure 6. Jconsole Eden Space Snapshot of MyAppComplex.java

Jstats shows that whenever the young generation space is emptied, the old generation space increases for MyAppComplex.java (see Figure 7).

Click to enlarge 
Figure 7. Jstat Snapshot of MyAppComplex.java

The old generation space keeps increasing until the JVM determines it has a major collection. When the JVM cannot reclaim any memory space—even after a major collection, then the application starts slowing down (see Figure 8).

Click to enlarge 
Figure 8. Jstat Snapshot of MyAppComplex.java

JDK 1.5 provides many command-line options to control the memory allocated to JVM spaces, such as –Xincgc, -Xloggc:<file>, -Xms<size>, -Xmx<size>, etc. The standard jstat and jconsole provide a lot of information about the internals of the running JVM. As noted in Figure 2, MyApp.java's old generation space memory usage is very little (16 to 20 percent). Though the default old generation space setting is 40 to 70 percent, keep it to less than 30 percent to prevent the JVM from interrupting your running application to do a major GC collection. The difference in running times between MyApp.java and MyAppComplex.java is the GC's interference of the running application.

Monitor the Performance of Your Java Application

Many profiler tools are available for monitoring the performance of your Java application (such as JProfiler and YourKitJavaProfiler), and they offer fine-grained control to the class and even method levels. This article demonstrated some internal details of JVMs with standard JDK tools.

With knowledge of JVM internals, Java developers can run their applications through the profilers and address all the bottlenecks before deploying them. This way, they can avoid OutOfMemory error failures and poor performance in production.

Previous Page: JVM Spaces  


Raghu Donepudi is a Lead Systems Developer for Global Computer Enterprises. He has a Masters degree in Computer Science from Lamar University in Texas. He is a Sun-certified Java developer and the author of many software design techniques.
Page 1: IntroductionPage 3: Java Profile Examples
Page 2: JVM Spaces 
Please rate this item (5=best)
 1  2  3  4  5
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Help  |   Site Map  |   Network Map  |   About


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers