diff --git a/src/hotspot/share/runtime/os.cpp b/src/hotspot/share/runtime/os.cpp index f24d9573236..35dd898ff7d 100644 --- a/src/hotspot/share/runtime/os.cpp +++ b/src/hotspot/share/runtime/os.cpp @@ -694,7 +694,7 @@ void* os::realloc(void *memblock, size_t size, MEMFLAGS memflags, const NativeCa // Special handling for NMT preinit phase before arguments are parsed void* rc = nullptr; - if (NMTPreInit::handle_realloc(&rc, memblock, size)) { + if (NMTPreInit::handle_realloc(&rc, memblock, size, memflags)) { return rc; } @@ -727,6 +727,8 @@ void* os::realloc(void *memblock, size_t size, MEMFLAGS memflags, const NativeCa // Perform integrity checks on and mark the old block as dead *before* calling the real realloc(3) since it // may invalidate the old block, including its header. MallocHeader* header = MallocHeader::resolve_checked(memblock); + assert(memflags == header->flags(), "weird NMT flags mismatch (new:\"%s\" != old:\"%s\")\n", + NMTUtil::flag_to_name(memflags), NMTUtil::flag_to_name(header->flags())); const MallocHeader::FreeInfo free_info = header->free_info(); header->mark_block_as_dead(); diff --git a/src/hotspot/share/services/nmtPreInit.cpp b/src/hotspot/share/services/nmtPreInit.cpp index c63aaac6cf2..ff29195b5cf 100644 --- a/src/hotspot/share/services/nmtPreInit.cpp +++ b/src/hotspot/share/services/nmtPreInit.cpp @@ -172,8 +172,8 @@ void NMTPreInit::create_table() { } // Allocate with os::malloc (hidden to prevent having to include os.hpp) -void* NMTPreInit::do_os_malloc(size_t size) { - return os::malloc(size, mtNMT); +void* NMTPreInit::do_os_malloc(size_t size, MEMFLAGS memflags) { + return os::malloc(size, memflags); } // Switches from NMT pre-init state to NMT post-init state; diff --git a/src/hotspot/share/services/nmtPreInit.hpp b/src/hotspot/share/services/nmtPreInit.hpp index 19e87a44679..30e67ffcbec 100644 --- a/src/hotspot/share/services/nmtPreInit.hpp +++ b/src/hotspot/share/services/nmtPreInit.hpp @@ -248,7 +248,7 @@ class NMTPreInit : public AllStatic { } // Just a wrapper for os::malloc to avoid including os.hpp here. - static void* do_os_malloc(size_t size); + static void* do_os_malloc(size_t size, MEMFLAGS memflags); public: @@ -276,7 +276,7 @@ public: // Called from os::realloc. // Returns true if reallocation was handled here; in that case, // *rc contains the return address. - static bool handle_realloc(void** rc, void* old_p, size_t new_size) { + static bool handle_realloc(void** rc, void* old_p, size_t new_size, MEMFLAGS memflags) { if (old_p == nullptr) { // realloc(null, n) return handle_malloc(rc, new_size); } @@ -305,7 +305,7 @@ public: // and confusing us. const NMTPreInitAllocation* a = find_in_map(old_p); if (a != nullptr) { // this was originally a pre-init allocation - void* p_new = do_os_malloc(new_size); + void* p_new = do_os_malloc(new_size, memflags); ::memcpy(p_new, a->payload(), MIN2(a->size, new_size)); (*rc) = p_new; return true;