Skip to content
Search

Java Virtual Machine

lastmod 2025-03-07created 2016-04-0920 edits

The Java Virtual Machine (JVM) is the entity that can execute Java bytecode. It is usually implemented to run bytecode on another computer through an interpreter or JIT compilation, but it is sometimes implemented as a mix of hardware and software, as with Java processors. (In theory a 100% hardware implementation is possible, but it is inefficient.) Java bytecode is platform-independent, and every Java virtual machine executes Java bytecode as defined in the Java Virtual Machine Specification. Therefore, as long as the implementation behaves identically down to the standard Java API, every Java program is theoretically guaranteed to behave the same regardless of the type of CPU or operating system.

Categories

  • org.apache.catalina.core.JreMemoryLeakPreventionListener - checks for JRE memory leaks
  • Scavenger - open-source runtime dead code analysis tool
  • Java class file
  • CheerpJ - browser alternative to the JVM implemented in HTML5/WASM
  • Jacobin JVM - Java 17 JVM implementation written in Go with no dependencies
  • Mill - fast JVM build tool for Java and Scala
  • HotSpot

Options

JVM options and what they do

Option

Function

-Xms<size>

Sets the initial heap size. E.g. -Xms512m sets the initial heap size to 512MB.

-Xmx<size>

Sets the maximum heap size. E.g. -Xmx1024m sets the maximum heap size to 1024MB.

-XX:PermSize=<size>

Sets the initial size of PermGen (permanent generation) memory. Replaced by Metaspace as of Java 8.

-XX:MaxPermSize=<size>

Sets the maximum size of PermGen (permanent generation) memory. Replaced by Metaspace as of Java 8.

-XX:MetaspaceSize=<size>

Sets the initial size of Metaspace (Java 8 and later).

-XX:MaxMetaspaceSize=<size>

Sets the maximum size of Metaspace (Java 8 and later).

-Xss<size>

Sets the stack size of each thread. E.g. -Xss1m sets the stack size to 1MB.

-XX:+UseG1GC

Enables the G1 (Garbage-First) garbage collector.

-XX:+UseParallelGC

Enables the parallel garbage collector.

-XX:+UseConcMarkSweepGC

Enables the CMS (Concurrent Mark-Sweep) garbage collector.

-verbose:gc

Prints garbage collection logs.

-XX:+PrintGCDetails

Prints detailed garbage collection logs.

-XX:+HeapDumpOnOutOfMemoryError

Creates a heap dump when an OutOfMemoryError occurs.

-XX:HeapDumpPath=<file_path>

Specifies the path where the heap dump is saved.

-D<name>=<value>

Sets a system property. E.g. -Dfile.encoding=UTF-8 sets the file encoding to UTF-8.

JVM optimization

JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms1024m -Xmx1024m -XX:NewSize=512m -XX:MaxNewSize=512m -XX:PermSize=512m -XX:MaxPermSize=512m -XX:+DisableExplicitGC"

Monitoring

See also

Favorite site

Flags

Tip

Guide

References


  1. Back_to_the_Essence_-_Java_Compile_and_Run_01.pdf ↩

  2. Back_to_the_Essence_-_Java_Compile_and_Run_02.pdf ↩

author Zer0 sitemap