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
| Option | Function |
| -Xms<size> | Sets the initial heap size. E.g. |
| -Xmx<size> | Sets the maximum heap size. E.g. |
| -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. |
| -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. |
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"
- The JVM's default heap memory size is 64MB, so at least the
-server,-Xms, and-Xmxoptions should be set. - List of JVM options: http://blogs.sun.com/watt/resource/jvm-options-list.html
- Recommended: Blog2Book, "Coding Habits and Tuning Stories That Determine Java Performance".
Monitoring
See also
Favorite site
Flags
Tip
- [Recommended] Java memory management - garbage collection
- [Recommended] Back to the Essence - Java from compilation to execution - (1) 1
- [Recommended] Back to the Essence - Java from compilation to execution - (2) 2
- JIT performance tuning - Programmer Sought
Guide
References
- Akka
- Apache Ant
- Apache Maven
- Bazel
- C signal handling
- CheerpJ
- Chicory
- ContinuousIntegration:ImplementationGuide
- Gradle
- Groovy
- HotSpot (virtual machine)
- IntelliJ IDEA
- Jacobin JVM
- Java
- Java class file
- JNIEnv
- Just-in-time compilation
- Mill
- MiniVM
- OpenJDK
- Scala
- Scavenger
- Virtual Machine
- Virtualization
- VisualVM