Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding the Java Memory Model and Garbage Collection [closed]

Tags:

java

tags

I tend to get these questions asked by a lot by students, or by co-workers looking for a resource, so I wanted a more definite reference for them. Might as well share it with the community.

  • How is the Java Memory Model represented and what are its characteristics?

  • How does Garbage Collection work in general and in the most common JVMs?

  • How do I test and tune my Java applications for performance?

like image 357
haylem Avatar asked Jun 09 '13 13:06

haylem


People also ask

What do you understand by Java memory model?

The Java memory model describes how threads in the Java programming language interact through memory. Together with the description of single-threaded execution of code, the memory model provides the semantics of the Java programming language.

How is memory allocation and garbage collection managed in Java?

In Java, memory management is the process of allocation and de-allocation of objects, called Memory management. Java does memory management automatically. Java uses an automatic memory management system called a garbage collector. Thus, we are not required to implement memory management logic in our application.

What is the JVM memory model and how does it work?

Java Memory Structure: JVM defines various run time data area which are used during execution of a program. Some of the areas are created by the JVM whereas some are created by the threads that are used in a program. However, the memory area created by JVM is destroyed only when the JVM exits.

How does JVM garbage collection work?

As long as an object is being referenced, the JVM considers it alive. Once an object is no longer referenced and therefore is not reachable by the application code, the garbage collector removes it and reclaims the unused memory.


1 Answers

Memory Basics

  • What Every Programmer Should Know About Memory - Ulrich Drepper [PDF]

Java Language and Virtual Machine Specifications

  • The Java Virtual Machine Specification [PDF and HTML for Java SE 7]

Java Memory Model

  • Advanced Topics in Programming: The Java Memory Model - Jeremy Manson [video]
  • Collection of Resources on the Java Memory Model - edited and compiled by Bill Pugh (collection)
  • Memory Management in the HotSpot Virtual Machine - Sun Microsystems (2006) [PDF]
  • Fixing the Java Memory Model - Brian Goetz, IBM Java Developer Series () [part 1, part 2]

Java Performance

  • 9 Fallacies of Java Performance - Ben Evans [video + slides]
  • JVM Performance Magic Tricks - Takipi [blog + slides]
  • Java and the Machine - Kirk Pepperdine, Martijn Verburg [video + slides]
  • Performance Testing Java Applications - Martin Thompson [video + slides]
  • Building Memory-Efficient Java Applications: Practices and Challenges - Mitchell, Sevitsky (2009) [PDF]

Advanced Topics and Real-Life Uses Cases

  • Optimizing Google’s Warehouse Scale Computers: The NUMA Experience - University of California & Google [PDF]
  • MegaPipe: A New Programming Interface for Scalable Network I/O [Google Doc]
  • Mythbusting modern hardware to gain "Mechanical Sympathy" - Martin Thompson [PDF] (slides)
  • Caching in: understand, measure and use your CPU Cache more effectively - Richard Warburton [video + slides]
  • A JVM Does That?! - Cliff Click [video]

GC Tuning

  • Hotspot Garbage Collection - Tuning Guide - Martijn Verburg, John Oliver [video, slides pt 1, slides pt 2]
  • Are your GC logs speaking to you, the G1GC edition [slides, video]
  • The Principles of Java Application Performance Tuning [article]
  • Everything I Ever Learned About JVM Performance Tuning @Twitter - Attila Szegedi [video & slides]
  • Visualizing Java GC - Ben Evans [video + slides]

Complementary StackExchange Questions and Answers

  • Java Memory Model
  • JRockit JVM versus HotSpot JVM
  • How to destroy java objects?
  • Smart Garbage Collection?

And many, many more to come that I need to dig up from my archives or from the inter-tubes.

like image 146
haylem Avatar answered Sep 25 '22 19:09

haylem