From 7ec561f8b7a72ce3f6adee27dbdd86a191654e50 Mon Sep 17 00:00:00 2001 From: Albert Mingkun Yang Date: Fri, 20 Feb 2026 09:01:08 +0000 Subject: [PATCH] 8378178: Change Thread::_allocated_bytes from jlong to uint64_t Reviewed-by: coleenp, stefank --- .../share/gc/shared/threadLocalAllocBuffer.cpp | 4 ++-- .../share/gc/shared/threadLocalAllocBuffer.hpp | 2 +- src/hotspot/share/jfr/periodic/jfrPeriodic.cpp | 2 +- src/hotspot/share/jvmci/vmStructs_jvmci.cpp | 2 +- src/hotspot/share/runtime/thread.cpp | 4 ++-- src/hotspot/share/runtime/thread.hpp | 8 ++++---- src/hotspot/share/runtime/thread.inline.hpp | 4 ++-- src/hotspot/share/runtime/vmStructs.cpp | 2 +- src/hotspot/share/services/management.cpp | 12 ++++++------ src/hotspot/share/services/threadService.cpp | 2 +- src/hotspot/share/services/threadService.hpp | 6 +++--- .../classes/sun/jvm/hotspot/runtime/Thread.java | 4 ++-- 12 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/hotspot/share/gc/shared/threadLocalAllocBuffer.cpp b/src/hotspot/share/gc/shared/threadLocalAllocBuffer.cpp index d99544c0573..61cf73fe04a 100644 --- a/src/hotspot/share/gc/shared/threadLocalAllocBuffer.cpp +++ b/src/hotspot/share/gc/shared/threadLocalAllocBuffer.cpp @@ -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"); diff --git a/src/hotspot/share/gc/shared/threadLocalAllocBuffer.hpp b/src/hotspot/share/gc/shared/threadLocalAllocBuffer.hpp index 61caac7ec51..25d9bf00eac 100644 --- a/src/hotspot/share/gc/shared/threadLocalAllocBuffer.hpp +++ b/src/hotspot/share/gc/shared/threadLocalAllocBuffer.hpp @@ -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 diff --git a/src/hotspot/share/jfr/periodic/jfrPeriodic.cpp b/src/hotspot/share/jfr/periodic/jfrPeriodic.cpp index b30ebd8108c..426ba4e7650 100644 --- a/src/hotspot/share/jfr/periodic/jfrPeriodic.cpp +++ b/src/hotspot/share/jfr/periodic/jfrPeriodic.cpp @@ -493,7 +493,7 @@ TRACE_REQUEST_FUNC(InitialSystemProperty) { TRACE_REQUEST_FUNC(ThreadAllocationStatistics) { ResourceMark rm; int initial_size = Threads::number_of_threads(); - GrowableArray allocated(initial_size); + GrowableArray allocated(initial_size); GrowableArray thread_ids(initial_size); JfrTicks time_stamp = JfrTicks::now(); JfrJavaThreadIterator iter; diff --git a/src/hotspot/share/jvmci/vmStructs_jvmci.cpp b/src/hotspot/share/jvmci/vmStructs_jvmci.cpp index 91482e825cd..74314b0ad61 100644 --- a/src/hotspot/share/jvmci/vmStructs_jvmci.cpp +++ b/src/hotspot/share/jvmci/vmStructs_jvmci.cpp @@ -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) \ diff --git a/src/hotspot/share/runtime/thread.cpp b/src/hotspot/share/runtime/thread.cpp index f27d355f56e..6de56c30d5f 100644 --- a/src/hotspot/share/runtime/thread.cpp +++ b/src/hotspot/share/runtime/thread.cpp @@ -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(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) ); diff --git a/src/hotspot/share/runtime/thread.hpp b/src/hotspot/share/runtime/thread.hpp index 0225fa808cb..bef31a70170 100644 --- a/src/hotspot/share/runtime/thread.hpp +++ b/src/hotspot/share/runtime/thread.hpp @@ -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; } diff --git a/src/hotspot/share/runtime/thread.inline.hpp b/src/hotspot/share/runtime/thread.inline.hpp index d2ac34c3e46..b4cf3ec589a 100644 --- a/src/hotspot/share/runtime/thread.inline.hpp +++ b/src/hotspot/share/runtime/thread.inline.hpp @@ -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 diff --git a/src/hotspot/share/runtime/vmStructs.cpp b/src/hotspot/share/runtime/vmStructs.cpp index 92be0217bf3..4d2ba90e326 100644 --- a/src/hotspot/share/runtime/vmStructs.cpp +++ b/src/hotspot/share/runtime/vmStructs.cpp @@ -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) \ diff --git a/src/hotspot/share/services/management.cpp b/src/hotspot/share/services/management.cpp index 290e4839c96..09277e16479 100644 --- a/src/hotspot/share/services/management.cpp +++ b/src/hotspot/share/services/management.cpp @@ -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(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(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(java_thread->cooked_allocated_bytes()); } return -1; JVM_END diff --git a/src/hotspot/share/services/threadService.cpp b/src/hotspot/share/services/threadService.cpp index 4dc6abe54b7..4f511075967 100644 --- a/src/hotspot/share/services/threadService.cpp +++ b/src/hotspot/share/services/threadService.cpp @@ -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; diff --git a/src/hotspot/share/services/threadService.hpp b/src/hotspot/share/services/threadService.hpp index 4b0e76658b6..ddfc78e6315 100644 --- a/src/hotspot/share/services/threadService.hpp +++ b/src/hotspot/share/services/threadService.hpp @@ -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. diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/Thread.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/Thread.java index 22bc02a06d9..d2e05c6f84d 100644 --- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/Thread.java +++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/Thread.java @@ -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) {