Download presentation
Presentation is loading. Please wait.
Published byYanti Darmali Modified over 6 years ago
2
CMS to G1 - Java GC Vaibhav Choudhary (@vaibhav_c) Java Platforms Team
This is a Title Slide with Java Graphic Theme ideal for including a brief title, subtitle and presenter information. Do not customize this slide with your own picture. To reuse this branded background in another presentation on PC Locate and open the presentation where you will be placing this artwork. Click New Slide from the Home tab's Slides group and select Reuse Slides. Click Browse in the Reuse Slides panel and select Browse Files. Double-click the PowerPoint presentation that contains the background you wish to copy. Check Keep Source Formatting and click the slide that contains the background you want. Click the left-hand slide preview to which you wish to apply the new master layout. Apply New Layout (Important): Right-click any selected slide, point to Layout, and click the slide containing the desired layout from the layout gallery. Delete any unwanted slides or duplicates. To reuse this branded background in another presentation on Mac Locate and open the presentation where you will be placing this artwork. Click New Slide from the Home tab's Slides group and select Insert Slides from Other Presentation… Navigate to the PowerPoint presentation file that contains the background you wish to copy. Double-click or press Insert. This prompts the Slide Finder dialogue box. Make sure Keep design of original slides is unchecked and click the slide(s) that contains the background you want. Hold Shift key to select multiple slides. Apply New Layout (Important): Click Layout from the Home tab's Slides group, and click the slide containing the desired layout from the layout gallery.
3
This is a Safe Harbor Front slide, one of two Safe Harbor Statement slides included in this template. One of the Safe Harbor slides must be used if your presentation covers material affected by Oracle’s Revenue Recognition Policy To learn more about this policy, For internal communication, Safe Harbor Statements are not required. However, there is an applicable disclaimer (Exhibit E) that should be used, found in the Oracle Revenue Recognition Policy for Future Product Communications. Copy and paste this link into a web browser, to find out more information. For all external communications such as press release, roadmaps, PowerPoint presentations, Safe Harbor Statements are required. You can refer to the link mentioned above to find out additional information/disclaimers required depending on your audience.
4
Agenda of the day … Basics of Garbage Collector
1 Basics of Garbage Collector Concurrent Mark and Sweep (CMS) CMS implementation and challenges Garbage First (G1) G1 implementation and comparison to CMS 2 3 4 5
5
Definition Mark Sweep Copy Compaction
find and mark all accessible objects Sweep scans through the heap and reclaims all the unmarked objects Copy copies all live objects from one part of the heap to another empty part Compaction moving all the live objects into contiguous memory locations
6
Java Heap Structure Minor GC Major GC Eden Generation S0 S1
Old Generation Meta Space new Object() After minor GC After threshold limit (n) Weak Generational Hypothesis : - Most of the object die young. - There are very few old to young reference.
7
CMS Simplified (In Young generation)…
Eden S0 S1 Eden S0 S1 Eden S0 S1 Old generation Old generation Old generation When eden space will be full. Minor GC will be triggered. Usages of S0 and S1.
8
CMS Simplified (In Young generation)…
Eden S0 S1 Eden S0 S1 Eden S0 S1 S1 Old generation Old generation Old generation Empty Eden and one of the Survivors after Minor GC completion. Stop the world process. Some objects can be promoted to Old generation.
9
CMS Simplified (In Old generation)…
May be the first snapshot of Old generation Old generation will mostly look like this No compaction in CMS Mostly concurrent
10
CMS Simplified (In Old generation)…
CMS phases :- Initial marking phase. Concurrent Marking phase. Concurrent Pre-cleaning Phase. Remarking phase. Concurrent Sweep Phase. Concurrent Reset Phase. STW STW
11
CMS Simplified (In Old generation)…
Initial Marking Phase :- Scan the object directly reachable from root or from Eden Generation. 2. All the mutator thread need to be stopped (STW). 3. STW - We don’t want to mess up with this information. 4. Generally small pause in nature. G C R O T Eden Generation
12
CMS Simplified (In Old generation)…
Concurrent Marking Phase :- Scan almost all live objects from the object marked from phase 1. 2. This will be done in concurrent fashion. 3. And this will lead to a remarking phase. 4. It will take time but it’s concurrent. Eden Generation
13
CMS Simplified (In Old generation)…
Remarking Phase :- Scan the newly created objects. 2. We need to do STW. 3. Generally, small pause in nature. Eden Generation We end up creating new Objects, because last phase is concurrent in nature.
14
CMS Simplified (In Old generation)…
Remarking Phase :- Scan the newly created objects. 2. We need to do STW. 3. Generally, small pause in nature. Eden Generation We end up creating new Objects, because last phase is concurrent in nature.
15
CMS Simplified (In Old generation)…
Concurrent Sweep Phase :- Start sweeping all the non-marked Object. 2. Concurrent in nature. 3. Red boxes can be claimed by GC. Eden Generation We end up creating new Objects, because last phase is concurrent in nature.
16
Final thoughts for CMS It’s almost concurrent other than some small STW’s. Memory Fragmentation - so can’t fit large object. Less predictable. Can Lead to promotion failure - Young to old promotion is not happening because object is too big or old space is almost full. Can Lead to Concurrent mode failure - Old generation not finished the collection work and Old generation is full. STW and then run a different GC algorithm, probably Mark-Sweep-Compact. If application is working fine with CMS, let it work !
17
Welcome to Garbage First (G1)
Default GC algorithm for JDK9. G1 Goals Low latency Predictable (Can’t be 100 percent) Easy to use (Less parameter settings) Concurrent, Parallel and better Compacting. If you are not on JDK9, use -XX:+UseG1GC. Careful with your greedy throughput desires.
18
Garbage First (G1) - Memory layout
Memory is divided into small regions More than 2000 regions More flexible boundaries Use -XX:+G1HeapRegionSize Different regions : Young Survivor Old Humongous Y S O H H H O Y O Y O O
19
G1 - Young region View O1 O4 None of the object is reachable from GC root in first block. Looks like the complete region can be collected. (No you can’t) O2 O3 GC Root O1 GC root is pointing to some object. Can’t collect this region. O2 O3
20
G1 - Young region View O1 O4 O1 O4 We have reference from Old region
to this block. Can’t be collected. O2 O3 O2 O3 GC Root Remembered Set (Remembers the references from old region) O1 O2 O3
21
G1 RS and Dirty Card Table Concept
APPLICATION TO UPDATE RSET A card table is a type of remembered set. Hotspot uses byte array as a Card Table. Each byte is referred as a Card which corresponds to range of address in Heap. Dirtying a card means changing the value of byte. Processing a card means seeing a old to young pointer. -XX:+ConcRefinementThread MANY CRT ONE CRT NO CRT
22
G1 - Ease to use java -Xmx50m -XX:+UseG1GC -XX:+MaxGCPauseMillis=200 - jar Java2DDemo.jar MaxGCPauseMillis=200 - A soft goal. G1 will try to respect as much as possible, but can’t guarantee you. Important to know -XX:+InitiatingHeapOccupancyPercentage=45
23
G1 - Young GC Phases Stop the world event.
Builds collection Set (cSet) for the regions which are subject of collection. In Young GC, cSet will contain :- Eden Region Survivor Region
24
G1 - Young GC Phases Phase 1 Phase 2 Phase 3 G1 [Young] Root Scanning
Find out the GC Roots like old time. Phase 2 G1 [Young] Update RSet Update RSet from dirty card queue. Phase 3 G1 [Young] Process RSet Detects old to young generation pointers.
25
G1 - Young GC Phases Phase 4 Phase 5 G1 [Young] Object copying
Traverse object graph Copy to either New Eden Region or Survivor Region Phase 5 G1 [Young] Reference Processing Finding the type of reference while copying (Phase-4)
26
G1 - Young GC Phases Dynamically setting up no. of Eden/Survivor Region MaxPauseMillis - Can increase or decrease the no. of region to respect the pause time. After fulfilling the latency goals, it will try to fulfil the throughput goal. So, if possible, don’t set Xmn Shrinking/Expansion can happen from percent.
27
G1 - Young GC View O Y O Y S O Y Y S O H H H O Y O Y O O
28
G1 - Young GC View O O O Y Y S O H H H O O O O O
29
G1 - Old GC Phases Kicks out when the heap occupancy is 45%.
-XX:+InitialHeapOccupancyPercentage=<n> (Can be changed) G1 uses Concurrent Marking in Old region Uses STAB [Snapshot at the beginning] Tri-color Marking Floating Garbage
30
Tri-color Marking GC Root
31
Concurrency Problem - Floating Garbage
GC Root X This is a sample Title and Code Layout slide, ideal for displaying codes. To take advantage of the pre-formatted paragraph style: Start typing the code, using the tab key (not space key) to increase and Shift+tab keys to decrease indention levels for each paragraphs. Ignore the bullets at this point. If copy and paste the text from other sources, make sure the text is reset to the defaulted size and formatting by clicking Reset, within the Slides Group. (Or select Reset Layout to Default Settings, located at the bottom of the Layout gallery, for Mac.) Delete extra spaces. Once finish typing, select all text in the body copy block and click the Bullets button, within the Paragraph group to turn off bullets.
32
G1 - Old GC Phases Performs a Young GC
Piggybacks root detection. Concurrent Old region marking starts Also, profile per region liveliness. Which region, I can claim the best garbage. Remarking Phase Process STAB Process Reference Queue Cleanup Phase No tree traversal in the region - So, its full of Garbage.
33
G1 - Mixed GC Phases Partial Regions
With young generation collection, G1 adds some area of Old region as well to perform GC. -XX:MixedGCCountTarget Which old region to give ? - One which can give max benefit -XX:G1MixedGCLiveThresholdPercentage Not interested in seeing the regions which are full of live objects. -XX:G1HeapWastePercentage
34
G1 - Mixed GC View O Y O Y S O Y Y S O H H H O Y O Y O O
35
G1 - Mixed GC View O O O Y Y S O H H H O O O O O
36
G1 - Best Practices Avoid setting up too much of parameter.
You will end up G1 behaving abruptly. Avoid full GC. Look at the adaptive policy. Avoid allocation Failure Very similar to Concurrent Mark Failure in CMS. It will call STW and a full GC Issue with heap or with the code Careful with Humongous Regions. Change region size, if it is more.
37
Golden References Charlie Hunt - G1 Evaluation
Simone Bordet - G1 Details and Tuning G1 - Devoxx talks Oracle Documentation on G1 Poonam Bajaj Blogs If you are seeing any unexceptional behaviour, feel free to contact us.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.