duke@435: /* coleenp@5614: * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_MEMORY_MEMREGION_HPP stefank@2314: #define SHARE_VM_MEMORY_MEMREGION_HPP stefank@2314: stefank@2314: #include "memory/allocation.hpp" stefank@2314: #include "utilities/debug.hpp" stefank@2314: #include "utilities/globalDefinitions.hpp" stefank@2314: duke@435: // A very simple data structure representing a contigous region duke@435: // region of address space. duke@435: duke@435: // Note that MemRegions are passed by value, not by reference. duke@435: // The intent is that they remain very small and contain no minqi@5103: // objects. _ValueObj should never be allocated in heap but we do minqi@5103: // create MemRegions (in CardTableModRefBS) in heap so operator minqi@5103: // new and operator new [] added for this special case. duke@435: coleenp@4037: class MetaWord; coleenp@4037: duke@435: class MemRegion VALUE_OBJ_CLASS_SPEC { duke@435: friend class VMStructs; duke@435: private: duke@435: HeapWord* _start; duke@435: size_t _word_size; duke@435: duke@435: public: duke@435: MemRegion() : _start(NULL), _word_size(0) {}; duke@435: MemRegion(HeapWord* start, size_t word_size) : duke@435: _start(start), _word_size(word_size) {}; duke@435: MemRegion(HeapWord* start, HeapWord* end) : duke@435: _start(start), _word_size(pointer_delta(end, start)) { duke@435: assert(end >= start, "incorrect constructor arguments"); duke@435: } coleenp@4037: MemRegion(MetaWord* start, MetaWord* end) : coleenp@4037: _start((HeapWord*)start), _word_size(pointer_delta(end, start)) { coleenp@4037: assert(end >= start, "incorrect constructor arguments"); coleenp@4037: } duke@435: duke@435: MemRegion(const MemRegion& mr): _start(mr._start), _word_size(mr._word_size) {} duke@435: duke@435: MemRegion intersection(const MemRegion mr2) const; duke@435: // regions must overlap or be adjacent duke@435: MemRegion _union(const MemRegion mr2) const; duke@435: // minus will fail a guarantee if mr2 is interior to this, duke@435: // since there's no way to return 2 disjoint regions. duke@435: MemRegion minus(const MemRegion mr2) const; duke@435: duke@435: HeapWord* start() const { return _start; } duke@435: HeapWord* end() const { return _start + _word_size; } duke@435: HeapWord* last() const { return _start + _word_size - 1; } duke@435: duke@435: void set_start(HeapWord* start) { _start = start; } duke@435: void set_end(HeapWord* end) { _word_size = pointer_delta(end, _start); } duke@435: void set_word_size(size_t word_size) { duke@435: _word_size = word_size; duke@435: } duke@435: duke@435: bool contains(const MemRegion mr2) const { duke@435: return _start <= mr2._start && end() >= mr2.end(); duke@435: } duke@435: bool contains(const void* addr) const { duke@435: return addr >= (void*)_start && addr < (void*)end(); duke@435: } duke@435: bool equals(const MemRegion mr2) const { duke@435: // first disjunct since we do not have a canonical empty set duke@435: return ((is_empty() && mr2.is_empty()) || duke@435: (start() == mr2.start() && end() == mr2.end())); duke@435: } duke@435: duke@435: size_t byte_size() const { return _word_size * sizeof(HeapWord); } duke@435: size_t word_size() const { return _word_size; } duke@435: duke@435: bool is_empty() const { return word_size() == 0; } coleenp@5614: void* operator new(size_t size) throw(); coleenp@5614: void* operator new [](size_t size) throw(); minqi@5103: void operator delete(void* p); minqi@5103: void operator delete [](void* p); duke@435: }; duke@435: duke@435: // For iteration over MemRegion's. duke@435: duke@435: class MemRegionClosure : public StackObj { duke@435: public: duke@435: virtual void do_MemRegion(MemRegion mr) = 0; duke@435: }; duke@435: duke@435: // A ResourceObj version of MemRegionClosure duke@435: duke@435: class MemRegionClosureRO: public MemRegionClosure { duke@435: public: coleenp@5614: void* operator new(size_t size, ResourceObj::allocation_type type, MEMFLAGS flags) throw() { zgu@3900: return ResourceObj::operator new(size, type, flags); duke@435: } coleenp@5614: void* operator new(size_t size, Arena *arena) throw() { duke@435: return ResourceObj::operator new(size, arena); duke@435: } coleenp@5614: void* operator new(size_t size) throw() { duke@435: return ResourceObj::operator new(size); duke@435: } duke@435: duke@435: void operator delete(void* p) {} // nothing to do duke@435: }; stefank@2314: stefank@2314: #endif // SHARE_VM_MEMORY_MEMREGION_HPP