Skip to main content

Taming Tiger: Virtual machine updates

Changes designed to speed startup time and reduce memory requirements

John Zukowski (jaz@zukowski.net), President, JZ Ventures, Inc.
Author photo
John Zukowski conducts strategic Java consulting with JZ Ventures, Inc. and is working with SavaJe Technologies to develop a next-generation mobile phone platform. His latest books are Mastering Java 2, J2SE 1.4 (Sybex, April 2002) and Learn Java with JBuilder 6 (Apress, March 2002). Reach him at jaz@zukowski.net.

Summary:  In this installment of Taming Tiger, John Zukowski shows you how the latest Java™ virtual machine improves startup time, reduces memory requirements, and improves performance. With Tiger, you get a shared data archive, new thread scheduling algorithms, and a fatal error handler for those times when things don't go well.

View more content in this series

Date:  15 Mar 2005
Level:  Introductory
Activity:  1702 views
Comments:  

Each release of the Java platform includes changes designed to speed startup time and reduce memory requirements. It's an old song, but a necessity nonetheless, as each new release results in a larger, broader platform. The 5.0 release is no exception. This month, I'll explore these additions.

Fatal error handler

The JVM includes several new command-line options. One such nonstandard option is a fatal error handler. Starting the JVM with the -XX:OnError option lets you specify a command to execute once the error happens and the JVM stalls. Listing 1 shows several such options:


Listing 1. Some OnError handling options

  -XX:OnError="gcore %p; dbx - %p"
  -XX:OnError="gdb %p"
  -XX:OnError="pmap %p"

The command within quotation marks executes when a fatal error happens within the JVM. The %p option is replaced with the process ID. Deliberately causing an error isn't easy, but if you run across a repeatable situation that does happen, the information made available through the handler can prove to be extremely helpful.

The OnError option uses the Java Debug Interface (JDI) serviceability agent connector bridge. With it, you can attach to core files or stalled VMs, among other tasks. Several diagnostic tools, shown below, come with the JDK and take advantage of this bridge, though the last three are not available on Microsoft Windows platforms:

  • jps -- gets process ID
  • jstat -- gets statistics for process ID (jstat -gc pid)
  • jinfo -- gets JVM configuration information
  • jmap -- prints memory map of libraries
  • jstack pid | core -- generates a stack trace

Class data sharing

To help improve startup time, the JVM now works with memory-mapped files. Created at installation time, these files store an internal representation of the system classes. Then, when it is time to start the JVM, instead of loading the system classes from scratch, the memory-mapped files are loaded. This helps in two ways. First, roughly half of the memory-mapped files are read-only, which means they can be shared across multiple simultaneously running processes, reducing startup time considerably and total memory needed. Second, as the files are already in a format usable by the Java HotSpot VM, the memory used to process the original class files never happens, which improves startup time.

The location of the shared archive file is platform dependent. The file is named classes.jsa, where the JSA extension stands for Java Shared Archive. On a Microsoft Windows platform, you'll find the shared archive file in jre\bin\client. On a Linux platform, the location is jre/lib/[arch]/client. Both of these locations are based off the JAVA_HOME root.

If you don't like the file, delete it. In fact, you must delete it if you want to regenerate the file. Use the -Xshare:dump command-line switch with the java command for regeneration. When executed, you'll get output similar to Listing 2:


Listing 2. Regenerating shared data file command output

  Loading classes to share ... done.
  Rewriting and unlinking classes ... done.
  Calculating hash values for String objects .. done.
  Calculating fingerprints ... done.
  Removing unshareable information ... done.
  Moving most read-only objects to shared space at 0x2aad0000 ... done.
  Moving common symbols to shared space at 0x2ae2e848 ... done.
  Moving remaining symbols to shared space at 0x2af51148 ... done.
  Moving string char arrays to shared space at 0x2af51bd8 ... done.
  Moving additional symbols to shared space at 0x2afd2ef0 ... done.
  Read-only space ends at 0x2b027960, 5601632 bytes.
  Moving read-write objects to shared space at 0x2b2d0000 ... done.
  Moving String objects to shared space at 0x2b825be8 ... done.
  Read-write space ends at 0x2b8643a8, 5850024 bytes.
  Updating references to shared objects ... done.

If you don't like the concept of having a shared data file, don't use it. You can disable it with the -Xshare:off option. Then, all the original class information will be loaded from the rt.jar file.

To ensure shared data file usage is enabled, use the -Xshare:on option. Usage is not on by default. Instead the -Xshare:auto option is the default. The auto option means that the file should be used if possible. If it isn't possible (for instance, if you deleted it), then the option is ignored.

If you manually control the usage of the shared class data file, be aware that the command-line options are subject to change in a future release -- at least that's what the documentation says.

Sun claims startup times improve by roughly 30 percent when enabled.


Solaris thread priorities

The Java Thread class includes a setPriority() method to help assign a priority to the created thread. The key thing to know about the setPriority() method is that the setting can be ignored. Also, different platforms have different thread schedule models, resulting in different results.

With the 5.0 release, the thread priority implementation for the Solaris platform changed somewhat, reverting to an older behavior. As a result, the mapping from the 10 logical Java priorities (Thread.MIN_PRIORITY to Thread.MAX_PRIORITY) to native priorities is different:

  • Threads with a Java priority in the range of 5 to 10 are mapped high
  • Threads with a Java priority in the range of 1 to 4 are mapped low

It is that simple -- if you want to think of fewer priorities as simpler. The reasoning behind the change is to ensure Java threads are scheduled to run at the same priority as native threads and processes. But this means that Java priorities between 5 and 10 are not treated differently. (For more information on this change, see "Thread Priority on the Solaris™ Platform" in the Resources section.)

If you are on a Linux or Microsoft Windows platform, you can ignore this change. Still, be aware of the difference in case your users are on a Solaris platform.


Server class detection

By default, the JVM starts up with the client HotSpot virtual machine, unless a 64-bit chip is used, which defaults to the server VM. You can use the -server command-line option to force the enabling of the server HotSpot VM. If you are on a 32-bit Solaris SPARC or Linux/Solaris i586 system and don't specify the -client or -server options, the VM will automatically detect which version to use. Microsoft Windows defaults to client-side.

When automatic detection is in use, a machine is considered server-class if it has at least two CPUs and two gigabytes of physical memory. If you don't mind the slower startup time, without the newly available shared memory, the server VM will run more quickly over time.


Garbage collection

If you do happen to run the server VM, or at least are on a server-class machine, the default garbage collector has changed from the old serial version (-XX:+UseSerialGC) to the new parallel collector (-XX:+UseParallelGC). Other default settings related to heap size and time limits have also changed. (See "Garbage Collector Ergonomics" in the Resources section for additional information related to these settings.)


Summary

We finish this tip where we started. With each Java release, things change. The VM configuration has new and different options promising a faster startup and a smaller memory footprint. The 5.0 release of the J2SE platform follows this same pattern.


Resources

About the author

Author photo

John Zukowski conducts strategic Java consulting with JZ Ventures, Inc. and is working with SavaJe Technologies to develop a next-generation mobile phone platform. His latest books are Mastering Java 2, J2SE 1.4 (Sybex, April 2002) and Learn Java with JBuilder 6 (Apress, March 2002). Reach him at jaz@zukowski.net.

Comments



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Java technology
ArticleID=56432
ArticleTitle=Taming Tiger: Virtual machine updates
publish-date=03152005
author1-email=jaz@zukowski.net
author1-email-cc=jaloi@us.ibm.com

My developerWorks community

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Special offers