Skip to content
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Review Assignment Due Date

Lab: JVM Memory Analysis

Goal

Analyze JVM memory usage and configure garbage collection settings for optimal performance.

Learning Objectives

  • Understand JVM memory regions (Heap, Stack, Metaspace)
  • Enable and interpret GC logs
  • Compare different garbage collectors
  • Use JVM tuning flags

Pre-requisites

  • Java 17+ installed
  • Basic understanding of Java memory model

Tasks

Task 1: Create Memory-Intensive Application

Create a Java application that allocates memory progressively.

Starter Code Provided: MemoryLabApp.java

Task 2: Run with GC Logging

Run the application with the following JVM flags:

java -Xms128m -Xmx256m -Xlog:gc*:file=gc.log:time,uptime MemoryLabApp

Questions to Answer:

  1. How many Minor GCs occurred? - 6
  2. How many Major/Full GCs occurred? - 7
  3. What was the longest GC pause time? - 9.343ms

Task 3: Compare Garbage Collectors

Run the application with different GC algorithms:

# Serial GC
java -XX:+UseSerialGC -Xmx256m -Xlog:gc*:file=gc-serial.log MemoryLabApp

# G1GC
java -XX:+UseG1GC -Xmx256m -Xlog:gc*:file=gc-g1.log MemoryLabApp

# ZGC (Java 11+)
java -XX:+UseZGC -Xmx256m -Xlog:gc*:file=gc-zgc.log MemoryLabApp

Record your observations in a table:

GC Type Total GC Events Longest Pause Throughput
Serial 6 25.018 99.9%
G1GC 22 18.124 99.92%
ZGC 28 5.557 99.9%

Task 4: Tune for Low Latency

Configure G1GC to target a maximum pause time of 100ms:

java -XX:+UseG1GC -XX:MaxGCPauseMillis=100 -Xmx256m MemoryLabApp

Questions:

  1. Did G1GC achieve the target pause time? yes
  2. What trade-offs did you observe? It seemed to be more inconsistent

Deliverables

  1. Completed MemoryLabApp.java
  2. GC log files from each run
  3. Answers to all questions in a markdown file

Starter Code

See starter_code/MemoryLabApp.java

About

251027-2304-java-java-garbage-collection-2304-9-1 created by GitHub Classroom

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages