hotspot/src/share/vm/memory/allocation.inline.hpp
changeset 14083 103054a71a30
parent 13963 e5b53c306fb5
child 15855 2ac9ebea17f3
equal deleted inserted replaced
14082:7425bbf64ead 14083:103054a71a30
    46 #endif
    46 #endif
    47 }
    47 }
    48 #endif
    48 #endif
    49 
    49 
    50 // allocate using malloc; will fail if no memory available
    50 // allocate using malloc; will fail if no memory available
    51 inline char* AllocateHeap(size_t size, MEMFLAGS flags, address pc = 0) {
    51 inline char* AllocateHeap(size_t size, MEMFLAGS flags, address pc = 0,
       
    52     AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) {
    52   if (pc == 0) {
    53   if (pc == 0) {
    53     pc = CURRENT_PC;
    54     pc = CURRENT_PC;
    54   }
    55   }
    55   char* p = (char*) os::malloc(size, flags, pc);
    56   char* p = (char*) os::malloc(size, flags, pc);
    56   #ifdef ASSERT
    57   #ifdef ASSERT
    57   if (PrintMallocFree) trace_heap_malloc(size, "AllocateHeap", p);
    58   if (PrintMallocFree) trace_heap_malloc(size, "AllocateHeap", p);
    58   #endif
    59   #endif
    59   if (p == NULL) vm_exit_out_of_memory(size, "AllocateHeap");
    60   if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) vm_exit_out_of_memory(size, "AllocateHeap");
    60   return p;
    61   return p;
    61 }
    62 }
    62 
    63 
    63 inline char* ReallocateHeap(char *old, size_t size, MEMFLAGS flags) {
    64 inline char* ReallocateHeap(char *old, size_t size, MEMFLAGS flags,
       
    65     AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) {
    64   char* p = (char*) os::realloc(old, size, flags, CURRENT_PC);
    66   char* p = (char*) os::realloc(old, size, flags, CURRENT_PC);
    65   #ifdef ASSERT
    67   #ifdef ASSERT
    66   if (PrintMallocFree) trace_heap_malloc(size, "ReallocateHeap", p);
    68   if (PrintMallocFree) trace_heap_malloc(size, "ReallocateHeap", p);
    67   #endif
    69   #endif
    68   if (p == NULL) vm_exit_out_of_memory(size, "ReallocateHeap");
    70   if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) vm_exit_out_of_memory(size, "ReallocateHeap");
    69   return p;
    71   return p;
    70 }
    72 }
    71 
    73 
    72 inline void FreeHeap(void* p, MEMFLAGS memflags = mtInternal) {
    74 inline void FreeHeap(void* p, MEMFLAGS memflags = mtInternal) {
    73   #ifdef ASSERT
    75   #ifdef ASSERT
    89   }
    91   }
    90 
    92 
    91 template <MEMFLAGS F> void* CHeapObj<F>::operator new (size_t size,
    93 template <MEMFLAGS F> void* CHeapObj<F>::operator new (size_t size,
    92   const std::nothrow_t&  nothrow_constant, address caller_pc) {
    94   const std::nothrow_t&  nothrow_constant, address caller_pc) {
    93 #ifdef ASSERT
    95 #ifdef ASSERT
    94     void* p = os::malloc(size, F, (caller_pc != 0 ? caller_pc : CALLER_PC));
    96   void* p = (void*)AllocateHeap(size, F, (caller_pc != 0 ? caller_pc : CALLER_PC),
       
    97       AllocFailStrategy::RETURN_NULL);
    95     if (PrintMallocFree) trace_heap_malloc(size, "CHeapObj-new", p);
    98     if (PrintMallocFree) trace_heap_malloc(size, "CHeapObj-new", p);
    96     return p;
    99     return p;
    97 #else
   100 #else
    98     return os::malloc(size, F, (caller_pc != 0 ? caller_pc : CALLER_PC));
   101   return (void *) AllocateHeap(size, F, (caller_pc != 0 ? caller_pc : CALLER_PC),
       
   102       AllocFailStrategy::RETURN_NULL);
    99 #endif
   103 #endif
   100 }
   104 }
   101 
   105 
   102 template <MEMFLAGS F> void CHeapObj<F>::operator delete(void* p){
   106 template <MEMFLAGS F> void CHeapObj<F>::operator delete(void* p){
   103    FreeHeap(p, F);
   107    FreeHeap(p, F);