--- /dev/null 2019-07-22 08:07:50.621255384 +0200 +++ new/test/hotspot/gtest/metaspace/test_pool.cpp 2019-07-22 11:08:21.857866266 +0200 @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2019, SAP. All rights reserved. + * Copyright (c) 2019, 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 "memory/allocation.hpp" +#include "memory/metaspace/abstractPool.hpp" +#include "runtime/os.hpp" + +#include "unittest.hpp" + +// Test AbstractPool class + +template +class AbstractPoolTest { + + typedef metaspace::AbstractPool PoolType; + + void test_exhaustion() { + PoolType pool; + for (I i = 0; i < max_size + 10; i ++) { + E* e = pool.allocate_element(); + if (i < max_size) { + ASSERT_EQUALS(e != NULL); + ASSERT_EQUALS(pool.get_used(), i); + } else { + ASSERT_EQUALS(e == NULL); + ASSERT_EQUALS(pool.get_used(), max_size); + } + } + ASSERT_EQUALS(pool.memory_footprint() == max_size * sizeof(E)); + } + + void random_alloc_free() { + PoolType pool; + E* elems = NEW_C_HEAP_ARRAY(E*, max_size, mtInternal); + int allocated = 0; + for (int iter = 0; iter < 1000; iter ++) { + I idx = (I)os::random() % max_size; + if (elems[idx] == NULL) { + elems[idx] = pool.allocate_element(); + } else { + pool.return_element(elems[idx]); + } + if ((os::random() & 1) > 0) { + + } else + for (I i = 0; i < max_size; i ++) { + + } + } + FREE_C_HEAP_ARRAY(elems); + } + +public: + + void do_test() { + test_exhaustion(); + } + + +}; + +