HotSpot Memory Usages on Windows Systems

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

To see the memory usage of the Java HotSpot VM, I wrote the following simple program to print out memory usage information:

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

When running LongWhile.java with HotSpot in 64-bit JDK 10, I got the following output:

C:\herong>\Progra~1\Java\jdk-10.0.1\bin\java LongWhile
Total memory: 62914560
 Free memory: 60982832
 Used memory: 1931728

As you can from the output, the JVM reserved about 62 MB memory and used only about 2 MB.

When I looked at this JVM process on Windows Task Manager, I saw a 25% of CPU usage and a 17,656K of memory usage. Comparing this with the output of LongWhile.java, I saw that Windows Task Manager is not reporting the total memory reserved by the JVM.

      JDK        Task Manager           JVM Runtime 
    HotSpot       Memory  CPU      Total      Free     Used
--------------   ------------   ---------------------------      
Server JVM 10     17656K  25%   62914560  60982832  1931728

It seems

As a reference, the table below lists outputs of the same tests on HotSpot Client and Server VMs of previous versions:

      JDK        Task Manager           JVM Runtime 
    HotSpot       Memory  CPU      Total      Free     Used
--------------   ------------   ---------------------------      
Server JVM 10     17656K  25%   62914560  60982832  1931728

Client JVM 1.7     3976K  25%   16252928  15964856   288072
Server JVM 1.7     5312K  25%   54788096  54211088   577008
                                                    
Client JVM 1.6     6996K  50%    5177344   4997088   180256
Server JVM 1.6     6990K  50%    5177344   4997088   180256
                                                    
Client JVM 1.4     4576K  50%    2031616   1779376   252240
Server JVM 1.4     5252K  50%    2031616   1779128   252488

As you can see, newer version of HotSpot JVM requires more memory to run.

Last update: 2018.

Table of Contents

 About This Book

 JVM (Java Virtual Machine) Specification

Java HotSpot VM - JVM by Oracle/Sun

 What Is HotSpot JVM

 Download and Install Latest JDK on Windows

 Running Java HotSpot Client VM

 Running Java HotSpot Server VM

HotSpot Memory Usages on Windows Systems

 Download and Install JDK 1.8.0 on Windows

 Download and Install 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

 JVM Runtime Data Areas

 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

 JRockit JVM 28.2.7 by Oracle Corporation

 Outdated Tutorials

 References

 Full Version in PDF/EPUB