src/share/vm/memory/memRegion.hpp

Tue, 24 Feb 2015 15:04:52 -0500

author
dlong
date
Tue, 24 Feb 2015 15:04:52 -0500
changeset 7598
ddce0b7cee93
parent 5614
9758d9f36299
child 6876
710a3c8b516e
permissions
-rw-r--r--

8072383: resolve conflicts between open and closed ports
Summary: refactor close to remove references to closed ports
Reviewed-by: kvn, simonis, sgehwolf, dholmes

duke@435 1 /*
coleenp@5614 2 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_MEMORY_MEMREGION_HPP
stefank@2314 26 #define SHARE_VM_MEMORY_MEMREGION_HPP
stefank@2314 27
stefank@2314 28 #include "memory/allocation.hpp"
stefank@2314 29 #include "utilities/debug.hpp"
stefank@2314 30 #include "utilities/globalDefinitions.hpp"
stefank@2314 31
duke@435 32 // A very simple data structure representing a contigous region
duke@435 33 // region of address space.
duke@435 34
duke@435 35 // Note that MemRegions are passed by value, not by reference.
duke@435 36 // The intent is that they remain very small and contain no
minqi@5103 37 // objects. _ValueObj should never be allocated in heap but we do
minqi@5103 38 // create MemRegions (in CardTableModRefBS) in heap so operator
minqi@5103 39 // new and operator new [] added for this special case.
duke@435 40
coleenp@4037 41 class MetaWord;
coleenp@4037 42
duke@435 43 class MemRegion VALUE_OBJ_CLASS_SPEC {
duke@435 44 friend class VMStructs;
duke@435 45 private:
duke@435 46 HeapWord* _start;
duke@435 47 size_t _word_size;
duke@435 48
duke@435 49 public:
duke@435 50 MemRegion() : _start(NULL), _word_size(0) {};
duke@435 51 MemRegion(HeapWord* start, size_t word_size) :
duke@435 52 _start(start), _word_size(word_size) {};
duke@435 53 MemRegion(HeapWord* start, HeapWord* end) :
duke@435 54 _start(start), _word_size(pointer_delta(end, start)) {
duke@435 55 assert(end >= start, "incorrect constructor arguments");
duke@435 56 }
coleenp@4037 57 MemRegion(MetaWord* start, MetaWord* end) :
coleenp@4037 58 _start((HeapWord*)start), _word_size(pointer_delta(end, start)) {
coleenp@4037 59 assert(end >= start, "incorrect constructor arguments");
coleenp@4037 60 }
duke@435 61
duke@435 62 MemRegion(const MemRegion& mr): _start(mr._start), _word_size(mr._word_size) {}
duke@435 63
duke@435 64 MemRegion intersection(const MemRegion mr2) const;
duke@435 65 // regions must overlap or be adjacent
duke@435 66 MemRegion _union(const MemRegion mr2) const;
duke@435 67 // minus will fail a guarantee if mr2 is interior to this,
duke@435 68 // since there's no way to return 2 disjoint regions.
duke@435 69 MemRegion minus(const MemRegion mr2) const;
duke@435 70
duke@435 71 HeapWord* start() const { return _start; }
duke@435 72 HeapWord* end() const { return _start + _word_size; }
duke@435 73 HeapWord* last() const { return _start + _word_size - 1; }
duke@435 74
duke@435 75 void set_start(HeapWord* start) { _start = start; }
duke@435 76 void set_end(HeapWord* end) { _word_size = pointer_delta(end, _start); }
duke@435 77 void set_word_size(size_t word_size) {
duke@435 78 _word_size = word_size;
duke@435 79 }
duke@435 80
duke@435 81 bool contains(const MemRegion mr2) const {
duke@435 82 return _start <= mr2._start && end() >= mr2.end();
duke@435 83 }
duke@435 84 bool contains(const void* addr) const {
duke@435 85 return addr >= (void*)_start && addr < (void*)end();
duke@435 86 }
duke@435 87 bool equals(const MemRegion mr2) const {
duke@435 88 // first disjunct since we do not have a canonical empty set
duke@435 89 return ((is_empty() && mr2.is_empty()) ||
duke@435 90 (start() == mr2.start() && end() == mr2.end()));
duke@435 91 }
duke@435 92
duke@435 93 size_t byte_size() const { return _word_size * sizeof(HeapWord); }
duke@435 94 size_t word_size() const { return _word_size; }
duke@435 95
duke@435 96 bool is_empty() const { return word_size() == 0; }
coleenp@5614 97 void* operator new(size_t size) throw();
coleenp@5614 98 void* operator new [](size_t size) throw();
minqi@5103 99 void operator delete(void* p);
minqi@5103 100 void operator delete [](void* p);
duke@435 101 };
duke@435 102
duke@435 103 // For iteration over MemRegion's.
duke@435 104
duke@435 105 class MemRegionClosure : public StackObj {
duke@435 106 public:
duke@435 107 virtual void do_MemRegion(MemRegion mr) = 0;
duke@435 108 };
duke@435 109
duke@435 110 // A ResourceObj version of MemRegionClosure
duke@435 111
duke@435 112 class MemRegionClosureRO: public MemRegionClosure {
duke@435 113 public:
coleenp@5614 114 void* operator new(size_t size, ResourceObj::allocation_type type, MEMFLAGS flags) throw() {
zgu@3900 115 return ResourceObj::operator new(size, type, flags);
duke@435 116 }
coleenp@5614 117 void* operator new(size_t size, Arena *arena) throw() {
duke@435 118 return ResourceObj::operator new(size, arena);
duke@435 119 }
coleenp@5614 120 void* operator new(size_t size) throw() {
duke@435 121 return ResourceObj::operator new(size);
duke@435 122 }
duke@435 123
duke@435 124 void operator delete(void* p) {} // nothing to do
duke@435 125 };
stefank@2314 126
stefank@2314 127 #endif // SHARE_VM_MEMORY_MEMREGION_HPP

mercurial