8337938: ZUtils::alloc_aligned allocates without reporting to NMT
Reviewed-by: stefank, kbarrett
This commit is contained in:
parent
03204600c5
commit
a6c0630737
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include "precompiled.hpp"
|
||||
#include "gc/z/zUtils.hpp"
|
||||
#include "utilities/debug.hpp"
|
||||
#include "utilities/globalDefinitions.hpp"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
uintptr_t ZUtils::alloc_aligned(size_t alignment, size_t size) {
|
||||
void* res = nullptr;
|
||||
|
||||
// Use raw posix_memalign as long as we have no wrapper for it
|
||||
ALLOW_C_FUNCTION(::posix_memalign, int rc = posix_memalign(&res, alignment, size);)
|
||||
if (rc != 0) {
|
||||
fatal("posix_memalign() failed");
|
||||
}
|
||||
|
||||
memset(res, 0, size);
|
||||
|
||||
return (uintptr_t)res;
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include "precompiled.hpp"
|
||||
#include "gc/z/zUtils.hpp"
|
||||
#include "utilities/debug.hpp"
|
||||
|
||||
#include <malloc.h>
|
||||
|
||||
uintptr_t ZUtils::alloc_aligned(size_t alignment, size_t size) {
|
||||
void* const res = _aligned_malloc(size, alignment);
|
||||
|
||||
if (res == nullptr) {
|
||||
fatal("_aligned_malloc failed");
|
||||
}
|
||||
|
||||
memset(res, 0, size);
|
||||
|
||||
return (uintptr_t)res;
|
||||
}
|
@ -35,7 +35,7 @@
|
||||
#include "gc/z/zRelocationSetSelector.inline.hpp"
|
||||
#include "gc/z/zStat.hpp"
|
||||
#include "gc/z/zTracer.inline.hpp"
|
||||
#include "gc/z/zUtils.hpp"
|
||||
#include "gc/z/zUtils.inline.hpp"
|
||||
#include "memory/metaspaceUtils.hpp"
|
||||
#include "memory/resourceArea.hpp"
|
||||
#include "runtime/atomic.hpp"
|
||||
@ -364,7 +364,7 @@ void ZStatValue::initialize() {
|
||||
|
||||
// Allocation aligned memory
|
||||
const size_t size = _cpu_offset * ZCPU::count();
|
||||
_base = ZUtils::alloc_aligned(ZCacheLineSize, size);
|
||||
_base = ZUtils::alloc_aligned_unfreeable(ZCacheLineSize, size);
|
||||
}
|
||||
|
||||
const char* ZStatValue::group() const {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -34,7 +34,7 @@ public:
|
||||
static const char* thread_name();
|
||||
|
||||
// Allocation
|
||||
static uintptr_t alloc_aligned(size_t alignment, size_t size);
|
||||
static uintptr_t alloc_aligned_unfreeable(size_t alignment, size_t size);
|
||||
|
||||
// Size conversion
|
||||
static size_t bytes_to_words(size_t size_in_words);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -28,11 +28,24 @@
|
||||
|
||||
#include "gc/z/zAddress.inline.hpp"
|
||||
#include "oops/oop.inline.hpp"
|
||||
#include "runtime/os.hpp"
|
||||
#include "utilities/align.hpp"
|
||||
#include "utilities/copy.hpp"
|
||||
#include "utilities/debug.hpp"
|
||||
#include "utilities/globalDefinitions.hpp"
|
||||
|
||||
inline uintptr_t ZUtils::alloc_aligned_unfreeable(size_t alignment, size_t size) {
|
||||
const size_t padded_size = size + (alignment - 1);
|
||||
void* const addr = os::malloc(padded_size, mtGC);
|
||||
void* const aligned_addr = align_up(addr, alignment);
|
||||
|
||||
memset(aligned_addr, 0, size);
|
||||
|
||||
// Since free expects pointers returned by malloc, aligned_addr cannot be
|
||||
// freed since it is most likely not the same as addr after alignment.
|
||||
return (uintptr_t)aligned_addr;
|
||||
}
|
||||
|
||||
inline size_t ZUtils::bytes_to_words(size_t size_in_bytes) {
|
||||
assert(is_aligned(size_in_bytes, BytesPerWord), "Size not word aligned");
|
||||
return size_in_bytes >> LogBytesPerWord;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -31,7 +31,7 @@
|
||||
#include "gc/z/zCPU.inline.hpp"
|
||||
#include "gc/z/zGlobals.hpp"
|
||||
#include "gc/z/zNUMA.hpp"
|
||||
#include "gc/z/zUtils.hpp"
|
||||
#include "gc/z/zUtils.inline.hpp"
|
||||
#include "runtime/globals.hpp"
|
||||
#include "utilities/align.hpp"
|
||||
|
||||
@ -58,7 +58,7 @@ uintptr_t ZValueStorage<S>::alloc(size_t size) {
|
||||
// Allocate new block of memory
|
||||
const size_t block_alignment = offset;
|
||||
const size_t block_size = offset * S::count();
|
||||
_top = ZUtils::alloc_aligned(block_alignment, block_size);
|
||||
_top = ZUtils::alloc_aligned_unfreeable(block_alignment, block_size);
|
||||
_end = _top + offset;
|
||||
|
||||
// Retry allocation
|
||||
|
Loading…
Reference in New Issue
Block a user