Composition of The Young Generation: Usage Is 0 For Both Spaces, Then Take That As A Sign That Something
Composition of The Young Generation: Usage Is 0 For Both Spaces, Then Take That As A Sign That Something
object is suitable for the Eden space. If the said object seems right, it
will be placed in the Eden space, and the new object goes on top. So,
when new objects are created, only the lastly added object needs to
be checked, which allows much faster memory allocations. However,
it is a different story if we consider a multithreaded environment. To
save objects used by multiple threads in the Eden space for ThreadSafe, an inevitable lock will occur and the performance will drop due
to the lock-contention. TLABs is the solution to this problem in
HotSpot VM. This allows each thread to have a small portion of its
Eden space that corresponds to its own share. As each thread can
only access to their own TLAB, even the bump-the-pointer technique
will allow memory allocations without a lock.
This has been a quick overview of the GC in the young generation.
You do not necessarily have to remember the two techniques that I
have just mentioned. You will not go to jail for not knowing them. But
please remember that after the objects are first created in the Eden
space, and the long-surviving objects are moved to the old generation
through the Survivor space.
Serial GC (-XX:+UseSerialGC)
The GC in the young generation uses the type we explained in the
previous paragraph. The GC in the old generation uses an algorithm
called "mark-sweep-compact."
1. The first step of this algorithm is to mark the surviving objects
in the old generation.
2. Then, it checks the heap from the front and leaves only the
surviving ones behind (sweep).
3. In the last step, it fills up the heap from the front with the
objects so that the objects are piled up consecutively, and
divides the heap into two parts: one with objects and one
without objects (compact).
The serial GC is suitable for a small memory and a small number of
CPU cores.
Parallel GC (-XX:+UseParallelGC)