JVM Tutorials - Herong's Tutorial Examples - Version 4.20, by Dr. Herong Yang

JVM Tutorials - Herong's Tutorial Examples

http://www.herongyang.com/JVM

Copyright © 2014 by Dr. Herong Yang. All rights reserved.

HerongYang.com This free book is a collection of notes and sample codes written by the author while he was learning JVM himself. Topics include JVM (Java Virtual Machine), HotSpot, JRockit, GC (Garbage Collection), Memory, Stack overflow, CDS (Class Data Sharing), Runtime, Reflection.

Table of Contents

About This Book

Downloading and Installing JDK 1.8.0 on Windows

Downloading and Installing JDK 1.7.0 on Windows

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

What Is java.lang.System?

Standard Input, Output, and Error Streams

Current Time in Milliseconds and Nanoseconds

Accessing System Environment Variables

Getting and Adding System Properties

ClassLoader Class - Class Loaders

What Is Class Loader?

What Is java.lang.ClassLoader Class?

Accessing the ClassLoader of a Class

JVM "-verbose:class" Option

loadClass() Method - Loading Classes Explicitly

getSystemResource() Method - Finding Files

Class Loading Problem - JAR Hell

Class Class - Class Reflections

What Is java.lang.Class Class?

forName() Method - Loading Classes

Class Reflection and Introspection

Array Class Introspection

Invoking Methods of Class Instances

Sun's JVM - Java HotSpot VM

What Is HotSpot?

Running Java HotSpot Client VM

Running Java HotSpot Server VM

VM Memory Usages on Windows Systems

JRockit JVM 28.2.7 by Oracle Corporation

What Is JRockit JVM?

Downloading and Installing JRockit R28.2.7

Running Java Programs on JRockit R28.2.7

Memory Footprint of JRockit R28.2.7

What Is JRockit Mission Control?

Running JRockit Mission Control

What JRockit Management Console

JRockit Management Console on HotSpot JVM

JVM Runtime Data Areas

What Are Runtime Data Areas?

Method Area Expansion Demonstration

OutOfMemoryError on the Method Area

Method Area Growth with Dynamically Generated Classes

Garbage Collection Issue with Dynamically Generated Classes

Interned Strings Stored in Heap

Heap Expansion Demonstration

Direct Memory Expansion Demonstration

allocateMemory() Method on Direct Memory

JVM Stack Expansion Demonstration

PC Register and Native Method Stack

Memory Management and Garbage Collectors

Memory Management General Rules

Java Exception: "java.lang.OutOfMemoryError: Java heap space"

OutOfMemoryError Comparison of HotSpot and JRockit

Garbage Collection Demonstration

JVM Memory Manager - Garbage Collector

Generational Garbage Collection in HotSpot

Young Generation Collection - Minor Collection

Tenured Generation Collection - Full Collection

HotSpot Default Garbage Collector - Serial Collector

"-XX:+PrintGCDetails" - Garbage Collection Logging

GC Log Messages on GarbageCollection.java

Serial, Parallel, Concurrent, and Regionalized Collectors

Parallel Collector GC Log Message Format

Parallel Compacting Collector GC Log Message Format

Concurrent Mark-Sweep Collector GC Log Message Format

Garbage First GC Log Message Format

Garbage Collection Tests

GCTest2.java - Garbage Collection Test Program

640/400/40MB Test on HotSpot Client 1.7

640/400/40MB Test on HotSpot Client 1.6

640/400/40MB Test on JRockit 28.2

441/400/40MB Test on JRockit 28.2

1076/800/80MB Test on HotSpot Client 1.7

1076/800/80MB Test on HotSpot Client 1.6

1076/800/80MB Test on JRockit 28.2

JVM Stack, Frame and Stack Overflow

What Is JVM Stack?

StackOverflowError Exception Test

-Xss JVM Option for Stack Size

Frame Impact of Extra Statements

JVM Stack Expansion and Footprint

JVM Stack Expansion and OutOfMemoryError

Largest Stack Size for HotSpot on Windows

Default Stack Sizes of HotSpot and JRockit

JRockit Frame Size Smaller than HotSpot

JRockit Expanding Stacks in Bigger Chunks

JRockit Running Out Of Memory Quicker

Largest Stack Size for JRockit on Windows

Thread Testing Program and Result

CrashThread2.java - Thread Testing Program

Thread Test on HotSpot 1.7

Thread Test on JRockit 28.7

Thread Test on HotSpot 1.4 and JRockit 7.0

Thread Test on HotSpot 1.6

CPU Impact of Multi-Thread Applications

PrimeCalculator.java - CPU Intensive Process

CPU Intensive Process - 1 Thread per CPU

Single Thread Process on 2-CPU-4-Thread Machine

Two-Thread Process on 2-CPU-4-Thread Machine

Multi-Thread Process on 2-CPU-4-Thread Machine

Multi-Thread Process Slows Down System Response Time

Multi-Thread Process Running on JRockit JVM

I/O Impact of Multi-Thread Applications

FileEditor.java - I/O Intensive Process

FileEditor2.java - Avoiding FileNotFoundException

MultithreadingIoRunner.java - Multiple I/O Threads

Running Multiple I/O Threads on JRockit

CDS (Class Data Sharing)

What Is Class Data Sharing?

Regenerating Shared Archive

Startup Time Saving with Restoring Shared Archive

Startup Time Saving with Multiple JVM Processes

Footprint Saving with Restoring Shared Archive

Viewing Shared Memory of JVM Processes

Micro Benchmark Runner and JVM Options

What Is Micro Benchmark?

BenchmarkRunner.java - Benchmark Runner Program

emptyLoop() - The Empty Loop Test Method

"-XX:+PrintCompilation" - Watching JIT Compilation Logs

"-XX:+PrintGC" - Watching GC (Garbage Collection) Logs

"-Xms" and "-Xmx" - Avoiding GC with Large Memory Size

Benchmark Affected by Other Running Applications

"-Xint" - Running in Interpreted-Only Mode

Micro Benchmark Tests on "int" Operations

Revised BenchmarkRunner.java

Hardware, OS and JVM Configurations

"int" Empty Loop: 16 Nanoseconds per Step

"int" Assignment Only: 14 Nanoseconds per Step

"int" Shift and Assignment: 17 Nanoseconds per Step

"int" Add and Assignment: 17 Nanoseconds per Step

"int" Multiply and Assignment: 17 Nanoseconds per Step

"int" Division and Assignment: 19 Nanoseconds per Step

Micro Benchmark Tests on "long" Operations

"long" Empty Loop: 25 Nanoseconds per Step

"long" Assignment Only: 24 Nanoseconds per Step

"long" Shift and Assignment: 30 Nanoseconds per Step

"long" Add and Assignment: 34 Nanoseconds per Step

"long" Multiply and Assignment: 38 Nanoseconds per Step

"long" Division and Assignment: 53 Nanoseconds per Step

Performance Comparisons between "int" and "long"

Micro Benchmark Tests in JIT Compilation Mode

"int" Loops with JIT Compilation

"long" Loops with JIT Compilation

Performance Improvements of JIT Compilation

Micro Benchmark Tests on "float" and "double" Operations

Benchmark Test Methods for "float" Operation

"float" Operations without JIT Compilation

"float" Operations with JIT Compilation

Benchmark Test Methods for "double" Operation

"double" Operations without JIT Compilation

"double" Operations with JIT Compilation

Performance Improvements of JIT Compilation

Outdated Tutorials

Outdated: Download and Install Java SE 1.6 Update 2

Outdated: Installing JRockit JVM 8.0

Outdated: Testing with LongWhile.java

Outdated: Testing with LongSleep.java

Outdated: GCTest.java - Garbage Collection Test Program

Outdated: GC Test - Constant Memory Requirement

Outdated: GC Test - Periodical Memory Requirement

Outdated: GC Test - Releasing Old vs. New Objects

Outdated: GC Test - JDK 1.4.0 vs. JDK 1.3.1

Outdated: GC Test - Client vs. Server

Outdated: StringBuffer Testing Program

Outdated: Installing JRockit JVM 7.0

Outdated: Running JRockit JVM with Management Console

References

PDF Printing Version

Keywords: JVM, Java, Virtual, Machine

Table of Contents - Updated in 2014, by Dr. Herong Yang