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