8299915: Remove ArrayAllocatorMallocLimit and associated code
Reviewed-by: dholmes, coleenp
This commit is contained in:
parent
50a7a04e9a
commit
45a145e5bc
src/hotspot/share
gc/shared
memory
runtime
utilities
test
hotspot/jtreg
lib-test/jdk/test/whitebox/vm_flags
@ -99,13 +99,13 @@ inline void GenericTaskQueueSet<T, F>::print_and_reset_taskqueue_stats(const cha
|
||||
|
||||
template<class E, MEMFLAGS F, unsigned int N>
|
||||
inline GenericTaskQueue<E, F, N>::GenericTaskQueue() :
|
||||
_elems(ArrayAllocator<E>::allocate(N, F)),
|
||||
_elems(MallocArrayAllocator<E>::allocate(N, F)),
|
||||
_last_stolen_queue_id(InvalidQueueId),
|
||||
_seed(17 /* random number */) {}
|
||||
|
||||
template<class E, MEMFLAGS F, unsigned int N>
|
||||
inline GenericTaskQueue<E, F, N>::~GenericTaskQueue() {
|
||||
ArrayAllocator<E>::free(_elems, N);
|
||||
MallocArrayAllocator<E>::free(_elems);
|
||||
}
|
||||
|
||||
template<class E, MEMFLAGS F, unsigned int N> inline bool
|
||||
|
@ -616,32 +616,6 @@ public:
|
||||
void check() PRODUCT_RETURN;
|
||||
};
|
||||
|
||||
// Helper class to allocate arrays that may become large.
|
||||
// Uses the OS malloc for allocations smaller than ArrayAllocatorMallocLimit
|
||||
// and uses mapped memory for larger allocations.
|
||||
// Most OS mallocs do something similar but Solaris malloc does not revert
|
||||
// to mapped memory for large allocations. By default ArrayAllocatorMallocLimit
|
||||
// is set so that we always use malloc except for Solaris where we set the
|
||||
// limit to get mapped memory.
|
||||
template <class E>
|
||||
class ArrayAllocator : public AllStatic {
|
||||
private:
|
||||
static bool should_use_malloc(size_t length);
|
||||
|
||||
static E* allocate_malloc(size_t length, MEMFLAGS flags);
|
||||
static E* allocate_mmap(size_t length, MEMFLAGS flags);
|
||||
|
||||
static E* reallocate_malloc(E* addr, size_t new_length, MEMFLAGS flags);
|
||||
|
||||
static void free_malloc(E* addr, size_t length);
|
||||
static void free_mmap(E* addr, size_t length);
|
||||
|
||||
public:
|
||||
static E* allocate(size_t length, MEMFLAGS flags);
|
||||
static E* reallocate(E* old_addr, size_t old_length, size_t new_length, MEMFLAGS flags);
|
||||
static void free(E* addr, size_t length);
|
||||
};
|
||||
|
||||
// Uses mmapped memory for all allocations. All allocations are initially
|
||||
// zero-filled. No pre-touching.
|
||||
template <class E>
|
||||
|
@ -111,75 +111,4 @@ void MallocArrayAllocator<E>::free(E* addr) {
|
||||
FreeHeap(addr);
|
||||
}
|
||||
|
||||
template <class E>
|
||||
bool ArrayAllocator<E>::should_use_malloc(size_t length) {
|
||||
return MallocArrayAllocator<E>::size_for(length) < ArrayAllocatorMallocLimit;
|
||||
}
|
||||
|
||||
template <class E>
|
||||
E* ArrayAllocator<E>::allocate_malloc(size_t length, MEMFLAGS flags) {
|
||||
return MallocArrayAllocator<E>::allocate(length, flags);
|
||||
}
|
||||
|
||||
template <class E>
|
||||
E* ArrayAllocator<E>::allocate_mmap(size_t length, MEMFLAGS flags) {
|
||||
return MmapArrayAllocator<E>::allocate(length, flags);
|
||||
}
|
||||
|
||||
template <class E>
|
||||
E* ArrayAllocator<E>::allocate(size_t length, MEMFLAGS flags) {
|
||||
if (should_use_malloc(length)) {
|
||||
return allocate_malloc(length, flags);
|
||||
}
|
||||
|
||||
return allocate_mmap(length, flags);
|
||||
}
|
||||
|
||||
template <class E>
|
||||
E* ArrayAllocator<E>::reallocate_malloc(E* addr, size_t new_length, MEMFLAGS flags) {
|
||||
return MallocArrayAllocator<E>::reallocate(addr, new_length, flags);
|
||||
}
|
||||
|
||||
template <class E>
|
||||
E* ArrayAllocator<E>::reallocate(E* old_addr, size_t old_length, size_t new_length, MEMFLAGS flags) {
|
||||
if (should_use_malloc(old_length) && should_use_malloc(new_length)) {
|
||||
return reallocate_malloc(old_addr, new_length, flags);
|
||||
}
|
||||
|
||||
E* new_addr = (new_length > 0)
|
||||
? allocate(new_length, flags)
|
||||
: nullptr;
|
||||
|
||||
if (new_addr != nullptr && old_addr != nullptr) {
|
||||
memcpy(new_addr, old_addr, MIN2(old_length, new_length) * sizeof(E));
|
||||
}
|
||||
|
||||
if (old_addr != nullptr) {
|
||||
free(old_addr, old_length);
|
||||
}
|
||||
|
||||
return new_addr;
|
||||
}
|
||||
|
||||
template <class E>
|
||||
void ArrayAllocator<E>::free_malloc(E* addr, size_t length) {
|
||||
MallocArrayAllocator<E>::free(addr);
|
||||
}
|
||||
|
||||
template <class E>
|
||||
void ArrayAllocator<E>::free_mmap(E* addr, size_t length) {
|
||||
MmapArrayAllocator<E>::free(addr, length);
|
||||
}
|
||||
|
||||
template <class E>
|
||||
void ArrayAllocator<E>::free(E* addr, size_t length) {
|
||||
if (addr != nullptr) {
|
||||
if (should_use_malloc(length)) {
|
||||
free_malloc(addr, length);
|
||||
} else {
|
||||
free_mmap(addr, length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // SHARE_MEMORY_ALLOCATION_INLINE_HPP
|
||||
|
@ -1888,10 +1888,6 @@ const int ObjectAlignmentInBytes = 8;
|
||||
product(bool, WhiteBoxAPI, false, DIAGNOSTIC, \
|
||||
"Enable internal testing APIs") \
|
||||
\
|
||||
product(size_t, ArrayAllocatorMallocLimit, SIZE_MAX, EXPERIMENTAL, \
|
||||
"Allocation less than this value will be allocated " \
|
||||
"using malloc. Larger allocations will use mmap.") \
|
||||
\
|
||||
product(bool, AlwaysAtomicAccesses, false, EXPERIMENTAL, \
|
||||
"Accesses to all variables should always be atomic") \
|
||||
\
|
||||
|
@ -135,15 +135,17 @@ CHeapBitMap::~CHeapBitMap() {
|
||||
}
|
||||
|
||||
bm_word_t* CHeapBitMap::allocate(idx_t size_in_words) const {
|
||||
return ArrayAllocator<bm_word_t>::allocate(size_in_words, _flags);
|
||||
return MallocArrayAllocator<bm_word_t>::allocate(size_in_words, _flags);
|
||||
}
|
||||
|
||||
// GrowableBitMap<T>::resize uses free(ptr, size) for T as CHeapBitMap, ArenaBitMap and ResourceBitMap allocators.
|
||||
// The free(ptr, size) signature is kept but the size parameter is ignored.
|
||||
void CHeapBitMap::free(bm_word_t* map, idx_t size_in_words) const {
|
||||
ArrayAllocator<bm_word_t>::free(map, size_in_words);
|
||||
MallocArrayAllocator<bm_word_t>::free(map);
|
||||
}
|
||||
|
||||
bm_word_t* CHeapBitMap::reallocate(bm_word_t* map, size_t old_size_in_words, size_t new_size_in_words) const {
|
||||
return ArrayAllocator<bm_word_t>::reallocate(map, old_size_in_words, new_size_in_words, _flags);
|
||||
return MallocArrayAllocator<bm_word_t>::reallocate(map, new_size_in_words, _flags);
|
||||
}
|
||||
|
||||
#ifdef ASSERT
|
||||
|
@ -1,100 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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.
|
||||
*/
|
||||
|
||||
package gc.arguments;
|
||||
|
||||
/*
|
||||
* @test TestArrayAllocatorMallocLimit
|
||||
* @summary Sanity check that the ArrayAllocatorMallocLimit flag can be set.
|
||||
* The test helps verifying that size_t flags can be set/read.
|
||||
* @bug 8054823
|
||||
* @library /test/lib
|
||||
* @library /
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* java.management
|
||||
* @run driver gc.arguments.TestArrayAllocatorMallocLimit
|
||||
*/
|
||||
|
||||
import jdk.test.lib.Asserts;
|
||||
import jdk.test.lib.process.OutputAnalyzer;
|
||||
import java.math.BigInteger;
|
||||
|
||||
public class TestArrayAllocatorMallocLimit {
|
||||
public static void main(String [] args) throws Exception {
|
||||
testDefaultValue();
|
||||
testSetValue();
|
||||
}
|
||||
|
||||
private static final String flagName = "ArrayAllocatorMallocLimit";
|
||||
|
||||
// size_t ArrayAllocatorMallocLimit = 18446744073709551615{experimental}
|
||||
private static final String printFlagsFinalPattern = " *size_t *" + flagName + " *:?= *(\\d+) *\\{experimental\\} *";
|
||||
|
||||
public static void testDefaultValue() throws Exception {
|
||||
ProcessBuilder pb = GCArguments.createTestJvm(
|
||||
"-XX:+UnlockExperimentalVMOptions", "-XX:+PrintFlagsFinal", "-version");
|
||||
|
||||
OutputAnalyzer output = new OutputAnalyzer(pb.start());
|
||||
String value = output.firstMatch(printFlagsFinalPattern, 1);
|
||||
|
||||
try {
|
||||
Asserts.assertNotNull(value, "Couldn't find size_t flag " + flagName);
|
||||
|
||||
// A size_t is not always parseable with Long.parseValue,
|
||||
// use BigInteger instead.
|
||||
BigInteger biValue = new BigInteger(value);
|
||||
|
||||
// Sanity check that we got a non-zero value.
|
||||
Asserts.assertNotEquals(biValue, "0");
|
||||
|
||||
output.shouldHaveExitValue(0);
|
||||
} catch (Exception e) {
|
||||
System.err.println(output.getOutput());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static void testSetValue() throws Exception {
|
||||
long flagValue = 2048;
|
||||
|
||||
ProcessBuilder pb = GCArguments.createJavaProcessBuilder(
|
||||
"-XX:+UnlockExperimentalVMOptions", "-XX:" + flagName + "=" + flagValue, "-XX:+PrintFlagsFinal", "-version");
|
||||
|
||||
OutputAnalyzer output = new OutputAnalyzer(pb.start());
|
||||
String value = output.firstMatch(printFlagsFinalPattern, 1);
|
||||
|
||||
try {
|
||||
Asserts.assertNotNull("Couldn't find size_t flag " + flagName);
|
||||
|
||||
long longValue = Long.parseLong(value);
|
||||
|
||||
Asserts.assertEquals(longValue, flagValue);
|
||||
|
||||
output.shouldHaveExitValue(0);
|
||||
} catch (Exception e) {
|
||||
System.err.println(output.getOutput());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 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
|
||||
@ -59,8 +59,7 @@ public class AttachSetGetFlag {
|
||||
|
||||
// Test a non-manageable size_t flag.
|
||||
// Since it is not manageable, we can't test the setFlag functionality.
|
||||
testGetFlag("ArrayAllocatorMallocLimit", "128");
|
||||
// testSetFlag("ArrayAllocatorMallocLimit", "64", "128");
|
||||
testGetFlag("MetaspaceSize", "65536");
|
||||
|
||||
// Test a uint flag.
|
||||
testGetFlag("ParallelGCThreads", "10");
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 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
|
||||
@ -35,7 +35,7 @@
|
||||
import jdk.test.lib.Platform;
|
||||
|
||||
public class SizeTTest {
|
||||
private static final String FLAG_NAME = "ArrayAllocatorMallocLimit";
|
||||
private static final String FLAG_NAME = "LargePageSizeInBytes";
|
||||
private static final Long[] TESTS = {0L, 100L, (long) Integer.MAX_VALUE,
|
||||
(1L << 32L) - 1L, 1L << 32L};
|
||||
private static final Long[] EXPECTED_64 = TESTS;
|
||||
|
Loading…
x
Reference in New Issue
Block a user