1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/memory/memRegion.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,119 @@ 1.4 +/* 1.5 + * Copyright (c) 2000, 2013, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "precompiled.hpp" 1.29 +#include "memory/allocation.hpp" 1.30 +#include "memory/allocation.inline.hpp" 1.31 +#include "memory/memRegion.hpp" 1.32 +#include "runtime/globals.hpp" 1.33 + 1.34 +// A very simple data structure representing a contigous word-aligned 1.35 +// region of address space. 1.36 + 1.37 +MemRegion MemRegion::intersection(const MemRegion mr2) const { 1.38 + MemRegion res; 1.39 + HeapWord* res_start = MAX2(start(), mr2.start()); 1.40 + HeapWord* res_end = MIN2(end(), mr2.end()); 1.41 + if (res_start < res_end) { 1.42 + res.set_start(res_start); 1.43 + res.set_end(res_end); 1.44 + } 1.45 + return res; 1.46 +} 1.47 + 1.48 +MemRegion MemRegion::_union(const MemRegion mr2) const { 1.49 + // If one region is empty, return the other 1.50 + if (is_empty()) return mr2; 1.51 + if (mr2.is_empty()) return MemRegion(start(), end()); 1.52 + 1.53 + // Otherwise, regions must overlap or be adjacent 1.54 + assert(((start() <= mr2.start()) && (end() >= mr2.start())) || 1.55 + ((mr2.start() <= start()) && (mr2.end() >= start())), 1.56 + "non-adjacent or overlapping regions"); 1.57 + MemRegion res; 1.58 + HeapWord* res_start = MIN2(start(), mr2.start()); 1.59 + HeapWord* res_end = MAX2(end(), mr2.end()); 1.60 + res.set_start(res_start); 1.61 + res.set_end(res_end); 1.62 + return res; 1.63 +} 1.64 + 1.65 +MemRegion MemRegion::minus(const MemRegion mr2) const { 1.66 + // There seem to be 6 cases: 1.67 + // |this MemRegion| 1.68 + // |strictly below| 1.69 + // |overlap beginning| 1.70 + // |interior| 1.71 + // |overlap ending| 1.72 + // |strictly above| 1.73 + // |completely overlapping| 1.74 + // We can't deal with an interior case because it would 1.75 + // produce two disjoint regions as a result. 1.76 + // We aren't trying to be optimal in the number of tests below, 1.77 + // but the order is important to distinguish the strictly cases 1.78 + // from the overlapping cases. 1.79 + if (mr2.end() <= start()) { 1.80 + // strictly below 1.81 + return MemRegion(start(), end()); 1.82 + } 1.83 + if (mr2.start() <= start() && mr2.end() <= end()) { 1.84 + // overlap beginning 1.85 + return MemRegion(mr2.end(), end()); 1.86 + } 1.87 + if (mr2.start() >= end()) { 1.88 + // strictly above 1.89 + return MemRegion(start(), end()); 1.90 + } 1.91 + if (mr2.start() >= start() && mr2.end() >= end()) { 1.92 + // overlap ending 1.93 + return MemRegion(start(), mr2.start()); 1.94 + } 1.95 + if (mr2.start() <= start() && mr2.end() >= end()) { 1.96 + // completely overlapping 1.97 + return MemRegion(); 1.98 + } 1.99 + if (mr2.start() > start() && mr2.end() < end()) { 1.100 + // interior 1.101 + guarantee(false, "MemRegion::minus, but interior"); 1.102 + return MemRegion(); 1.103 + } 1.104 + ShouldNotReachHere(); 1.105 + return MemRegion(); 1.106 +} 1.107 + 1.108 +void* MemRegion::operator new(size_t size) throw() { 1.109 + return (address)AllocateHeap(size, mtGC, 0, AllocFailStrategy::RETURN_NULL); 1.110 +} 1.111 + 1.112 +void* MemRegion::operator new [](size_t size) throw() { 1.113 + return (address)AllocateHeap(size, mtGC, 0, AllocFailStrategy::RETURN_NULL); 1.114 +} 1.115 +void MemRegion::operator delete(void* p) { 1.116 + FreeHeap(p, mtGC); 1.117 +} 1.118 + 1.119 +void MemRegion::operator delete [](void* p) { 1.120 + FreeHeap(p, mtGC); 1.121 +} 1.122 +