141 |
141 |
142 void MemAllocator::Allocation::verify_before() { |
142 void MemAllocator::Allocation::verify_before() { |
143 // Clear unhandled oops for memory allocation. Memory allocation might |
143 // Clear unhandled oops for memory allocation. Memory allocation might |
144 // not take out a lock if from tlab, so clear here. |
144 // not take out a lock if from tlab, so clear here. |
145 Thread* THREAD = _thread; |
145 Thread* THREAD = _thread; |
146 CHECK_UNHANDLED_OOPS_ONLY(THREAD->clear_unhandled_oops();) |
|
147 assert(!HAS_PENDING_EXCEPTION, "Should not allocate with exception pending"); |
146 assert(!HAS_PENDING_EXCEPTION, "Should not allocate with exception pending"); |
148 debug_only(check_for_valid_allocation_state()); |
147 debug_only(check_for_valid_allocation_state()); |
149 assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed"); |
148 assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed"); |
150 } |
149 } |
151 |
150 |
170 // How to choose between a pending exception and a potential |
169 // How to choose between a pending exception and a potential |
171 // OutOfMemoryError? Don't allow pending exceptions. |
170 // OutOfMemoryError? Don't allow pending exceptions. |
172 // This is a VM policy failure, so how do we exhaustively test it? |
171 // This is a VM policy failure, so how do we exhaustively test it? |
173 assert(!_thread->has_pending_exception(), |
172 assert(!_thread->has_pending_exception(), |
174 "shouldn't be allocating with pending exception"); |
173 "shouldn't be allocating with pending exception"); |
175 if (StrictSafepointChecks) { |
174 // Allocation of an oop can always invoke a safepoint. |
176 assert(_thread->allow_allocation(), |
175 _thread->check_for_valid_safepoint_state(); |
177 "Allocation done by thread for which allocation is blocked " |
|
178 "by No_Allocation_Verifier!"); |
|
179 // Allocation of an oop can always invoke a safepoint, |
|
180 // hence, the true argument |
|
181 _thread->check_for_valid_safepoint_state(true); |
|
182 } |
|
183 } |
176 } |
184 #endif |
177 #endif |
185 |
178 |
186 void MemAllocator::Allocation::notify_allocation_jvmti_sampler() { |
179 void MemAllocator::Allocation::notify_allocation_jvmti_sampler() { |
187 // support for JVMTI VMObjectAlloc event (no-op if not enabled) |
180 // support for JVMTI VMObjectAlloc event (no-op if not enabled) |
230 void MemAllocator::Allocation::notify_allocation_jfr_sampler() { |
223 void MemAllocator::Allocation::notify_allocation_jfr_sampler() { |
231 HeapWord* mem = (HeapWord*)obj(); |
224 HeapWord* mem = (HeapWord*)obj(); |
232 size_t size_in_bytes = _allocator._word_size * HeapWordSize; |
225 size_t size_in_bytes = _allocator._word_size * HeapWordSize; |
233 |
226 |
234 if (_allocated_outside_tlab) { |
227 if (_allocated_outside_tlab) { |
235 AllocTracer::send_allocation_outside_tlab(_allocator._klass, mem, size_in_bytes, _thread); |
228 AllocTracer::send_allocation_outside_tlab(obj()->klass(), mem, size_in_bytes, _thread); |
236 } else if (_allocated_tlab_size != 0) { |
229 } else if (_allocated_tlab_size != 0) { |
237 // TLAB was refilled |
230 // TLAB was refilled |
238 AllocTracer::send_allocation_in_new_tlab(_allocator._klass, mem, _allocated_tlab_size * HeapWordSize, |
231 AllocTracer::send_allocation_in_new_tlab(obj()->klass(), mem, _allocated_tlab_size * HeapWordSize, |
239 size_in_bytes, _thread); |
232 size_in_bytes, _thread); |
240 } |
233 } |
241 } |
234 } |
242 |
235 |
243 void MemAllocator::Allocation::notify_allocation_dtrace_sampler() { |
236 void MemAllocator::Allocation::notify_allocation_dtrace_sampler() { |
244 if (DTraceAllocProbes) { |
237 if (DTraceAllocProbes) { |
245 // support for Dtrace object alloc event (no-op most of the time) |
238 // support for Dtrace object alloc event (no-op most of the time) |
246 Klass* klass = _allocator._klass; |
239 Klass* klass = obj()->klass(); |
247 size_t word_size = _allocator._word_size; |
240 size_t word_size = _allocator._word_size; |
248 if (klass != NULL && klass->name() != NULL) { |
241 if (klass != NULL && klass->name() != NULL) { |
249 SharedRuntime::dtrace_object_alloc(obj(), (int)word_size); |
242 SharedRuntime::dtrace_object_alloc(obj(), (int)word_size); |
250 } |
243 } |
251 } |
244 } |
387 assert(mem != NULL, "NULL object pointer"); |
384 assert(mem != NULL, "NULL object pointer"); |
388 if (UseBiasedLocking) { |
385 if (UseBiasedLocking) { |
389 oopDesc::set_mark_raw(mem, _klass->prototype_header()); |
386 oopDesc::set_mark_raw(mem, _klass->prototype_header()); |
390 } else { |
387 } else { |
391 // May be bootstrapping |
388 // May be bootstrapping |
392 oopDesc::set_mark_raw(mem, markOopDesc::prototype()); |
389 oopDesc::set_mark_raw(mem, markWord::prototype()); |
393 } |
390 } |
394 // Need a release store to ensure array/class length, mark word, and |
391 // Need a release store to ensure array/class length, mark word, and |
395 // object zeroing are visible before setting the klass non-NULL, for |
392 // object zeroing are visible before setting the klass non-NULL, for |
396 // concurrent collectors. |
393 // concurrent collectors. |
397 oopDesc::release_set_klass(mem, _klass); |
394 oopDesc::release_set_klass(mem, _klass); |