JVM Tutorials - Herong's Tutorial Examples - v5.13, by Herong Yang
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 17, I got the following output:
herong> \Progra~1\Java\jdk-17.0.1\bin\java LongWhile Total memory: 67108864 Free memory: 50331648 Used memory: 16777216
As you can see from the output, the JVM reserved about 67 MB memory and used only about 16 MB.
When I looked at this JVM process on Windows Task Manager, I saw a 12% of CPU usage and a 16,777 KB 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 17 40196K 12% 67108864 50331648 16777216
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 17 40196K 12% 67108864 50331648 16777216 Server JVM 15 44412K 12% 67108864 47487896 19620968 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.
Table of Contents
JVM (Java Virtual Machine) Specification
►Java HotSpot VM - JVM by Oracle/Sun
Download and Install JDK on macOS
Download and Install JDK on Windows
Running Java HotSpot Client VM
Running Java HotSpot Server VM
►HotSpot Memory Usages on Windows Systems
java.lang.Runtime Class - The JVM Instance
java.lang.System Class - The Operating System
ClassLoader Class - Class Loaders
Class Class - Class Reflections
JVM Stack, Frame and Stack Overflow
Thread Testing Program and Result
CPU Impact of Multi-Thread Applications
I/O Impact of Multi-Thread Applications
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