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 assert(JavaThread::current()->heap_sampler().add_sampling_collector(),
202 "Should never return false.");
203
204 // Only check if the sampler could actually sample something in this path.
205 assert(!JvmtiExport::should_post_sampled_object_alloc() ||
206 !JvmtiSampledObjectAllocEventCollector::object_alloc_is_safe_to_sample() ||
207 _thread->heap_sampler().sampling_collector_present(),
208 "Sampling collector not present.");
209
210 if (JvmtiExport::should_post_sampled_object_alloc()) {
211 // If we want to be sampling, protect the allocated object with a Handle
212 // before doing the callback. The callback is done in the destructor of
213 // the JvmtiSampledObjectAllocEventCollector.
214 PreserveObj obj_h(_thread, _obj_ptr);
215 JvmtiSampledObjectAllocEventCollector collector;
216 size_t size_in_bytes = _allocator._word_size * HeapWordSize;
217 ThreadLocalAllocBuffer& tlab = _thread->tlab();
218 size_t bytes_since_last = _allocated_outside_tlab ? 0 : tlab.bytes_since_last_sample_point();
219 _thread->heap_sampler().check_for_sampling(obj_h(), size_in_bytes, bytes_since_last);
220 }
221
222 assert(JavaThread::current()->heap_sampler().remove_sampling_collector(), "Should never return false.");
223
224 if (_tlab_end_reset_for_sample || _allocated_tlab_size != 0) {
225 _thread->tlab().set_sample_end();
226 }
227 }
228
229 void MemAllocator::Allocation::notify_allocation_low_memory_detector() {
230 // support low memory notifications (no-op if not enabled)
231 LowMemoryDetector::detect_low_memory_for_collected_pools();
232 }
233
234 void MemAllocator::Allocation::notify_allocation_jfr_sampler() {
235 HeapWord* mem = (HeapWord*)obj();
236 size_t size_in_bytes = _allocator._word_size * HeapWordSize;
237
238 if (_allocated_outside_tlab) {
239 AllocTracer::send_allocation_outside_tlab(_allocator._klass, mem, size_in_bytes, _thread);
240 } else if (_allocated_tlab_size != 0) {
241 // TLAB was refilled
242 AllocTracer::send_allocation_in_new_tlab(_allocator._klass, mem, _allocated_tlab_size * HeapWordSize,
|
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);
211 }
212
213 if (_tlab_end_reset_for_sample || _allocated_tlab_size != 0) {
214 _thread->tlab().set_sample_end();
215 }
216 }
217
218 void MemAllocator::Allocation::notify_allocation_low_memory_detector() {
219 // support low memory notifications (no-op if not enabled)
220 LowMemoryDetector::detect_low_memory_for_collected_pools();
221 }
222
223 void MemAllocator::Allocation::notify_allocation_jfr_sampler() {
224 HeapWord* mem = (HeapWord*)obj();
225 size_t size_in_bytes = _allocator._word_size * HeapWordSize;
226
227 if (_allocated_outside_tlab) {
228 AllocTracer::send_allocation_outside_tlab(_allocator._klass, mem, size_in_bytes, _thread);
229 } else if (_allocated_tlab_size != 0) {
230 // TLAB was refilled
231 AllocTracer::send_allocation_in_new_tlab(_allocator._klass, mem, _allocated_tlab_size * HeapWordSize,
|