VM Memory Usages on Windows Systems

This section provides a tutorial example on how to check HotSpot VM memory usages on Windows systems using the Runtime class.

Let's use the following simple program to see the memory usages of the Java HotSpot VM:

/**
 * LongWhile.java
 * Copyright (c) 2010, HerongYang.com, All Rights Reserved.
 */
class LongWhile {
   public static void main(String[] a) {
      Runtime rt = Runtime.getRuntime();
      System.out.println(" Free memory: " + rt.freeMemory());
      System.out.println("Total memory: " + rt.totalMemory());
      while (true);
   }
}

The following notes were taken in 2013 on a Windows 7 system.

This program was compiled with JDK 7u45, and executed in two command windows: one with the Client VM, and the other with the Server VM. They both reported the same amount total memory and free memory in the run time environment, as shown in the table below:

C:\>\progra~1\java\jdk1.7.0_45\bin\java LongWhile
 Free memory: 15964856
Total memory: 16252928

C:\>\progra~1\java\jdk1.7.0_45\bin\java -server LongWhile
 Free memory: 54211088
Total memory: 54788096

As you can from the output, the Server VM starts with a much higher memory size. The footprint of the Server VM, 577,008 bytes, is also higher than the Client VM, 288,072 bytes.

While the two programs were running, I also used the Windows XP Task Manager to look at them from the operating system point of view. The Task Manager reported a 1332K more memory usage in the Server VM. See the table bellow for details:

            Task Manager   Run Time Environment
JVM         Memory CPU     Free     Total

Client VM   3976K  25%     15964856 16252928
Server VM   5312K  25%     54211088 54788096

The following notes were taken in 2007 on a Windows XP system.

This program was compiled with JDK 6u2, and executed in two command windows: one with the Client VM, and the other with the Server VM. They both reported the same amount total memory and free memory in the run time environment, as shown in the table below:

C:\>\progra~1\java\jdk1.6.0_02\bin\java LongWhile
 Free memory: 4997088
Total memory: 5177344

C:\>\progra~1\java\jdk1.6.0_02\bin\java -server LongWhile
 Free memory: 4997088
Total memory: 5177344

So the JVM itself used about 5177344 - 4997088 = 180256 bytes for both client and server versions. Comparing with notes taken on JDK 1.4.0, JDK 6 seems to have smaller footprint 252240 - 180256 = 71984 bytes.

While the two programs were running, I also used the Windows XP Task Manager to look at them from the operating system point of view. The Task Manager reported a 6K less memory usage in the Server VM. See the table bellow for details:

            Task Manager   Run Time Environment
JVM         Memory CPU     Free    Total

Client VM   6996K  50%     4997088 5177344
Server VM   6990K  50%     4997088 5177344

The following notes were taken in 2004 on a Windows 2000 system.

This program was compiled with j2sdk1.4.0_02, and executed in two command windows: one with the Client VM, and the other with the Server VM. They both reported the same amount total memory in the run time environment. But the Server VM gives 248 bytes less free memory.

While the two programs were running, I also used the Windows 2000 Task Manager to look at them from the operating system point of view. The Task Manager reported a 676K more memory usage in the Server VM. See the table bellow for details:

            Task Manager   Run Time Environment 
JVM         Memory CPU     Free    Total   Used

Client VM   4576K  50%     1779376 2031616 252240
Server VM   5252K  50%     1779128 2031616 252488

Last update: 2014.

Table of Contents

 About This Book

 Downloading and Installing JDK 1.8.0 on Windows

 Downloading and Installing JDK 1.7.0 on Windows

 java.lang.Runtime Class - The JVM Instance

 java.lang.System Class - The Operating System

 ClassLoader Class - Class Loaders

 Class Class - Class Reflections

Sun's JVM - Java HotSpot VM

 What Is HotSpot?

 Running Java HotSpot Client VM

 Running Java HotSpot Server VM

VM Memory Usages on Windows Systems

 JRockit JVM 28.2.7 by Oracle Corporation

 JVM Runtime Data Areas

 Memory Management and Garbage Collectors

 Garbage Collection Tests

 JVM Stack, Frame and Stack Overflow

 Thread Testing Program and Result

 CPU Impact of Multi-Thread Applications

 I/O Impact of Multi-Thread Applications

 CDS (Class Data Sharing)

 Micro Benchmark Runner and JVM Options

 Micro Benchmark Tests on "int" Operations

 Micro Benchmark Tests on "long" Operations

 Micro Benchmark Tests in JIT Compilation Mode

 Micro Benchmark Tests on "float" and "double" Operations

 Outdated Tutorials

 References

 PDF Printing Version