From 51e52c4eb851d485fd41ad0bdf7df617a1cdb792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Gr=C3=B6nlund?= Date: Mon, 19 Sep 2022 11:27:04 +0000 Subject: [PATCH] 8286496: Improve Thread labels Reviewed-by: mschoene, rhalade, egahlin --- .../jfr/recorder/checkpoint/jfrCheckpointManager.cpp | 9 ++++++--- src/hotspot/share/jfr/recorder/storage/jfrBuffer.cpp | 8 +++++--- src/hotspot/share/jfr/recorder/storage/jfrBuffer.hpp | 5 +++-- .../jfr/recorder/storage/jfrMemorySpace.inline.hpp | 10 +++++++++- src/hotspot/share/jfr/writers/jfrWriterHost.inline.hpp | 6 ++++-- 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/hotspot/share/jfr/recorder/checkpoint/jfrCheckpointManager.cpp b/src/hotspot/share/jfr/recorder/checkpoint/jfrCheckpointManager.cpp index b9923a9c8ad..8fce812b074 100644 --- a/src/hotspot/share/jfr/recorder/checkpoint/jfrCheckpointManager.cpp +++ b/src/hotspot/share/jfr/recorder/checkpoint/jfrCheckpointManager.cpp @@ -132,7 +132,9 @@ bool JfrCheckpointManager::initialize() { #ifdef ASSERT static void assert_lease(ConstBufferPtr buffer) { - assert(buffer != NULL, "invariant"); + if (buffer == nullptr) { + return; + } assert(buffer->acquired_by_self(), "invariant"); assert(buffer->lease(), "invariant"); } @@ -293,8 +295,9 @@ BufferPtr JfrCheckpointManager::flush(BufferPtr old, size_t used, size_t request return NULL; } BufferPtr new_buffer = renew(old, thread, used + requested, kind(old)); - assert(new_buffer != NULL, "invariant"); - migrate_outstanding_writes(old, new_buffer, used, requested); + if (new_buffer != nullptr) { + migrate_outstanding_writes(old, new_buffer, used, requested); + } retire(old); return new_buffer; } diff --git a/src/hotspot/share/jfr/recorder/storage/jfrBuffer.cpp b/src/hotspot/share/jfr/recorder/storage/jfrBuffer.cpp index 25cd473933f..6d8c86a0c65 100644 --- a/src/hotspot/share/jfr/recorder/storage/jfrBuffer.cpp +++ b/src/hotspot/share/jfr/recorder/storage/jfrBuffer.cpp @@ -35,13 +35,15 @@ JfrBuffer::JfrBuffer() : _next(NULL), _size(0), _header_size(0), _flags(0), - _context(0) {} + _context(0) + LP64_ONLY(COMMA _pad(0)) {} void JfrBuffer::initialize(size_t header_size, size_t size) { assert(_next == NULL, "invariant"); assert(_identity == NULL, "invariant"); - _header_size = (u2)header_size; - _size = (u4)(size / BytesPerWord); + assert(header_size <= max_jushort, "invariant"); + _header_size = static_cast(header_size); + _size = size; set_pos(start()); set_top(start()); assert(free_size() == size, "invariant"); diff --git a/src/hotspot/share/jfr/recorder/storage/jfrBuffer.hpp b/src/hotspot/share/jfr/recorder/storage/jfrBuffer.hpp index 7ec97a88c61..ae059e9230c 100644 --- a/src/hotspot/share/jfr/recorder/storage/jfrBuffer.hpp +++ b/src/hotspot/share/jfr/recorder/storage/jfrBuffer.hpp @@ -70,10 +70,11 @@ class JfrBuffer { const void* _identity; u1* _pos; mutable const u1* _top; - u4 _size; + size_t _size; u2 _header_size; u1 _flags; u1 _context; + LP64_ONLY(const u4 _pad;) const u1* stable_top() const; @@ -125,7 +126,7 @@ class JfrBuffer { void release_critical_section_top(const u1* new_top); size_t size() const { - return _size * BytesPerWord; + return _size; } size_t total_size() const { diff --git a/src/hotspot/share/jfr/recorder/storage/jfrMemorySpace.inline.hpp b/src/hotspot/share/jfr/recorder/storage/jfrMemorySpace.inline.hpp index f4b226cde9f..2e33958ace5 100644 --- a/src/hotspot/share/jfr/recorder/storage/jfrMemorySpace.inline.hpp +++ b/src/hotspot/share/jfr/recorder/storage/jfrMemorySpace.inline.hpp @@ -202,16 +202,24 @@ inline bool JfrMemorySpace< Client, RetrievalPolicy, FreeListType, FullListType, // allocations are even multiples of the mspace min size static inline size_t align_allocation_size(size_t requested_size, size_t min_element_size) { + if (requested_size > static_cast(min_intx)) { + assert(false, "requested size: " SIZE_FORMAT " is too large", requested_size); + return 0; + } u8 alloc_size_bytes = min_element_size; while (requested_size > alloc_size_bytes) { alloc_size_bytes <<= 1; } - return (size_t)alloc_size_bytes; + assert(alloc_size_bytes <= static_cast(min_intx), "invariant"); + return static_cast(alloc_size_bytes); } template class RetrievalPolicy, typename FreeListType, typename FullListType, bool epoch_aware> inline typename FreeListType::NodePtr JfrMemorySpace::allocate(size_t size) { const size_t aligned_size_bytes = align_allocation_size(size, _min_element_size); + if (aligned_size_bytes == 0) { + return NULL; + } void* const allocation = JfrCHeapObj::new_array(aligned_size_bytes + sizeof(Node)); if (allocation == NULL) { return NULL; diff --git a/src/hotspot/share/jfr/writers/jfrWriterHost.inline.hpp b/src/hotspot/share/jfr/writers/jfrWriterHost.inline.hpp index 629f994bb76..627ed53d303 100644 --- a/src/hotspot/share/jfr/writers/jfrWriterHost.inline.hpp +++ b/src/hotspot/share/jfr/writers/jfrWriterHost.inline.hpp @@ -73,6 +73,7 @@ template inline void WriterHost::write(const T* value, size_t len) { assert(value != NULL, "invariant"); assert(len > 0, "invariant"); + assert(len <= max_jint, "invariant"); // Might need T + 1 size u1* const pos = ensure_size(sizeof(T) * len + len); if (pos) { @@ -125,8 +126,9 @@ template inline void WriterHost::be_write(const T* value, size_t len) { assert(value != NULL, "invariant"); assert(len > 0, "invariant"); - // Might need T + 1 size - u1* const pos = ensure_size(sizeof(T) * len + len); + assert(len <= max_jint, "invariant"); + // Big endian writes map one-to-one for length, so no extra space is needed. + u1* const pos = ensure_size(sizeof(T) * len); if (pos) { this->set_current_pos(BE::be_write(value, len, pos)); }