INFO: Performance Issues with the Microsoft Virtual Machine (281201)



The information in this article applies to:

  • Microsoft virtual machine

This article was previously published under Q281201

SUMMARY

Important This article contains information about how to modify the registry. Make sure to back up the registry before you modify it. Make sure that you know how to restore the registry if a problem occurs. For more information about how to back up, restore, and modify the registry, click the following article number to view the article in the Microsoft Knowledge Base:

256986 Description of the Microsoft Windows registry

This article describes some of the issues that can affect the performance of Java-based programs that target the Microsoft virtual machine (Microsoft VM) for Java. However, the information is generic; apply the content based on the specific program in question and consider its design, memory usage, and other functional requirements.

MORE INFORMATION

The Microsoft VM Garbage Collection Operation

The garbage collection (GC) operation is an expensive operation, and a higher frequency can severely affect performance. Here are some of the ways that you can minimize the effect of the GC process and improve performance:
  • Microsoft VM build 3229 and later provide a registry key that you can use to specify the quantity of new memory that objects can consume before a GC is initiated.

    NOTE: To determine which version of Microsoft VM you are running, visit the following Microsoft Web site:
  • Warning Serious problems might occur if you modify the registry incorrectly by using Registry Editor or by using another method. These problems might require that you reinstall your operating system. Microsoft cannot guarantee that these problems can be solved. Modify the registry at your own risk.

    Microsoft VM uses a DWORD value, Generation0Size, to calculate how frequently to perform garbage collection. You can set a value for Generation0Size in the registry. If Generation0Size is not set in the registry, Generation0Size is dynamically calculated to one of the following values when Microsoft VM first starts:
    • The default value is 256 kilobytes (KB) on single processor computers (computers that have only one CPU).
    • The default value is 512 KB on multiprocessor computers that have less than 256 MB of RAM.
    • The default value is 1 megabyte (MB) on multiprocessor computers that have 256 MB or greater of RAM.

    The maximum value of this key is 0x400000 (4194304 in decimal, which is equivalent to 4 MB). If you increase the value of Generation0Size, you can reduce the number of GC operations to boost performance. You can reduce the value of Generation0Size to increase the frequency of calls to GC and reduce the memory footprint of your program.

    NOTE: The Generation0Size value may not be present in the registry. If it is not, use Registry Editor to add it. In Regedit, select the HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Java VM registry key, and add a new DWORD value named Generation0Size. Then set the value of Generation0Size to the amount that you want.
  • Make sure that there are no explicit System.gc calls that force GC. Although an explicit GC can free resources in a timely manner, overuse can severely affect performance. If you must use forced garbage collection in your programs, use com.ms.lang.SystemX.gc() instead of java.lang.System.gc() because the former does not try to collect class objects and is typically faster than the latter.
  • Because allocation and GC are expensive, it helps to create as few objects as possible or even create object caches for high use, short lived objects.

Use of Component Object Model (COM) Objects

Programs that use apartment-threaded COM objects should not hit serialization in the Microsoft VM. For additional information about serialization and the steps to create Java threads that can directly create and host COM objects, click the article number below to view the article in the Microsoft Knowledge Base:

232368 PRB: Java Threads Blocking when Accessing COM Objects

For more information, visit the following Microsoft Web site:

Memory Leaks

Verify that the program is not leaking objects. Generally, object leakage leads to performance degradation over time as the GC operations take more time to complete. The heapmon utility that is included with Microsoft SDK for Java, version 4.0 is a good tool to monitor the GC heap, track objects, and identify any potential object leaks. For more information about this utility, visit the following Microsoft Web site:

General

Code hotspots can exist in programs that affect performance, and that use third-party tools such as Rational's Visual Quantify or Intel's VTune. You can profile the programs to determine if there are any code hotspots. The third-party products that are discussed in this article are manufactured by companies that are independent of Microsoft. Microsoft makes no warranty, implied or otherwise, regarding the performance or reliability of these products.

REFERENCES

For support information about Visual J++ and the SDK for Java, visit the following Microsoft Web site:

Modification Type:MajorLast Reviewed:6/14/2006
Keywords:kbBug kbDebug kbFAQ kbGarbageCollect kbinfo kbJava KB281201