JVM Memory Managemnt and Garbage Collection Flashcards Preview

Software Developer Interview Prep > JVM Memory Managemnt and Garbage Collection > Flashcards

Flashcards in JVM Memory Managemnt and Garbage Collection Deck (118)
Loading flashcards...
1

What does it mean by generational collectors?

Most objects in an application are short lived. So to avoid scanning whole heap to clear objects it is better to divide heap in sections based on Generations. Young and Old.

2

Young Gen sections?

Eden space, where objects are first allocated. Survivor spaces, S0 and S1.

3

What is old gen also called?

Tenured area. Objects that have survived some number of GC cycles are probable to live long, so are tenured in old gen area.

4

What is GC that occurs in Young gen called?

Minor GC

5

What is GC that occurs in Old gen called?

Major GC or Stop the world GC.

6

Heap structure

Young Gen (Eden + Survivor spaces), Old Gen, Perm Gen (Method area)

7

When does Minor GC occur?

When Eden space gets full.

8

What does Minor GC do?

Collects garbage from Young gen. All objects that are referenced are moved to one of the survivor spaces. Minor GC also checks for survivor objects in survivor spaces and moves them to other survivor space. So at any given point in time, one survivor space is empty.

9

When are objects moved to Old gen?

When objects have survived many minor GC cycles, they are moved to old gen space. This is triggered either by threshold or age of objects.

10

When does Major GC occur?

When old gen is getting full. It is triggered using some ratio of old gen. Say trigger major GC if 60% gets full.

11

Which is faster Minor GC or Major GC?

Minor is faster.

12

What is keep area?

It contains most recently allocated objects and is not garbage collected until the next GC cycle. This is done to prevent objects from being promoted just because they were allocated just before young collection started.

13

What is metaspace?

In Java 8, there is no perm gen. Unlike Perm gen which is part of heap, Metaspace is not part of heap. Allocation for class metadata is done out of native memory. Metaspace grows in size while PermGen was fixed in size.

14

PermGen vs Metaspace?

- PermGen till Java 7 and Metaspace from Java 8.
- PermGen is fixed in size while Metaspace can grow
- PermGen is part of heap while Metaspace is not part of heap, it is allocated from native memory.

15

What is code cache?

Code cache is the area where JIT compiled native code is cached. This area is flushed if its size exceeds given threshold.

16

-Xms flag

Set the initial size of heap when JVM starts

17

-Xmx flag

Set the maximum size of heap

18

-Xmn flag

For setting size of Young gen, rest of the space goes to old gen

19

-XX:PermGen flag

Initial size of Perm Gen

20

-XX:MaxPermGen flag

Maximum size of Perm Gen

21

-XX:SurvivorRatio flag

Ratio of Eden space to survivor. Eg if 10m is size of young gen and survivor ratio is 2, then 5m is allocated to young and 2.5m for each survivor space. Default value is 8

22

-XX:NewRatio

Ratio of old/new gen size. Default value is 2

23

Which are the stages of garbage collection

- Marking phase
- Sweeping phase
- Compaction phase optional

24

What is mark phase?

Mark phase is process of finding which objects are reachable and are marked as live. Marking phase starts from GC roots such as Java threads, native handlers etc.

25

What is sweep phase?

In sweep phase, the heap is traversed to find gaps between live objects and gaps are recorded in freel list. That space is then available for new object allocation.

26

What is heap compaction?

It is similar to disk defragmentation. When there are small holes between objects, the performance of object allocation suffers. So during compaction all objects are moved together to create contiguous section of used and free memory.

27

What is Serial GC?

Uses simple mark-sweep-compact approach for young and old generation. Uses only single thread.

28

What is Parallel GC?

Uses N parallel threads to do Young gen collection and serially in Old generation. N is equal to number of CPU cores in system.

29

What is Parallel Old GC?

Same as Parallel new GC but it uses multiple threads for both young and old collection.

30

What is Concurrent Mark and Sweep collector>

It is referred to as concurrent low pause collector. CMS works on Old generation and algorithm for new generation is same as parallel collector. Suitable for responsive applications which cannot afford high pause times.