Mercurial > hg > truffle
annotate src/share/vm/memory/memRegion.cpp @ 2831:f072013daba9
Added lookup method.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Tue, 31 May 2011 11:32:48 +0200 |
parents | f95d63e2154a |
children | f9be75d21404 |
rev | line source |
---|---|
0 | 1 /* |
1972 | 2 * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "memory/memRegion.hpp" | |
27 #include "runtime/globals.hpp" | |
28 | |
0 | 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"); | |
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 } | |
59 | |
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 } |