src/share/vm/memory/memRegion.hpp

Mon, 29 Apr 2013 16:13:57 -0400

author
hseigel
date
Mon, 29 Apr 2013 16:13:57 -0400
changeset 4987
f258c5828eb8
parent 4037
da91efe96a93
child 5103
f9be75d21404
permissions
-rw-r--r--

8011773: Some tests on Interned String crashed JVM with OOM
Summary: Instead of terminating the VM, throw OutOfMemoryError exceptions.
Reviewed-by: coleenp, dholmes

duke@435 1 /*
coleenp@4037 2 * Copyright (c) 2000, 2012, 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
duke@435 37 // objects.
duke@435 38
coleenp@4037 39 class MetaWord;
coleenp@4037 40
duke@435 41 class MemRegion VALUE_OBJ_CLASS_SPEC {
duke@435 42 friend class VMStructs;
duke@435 43 private:
duke@435 44 HeapWord* _start;
duke@435 45 size_t _word_size;
duke@435 46
duke@435 47 public:
duke@435 48 MemRegion() : _start(NULL), _word_size(0) {};
duke@435 49 MemRegion(HeapWord* start, size_t word_size) :
duke@435 50 _start(start), _word_size(word_size) {};
duke@435 51 MemRegion(HeapWord* start, HeapWord* end) :
duke@435 52 _start(start), _word_size(pointer_delta(end, start)) {
duke@435 53 assert(end >= start, "incorrect constructor arguments");
duke@435 54 }
coleenp@4037 55 MemRegion(MetaWord* start, MetaWord* end) :
coleenp@4037 56 _start((HeapWord*)start), _word_size(pointer_delta(end, start)) {
coleenp@4037 57 assert(end >= start, "incorrect constructor arguments");
coleenp@4037 58 }
duke@435 59
duke@435 60 MemRegion(const MemRegion& mr): _start(mr._start), _word_size(mr._word_size) {}
duke@435 61
duke@435 62 MemRegion intersection(const MemRegion mr2) const;
duke@435 63 // regions must overlap or be adjacent
duke@435 64 MemRegion _union(const MemRegion mr2) const;
duke@435 65 // minus will fail a guarantee if mr2 is interior to this,
duke@435 66 // since there's no way to return 2 disjoint regions.
duke@435 67 MemRegion minus(const MemRegion mr2) const;
duke@435 68
duke@435 69 HeapWord* start() const { return _start; }
duke@435 70 HeapWord* end() const { return _start + _word_size; }
duke@435 71 HeapWord* last() const { return _start + _word_size - 1; }
duke@435 72
duke@435 73 void set_start(HeapWord* start) { _start = start; }
duke@435 74 void set_end(HeapWord* end) { _word_size = pointer_delta(end, _start); }
duke@435 75 void set_word_size(size_t word_size) {
duke@435 76 _word_size = word_size;
duke@435 77 }
duke@435 78
duke@435 79 bool contains(const MemRegion mr2) const {
duke@435 80 return _start <= mr2._start && end() >= mr2.end();
duke@435 81 }
duke@435 82 bool contains(const void* addr) const {
duke@435 83 return addr >= (void*)_start && addr < (void*)end();
duke@435 84 }
duke@435 85 bool equals(const MemRegion mr2) const {
duke@435 86 // first disjunct since we do not have a canonical empty set
duke@435 87 return ((is_empty() && mr2.is_empty()) ||
duke@435 88 (start() == mr2.start() && end() == mr2.end()));
duke@435 89 }
duke@435 90
duke@435 91 size_t byte_size() const { return _word_size * sizeof(HeapWord); }
duke@435 92 size_t word_size() const { return _word_size; }
duke@435 93
duke@435 94 bool is_empty() const { return word_size() == 0; }
duke@435 95 };
duke@435 96
duke@435 97 // For iteration over MemRegion's.
duke@435 98
duke@435 99 class MemRegionClosure : public StackObj {
duke@435 100 public:
duke@435 101 virtual void do_MemRegion(MemRegion mr) = 0;
duke@435 102 };
duke@435 103
duke@435 104 // A ResourceObj version of MemRegionClosure
duke@435 105
duke@435 106 class MemRegionClosureRO: public MemRegionClosure {
duke@435 107 public:
zgu@3900 108 void* operator new(size_t size, ResourceObj::allocation_type type, MEMFLAGS flags) {
zgu@3900 109 return ResourceObj::operator new(size, type, flags);
duke@435 110 }
duke@435 111 void* operator new(size_t size, Arena *arena) {
duke@435 112 return ResourceObj::operator new(size, arena);
duke@435 113 }
duke@435 114 void* operator new(size_t size) {
duke@435 115 return ResourceObj::operator new(size);
duke@435 116 }
duke@435 117
duke@435 118 void operator delete(void* p) {} // nothing to do
duke@435 119 };
stefank@2314 120
stefank@2314 121 #endif // SHARE_VM_MEMORY_MEMREGION_HPP

mercurial