Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/nio/Buffer/LimitDirectMemory.sh
38813 views
#!/bin/sh12#3# Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.4# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.5#6# This code is free software; you can redistribute it and/or modify it7# under the terms of the GNU General Public License version 2 only, as8# published by the Free Software Foundation.9#10# This code is distributed in the hope that it will be useful, but WITHOUT11# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13# version 2 for more details (a copy is included in the LICENSE file that14# accompanied this code).15#16# You should have received a copy of the GNU General Public License version17# 2 along with this work; if not, write to the Free Software Foundation,18# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19#20# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21# or visit www.oracle.com if you need additional information or have any22# questions.23#2425# @test26# @bug 4627316 674352627# @summary Test option to limit direct memory allocation28#29# @build LimitDirectMemory30# @run shell LimitDirectMemory.sh3132TMP1=tmp_$$3334runTest() {35echo "Testing: $*"36${TESTJAVA}/bin/java ${TESTVMOPTS} $*37if [ $? -eq 0 ]38then echo "--- passed as expected"39else40echo "--- failed"41exit 142fi43}444546launchFail() {47echo "Testing: -XX:MaxDirectMemorySize=$* -cp ${TESTCLASSES} \48LimitDirectMemory true DEFAULT DEFAULT+1M"49${TESTJAVA}/bin/java ${TESTVMOPTS} -XX:MaxDirectMemorySize=$* -cp ${TESTCLASSES} \50LimitDirectMemory true DEFAULT DEFAULT+1M > ${TMP1} 2>&151cat ${TMP1}52cat ${TMP1} | grep -s "Unrecognized VM option: \'MaxDirectMemorySize="53if [ $? -ne 0 ]54then echo "--- failed as expected"55else56echo "--- failed"57exit 158fi59}6061# $java LimitDirectMemory throwp fill_direct_memory size_per_buffer6263# Memory is properly limited using multiple buffers.64runTest -XX:MaxDirectMemorySize=10 -cp ${TESTCLASSES} LimitDirectMemory true 10 165runTest -XX:MaxDirectMemorySize=1k -cp ${TESTCLASSES} LimitDirectMemory true 1k 10066runTest -XX:MaxDirectMemorySize=10m -cp ${TESTCLASSES} LimitDirectMemory true 10m 10m6768# We can increase the amount of available memory.69runTest -XX:MaxDirectMemorySize=65M -cp ${TESTCLASSES} \70LimitDirectMemory false 64M 65M7172# Exactly the default amount of memory is available.73runTest -cp ${TESTCLASSES} LimitDirectMemory false 10 174runTest -Xmx64m -cp ${TESTCLASSES} LimitDirectMemory false 0 DEFAULT75runTest -Xmx64m -cp ${TESTCLASSES} LimitDirectMemory true 0 DEFAULT+17677# We should be able to eliminate direct memory allocation entirely.78runTest -XX:MaxDirectMemorySize=0 -cp ${TESTCLASSES} LimitDirectMemory true 0 17980# Setting the system property should not work so we should be able to allocate81# the default amount.82runTest -Dsun.nio.MaxDirectMemorySize=1K -Xmx64m -cp ${TESTCLASSES} \83LimitDirectMemory false DEFAULT-1 DEFAULT/28485# Various bad values fail to launch the VM.86launchFail foo87launchFail 10kmt88launchFail -18990# Clean-up91rm ${TMP1}929394