From 22182f71ed520150b1ee05e5b788ecddfb0a6508 Mon Sep 17 00:00:00 2001 From: Vladimir Kozlov Date: Fri, 21 Mar 2025 20:51:30 +0000 Subject: [PATCH] 8352112: [ubsan] hotspot/share/code/relocInfo.cpp:130:37: runtime error: applying non-zero offset 18446744073709551614 to null pointer Reviewed-by: dlong, bulasevich --- src/hotspot/share/code/codeBlob.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/hotspot/share/code/codeBlob.cpp b/src/hotspot/share/code/codeBlob.cpp index 79f6bf61ff1..72f0dd67a44 100644 --- a/src/hotspot/share/code/codeBlob.cpp +++ b/src/hotspot/share/code/codeBlob.cpp @@ -121,7 +121,7 @@ CodeBlob::CodeBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size int mutable_data_size) : _oop_maps(nullptr), // will be set by set_oop_maps() call _name(name), - _mutable_data(nullptr), + _mutable_data(header_begin() + size), // default value is blob_end() _size(size), _relocation_size(align_up(cb->total_relocation_size(), oopSize)), _content_offset(CodeBlob::align_code_offset(header_size)), @@ -151,6 +151,9 @@ CodeBlob::CodeBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size if (_mutable_data == nullptr) { vm_exit_out_of_memory(_mutable_data_size, OOM_MALLOC_ERROR, "codebuffer: no space for mutable data"); } + } else { + // We need unique and valid not null address + assert(_mutable_data = blob_end(), "sanity"); } set_oop_maps(oop_maps); @@ -160,7 +163,7 @@ CodeBlob::CodeBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size CodeBlob::CodeBlob(const char* name, CodeBlobKind kind, int size, uint16_t header_size) : _oop_maps(nullptr), _name(name), - _mutable_data(nullptr), + _mutable_data(header_begin() + size), // default value is blob_end() _size(size), _relocation_size(0), _content_offset(CodeBlob::align_code_offset(header_size)), @@ -175,12 +178,14 @@ 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"); } void CodeBlob::purge() { - if (_mutable_data != nullptr) { + assert(_mutable_data != nullptr, "should never be null"); + if (_mutable_data != blob_end()) { os::free(_mutable_data); - _mutable_data = nullptr; + _mutable_data = blob_end(); // Valid not null address } if (_oop_maps != nullptr) { delete _oop_maps;