8298293: NMT: os::realloc() should verify that flags do not change between reallocations
Reviewed-by: dholmes, stuefe, iklam
This commit is contained in:
parent
101db262e1
commit
c37e9d1c8d
@ -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();
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user