Java Reference
In-Depth Information
To avoid this, a simple GC like the one just shown will cause a stop-the-world
(STW) pause when it runs—because all application threads are stopped, then GC
occurs, and finally application threads are started up again. The runtime takes care
of this by halting application threads as they reach a safepoint —for example the start
of a loop or when about to call a method. At these execution points, the runtime
knows that it can stop an application thread without a problem.
These pauses sometimes worry developers, but for most mainstream usages, Java is
running on top of an operating system that is constantly swapping processes on and
off processor cores, so this slight additional stoppage is usually not a concern. In the
HotSpot case, a large amount of work has been done to optimize GC and to reduce
STW times, for those cases where it is important to an application's workload. We
will discuss some of those optimizations in the next section.
How the JVM Optimizes Garbage Collection
The weak generational hypothesis (WGH) is a great example of one of the runtime
facts about software that we introduced in Chapter 1 . Simply put, it is that objects
tend to have one of a small number of possible life expectancies (referred to as
generations ).
Usually objects are alive for a very short amount of time (sometimes called transient
objects), and then become eligible for garbage collection. However, some small frac‐
tion of objects live for longer, and are destined to become part of the longer-term
state of the program (sometimes referred to as the working set of the program). This
can be seen in Figure 6-2 where we see Volume of memory plotted against expected
lifetime.
y
y d
Figure 6-2. Weak generational hypothesis
 
Search WWH ::




Custom Search