diff --git a/src/hotspot/share/utilities/concurrentHashTable.hpp b/src/hotspot/share/utilities/concurrentHashTable.hpp index 5277f44087c..6edd10a63d7 100644 --- a/src/hotspot/share/utilities/concurrentHashTable.hpp +++ b/src/hotspot/share/utilities/concurrentHashTable.hpp @@ -73,7 +73,7 @@ class ConcurrentHashTable : public CHeapObj { void print_value_on(outputStream* st) const {}; }; - // Only constructed with placement new[] from an array allocated with MEMFLAGS + // Only constructed with placement new from an array allocated with MEMFLAGS // of InternalTable. class Bucket { private: diff --git a/src/hotspot/share/utilities/concurrentHashTable.inline.hpp b/src/hotspot/share/utilities/concurrentHashTable.inline.hpp index 2f604932fbe..d2edc60f82d 100644 --- a/src/hotspot/share/utilities/concurrentHashTable.inline.hpp +++ b/src/hotspot/share/utilities/concurrentHashTable.inline.hpp @@ -193,8 +193,12 @@ inline ConcurrentHashTable:: { assert(_log2_size >= SIZE_SMALL_LOG2 && _log2_size <= SIZE_BIG_LOG2, "Bad size"); - void* memory = NEW_C_HEAP_ARRAY(Bucket, _size, F); - _buckets = new (memory) Bucket[_size]; + _buckets = NEW_C_HEAP_ARRAY(Bucket, _size, F); + // Use placement new for each element instead of new[] which could use more + // memory than allocated. + for (size_t i = 0; i < _size; ++i) { + new (_buckets + i) Bucket(); + } } template