Tue, 30 Apr 2013 11:56:52 -0700
8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
Reviewed-by: coleenp, zgu, hseigel
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 */
25 #include "precompiled.hpp"
26 #include "memory/memRegion.hpp"
27 #include "runtime/globals.hpp"
29 // A very simple data structure representing a contigous word-aligned
30 // region of address space.
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 }
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());
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");
52 MemRegion res;
53 HeapWord* res_start = MIN2(start(), mr2.start());
54 HeapWord* res_end = MAX2(end(), mr2.end());
55 res.set_start(res_start);
56 res.set_end(res_end);
57 return res;
58 }
60 MemRegion MemRegion::minus(const MemRegion mr2) const {
61 // There seem to be 6 cases:
62 // |this MemRegion|
63 // |strictly below|
64 // |overlap beginning|
65 // |interior|
66 // |overlap ending|
67 // |strictly above|
68 // |completely overlapping|
69 // We can't deal with an interior case because it would
70 // produce two disjoint regions as a result.
71 // We aren't trying to be optimal in the number of tests below,
72 // but the order is important to distinguish the strictly cases
73 // from the overlapping cases.
74 if (mr2.end() <= start()) {
75 // strictly below
76 return MemRegion(start(), end());
77 }
78 if (mr2.start() <= start() && mr2.end() <= end()) {
79 // overlap beginning
80 return MemRegion(mr2.end(), end());
81 }
82 if (mr2.start() >= end()) {
83 // strictly above
84 return MemRegion(start(), end());
85 }
86 if (mr2.start() >= start() && mr2.end() >= end()) {
87 // overlap ending
88 return MemRegion(start(), mr2.start());
89 }
90 if (mr2.start() <= start() && mr2.end() >= end()) {
91 // completely overlapping
92 return MemRegion();
93 }
94 if (mr2.start() > start() && mr2.end() < end()) {
95 // interior
96 guarantee(false, "MemRegion::minus, but interior");
97 return MemRegion();
98 }
99 ShouldNotReachHere();
100 return MemRegion();
101 }