@@ -56,11 +56,11 @@ class MemAllocator::Allocation: StackObj {
56
56
bool check_out_of_memory ();
57
57
void verify_before ();
58
58
void verify_after ();
59
- void notify_allocation (JavaThread* thread );
59
+ void notify_allocation ();
60
60
void notify_allocation_jvmti_sampler ();
61
61
void notify_allocation_low_memory_detector ();
62
62
void notify_allocation_jfr_sampler ();
63
- void notify_allocation_dtrace_sampler (JavaThread* thread );
63
+ void notify_allocation_dtrace_sampler ();
64
64
#ifdef ASSERT
65
65
void check_for_valid_allocation_state () const ;
66
66
#endif
@@ -70,19 +70,20 @@ class MemAllocator::Allocation: StackObj {
70
70
public:
71
71
Allocation (const MemAllocator& allocator, oop* obj_ptr)
72
72
: _allocator(allocator),
73
- _thread (JavaThread::current( )),
73
+ _thread (JavaThread::cast(allocator._thread )), // Do not use Allocation in non-JavaThreads.
74
74
_obj_ptr(obj_ptr),
75
75
_overhead_limit_exceeded(false ),
76
76
_allocated_outside_tlab(false ),
77
77
_allocated_tlab_size(0 ),
78
78
_tlab_end_reset_for_sample(false )
79
79
{
80
+ assert (Thread::current () == allocator._thread , " do not pass MemAllocator across threads" );
80
81
verify_before ();
81
82
}
82
83
83
84
~Allocation () {
84
85
if (!check_out_of_memory ()) {
85
- notify_allocation (_thread );
86
+ notify_allocation ();
86
87
}
87
88
}
88
89
@@ -156,7 +157,7 @@ void MemAllocator::Allocation::check_for_valid_allocation_state() const {
156
157
assert (!_thread->has_pending_exception (),
157
158
" shouldn't be allocating with pending exception" );
158
159
// Allocation of an oop can always invoke a safepoint.
159
- JavaThread::cast ( _thread) ->check_for_valid_safepoint_state ();
160
+ _thread->check_for_valid_safepoint_state ();
160
161
}
161
162
#endif
162
163
@@ -217,21 +218,21 @@ void MemAllocator::Allocation::notify_allocation_jfr_sampler() {
217
218
}
218
219
}
219
220
220
- void MemAllocator::Allocation::notify_allocation_dtrace_sampler (JavaThread* thread ) {
221
+ void MemAllocator::Allocation::notify_allocation_dtrace_sampler () {
221
222
if (DTraceAllocProbes) {
222
223
// support for Dtrace object alloc event (no-op most of the time)
223
224
Klass* klass = obj ()->klass ();
224
225
size_t word_size = _allocator._word_size ;
225
226
if (klass != nullptr && klass->name () != nullptr ) {
226
- SharedRuntime::dtrace_object_alloc (thread , obj (), word_size);
227
+ SharedRuntime::dtrace_object_alloc (_thread , obj (), word_size);
227
228
}
228
229
}
229
230
}
230
231
231
- void MemAllocator::Allocation::notify_allocation (JavaThread* thread ) {
232
+ void MemAllocator::Allocation::notify_allocation () {
232
233
notify_allocation_low_memory_detector ();
233
234
notify_allocation_jfr_sampler ();
234
- notify_allocation_dtrace_sampler (thread );
235
+ notify_allocation_dtrace_sampler ();
235
236
notify_allocation_jvmti_sampler ();
236
237
}
237
238
@@ -335,7 +336,7 @@ HeapWord* MemAllocator::mem_allocate_inside_tlab_slow(Allocation& allocation) co
335
336
336
337
HeapWord* MemAllocator::mem_allocate_slow (Allocation& allocation) const {
337
338
// Allocation of an oop can always invoke a safepoint.
338
- debug_only (JavaThread::cast ( _thread) ->check_for_valid_safepoint_state ());
339
+ debug_only (allocation. _thread ->check_for_valid_safepoint_state ());
339
340
340
341
if (UseTLAB) {
341
342
// Try refilling the TLAB and allocating the object in it.
1 commit comments
openjdk-notifier[bot] commentedon Aug 11, 2023
Review
Issues