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
107 #endif // SHARE_VM_MEMORY_ALLOCATION_INLINE_HPP
|
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 template <class E, MEMFLAGS F>
107 E* ArrayAllocator<E, F>::allocate(size_t length) {
108 assert(_addr == NULL, "Already in use");
109
110 _size = sizeof(E) * length;
111 _use_malloc = _size < ArrayAllocatorMallocLimit;
112
113 if (_use_malloc) {
114 _addr = AllocateHeap(_size, F);
115 if (_addr == NULL && _size >= (size_t)os::vm_allocation_granularity()) {
116 // malloc failed let's try with mmap instead
117 _use_malloc = false;
118 } else {
119 return (E*)_addr;
120 }
121 }
122
123 int alignment = os::vm_allocation_granularity();
124 _size = align_size_up(_size, alignment);
125
126 _addr = os::reserve_memory(_size, NULL, alignment, F);
127 if (_addr == NULL) {
128 vm_exit_out_of_memory(_size, "Allocator (reserve)");
129 }
130
131 bool success = os::commit_memory(_addr, _size, false /* executable */);
132 if (!success) {
133 vm_exit_out_of_memory(_size, "Allocator (commit)");
134 }
135
136 return (E*)_addr;
137 }
138
139 template<class E, MEMFLAGS F>
140 void ArrayAllocator<E, F>::free() {
141 if (_addr != NULL) {
142 if (_use_malloc) {
143 FreeHeap(_addr, F);
144 } else {
145 os::release_memory(_addr, _size);
146 }
147 _addr = NULL;
148 }
149 }
150
151 #endif // SHARE_VM_MEMORY_ALLOCATION_INLINE_HPP
|