src/share/vm/memory/memRegion.hpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/memory/memRegion.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,127 @@
     1.4 +/*
     1.5 + * Copyright (c) 2000, 2013, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_MEMORY_MEMREGION_HPP
    1.29 +#define SHARE_VM_MEMORY_MEMREGION_HPP
    1.30 +
    1.31 +#include "memory/allocation.hpp"
    1.32 +#include "utilities/debug.hpp"
    1.33 +#include "utilities/globalDefinitions.hpp"
    1.34 +
    1.35 +// A very simple data structure representing a contigous region
    1.36 +// region of address space.
    1.37 +
    1.38 +// Note that MemRegions are passed by value, not by reference.
    1.39 +// The intent is that they remain very small and contain no
    1.40 +// objects. _ValueObj should never be allocated in heap but we do
    1.41 +// create MemRegions (in CardTableModRefBS) in heap so operator
    1.42 +// new and operator new [] added for this special case.
    1.43 +
    1.44 +class MetaWord;
    1.45 +
    1.46 +class MemRegion VALUE_OBJ_CLASS_SPEC {
    1.47 +  friend class VMStructs;
    1.48 +private:
    1.49 +  HeapWord* _start;
    1.50 +  size_t    _word_size;
    1.51 +
    1.52 +public:
    1.53 +  MemRegion() : _start(NULL), _word_size(0) {};
    1.54 +  MemRegion(HeapWord* start, size_t word_size) :
    1.55 +    _start(start), _word_size(word_size) {};
    1.56 +  MemRegion(HeapWord* start, HeapWord* end) :
    1.57 +    _start(start), _word_size(pointer_delta(end, start)) {
    1.58 +    assert(end >= start, "incorrect constructor arguments");
    1.59 +  }
    1.60 +  MemRegion(MetaWord* start, MetaWord* end) :
    1.61 +    _start((HeapWord*)start), _word_size(pointer_delta(end, start)) {
    1.62 +    assert(end >= start, "incorrect constructor arguments");
    1.63 +  }
    1.64 +
    1.65 +  MemRegion(const MemRegion& mr): _start(mr._start), _word_size(mr._word_size) {}
    1.66 +
    1.67 +  MemRegion intersection(const MemRegion mr2) const;
    1.68 +  // regions must overlap or be adjacent
    1.69 +  MemRegion _union(const MemRegion mr2) const;
    1.70 +  // minus will fail a guarantee if mr2 is interior to this,
    1.71 +  // since there's no way to return 2 disjoint regions.
    1.72 +  MemRegion minus(const MemRegion mr2) const;
    1.73 +
    1.74 +  HeapWord* start() const { return _start; }
    1.75 +  HeapWord* end() const   { return _start + _word_size; }
    1.76 +  HeapWord* last() const  { return _start + _word_size - 1; }
    1.77 +
    1.78 +  void set_start(HeapWord* start) { _start = start; }
    1.79 +  void set_end(HeapWord* end)     { _word_size = pointer_delta(end, _start); }
    1.80 +  void set_word_size(size_t word_size) {
    1.81 +    _word_size = word_size;
    1.82 +  }
    1.83 +
    1.84 +  bool contains(const MemRegion mr2) const {
    1.85 +    return _start <= mr2._start && end() >= mr2.end();
    1.86 +  }
    1.87 +  bool contains(const void* addr) const {
    1.88 +    return addr >= (void*)_start && addr < (void*)end();
    1.89 +  }
    1.90 +  bool equals(const MemRegion mr2) const {
    1.91 +    // first disjunct since we do not have a canonical empty set
    1.92 +    return ((is_empty() && mr2.is_empty()) ||
    1.93 +            (start() == mr2.start() && end() == mr2.end()));
    1.94 +  }
    1.95 +
    1.96 +  size_t byte_size() const { return _word_size * sizeof(HeapWord); }
    1.97 +  size_t word_size() const { return _word_size; }
    1.98 +
    1.99 +  bool is_empty() const { return word_size() == 0; }
   1.100 +  void* operator new(size_t size) throw();
   1.101 +  void* operator new [](size_t size) throw();
   1.102 +  void  operator delete(void* p);
   1.103 +  void  operator delete [](void* p);
   1.104 +};
   1.105 +
   1.106 +// For iteration over MemRegion's.
   1.107 +
   1.108 +class MemRegionClosure : public StackObj {
   1.109 +public:
   1.110 +  virtual void do_MemRegion(MemRegion mr) = 0;
   1.111 +};
   1.112 +
   1.113 +// A ResourceObj version of MemRegionClosure
   1.114 +
   1.115 +class MemRegionClosureRO: public MemRegionClosure {
   1.116 +public:
   1.117 +  void* operator new(size_t size, ResourceObj::allocation_type type, MEMFLAGS flags) throw() {
   1.118 +        return ResourceObj::operator new(size, type, flags);
   1.119 +  }
   1.120 +  void* operator new(size_t size, Arena *arena) throw() {
   1.121 +        return ResourceObj::operator new(size, arena);
   1.122 +  }
   1.123 +  void* operator new(size_t size) throw() {
   1.124 +        return ResourceObj::operator new(size);
   1.125 +  }
   1.126 +
   1.127 +  void  operator delete(void* p) {} // nothing to do
   1.128 +};
   1.129 +
   1.130 +#endif // SHARE_VM_MEMORY_MEMREGION_HPP

mercurial