1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/memory/memRegion.hpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,106 @@ 1.4 +/* 1.5 + * Copyright 2000-2004 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +// A very simple data structure representing a contigous region 1.29 +// region of address space. 1.30 + 1.31 +// Note that MemRegions are passed by value, not by reference. 1.32 +// The intent is that they remain very small and contain no 1.33 +// objects. 1.34 + 1.35 +class MemRegion VALUE_OBJ_CLASS_SPEC { 1.36 + friend class VMStructs; 1.37 +private: 1.38 + HeapWord* _start; 1.39 + size_t _word_size; 1.40 + 1.41 +public: 1.42 + MemRegion() : _start(NULL), _word_size(0) {}; 1.43 + MemRegion(HeapWord* start, size_t word_size) : 1.44 + _start(start), _word_size(word_size) {}; 1.45 + MemRegion(HeapWord* start, HeapWord* end) : 1.46 + _start(start), _word_size(pointer_delta(end, start)) { 1.47 + assert(end >= start, "incorrect constructor arguments"); 1.48 + } 1.49 + 1.50 + MemRegion(const MemRegion& mr): _start(mr._start), _word_size(mr._word_size) {} 1.51 + 1.52 + MemRegion intersection(const MemRegion mr2) const; 1.53 + // regions must overlap or be adjacent 1.54 + MemRegion _union(const MemRegion mr2) const; 1.55 + // minus will fail a guarantee if mr2 is interior to this, 1.56 + // since there's no way to return 2 disjoint regions. 1.57 + MemRegion minus(const MemRegion mr2) const; 1.58 + 1.59 + HeapWord* start() const { return _start; } 1.60 + HeapWord* end() const { return _start + _word_size; } 1.61 + HeapWord* last() const { return _start + _word_size - 1; } 1.62 + 1.63 + void set_start(HeapWord* start) { _start = start; } 1.64 + void set_end(HeapWord* end) { _word_size = pointer_delta(end, _start); } 1.65 + void set_word_size(size_t word_size) { 1.66 + _word_size = word_size; 1.67 + } 1.68 + 1.69 + bool contains(const MemRegion mr2) const { 1.70 + return _start <= mr2._start && end() >= mr2.end(); 1.71 + } 1.72 + bool contains(const void* addr) const { 1.73 + return addr >= (void*)_start && addr < (void*)end(); 1.74 + } 1.75 + bool equals(const MemRegion mr2) const { 1.76 + // first disjunct since we do not have a canonical empty set 1.77 + return ((is_empty() && mr2.is_empty()) || 1.78 + (start() == mr2.start() && end() == mr2.end())); 1.79 + } 1.80 + 1.81 + size_t byte_size() const { return _word_size * sizeof(HeapWord); } 1.82 + size_t word_size() const { return _word_size; } 1.83 + 1.84 + bool is_empty() const { return word_size() == 0; } 1.85 +}; 1.86 + 1.87 +// For iteration over MemRegion's. 1.88 + 1.89 +class MemRegionClosure : public StackObj { 1.90 +public: 1.91 + virtual void do_MemRegion(MemRegion mr) = 0; 1.92 +}; 1.93 + 1.94 +// A ResourceObj version of MemRegionClosure 1.95 + 1.96 +class MemRegionClosureRO: public MemRegionClosure { 1.97 +public: 1.98 + void* operator new(size_t size, ResourceObj::allocation_type type) { 1.99 + return ResourceObj::operator new(size, type); 1.100 + } 1.101 + void* operator new(size_t size, Arena *arena) { 1.102 + return ResourceObj::operator new(size, arena); 1.103 + } 1.104 + void* operator new(size_t size) { 1.105 + return ResourceObj::operator new(size); 1.106 + } 1.107 + 1.108 + void operator delete(void* p) {} // nothing to do 1.109 +};