< prev index next >

src/hotspot/share/gc/shared/memAllocator.cpp

Print this page
rev 52084 : 8211980: Remove ThreadHeapSampler enable/disable/enabled methods
Summary:
Reviewed-by:


 170   // How to choose between a pending exception and a potential
 171   // OutOfMemoryError?  Don't allow pending exceptions.
 172   // This is a VM policy failure, so how do we exhaustively test it?
 173   assert(!_thread->has_pending_exception(),
 174          "shouldn't be allocating with pending exception");
 175   if (StrictSafepointChecks) {
 176     assert(_thread->allow_allocation(),
 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 }
 184 #endif
 185 
 186 void MemAllocator::Allocation::notify_allocation_jvmti_sampler() {
 187   // support for JVMTI VMObjectAlloc event (no-op if not enabled)
 188   JvmtiExport::vm_object_alloc_event_collector(obj());
 189 
 190   if (!ThreadHeapSampler::enabled()) {
 191     // Sampling disabled
 192     return;
 193   }
 194 
 195   if (!_allocated_outside_tlab && _allocated_tlab_size == 0 && !_tlab_end_reset_for_sample) {
 196     // Sample if it's a non-TLAB allocation, or a TLAB allocation that either refills the TLAB
 197     // or expands it due to taking a sampler induced slow path.
 198     return;
 199   }
 200 
 201   if (JvmtiExport::should_post_sampled_object_alloc()) {
 202     // If we want to be sampling, protect the allocated object with a Handle
 203     // before doing the callback. The callback is done in the destructor of
 204     // the JvmtiSampledObjectAllocEventCollector.
 205     PreserveObj obj_h(_thread, _obj_ptr);
 206     JvmtiSampledObjectAllocEventCollector collector;
 207     size_t size_in_bytes = _allocator._word_size * HeapWordSize;
 208     ThreadLocalAllocBuffer& tlab = _thread->tlab();
 209     size_t bytes_since_last = _allocated_outside_tlab ? 0 : tlab.bytes_since_last_sample_point();
 210     _thread->heap_sampler().check_for_sampling(obj_h(), size_in_bytes, bytes_since_last);


 265   return mem;
 266 }
 267 
 268 HeapWord* MemAllocator::allocate_inside_tlab(Allocation& allocation) const {
 269   assert(UseTLAB, "should use UseTLAB");
 270 
 271   // Try allocating from an existing TLAB.
 272   HeapWord* mem = _thread->tlab().allocate(_word_size);
 273   if (mem != NULL) {
 274     return mem;
 275   }
 276 
 277   // Try refilling the TLAB and allocating the object in it.
 278   return allocate_inside_tlab_slow(allocation);
 279 }
 280 
 281 HeapWord* MemAllocator::allocate_inside_tlab_slow(Allocation& allocation) const {
 282   HeapWord* mem = NULL;
 283   ThreadLocalAllocBuffer& tlab = _thread->tlab();
 284 
 285   if (ThreadHeapSampler::enabled()) {
 286     // Try to allocate the sampled object from TLAB, it is possible a sample
 287     // point was put and the TLAB still has space.
 288     tlab.set_back_allocation_end();
 289     mem = tlab.allocate(_word_size);
 290     if (mem != NULL) {
 291       allocation._tlab_end_reset_for_sample = true;
 292       return mem;
 293     }
 294   }
 295 
 296   // Retain tlab and allocate object in shared space if
 297   // the amount free in the tlab is too large to discard.
 298   if (tlab.free() > tlab.refill_waste_limit()) {
 299     tlab.record_slow_allocation(_word_size);
 300     return NULL;
 301   }
 302 
 303   // Discard tlab and allocate a new one.
 304   // To minimize fragmentation, the last TLAB may be smaller than the rest.
 305   size_t new_tlab_size = tlab.compute_size(_word_size);




 170   // How to choose between a pending exception and a potential
 171   // OutOfMemoryError?  Don't allow pending exceptions.
 172   // This is a VM policy failure, so how do we exhaustively test it?
 173   assert(!_thread->has_pending_exception(),
 174          "shouldn't be allocating with pending exception");
 175   if (StrictSafepointChecks) {
 176     assert(_thread->allow_allocation(),
 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 }
 184 #endif
 185 
 186 void MemAllocator::Allocation::notify_allocation_jvmti_sampler() {
 187   // support for JVMTI VMObjectAlloc event (no-op if not enabled)
 188   JvmtiExport::vm_object_alloc_event_collector(obj());
 189 
 190   if (!JvmtiExport::should_post_sampled_object_alloc()) {
 191     // Sampling disabled
 192     return;
 193   }
 194 
 195   if (!_allocated_outside_tlab && _allocated_tlab_size == 0 && !_tlab_end_reset_for_sample) {
 196     // Sample if it's a non-TLAB allocation, or a TLAB allocation that either refills the TLAB
 197     // or expands it due to taking a sampler induced slow path.
 198     return;
 199   }
 200 
 201   if (JvmtiExport::should_post_sampled_object_alloc()) {
 202     // If we want to be sampling, protect the allocated object with a Handle
 203     // before doing the callback. The callback is done in the destructor of
 204     // the JvmtiSampledObjectAllocEventCollector.
 205     PreserveObj obj_h(_thread, _obj_ptr);
 206     JvmtiSampledObjectAllocEventCollector collector;
 207     size_t size_in_bytes = _allocator._word_size * HeapWordSize;
 208     ThreadLocalAllocBuffer& tlab = _thread->tlab();
 209     size_t bytes_since_last = _allocated_outside_tlab ? 0 : tlab.bytes_since_last_sample_point();
 210     _thread->heap_sampler().check_for_sampling(obj_h(), size_in_bytes, bytes_since_last);


 265   return mem;
 266 }
 267 
 268 HeapWord* MemAllocator::allocate_inside_tlab(Allocation& allocation) const {
 269   assert(UseTLAB, "should use UseTLAB");
 270 
 271   // Try allocating from an existing TLAB.
 272   HeapWord* mem = _thread->tlab().allocate(_word_size);
 273   if (mem != NULL) {
 274     return mem;
 275   }
 276 
 277   // Try refilling the TLAB and allocating the object in it.
 278   return allocate_inside_tlab_slow(allocation);
 279 }
 280 
 281 HeapWord* MemAllocator::allocate_inside_tlab_slow(Allocation& allocation) const {
 282   HeapWord* mem = NULL;
 283   ThreadLocalAllocBuffer& tlab = _thread->tlab();
 284 
 285   if (JvmtiExport::should_post_sampled_object_alloc()) {
 286     // Try to allocate the sampled object from TLAB, it is possible a sample
 287     // point was put and the TLAB still has space.
 288     tlab.set_back_allocation_end();
 289     mem = tlab.allocate(_word_size);
 290     if (mem != NULL) {
 291       allocation._tlab_end_reset_for_sample = true;
 292       return mem;
 293     }
 294   }
 295 
 296   // Retain tlab and allocate object in shared space if
 297   // the amount free in the tlab is too large to discard.
 298   if (tlab.free() > tlab.refill_waste_limit()) {
 299     tlab.record_slow_allocation(_word_size);
 300     return NULL;
 301   }
 302 
 303   // Discard tlab and allocate a new one.
 304   // To minimize fragmentation, the last TLAB may be smaller than the rest.
 305   size_t new_tlab_size = tlab.compute_size(_word_size);


< prev index next >