Printing Runtime Basic Information

This section provides a tutorial example on how to access the Runtime instance of a running JVM and print some basic information.

To see how to access the Runtime instance of a running JVM and get some basic information, I wrote this simple Runtime test program,

 * Copyright (c) All Rights Reserved.
class RuntimeMemory {
   public static void main(String[] a) { out = System.out;

      // getting the Runtime instance of the JVM
      Runtime rt = Runtime.getRuntime();

      // obtaining basic information
      out.println("# of processors: " + rt.availableProcessors());
      out.println(" Maximum memory: " + rt.maxMemory());
      out.println("   Total memory: " + rt.totalMemory());
      out.println("    Free memory: " + rt.freeMemory());

If I run it with the JVM in JDK 14 on my macOS, I am getting the following output:

herong$ java
# of processors: 8
 Maximum memory: 4294967296
   Total memory: 270532608
    Free memory: 252471760

This tells me that:

As references, I collected outputs of running on different versions JVMs on different computers:

JVM/JDK   Year         # of                       Memory
Version          Processors      Maximum      Total        Free       Used
-------   ----   ----------   ----------   --------    --------   --------
 13       2020            8   4294967296  270532608   252471760   18060848
 10.0.1   2018            4   1006632960   62914560    60817408    2097152
  1.8.0   2016            4    259522560   16252928    15800200     452728
  1.7.0   2013            4    259522560   16252928    15964936     287992
  1.6.0   2007            2     66650112    5177344     4993136     184208

As you can see, the newer version of JVM always uses more memory than older versions.

Table of Contents

 About This Book

 JVM (Java Virtual Machine) Specification

 Java HotSpot VM - JVM by Oracle/Sun

java.lang.Runtime Class - The JVM Instance

 What Is Runtime?

Printing Runtime Basic Information

 Running the Garbage Collector Explicitly

 Shutting Down or Terminating the JVM Instance

 Executing System Commands

 Loading Native Libraries

 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

 OpenJ9 by Eclipse Foundation

 JRockit JVM 28.2.7 by Oracle Corporation

 Outdated Tutorials


 Full Version in PDF/EPUB