src/share/vm/gc_implementation/g1/heapRegionSet.inline.hpp

Tue, 17 Oct 2017 12:58:25 +0800

author
aoqi
date
Tue, 17 Oct 2017 12:58:25 +0800
changeset 7994
04ff2f6cd0eb
parent 7535
7ae4e26cb1e0
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP
aoqi@0 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP
aoqi@0 27
aoqi@0 28 #include "gc_implementation/g1/heapRegionSet.hpp"
aoqi@0 29
aoqi@0 30 inline void HeapRegionSetBase::add(HeapRegion* hr) {
aoqi@0 31 check_mt_safety();
aoqi@0 32 assert(hr->containing_set() == NULL, hrs_ext_msg(this, "should not already have a containing set %u"));
tschatzl@7050 33 assert(hr->next() == NULL, hrs_ext_msg(this, "should not already be linked"));
tschatzl@7050 34 assert(hr->prev() == NULL, hrs_ext_msg(this, "should not already be linked"));
aoqi@0 35
aoqi@0 36 _count.increment(1u, hr->capacity());
aoqi@0 37 hr->set_containing_set(this);
aoqi@0 38 verify_region(hr);
aoqi@0 39 }
aoqi@0 40
aoqi@0 41 inline void HeapRegionSetBase::remove(HeapRegion* hr) {
aoqi@0 42 check_mt_safety();
aoqi@0 43 verify_region(hr);
tschatzl@7050 44 assert(hr->next() == NULL, hrs_ext_msg(this, "should already be unlinked"));
tschatzl@7050 45 assert(hr->prev() == NULL, hrs_ext_msg(this, "should already be unlinked"));
aoqi@0 46
aoqi@0 47 hr->set_containing_set(NULL);
aoqi@0 48 assert(_count.length() > 0, hrs_ext_msg(this, "pre-condition"));
aoqi@0 49 _count.decrement(1u, hr->capacity());
aoqi@0 50 }
aoqi@0 51
aoqi@0 52 inline void FreeRegionList::add_ordered(HeapRegion* hr) {
tschatzl@7050 53 assert((length() == 0 && _head == NULL && _tail == NULL && _last == NULL) ||
aoqi@0 54 (length() > 0 && _head != NULL && _tail != NULL),
aoqi@0 55 hrs_ext_msg(this, "invariant"));
aoqi@0 56 // add() will verify the region and check mt safety.
aoqi@0 57 add(hr);
aoqi@0 58
aoqi@0 59 // Now link the region
aoqi@0 60 if (_head != NULL) {
aoqi@0 61 HeapRegion* curr;
aoqi@0 62
tschatzl@7091 63 if (_last != NULL && _last->hrm_index() < hr->hrm_index()) {
aoqi@0 64 curr = _last;
aoqi@0 65 } else {
aoqi@0 66 curr = _head;
aoqi@0 67 }
aoqi@0 68
aoqi@0 69 // Find first entry with a Region Index larger than entry to insert.
tschatzl@7091 70 while (curr != NULL && curr->hrm_index() < hr->hrm_index()) {
aoqi@0 71 curr = curr->next();
aoqi@0 72 }
aoqi@0 73
aoqi@0 74 hr->set_next(curr);
aoqi@0 75
aoqi@0 76 if (curr == NULL) {
aoqi@0 77 // Adding at the end
aoqi@0 78 hr->set_prev(_tail);
aoqi@0 79 _tail->set_next(hr);
aoqi@0 80 _tail = hr;
aoqi@0 81 } else if (curr->prev() == NULL) {
aoqi@0 82 // Adding at the beginning
aoqi@0 83 hr->set_prev(NULL);
aoqi@0 84 _head = hr;
aoqi@0 85 curr->set_prev(hr);
aoqi@0 86 } else {
aoqi@0 87 hr->set_prev(curr->prev());
aoqi@0 88 hr->prev()->set_next(hr);
aoqi@0 89 curr->set_prev(hr);
aoqi@0 90 }
aoqi@0 91 } else {
aoqi@0 92 // The list was empty
aoqi@0 93 _tail = hr;
aoqi@0 94 _head = hr;
aoqi@0 95 }
aoqi@0 96 _last = hr;
aoqi@0 97 }
aoqi@0 98
tschatzl@7050 99 inline HeapRegion* FreeRegionList::remove_from_head_impl() {
tschatzl@7050 100 HeapRegion* result = _head;
tschatzl@7050 101 _head = result->next();
aoqi@0 102 if (_head == NULL) {
aoqi@0 103 _tail = NULL;
aoqi@0 104 } else {
aoqi@0 105 _head->set_prev(NULL);
aoqi@0 106 }
tschatzl@7050 107 result->set_next(NULL);
tschatzl@7050 108 return result;
tschatzl@7050 109 }
tschatzl@7050 110
tschatzl@7050 111 inline HeapRegion* FreeRegionList::remove_from_tail_impl() {
tschatzl@7050 112 HeapRegion* result = _tail;
tschatzl@7050 113
tschatzl@7050 114 _tail = result->prev();
tschatzl@7050 115 if (_tail == NULL) {
tschatzl@7050 116 _head = NULL;
tschatzl@7050 117 } else {
tschatzl@7050 118 _tail->set_next(NULL);
tschatzl@7050 119 }
tschatzl@7050 120 result->set_prev(NULL);
tschatzl@7050 121 return result;
tschatzl@7050 122 }
tschatzl@7050 123
tschatzl@7050 124 inline HeapRegion* FreeRegionList::remove_region(bool from_head) {
tschatzl@7050 125 check_mt_safety();
tschatzl@7050 126 verify_optional();
tschatzl@7050 127
tschatzl@7050 128 if (is_empty()) {
tschatzl@7050 129 return NULL;
tschatzl@7050 130 }
tschatzl@7050 131 assert(length() > 0 && _head != NULL && _tail != NULL,
tschatzl@7050 132 hrs_ext_msg(this, "invariant"));
tschatzl@7050 133
tschatzl@7050 134 HeapRegion* hr;
tschatzl@7050 135
tschatzl@7050 136 if (from_head) {
tschatzl@7050 137 hr = remove_from_head_impl();
tschatzl@7050 138 } else {
tschatzl@7050 139 hr = remove_from_tail_impl();
tschatzl@7050 140 }
aoqi@0 141
aoqi@0 142 if (_last == hr) {
aoqi@0 143 _last = NULL;
aoqi@0 144 }
aoqi@0 145
aoqi@0 146 // remove() will verify the region and check mt safety.
aoqi@0 147 remove(hr);
aoqi@0 148 return hr;
aoqi@0 149 }
aoqi@0 150
tschatzl@7050 151 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP
aoqi@0 152

mercurial