1' Copyright (c) 2021-2022 Huawei Device Co., Ltd. 2' Licensed under the Apache License, Version 2.0 (the "License"); 3' you may not use this file except in compliance with the License. 4' You may obtain a copy of the License at 5' 6' http://www.apache.org/licenses/LICENSE-2.0 7' 8' Unless required by applicable law or agreed to in writing, software 9' distributed under the License is distributed on an "AS IS" BASIS, 10' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11' See the License for the specific language governing permissions and 12' limitations under the License. 13 14@startuml 15skinparam monochrome true 16title G1: garbage collection flow 17:Process not processed cards from CardTable to fill RemSets; 18:Add all Eden regions to the Collection Set; 19if (Mixed) then(Yes) 20 :Select and add some old regions to the Collection Set 21 We can use these metrics for selection: 22 - last time when this region participated in GC or when it was created 23 - number of GCs it survived 24 - occupied space; 25endif 26:Collect Roots for regions in the Collection Set: 27Roots from stack 28Class roots, string roots etc 29__Heap roots collected via RemSets__; 30:Mark objects by traversing object stack obtained from the roots; 31:Compact: copy marked/alive objects to the old regions(create new if required) 32Note: only if occupied by alive objects space in region < some threshold; 33:Update references to the moved objects; 34:Update RemSets(remove freed regions from RemSets, mark cards with moved objects as "dirty"); 35:Return freed regions to region space; 36stop 37@enduml 38