30
30
#include " gc/shared/memAllocator.hpp"
31
31
#include " gc/shared/threadLocalAllocBuffer.inline.hpp"
32
32
#include " gc/shared/tlab_globals.hpp"
33
+ #include " jfr/jfrEvents.hpp"
33
34
#include " memory/universe.hpp"
34
35
#include " oops/arrayOop.hpp"
35
36
#include " oops/oop.inline.hpp"
41
42
#include " services/lowMemoryDetector.hpp"
42
43
#include " utilities/align.hpp"
43
44
#include " utilities/copy.hpp"
45
+ #include " utilities/dtrace.hpp"
44
46
#include " utilities/globalDefinitions.hpp"
45
47
46
48
class MemAllocator ::Allocation: StackObj {
@@ -171,7 +173,8 @@ void MemAllocator::Allocation::notify_allocation_jvmti_sampler() {
171
173
return ;
172
174
}
173
175
174
- if (!_allocated_outside_tlab && _allocated_tlab_size == 0 && !_tlab_end_reset_for_sample) {
176
+ bool hit_mark = _allocated_tlab_size != 0 || _tlab_end_reset_for_sample;
177
+ if (!_allocated_outside_tlab && !hit_mark) {
175
178
// Sample if it's a non-TLAB allocation, or a TLAB allocation that either refills the TLAB
176
179
// or expands it due to taking a sampler induced slow path.
177
180
return ;
@@ -181,23 +184,21 @@ void MemAllocator::Allocation::notify_allocation_jvmti_sampler() {
181
184
// before doing the callback. The callback is done in the destructor of
182
185
// the JvmtiSampledObjectAllocEventCollector.
183
186
size_t bytes_since_last = 0 ;
184
-
187
+ size_t bytes_since_allocation = 0 ;
185
188
{
186
189
PreserveObj obj_h (_thread, _obj_ptr);
187
190
JvmtiSampledObjectAllocEventCollector collector;
188
191
size_t size_in_bytes = _allocator._word_size * HeapWordSize;
189
- ThreadLocalAllocBuffer& tlab = _thread->tlab ();
190
192
191
- if (!_allocated_outside_tlab) {
192
- bytes_since_last = tlab. bytes_since_last_sample_point ( );
193
+ if (_thread-> heap_samplers (). jvmti (). check_for_sampling (&bytes_since_allocation, size_in_bytes, !_allocated_outside_tlab) ) {
194
+ JvmtiExport::sampled_object_alloc_event_collector ( obj_h () );
193
195
}
194
-
195
- _thread->heap_sampler ().check_for_sampling (obj_h (), size_in_bytes, bytes_since_last);
196
196
}
197
197
198
- if (_tlab_end_reset_for_sample || _allocated_tlab_size != 0 ) {
198
+ if (hit_mark) {
199
+ ThreadHeapSampler& sampler = _thread->heap_samplers ().jvmti ();
199
200
// Tell tlab to forget bytes_since_last if we passed it to the heap sampler.
200
- _thread->tlab ().set_sample_end (bytes_since_last != 0 );
201
+ sampler. update_bytes ( _thread->tlab ().set_sample_end (sampler. bytes_until_sample ()), !_allocated_outside_tlab );
201
202
}
202
203
}
203
204
@@ -217,6 +218,36 @@ void MemAllocator::Allocation::notify_allocation_jfr_sampler() {
217
218
AllocTracer::send_allocation_in_new_tlab (obj ()->klass (), mem, _allocated_tlab_size * HeapWordSize,
218
219
size_in_bytes, _thread);
219
220
}
221
+
222
+ EventObjectAllocationSample event;
223
+ if (!event.should_commit ()) {
224
+ return ;
225
+ }
226
+
227
+ bool hit_mark = _allocated_tlab_size != 0 || _tlab_end_reset_for_sample;
228
+ if (!_allocated_outside_tlab && !hit_mark) {
229
+ // Sample if it's a non-TLAB allocation, or a TLAB allocation that either refills the TLAB
230
+ // or expands it due to taking a sampler induced slow path.
231
+ return ;
232
+ }
233
+
234
+ ThreadHeapSampler& sampler = _thread->heap_samplers ().jfr ();
235
+ if (sampler.bytes_until_sample () == static_cast <size_t >(-1 )) {
236
+ return ;
237
+ }
238
+
239
+ size_t bytes_since_allocation = 0 ;
240
+ if (sampler.check_for_sampling (&bytes_since_allocation, size_in_bytes, !_allocated_outside_tlab)) {
241
+ size_t weight = bytes_since_allocation == 0 ? size_in_bytes : bytes_since_allocation;
242
+ AllocTracer::send_allocation_sample (obj ()->klass (), mem, size_in_bytes, weight, _allocated_outside_tlab, _thread);
243
+ HOTSPOT_GC_ALLOCOBJECT_SAMPLE (obj ()->klass ()->name ()->as_C_string (), size_in_bytes, weight);
244
+ }
245
+
246
+ if (hit_mark) {
247
+ // Tell tlab to forget bytes_since_last if we passed it to the heap sampler.
248
+ size_t bytes_inc = _thread->tlab ().set_sample_end (sampler.bytes_until_sample ());
249
+ sampler.update_bytes (bytes_inc, !_allocated_outside_tlab);
250
+ }
220
251
}
221
252
222
253
void MemAllocator::Allocation::notify_allocation_dtrace_sampler () {
@@ -258,7 +289,9 @@ HeapWord* MemAllocator::mem_allocate_inside_tlab_slow(Allocation& allocation) co
258
289
HeapWord* mem = nullptr ;
259
290
ThreadLocalAllocBuffer& tlab = _thread->tlab ();
260
291
261
- if (JvmtiExport::should_post_sampled_object_alloc ()) {
292
+ EventObjectAllocationSample event;
293
+
294
+ if (JvmtiExport::should_post_sampled_object_alloc () || event.should_commit ()) {
262
295
tlab.set_back_allocation_end ();
263
296
mem = tlab.allocate (_word_size);
264
297
0 commit comments