KK List of Java 5
KK List of Java 5
KK List of Java 5
Often the size of the JDBC statement pool is set to the default
value. Using the default value, of course does not usually lead
to any special issue. But a well-configured maxStatements value
can be as effective as GC tuning. If you are using the
default maxStatements value and would like to optimize the use
of memory, let's think about the correct statement pool value
before attempting GC tuning.
There are 3 spaces in total, two of which are Survivor spaces. The
order of execution process of each space is as below:
1. The majority of newly created objects are located in the Eden
space.
2. After one GC in the Eden space, the surviving objects are moved
to one of the Survivor spaces.
3. After a GC in the Eden space, the objects are piled up into the
Survivor space, where other surviving objects already exist.
4. Once a Survivor space is full, surviving objects are moved to the
other Survivor space. Then, the Survivor space that is full will be
changed to a state where there is no data at all.
5. The objects that survived these steps that have been repeated
a number of times are moved to the old generation.
As you can see by checking these steps, one of the Survivor spaces
must remain empty. If data exists in both Survivor spaces, or the
usage is 0 for both spaces, then take that as a sign that something
is wrong with your system.
The process of data piling up into the old generation through minor
GCs can be shown as in the below chart:
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)