diff --git a/src/hotspot/share/gc/shared/taskqueue.inline.hpp b/src/hotspot/share/gc/shared/taskqueue.inline.hpp index 8faeb73cb8d..f937ce8a2e9 100644 --- a/src/hotspot/share/gc/shared/taskqueue.inline.hpp +++ b/src/hotspot/share/gc/shared/taskqueue.inline.hpp @@ -99,13 +99,13 @@ inline void GenericTaskQueueSet::print_and_reset_taskqueue_stats(const cha template inline GenericTaskQueue::GenericTaskQueue() : - _elems(ArrayAllocator::allocate(N, F)), + _elems(MallocArrayAllocator::allocate(N, F)), _last_stolen_queue_id(InvalidQueueId), _seed(17 /* random number */) {} template inline GenericTaskQueue::~GenericTaskQueue() { - ArrayAllocator::free(_elems, N); + MallocArrayAllocator::free(_elems); } template inline bool diff --git a/src/hotspot/share/memory/allocation.hpp b/src/hotspot/share/memory/allocation.hpp index 0bb1840fd34..50bb2e0c68b 100644 --- a/src/hotspot/share/memory/allocation.hpp +++ b/src/hotspot/share/memory/allocation.hpp @@ -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 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 diff --git a/src/hotspot/share/memory/allocation.inline.hpp b/src/hotspot/share/memory/allocation.inline.hpp index fa2b2a7a7e3..4a1b0b0c597 100644 --- a/src/hotspot/share/memory/allocation.inline.hpp +++ b/src/hotspot/share/memory/allocation.inline.hpp @@ -111,75 +111,4 @@ void MallocArrayAllocator::free(E* addr) { FreeHeap(addr); } -template -bool ArrayAllocator::should_use_malloc(size_t length) { - return MallocArrayAllocator::size_for(length) < ArrayAllocatorMallocLimit; -} - -template -E* ArrayAllocator::allocate_malloc(size_t length, MEMFLAGS flags) { - return MallocArrayAllocator::allocate(length, flags); -} - -template -E* ArrayAllocator::allocate_mmap(size_t length, MEMFLAGS flags) { - return MmapArrayAllocator::allocate(length, flags); -} - -template -E* ArrayAllocator::allocate(size_t length, MEMFLAGS flags) { - if (should_use_malloc(length)) { - return allocate_malloc(length, flags); - } - - return allocate_mmap(length, flags); -} - -template -E* ArrayAllocator::reallocate_malloc(E* addr, size_t new_length, MEMFLAGS flags) { - return MallocArrayAllocator::reallocate(addr, new_length, flags); -} - -template -E* ArrayAllocator::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 -void ArrayAllocator::free_malloc(E* addr, size_t length) { - MallocArrayAllocator::free(addr); -} - -template -void ArrayAllocator::free_mmap(E* addr, size_t length) { - MmapArrayAllocator::free(addr, length); -} - -template -void ArrayAllocator::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 diff --git a/src/hotspot/share/runtime/globals.hpp b/src/hotspot/share/runtime/globals.hpp index 6b96e109d11..4ae156a773e 100644 --- a/src/hotspot/share/runtime/globals.hpp +++ b/src/hotspot/share/runtime/globals.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") \ \ diff --git a/src/hotspot/share/utilities/bitMap.cpp b/src/hotspot/share/utilities/bitMap.cpp index 5ab586debd9..3cef6122557 100644 --- a/src/hotspot/share/utilities/bitMap.cpp +++ b/src/hotspot/share/utilities/bitMap.cpp @@ -135,15 +135,17 @@ CHeapBitMap::~CHeapBitMap() { } bm_word_t* CHeapBitMap::allocate(idx_t size_in_words) const { - return ArrayAllocator::allocate(size_in_words, _flags); + return MallocArrayAllocator::allocate(size_in_words, _flags); } +// GrowableBitMap::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::free(map, size_in_words); + MallocArrayAllocator::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::reallocate(map, old_size_in_words, new_size_in_words, _flags); + return MallocArrayAllocator::reallocate(map, new_size_in_words, _flags); } #ifdef ASSERT diff --git a/test/hotspot/jtreg/gc/arguments/TestArrayAllocatorMallocLimit.java b/test/hotspot/jtreg/gc/arguments/TestArrayAllocatorMallocLimit.java deleted file mode 100644 index 80f0ec4f0cc..00000000000 --- a/test/hotspot/jtreg/gc/arguments/TestArrayAllocatorMallocLimit.java +++ /dev/null @@ -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; - } - } - -} diff --git a/test/hotspot/jtreg/serviceability/attach/AttachSetGetFlag.java b/test/hotspot/jtreg/serviceability/attach/AttachSetGetFlag.java index 939cc872a11..d6b21a5a327 100644 --- a/test/hotspot/jtreg/serviceability/attach/AttachSetGetFlag.java +++ b/test/hotspot/jtreg/serviceability/attach/AttachSetGetFlag.java @@ -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"); diff --git a/test/lib-test/jdk/test/whitebox/vm_flags/SizeTTest.java b/test/lib-test/jdk/test/whitebox/vm_flags/SizeTTest.java index ae57d6701fd..4dc7a75065f 100644 --- a/test/lib-test/jdk/test/whitebox/vm_flags/SizeTTest.java +++ b/test/lib-test/jdk/test/whitebox/vm_flags/SizeTTest.java @@ -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;