< prev index next >

src/hotspot/share/memory/allocation.cpp

Print this page




  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  */
  24 
  25 #include "precompiled.hpp"
  26 #include "memory/allocation.hpp"
  27 #include "memory/allocation.inline.hpp"
  28 #include "memory/arena.hpp"
  29 #include "memory/metaspaceShared.hpp"
  30 #include "memory/resourceArea.hpp"

  31 #include "runtime/atomic.hpp"
  32 #include "runtime/os.hpp"
  33 #include "runtime/task.hpp"
  34 #include "runtime/threadCritical.hpp"
  35 #include "services/memTracker.hpp"
  36 #include "utilities/ostream.hpp"
  37 
  38 // allocate using malloc; will fail if no memory available
  39 char* AllocateHeap(size_t size,
  40                    MEMFLAGS flags,
  41                    const NativeCallStack& stack,
  42                    AllocFailType alloc_failmode /* = AllocFailStrategy::EXIT_OOM*/) {
  43   char* p = (char*) os::malloc(size, flags, stack);
  44   if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) {
  45     vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "AllocateHeap");
  46   }
  47   return p;
  48 }
  49 
  50 char* AllocateHeap(size_t size,


  66 
  67 void FreeHeap(void* p) {
  68   os::free(p);
  69 }
  70 
  71 void* MetaspaceObj::_shared_metaspace_base = NULL;
  72 void* MetaspaceObj::_shared_metaspace_top  = NULL;
  73 
  74 void* StackObj::operator new(size_t size)     throw() { ShouldNotCallThis(); return 0; }
  75 void  StackObj::operator delete(void* p)              { ShouldNotCallThis(); }
  76 void* StackObj::operator new [](size_t size)  throw() { ShouldNotCallThis(); return 0; }
  77 void  StackObj::operator delete [](void* p)           { ShouldNotCallThis(); }
  78 
  79 void* MetaspaceObj::operator new(size_t size, ClassLoaderData* loader_data,
  80                                  size_t word_size,
  81                                  MetaspaceObj::Type type, TRAPS) throw() {
  82   // Klass has it's own operator new
  83   return Metaspace::allocate(loader_data, word_size, type, THREAD);
  84 }
  85 
  86 bool MetaspaceObj::is_valid(const MetaspaceObj* p) {
  87   // Weed out obvious bogus values first without traversing metaspace
  88   if ((size_t)p < os::min_page_size()) {
  89     return false;
  90   } else if (!is_aligned((address)p, sizeof(MetaWord))) {
  91     return false;
  92   }
  93   return Metaspace::contains((void*)p);
  94 }
  95 
  96 void MetaspaceObj::print_address_on(outputStream* st) const {
  97   st->print(" {" INTPTR_FORMAT "}", p2i(this));
  98 }
  99 
 100 void* ResourceObj::operator new(size_t size, Arena *arena) throw() {
 101   address res = (address)arena->Amalloc(size);
 102   DEBUG_ONLY(set_allocation_type(res, ARENA);)
 103   return res;
 104 }
 105 
 106 void* ResourceObj::operator new [](size_t size, Arena *arena) throw() {
 107   address res = (address)arena->Amalloc(size);
 108   DEBUG_ONLY(set_allocation_type(res, ARENA);)
 109   return res;
 110 }
 111 
 112 void* ResourceObj::operator new(size_t size, allocation_type type, MEMFLAGS flags) throw() {
 113   address res = NULL;




  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  */
  24 
  25 #include "precompiled.hpp"
  26 #include "memory/allocation.hpp"
  27 #include "memory/allocation.inline.hpp"
  28 #include "memory/arena.hpp"
  29 #include "memory/metaspaceShared.hpp"
  30 #include "memory/resourceArea.hpp"
  31 #include "memory/universe.hpp"
  32 #include "runtime/atomic.hpp"
  33 #include "runtime/os.hpp"
  34 #include "runtime/task.hpp"
  35 #include "runtime/threadCritical.hpp"
  36 #include "services/memTracker.hpp"
  37 #include "utilities/ostream.hpp"
  38 
  39 // allocate using malloc; will fail if no memory available
  40 char* AllocateHeap(size_t size,
  41                    MEMFLAGS flags,
  42                    const NativeCallStack& stack,
  43                    AllocFailType alloc_failmode /* = AllocFailStrategy::EXIT_OOM*/) {
  44   char* p = (char*) os::malloc(size, flags, stack);
  45   if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) {
  46     vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "AllocateHeap");
  47   }
  48   return p;
  49 }
  50 
  51 char* AllocateHeap(size_t size,


  67 
  68 void FreeHeap(void* p) {
  69   os::free(p);
  70 }
  71 
  72 void* MetaspaceObj::_shared_metaspace_base = NULL;
  73 void* MetaspaceObj::_shared_metaspace_top  = NULL;
  74 
  75 void* StackObj::operator new(size_t size)     throw() { ShouldNotCallThis(); return 0; }
  76 void  StackObj::operator delete(void* p)              { ShouldNotCallThis(); }
  77 void* StackObj::operator new [](size_t size)  throw() { ShouldNotCallThis(); return 0; }
  78 void  StackObj::operator delete [](void* p)           { ShouldNotCallThis(); }
  79 
  80 void* MetaspaceObj::operator new(size_t size, ClassLoaderData* loader_data,
  81                                  size_t word_size,
  82                                  MetaspaceObj::Type type, TRAPS) throw() {
  83   // Klass has it's own operator new
  84   return Metaspace::allocate(loader_data, word_size, type, THREAD);
  85 }
  86 
  87 bool MetaspaceObj::is_metaspace_object() const {
  88   return Metaspace::contains((void*)this);






  89 }
  90 
  91 void MetaspaceObj::print_address_on(outputStream* st) const {
  92   st->print(" {" INTPTR_FORMAT "}", p2i(this));
  93 }
  94 
  95 void* ResourceObj::operator new(size_t size, Arena *arena) throw() {
  96   address res = (address)arena->Amalloc(size);
  97   DEBUG_ONLY(set_allocation_type(res, ARENA);)
  98   return res;
  99 }
 100 
 101 void* ResourceObj::operator new [](size_t size, Arena *arena) throw() {
 102   address res = (address)arena->Amalloc(size);
 103   DEBUG_ONLY(set_allocation_type(res, ARENA);)
 104   return res;
 105 }
 106 
 107 void* ResourceObj::operator new(size_t size, allocation_type type, MEMFLAGS flags) throw() {
 108   address res = NULL;


< prev index next >