1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/memory/memRegion.cpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,100 @@ 1.4 +/* 1.5 + * Copyright 2000-2004 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +// A very simple data structure representing a contigous word-aligned 1.29 +// region of address space. 1.30 + 1.31 +#include "incls/_precompiled.incl" 1.32 +#include "incls/_memRegion.cpp.incl" 1.33 + 1.34 +MemRegion MemRegion::intersection(const MemRegion mr2) const { 1.35 + MemRegion res; 1.36 + HeapWord* res_start = MAX2(start(), mr2.start()); 1.37 + HeapWord* res_end = MIN2(end(), mr2.end()); 1.38 + if (res_start < res_end) { 1.39 + res.set_start(res_start); 1.40 + res.set_end(res_end); 1.41 + } 1.42 + return res; 1.43 +} 1.44 + 1.45 +MemRegion MemRegion::_union(const MemRegion mr2) const { 1.46 + // If one region is empty, return the other 1.47 + if (is_empty()) return mr2; 1.48 + if (mr2.is_empty()) return MemRegion(start(), end()); 1.49 + 1.50 + // Otherwise, regions must overlap or be adjacent 1.51 + assert(((start() <= mr2.start()) && (end() >= mr2.start())) || 1.52 + ((mr2.start() <= start()) && (mr2.end() >= start())), 1.53 + "non-adjacent or overlapping regions"); 1.54 + MemRegion res; 1.55 + HeapWord* res_start = MIN2(start(), mr2.start()); 1.56 + HeapWord* res_end = MAX2(end(), mr2.end()); 1.57 + res.set_start(res_start); 1.58 + res.set_end(res_end); 1.59 + return res; 1.60 +} 1.61 + 1.62 +MemRegion MemRegion::minus(const MemRegion mr2) const { 1.63 + // There seem to be 6 cases: 1.64 + // |this MemRegion| 1.65 + // |strictly below| 1.66 + // |overlap beginning| 1.67 + // |interior| 1.68 + // |overlap ending| 1.69 + // |strictly above| 1.70 + // |completely overlapping| 1.71 + // We can't deal with an interior case because it would 1.72 + // produce two disjoint regions as a result. 1.73 + // We aren't trying to be optimal in the number of tests below, 1.74 + // but the order is important to distinguish the strictly cases 1.75 + // from the overlapping cases. 1.76 + if (mr2.end() <= start()) { 1.77 + // strictly below 1.78 + return MemRegion(start(), end()); 1.79 + } 1.80 + if (mr2.start() <= start() && mr2.end() <= end()) { 1.81 + // overlap beginning 1.82 + return MemRegion(mr2.end(), end()); 1.83 + } 1.84 + if (mr2.start() >= end()) { 1.85 + // strictly above 1.86 + return MemRegion(start(), end()); 1.87 + } 1.88 + if (mr2.start() >= start() && mr2.end() >= end()) { 1.89 + // overlap ending 1.90 + return MemRegion(start(), mr2.start()); 1.91 + } 1.92 + if (mr2.start() <= start() && mr2.end() >= end()) { 1.93 + // completely overlapping 1.94 + return MemRegion(); 1.95 + } 1.96 + if (mr2.start() > start() && mr2.end() < end()) { 1.97 + // interior 1.98 + guarantee(false, "MemRegion::minus, but interior"); 1.99 + return MemRegion(); 1.100 + } 1.101 + ShouldNotReachHere(); 1.102 + return MemRegion(); 1.103 +}