1 /* 2 * Copyright (c) 2000, 2004, 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 // A very simple data structure representing a contigous word-aligned 26 // region of address space. 27 28 #include "incls/_precompiled.incl" 29 #include "incls/_memRegion.cpp.incl" 30 31 MemRegion MemRegion::intersection(const MemRegion mr2) const { 32 MemRegion res; 33 HeapWord* res_start = MAX2(start(), mr2.start()); 34 HeapWord* res_end = MIN2(end(), mr2.end()); 35 if (res_start < res_end) { 36 res.set_start(res_start); 37 res.set_end(res_end); 38 } 39 return res; 40 } 41 42 MemRegion MemRegion::_union(const MemRegion mr2) const { 43 // If one region is empty, return the other 44 if (is_empty()) return mr2; 45 if (mr2.is_empty()) return MemRegion(start(), end()); 46 47 // Otherwise, regions must overlap or be adjacent 48 assert(((start() <= mr2.start()) && (end() >= mr2.start())) || 49 ((mr2.start() <= start()) && (mr2.end() >= start())), 50 "non-adjacent or overlapping regions"); | 1 /* 2 * Copyright (c) 2000, 2010, 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 "memory/memRegion.hpp" 27 #include "runtime/globals.hpp" 28 29 // A very simple data structure representing a contigous word-aligned 30 // region of address space. 31 32 MemRegion MemRegion::intersection(const MemRegion mr2) const { 33 MemRegion res; 34 HeapWord* res_start = MAX2(start(), mr2.start()); 35 HeapWord* res_end = MIN2(end(), mr2.end()); 36 if (res_start < res_end) { 37 res.set_start(res_start); 38 res.set_end(res_end); 39 } 40 return res; 41 } 42 43 MemRegion MemRegion::_union(const MemRegion mr2) const { 44 // If one region is empty, return the other 45 if (is_empty()) return mr2; 46 if (mr2.is_empty()) return MemRegion(start(), end()); 47 48 // Otherwise, regions must overlap or be adjacent 49 assert(((start() <= mr2.start()) && (end() >= mr2.start())) || 50 ((mr2.start() <= start()) && (mr2.end() >= start())), 51 "non-adjacent or overlapping regions"); |