198 } |
199 } |
199 |
200 |
200 NOT_PRODUCT(Universe::heap()->check_for_non_bad_heap_word_value(result, size)); |
201 NOT_PRODUCT(Universe::heap()->check_for_non_bad_heap_word_value(result, size)); |
201 assert(!HAS_PENDING_EXCEPTION, |
202 assert(!HAS_PENDING_EXCEPTION, |
202 "Unexpected exception, will result in uninitialized storage"); |
203 "Unexpected exception, will result in uninitialized storage"); |
203 THREAD->incr_allocated_bytes(size * HeapWordSize); |
204 size_t size_in_bytes = size * HeapWordSize; |
204 |
205 THREAD->incr_allocated_bytes(size_in_bytes); |
205 AllocTracer::send_allocation_outside_tlab(klass, result, size * HeapWordSize, THREAD); |
206 |
|
207 AllocTracer::send_allocation_outside_tlab(klass, result, size_in_bytes, THREAD); |
|
208 |
|
209 if (ThreadHeapSampler::enabled()) { |
|
210 THREAD->heap_sampler().check_for_sampling(result, size_in_bytes); |
|
211 } |
|
212 |
206 return result; |
213 return result; |
207 } |
214 } |
208 |
215 |
209 void CollectedHeap::init_obj(HeapWord* obj, size_t size) { |
216 void CollectedHeap::init_obj(HeapWord* obj, size_t size) { |
210 assert(obj != NULL, "cannot initialize NULL object"); |
217 assert(obj != NULL, "cannot initialize NULL object"); |
212 assert(size >= hs, "unexpected object size"); |
219 assert(size >= hs, "unexpected object size"); |
213 ((oop)obj)->set_klass_gap(0); |
220 ((oop)obj)->set_klass_gap(0); |
214 Copy::fill_to_aligned_words(obj + hs, size - hs); |
221 Copy::fill_to_aligned_words(obj + hs, size - hs); |
215 } |
222 } |
216 |
223 |
|
224 HeapWord* CollectedHeap::common_allocate_memory(Klass* klass, int size, |
|
225 void (*post_setup)(Klass*, HeapWord*, int), |
|
226 int size_for_post, bool init_memory, |
|
227 TRAPS) { |
|
228 HeapWord* obj; |
|
229 if (init_memory) { |
|
230 obj = common_mem_allocate_init(klass, size, CHECK_NULL); |
|
231 } else { |
|
232 obj = common_mem_allocate_noinit(klass, size, CHECK_NULL); |
|
233 } |
|
234 post_setup(klass, obj, size_for_post); |
|
235 return obj; |
|
236 } |
|
237 |
|
238 HeapWord* CollectedHeap::allocate_memory(Klass* klass, int size, |
|
239 void (*post_setup)(Klass*, HeapWord*, int), |
|
240 int size_for_post, bool init_memory, |
|
241 TRAPS) { |
|
242 HeapWord* obj; |
|
243 |
|
244 assert(JavaThread::current()->heap_sampler().add_sampling_collector(), |
|
245 "Should never return false."); |
|
246 |
|
247 if (JvmtiExport::should_post_sampled_object_alloc()) { |
|
248 HandleMark hm(THREAD); |
|
249 Handle obj_h; |
|
250 { |
|
251 JvmtiSampledObjectAllocEventCollector collector; |
|
252 obj = common_allocate_memory(klass, size, post_setup, size_for_post, |
|
253 init_memory, CHECK_NULL); |
|
254 // If we want to be sampling, protect the allocated object with a Handle |
|
255 // before doing the callback. The callback is done in the destructor of |
|
256 // the JvmtiSampledObjectAllocEventCollector. |
|
257 obj_h = Handle(THREAD, (oop) obj); |
|
258 } |
|
259 obj = (HeapWord*) obj_h(); |
|
260 } else { |
|
261 obj = common_allocate_memory(klass, size, post_setup, size_for_post, |
|
262 init_memory, CHECK_NULL); |
|
263 } |
|
264 |
|
265 assert(JavaThread::current()->heap_sampler().remove_sampling_collector(), |
|
266 "Should never return false."); |
|
267 return obj; |
|
268 } |
|
269 |
217 oop CollectedHeap::obj_allocate(Klass* klass, int size, TRAPS) { |
270 oop CollectedHeap::obj_allocate(Klass* klass, int size, TRAPS) { |
218 debug_only(check_for_valid_allocation_state()); |
271 debug_only(check_for_valid_allocation_state()); |
219 assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed"); |
272 assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed"); |
220 assert(size >= 0, "int won't convert to size_t"); |
273 assert(size >= 0, "int won't convert to size_t"); |
221 HeapWord* obj = common_mem_allocate_init(klass, size, CHECK_NULL); |
274 HeapWord* obj = allocate_memory(klass, size, post_allocation_setup_obj, |
222 post_allocation_setup_obj(klass, obj, size); |
275 size, true, CHECK_NULL); |
223 NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value(obj, size)); |
276 NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value(obj, size)); |
224 return (oop)obj; |
277 return (oop)obj; |
225 } |
278 } |
226 |
279 |
227 oop CollectedHeap::class_allocate(Klass* klass, int size, TRAPS) { |
280 oop CollectedHeap::class_allocate(Klass* klass, int size, TRAPS) { |
228 debug_only(check_for_valid_allocation_state()); |
281 debug_only(check_for_valid_allocation_state()); |
229 assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed"); |
282 assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed"); |
230 assert(size >= 0, "int won't convert to size_t"); |
283 assert(size >= 0, "int won't convert to size_t"); |
231 HeapWord* obj = common_mem_allocate_init(klass, size, CHECK_NULL); |
284 HeapWord* obj = allocate_memory(klass, size, post_allocation_setup_class, |
232 post_allocation_setup_class(klass, obj, size); // set oop_size |
285 size, true, CHECK_NULL); |
233 NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value(obj, size)); |
286 NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value(obj, size)); |
234 return (oop)obj; |
287 return (oop)obj; |
235 } |
288 } |
236 |
289 |
237 oop CollectedHeap::array_allocate(Klass* klass, |
290 oop CollectedHeap::array_allocate(Klass* klass, |
239 int length, |
292 int length, |
240 TRAPS) { |
293 TRAPS) { |
241 debug_only(check_for_valid_allocation_state()); |
294 debug_only(check_for_valid_allocation_state()); |
242 assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed"); |
295 assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed"); |
243 assert(size >= 0, "int won't convert to size_t"); |
296 assert(size >= 0, "int won't convert to size_t"); |
244 HeapWord* obj = common_mem_allocate_init(klass, size, CHECK_NULL); |
297 HeapWord* obj = allocate_memory(klass, size, post_allocation_setup_array, |
245 post_allocation_setup_array(klass, obj, length); |
298 length, true, CHECK_NULL); |
246 NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value(obj, size)); |
299 NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value(obj, size)); |
247 return (oop)obj; |
300 return (oop)obj; |
248 } |
301 } |
249 |
302 |
250 oop CollectedHeap::array_allocate_nozero(Klass* klass, |
303 oop CollectedHeap::array_allocate_nozero(Klass* klass, |
252 int length, |
305 int length, |
253 TRAPS) { |
306 TRAPS) { |
254 debug_only(check_for_valid_allocation_state()); |
307 debug_only(check_for_valid_allocation_state()); |
255 assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed"); |
308 assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed"); |
256 assert(size >= 0, "int won't convert to size_t"); |
309 assert(size >= 0, "int won't convert to size_t"); |
257 HeapWord* obj = common_mem_allocate_noinit(klass, size, CHECK_NULL); |
310 |
258 ((oop)obj)->set_klass_gap(0); |
311 HeapWord* obj = allocate_memory(klass, size, post_allocation_setup_array, |
259 post_allocation_setup_array(klass, obj, length); |
312 length, false, CHECK_NULL); |
260 #ifndef PRODUCT |
313 #ifndef PRODUCT |
261 const size_t hs = oopDesc::header_size()+1; |
314 const size_t hs = oopDesc::header_size()+1; |
262 Universe::heap()->check_for_non_bad_heap_word_value(obj+hs, size-hs); |
315 Universe::heap()->check_for_non_bad_heap_word_value(obj+hs, size-hs); |
263 #endif |
316 #endif |
264 return (oop)obj; |
317 return (oop)obj; |