< prev index next >

src/share/vm/memory/allocation.inline.hpp

Print this page




  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_MEMORY_ALLOCATION_INLINE_HPP
  26 #define SHARE_VM_MEMORY_ALLOCATION_INLINE_HPP
  27 
  28 #include "runtime/atomic.inline.hpp"
  29 #include "runtime/os.hpp"
  30 #include "services/memTracker.hpp"
  31 
  32 // Explicit C-heap memory management
  33 
  34 void trace_heap_malloc(size_t size, const char* name, void *p);
  35 void trace_heap_free(void *p);
  36 
  37 #ifndef PRODUCT
  38 // Increments unsigned long value for statistics (not atomic on MP).
  39 inline void inc_stat_counter(volatile julong* dest, julong add_value) {
  40 #if defined(SPARC) || defined(X86)
  41   // Sparc and X86 have atomic jlong (8 bytes) instructions
  42   julong value = Atomic::load((volatile jlong*)dest);
  43   value += add_value;
  44   Atomic::store((jlong)value, (volatile jlong*)dest);
  45 #else
  46   // possible word-tearing during load/store
  47   *dest += add_value;
  48 #endif
  49 }
  50 #endif
  51 
  52 // allocate using malloc; will fail if no memory available
  53 inline char* AllocateHeap(size_t size, MEMFLAGS flags,
  54     const NativeCallStack& stack,
  55     AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) {
  56   char* p = (char*) os::malloc(size, flags, stack);
  57   #ifdef ASSERT
  58   if (PrintMallocFree) trace_heap_malloc(size, "AllocateHeap", p);
  59   #endif
  60   if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) {




  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_MEMORY_ALLOCATION_INLINE_HPP
  26 #define SHARE_VM_MEMORY_ALLOCATION_INLINE_HPP
  27 
  28 #include "runtime/atomic.inline.hpp"
  29 #include "runtime/os.hpp"
  30 #include "services/memTracker.hpp"
  31 
  32 // Explicit C-heap memory management
  33 
  34 void trace_heap_malloc(size_t size, const char* name, void *p);
  35 void trace_heap_free(void *p);
  36 
  37 #ifndef PRODUCT
  38 // Increments unsigned long value for statistics (not atomic on MP).
  39 inline void inc_stat_counter(volatile julong* dest, julong add_value) {
  40 #if defined(SPARC) || defined(X86) || defined(AARCH64)
  41   // Sparc and X86 have atomic jlong (8 bytes) instructions
  42   julong value = Atomic::load((volatile jlong*)dest);
  43   value += add_value;
  44   Atomic::store((jlong)value, (volatile jlong*)dest);
  45 #else
  46   // possible word-tearing during load/store
  47   *dest += add_value;
  48 #endif
  49 }
  50 #endif
  51 
  52 // allocate using malloc; will fail if no memory available
  53 inline char* AllocateHeap(size_t size, MEMFLAGS flags,
  54     const NativeCallStack& stack,
  55     AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) {
  56   char* p = (char*) os::malloc(size, flags, stack);
  57   #ifdef ASSERT
  58   if (PrintMallocFree) trace_heap_malloc(size, "AllocateHeap", p);
  59   #endif
  60   if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) {


< prev index next >