Path: blob/master/test/jdk/java/lang/management/MemoryMXBean/LowMemoryTest2.sh
41155 views
#1# Copyright (c) 2004, 2019, Oracle and/or its affiliates. All rights reserved.2# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3#4# This code is free software; you can redistribute it and/or modify it5# under the terms of the GNU General Public License version 2 only, as6# published by the Free Software Foundation.7#8# This code is distributed in the hope that it will be useful, but WITHOUT9# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11# version 2 for more details (a copy is included in the LICENSE file that12# accompanied this code).13#14# You should have received a copy of the GNU General Public License version15# 2 along with this work; if not, write to the Free Software Foundation,16# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17#18# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19# or visit www.oracle.com if you need additional information or have any20# questions.21#2223#24# @test25# @bug 498212826# @summary Test low memory detection of non-heap memory pool27#28# @requires vm.gc=="null"29#30# @run build LowMemoryTest2 MemoryUtil31# @run shell/timeout=600 LowMemoryTest2.sh32#3334if [ ! -z "${TESTJAVA}" ] ; then35JAVA=${TESTJAVA}/bin/java36CLASSPATH=${TESTCLASSES}37export CLASSPATH38else39echo "--Error: TESTJAVA must be defined as the pathname of a jdk to test."40exit 141fi4243# Test execution4445failures=04647go() {48echo ''49sh -xc "$JAVA $TESTVMOPTS $*" 2>&150if [ $? != 0 ]; then failures=`expr $failures + 1`; fi51}5253# Run test with each GC configuration54#55# Notes: To ensure that metaspace fills up we disable class unloading.56# Also we set the max metaspace to 16MB/32MB - otherwise the test takes too57# long to run. The 32MB setting is required for running with CDS archive.5859go -noclassgc -XX:MaxMetaspaceSize=32m -XX:+UseSerialGC LowMemoryTest260go -noclassgc -XX:MaxMetaspaceSize=32m -XX:+UseParallelGC LowMemoryTest26162# Test class metaspace - might hit MaxMetaspaceSize instead if63# UseCompressedClassPointers is off or if 32 bit.64#65# (note: This is very shaky and that shakiness exposes a problem with MemoryMXBean:66#67# MemoryMXBean defines "used" "committed" and "max" (see java/lang/management/MemoryUsage.java)68# This abstraction misses a definition for "address space exhausted" which with the new Metaspace (jep387)69# can happen before committed/used hits any trigger. We now commit only on demand and therefore class loaders70# can sit atop of uncommitted address space, denying new loaders address space. In the old Metaspace,71# we would have committed the space right away and therefore the MemoryMXBean "committed" trigger72# would have fired. In the new Metaspace, we don't commit, so the MemoryMXBean does not fire.73go -noclassgc -XX:MaxMetaspaceSize=16m -XX:CompressedClassSpaceSize=4m LowMemoryTest27475echo ''76if [ $failures -gt 0 ];77then echo "$failures test(s) failed";78else echo "All test(s) passed"; fi79exit $failures808182