Mercurial > hg > truffle
comparison src/share/vm/memory/allocation.inline.hpp @ 6197:d2a62e0f25eb
6995781: Native Memory Tracking (Phase 1)
7151532: DCmd for hotspot native memory tracking
Summary: Implementation of native memory tracking phase 1, which tracks VM native memory usage, and related DCmd
Reviewed-by: acorn, coleenp, fparain
author | zgu |
---|---|
date | Thu, 28 Jun 2012 17:03:16 -0400 |
parents | bf29934d2f4f |
children | b9a9ed0f8eeb |
comparison
equal
deleted
inserted
replaced
6174:74533f63b116 | 6197:d2a62e0f25eb |
---|---|
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, const char* name = NULL) { | 51 inline char* AllocateHeap(size_t size, MEMFLAGS flags, address pc = 0) { |
52 char* p = (char*) os::malloc(size); | 52 if (pc == 0) { |
53 pc = CURRENT_PC; | |
54 } | |
55 char* p = (char*) os::malloc(size, flags, pc); | |
53 #ifdef ASSERT | 56 #ifdef ASSERT |
54 if (PrintMallocFree) trace_heap_malloc(size, name, p); | 57 if (PrintMallocFree) trace_heap_malloc(size, "AllocateHeap", p); |
55 #else | |
56 Unused_Variable(name); | |
57 #endif | 58 #endif |
58 if (p == NULL) vm_exit_out_of_memory(size, name); | 59 if (p == NULL) vm_exit_out_of_memory(size, "AllocateHeap"); |
59 return p; | 60 return p; |
60 } | 61 } |
61 | 62 |
62 inline char* ReallocateHeap(char *old, size_t size, const char* name = NULL) { | 63 inline char* ReallocateHeap(char *old, size_t size, MEMFLAGS flags) { |
63 char* p = (char*) os::realloc(old,size); | 64 char* p = (char*) os::realloc(old, size, flags, CURRENT_PC); |
64 #ifdef ASSERT | 65 #ifdef ASSERT |
65 if (PrintMallocFree) trace_heap_malloc(size, name, p); | 66 if (PrintMallocFree) trace_heap_malloc(size, "ReallocateHeap", p); |
66 #else | |
67 Unused_Variable(name); | |
68 #endif | 67 #endif |
69 if (p == NULL) vm_exit_out_of_memory(size, name); | 68 if (p == NULL) vm_exit_out_of_memory(size, "ReallocateHeap"); |
70 return p; | 69 return p; |
71 } | 70 } |
72 | 71 |
73 inline void FreeHeap(void* p) { | 72 inline void FreeHeap(void* p, MEMFLAGS memflags = mtInternal) { |
74 #ifdef ASSERT | 73 #ifdef ASSERT |
75 if (PrintMallocFree) trace_heap_free(p); | 74 if (PrintMallocFree) trace_heap_free(p); |
76 #endif | 75 #endif |
77 os::free(p); | 76 os::free(p, memflags); |
78 } | 77 } |
79 | 78 |
79 | |
80 template <MEMFLAGS F> void* CHeapObj<F>::operator new(size_t size, | |
81 address caller_pc){ | |
82 #ifdef ASSERT | |
83 void* p = (void*)AllocateHeap(size, F, (caller_pc != 0 ? caller_pc : CALLER_PC)); | |
84 if (PrintMallocFree) trace_heap_malloc(size, "CHeapObj-new", p); | |
85 return p; | |
86 #else | |
87 return (void *) AllocateHeap(size, F, (caller_pc != 0 ? caller_pc : CALLER_PC)); | |
88 #endif | |
89 } | |
90 | |
91 template <MEMFLAGS F> void* CHeapObj<F>::operator new (size_t size, | |
92 const std::nothrow_t& nothrow_constant, address caller_pc) { | |
93 #ifdef ASSERT | |
94 void* p = os::malloc(size, F, (caller_pc != 0 ? caller_pc : CALLER_PC)); | |
95 if (PrintMallocFree) trace_heap_malloc(size, "CHeapObj-new", p); | |
96 return p; | |
97 #else | |
98 return os::malloc(size, F, (caller_pc != 0 ? caller_pc : CALLER_PC)); | |
99 #endif | |
100 } | |
101 | |
102 template <MEMFLAGS F> void CHeapObj<F>::operator delete(void* p){ | |
103 FreeHeap(p, F); | |
104 } | |
105 | |
106 | |
80 #endif // SHARE_VM_MEMORY_ALLOCATION_INLINE_HPP | 107 #endif // SHARE_VM_MEMORY_ALLOCATION_INLINE_HPP |