8378178: Change Thread::_allocated_bytes from jlong to uint64_t

Reviewed-by: coleenp, stefank
This commit is contained in:
Albert Mingkun Yang 2026-02-20 09:01:08 +00:00
parent fa2f4d82f5
commit 7ec561f8b7
12 changed files with 26 additions and 26 deletions

View File

@ -76,8 +76,8 @@ void ThreadLocalAllocBuffer::accumulate_and_reset_statistics(ThreadLocalAllocSta
size_t used = Universe::heap()->tlab_used();
_gc_waste += (unsigned)remaining();
size_t total_allocated = (size_t)thread()->allocated_bytes();
size_t allocated_since_last_gc = total_allocated - _allocated_before_last_gc;
uint64_t total_allocated = thread()->allocated_bytes();
uint64_t allocated_since_last_gc = total_allocated - _allocated_before_last_gc;
_allocated_before_last_gc = total_allocated;
print_stats("gc");

View File

@ -54,7 +54,7 @@ private:
size_t _desired_size; // desired size (including alignment_reserve)
size_t _refill_waste_limit; // hold onto tlab if free() is larger than this
size_t _allocated_before_last_gc; // total bytes allocated up until the last gc
uint64_t _allocated_before_last_gc; // total bytes allocated up until the last gc
static size_t _max_size; // maximum size of any TLAB
static int _reserve_for_allocation_prefetch; // Reserve at the end of the TLAB

View File

@ -493,7 +493,7 @@ TRACE_REQUEST_FUNC(InitialSystemProperty) {
TRACE_REQUEST_FUNC(ThreadAllocationStatistics) {
ResourceMark rm;
int initial_size = Threads::number_of_threads();
GrowableArray<jlong> allocated(initial_size);
GrowableArray<uint64_t> allocated(initial_size);
GrowableArray<traceid> thread_ids(initial_size);
JfrTicks time_stamp = JfrTicks::now();
JfrJavaThreadIterator iter;

View File

@ -432,7 +432,7 @@
\
nonstatic_field(Thread, _poll_data, SafepointMechanism::ThreadData) \
nonstatic_field(Thread, _tlab, ThreadLocalAllocBuffer) \
nonstatic_field(Thread, _allocated_bytes, jlong) \
nonstatic_field(Thread, _allocated_bytes, uint64_t) \
JFR_ONLY(nonstatic_field(Thread, _jfr_thread_local, JfrThreadLocal)) \
\
static_field(java_lang_Thread, _tid_offset, int) \

View File

@ -485,8 +485,8 @@ void Thread::print_on(outputStream* st, bool print_extended_info) const {
(double)_statistical_info.getElapsedTime() / 1000.0
);
if (is_Java_thread() && (PrintExtendedThreadInfo || print_extended_info)) {
size_t allocated_bytes = checked_cast<size_t>(cooked_allocated_bytes());
st->print("allocated=%zu%s ",
uint64_t allocated_bytes = cooked_allocated_bytes();
st->print("allocated=" UINT64_FORMAT "%s ",
byte_size_in_proper_unit(allocated_bytes),
proper_unit_for_byte_size(allocated_bytes)
);

View File

@ -257,7 +257,7 @@ class Thread: public ThreadShadow {
private:
ThreadLocalAllocBuffer _tlab; // Thread-local eden
jlong _allocated_bytes; // Cumulative number of bytes allocated on
uint64_t _allocated_bytes; // Cumulative number of bytes allocated on
// the Java heap
ThreadHeapSampler _heap_sampler; // For use when sampling the memory.
@ -410,9 +410,9 @@ class Thread: public ThreadShadow {
void retire_tlab(ThreadLocalAllocStats* stats = nullptr);
void fill_tlab(HeapWord* start, size_t pre_reserved, size_t new_size);
jlong allocated_bytes() { return _allocated_bytes; }
void incr_allocated_bytes(jlong size) { _allocated_bytes += size; }
inline jlong cooked_allocated_bytes() const;
uint64_t allocated_bytes() { return _allocated_bytes; }
void incr_allocated_bytes(uint64_t size) { _allocated_bytes += size; }
inline uint64_t cooked_allocated_bytes() const;
ThreadHeapSampler& heap_sampler() { return _heap_sampler; }

View File

@ -36,8 +36,8 @@
#include "runtime/os.hpp"
#endif
inline jlong Thread::cooked_allocated_bytes() const {
jlong allocated_bytes = AtomicAccess::load_acquire(&_allocated_bytes);
inline uint64_t Thread::cooked_allocated_bytes() const {
uint64_t allocated_bytes = AtomicAccess::load_acquire(&_allocated_bytes);
size_t used_bytes = 0;
if (UseTLAB) {
// cooked_used_bytes() does its best to not return implausible values, but

View File

@ -576,7 +576,7 @@
nonstatic_field(ThreadShadow, _exception_file, const char*) \
nonstatic_field(ThreadShadow, _exception_line, int) \
nonstatic_field(Thread, _tlab, ThreadLocalAllocBuffer) \
nonstatic_field(Thread, _allocated_bytes, jlong) \
nonstatic_field(Thread, _allocated_bytes, uint64_t) \
nonstatic_field(JavaThread, _lock_stack, LockStack) \
nonstatic_field(LockStack, _top, uint32_t) \
nonstatic_field(LockStack, _base[0], oop) \

View File

@ -2124,12 +2124,12 @@ JVM_ENTRY(jlong, jmm_GetTotalThreadAllocatedMemory(JNIEnv *env))
// We keep a high water mark to ensure monotonicity in case threads counted
// on a previous call end up in state (2).
static jlong high_water_result = 0;
static uint64_t high_water_result = 0;
JavaThreadIteratorWithHandle jtiwh;
jlong result = ThreadService::exited_allocated_bytes();
uint64_t result = ThreadService::exited_allocated_bytes();
for (; JavaThread* thread = jtiwh.next();) {
jlong size = thread->cooked_allocated_bytes();
uint64_t size = thread->cooked_allocated_bytes();
result += size;
}
@ -2144,7 +2144,7 @@ JVM_ENTRY(jlong, jmm_GetTotalThreadAllocatedMemory(JNIEnv *env))
high_water_result = result;
}
}
return result;
return checked_cast<jlong>(result);
JVM_END
// Gets the amount of memory allocated on the Java heap for a single thread.
@ -2156,13 +2156,13 @@ JVM_ENTRY(jlong, jmm_GetOneThreadAllocatedMemory(JNIEnv *env, jlong thread_id))
}
if (thread_id == 0) { // current thread
return thread->cooked_allocated_bytes();
return checked_cast<jlong>(thread->cooked_allocated_bytes());
}
ThreadsListHandle tlh;
JavaThread* java_thread = tlh.list()->find_JavaThread_from_java_tid(thread_id);
if (is_platform_thread(java_thread)) {
return java_thread->cooked_allocated_bytes();
return checked_cast<jlong>(java_thread->cooked_allocated_bytes());
}
return -1;
JVM_END

View File

@ -74,7 +74,7 @@ PerfVariable* ThreadService::_daemon_threads_count = nullptr;
volatile int ThreadService::_atomic_threads_count = 0;
volatile int ThreadService::_atomic_daemon_threads_count = 0;
volatile jlong ThreadService::_exited_allocated_bytes = 0;
volatile uint64_t ThreadService::_exited_allocated_bytes = 0;
ThreadDumpResult* ThreadService::_threaddump_list = nullptr;

View File

@ -63,7 +63,7 @@ private:
// As could this...
// Number of heap bytes allocated by terminated threads.
static volatile jlong _exited_allocated_bytes;
static volatile uint64_t _exited_allocated_bytes;
// These 2 counters are like the above thread counts, but are
// atomically decremented in ThreadService::current_thread_exiting instead of
@ -106,8 +106,8 @@ public:
static int get_live_thread_count() { return _atomic_threads_count; }
static int get_daemon_thread_count() { return _atomic_daemon_threads_count; }
static jlong exited_allocated_bytes() { return AtomicAccess::load(&_exited_allocated_bytes); }
static void incr_exited_allocated_bytes(jlong size) {
static uint64_t exited_allocated_bytes() { return AtomicAccess::load(&_exited_allocated_bytes); }
static void incr_exited_allocated_bytes(uint64_t size) {
// No need for an atomic add because called under the Threads_lock,
// but because _exited_allocated_bytes is read concurrently, need
// atomic store to avoid readers seeing a partial update.

View File

@ -39,7 +39,7 @@ public class Thread extends VMObject {
private static AddressField currentWaitingMonitorField;
private static AddressField osThreadField;
private static JLongField allocatedBytesField;
private static CIntegerField allocatedBytesField;
static {
VM.registerVMInitializedObserver(new Observer() {
@ -60,7 +60,7 @@ public class Thread extends VMObject {
tlabFieldOffset = typeThread.getField("_tlab").getOffset();
currentPendingMonitorField = typeJavaThread.getAddressField("_current_pending_monitor");
currentWaitingMonitorField = typeJavaThread.getAddressField("_current_waiting_monitor");
allocatedBytesField = typeThread.getJLongField("_allocated_bytes");
allocatedBytesField = typeThread.getCIntegerField("_allocated_bytes");
}
public Thread(Address addr) {