Skip to content

Add JVM Tuning and Profiling documentation#98

Merged
janbodnar merged 2 commits intomasterfrom
copilot/create-jvm-tuning-documentation
Nov 30, 2025
Merged

Add JVM Tuning and Profiling documentation#98
janbodnar merged 2 commits intomasterfrom
copilot/create-jvm-tuning-documentation

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 30, 2025

Comprehensive technical documentation for JVM tuning and profiling, covering memory management, JVM flags, profiling tools, and performance optimization workflows.

Contents

  • JVM Memory Management Basics — Heap/stack/metaspace architecture with ASCII diagrams showing G1 region layout
  • JVM Flags Reference — Heap sizing (-Xmx, -Xms), GC selection (G1/ZGC/Shenandoah/Parallel), logging, heap dumps
  • Profiling Tools — JFR (including custom events), VisualVM, JDK Mission Control with comparison table
  • Tuning Workflow — Measure → Analyze → Tune → Verify cycle with sample JFR/VisualVM workflow
  • Best Practices & Pitfalls — Common mistakes (heap sizing, GC log misinterpretation, ignoring app-level issues)
  • Production Configurations — Ready-to-use examples for web apps, microservices, batch jobs

Example

// Custom JFR event for business metrics
@Name("com.example.OrderProcessed")
@Label("Order Processed")
@Category("Business Events")
class OrderProcessedEvent extends Event {
    @Label("Order ID")
    String orderId;
    
    @Label("Processing Time (ms)")
    long processingTimeMs;
}

void main() {
    var event = new OrderProcessedEvent();
    event.orderId = "ORD-123";
    long start = System.currentTimeMillis();
    // process order...
    event.processingTimeMs = System.currentTimeMillis() - start;
    event.commit();
}

Follows repository conventions: Java 25 compact source files, implicit imports, 80-char line limit.

Original prompt

On jvm-tuning.md, Create a detailed technical document explaining JVM Tuning and Profiling in Java, focusing on memory flags, advanced options, and profiling tools.
The document should include:

  1. Introduction

    • Define JVM tuning and profiling.
    • Explain why tuning is critical for performance and stability.
    • Highlight the role of profiling in diagnosing bottlenecks.
  2. JVM Memory Management Basics

    • Describe heap, stack, metaspace, and GC regions.
    • Explain how JVM allocates and manages memory.
    • Provide diagrams showing JVM memory layout.
  3. Tuning with JVM Flags

    • Heap Size Flags
      • -Xmx (maximum heap size).
      • -Xms (initial heap size).
      • Best practices for setting values.
    • Garbage Collection Flags
      • -XX:+UseG1GC, -XX:+UseZGC, -XX:+UseShenandoahGC.
      • Explain tuning options for pause times and throughput.
    • Other Useful Flags
      • -XX:MaxMetaspaceSize, -XX:+PrintGCDetails, -XX:+HeapDumpOnOutOfMemoryError.
      • Provide examples of usage.
  4. Profiling Tools

    • Java Flight Recorder (JFR)
      • Explain what JFR is and how it integrates with the JVM.
      • Show how to enable and analyze recordings.
    • VisualVM
      • Explain features: heap analysis, thread monitoring, GC visualization.
      • Provide examples of diagnosing memory leaks.
    • Mission Control
      • Explain integration with JFR.
      • Show how to analyze performance data and detect bottlenecks.
  5. Performance Tuning Workflow

    • Step-by-step guide:
      • Identify performance issues.
      • Collect profiling data.
      • Adjust JVM flags.
      • Validate improvements.
    • Provide a sample workflow with VisualVM and JFR.
  6. Best Practices

    • Avoid over-tuning; rely on defaults unless necessary.
    • Always test under realistic workloads.
    • Monitor GC logs and heap usage regularly.
    • Use profiling tools before changing flags.
  7. Common Pitfalls

    • Setting heap sizes too small or too large.
    • Misinterpreting GC logs.
    • Ignoring application-level bottlenecks.
    • Over-reliance on tuning without profiling.
  8. Examples

    • Show sample JVM configurations for:
      • Web applications.
      • Microservices.
      • High-throughput batch jobs.
    • Provide code snippets and flag combinations.
  9. Conclusion

    • Summarize the importance of JVM tuning and profiling.
    • Emphasize balancing performance, stability, and maintainability.

Formatting Requirements:

  • Use clear section headings.
  • Include code snippets for JVM flag usage.
  • Provide diagrams or tables comparing profiling tools and flags.
  • Write in a professional, educational tone suitable for intermediate to advanced Java developers.
  • Ensure the document is cohesive, well-organized, and easy to follow.

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: janbodnar <16985640+janbodnar@users.noreply.github.com>
Copilot AI changed the title [WIP] Create detailed technical document on JVM tuning and profiling Add JVM Tuning and Profiling documentation Nov 30, 2025
Copilot AI requested a review from janbodnar November 30, 2025 22:34
@janbodnar janbodnar marked this pull request as ready for review November 30, 2025 22:35
@janbodnar janbodnar merged commit 006edb9 into master Nov 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants