From e92f387ab5db8245778c19a35f08079dfa46453c Mon Sep 17 00:00:00 2001 From: Vladimir Kozlov Date: Thu, 10 Jul 2025 17:04:29 +0000 Subject: [PATCH] 8360942: [ubsan] aotCache tests trigger runtime error: applying non-zero offset 16 to null pointer in CodeBlob::relocation_end() Reviewed-by: shade, thartmann Backport-of: dedcce045013b3ff84f5ef8857e1a83f0c09f9ad --- src/hotspot/share/code/codeBlob.cpp | 8 ++++++-- src/hotspot/share/code/codeBlob.hpp | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/hotspot/share/code/codeBlob.cpp b/src/hotspot/share/code/codeBlob.cpp index 5bb37c198d0..81ebb08fd51 100644 --- a/src/hotspot/share/code/codeBlob.cpp +++ b/src/hotspot/share/code/codeBlob.cpp @@ -160,7 +160,7 @@ CodeBlob::CodeBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size } } else { // We need unique and valid not null address - assert(_mutable_data = blob_end(), "sanity"); + assert(_mutable_data == blob_end(), "sanity"); } set_oop_maps(oop_maps); @@ -177,6 +177,7 @@ CodeBlob::CodeBlob(const char* name, CodeBlobKind kind, int size, uint16_t heade _code_offset(_content_offset), _data_offset(size), _frame_size(0), + _mutable_data_size(0), S390_ONLY(_ctable_offset(0) COMMA) _header_size(header_size), _frame_complete_offset(CodeOffsets::frame_never_safe), @@ -185,7 +186,7 @@ CodeBlob::CodeBlob(const char* name, CodeBlobKind kind, int size, uint16_t heade { assert(is_aligned(size, oopSize), "unaligned size"); assert(is_aligned(header_size, oopSize), "unaligned size"); - assert(_mutable_data = blob_end(), "sanity"); + assert(_mutable_data == blob_end(), "sanity"); } void CodeBlob::restore_mutable_data(address reloc_data) { @@ -195,8 +196,11 @@ void CodeBlob::restore_mutable_data(address reloc_data) { if (_mutable_data == nullptr) { vm_exit_out_of_memory(_mutable_data_size, OOM_MALLOC_ERROR, "codebuffer: no space for mutable data"); } + } else { + _mutable_data = blob_end(); // default value } if (_relocation_size > 0) { + assert(_mutable_data_size > 0, "relocation is part of mutable data section"); memcpy((address)relocation_begin(), reloc_data, relocation_size()); } } diff --git a/src/hotspot/share/code/codeBlob.hpp b/src/hotspot/share/code/codeBlob.hpp index f1920a829fc..118594c9ea1 100644 --- a/src/hotspot/share/code/codeBlob.hpp +++ b/src/hotspot/share/code/codeBlob.hpp @@ -247,7 +247,7 @@ public: // Sizes int size() const { return _size; } int header_size() const { return _header_size; } - int relocation_size() const { return pointer_delta_as_int((address) relocation_end(), (address) relocation_begin()); } + int relocation_size() const { return _relocation_size; } int content_size() const { return pointer_delta_as_int(content_end(), content_begin()); } int code_size() const { return pointer_delta_as_int(code_end(), code_begin()); }