Title: Theory / Unimportant / CS / Programming / Java / JVM / Garbage collection

Name: Garbage collection
Definition: Allocates from and gives back memory to the operating system.
Page: https://docs.oracle.com/en/java/javase/16/gctuning/introduction-garbage-collection-tuning.html#GUID-326EB4CF-8C8C-4267-8355-21AB04F0D304
Chapter: 1
Definition2: Hands out that memory to the application as it requests it.
Conjdef: Part of the runtime that performs automatic dynamic memory management through the following operations:
Definition3: Determines which parts of that memory is still in use by the application.
Abbreviation: GC
Definition4: Reclaims the unused memory for reuse by the application.

Question: What heuristic does Java HotSpot garbage collectors uses?
Answer: Use generational scavenging in conjunction with aging to concentrate their efforts on areas in the heap that most likely contain a lot of reclaimable memory areas.
Page: https://docs.oracle.com/en/java/javase/16/gctuning/introduction-garbage-collection-tuning.html#GUID-326EB4CF-8C8C-4267-8355-21AB04F0D304
Chapter: 1
Answer2: Use multiple threads to aggressively make operations parallel, or perform some long-running operations in the background concurrent to the application.
Answer3: Try to recover larger contiguous free memory by compacting live objects.

Name: Amdahl's law
Definition: parallel speedup in a given problem is limited by the sequential portion of the problem
Page: https://docs.oracle.com/en/java/javase/16/gctuning/introduction-garbage-collection-tuning.html#GUID-326EB4CF-8C8C-4267-8355-21AB04F0D304
Chapter: 1

Question: What can influence the choice of garbage collector
Answer: Number of thread
Page: https://docs.oracle.com/en/java/javase/16/gctuning/introduction-garbage-collection-tuning.html#GUID-326EB4CF-8C8C-4267-8355-21AB04F0D304
Chapter: 1
Answer2: size of the heap

Name: Ergonomics
Definition: the process by which theJVM and GC heuristics, such as behavior-based heuristics, improve application performance.
Page: https://docs.oracle.com/en/java/javase/16/gctuning/ergonomics.html#GUID-DB4CAE94-2041-4A16-90EC-6AE3D91EC1F1
Chapter: 1
Context: JVM

Question: Initial heap size
Answer: 1/64 of physical memory
Page: https://docs.oracle.com/en/java/javase/16/gctuning/ergonomics.html#GUID-DB4CAE94-2041-4A16-90EC-6AE3D91EC1F1
Chapter: 1
Context: JVM

Question: Maximum heap size
Answer: 1/4 of physical memory
Page: https://docs.oracle.com/en/java/javase/16/gctuning/ergonomics.html#GUID-DB4CAE94-2041-4A16-90EC-6AE3D91EC1F1
Chapter: 1
Context: JVM

Question: The maximum number of GC threads is
Answer: limited by heap size and available CPU resources
Page: https://docs.oracle.com/en/java/javase/16/gctuning/ergonomics.html#GUID-DB4CAE94-2041-4A16-90EC-6AE3D91EC1F1
Chapter: 1
Context: JVM

Name: Pause time
Definition: the duration during which the garbage collector stops the application and recovers space that's no longer in use
Page: https://docs.oracle.com/en/java/javase/16/gctuning/ergonomics.html#GUID-DB4CAE94-2041-4A16-90EC-6AE3D91EC1F1
Chapter: 1
Context: JVM

Name: Maximum pause-time goal
Definition: Goal of limiting the longest of the pause time
Page: https://docs.oracle.com/en/java/javase/16/gctuning/ergonomics.html#GUID-DB4CAE94-2041-4A16-90EC-6AE3D91EC1F1
Chapter: 1
Context: JVM

Fla: -XX:MaxGCPauseMillis=<nnn>
Effect: Tell JVM to try to have pause of maximum nnn millisecond
Page: https://docs.oracle.com/en/java/javase/16/gctuning/ergonomics.html#GUID-DB4CAE94-2041-4A16-90EC-6AE3D91EC1F1
Chapter: 1
Context: JVM

Name: Throughput goal
Definition: Portion of the time spent collecting garbage
Page: https://docs.oracle.com/en/java/javase/16/gctuning/ergonomics.html#GUID-DB4CAE94-2041-4A16-90EC-6AE3D91EC1F1
Chapter: 1
Context: JVM

Fla: -XX:GCTimeRatio=nnn
Effect: The ratio of garbage collection time to application time is 1/ (1+nnn)
Page: https://docs.oracle.com/en/java/javase/16/gctuning/ergonomics.html#GUID-DB4CAE94-2041-4A16-90EC-6AE3D91EC1F1
Chapter: 1
Context: JVM

Name: Behavior-based tuning
Definition: Tuning that tries to optimize a goal up to some specified threshold, then move to a next goal, and so on
Page: https://docs.oracle.com/en/java/javase/16/gctuning/ergonomics.html#GUID-DB4CAE94-2041-4A16-90EC-6AE3D91EC1F1
Chapter: 1
Context: JVM

Question: How do GC prioritize tuning
Answer: The user decide whether they want to minimize throughput or maxum pause-time, and what value they want to attin
Page: https://docs.oracle.com/en/java/javase/16/gctuning/ergonomics.html#GUID-DB4CAE94-2041-4A16-90EC-6AE3D91EC1F1
Chapter: 1
Context: JVM
Answer2: once it's done, GC optimize for the second criteria
Answer3: If both criteria are met, then diminishing footprint until throughput goal fails

Fla: -Xms=<nnn>
Effect: Set minimum heap size for GC to nnn
Page: https://docs.oracle.com/en/java/javase/16/gctuning/ergonomics.html#GUID-DB4CAE94-2041-4A16-90EC-6AE3D91EC1F1
Chapter: 1
Context: JVM

Fla: -Xmx=<nnn>
Effect: Set minimal heap size for GC to nnn
Page: https://docs.oracle.com/en/java/javase/16/gctuning/ergonomics.html#GUID-DB4CAE94-2041-4A16-90EC-6AE3D91EC1F1
Chapter: 1
Context: JVM

Name: Garbage
Definition: An object that can no longer be reached from any reference to any other live object in the running program
Page: https://docs.oracle.com/en/java/javase/16/gctuning/ergonomics.html#GUID-DB4CAE94-2041-4A16-90EC-6AE3D91EC1F1
Chapter: 3
Context: JVM GC
Intuition: An object whose memory can be reused

Name: A live object
Definition: Either an object referenced by some stack of some thread, or an object referenced by a live object
Page: https://docs.oracle.com/en/java/javase/16/gctuning/ergonomics.html#GUID-DB4CAE94-2041-4A16-90EC-6AE3D91EC1F1
Chapter: 3
Context: JVM GC

Page: https://docs.oracle.com/en/java/javase/16/gctuning/ergonomics.html#GUID-DB4CAE94-2041-4A16-90EC-6AE3D91EC1F1
Implementation: The gc halt the program, runs through all live objects, following reference. Objects not marked as live are garbage and deleted. Then the run restart
Chapter: 3
Name: naive GC
Context: JVM GC

Name: Weak generational hypothesis
Definition: Heuristic that most objects survive for only a short period of time.
Page: https://docs.oracle.com/en/java/javase/16/gctuning/ergonomics.html#GUID-DB4CAE94-2041-4A16-90EC-6AE3D91EC1F1
Chapter: 3
Context: JVM GC

Name: Generational garbage collection
Definition: GC where the objects are allocated in pools depending on their age.
Page: https://docs.oracle.com/en/java/javase/16/gctuning/ergonomics.html#GUID-DB4CAE94-2041-4A16-90EC-6AE3D91EC1F1
Chapter: 3
Context: JVM GC
Intuition: GC more regularly tries to free new objects than old one

Name: Young generation
Definition: Generation of objects that are relatively new.
Page: https://docs.oracle.com/en/java/javase/16/gctuning/ergonomics.html#GUID-DB4CAE94-2041-4A16-90EC-6AE3D91EC1F1
Chapter: 3
Context: JVM GC

Name: Old generation
Definition: Generaton of objects that are not young
Page: https://docs.oracle.com/en/java/javase/16/gctuning/ergonomics.html#GUID-DB4CAE94-2041-4A16-90EC-6AE3D91EC1F1
Chapter: 3
Context: JVM GC

Name: Minor collection
Definition: Collection of objects restricted to the young generation. All of the objects remaining move to the old generation
Page: https://docs.oracle.com/en/java/javase/16/gctuning/ergonomics.html#GUID-DB4CAE94-2041-4A16-90EC-6AE3D91EC1F1
Chapter: 3
Context: JVM GC

Name: Major collection
Definition: GC over all objects, done when there are no place anymore
Page: https://docs.oracle.com/en/java/javase/16/gctuning/ergonomics.html#GUID-DB4CAE94-2041-4A16-90EC-6AE3D91EC1F1
Chapter: 3
Context: JVM GC
Intuition: Rarer than minor collection. Free more but more expansive

Name: Eden
Definition: Part of the young generation heap where objects are initially created
Page: https://docs.oracle.com/en/java/javase/16/gctuning/ergonomics.html#GUID-DB4CAE94-2041-4A16-90EC-6AE3D91EC1F1
Chapter: 3
Context: JVM GC

Name: Survivor space
Definition: Part of the young generation where object surviving garbage collection are moved to.
Page: https://docs.oracle.com/en/java/javase/16/gctuning/ergonomics.html#GUID-DB4CAE94-2041-4A16-90EC-6AE3D91EC1F1
Chapter: 3
Context: JVM GC

Question: When are objects moved from young to old generation
Answer: When the survivor space is full
Page: https://docs.oracle.com/en/java/javase/16/gctuning/ergonomics.html#GUID-DB4CAE94-2041-4A16-90EC-6AE3D91EC1F1
Chapter: 3
Context: JVM GC

Name: Latency
Definition: the responsiveness of an application.
Page: https://docs.oracle.com/en/java/javase/16/gctuning/ergonomics.html#GUID-DB4CAE94-2041-4A16-90EC-6AE3D91EC1F1
Chapter: 3
Context: JVM GC

Name: Promptness
Definition: the time between when an object becomes dead and when the memory becomes available
Page: https://docs.oracle.com/en/java/javase/16/gctuning/ergonomics.html#GUID-DB4CAE94-2041-4A16-90EC-6AE3D91EC1F1
Chapter: 3
Context: JVM GC

Question: most important factors affecting garbage collection performance
Answer: total available memory
Page: https://docs.oracle.com/en/java/javase/16/gctuning/factors-affecting-garbage-collection-performance.html#GUID-5508674B-F32D-4B02-9002-D0D8C7CDDC75
Chapter: 3
Context: JVM GC
Answer2: proportion of the heap dedicated to the young generation.

Question: How does the ratio of the heap reserved for young generation affect performance
Answer: A bigger young generation mean less minor collections and more major collections.
Page: https://docs.oracle.com/en/java/javase/16/gctuning/factors-affecting-garbage-collection-performance.html#GUID-5508674B-F32D-4B02-9002-D0D8C7CDDC75
Chapter: 3
Context: JVM GC

Question: The available collectors are
Answer: Serial collector
Page: https://docs.oracle.com/en/java/javase/16/gctuning/factors-affecting-garbage-collection-performance.html#GUID-5508674B-F32D-4B02-9002-D0D8C7CDDC75
Chapter: 3
Context: JVM GC
Answer2: Parallel collector
Answer3: Garbage-First (G1) Garbage collector
Answer4: The Z Garbage Collector

Name: Serial collector
Definition: GC which uses a single thread
Page: https://docs.oracle.com/en/java/javase/16/gctuning/factors-affecting-garbage-collection-performance.html#GUID-5508674B-F32D-4B02-9002-D0D8C7CDDC75
Chapter: 3
Context: JVM GC

Question: When is serial collector best suited
Answer: Single threaded processor
Page: https://docs.oracle.com/en/java/javase/16/gctuning/factors-affecting-garbage-collection-performance.html#GUID-5508674B-F32D-4B02-9002-D0D8C7CDDC75
Chapter: 3
Context: JVM GC
Answer2: applications with small data sets (up to approximately 100 MB)

Name: Parallel collector
Definition: Generational collector that uses multiple threads to be more efficient
Page: https://docs.oracle.com/en/java/javase/16/gctuning/factors-affecting-garbage-collection-performance.html#GUID-5508674B-F32D-4B02-9002-D0D8C7CDDC75
Chapter: 3
Context: JVM GC
Name2: throughput collector

Name: Garbage-First Garbage Collector
Definition: A GC that perform some expensive work concurrently to the application
Page: https://docs.oracle.com/en/java/javase/16/gctuning/factors-affecting-garbage-collection-performance.html#GUID-5508674B-F32D-4B02-9002-D0D8C7CDDC75
Chapter: 3
Context: JVM GC
Abbreviation: G1

Name: Z Garbage Collector
Definition: GC that performs all expensive work concurrently, without stopping the execution of application threads.
Page: https://docs.oracle.com/en/java/javase/16/gctuning/factors-affecting-garbage-collection-performance.html#GUID-5508674B-F32D-4B02-9002-D0D8C7CDDC75
Chapter: 3
Context: JVM GC
Abbreviation: ZGC
Intuition: Few milisecond of pause time, may worsen throughput