src/share/vm/memory/memRegion.hpp

Thu, 12 Oct 2017 21:27:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 21:27:07 +0800
changeset 7535
7ae4e26cb1e0
parent 6876
710a3c8b516e
permissions
-rw-r--r--

merge

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

mercurial