src/hotspot/share/gc/g1/g1CollectionSetCandidates.cpp
changeset 53703 24341625d8f2
child 53704 ef72c85a0534
equal deleted inserted replaced
53702:50a5d0353570 53703:24341625d8f2
       
     1 /*
       
     2  * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  *
       
    23  */
       
    24 
       
    25 #include "precompiled.hpp"
       
    26 #include "gc/g1/collectionSetChooser.hpp"
       
    27 #include "gc/g1/g1CollectionSetCandidates.hpp"
       
    28 #include "gc/g1/heapRegion.inline.hpp"
       
    29 
       
    30 HeapRegion* G1CollectionSetCandidates::pop_front() {
       
    31   assert(_front_idx < _num_regions, "pre-condition");
       
    32   HeapRegion* hr = _regions[_front_idx];
       
    33   assert(hr != NULL, "pre-condition");
       
    34   _regions[_front_idx] = NULL;
       
    35   assert(hr->reclaimable_bytes() <= _remaining_reclaimable_bytes,
       
    36          "Remaining reclaimable bytes inconsistent "
       
    37          "from region: " SIZE_FORMAT " remaining: " SIZE_FORMAT,
       
    38          hr->reclaimable_bytes(), _remaining_reclaimable_bytes);
       
    39   _remaining_reclaimable_bytes -= hr->reclaimable_bytes();
       
    40   _front_idx++;
       
    41   return hr;
       
    42 }
       
    43 
       
    44 void G1CollectionSetCandidates::push_front(HeapRegion* hr) {
       
    45   assert(hr != NULL, "Can't put back a NULL region");
       
    46   assert(_front_idx >= 1, "Too many regions have been put back.");
       
    47   _front_idx--;
       
    48   _regions[_front_idx] = hr;
       
    49   _remaining_reclaimable_bytes += hr->reclaimable_bytes();
       
    50 }
       
    51 
       
    52 void G1CollectionSetCandidates::iterate(HeapRegionClosure* cl) {
       
    53   for (uint i = _front_idx; i < _num_regions; i++) {
       
    54     HeapRegion* r = _regions[i];
       
    55     if (cl->do_heap_region(r)) {
       
    56       cl->set_incomplete();
       
    57       break;
       
    58     }
       
    59   }
       
    60 }
       
    61 
       
    62 #ifndef PRODUCT
       
    63 void G1CollectionSetCandidates::verify() const {
       
    64   guarantee(_front_idx <= _num_regions, "Index: %u Num_regions: %u", _front_idx, _num_regions);
       
    65   uint idx = 0;
       
    66   size_t sum_of_reclaimable_bytes = 0;
       
    67   while (idx < _front_idx) {
       
    68     guarantee(_regions[idx] == NULL, "All entries before _front_idx %u should be NULL, but %u is not",
       
    69               _front_idx, idx);
       
    70     idx++;
       
    71   }
       
    72   HeapRegion *prev = NULL;
       
    73   for (; idx < _num_regions; idx++) {
       
    74     HeapRegion *cur = _regions[idx];
       
    75     guarantee(cur != NULL, "Regions after _front_idx %u cannot be NULL but %u is", _front_idx, idx);
       
    76     guarantee(CollectionSetChooser::should_add(cur), "Region %u should be eligible for addition.", cur->hrm_index());
       
    77     if (prev != NULL) {
       
    78       guarantee(prev->gc_efficiency() >= cur->gc_efficiency(),
       
    79                 "GC efficiency for region %u: %1.4f smaller than for region %u: %1.4f",
       
    80                 prev->hrm_index(), prev->gc_efficiency(), cur->hrm_index(), cur->gc_efficiency());
       
    81     }
       
    82     sum_of_reclaimable_bytes += cur->reclaimable_bytes();
       
    83     prev = cur;
       
    84   }
       
    85   guarantee(sum_of_reclaimable_bytes == _remaining_reclaimable_bytes,
       
    86             "Inconsistent remaining_reclaimable bytes, remaining " SIZE_FORMAT " calculated " SIZE_FORMAT,
       
    87             _remaining_reclaimable_bytes, sum_of_reclaimable_bytes);
       
    88 }
       
    89 #endif // !PRODUCT