src/share/vm/memory/memRegion.hpp

Tue, 14 May 2013 09:41:12 -0700

author
minqi
date
Tue, 14 May 2013 09:41:12 -0700
changeset 5103
f9be75d21404
parent 4037
da91efe96a93
child 5614
9758d9f36299
permissions
-rw-r--r--

8012902: remove use of global operator new - take 2
Summary: The fix of 8010992, disable use of global operator new and new[] which caused failure on some tests. This takes two of the bugs also add ALLOW_OPERATOR_NEW_USAGE to prevent crash for third party code calling operator new of jvm on certain platforms.
Reviewed-by: coleenp, dholmes, zgu
Contributed-by: yumin.qi@oracle.com

     1 /*
     2  * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 #ifndef SHARE_VM_MEMORY_MEMREGION_HPP
    26 #define SHARE_VM_MEMORY_MEMREGION_HPP
    28 #include "memory/allocation.hpp"
    29 #include "utilities/debug.hpp"
    30 #include "utilities/globalDefinitions.hpp"
    32 // A very simple data structure representing a contigous region
    33 // region of address space.
    35 // Note that MemRegions are passed by value, not by reference.
    36 // The intent is that they remain very small and contain no
    37 // objects. _ValueObj should never be allocated in heap but we do
    38 // create MemRegions (in CardTableModRefBS) in heap so operator
    39 // new and operator new [] added for this special case.
    41 class MetaWord;
    43 class MemRegion VALUE_OBJ_CLASS_SPEC {
    44   friend class VMStructs;
    45 private:
    46   HeapWord* _start;
    47   size_t    _word_size;
    49 public:
    50   MemRegion() : _start(NULL), _word_size(0) {};
    51   MemRegion(HeapWord* start, size_t word_size) :
    52     _start(start), _word_size(word_size) {};
    53   MemRegion(HeapWord* start, HeapWord* end) :
    54     _start(start), _word_size(pointer_delta(end, start)) {
    55     assert(end >= start, "incorrect constructor arguments");
    56   }
    57   MemRegion(MetaWord* start, MetaWord* end) :
    58     _start((HeapWord*)start), _word_size(pointer_delta(end, start)) {
    59     assert(end >= start, "incorrect constructor arguments");
    60   }
    62   MemRegion(const MemRegion& mr): _start(mr._start), _word_size(mr._word_size) {}
    64   MemRegion intersection(const MemRegion mr2) const;
    65   // regions must overlap or be adjacent
    66   MemRegion _union(const MemRegion mr2) const;
    67   // minus will fail a guarantee if mr2 is interior to this,
    68   // since there's no way to return 2 disjoint regions.
    69   MemRegion minus(const MemRegion mr2) const;
    71   HeapWord* start() const { return _start; }
    72   HeapWord* end() const   { return _start + _word_size; }
    73   HeapWord* last() const  { return _start + _word_size - 1; }
    75   void set_start(HeapWord* start) { _start = start; }
    76   void set_end(HeapWord* end)     { _word_size = pointer_delta(end, _start); }
    77   void set_word_size(size_t word_size) {
    78     _word_size = word_size;
    79   }
    81   bool contains(const MemRegion mr2) const {
    82     return _start <= mr2._start && end() >= mr2.end();
    83   }
    84   bool contains(const void* addr) const {
    85     return addr >= (void*)_start && addr < (void*)end();
    86   }
    87   bool equals(const MemRegion mr2) const {
    88     // first disjunct since we do not have a canonical empty set
    89     return ((is_empty() && mr2.is_empty()) ||
    90             (start() == mr2.start() && end() == mr2.end()));
    91   }
    93   size_t byte_size() const { return _word_size * sizeof(HeapWord); }
    94   size_t word_size() const { return _word_size; }
    96   bool is_empty() const { return word_size() == 0; }
    97   void* operator new(size_t size);
    98   void* operator new [](size_t size);
    99   void  operator delete(void* p);
   100   void  operator delete [](void* p);
   101 };
   103 // For iteration over MemRegion's.
   105 class MemRegionClosure : public StackObj {
   106 public:
   107   virtual void do_MemRegion(MemRegion mr) = 0;
   108 };
   110 // A ResourceObj version of MemRegionClosure
   112 class MemRegionClosureRO: public MemRegionClosure {
   113 public:
   114   void* operator new(size_t size, ResourceObj::allocation_type type, MEMFLAGS flags) {
   115         return ResourceObj::operator new(size, type, flags);
   116   }
   117   void* operator new(size_t size, Arena *arena) {
   118         return ResourceObj::operator new(size, arena);
   119   }
   120   void* operator new(size_t size) {
   121         return ResourceObj::operator new(size);
   122   }
   124   void  operator delete(void* p) {} // nothing to do
   125 };
   127 #endif // SHARE_VM_MEMORY_MEMREGION_HPP

mercurial