src/share/vm/memory/memRegion.cpp

Thu, 24 Mar 2011 15:47:01 -0700

author
ysr
date
Thu, 24 Mar 2011 15:47:01 -0700
changeset 2710
5134fa1cfe63
parent 2314
f95d63e2154a
child 5103
f9be75d21404
permissions
-rw-r--r--

7029036: Card-table verification hangs with all framework collectors, except G1, even before the first GC
Summary: When verifying clean card ranges, use memory-range-bounded iteration over oops of objects overlapping that range, thus avoiding the otherwise quadratic worst-case cost of scanning large object arrays.
Reviewed-by: jmasa, jwilhelm, tonyp

duke@435 1 /*
stefank@2314 2 * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "memory/memRegion.hpp"
stefank@2314 27 #include "runtime/globals.hpp"
stefank@2314 28
duke@435 29 // A very simple data structure representing a contigous word-aligned
duke@435 30 // region of address space.
duke@435 31
duke@435 32 MemRegion MemRegion::intersection(const MemRegion mr2) const {
duke@435 33 MemRegion res;
duke@435 34 HeapWord* res_start = MAX2(start(), mr2.start());
duke@435 35 HeapWord* res_end = MIN2(end(), mr2.end());
duke@435 36 if (res_start < res_end) {
duke@435 37 res.set_start(res_start);
duke@435 38 res.set_end(res_end);
duke@435 39 }
duke@435 40 return res;
duke@435 41 }
duke@435 42
duke@435 43 MemRegion MemRegion::_union(const MemRegion mr2) const {
duke@435 44 // If one region is empty, return the other
duke@435 45 if (is_empty()) return mr2;
duke@435 46 if (mr2.is_empty()) return MemRegion(start(), end());
duke@435 47
duke@435 48 // Otherwise, regions must overlap or be adjacent
duke@435 49 assert(((start() <= mr2.start()) && (end() >= mr2.start())) ||
duke@435 50 ((mr2.start() <= start()) && (mr2.end() >= start())),
duke@435 51 "non-adjacent or overlapping regions");
duke@435 52 MemRegion res;
duke@435 53 HeapWord* res_start = MIN2(start(), mr2.start());
duke@435 54 HeapWord* res_end = MAX2(end(), mr2.end());
duke@435 55 res.set_start(res_start);
duke@435 56 res.set_end(res_end);
duke@435 57 return res;
duke@435 58 }
duke@435 59
duke@435 60 MemRegion MemRegion::minus(const MemRegion mr2) const {
duke@435 61 // There seem to be 6 cases:
duke@435 62 // |this MemRegion|
duke@435 63 // |strictly below|
duke@435 64 // |overlap beginning|
duke@435 65 // |interior|
duke@435 66 // |overlap ending|
duke@435 67 // |strictly above|
duke@435 68 // |completely overlapping|
duke@435 69 // We can't deal with an interior case because it would
duke@435 70 // produce two disjoint regions as a result.
duke@435 71 // We aren't trying to be optimal in the number of tests below,
duke@435 72 // but the order is important to distinguish the strictly cases
duke@435 73 // from the overlapping cases.
duke@435 74 if (mr2.end() <= start()) {
duke@435 75 // strictly below
duke@435 76 return MemRegion(start(), end());
duke@435 77 }
duke@435 78 if (mr2.start() <= start() && mr2.end() <= end()) {
duke@435 79 // overlap beginning
duke@435 80 return MemRegion(mr2.end(), end());
duke@435 81 }
duke@435 82 if (mr2.start() >= end()) {
duke@435 83 // strictly above
duke@435 84 return MemRegion(start(), end());
duke@435 85 }
duke@435 86 if (mr2.start() >= start() && mr2.end() >= end()) {
duke@435 87 // overlap ending
duke@435 88 return MemRegion(start(), mr2.start());
duke@435 89 }
duke@435 90 if (mr2.start() <= start() && mr2.end() >= end()) {
duke@435 91 // completely overlapping
duke@435 92 return MemRegion();
duke@435 93 }
duke@435 94 if (mr2.start() > start() && mr2.end() < end()) {
duke@435 95 // interior
duke@435 96 guarantee(false, "MemRegion::minus, but interior");
duke@435 97 return MemRegion();
duke@435 98 }
duke@435 99 ShouldNotReachHere();
duke@435 100 return MemRegion();
duke@435 101 }

mercurial